Bug 1345756: [MSE] P4. Pre-roll AAC by 2112 audio frames. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 09 Mar 2017 10:57:02 +0100
changeset 495897 ea54ec0b2ad1176f5580e5621843fd8bc98e6c5b
parent 495896 efd170c0baed9e571d0e0938e14281a0d77cb1e8
child 548491 b6a25b7564f338ecaff891aeddcdf141eb737f37
push id48463
push userbmo:jyavenard@mozilla.com
push dateThu, 09 Mar 2017 13:06:11 +0000
reviewersgerald
bugs1345756
milestone55.0a1
Bug 1345756: [MSE] P4. Pre-roll AAC by 2112 audio frames. r?gerald MozReview-Commit-ID: K09DyZMzbY7
dom/media/mediasource/MediaSourceDemuxer.cpp
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -297,18 +297,25 @@ MediaSourceTrackDemuxer::MediaSourceTrac
                                                  TrackInfo::TrackType aType,
                                                  TrackBuffersManager* aManager)
   : mParent(aParent)
   , mManager(aManager)
   , mType(aType)
   , mMonitor("MediaSourceTrackDemuxer")
   , mReset(true)
   , mPreRoll(TimeUnit::FromMicroseconds(
-      OpusDataDecoder::IsOpus(mParent->GetTrackInfo(mType)->mMimeType) ? 80000
-                                                                       : 0))
+      OpusDataDecoder::IsOpus(mParent->GetTrackInfo(mType)->mMimeType)
+      ? 80000
+      : mParent->GetTrackInfo(mType)->mMimeType.EqualsLiteral("audio/mp4a-latm")
+        // AAC encoder delay is by default 2112 audio frames.
+        // See https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html
+        // So we always seek 2112 frames
+        ? (2112 * 1000000ULL
+           / mParent->GetTrackInfo(mType)->GetAsAudioInfo()->mRate)
+        : 0))
 {
 }
 
 UniquePtr<TrackInfo>
 MediaSourceTrackDemuxer::GetInfo() const
 {
   return mParent->GetTrackInfo(mType)->Clone();
 }