Bug 1482706 - Pre-roll seek by 2112 frames to account for encoder delay. r=kinetik

Differential Revision: https://phabricator.services.mozilla.com/D3485

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2019-01-28 08:15:32 +00:00
parent a98680f98b
commit 92877ec9a4
2 changed files with 12 additions and 2 deletions

View File

@ -337,6 +337,10 @@ bool ADTSTrackDemuxer::Init() {
mInfo->mRate, mInfo->mChannels, mInfo->mBitDepth,
mInfo->mDuration.ToMicroseconds());
// 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 prior the seeking point.
mPreRoll = TimeUnit::FromMicroseconds(2112 * 1000000ULL / mSamplesPerSecond);
return mSamplesPerSecond && mChannels;
}
@ -347,9 +351,10 @@ UniquePtr<TrackInfo> ADTSTrackDemuxer::GetInfo() const {
RefPtr<ADTSTrackDemuxer::SeekPromise> ADTSTrackDemuxer::Seek(
const TimeUnit& aTime) {
// Efficiently seek to the position.
FastSeek(aTime);
const TimeUnit time = aTime > mPreRoll ? aTime - mPreRoll : TimeUnit::Zero();
FastSeek(time);
// Correct seek position by scanning the next frames.
const TimeUnit seekTime = ScanUntil(aTime);
const TimeUnit seekTime = ScanUntil(time);
return SeekPromise::CreateAndResolve(seekTime, __func__);
}

View File

@ -141,6 +141,11 @@ class ADTSTrackDemuxer : public MediaTrackDemuxer,
// Audio track config info.
UniquePtr<AudioInfo> mInfo;
// Amount of pre-roll time when seeking.
// AAC encoder delay is by default 2112 audio frames.
media::TimeUnit mPreRoll;
};
} // namespace mozilla