Skip to content

Commit 6cd06d4

Browse files
alfredoyangkinetiknz
alfredoyang
authored andcommitted
get audio codec specific data (#79)
* add audio codec specific data * assert if decoder_specific_data is not empty
1 parent 9d91141 commit 6cd06d4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

mp4parse/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub struct ES_Descriptor {
238238
pub audio_sample_rate: Option<u32>,
239239
pub audio_channel_count: Option<u16>,
240240
pub codec_esds: Vec<u8>,
241+
pub decoder_specific_data: Vec<u8>, // Data in DECODER_SPECIFIC_TAG
241242
}
242243

243244
#[allow(non_camel_case_types)]
@@ -1412,6 +1413,8 @@ fn read_ds_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
14121413
esds.audio_object_type = Some(audio_object_type);
14131414
esds.audio_sample_rate = sample_frequency;
14141415
esds.audio_channel_count = Some(channel_counts);
1416+
assert!(esds.decoder_specific_data.is_empty());
1417+
esds.decoder_specific_data.extend(data.iter());
14151418

14161419
Ok(())
14171420
}

mp4parse/src/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,8 @@ fn read_esds() {
863863
0x05, 0x88, 0x05, 0x00, 0x48, 0x21, 0x10, 0x00,
864864
0x56, 0xe5, 0x98, 0x06, 0x01, 0x02,
865865
];
866+
let aac_dc_descriptor = &aac_esds[22 .. 35];
867+
866868
let mut stream = make_box(BoxSize::Auto, b"esds", |s| {
867869
s.B32(0) // reserved
868870
.append_bytes(aac_esds.as_slice())
@@ -877,6 +879,7 @@ fn read_esds() {
877879
assert_eq!(es.audio_sample_rate, Some(24000));
878880
assert_eq!(es.audio_channel_count, Some(6));
879881
assert_eq!(es.codec_esds, aac_esds);
882+
assert_eq!(es.decoder_specific_data, aac_dc_descriptor);
880883
}
881884

882885
#[test]

mp4parse_capi/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ pub struct mp4parse_track_audio_info {
178178
pub bit_depth: u16,
179179
pub sample_rate: u32,
180180
pub profile: u16,
181+
// TODO:
182+
// codec_specific_data is AudioInfo.mCodecSpecificConfig,
183+
// codec_specific_config is AudioInfo.mExtraData.
184+
// It'd be better to change name same as AudioInfo.
185+
pub codec_specific_data: mp4parse_byte_data,
181186
pub codec_specific_config: mp4parse_byte_data,
182187
pub protected_data: mp4parse_sinf_info,
183188
}
@@ -525,6 +530,8 @@ pub unsafe extern fn mp4parse_get_track_audio_info(parser: *mut mp4parse_parser,
525530
}
526531
(*info).codec_specific_config.length = v.codec_esds.len() as u32;
527532
(*info).codec_specific_config.data = v.codec_esds.as_ptr();
533+
(*info).codec_specific_data.length = v.decoder_specific_data.len() as u32;
534+
(*info).codec_specific_data.data = v.decoder_specific_data.as_ptr();
528535
if let Some(rate) = v.audio_sample_rate {
529536
(*info).sample_rate = rate;
530537
}

0 commit comments

Comments
 (0)