Bug 1290371 - handle files with audio and video tracks but no samples at all; r=jya draft
authorKaku Kuo <tkuo@mozilla.com>
Wed, 03 Aug 2016 16:51:29 +0800
changeset 396646 da6a1aec19827bb305fe210461169a9f18783195
parent 395624 6608e5864780589b25d5421c3d3673ab30c4c318
child 527258 1895f2e5c38482c8940c1a76c84b0bf39fa17ac6
push id25065
push usertkuo@mozilla.com
push dateThu, 04 Aug 2016 06:49:54 +0000
reviewersjya
bugs1290371
milestone51.0a1
Bug 1290371 - handle files with audio and video tracks but no samples at all; r=jya So, we have 4 boolean variables and here is the truth table. Case 1, 2, 3, 4, 7, 8, 10 and 12 are not possible to happen. Then, the remaining cases could be clustered into three categories: (1) Case 5, 9 and 13: no sample is demuxed at all, return 0. (2) Case 6, 11, 14 and 15: either audio or video is able to be demuxed, return the known value. (3) Case 15: both audio and video are demuxed, return the minimum of the values. For simplifying the logic, I will initialize the audioStartTime and videoStartTime to be INFINITY if we don't have the first-demuxed sample, otherwise, initialize them to be the real first-demuxed sample's time. Then, the final calculation will be: (1) Case 5, 9 and 13: the minimum of two INFINITY values is still INFINITY, return 0. (2) Case 6, 11, 14 and 15: return the minimum of one real first-demuxed-time and the INFINITY. (3) Case 15: return the minimum of two real first-demuxed-time values. Case HasAudio HasVideo HasAudioSample HasVideoSample ExpectedResult --------------------------------------------------------------------------------------------------- 1 F F F F not possible 2 F F F T not possible 3 F F T F not possible 4 F F T T not possible --------------------------------------------------------------------------------------------------- 5 F T F F return 0 6 F T F T return video sample 7 F T T F not possible 8 F T T T not possible --------------------------------------------------------------------------------------------------- 9 T F F F return 0 10 T F F T not possible 11 T F T F return audio sample 12 T F T T not possible --------------------------------------------------------------------------------------------------- 13 T T F F return 0 14 T T F T return videoSample 15 T T T F return audioSample 16 T T T T return min(auidoSample, videoSample) MozReview-Commit-ID: ANsYDth7slJ
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1647,25 +1647,23 @@ MediaFormatReader::SetSeekTarget(const S
   mFallbackSeekTime = mPendingSeekTime = Some(target.GetTime());
 }
 
 TimeUnit
 MediaFormatReader::DemuxStartTime()
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(!ForceZeroStartTime());
-  MOZ_ASSERT((!HasAudio() || mAudio.mFirstDemuxedSampleTime.isSome()) &&
-             (!HasVideo() || mVideo.mFirstDemuxedSampleTime.isSome()));
+  MOZ_ASSERT(HasAudio() || HasVideo());
 
-  return std::min(HasAudio()
-                  ? mAudio.mFirstDemuxedSampleTime.ref()
-                  : TimeUnit::FromInfinity(),
-                  HasVideo()
-                  ? mVideo.mFirstDemuxedSampleTime.ref()
-                  : TimeUnit::FromInfinity());
+  const TimeUnit startTime =
+    std::min(mAudio.mFirstDemuxedSampleTime.refOr(TimeUnit::FromInfinity()),
+             mVideo.mFirstDemuxedSampleTime.refOr(TimeUnit::FromInfinity()));
+
+  return startTime.IsInfinite() ? TimeUnit::FromMicroseconds(0) : startTime;
 }
 
 void
 MediaFormatReader::ScheduleSeek()
 {
   if (mSeekScheduled) {
     return;
   }