Bug 1328221 - Support GASpecificConfig audio channel in rust mp4 parser. r=rillian

MozReview-Commit-ID: IQKxtjatU9J
This commit is contained in:
Alfredo.Yang
2017-01-11 09:03:30 +08:00
parent 87f0396711
commit ad92585014
23 changed files with 457 additions and 235 deletions

View File

@@ -161,6 +161,15 @@ impl<'a> BitReader<'a> {
Ok(value)
}
/// Read a single bit as a boolean value.
/// Interprets 1 as true and 0 as false.
pub fn read_bool(&mut self) -> Result<bool> {
match try!(self.read_value(1, 1)) {
0 => Ok(false),
_ => Ok(true),
}
}
/// Skip arbitrary number of bits. However, you can skip at most to the end of the byte slice.
pub fn skip(&mut self, bit_count: u64) -> Result<()> {
let end_position = self.position + bit_count;
@@ -283,24 +292,28 @@ impl fmt::Display for BitReaderError {
///
/// If you can't or want, for some reason, to use BitReader's read methods (`read_u8` etc.) but
/// want to rely on type inference instead, you can use the ReadInto trait. The trait is
/// implemented for all basic integer types (8/16/32/64 bits, signed/unsigned).
/// implemented for all basic integer types (8/16/32/64 bits, signed/unsigned)
/// and the boolean type.
///
/// ```
/// use bitreader::{BitReader,ReadInto};
///
/// let slice_of_u8 = &[0b1100_0000];
/// let slice_of_u8 = &[0b1110_0000];
/// let mut reader = BitReader::new(slice_of_u8);
///
/// struct Foo {
/// bar: u8
/// bar: u8,
/// valid: bool,
/// }
///
/// // No type mentioned here, instead the type of bits is inferred from the type of Foo::bar,
/// // and consequently the correct "overload" is used.
/// let bits = ReadInto::read(&mut reader, 2).unwrap();
/// let valid = ReadInto::read(&mut reader, 1).unwrap();
///
/// let foo = Foo { bar: bits };
/// assert_eq!(foo.bar, 3)
/// let foo = Foo { bar: bits, valid: valid };
/// assert_eq!(foo.bar, 3);
/// assert!(foo.valid);
/// ```
pub trait ReadInto
where Self: Sized
@@ -328,3 +341,13 @@ impl_read_into!(i8, read_i8);
impl_read_into!(i16, read_i16);
impl_read_into!(i32, read_i32);
impl_read_into!(i64, read_i64);
// We can't cast to bool, so this requires a separate method.
impl ReadInto for bool {
fn read(reader: &mut BitReader, bits: u8) -> Result<Self> {
match try!(reader.read_u8(bits)) {
0 => Ok(false),
_ => Ok(true),
}
}
}