mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-05-19 16:58:04 +00:00
mp4a: Make Descriptor::desc_size non-static
Descriptions may require different amount of bytes to serialize depending on content of fields. In preparation of supporing reading and writing DecoderSpecificDescriptor::profiles (audio object type) values larger than 30.
This commit is contained in:
parent
35560e94f5
commit
32674a6855
|
@ -181,11 +181,12 @@ impl Mp4Box for EsdsBox {
|
|||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let es_desc_size = self.es_desc.desc_size();
|
||||
HEADER_SIZE
|
||||
+ HEADER_EXT_SIZE
|
||||
+ 1
|
||||
+ size_of_length(ESDescriptor::desc_size()) as u64
|
||||
+ ESDescriptor::desc_size() as u64
|
||||
+ size_of_length(es_desc_size) as u64
|
||||
+ es_desc_size as u64
|
||||
}
|
||||
|
||||
fn to_json(&self) -> Result<String> {
|
||||
|
@ -247,7 +248,7 @@ impl<W: Write> WriteBox<&mut W> for EsdsBox {
|
|||
|
||||
trait Descriptor: Sized {
|
||||
fn desc_tag() -> u8;
|
||||
fn desc_size() -> u32;
|
||||
fn desc_size(&self) -> u32;
|
||||
}
|
||||
|
||||
trait ReadDesc<T>: Sized {
|
||||
|
@ -325,13 +326,15 @@ impl Descriptor for ESDescriptor {
|
|||
0x03
|
||||
}
|
||||
|
||||
fn desc_size() -> u32 {
|
||||
fn desc_size(&self) -> u32 {
|
||||
let dec_config_size = self.dec_config.desc_size();
|
||||
let sl_config_size = self.sl_config.desc_size();
|
||||
3 + 1
|
||||
+ size_of_length(DecoderConfigDescriptor::desc_size())
|
||||
+ DecoderConfigDescriptor::desc_size()
|
||||
+ size_of_length(dec_config_size)
|
||||
+ dec_config_size
|
||||
+ 1
|
||||
+ size_of_length(SLConfigDescriptor::desc_size())
|
||||
+ SLConfigDescriptor::desc_size()
|
||||
+ size_of_length(sl_config_size)
|
||||
+ sl_config_size
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +376,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for ESDescriptor {
|
|||
|
||||
impl<W: Write> WriteDesc<&mut W> for ESDescriptor {
|
||||
fn write_desc(&self, writer: &mut W) -> Result<u32> {
|
||||
let size = Self::desc_size();
|
||||
let size = self.desc_size();
|
||||
write_desc(writer, Self::desc_tag(), size)?;
|
||||
|
||||
writer.write_u16::<BigEndian>(self.es_id)?;
|
||||
|
@ -417,10 +420,9 @@ impl Descriptor for DecoderConfigDescriptor {
|
|||
0x04
|
||||
}
|
||||
|
||||
fn desc_size() -> u32 {
|
||||
13 + 1
|
||||
+ size_of_length(DecoderSpecificDescriptor::desc_size())
|
||||
+ DecoderSpecificDescriptor::desc_size()
|
||||
fn desc_size(&self) -> u32 {
|
||||
let dec_specific_size = self.dec_specific.desc_size();
|
||||
13 + 1 + size_of_length(dec_specific_size) + dec_specific_size
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -467,7 +469,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for DecoderConfigDescriptor {
|
|||
|
||||
impl<W: Write> WriteDesc<&mut W> for DecoderConfigDescriptor {
|
||||
fn write_desc(&self, writer: &mut W) -> Result<u32> {
|
||||
let size = Self::desc_size();
|
||||
let size = self.desc_size();
|
||||
write_desc(writer, Self::desc_tag(), size)?;
|
||||
|
||||
writer.write_u8(self.object_type_indication)?;
|
||||
|
@ -504,7 +506,7 @@ impl Descriptor for DecoderSpecificDescriptor {
|
|||
0x05
|
||||
}
|
||||
|
||||
fn desc_size() -> u32 {
|
||||
fn desc_size(&self) -> u32 {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +566,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for DecoderSpecificDescriptor {
|
|||
|
||||
impl<W: Write> WriteDesc<&mut W> for DecoderSpecificDescriptor {
|
||||
fn write_desc(&self, writer: &mut W) -> Result<u32> {
|
||||
let size = Self::desc_size();
|
||||
let size = self.desc_size();
|
||||
write_desc(writer, Self::desc_tag(), size)?;
|
||||
|
||||
writer.write_u8((self.profile << 3) + (self.freq_index >> 1))?;
|
||||
|
@ -588,7 +590,7 @@ impl Descriptor for SLConfigDescriptor {
|
|||
0x06
|
||||
}
|
||||
|
||||
fn desc_size() -> u32 {
|
||||
fn desc_size(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
@ -603,7 +605,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for SLConfigDescriptor {
|
|||
|
||||
impl<W: Write> WriteDesc<&mut W> for SLConfigDescriptor {
|
||||
fn write_desc(&self, writer: &mut W) -> Result<u32> {
|
||||
let size = Self::desc_size();
|
||||
let size = self.desc_size();
|
||||
write_desc(writer, Self::desc_tag(), size)?;
|
||||
|
||||
writer.write_u8(2)?; // pre-defined
|
||||
|
|
Loading…
Reference in a new issue