Skip to content

Commit

Permalink
Bug 1540748 - part1 : Android decoder should throw an error when the …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alastor0325 committed Apr 24, 2019
1 parent 6e8934b commit 4e04204
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion dom/media/platforms/android/RemoteDataDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,19 @@ class RemoteAudioDecoder : public RemoteDataDecoder {
return InitPromise::CreateAndResolve(TrackInfo::kAudioTrack, __func__);
}

RefPtr<FlushPromise> Flush() override {
mFirstDemuxedSampleTime.reset();
return RemoteDataDecoder::Flush();
}

RefPtr<DecodePromise> 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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -500,6 +518,7 @@ class RemoteAudioDecoder : public RemoteDataDecoder {

int32_t mOutputChannels;
int32_t mOutputSampleRate;
Maybe<TimeUnit> mFirstDemuxedSampleTime;
};

already_AddRefed<MediaDataDecoder> RemoteDataDecoder::CreateAudioDecoder(
Expand Down

0 comments on commit 4e04204

Please sign in to comment.