Bug 1317609 - update rust mp4 parser to support avc extra data. r=kinetik

MozReview-Commit-ID: 7sWkDrXD8bs

--HG--
extra : rebase_source : cbee895e95f2c0f2ad3c06b03b65ab3c3ad6d34d
This commit is contained in:
Alfredo.Yang 2016-11-25 09:08:37 +08:00
Родитель 2160edf69f
Коммит f000f87291
5 изменённых файлов: 354 добавлений и 332 удалений

Просмотреть файл

@ -69,6 +69,7 @@ typedef struct mp4parse_track_video_info {
uint32_t display_height;
uint16_t image_width;
uint16_t image_height;
mp4parse_byte_data extra_data;
} mp4parse_track_video_info;
typedef struct mp4parse_fragment_info {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -148,8 +148,8 @@ fn read_truncated_ftyp() {
let mut context = MediaContext::new();
match read_mp4(&mut stream, &mut context) {
Err(Error::UnexpectedEOF) => (),
Ok(_) => assert!(false, "expected an error result"),
_ => assert!(false, "expected a different error result"),
Ok(_) => panic!("expected an error result"),
_ => panic!("expected a different error result"),
}
}
@ -593,8 +593,8 @@ fn serialize_opus_header() {
};
let mut v = Vec::<u8>::new();
super::serialize_opus_header(&opus, &mut v).unwrap();
assert!(v.len() == 19);
assert!(v == vec![
assert_eq!(v.len(), 19);
assert_eq!(v, vec![
0x4f, 0x70, 0x75, 0x73, 0x48,0x65, 0x61, 0x64,
0x01, 0x01, 0x56, 0x01,
0xc0, 0x5d, 0x00, 0x00,
@ -615,8 +615,8 @@ fn serialize_opus_header() {
};
let mut v = Vec::<u8>::new();
super::serialize_opus_header(&opus, &mut v).unwrap();
assert!(v.len() == 27);
assert!(v == vec![
assert_eq!(v.len(), 27);
assert_eq!(v, vec![
0x4f, 0x70, 0x75, 0x73, 0x48,0x65, 0x61, 0x64,
0x01, 0x06, 0x98, 0x00,
0x80, 0xbb, 0x00, 0x00,
@ -645,8 +645,8 @@ fn avcc_limit() {
let mut track = super::Track::new(0);
match super::read_video_sample_entry(&mut stream, &mut track) {
Err(Error::InvalidData(s)) => assert_eq!(s, "avcC box exceeds BUF_SIZE_LIMIT"),
Ok(_) => assert!(false, "expected an error result"),
_ => assert!(false, "expected a different error result"),
Ok(_) => panic!("expected an error result"),
_ => panic!("expected a different error result"),
}
}
@ -671,8 +671,8 @@ fn esds_limit() {
let mut track = super::Track::new(0);
match super::read_audio_sample_entry(&mut stream, &mut track) {
Err(Error::InvalidData(s)) => assert_eq!(s, "esds box exceeds BUF_SIZE_LIMIT"),
Ok(_) => assert!(false, "expected an error result"),
_ => assert!(false, "expected a different error result"),
Ok(_) => panic!("expected an error result"),
_ => panic!("expected a different error result"),
}
}
@ -697,8 +697,8 @@ fn esds_limit_2() {
let mut track = super::Track::new(0);
match super::read_audio_sample_entry(&mut stream, &mut track) {
Err(Error::UnexpectedEOF) => (),
Ok(_) => assert!(false, "expected an error result"),
_ => assert!(false, "expected a different error result"),
Ok(_) => panic!("expected an error result"),
_ => panic!("expected a different error result"),
}
}
@ -713,8 +713,8 @@ fn read_elst_zero_entries() {
let mut stream = iter.next_box().unwrap().unwrap();
match super::read_elst(&mut stream) {
Err(Error::InvalidData(s)) => assert_eq!(s, "invalid edit count"),
Ok(_) => assert!(false, "expected an error result"),
_ => assert!(false, "expected a different error result"),
Ok(_) => panic!("expected an error result"),
_ => panic!("expected a different error result"),
}
}
@ -741,8 +741,8 @@ fn read_edts_bogus() {
let mut track = super::Track::new(0);
match super::read_edts(&mut stream, &mut track) {
Err(Error::InvalidData(s)) => assert_eq!(s, "expected additional edit"),
Ok(_) => assert!(false, "expected an error result"),
_ => assert!(false, "expected a different error result"),
Ok(_) => panic!("expected an error result"),
_ => panic!("expected a different error result"),
}
}
@ -827,7 +827,7 @@ fn skip_padding_in_stsd() {
fn read_qt_wave_atom() {
let esds = make_fullbox(BoxSize::Auto, b"esds", 0, |s| {
s.B8(0x03) // elementary stream descriptor tag
.B8(0x0b) // esds length
.B8(0x12) // esds length
.append_repeated(0, 2)
.B8(0x00) // flags
.B8(0x04) // decoder config descriptor tag

Просмотреть файл

@ -78,8 +78,8 @@ fn public_api() {
mp4::AudioCodecSpecific::FLACSpecificBox(flac) => {
// STREAMINFO block must be present and first.
assert!(flac.blocks.len() > 0);
assert!(flac.blocks[0].block_type == 0);
assert!(flac.blocks[0].data.len() == 34);
assert_eq!(flac.blocks[0].block_type, 0);
assert_eq!(flac.blocks[0].data.len(), 34);
"FLAC"
}
mp4::AudioCodecSpecific::OpusSpecificBox(opus) => {

Просмотреть файл

@ -141,7 +141,7 @@ pub struct mp4parse_track_audio_info {
// TODO(kinetik):
// int32_t profile;
// int32_t extended_profile; // check types
codec_specific_config: mp4parse_byte_data,
pub codec_specific_config: mp4parse_byte_data,
}
#[repr(C)]
@ -150,9 +150,7 @@ pub struct mp4parse_track_video_info {
pub display_height: u32,
pub image_width: u16,
pub image_height: u16,
// TODO(kinetik):
// extra_data
// codec_specific_config
pub extra_data: mp4parse_byte_data,
}
#[repr(C)]
@ -336,7 +334,7 @@ fn media_time_to_us(time: MediaScaledTime, scale: MediaTimeScale) -> Option<u64>
}
fn track_time_to_us(time: TrackScaledTime, scale: TrackTimeScale) -> Option<u64> {
assert!(time.1 == scale.1);
assert_eq!(time.1, scale.1);
let microseconds_per_second = 1000000;
rational_scale(time.0, scale.0, microseconds_per_second)
}
@ -460,11 +458,11 @@ pub unsafe extern fn mp4parse_get_track_audio_info(parser: *mut mp4parse_parser,
match audio.codec_specific {
AudioCodecSpecific::ES_Descriptor(ref v) => {
if v.codec_specific_config.len() > std::u32::MAX as usize {
if v.codec_esds.len() > std::u32::MAX as usize {
return MP4PARSE_ERROR_INVALID;
}
(*info).codec_specific_config.length = v.codec_specific_config.len() as u32;
(*info).codec_specific_config.data = v.codec_specific_config.as_ptr();
(*info).codec_specific_config.length = v.codec_esds.len() as u32;
(*info).codec_specific_config.data = v.codec_esds.as_ptr();
if let Some(rate) = v.audio_sample_rate {
(*info).sample_rate = rate;
}
@ -547,6 +545,13 @@ pub unsafe extern fn mp4parse_get_track_video_info(parser: *mut mp4parse_parser,
(*info).image_width = video.width;
(*info).image_height = video.height;
match video.codec_specific {
VideoCodecSpecific::AVCConfig(ref avc) => {
(*info).extra_data.set_data(avc);
},
_ => {},
}
MP4PARSE_OK
}
@ -686,9 +691,9 @@ fn get_track_count_null_parser() {
unsafe {
let mut count: u32 = 0;
let rv = mp4parse_get_track_count(std::ptr::null(), std::ptr::null_mut());
assert!(rv == MP4PARSE_ERROR_BADARG);
assert_eq!(rv, MP4PARSE_ERROR_BADARG);
let rv = mp4parse_get_track_count(std::ptr::null(), &mut count);
assert!(rv == MP4PARSE_ERROR_BADARG);
assert_eq!(rv, MP4PARSE_ERROR_BADARG);
}
}
@ -737,6 +742,7 @@ fn arg_validation() {
display_height: 0,
image_width: 0,
image_height: 0,
extra_data: mp4parse_byte_data::default(),
};
assert_eq!(MP4PARSE_ERROR_BADARG, mp4parse_get_track_video_info(std::ptr::null_mut(), 0, &mut dummy_video));
@ -781,6 +787,7 @@ fn arg_validation_with_parser() {
display_height: 0,
image_width: 0,
image_height: 0,
extra_data: mp4parse_byte_data::default(),
};
assert_eq!(MP4PARSE_ERROR_BADARG, mp4parse_get_track_video_info(parser, 0, &mut dummy_video));
@ -807,7 +814,7 @@ fn get_track_count_poisoned_parser() {
let mut count: u32 = 0;
let rv = mp4parse_get_track_count(parser, &mut count);
assert!(rv == MP4PARSE_ERROR_BADARG);
assert_eq!(rv, MP4PARSE_ERROR_BADARG);
}
}
@ -852,6 +859,7 @@ fn arg_validation_with_data() {
display_height: 0,
image_width: 0,
image_height: 0,
extra_data: mp4parse_byte_data::default(),
};
assert_eq!(MP4PARSE_OK, mp4parse_get_track_video_info(parser, 0, &mut video));
assert_eq!(video.display_width, 320);
@ -883,7 +891,8 @@ fn arg_validation_with_data() {
let mut video = mp4parse_track_video_info { display_width: 0,
display_height: 0,
image_width: 0,
image_height: 0 };
image_height: 0,
extra_data: mp4parse_byte_data::default(),};
assert_eq!(MP4PARSE_ERROR_BADARG, mp4parse_get_track_video_info(parser, 3, &mut video));
assert_eq!(video.display_width, 0);
assert_eq!(video.display_height, 0);