Skip to content

Commit f509579

Browse files
alfredoyangkinetiknz
authored andcommitted
check channelcounts in CSD (#40)
* check channelcounts in CSD * Fix channel count in test
1 parent c30d530 commit f509579

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

mp4parse/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ pub enum SampleEntry {
209209
pub struct ES_Descriptor {
210210
pub audio_codec: CodecType,
211211
pub audio_sample_rate: Option<u32>,
212+
pub audio_channel_count: Option<u16>,
212213
pub codec_specific_config: Vec<u8>,
213214
}
214215

@@ -1136,10 +1137,11 @@ fn read_esds<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
11361137
let esds_array = try!(read_buf(src, esds_size as usize));
11371138

11381139
// Parsing DecoderConfig descriptor to get the object_profile_indicator
1139-
// for correct codec type and audio sample rate.
1140-
let (object_profile_indicator, sample_frequency) = {
1140+
// for correct codec type, audio sample rate and channel counts.
1141+
let (object_profile_indicator, sample_frequency, channels) = {
11411142
let mut object_profile: u8 = 0;
11421143
let mut sample_frequency = None;
1144+
let mut channels = None;
11431145

11441146
// clone a esds cursor for parsing.
11451147
let esds = &mut Cursor::new(&esds_array);
@@ -1209,12 +1211,16 @@ fn read_esds<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
12091211

12101212
let sample_index = (audio_specific_config & 0x07FF) >> 7;
12111213

1214+
let channel_counts = (audio_specific_config & 0x007F) >> 3;
1215+
12121216
sample_frequency =
12131217
frequency_table.iter().find(|item| item.0 == sample_index).map(|x| x.1);
1218+
1219+
channels = Some(channel_counts);
12141220
}
12151221
}
12161222

1217-
(object_profile, sample_frequency)
1223+
(object_profile, sample_frequency, channels)
12181224
};
12191225

12201226
let codec = match object_profile_indicator {
@@ -1230,6 +1236,7 @@ fn read_esds<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
12301236
Ok(ES_Descriptor {
12311237
audio_codec: codec,
12321238
audio_sample_rate: sample_frequency,
1239+
audio_channel_count: channels,
12331240
codec_specific_config: esds_array,
12341241
})
12351242
}

mp4parse_capi/examples/test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void test_arg_validation_with_data(const std::string& filename)
166166
memset(&audio, 0, sizeof(audio));
167167
rv = mp4parse_get_track_audio_info(parser, 1, &audio);
168168
assert(rv == MP4PARSE_OK);
169-
assert(audio.channels == 2);
169+
assert(audio.channels == 1);
170170
assert(audio.bit_depth == 16);
171171
assert(audio.sample_rate == 48000);
172172

mp4parse_capi/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ pub unsafe extern fn mp4parse_get_track_audio_info(parser: *mut mp4parse_parser,
447447
if let Some(rate) = v.audio_sample_rate {
448448
(*info).sample_rate = rate;
449449
}
450+
if let Some(channels) = v.audio_channel_count {
451+
(*info).channels = channels;
452+
}
450453
}
451454
AudioCodecSpecific::FLACSpecificBox(ref flac) => {
452455
// Return the STREAMINFO metadata block in the codec_specific.
@@ -801,7 +804,7 @@ fn arg_validation_with_data() {
801804

802805
let mut audio = Default::default();
803806
assert_eq!(MP4PARSE_OK, mp4parse_get_track_audio_info(parser, 1, &mut audio));
804-
assert_eq!(audio.channels, 2);
807+
assert_eq!(audio.channels, 1);
805808
assert_eq!(audio.bit_depth, 16);
806809
assert_eq!(audio.sample_rate, 48000);
807810

0 commit comments

Comments
 (0)