#codec #parser #parser-generator #rfc #generate #section #rfc6381

rfc6381-codec

Parser and generator for codec-string values, as specified in RFC 6381, section 3

2 unstable releases

0.2.0 Mar 17, 2024
0.1.0 May 12, 2021

#70 in Video

Download history 1269/week @ 2024-01-30 1329/week @ 2024-02-06 1352/week @ 2024-02-13 1312/week @ 2024-02-20 1744/week @ 2024-02-27 1362/week @ 2024-03-05 1114/week @ 2024-03-12 749/week @ 2024-03-19 997/week @ 2024-03-26 1017/week @ 2024-04-02 1107/week @ 2024-04-09 902/week @ 2024-04-16 549/week @ 2024-04-23 453/week @ 2024-04-30 531/week @ 2024-05-07 711/week @ 2024-05-14

2,404 downloads per month
Used in 9 crates (3 directly)

MIT/Apache

14KB
257 lines

rfc6381-codec

Rust library for parsing and generating codec string values, as specified in RFC 6381, section 3.

crates.io version Documentation Coverage Status

Supported RFC 6381 features

  • avc1
  • mp4a only object-type-identifier 0x40 (MPEG 4 Audio) supported
  • other four-character-code values not supported
  • generic syntax including 'charset' and 'percent-encoding' not supported

lib.rs:

Support for codec parameter values

See also,

Basic usage

Parse a codec string,

let codec = Codec::from_str("avc1.4D401E");
if let Ok(Codec::Avc1(avc1)) = codec {
    assert_eq!(avc1.profile(), 0x4d);
} else {
    panic!("unexpected codec type");
}

Generate a codec string,

let codec = Codec::avc1(0x4d, 0x40, 0x1e);
assert_eq!(codec.to_string(), "avc1.4D401E")

No support for 'fancy' syntax

RFC 6381 specifies the following BNF grammar for general syntax, which this crate does not yet fully support:

  codecs      := cod-simple / cod-fancy
  cod-simple  := "codecs" "=" unencodedv
  unencodedv  := id-simple / simp-list
  simp-list   := DQUOTE id-simple *( "," id-simple ) DQUOTE
  id-simple   := element
              ; "." reserved as hierarchy delimiter
  element     := 1*octet-sim
  octet-sim   := <any TOKEN character>

              ; Within a 'codecs' parameter value, "." is reserved
              ; as a hierarchy delimiter
  cod-fancy   := "codecs*" "=" encodedv
  encodedv    := fancy-sing / fancy-list
  fancy-sing  := [charset] "'" [language] "'" id-encoded
              ; Parsers MAY ignore <language>
              ; Parsers MAY support only US-ASCII and UTF-8
  fancy-list  := DQUOTE [charset] "'" [language] "'" id-list DQUOTE
              ; Parsers MAY ignore <language>
              ; Parsers MAY support only US-ASCII and UTF-8
  id-list     := id-encoded *( "," id-encoded )
  id-encoded  := encoded-elm *( "." encoded-elm )
              ; "." reserved as hierarchy delimiter
  encoded-elm := 1*octet-fancy
  octet-fancy := ext-octet / attribute-char

  DQUOTE      := %x22 ; " (double quote)

In particular note the following productions:

  • cod-simple - specifies the attribute name+value structure codec=".." — this crate only supports dealing with the value of this attribute (the bit inside quotes).
  • cod-fancy (and related productions fancy-sing / fancy-list etc.) — show extended structures that can optionally specify a charset for the data like en-gb'UTF-8'%25%20xz or ''%25%20xz — this crate does not support values using these structures.

Dependencies

~195KB