Bug 1378607 - update rust mp4 parser. r?kinetik
MozReview-Commit-ID: DzZsShTgik3
--- a/media/libstagefright/binding/mp4parse/src/lib.rs
+++ b/media/libstagefright/binding/mp4parse/src/lib.rs
@@ -1670,17 +1670,20 @@ fn read_video_sample_entry<T: Read>(src:
let name = src.get_header().name;
let codec_type = match name {
BoxType::AVCSampleEntry | BoxType::AVC3SampleEntry => CodecType::H264,
BoxType::MP4VideoSampleEntry => CodecType::MP4V,
BoxType::VP8SampleEntry => CodecType::VP8,
BoxType::VP9SampleEntry => CodecType::VP9,
BoxType::ProtectedVisualSampleEntry => CodecType::EncryptedVideo,
BoxType::JPEGAtom => CodecType::JPEG,
- _ => CodecType::Unknown,
+ _ => {
+ log!("Unsupported video codec, box {:?} found", name);
+ CodecType::Unknown
+ }
};
// Skip uninteresting fields.
skip(src, 6)?;
let data_reference_index = be_u16(src)?;
// Skip uninteresting fields.
@@ -1742,30 +1745,33 @@ fn read_video_sample_entry<T: Read>(src:
BoxType::ProtectionSchemeInformationBox => {
if name != BoxType::ProtectedVisualSampleEntry {
return Err(Error::InvalidData("malformed video sample entry"));
}
let sinf = read_sinf(&mut b)?;
log!("{:?} (sinf)", sinf);
protection_info.push(sinf);
}
- _ => skip_box_content(&mut b)?,
+ _ => {
+ log!("Unsupported video codec, box {:?} found", b.head.name);
+ skip_box_content(&mut b)?;
+ }
}
check_parser_state!(b.content);
}
- codec_specific
- .map(|codec_specific| (codec_type, SampleEntry::Video(VideoSampleEntry {
+ Ok(codec_specific.map_or((CodecType::Unknown, SampleEntry::Unknown),
+ |codec_specific| (codec_type, SampleEntry::Video(VideoSampleEntry {
data_reference_index: data_reference_index,
width: width,
height: height,
codec_specific: codec_specific,
protection_info: protection_info,
})))
- .ok_or_else(|| Error::InvalidData("malformed video sample entry"))
+ )
}
fn read_qt_wave_atom<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
let mut codec_specific = None;
let mut iter = src.box_iter();
while let Some(mut b) = iter.next_box()? {
match b.head.name {
BoxType::ESDBox => {
@@ -1884,31 +1890,34 @@ fn read_audio_sample_entry<T: Read>(src:
return Err(Error::InvalidData("malformed EC3 sample entry"));
}
// TODO: EC3SpecificBox needs to be parsed for detail information.
skip_box_remain(&mut b)?;
log!("(ec3)");
codec_type = CodecType::EC3;
codec_specific = Some(AudioCodecSpecific::EC3SpecificBox);
}
- _ => skip_box_content(&mut b)?,
+ _ => {
+ log!("Unsupported audio codec, box {:?} found", b.head.name);
+ skip_box_content(&mut b)?;
+ }
}
check_parser_state!(b.content);
}
- codec_specific
- .map(|codec_specific| (codec_type, SampleEntry::Audio(AudioSampleEntry {
+ Ok(codec_specific.map_or((CodecType::Unknown, SampleEntry::Unknown),
+ |codec_specific| (codec_type, SampleEntry::Audio(AudioSampleEntry {
data_reference_index: data_reference_index,
channelcount: channelcount,
samplesize: samplesize,
samplerate: samplerate,
codec_specific: codec_specific,
protection_info: protection_info,
})))
- .ok_or_else(|| Error::InvalidData("malformed audio sample entry"))
+ )
}
/// Parse a stsd box.
fn read_stsd<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) -> Result<SampleDescriptionBox> {
let (_, _) = read_fullbox_extra(src)?;
let description_count = be_u32(src)?;
let mut descriptions = Vec::new();
--- a/media/libstagefright/binding/mp4parse/src/tests.rs
+++ b/media/libstagefright/binding/mp4parse/src/tests.rs
@@ -1066,8 +1066,57 @@ fn jpeg_video_sample_entry() {
assert_eq!(jpeg.width, 1024);
} ,
_ => {},
}
},
_ => panic!("failed to parse a jpeg atom"),
}
}
+
+#[test]
+fn unknown_video_sample_entry() {
+ let unknown_codec = make_box(BoxSize::Auto, b"yyyy", |s| {
+ s.append_repeated(0, 16)
+ }).into_inner();
+ let mut stream = make_box(BoxSize::Auto, b"xxxx", |s| {
+ s.append_repeated(0, 6)
+ .B16(1)
+ .append_repeated(0, 16)
+ .B16(0)
+ .B16(0)
+ .append_repeated(0, 14)
+ .append_repeated(0, 32)
+ .append_repeated(0, 4)
+ .append_bytes(unknown_codec.as_slice())
+ });
+ let mut iter = super::BoxIter::new(&mut stream);
+ let mut stream = iter.next_box().unwrap().unwrap();
+ match super::read_video_sample_entry(&mut stream) {
+ Ok((super::CodecType::Unknown, super::SampleEntry::Unknown)) => (),
+ _ => panic!("expected a different error result"),
+ }
+}
+
+#[test]
+fn unknown_audio_sample_entry() {
+ let unknown_codec = make_box(BoxSize::Auto, b"yyyy", |s| {
+ s.append_repeated(0, 16)
+ }).into_inner();
+ let mut stream = make_box(BoxSize::Auto, b"xxxx", |s| {
+ s.append_repeated(0, 6)
+ .B16(1)
+ .B32(0)
+ .B32(0)
+ .B16(2)
+ .B16(16)
+ .B16(0)
+ .B16(0)
+ .B32(48000 << 16)
+ .append_bytes(unknown_codec.as_slice())
+ });
+ let mut iter = super::BoxIter::new(&mut stream);
+ let mut stream = iter.next_box().unwrap().unwrap();
+ match super::read_audio_sample_entry(&mut stream) {
+ Ok((super::CodecType::Unknown, super::SampleEntry::Unknown)) => (),
+ _ => panic!("expected a different error result"),
+ }
+}
--- a/media/libstagefright/binding/update-rust.sh
+++ b/media/libstagefright/binding/update-rust.sh
@@ -1,13 +1,13 @@
#!/bin/sh -e
# Script to update mp4parse-rust sources to latest upstream
# Default version.
-VER=ae58bb5063cde8018d51c1778a52392777ddb0d4
+VER=ce7e2e66613009d56aea2588c4d11a23d4dd8056
# Accept version or commit from the command line.
if test -n "$1"; then
VER=$1
fi
echo "Fetching sources..."
rm -rf _upstream