Skip to content

Commit a96eabb

Browse files
author
alfredoyang
committed
address review comments
1 parent a1db061 commit a96eabb

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

mp4parse/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub struct AudioSampleEntry {
228228
pub samplesize: u16,
229229
pub samplerate: u32,
230230
pub codec_specific: AudioCodecSpecific,
231-
pub protect_info: Option<ProtectionSchemeInfoBox>,
231+
pub protection_info: Option<ProtectionSchemeInfoBox>,
232232
}
233233

234234
#[derive(Debug, Clone)]
@@ -243,7 +243,7 @@ pub struct VideoSampleEntry {
243243
pub width: u16,
244244
pub height: u16,
245245
pub codec_specific: VideoCodecSpecific,
246-
pub protect_info: Option<ProtectionSchemeInfoBox>,
246+
pub protection_info: Option<ProtectionSchemeInfoBox>,
247247
}
248248

249249
/// Represent a Video Partition Codec Configuration 'vpcC' box (aka vp9).
@@ -1491,7 +1491,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) ->
14911491

14921492
// Skip clap/pasp/etc. for now.
14931493
let mut codec_specific = None;
1494-
let mut protect_info = None;
1494+
let mut protection_info = None;
14951495
let mut iter = src.box_iter();
14961496
while let Some(mut b) = iter.next_box()? {
14971497
match b.head.name {
@@ -1526,7 +1526,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) ->
15261526
}
15271527
let sinf = read_sinf(&mut b)?;
15281528
log!("{:?} (sinf)", sinf);
1529-
protect_info = Some(sinf);
1529+
protection_info = Some(sinf);
15301530
}
15311531
_ => skip_box_content(&mut b)?,
15321532
}
@@ -1539,7 +1539,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) ->
15391539
width: width,
15401540
height: height,
15411541
codec_specific: codec_specific,
1542-
protect_info: protect_info,
1542+
protection_info: protection_info,
15431543
}))
15441544
.ok_or_else(|| Error::InvalidData("malformed video sample entry"))
15451545
}
@@ -1598,7 +1598,7 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) ->
15981598

15991599
// Skip chan/etc. for now.
16001600
let mut codec_specific = None;
1601-
let mut protect_info = None;
1601+
let mut protection_info = None;
16021602
let mut iter = src.box_iter();
16031603
while let Some(mut b) = iter.next_box()? {
16041604
match b.head.name {
@@ -1643,7 +1643,7 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) ->
16431643
let sinf = read_sinf(&mut b)?;
16441644
log!("{:?} (sinf)", sinf);
16451645
track.codec_type = CodecType::EncryptedAudio;
1646-
protect_info = Some(sinf);
1646+
protection_info = Some(sinf);
16471647
}
16481648
_ => skip_box_content(&mut b)?,
16491649
}
@@ -1657,7 +1657,7 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) ->
16571657
samplesize: samplesize,
16581658
samplerate: samplerate,
16591659
codec_specific: codec_specific,
1660-
protect_info: protect_info,
1660+
protection_info: protection_info,
16611661
}))
16621662
.ok_or_else(|| Error::InvalidData("malformed audio sample entry"))
16631663
}
@@ -1714,23 +1714,30 @@ fn read_stsd<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) -> Result<SampleD
17141714
fn read_sinf<T: Read>(src: &mut BMFFBox<T>) -> Result<ProtectionSchemeInfoBox> {
17151715
let mut sinf = ProtectionSchemeInfoBox::default();
17161716

1717+
let mut has_frma_schi_boxes = (false, false);
17171718
let mut iter = src.box_iter();
17181719
while let Some(mut b) = iter.next_box()? {
17191720
match b.head.name {
17201721
BoxType::OriginalFormatBox => {
17211722
let frma = read_frma(&mut b)?;
17221723
sinf.code_name = frma;
1724+
has_frma_schi_boxes.0 = true;
17231725
},
17241726
BoxType::SchemeInformationBox => {
17251727
// We only need tenc box in schi box so far.
17261728
let schi_tenc = read_schi(&mut b)?;
17271729
sinf.tenc = schi_tenc;
1730+
has_frma_schi_boxes.1 = true
17281731
},
17291732
_ => skip_box_content(&mut b)?,
17301733
}
17311734
check_parser_state!(b.content);
17321735
}
17331736

1737+
if has_frma_schi_boxes != (true, true) {
1738+
return Err(Error::InvalidData("malformat sinf box"));
1739+
}
1740+
17341741
Ok(sinf)
17351742
}
17361743

mp4parse/tests/public.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn public_audio_tenc() {
117117
assert_eq!(track.codec_type, mp4::CodecType::EncryptedAudio);
118118
match track.data {
119119
Some(mp4::SampleEntry::Audio(a)) => {
120-
match a.protect_info {
120+
match a.protection_info {
121121
Some(p) => {
122122
assert_eq!(p.code_name, "mp4a");
123123
assert!(p.tenc.is_encrypted > 0);
@@ -168,7 +168,7 @@ fn public_video_cenc() {
168168
assert_eq!(track.codec_type, mp4::CodecType::EncryptedVideo);
169169
match track.data {
170170
Some(mp4::SampleEntry::Video(v)) => {
171-
match v.protect_info {
171+
match v.protection_info {
172172
Some(p) => {
173173
assert_eq!(p.code_name, "avc1");
174174
assert!(p.tenc.is_encrypted > 0);

mp4parse_capi/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ pub unsafe extern fn mp4parse_get_track_audio_info(parser: *mut mp4parse_parser,
513513
}
514514
}
515515

516-
match audio.protect_info {
516+
match audio.protection_info {
517517
Some(ref protected) => {
518518
(*info).protected_data.is_encrypted = protected.tenc.is_encrypted;
519519
(*info).protected_data.iv_size = protected.tenc.iv_size;
@@ -571,7 +571,7 @@ pub unsafe extern fn mp4parse_get_track_video_info(parser: *mut mp4parse_parser,
571571
_ => {},
572572
}
573573

574-
match video.protect_info {
574+
match video.protection_info {
575575
Some(ref protected) => {
576576
(*info).protected_data.is_encrypted = protected.tenc.is_encrypted;
577577
(*info).protected_data.iv_size = protected.tenc.iv_size;

0 commit comments

Comments
 (0)