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

#153 in Video

Download history 357/week @ 2024-08-20 376/week @ 2024-08-27 309/week @ 2024-09-03 361/week @ 2024-09-10 341/week @ 2024-09-17 408/week @ 2024-09-24 446/week @ 2024-10-01 461/week @ 2024-10-08 441/week @ 2024-10-15 612/week @ 2024-10-22 676/week @ 2024-10-29 644/week @ 2024-11-05 444/week @ 2024-11-12 403/week @ 2024-11-19 964/week @ 2024-11-26 1064/week @ 2024-12-03

3,002 downloads per month
Used in 12 crates (2 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