Bug 1417300 - store mDecodedAudioDuration before adjusting sample time. draft
authorAlastor Wu <alwu@mozilla.com>
Mon, 11 Dec 2017 00:03:51 +0800
changeset 710484 4b20e20b756a987617dbeb216191637eb6bd5356
parent 709416 457b0fe91e0d49a5bc35014fb6f86729cd5bac9b
child 710903 755ff90033094707898b86caf1f66c7f2479a2ac
push id92831
push useralwu@mozilla.com
push dateSun, 10 Dec 2017 16:04:15 +0000
bugs1417300
milestone59.0a1
Bug 1417300 - store mDecodedAudioDuration before adjusting sample time. mDecodedAudioDuration should only save unadjusted timestamp, or it would cause next adjustment to be incorrect. MozReview-Commit-ID: 7grtYs075p0
dom/media/ogg/OggDemuxer.cpp
--- a/dom/media/ogg/OggDemuxer.cpp
+++ b/dom/media/ogg/OggDemuxer.cpp
@@ -1351,27 +1351,26 @@ OggTrackDemuxer::NextSample()
   OggCodecState* state = mParent->GetTrackCodecState(mType);
   RefPtr<MediaRawData> data = state->PacketOutAsMediaRawData();
   if (!data) {
     return nullptr;
   }
   if (mType == TrackInfo::kAudioTrack) {
     data->mTrackInfo = mParent->mSharedAudioTrackInfo;
   }
-  // We do not want to perform the adjustment of the timestamp after reading
-  // the ogg chain but before. Otherwise the parent's mDecodedAudioDuration
-  // would be adjusted causing the sample's time to be twice the value it
-  // should be.
-  data->mTime += mParent->mDecodedAudioDuration;
+  // mDecodedAudioDuration gets adjusted during ReadOggChain().
+  TimeUnit totalDuration = mParent->mDecodedAudioDuration;
   if (eos) {
     // We've encountered an end of bitstream packet; check for a chained
     // bitstream following this one.
     // This will also update mSharedAudioTrackInfo.
     mParent->ReadOggChain(data->GetEndTime());
   }
+  // We adjust the start time of the sample to account for the potential ogg chaining.
+  data->mTime += totalDuration;
   return data;
 }
 
 RefPtr<OggTrackDemuxer::SamplesPromise>
 OggTrackDemuxer::GetSamples(int32_t aNumSamples)
 {
   RefPtr<SamplesHolder> samples = new SamplesHolder;
   if (!aNumSamples) {