From 93448dedd82d8416ecc69b5939c8df95ba1d750f Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Thu, 5 Dec 2024 12:49:28 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=84=E3=81=A3=E3=81=9F=E3=82=93=E3=83=87?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AF=E5=8B=95=E3=81=84=E3=81=9F?= =?UTF-8?q?=EF=BC=88=E3=82=B3=E3=83=BC=E3=83=89=E6=95=B4=E7=90=86=E5=89=8D?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boxes.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/src/boxes.rs b/src/boxes.rs index c7c81e6..69e33d9 100644 --- a/src/boxes.rs +++ b/src/boxes.rs @@ -4140,8 +4140,7 @@ pub struct DecoderConfigDescriptor { buffer_size_db: Uint, max_bitrate: u32, avg_bitrate: u32, - // dec_specific_info: (), // tag=DecSpecificInfoTag - // profile_level_indication_index_descr: (), + dec_specific_info: DecoderSpecificInfo, } impl Decode for DecoderConfigDescriptor { @@ -4177,6 +4176,7 @@ impl Decode for DecoderConfigDescriptor { let max_bitrate = u32::decode(&mut reader)?; let avg_bitrate = u32::decode(&mut reader)?; + let dec_specific_info = DecoderSpecificInfo::decode(&mut reader)?; Ok(Self { object_type_indication, stream_type, @@ -4184,10 +4184,78 @@ impl Decode for DecoderConfigDescriptor { buffer_size_db, max_bitrate, avg_bitrate, + dec_specific_info, }) } } +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[allow(missing_docs)] +pub struct DecoderSpecificInfo { + pub payload: Vec, +} + +impl Decode for DecoderSpecificInfo { + fn decode(mut reader: R) -> Result { + let tag = u8::decode(&mut reader)?; + if tag != 5 { + // 5 = DecSpecificInfoTag + return Err(Error::invalid_data(&format!( + "Unexpected descriptor tag: expected=5, actual={tag}" + ))); + } + + // TODO: + let mut size = 0; + let mut has_next_byte = true; + while has_next_byte { + let b = u8::decode(&mut reader)?; + has_next_byte = Uint::::from_bits(b).get() == 1; + size = (size << 7) | Uint::::from_bits(b).get() as usize + } + + let mut payload = vec![0; size]; + reader.read_exact(&mut payload)?; + + Ok(Self { payload }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[allow(missing_docs)] +pub struct SlConfigDescriptor { + pub payload: Vec, +} + +impl Decode for SlConfigDescriptor { + fn decode(mut reader: R) -> Result { + let tag = u8::decode(&mut reader)?; + if tag != 6 { + // 6 = SLConfigDescrTag + return Err(Error::invalid_data(&format!( + "Unexpected descriptor tag: expected=6, actual={tag}" + ))); + } + + // TODO: + let mut size = 0; + let mut has_next_byte = true; + while has_next_byte { + let b = u8::decode(&mut reader)?; + has_next_byte = Uint::::from_bits(b).get() == 1; + size = (size << 7) | Uint::::from_bits(b).get() as usize + } + dbg!(size); + + // TODO: + let mut payload = vec![0; size]; + reader.read_exact(&mut payload)?; + dbg!(&payload); + + Ok(Self { payload }) + } +} + /// [ISO/IEC 14496-14] ESDBox class #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[allow(missing_docs)] @@ -4198,6 +4266,7 @@ pub struct EsdsBox { pub url_string: Option, pub ocr_es_id: Option, pub dec_config_descr: DecoderConfigDescriptor, + pub sl_config_descr: SlConfigDescriptor, } impl EsdsBox { @@ -4262,13 +4331,12 @@ impl EsdsBox { .transpose()?; let dec_config_descr = DecoderConfigDescriptor::decode(&mut reader)?; - + let sl_config_descr = SlConfigDescriptor::decode(&mut reader)?; dbg!(es_id); dbg!(stream_priority); dbg!(&url_string); dbg!(ocr_es_id); dbg!(&dec_config_descr); - // 残りのフィールドは必要になるまでは未対応 Ok(Self { es_id, @@ -4277,6 +4345,7 @@ impl EsdsBox { url_string, ocr_es_id, dec_config_descr, + sl_config_descr, }) } }