2015-05-18 05:40:32 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#if !defined(MediaFormatReader_h_)
|
|
|
|
#define MediaFormatReader_h_
|
|
|
|
|
2015-05-18 05:42:01 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2015-05-18 05:40:32 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-07-16 18:52:43 +00:00
|
|
|
#include "mozilla/TaskQueue.h"
|
2016-01-22 03:01:50 +00:00
|
|
|
#include "mozilla/Monitor.h"
|
2015-07-16 18:52:43 +00:00
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
#include "MediaDataDemuxer.h"
|
|
|
|
#include "MediaDecoderReader.h"
|
2016-06-07 20:10:18 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2015-10-06 08:56:29 +00:00
|
|
|
#include "PDMFactory.h"
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-09-27 10:40:03 +00:00
|
|
|
class CDMProxy;
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
class MediaFormatReader final : public MediaDecoderReader
|
|
|
|
{
|
|
|
|
typedef TrackInfo::TrackType TrackType;
|
|
|
|
|
|
|
|
public:
|
2015-10-15 00:04:00 +00:00
|
|
|
MediaFormatReader(AbstractMediaDecoder* aDecoder,
|
|
|
|
MediaDataDemuxer* aDemuxer,
|
|
|
|
VideoFrameContainer* aVideoFrameContainer = nullptr,
|
|
|
|
layers::LayersBackend aLayersBackend = layers::LayersBackend::LAYERS_NONE);
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
virtual ~MediaFormatReader();
|
|
|
|
|
2015-10-13 07:28:57 +00:00
|
|
|
nsresult Init() override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-06-11 23:26:58 +00:00
|
|
|
size_t SizeOfVideoQueueInFrames() override;
|
|
|
|
size_t SizeOfAudioQueueInFrames() override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2016-04-22 06:16:49 +00:00
|
|
|
RefPtr<MediaDataPromise>
|
2015-08-24 01:32:49 +00:00
|
|
|
RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThreshold) override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2016-04-22 06:16:49 +00:00
|
|
|
RefPtr<MediaDataPromise> RequestAudioData() override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-10-21 02:59:56 +00:00
|
|
|
RefPtr<MetadataPromise> AsyncReadMetadata() override;
|
|
|
|
|
2015-06-11 23:26:58 +00:00
|
|
|
void ReadUpdatedMetadata(MediaInfo* aInfo) override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SeekPromise>
|
2016-02-01 04:05:25 +00:00
|
|
|
Seek(SeekTarget aTarget, int64_t aUnused) override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-06-16 22:37:48 +00:00
|
|
|
protected:
|
2015-11-02 13:28:57 +00:00
|
|
|
void NotifyDataArrivedInternal() override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-10-26 06:10:29 +00:00
|
|
|
public:
|
2015-06-11 23:26:58 +00:00
|
|
|
media::TimeIntervals GetBuffered() override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2016-03-09 02:32:49 +00:00
|
|
|
RefPtr<BufferedUpdatePromise> UpdateBufferedWithPromise() override;
|
|
|
|
|
2016-01-18 03:50:29 +00:00
|
|
|
bool ForceZeroStartTime() const override;
|
2015-06-06 21:42:40 +00:00
|
|
|
|
2015-10-21 06:04:20 +00:00
|
|
|
// For Media Resource Management
|
|
|
|
void ReleaseMediaResources() override;
|
|
|
|
|
2016-05-31 04:32:37 +00:00
|
|
|
nsresult ResetDecode(TrackSet aTracks) override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ShutdownPromise> Shutdown() override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-06-11 23:26:58 +00:00
|
|
|
bool IsAsync() const override { return true; }
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-06-11 23:26:58 +00:00
|
|
|
bool VideoIsHardwareAccelerated() const override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2016-04-19 08:14:33 +00:00
|
|
|
bool IsWaitForDataSupported() const override { return true; }
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType) override;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-10-20 09:33:00 +00:00
|
|
|
// MediaFormatReader supports demuxed-only mode.
|
|
|
|
bool IsDemuxOnlySupported() const override { return true; }
|
|
|
|
|
|
|
|
void SetDemuxOnly(bool aDemuxedOnly) override
|
|
|
|
{
|
|
|
|
if (OnTaskQueue()) {
|
|
|
|
mDemuxOnly = aDemuxedOnly;
|
|
|
|
return;
|
|
|
|
}
|
2016-05-05 08:45:00 +00:00
|
|
|
nsCOMPtr<nsIRunnable> r = NewRunnableMethod<bool>(
|
2015-10-20 09:33:00 +00:00
|
|
|
this, &MediaDecoderReader::SetDemuxOnly, aDemuxedOnly);
|
|
|
|
OwnerThread()->Dispatch(r.forget());
|
|
|
|
}
|
|
|
|
|
2016-04-19 08:14:33 +00:00
|
|
|
bool UseBufferingHeuristics() const override
|
2015-06-11 23:26:58 +00:00
|
|
|
{
|
|
|
|
return mTrackDemuxersMayBlock;
|
|
|
|
}
|
|
|
|
|
2015-09-27 10:40:03 +00:00
|
|
|
#ifdef MOZ_EME
|
|
|
|
void SetCDMProxy(CDMProxy* aProxy) override;
|
|
|
|
#endif
|
|
|
|
|
2016-01-17 23:21:59 +00:00
|
|
|
// Returns a string describing the state of the decoder data.
|
|
|
|
// Used for debugging purposes.
|
|
|
|
void GetMozDebugReaderData(nsAString& aString);
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
private:
|
2016-06-08 12:28:24 +00:00
|
|
|
|
2015-10-26 06:10:29 +00:00
|
|
|
bool HasVideo() { return mVideo.mTrackDemuxer; }
|
|
|
|
bool HasAudio() { return mAudio.mTrackDemuxer; }
|
|
|
|
|
2015-09-27 10:59:52 +00:00
|
|
|
bool IsWaitingOnCDMResource();
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
bool InitDemuxer();
|
2015-05-25 05:09:16 +00:00
|
|
|
// Notify the demuxer that new data has been received.
|
|
|
|
// The next queued task calling GetBuffered() is guaranteed to have up to date
|
|
|
|
// buffered ranges.
|
2015-11-02 13:28:57 +00:00
|
|
|
void NotifyDemuxer();
|
2015-05-18 05:40:32 +00:00
|
|
|
void ReturnOutput(MediaData* aData, TrackType aTrack);
|
|
|
|
|
2015-11-21 11:18:45 +00:00
|
|
|
bool EnsureDecoderCreated(TrackType aTrack);
|
2015-09-30 04:35:11 +00:00
|
|
|
bool EnsureDecoderInitialized(TrackType aTrack);
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
// Enqueues a task to call Update(aTrack) on the decoder task queue.
|
|
|
|
// Lock for corresponding track must be held.
|
|
|
|
void ScheduleUpdate(TrackType aTrack);
|
|
|
|
void Update(TrackType aTrack);
|
|
|
|
// Handle actions should more data be received.
|
|
|
|
// Returns true if no more action is required.
|
|
|
|
bool UpdateReceivedNewData(TrackType aTrack);
|
|
|
|
// Called when new samples need to be demuxed.
|
|
|
|
void RequestDemuxSamples(TrackType aTrack);
|
2015-10-20 09:33:00 +00:00
|
|
|
// Handle demuxed samples by the input behavior.
|
|
|
|
void HandleDemuxedSamples(TrackType aTrack,
|
2015-05-18 05:40:32 +00:00
|
|
|
AbstractMediaDecoder::AutoNotifyDecoded& aA);
|
2015-10-20 09:33:00 +00:00
|
|
|
// Decode any pending already demuxed samples.
|
|
|
|
bool DecodeDemuxedSamples(TrackType aTrack,
|
|
|
|
MediaRawData* aSample);
|
2015-12-08 19:30:25 +00:00
|
|
|
|
2016-02-01 04:05:25 +00:00
|
|
|
struct InternalSeekTarget {
|
2016-05-18 03:48:05 +00:00
|
|
|
InternalSeekTarget(const media::TimeInterval& aTime, bool aDropTarget)
|
2015-12-08 19:30:25 +00:00
|
|
|
: mTime(aTime)
|
|
|
|
, mDropTarget(aDropTarget)
|
|
|
|
, mWaiting(false)
|
2016-05-05 04:52:58 +00:00
|
|
|
, mHasSeeked(false)
|
2015-12-08 19:30:25 +00:00
|
|
|
{}
|
|
|
|
|
2016-05-18 03:48:05 +00:00
|
|
|
media::TimeUnit Time() const { return mTime.mStart; }
|
|
|
|
media::TimeUnit EndTime() const { return mTime.mEnd; }
|
|
|
|
bool Contains(const media::TimeUnit& aTime) const
|
|
|
|
{
|
|
|
|
return mTime.Contains(aTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
media::TimeInterval mTime;
|
2015-12-08 19:30:25 +00:00
|
|
|
bool mDropTarget;
|
|
|
|
bool mWaiting;
|
2016-05-05 04:52:58 +00:00
|
|
|
bool mHasSeeked;
|
2015-12-08 19:30:25 +00:00
|
|
|
};
|
2016-05-05 04:52:58 +00:00
|
|
|
|
2015-12-08 19:30:25 +00:00
|
|
|
// Perform an internal seek to aTime. If aDropTarget is true then
|
|
|
|
// the first sample past the target will be dropped.
|
2016-02-01 04:05:25 +00:00
|
|
|
void InternalSeek(TrackType aTrack, const InternalSeekTarget& aTarget);
|
2015-12-08 19:30:25 +00:00
|
|
|
|
2015-07-13 06:21:04 +00:00
|
|
|
// Drain the current decoder.
|
|
|
|
void DrainDecoder(TrackType aTrack);
|
2015-05-18 05:42:01 +00:00
|
|
|
void NotifyNewOutput(TrackType aTrack, MediaData* aSample);
|
|
|
|
void NotifyInputExhausted(TrackType aTrack);
|
|
|
|
void NotifyDrainComplete(TrackType aTrack);
|
2016-05-30 16:24:00 +00:00
|
|
|
void NotifyError(TrackType aTrack, MediaDataDecoderError aError = MediaDataDecoderError::FATAL_ERROR);
|
2015-05-18 05:42:01 +00:00
|
|
|
void NotifyWaitingForData(TrackType aTrack);
|
2015-06-15 00:58:12 +00:00
|
|
|
void NotifyEndOfStream(TrackType aTrack);
|
2015-08-24 02:50:27 +00:00
|
|
|
void NotifyDecodingRequested(TrackType aTrack);
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
void ExtractCryptoInitData(nsTArray<uint8_t>& aInitData);
|
|
|
|
|
|
|
|
// Initializes mLayersBackendType if possible.
|
|
|
|
void InitLayersBackendType();
|
|
|
|
|
|
|
|
// DecoderCallback proxies the MediaDataDecoderCallback calls to these
|
|
|
|
// functions.
|
|
|
|
void Output(TrackType aType, MediaData* aSample);
|
|
|
|
void InputExhausted(TrackType aTrack);
|
2016-05-30 16:24:00 +00:00
|
|
|
void Error(TrackType aTrack, MediaDataDecoderError aError = MediaDataDecoderError::FATAL_ERROR);
|
2016-05-05 05:06:40 +00:00
|
|
|
void Reset(TrackType aTrack);
|
2015-05-18 05:40:32 +00:00
|
|
|
void DrainComplete(TrackType aTrack);
|
2016-05-26 04:58:48 +00:00
|
|
|
void DropDecodedSamples(TrackType aTrack);
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
bool ShouldSkip(bool aSkipToNextKeyframe, media::TimeUnit aTimeThreshold);
|
|
|
|
|
2016-06-08 02:59:57 +00:00
|
|
|
void SetVideoDecodeThreshold();
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
size_t SizeOfQueue(TrackType aTrack);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PDMFactory> mPlatform;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
class DecoderCallback : public MediaDataDecoderCallback {
|
|
|
|
public:
|
|
|
|
DecoderCallback(MediaFormatReader* aReader, TrackType aType)
|
|
|
|
: mReader(aReader)
|
|
|
|
, mType(aType)
|
|
|
|
{
|
|
|
|
}
|
2015-06-11 23:26:58 +00:00
|
|
|
void Output(MediaData* aSample) override {
|
2015-05-18 05:40:32 +00:00
|
|
|
mReader->Output(mType, aSample);
|
|
|
|
}
|
2015-06-11 23:26:58 +00:00
|
|
|
void InputExhausted() override {
|
2015-05-18 05:40:32 +00:00
|
|
|
mReader->InputExhausted(mType);
|
|
|
|
}
|
2016-05-30 16:24:00 +00:00
|
|
|
void Error(MediaDataDecoderError aError) override {
|
|
|
|
mReader->Error(mType, aError);
|
2015-05-18 05:40:32 +00:00
|
|
|
}
|
2015-06-11 23:26:58 +00:00
|
|
|
void DrainComplete() override {
|
2015-05-18 05:40:32 +00:00
|
|
|
mReader->DrainComplete(mType);
|
|
|
|
}
|
2015-06-11 23:26:58 +00:00
|
|
|
void ReleaseMediaResources() override {
|
2015-05-18 05:40:32 +00:00
|
|
|
mReader->ReleaseMediaResources();
|
|
|
|
}
|
2015-06-11 23:26:58 +00:00
|
|
|
bool OnReaderTaskQueue() override {
|
2015-05-18 05:40:32 +00:00
|
|
|
return mReader->OnTaskQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MediaFormatReader* mReader;
|
|
|
|
TrackType mType;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DecoderData {
|
|
|
|
DecoderData(MediaFormatReader* aOwner,
|
|
|
|
MediaData::Type aType,
|
2016-05-30 16:24:00 +00:00
|
|
|
uint32_t aDecodeAhead,
|
|
|
|
uint32_t aNumOfMaxError)
|
2015-05-18 05:40:32 +00:00
|
|
|
: mOwner(aOwner)
|
|
|
|
, mType(aType)
|
2016-01-22 03:01:50 +00:00
|
|
|
, mMonitor("DecoderData")
|
|
|
|
, mDescription("shutdown")
|
2015-05-18 05:42:01 +00:00
|
|
|
, mDecodeAhead(aDecodeAhead)
|
|
|
|
, mUpdateScheduled(false)
|
2015-05-18 05:40:32 +00:00
|
|
|
, mDemuxEOS(false)
|
|
|
|
, mWaitingForData(false)
|
|
|
|
, mReceivedNewData(false)
|
2015-05-18 05:42:01 +00:00
|
|
|
, mDiscontinuity(true)
|
2015-08-11 03:50:07 +00:00
|
|
|
, mDecoderInitialized(false)
|
2015-08-24 02:50:27 +00:00
|
|
|
, mDecodingRequested(false)
|
2015-05-18 05:42:01 +00:00
|
|
|
, mOutputRequested(false)
|
2015-05-18 05:40:32 +00:00
|
|
|
, mInputExhausted(false)
|
2015-07-13 06:21:04 +00:00
|
|
|
, mNeedDraining(false)
|
2015-07-15 04:43:35 +00:00
|
|
|
, mDraining(false)
|
2015-05-18 05:40:32 +00:00
|
|
|
, mDrainComplete(false)
|
2016-05-30 16:24:00 +00:00
|
|
|
, mNumOfConsecutiveError(0)
|
|
|
|
, mMaxConsecutiveError(aNumOfMaxError)
|
2015-05-18 05:42:01 +00:00
|
|
|
, mNumSamplesInput(0)
|
|
|
|
, mNumSamplesOutput(0)
|
2015-08-24 02:57:29 +00:00
|
|
|
, mNumSamplesOutputTotal(0)
|
2016-01-17 23:21:59 +00:00
|
|
|
, mNumSamplesSkippedTotal(0)
|
2015-05-18 05:42:01 +00:00
|
|
|
, mSizeOfQueue(0)
|
2015-07-20 19:14:37 +00:00
|
|
|
, mIsHardwareAccelerated(false)
|
2015-06-15 00:58:12 +00:00
|
|
|
, mLastStreamSourceID(UINT32_MAX)
|
2015-05-18 05:40:32 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
MediaFormatReader* mOwner;
|
|
|
|
// Disambiguate Audio vs Video.
|
|
|
|
MediaData::Type mType;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaTrackDemuxer> mTrackDemuxer;
|
2015-05-18 05:40:32 +00:00
|
|
|
// TaskQueue on which decoder can choose to decode.
|
|
|
|
// Only non-null up until the decoder is created.
|
2016-05-24 08:48:26 +00:00
|
|
|
RefPtr<TaskQueue> mTaskQueue;
|
2015-05-18 05:40:32 +00:00
|
|
|
// Callback that receives output and error notifications from the decoder.
|
|
|
|
nsAutoPtr<DecoderCallback> mCallback;
|
|
|
|
|
2016-01-22 03:01:50 +00:00
|
|
|
// Monitor protecting mDescription and mDecoder.
|
|
|
|
Monitor mMonitor;
|
|
|
|
// The platform decoder.
|
|
|
|
RefPtr<MediaDataDecoder> mDecoder;
|
|
|
|
const char* mDescription;
|
|
|
|
void ShutdownDecoder()
|
|
|
|
{
|
|
|
|
MonitorAutoLock mon(mMonitor);
|
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->Shutdown();
|
|
|
|
}
|
|
|
|
mDescription = "shutdown";
|
|
|
|
mDecoder = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
// Only accessed from reader's task queue.
|
2015-05-18 05:42:01 +00:00
|
|
|
uint32_t mDecodeAhead;
|
|
|
|
bool mUpdateScheduled;
|
2015-05-18 05:40:32 +00:00
|
|
|
bool mDemuxEOS;
|
|
|
|
bool mWaitingForData;
|
|
|
|
bool mReceivedNewData;
|
2015-05-18 05:42:01 +00:00
|
|
|
bool mDiscontinuity;
|
|
|
|
|
2015-06-15 00:58:12 +00:00
|
|
|
// Pending seek.
|
2015-07-16 18:06:49 +00:00
|
|
|
MozPromiseRequestHolder<MediaTrackDemuxer::SeekPromise> mSeekRequest;
|
2015-06-15 00:58:12 +00:00
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
// Queued demux samples waiting to be decoded.
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<MediaRawData>> mQueuedSamples;
|
2015-07-16 18:06:49 +00:00
|
|
|
MozPromiseRequestHolder<MediaTrackDemuxer::SamplesPromise> mDemuxRequest;
|
|
|
|
MozPromiseHolder<WaitForDataPromise> mWaitingPromise;
|
2015-05-18 05:40:32 +00:00
|
|
|
bool HasWaitingPromise()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
return !mWaitingPromise.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2015-05-18 05:42:01 +00:00
|
|
|
// MediaDataDecoder handler's variables.
|
2015-09-30 04:35:11 +00:00
|
|
|
// Decoder initialization promise holder.
|
|
|
|
MozPromiseRequestHolder<MediaDataDecoder::InitPromise> mInitPromise;
|
2015-08-11 03:50:07 +00:00
|
|
|
// False when decoder is created. True when decoder Init() promise is resolved.
|
|
|
|
bool mDecoderInitialized;
|
2016-05-05 04:52:58 +00:00
|
|
|
// Set when decoding can proceed. It is reset when a decoding promise is
|
|
|
|
// rejected or prior a seek operation.
|
2015-08-24 02:50:27 +00:00
|
|
|
bool mDecodingRequested;
|
2015-05-18 05:42:01 +00:00
|
|
|
bool mOutputRequested;
|
|
|
|
bool mInputExhausted;
|
2015-07-13 06:21:04 +00:00
|
|
|
bool mNeedDraining;
|
2015-07-15 04:43:35 +00:00
|
|
|
bool mDraining;
|
2015-05-18 05:42:01 +00:00
|
|
|
bool mDrainComplete;
|
2016-05-30 16:24:00 +00:00
|
|
|
|
2016-06-02 11:08:05 +00:00
|
|
|
bool HasPendingDrain() const
|
|
|
|
{
|
|
|
|
return mDraining || mDrainComplete;
|
|
|
|
}
|
|
|
|
|
2016-05-30 16:24:00 +00:00
|
|
|
uint32_t mNumOfConsecutiveError;
|
|
|
|
uint32_t mMaxConsecutiveError;
|
|
|
|
|
|
|
|
Maybe<MediaDataDecoderError> mError;
|
|
|
|
bool HasFatalError() const
|
|
|
|
{
|
|
|
|
return mError.isSome() && mError.ref() == MediaDataDecoderError::FATAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2015-06-15 00:58:12 +00:00
|
|
|
// If set, all decoded samples prior mTimeThreshold will be dropped.
|
2015-12-08 19:30:25 +00:00
|
|
|
// Used for internal seeking when a change of stream is detected or when
|
|
|
|
// encountering data discontinuity.
|
2016-02-01 04:05:25 +00:00
|
|
|
Maybe<InternalSeekTarget> mTimeThreshold;
|
2015-12-08 19:30:25 +00:00
|
|
|
// Time of last sample returned.
|
2016-05-18 03:48:05 +00:00
|
|
|
Maybe<media::TimeInterval> mLastSampleTime;
|
2015-06-15 00:58:12 +00:00
|
|
|
|
2015-05-18 05:42:01 +00:00
|
|
|
// Decoded samples returned my mDecoder awaiting being returned to
|
|
|
|
// state machine upon request.
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<MediaData>> mOutput;
|
2015-05-18 05:42:01 +00:00
|
|
|
uint64_t mNumSamplesInput;
|
|
|
|
uint64_t mNumSamplesOutput;
|
2015-08-24 02:57:29 +00:00
|
|
|
uint64_t mNumSamplesOutputTotal;
|
2016-01-17 23:21:59 +00:00
|
|
|
uint64_t mNumSamplesSkippedTotal;
|
2015-05-18 05:42:01 +00:00
|
|
|
|
2016-04-18 06:33:52 +00:00
|
|
|
// These get overridden in the templated concrete class.
|
2015-05-18 05:40:32 +00:00
|
|
|
// Indicate if we have a pending promise for decoded frame.
|
2015-08-24 02:50:27 +00:00
|
|
|
// Rejecting the promise will stop the reader from decoding ahead.
|
2016-05-05 05:11:21 +00:00
|
|
|
virtual bool HasPromise() const = 0;
|
|
|
|
virtual RefPtr<MediaDataPromise> EnsurePromise(const char* aMethodName) = 0;
|
|
|
|
virtual void ResolvePromise(MediaData* aData, const char* aMethodName) = 0;
|
2015-05-18 05:40:32 +00:00
|
|
|
virtual void RejectPromise(MediaDecoderReader::NotDecodedReason aReason,
|
|
|
|
const char* aMethodName) = 0;
|
|
|
|
|
2016-05-05 05:06:40 +00:00
|
|
|
// Clear track demuxer related data.
|
2015-05-25 05:09:16 +00:00
|
|
|
void ResetDemuxer()
|
|
|
|
{
|
|
|
|
mDemuxRequest.DisconnectIfExists();
|
2016-05-05 04:52:58 +00:00
|
|
|
mSeekRequest.DisconnectIfExists();
|
2015-05-25 05:09:16 +00:00
|
|
|
mTrackDemuxer->Reset();
|
2016-05-05 05:06:40 +00:00
|
|
|
mQueuedSamples.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush the decoder if present and reset decoding related data.
|
|
|
|
// Decoding will be suspended until mInputRequested is set again.
|
|
|
|
// Following a flush, the decoder is ready to accept any new data.
|
|
|
|
void Flush()
|
|
|
|
{
|
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->Flush();
|
|
|
|
}
|
|
|
|
mDecodingRequested = false;
|
|
|
|
mOutputRequested = false;
|
|
|
|
mInputExhausted = false;
|
|
|
|
mOutput.Clear();
|
|
|
|
mNumSamplesInput = 0;
|
|
|
|
mNumSamplesOutput = 0;
|
|
|
|
mSizeOfQueue = 0;
|
|
|
|
mDraining = false;
|
|
|
|
mDrainComplete = false;
|
2015-05-25 05:09:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:06:40 +00:00
|
|
|
// Reset the state of the DecoderData, clearing all queued frames
|
|
|
|
// (pending demuxed and decoded).
|
|
|
|
// Decoding will be suspended until mInputRequested is set again.
|
|
|
|
// The track demuxer is *not* reset.
|
2015-05-18 05:40:32 +00:00
|
|
|
void ResetState()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
mDemuxEOS = false;
|
|
|
|
mWaitingForData = false;
|
2015-05-18 05:42:01 +00:00
|
|
|
mDiscontinuity = true;
|
2015-05-18 05:40:32 +00:00
|
|
|
mQueuedSamples.Clear();
|
2015-08-29 11:01:13 +00:00
|
|
|
mDecodingRequested = false;
|
2015-05-18 05:42:01 +00:00
|
|
|
mOutputRequested = false;
|
2015-05-18 05:40:32 +00:00
|
|
|
mInputExhausted = false;
|
2015-07-13 06:21:04 +00:00
|
|
|
mNeedDraining = false;
|
2015-07-15 04:43:35 +00:00
|
|
|
mDraining = false;
|
2015-05-18 05:40:32 +00:00
|
|
|
mDrainComplete = false;
|
2015-06-15 00:58:12 +00:00
|
|
|
mTimeThreshold.reset();
|
2015-12-08 19:30:25 +00:00
|
|
|
mLastSampleTime.reset();
|
2015-05-18 05:42:01 +00:00
|
|
|
mOutput.Clear();
|
|
|
|
mNumSamplesInput = 0;
|
|
|
|
mNumSamplesOutput = 0;
|
2015-07-15 02:27:09 +00:00
|
|
|
mSizeOfQueue = 0;
|
2015-07-13 06:25:04 +00:00
|
|
|
mNextStreamSourceID.reset();
|
2016-05-30 16:24:00 +00:00
|
|
|
if (!HasFatalError()) {
|
|
|
|
mError.reset();
|
|
|
|
}
|
2015-05-18 05:40:32 +00:00
|
|
|
}
|
2015-05-18 05:42:01 +00:00
|
|
|
|
2016-05-05 04:52:58 +00:00
|
|
|
bool HasInternalSeekPending() const
|
|
|
|
{
|
|
|
|
return mTimeThreshold && !mTimeThreshold.ref().mHasSeeked;
|
|
|
|
}
|
|
|
|
|
2015-05-18 05:42:01 +00:00
|
|
|
// Used by the MDSM for logging purposes.
|
|
|
|
Atomic<size_t> mSizeOfQueue;
|
2015-07-20 19:14:37 +00:00
|
|
|
// Used by the MDSM to determine if video decoding is hardware accelerated.
|
|
|
|
// This value is updated after a frame is successfully decoded.
|
|
|
|
Atomic<bool> mIsHardwareAccelerated;
|
2015-06-15 00:58:12 +00:00
|
|
|
// Sample format monitoring.
|
|
|
|
uint32_t mLastStreamSourceID;
|
2015-07-13 06:25:04 +00:00
|
|
|
Maybe<uint32_t> mNextStreamSourceID;
|
2015-05-18 05:40:32 +00:00
|
|
|
media::TimeIntervals mTimeRanges;
|
2015-12-08 19:30:25 +00:00
|
|
|
Maybe<media::TimeUnit> mLastTimeRangesEnd;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SharedTrackInfo> mInfo;
|
2016-05-16 10:15:17 +00:00
|
|
|
Maybe<media::TimeUnit> mFirstDemuxedSampleTime;
|
2015-05-18 05:40:32 +00:00
|
|
|
};
|
|
|
|
|
2016-05-05 05:11:21 +00:00
|
|
|
class DecoderDataWithPromise : public DecoderData {
|
|
|
|
public:
|
2015-05-18 05:40:32 +00:00
|
|
|
DecoderDataWithPromise(MediaFormatReader* aOwner,
|
|
|
|
MediaData::Type aType,
|
2016-05-30 16:24:00 +00:00
|
|
|
uint32_t aDecodeAhead,
|
|
|
|
uint32_t aNumOfMaxError)
|
|
|
|
: DecoderData(aOwner, aType, aDecodeAhead, aNumOfMaxError)
|
2016-05-05 05:11:21 +00:00
|
|
|
, mHasPromise(false)
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
{}
|
|
|
|
|
2016-05-05 05:11:21 +00:00
|
|
|
bool HasPromise() const override
|
|
|
|
{
|
|
|
|
return mHasPromise;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MediaDataPromise> EnsurePromise(const char* aMethodName) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
mHasPromise = true;
|
|
|
|
return mPromise.Ensure(aMethodName);
|
|
|
|
}
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2016-05-05 05:11:21 +00:00
|
|
|
void ResolvePromise(MediaData* aData, const char* aMethodName) override
|
2015-05-18 05:40:32 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
2016-05-05 05:11:21 +00:00
|
|
|
mPromise.Resolve(aData, aMethodName);
|
|
|
|
mHasPromise = false;
|
2015-05-18 05:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RejectPromise(MediaDecoderReader::NotDecodedReason aReason,
|
|
|
|
const char* aMethodName) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
mPromise.Reject(aReason, aMethodName);
|
2015-08-24 02:50:27 +00:00
|
|
|
mDecodingRequested = false;
|
2016-05-05 05:11:21 +00:00
|
|
|
mHasPromise = false;
|
2015-05-18 05:40:32 +00:00
|
|
|
}
|
2016-05-05 05:11:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
MozPromiseHolder<MediaDataPromise> mPromise;
|
|
|
|
Atomic<bool> mHasPromise;
|
2015-05-18 05:40:32 +00:00
|
|
|
};
|
|
|
|
|
2016-04-22 06:16:56 +00:00
|
|
|
DecoderDataWithPromise mAudio;
|
|
|
|
DecoderDataWithPromise mVideo;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
// Returns true when the decoder for this track needs input.
|
|
|
|
bool NeedInput(DecoderData& aDecoder);
|
|
|
|
|
|
|
|
DecoderData& GetDecoderData(TrackType aTrack);
|
|
|
|
|
|
|
|
// Demuxer objects.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaDataDemuxer> mDemuxer;
|
2015-10-07 01:00:52 +00:00
|
|
|
bool mDemuxerInitDone;
|
2015-05-18 05:40:32 +00:00
|
|
|
void OnDemuxerInitDone(nsresult);
|
|
|
|
void OnDemuxerInitFailed(DemuxerFailureReason aFailure);
|
2015-07-16 18:06:49 +00:00
|
|
|
MozPromiseRequestHolder<MediaDataDemuxer::InitPromise> mDemuxerInitRequest;
|
2015-05-18 05:40:32 +00:00
|
|
|
void OnDemuxFailed(TrackType aTrack, DemuxerFailureReason aFailure);
|
|
|
|
|
|
|
|
void DoDemuxVideo();
|
2015-10-18 05:24:48 +00:00
|
|
|
void OnVideoDemuxCompleted(RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples);
|
2015-05-18 05:40:32 +00:00
|
|
|
void OnVideoDemuxFailed(DemuxerFailureReason aFailure)
|
|
|
|
{
|
|
|
|
OnDemuxFailed(TrackType::kVideoTrack, aFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoDemuxAudio();
|
2015-10-18 05:24:48 +00:00
|
|
|
void OnAudioDemuxCompleted(RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples);
|
2015-05-18 05:40:32 +00:00
|
|
|
void OnAudioDemuxFailed(DemuxerFailureReason aFailure)
|
|
|
|
{
|
|
|
|
OnDemuxFailed(TrackType::kAudioTrack, aFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkipVideoDemuxToNextKeyFrame(media::TimeUnit aTimeThreshold);
|
2015-07-16 18:06:49 +00:00
|
|
|
MozPromiseRequestHolder<MediaTrackDemuxer::SkipAccessPointPromise> mSkipRequest;
|
2016-05-19 07:02:43 +00:00
|
|
|
void VideoSkipReset(uint32_t aSkipped);
|
2015-05-18 05:40:32 +00:00
|
|
|
void OnVideoSkipCompleted(uint32_t aSkipped);
|
|
|
|
void OnVideoSkipFailed(MediaTrackDemuxer::SkipFailureHolder aFailure);
|
|
|
|
|
|
|
|
// The last number of decoded output frames that we've reported to
|
|
|
|
// MediaDecoder::NotifyDecoded(). We diff the number of output video
|
|
|
|
// frames every time that DecodeVideoData() is called, and report the
|
|
|
|
// delta there.
|
|
|
|
uint64_t mLastReportedNumDecodedFrames;
|
|
|
|
|
|
|
|
layers::LayersBackend mLayersBackendType;
|
|
|
|
|
|
|
|
// Metadata objects
|
|
|
|
// True if we've read the streams' metadata.
|
|
|
|
bool mInitDone;
|
2015-07-16 18:06:49 +00:00
|
|
|
MozPromiseHolder<MetadataPromise> mMetadataPromise;
|
2015-05-18 05:40:32 +00:00
|
|
|
bool IsEncrypted()
|
|
|
|
{
|
|
|
|
return mIsEncrypted;
|
|
|
|
}
|
|
|
|
bool mIsEncrypted;
|
|
|
|
|
2015-06-11 23:26:58 +00:00
|
|
|
// Set to true if any of our track buffers may be blocking.
|
|
|
|
bool mTrackDemuxersMayBlock;
|
|
|
|
|
2015-10-20 09:33:00 +00:00
|
|
|
// Set the demuxed-only flag.
|
|
|
|
Atomic<bool> mDemuxOnly;
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
// Seeking objects.
|
2016-05-16 10:15:17 +00:00
|
|
|
void SetSeekTarget(const SeekTarget& aTarget);
|
|
|
|
media::TimeUnit DemuxStartTime();
|
2015-05-18 05:40:32 +00:00
|
|
|
bool IsSeeking() const { return mPendingSeekTime.isSome(); }
|
2016-05-16 08:15:45 +00:00
|
|
|
bool IsVideoSeeking() const
|
|
|
|
{
|
|
|
|
return IsSeeking() && mOriginalSeekTarget.IsVideoOnly();
|
|
|
|
}
|
2016-05-05 05:01:51 +00:00
|
|
|
void ScheduleSeek();
|
2015-05-18 05:40:32 +00:00
|
|
|
void AttemptSeek();
|
|
|
|
void OnSeekFailed(TrackType aTrack, DemuxerFailureReason aFailure);
|
|
|
|
void DoVideoSeek();
|
|
|
|
void OnVideoSeekCompleted(media::TimeUnit aTime);
|
|
|
|
void OnVideoSeekFailed(DemuxerFailureReason aFailure)
|
|
|
|
{
|
|
|
|
OnSeekFailed(TrackType::kVideoTrack, aFailure);
|
|
|
|
}
|
2016-05-05 05:01:51 +00:00
|
|
|
bool mSeekScheduled;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
|
|
|
void DoAudioSeek();
|
|
|
|
void OnAudioSeekCompleted(media::TimeUnit aTime);
|
|
|
|
void OnAudioSeekFailed(DemuxerFailureReason aFailure)
|
|
|
|
{
|
|
|
|
OnSeekFailed(TrackType::kAudioTrack, aFailure);
|
|
|
|
}
|
2016-05-16 06:47:57 +00:00
|
|
|
// The SeekTarget that was last given to Seek()
|
|
|
|
SeekTarget mOriginalSeekTarget;
|
2015-05-18 05:40:32 +00:00
|
|
|
// Temporary seek information while we wait for the data
|
2016-05-16 06:47:57 +00:00
|
|
|
Maybe<media::TimeUnit> mFallbackSeekTime;
|
2015-05-18 05:40:32 +00:00
|
|
|
Maybe<media::TimeUnit> mPendingSeekTime;
|
2015-07-16 18:06:49 +00:00
|
|
|
MozPromiseHolder<SeekPromise> mSeekPromise;
|
2015-05-18 05:40:32 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<VideoFrameContainer> mVideoFrameContainer;
|
2015-10-15 00:04:00 +00:00
|
|
|
layers::ImageContainer* GetImageContainer();
|
|
|
|
|
2015-05-18 05:40:32 +00:00
|
|
|
#ifdef MOZ_EME
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<CDMProxy> mCDMProxy;
|
2015-05-18 05:40:32 +00:00
|
|
|
#endif
|
2016-06-28 23:42:07 +00:00
|
|
|
RefPtr<GMPCrashHelper> mCrashHelper;
|
2015-05-18 05:40:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|