From 4e0420416fcb5ef59557ac3e12dc308af8efcfa4 Mon Sep 17 00:00:00 2001 From: Alastor Wu Date: Wed, 24 Apr 2019 15:16:58 +0000 Subject: [PATCH] Bug 1540748 - part1 : Android decoder should throw an error when the decoded sample's time is smaller than the time of first demuxed sample. r=jolin Considering that the audio sample's time is always increased, the decoded sample's time decoder returns should always be equal or larger than its demuxed time. When the decoded sample's time is smaller than the time of first demuxed sample, that time would probably cause a problem so we should throw an error for that. Differential Revision: https://phabricator.services.mozilla.com/D28167 --HG-- extra : moz-landing-system : lando --- .../platforms/android/RemoteDataDecoder.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/dom/media/platforms/android/RemoteDataDecoder.cpp b/dom/media/platforms/android/RemoteDataDecoder.cpp index e1e3851b040e..568cd83c9d6e 100644 --- a/dom/media/platforms/android/RemoteDataDecoder.cpp +++ b/dom/media/platforms/android/RemoteDataDecoder.cpp @@ -364,6 +364,19 @@ class RemoteAudioDecoder : public RemoteDataDecoder { return InitPromise::CreateAndResolve(TrackInfo::kAudioTrack, __func__); } + RefPtr Flush() override { + mFirstDemuxedSampleTime.reset(); + return RemoteDataDecoder::Flush(); + } + + RefPtr Decode(MediaRawData* aSample) override { + if (mFirstDemuxedSampleTime.isNothing()) { + MOZ_ASSERT(aSample->mTime.IsValid()); + mFirstDemuxedSampleTime.emplace(aSample->mTime); + } + return RemoteDataDecoder::Decode(aSample); + } + private: class CallbacksSupport final : public JavaCallbacksSupport { public: @@ -408,6 +421,10 @@ class RemoteAudioDecoder : public RemoteDataDecoder { RemoteAudioDecoder* mDecoder; }; + bool IsSampleTimeSmallerThanFirstDemuxedSampleTime(int64_t aTime) const { + return TimeUnit::FromMicroseconds(aTime) < mFirstDemuxedSampleTime.ref(); + } + // Param and LocalRef are only valid for the duration of a JNI method call. // Use GlobalRef as the parameter type to keep the Java object referenced // until running. @@ -448,7 +465,8 @@ class RemoteAudioDecoder : public RemoteDataDecoder { int32_t size; ok &= NS_SUCCEEDED(info->Size(&size)); - if (!ok) { + if (!ok || + IsSampleTimeSmallerThanFirstDemuxedSampleTime(presentationTimeUs)) { Error(MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__)); return; } @@ -500,6 +518,7 @@ class RemoteAudioDecoder : public RemoteDataDecoder { int32_t mOutputChannels; int32_t mOutputSampleRate; + Maybe mFirstDemuxedSampleTime; }; already_AddRefed RemoteDataDecoder::CreateAudioDecoder(