#codec #parser-generator #values #rfc #section #string #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

#78 in Video

Download history 342/week @ 2023-12-23 580/week @ 2023-12-30 886/week @ 2024-01-06 834/week @ 2024-01-13 1701/week @ 2024-01-20 1611/week @ 2024-01-27 1099/week @ 2024-02-03 1302/week @ 2024-02-10 1649/week @ 2024-02-17 1559/week @ 2024-02-24 1592/week @ 2024-03-02 848/week @ 2024-03-09 978/week @ 2024-03-16 911/week @ 2024-03-23 1090/week @ 2024-03-30 890/week @ 2024-04-06

4,004 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