--- a/media/libstagefright/binding/mp4parse_capi/src/lib.rs
+++ b/media/libstagefright/binding/mp4parse_capi/src/lib.rs
@@ -102,17 +102,17 @@ pub enum mp4parse_codec {
EC3,
}
impl Default for mp4parse_codec {
fn default() -> Self { mp4parse_codec::UNKNOWN }
}
#[repr(C)]
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct mp4parse_track_info {
pub track_type: mp4parse_track_type,
pub codec: mp4parse_codec,
pub track_id: u32,
pub duration: u64,
pub media_time: i64, // wants to be u64? understand how elst adjustment works
// TODO(kinetik): include crypto guff
}
@@ -124,16 +124,17 @@ pub struct mp4parse_indice {
pub end_offset: u64,
pub start_composition: i64,
pub end_composition: i64,
pub start_decode: i64,
pub sync: bool,
}
#[repr(C)]
+#[derive(Debug)]
pub struct mp4parse_byte_data {
pub length: u32,
// cheddar can't handle generic type, so it needs to be multiple data types here.
pub data: *const u8,
pub indices: *const mp4parse_indice,
}
impl Default for mp4parse_byte_data {
@@ -159,49 +160,49 @@ impl mp4parse_byte_data {
#[repr(C)]
#[derive(Default)]
pub struct mp4parse_pssh_info {
pub data: mp4parse_byte_data,
}
#[repr(C)]
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct mp4parse_sinf_info {
pub is_encrypted: u32,
pub iv_size: u8,
pub kid: mp4parse_byte_data,
}
#[repr(C)]
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct mp4parse_track_audio_info {
pub channels: u16,
pub bit_depth: u16,
pub sample_rate: u32,
pub profile: u16,
pub codec_specific_config: mp4parse_byte_data,
pub extra_data: mp4parse_byte_data,
pub protected_data: mp4parse_sinf_info,
}
#[repr(C)]
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct mp4parse_track_video_info {
pub display_width: u32,
pub display_height: u32,
pub image_width: u16,
pub image_height: u16,
pub rotation: u16,
pub extra_data: mp4parse_byte_data,
pub protected_data: mp4parse_sinf_info,
}
#[repr(C)]
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct mp4parse_fragment_info {
pub fragment_duration: u64,
// TODO:
// info in trex box.
}
// Even though mp4parse_parser is opaque to C, rusty-cheddar won't let us
// use more than one member, so we introduce *another* wrapper.
@@ -827,30 +828,33 @@ struct SampleToChunkIterator<'a> {
impl<'a> Iterator for SampleToChunkIterator<'a> {
type Item = (u32, u32);
fn next(&mut self) -> Option<(u32, u32)> {
let has_chunk = self.chunks.next()
.or_else(|| {
self.chunks = match (self.stsc_peek_iter.next(), self.stsc_peek_iter.peek()) {
- (Some(next), Some(peek)) => {
+ (Some(next), Some(peek)) if next.first_chunk > 0 && peek.first_chunk > 0 => {
self.sample_count = next.samples_per_chunk;
((next.first_chunk - 1) .. (peek.first_chunk - 1))
},
- (Some(next), None) => {
+ (Some(next), None) if next.first_chunk > 0 => {
self.sample_count = next.samples_per_chunk;
// Total chunk number in 'stsc' could be different to 'stco',
// there could be more chunks at the last 'stsc' record.
((next.first_chunk - 1) .. next.first_chunk + self.remain_chunk_count -1)
},
_ => (0 .. 0),
};
- self.remain_chunk_count -= self.chunks.len() as u32;
- self.chunks.next()
+
+ self.remain_chunk_count.checked_sub(self.chunks.len() as u32).and_then(|res| {
+ self.remain_chunk_count = res;
+ self.chunks.next()
+ })
});
has_chunk.map_or(None, |id| { Some((id, self.sample_count)) })
}
}
fn create_sample_table(track: &Track, track_offset_time: i64) -> Option<Vec<mp4parse_indice>> {
let timescale = match track.timescale {