mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1487797 - Part 2: Make sure the time of audio data are monotonically increasing r=jya
Depends on D6425 Differential Revision: https://phabricator.services.mozilla.com/D6426 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ed8b8bf20c
commit
26daae07c7
@ -62,8 +62,9 @@ ReaderProxy::OnAudioDataRequestCompleted(RefPtr<AudioData> aAudio)
|
||||
int64_t offset =
|
||||
StartTime().ToMicroseconds() - mLoopingOffset.ToMicroseconds();
|
||||
aAudio->AdjustForStartTime(offset);
|
||||
if (aAudio->mTime.IsValid() && aAudio->GetEndTime().IsValid()) {
|
||||
mLastAudioEndTime = aAudio->GetEndTime();
|
||||
if (aAudio->mTime.IsValid() && aAudio->GetEndTime().IsValid() &&
|
||||
CorrectTimeOfAudioDataIfNeeded(aAudio)) {
|
||||
UpdateLastAudioEndTime(aAudio);
|
||||
return AudioDataPromise::CreateAndResolve(aAudio.forget(), __func__);
|
||||
}
|
||||
return AudioDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_OVERFLOW_ERR,
|
||||
@ -114,6 +115,28 @@ ReaderProxy::OnAudioDataRequestFailed(const MediaResult& aError)
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ReaderProxy::CorrectTimeOfAudioDataIfNeeded(const RefPtr<AudioData>& aAudio)
|
||||
{
|
||||
MOZ_ASSERT(aAudio->mTime.IsValid() && mLastAudioEndTime.IsValid());
|
||||
// The start time of the current audio data should be greater than the end
|
||||
// time of the previous audio data.
|
||||
if (aAudio->mTime < mLastAudioEndTime) {
|
||||
aAudio->mTime = mLastAudioEndTime;
|
||||
}
|
||||
return aAudio->GetEndTime().IsValid();
|
||||
}
|
||||
|
||||
void
|
||||
ReaderProxy::UpdateLastAudioEndTime(const AudioData* aAudio)
|
||||
{
|
||||
MOZ_ASSERT(aAudio);
|
||||
MOZ_ASSERT(aAudio->GetEndTime().IsValid() && mLastAudioEndTime.IsValid());
|
||||
// Make sure the end time of the audio data are non-decreasing.
|
||||
MOZ_ASSERT(aAudio->GetEndTime() >= mLastAudioEndTime);
|
||||
mLastAudioEndTime = aAudio->GetEndTime();
|
||||
}
|
||||
|
||||
RefPtr<ReaderProxy::AudioDataPromise>
|
||||
ReaderProxy::RequestAudioData()
|
||||
{
|
||||
|
@ -100,6 +100,12 @@ private:
|
||||
RefPtr<ReaderProxy::AudioDataPromise> OnAudioDataRequestFailed(
|
||||
const MediaResult& aError);
|
||||
|
||||
// Make sure the timestamp of the audio data increase monotonically by
|
||||
// adjusting it according to mLastAudioEndTime. Returns true if the
|
||||
// endtime is valid after correction and false otherwise.
|
||||
bool CorrectTimeOfAudioDataIfNeeded(const RefPtr<AudioData>& aAudio);
|
||||
void UpdateLastAudioEndTime(const AudioData* aAudio);
|
||||
|
||||
const RefPtr<AbstractThread> mOwnerThread;
|
||||
const RefPtr<MediaFormatReader> mReader;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user