From 4fc9a95a36e5b44aec3cffe1383da86f41ff6523 Mon Sep 17 00:00:00 2001 From: alfredoyang Date: Thu, 13 Apr 2017 14:44:15 +0800 Subject: [PATCH 1/2] remove empty_sample_boxes, fragmented file can be recoginzed from stsc, stco, and stts. --- mp4parse/src/lib.rs | 20 -------------------- mp4parse_capi/src/lib.rs | 16 +++++++++------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/mp4parse/src/lib.rs b/mp4parse/src/lib.rs index 4278bccb..653a62ca 100644 --- a/mp4parse/src/lib.rs +++ b/mp4parse/src/lib.rs @@ -437,22 +437,6 @@ impl std::ops::Add for TrackScaledTime where T: Num { } } -/// A fragmented file contains no sample data in stts, stsc, and stco. -#[derive(Debug, Default)] -pub struct EmptySampleTableBoxes { - // TODO: Track has stts, stsc and stco, this structure can be discarded. - pub empty_stts: bool, - pub empty_stsc: bool, - pub empty_stco: bool, -} - -/// Check boxes contain data. -impl EmptySampleTableBoxes { - pub fn all_empty(&self) -> bool { - self.empty_stts & self.empty_stsc & self.empty_stco - } -} - #[derive(Debug, Default)] pub struct Track { pub id: usize, @@ -463,7 +447,6 @@ pub struct Track { pub duration: Option>, pub track_id: Option, pub codec_type: CodecType, - pub empty_sample_boxes: EmptySampleTableBoxes, pub data: Option, pub tkhd: Option, // TODO(kinetik): find a nicer way to export this. pub stts: Option, @@ -892,13 +875,11 @@ fn read_stbl(f: &mut BMFFBox, track: &mut Track) -> Result<()> { BoxType::TimeToSampleBox => { let stts = read_stts(&mut b)?; log!("{:?}", stts); - track.empty_sample_boxes.empty_stts = stts.samples.is_empty(); track.stts = Some(stts); } BoxType::SampleToChunkBox => { let stsc = read_stsc(&mut b)?; log!("{:?}", stsc); - track.empty_sample_boxes.empty_stsc = stsc.samples.is_empty(); track.stsc = Some(stsc); } BoxType::SampleSizeBox => { @@ -908,7 +889,6 @@ fn read_stbl(f: &mut BMFFBox, track: &mut Track) -> Result<()> { } BoxType::ChunkOffsetBox => { let stco = read_stco(&mut b)?; - track.empty_sample_boxes.empty_stco = stco.offsets.is_empty(); log!("{:?}", stco); track.stco = Some(stco); } diff --git a/mp4parse_capi/src/lib.rs b/mp4parse_capi/src/lib.rs index e1a31ca8..dca7f480 100644 --- a/mp4parse_capi/src/lib.rs +++ b/mp4parse_capi/src/lib.rs @@ -1049,13 +1049,15 @@ pub unsafe extern fn mp4parse_is_fragmented(parser: *mut mp4parse_parser, track_ // check sample tables. let mut iter = tracks.iter(); - match iter.find(|track| track.track_id == Some(track_id)) { - Some(track) if track.empty_sample_boxes.all_empty() => (*fragmented) = true as u8, - Some(_) => {}, - None => return mp4parse_status::BAD_ARG, - } - - mp4parse_status::OK + iter.find(|track| track.track_id == Some(track_id)).map_or(mp4parse_status::BAD_ARG, |track| { + match (&track.stsc, &track.stco, &track.stts) { + (&Some(ref stsc), &Some(ref stco), &Some(ref stts)) if stsc.samples.is_empty() && + stco.offsets.is_empty() && + stts.samples.is_empty() => (*fragmented) = true as u8, + _ => {}, + }; + mp4parse_status::OK + }) } /// Get 'pssh' system id and 'pssh' box content for eme playback. From a9007e8871a5056ab23d8ff233dab468e2f17e8b Mon Sep 17 00:00:00 2001 From: alfredoyang Date: Mon, 17 Apr 2017 14:15:05 +0800 Subject: [PATCH 2/2] reformat the long match branch --- mp4parse_capi/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mp4parse_capi/src/lib.rs b/mp4parse_capi/src/lib.rs index dca7f480..632c32b9 100644 --- a/mp4parse_capi/src/lib.rs +++ b/mp4parse_capi/src/lib.rs @@ -1051,9 +1051,8 @@ pub unsafe extern fn mp4parse_is_fragmented(parser: *mut mp4parse_parser, track_ let mut iter = tracks.iter(); iter.find(|track| track.track_id == Some(track_id)).map_or(mp4parse_status::BAD_ARG, |track| { match (&track.stsc, &track.stco, &track.stts) { - (&Some(ref stsc), &Some(ref stco), &Some(ref stts)) if stsc.samples.is_empty() && - stco.offsets.is_empty() && - stts.samples.is_empty() => (*fragmented) = true as u8, + (&Some(ref stsc), &Some(ref stco), &Some(ref stts)) + if stsc.samples.is_empty() && stco.offsets.is_empty() && stts.samples.is_empty() => (*fragmented) = true as u8, _ => {}, }; mp4parse_status::OK