2015-05-18 08:40:32 +03: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 08:42:01 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-08-10 08:30:12 +03:00
|
|
|
#include "mozilla/TaskQueue.h"
|
2016-11-29 17:50:08 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-07-16 21:52:43 +03:00
|
|
|
|
2016-11-08 05:23:12 +03:00
|
|
|
#include "MediaEventSource.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
#include "MediaDataDemuxer.h"
|
|
|
|
#include "MediaDecoderReader.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2015-10-06 11:56:29 +03:00
|
|
|
#include "PDMFactory.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-09-27 13:40:03 +03:00
|
|
|
class CDMProxy;
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
class MediaFormatReader final : public MediaDecoderReader
|
|
|
|
{
|
|
|
|
typedef TrackInfo::TrackType TrackType;
|
2016-11-28 13:08:01 +03:00
|
|
|
typedef MozPromise<bool, MediaResult, /* IsExclusive = */ true> NotifyDataArrivedPromise;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
public:
|
2015-10-15 03:04:00 +03:00
|
|
|
MediaFormatReader(AbstractMediaDecoder* aDecoder,
|
|
|
|
MediaDataDemuxer* aDemuxer,
|
2016-10-07 11:13:33 +03:00
|
|
|
VideoFrameContainer* aVideoFrameContainer = nullptr);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
virtual ~MediaFormatReader();
|
|
|
|
|
2015-06-12 02:26:58 +03:00
|
|
|
size_t SizeOfVideoQueueInFrames() override;
|
|
|
|
size_t SizeOfAudioQueueInFrames() override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-04-22 09:16:49 +03:00
|
|
|
RefPtr<MediaDataPromise>
|
2015-08-24 04:32:49 +03:00
|
|
|
RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThreshold) override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-04-22 09:16:49 +03:00
|
|
|
RefPtr<MediaDataPromise> RequestAudioData() override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-10-21 05:59:56 +03:00
|
|
|
RefPtr<MetadataPromise> AsyncReadMetadata() override;
|
|
|
|
|
2015-06-12 02:26:58 +03:00
|
|
|
void ReadUpdatedMetadata(MediaInfo* aInfo) override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-11-29 17:42:50 +03:00
|
|
|
RefPtr<SeekPromise> Seek(const SeekTarget& aTarget) override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-06-17 01:37:48 +03:00
|
|
|
protected:
|
2016-11-28 13:08:01 +03:00
|
|
|
void NotifyDataArrived() override;
|
|
|
|
void UpdateBuffered() override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-10-26 09:10:29 +03:00
|
|
|
public:
|
2015-10-21 09:04:20 +03:00
|
|
|
// For Media Resource Management
|
2016-08-17 10:03:30 +03:00
|
|
|
void ReleaseResources() override;
|
2015-10-21 09:04:20 +03:00
|
|
|
|
2016-05-31 07:32:37 +03:00
|
|
|
nsresult ResetDecode(TrackSet aTracks) override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ShutdownPromise> Shutdown() override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-06-12 02:26:58 +03:00
|
|
|
bool IsAsync() const override { return true; }
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-06-12 02:26:58 +03:00
|
|
|
bool VideoIsHardwareAccelerated() const override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-04-19 11:14:33 +03:00
|
|
|
bool IsWaitForDataSupported() const override { return true; }
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType) override;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-04-19 11:14:33 +03:00
|
|
|
bool UseBufferingHeuristics() const override
|
2015-06-12 02:26:58 +03:00
|
|
|
{
|
|
|
|
return mTrackDemuxersMayBlock;
|
|
|
|
}
|
|
|
|
|
2015-09-27 13:40:03 +03:00
|
|
|
void SetCDMProxy(CDMProxy* aProxy) override;
|
|
|
|
|
2016-01-18 02:21:59 +03:00
|
|
|
// Returns a string describing the state of the decoder data.
|
|
|
|
// Used for debugging purposes.
|
2017-01-18 11:51:31 +03:00
|
|
|
void GetMozDebugReaderData(nsACString& aString);
|
2016-01-18 02:21:59 +03:00
|
|
|
|
2016-07-29 09:51:18 +03:00
|
|
|
void SetVideoBlankDecode(bool aIsBlankDecode) override;
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
private:
|
2016-11-08 18:09:34 +03:00
|
|
|
nsresult InitInternal() override;
|
2016-06-08 15:28:24 +03:00
|
|
|
|
2016-09-28 03:34:57 +03:00
|
|
|
bool HasVideo() const { return mVideo.mTrackDemuxer; }
|
|
|
|
bool HasAudio() const { return mAudio.mTrackDemuxer; }
|
2015-10-26 09:10:29 +03:00
|
|
|
|
2015-09-27 13:59:52 +03:00
|
|
|
bool IsWaitingOnCDMResource();
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
bool InitDemuxer();
|
2016-11-28 13:08:01 +03:00
|
|
|
// Notify the track demuxers that new data has been received.
|
|
|
|
void NotifyTrackDemuxers();
|
2015-05-18 08:40:32 +03:00
|
|
|
void ReturnOutput(MediaData* aData, TrackType aTrack);
|
|
|
|
|
|
|
|
// 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 12:33:00 +03:00
|
|
|
// Handle demuxed samples by the input behavior.
|
|
|
|
void HandleDemuxedSamples(TrackType aTrack,
|
2015-05-18 08:40:32 +03:00
|
|
|
AbstractMediaDecoder::AutoNotifyDecoded& aA);
|
2015-10-20 12:33:00 +03:00
|
|
|
// Decode any pending already demuxed samples.
|
2016-09-09 06:50:37 +03:00
|
|
|
void DecodeDemuxedSamples(TrackType aTrack,
|
2015-10-20 12:33:00 +03:00
|
|
|
MediaRawData* aSample);
|
2015-12-08 22:30:25 +03:00
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
struct InternalSeekTarget
|
|
|
|
{
|
2016-05-18 06:48:05 +03:00
|
|
|
InternalSeekTarget(const media::TimeInterval& aTime, bool aDropTarget)
|
2015-12-08 22:30:25 +03:00
|
|
|
: mTime(aTime)
|
|
|
|
, mDropTarget(aDropTarget)
|
|
|
|
, mWaiting(false)
|
2016-05-05 07:52:58 +03:00
|
|
|
, mHasSeeked(false)
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
|
|
|
}
|
2015-12-08 22:30:25 +03:00
|
|
|
|
2016-05-18 06:48:05 +03: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 22:30:25 +03:00
|
|
|
bool mDropTarget;
|
|
|
|
bool mWaiting;
|
2016-05-05 07:52:58 +03:00
|
|
|
bool mHasSeeked;
|
2015-12-08 22:30:25 +03:00
|
|
|
};
|
2016-05-05 07:52:58 +03:00
|
|
|
|
2015-12-08 22:30:25 +03:00
|
|
|
// Perform an internal seek to aTime. If aDropTarget is true then
|
|
|
|
// the first sample past the target will be dropped.
|
2016-02-01 07:05:25 +03:00
|
|
|
void InternalSeek(TrackType aTrack, const InternalSeekTarget& aTarget);
|
2015-12-08 22:30:25 +03:00
|
|
|
|
2015-07-13 09:21:04 +03:00
|
|
|
// Drain the current decoder.
|
|
|
|
void DrainDecoder(TrackType aTrack);
|
2017-01-26 15:56:46 +03:00
|
|
|
void NotifyNewOutput(TrackType aTrack,
|
|
|
|
const MediaDataDecoder::DecodedData& aResults);
|
2016-09-13 06:07:26 +03:00
|
|
|
void NotifyError(TrackType aTrack, const MediaResult& aError);
|
2015-05-18 08:42:01 +03:00
|
|
|
void NotifyWaitingForData(TrackType aTrack);
|
2017-01-27 13:48:00 +03:00
|
|
|
void NotifyWaitingForKey(TrackType aTrack);
|
2015-06-15 03:58:12 +03:00
|
|
|
void NotifyEndOfStream(TrackType aTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
void ExtractCryptoInitData(nsTArray<uint8_t>& aInitData);
|
|
|
|
|
|
|
|
// Initializes mLayersBackendType if possible.
|
|
|
|
void InitLayersBackendType();
|
|
|
|
|
2016-05-05 08:06:40 +03:00
|
|
|
void Reset(TrackType aTrack);
|
2016-05-26 07:58:48 +03:00
|
|
|
void DropDecodedSamples(TrackType aTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
bool ShouldSkip(bool aSkipToNextKeyframe, media::TimeUnit aTimeThreshold);
|
|
|
|
|
2016-06-08 05:59:57 +03:00
|
|
|
void SetVideoDecodeThreshold();
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
size_t SizeOfQueue(TrackType aTrack);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PDMFactory> mPlatform;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-02-09 17:31:44 +03:00
|
|
|
enum class DrainState
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
DrainRequested,
|
|
|
|
Draining,
|
|
|
|
PartialDrainPending,
|
|
|
|
DrainCompleted,
|
|
|
|
DrainAborted,
|
|
|
|
};
|
|
|
|
|
2017-02-27 04:56:36 +03:00
|
|
|
class SharedShutdownPromiseHolder : public MozPromiseHolder<ShutdownPromise>
|
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedShutdownPromiseHolder)
|
|
|
|
private:
|
|
|
|
~SharedShutdownPromiseHolder() { }
|
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
struct DecoderData
|
|
|
|
{
|
2015-05-18 08:40:32 +03:00
|
|
|
DecoderData(MediaFormatReader* aOwner,
|
|
|
|
MediaData::Type aType,
|
2016-05-30 19:24:00 +03:00
|
|
|
uint32_t aNumOfMaxError)
|
2015-05-18 08:40:32 +03:00
|
|
|
: mOwner(aOwner)
|
|
|
|
, mType(aType)
|
2016-11-29 17:50:08 +03:00
|
|
|
, mMutex("DecoderData")
|
2016-01-22 06:01:50 +03:00
|
|
|
, mDescription("shutdown")
|
2015-05-18 08:42:01 +03:00
|
|
|
, mUpdateScheduled(false)
|
2015-05-18 08:40:32 +03:00
|
|
|
, mDemuxEOS(false)
|
|
|
|
, mWaitingForData(false)
|
2017-01-27 13:48:00 +03:00
|
|
|
, mWaitingForKey(false)
|
2015-05-18 08:40:32 +03:00
|
|
|
, mReceivedNewData(false)
|
2017-02-24 12:04:32 +03:00
|
|
|
, mFlushing(false)
|
2017-01-26 15:56:46 +03:00
|
|
|
, mFlushed(true)
|
2017-02-09 17:31:44 +03:00
|
|
|
, mDrainState(DrainState::None)
|
2016-05-30 19:24:00 +03:00
|
|
|
, mNumOfConsecutiveError(0)
|
|
|
|
, mMaxConsecutiveError(aNumOfMaxError)
|
2015-05-18 08:42:01 +03:00
|
|
|
, mNumSamplesInput(0)
|
|
|
|
, mNumSamplesOutput(0)
|
2015-08-24 05:57:29 +03:00
|
|
|
, mNumSamplesOutputTotal(0)
|
2016-01-18 02:21:59 +03:00
|
|
|
, mNumSamplesSkippedTotal(0)
|
2015-05-18 08:42:01 +03:00
|
|
|
, mSizeOfQueue(0)
|
2015-07-20 22:14:37 +03:00
|
|
|
, mIsHardwareAccelerated(false)
|
2015-06-15 03:58:12 +03:00
|
|
|
, mLastStreamSourceID(UINT32_MAX)
|
2016-07-29 09:51:18 +03:00
|
|
|
, mIsBlankDecode(false)
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
MediaFormatReader* mOwner;
|
|
|
|
// Disambiguate Audio vs Video.
|
|
|
|
MediaData::Type mType;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaTrackDemuxer> mTrackDemuxer;
|
2015-05-18 08:40:32 +03:00
|
|
|
// TaskQueue on which decoder can choose to decode.
|
|
|
|
// Only non-null up until the decoder is created.
|
2016-05-24 11:48:26 +03:00
|
|
|
RefPtr<TaskQueue> mTaskQueue;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-11-29 17:50:08 +03:00
|
|
|
// Mutex protecting mDescription and mDecoder.
|
|
|
|
Mutex mMutex;
|
2016-01-22 06:01:50 +03:00
|
|
|
// The platform decoder.
|
|
|
|
RefPtr<MediaDataDecoder> mDecoder;
|
|
|
|
const char* mDescription;
|
2017-02-24 12:27:42 +03:00
|
|
|
void ShutdownDecoder();
|
2016-01-22 06:01:50 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
// Only accessed from reader's task queue.
|
2015-05-18 08:42:01 +03:00
|
|
|
bool mUpdateScheduled;
|
2015-05-18 08:40:32 +03:00
|
|
|
bool mDemuxEOS;
|
|
|
|
bool mWaitingForData;
|
2017-01-27 13:48:00 +03:00
|
|
|
bool mWaitingForKey;
|
2015-05-18 08:40:32 +03:00
|
|
|
bool mReceivedNewData;
|
2015-05-18 08:42:01 +03:00
|
|
|
|
2015-06-15 03:58:12 +03:00
|
|
|
// Pending seek.
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseRequestHolder<MediaTrackDemuxer::SeekPromise> mSeekRequest;
|
2015-06-15 03:58:12 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
// Queued demux samples waiting to be decoded.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<MediaRawData>> mQueuedSamples;
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseRequestHolder<MediaTrackDemuxer::SamplesPromise> mDemuxRequest;
|
2016-10-27 12:25:21 +03:00
|
|
|
// A WaitingPromise is pending if the demuxer is waiting for data or
|
|
|
|
// if the decoder is waiting for a key.
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseHolder<WaitForDataPromise> mWaitingPromise;
|
2016-10-27 12:25:21 +03:00
|
|
|
bool HasWaitingPromise() const
|
2015-05-18 08:40:32 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
return !mWaitingPromise.IsEmpty();
|
|
|
|
}
|
2016-10-27 12:25:21 +03:00
|
|
|
bool IsWaiting() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
2017-01-27 13:48:00 +03:00
|
|
|
return mWaitingForData || mWaitingForKey;
|
2016-10-27 12:25:21 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-05-18 08:42:01 +03:00
|
|
|
// MediaDataDecoder handler's variables.
|
2017-01-26 15:56:46 +03:00
|
|
|
MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDecodeRequest;
|
2017-02-24 12:04:32 +03:00
|
|
|
bool mFlushing; // True if flush is in action.
|
2017-01-26 15:56:46 +03:00
|
|
|
// Set to true if the last operation run on the decoder was a flush.
|
|
|
|
bool mFlushed;
|
2017-02-27 04:56:36 +03:00
|
|
|
RefPtr<SharedShutdownPromiseHolder> mShutdownPromise;
|
2016-05-30 19:24:00 +03:00
|
|
|
|
2017-02-09 17:31:44 +03:00
|
|
|
MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDrainRequest;
|
|
|
|
DrainState mDrainState;
|
2016-06-02 14:08:05 +03:00
|
|
|
bool HasPendingDrain() const
|
|
|
|
{
|
2017-02-09 17:31:44 +03:00
|
|
|
return mDrainState != DrainState::None;
|
|
|
|
}
|
|
|
|
void RequestDrain()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(mDrainState == DrainState::None);
|
|
|
|
mDrainState = DrainState::DrainRequested;
|
2016-06-02 14:08:05 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 19:24:00 +03:00
|
|
|
uint32_t mNumOfConsecutiveError;
|
|
|
|
uint32_t mMaxConsecutiveError;
|
|
|
|
|
2016-09-10 02:56:53 +03:00
|
|
|
Maybe<MediaResult> mError;
|
2016-05-30 19:24:00 +03:00
|
|
|
bool HasFatalError() const
|
|
|
|
{
|
2016-11-08 05:22:37 +03:00
|
|
|
if (!mError.isSome()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mError.ref() == NS_ERROR_DOM_MEDIA_DECODE_ERR) {
|
|
|
|
// Allow decode errors to be non-fatal, but give up
|
|
|
|
// if we have too many.
|
|
|
|
return mNumOfConsecutiveError > mMaxConsecutiveError;
|
|
|
|
} else if (mError.ref() == NS_ERROR_DOM_MEDIA_NEED_NEW_DECODER) {
|
|
|
|
// If the caller asked for a new decoder we shouldn't treat
|
|
|
|
// it as fatal.
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// All other error types are fatal
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-30 19:24:00 +03:00
|
|
|
}
|
|
|
|
|
2015-06-15 03:58:12 +03:00
|
|
|
// If set, all decoded samples prior mTimeThreshold will be dropped.
|
2015-12-08 22:30:25 +03:00
|
|
|
// Used for internal seeking when a change of stream is detected or when
|
|
|
|
// encountering data discontinuity.
|
2016-02-01 07:05:25 +03:00
|
|
|
Maybe<InternalSeekTarget> mTimeThreshold;
|
2015-12-08 22:30:25 +03:00
|
|
|
// Time of last sample returned.
|
2016-05-18 06:48:05 +03:00
|
|
|
Maybe<media::TimeInterval> mLastSampleTime;
|
2015-06-15 03:58:12 +03:00
|
|
|
|
2015-05-18 08:42:01 +03:00
|
|
|
// Decoded samples returned my mDecoder awaiting being returned to
|
|
|
|
// state machine upon request.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<MediaData>> mOutput;
|
2015-05-18 08:42:01 +03:00
|
|
|
uint64_t mNumSamplesInput;
|
|
|
|
uint64_t mNumSamplesOutput;
|
2015-08-24 05:57:29 +03:00
|
|
|
uint64_t mNumSamplesOutputTotal;
|
2016-01-18 02:21:59 +03:00
|
|
|
uint64_t mNumSamplesSkippedTotal;
|
2015-05-18 08:42:01 +03:00
|
|
|
|
2016-04-18 09:33:52 +03:00
|
|
|
// These get overridden in the templated concrete class.
|
2015-05-18 08:40:32 +03:00
|
|
|
// Indicate if we have a pending promise for decoded frame.
|
2015-08-24 05:50:27 +03:00
|
|
|
// Rejecting the promise will stop the reader from decoding ahead.
|
2016-05-05 08:11:21 +03:00
|
|
|
virtual bool HasPromise() const = 0;
|
|
|
|
virtual RefPtr<MediaDataPromise> EnsurePromise(const char* aMethodName) = 0;
|
|
|
|
virtual void ResolvePromise(MediaData* aData, const char* aMethodName) = 0;
|
2016-09-10 09:48:53 +03:00
|
|
|
virtual void RejectPromise(const MediaResult& aError,
|
2015-05-18 08:40:32 +03:00
|
|
|
const char* aMethodName) = 0;
|
|
|
|
|
2016-05-05 08:06:40 +03:00
|
|
|
// Clear track demuxer related data.
|
2015-05-25 08:09:16 +03:00
|
|
|
void ResetDemuxer()
|
|
|
|
{
|
|
|
|
mDemuxRequest.DisconnectIfExists();
|
2016-05-05 07:52:58 +03:00
|
|
|
mSeekRequest.DisconnectIfExists();
|
2015-05-25 08:09:16 +03:00
|
|
|
mTrackDemuxer->Reset();
|
2016-05-05 08:06:40 +03:00
|
|
|
mQueuedSamples.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush the decoder if present and reset decoding related data.
|
|
|
|
// Following a flush, the decoder is ready to accept any new data.
|
2017-02-24 12:27:42 +03:00
|
|
|
void Flush();
|
2015-05-25 08:09:16 +03:00
|
|
|
|
2017-02-23 16:10:12 +03:00
|
|
|
bool CancelWaitingForKey()
|
|
|
|
{
|
|
|
|
if (!mWaitingForKey) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mWaitingForKey = false;
|
2017-02-24 17:00:39 +03:00
|
|
|
if (IsWaiting() || !HasWaitingPromise()) {
|
2017-02-23 16:10:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mWaitingPromise.Resolve(mType, __func__);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:06:40 +03:00
|
|
|
// Reset the state of the DecoderData, clearing all queued frames
|
|
|
|
// (pending demuxed and decoded).
|
|
|
|
// The track demuxer is *not* reset.
|
2015-05-18 08:40:32 +03:00
|
|
|
void ResetState()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
mDemuxEOS = false;
|
|
|
|
mWaitingForData = false;
|
|
|
|
mQueuedSamples.Clear();
|
2017-01-26 15:56:46 +03:00
|
|
|
mDecodeRequest.DisconnectIfExists();
|
|
|
|
mDrainRequest.DisconnectIfExists();
|
2017-02-09 17:31:44 +03:00
|
|
|
mDrainState = DrainState::None;
|
2017-02-23 16:10:12 +03:00
|
|
|
CancelWaitingForKey();
|
2015-06-15 03:58:12 +03:00
|
|
|
mTimeThreshold.reset();
|
2015-12-08 22:30:25 +03:00
|
|
|
mLastSampleTime.reset();
|
2015-05-18 08:42:01 +03:00
|
|
|
mOutput.Clear();
|
|
|
|
mNumSamplesInput = 0;
|
|
|
|
mNumSamplesOutput = 0;
|
2015-07-15 05:27:09 +03:00
|
|
|
mSizeOfQueue = 0;
|
2015-07-13 09:25:04 +03:00
|
|
|
mNextStreamSourceID.reset();
|
2016-05-30 19:24:00 +03:00
|
|
|
if (!HasFatalError()) {
|
|
|
|
mError.reset();
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2015-05-18 08:42:01 +03:00
|
|
|
|
2016-05-05 07:52:58 +03:00
|
|
|
bool HasInternalSeekPending() const
|
|
|
|
{
|
|
|
|
return mTimeThreshold && !mTimeThreshold.ref().mHasSeeked;
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:42:01 +03:00
|
|
|
// Used by the MDSM for logging purposes.
|
|
|
|
Atomic<size_t> mSizeOfQueue;
|
2015-07-20 22:14:37 +03: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 03:58:12 +03:00
|
|
|
// Sample format monitoring.
|
|
|
|
uint32_t mLastStreamSourceID;
|
2015-07-13 09:25:04 +03:00
|
|
|
Maybe<uint32_t> mNextStreamSourceID;
|
2015-05-18 08:40:32 +03:00
|
|
|
media::TimeIntervals mTimeRanges;
|
2015-12-08 22:30:25 +03:00
|
|
|
Maybe<media::TimeUnit> mLastTimeRangesEnd;
|
2016-10-26 12:09:41 +03:00
|
|
|
// TrackInfo as first discovered during ReadMetadata.
|
|
|
|
UniquePtr<TrackInfo> mOriginalInfo;
|
2017-02-13 21:18:05 +03:00
|
|
|
RefPtr<TrackInfoSharedPtr> mInfo;
|
2016-05-16 13:15:17 +03:00
|
|
|
Maybe<media::TimeUnit> mFirstDemuxedSampleTime;
|
2016-07-29 09:51:18 +03:00
|
|
|
// Use BlankDecoderModule or not.
|
|
|
|
bool mIsBlankDecode;
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class DecoderDataWithPromise : public DecoderData
|
|
|
|
{
|
2016-05-05 08:11:21 +03:00
|
|
|
public:
|
2015-05-18 08:40:32 +03:00
|
|
|
DecoderDataWithPromise(MediaFormatReader* aOwner,
|
|
|
|
MediaData::Type aType,
|
2016-05-30 19:24:00 +03:00
|
|
|
uint32_t aNumOfMaxError)
|
2016-09-01 12:25:54 +03:00
|
|
|
: DecoderData(aOwner, aType, aNumOfMaxError)
|
2016-05-05 08:11:21 +03:00
|
|
|
, mHasPromise(false)
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-05-05 08:11:21 +03: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 08:40:32 +03:00
|
|
|
|
2016-05-05 08:11:21 +03:00
|
|
|
void ResolvePromise(MediaData* aData, const char* aMethodName) override
|
2015-05-18 08:40:32 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
2016-05-05 08:11:21 +03:00
|
|
|
mPromise.Resolve(aData, aMethodName);
|
|
|
|
mHasPromise = false;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-09-10 09:48:53 +03:00
|
|
|
void RejectPromise(const MediaResult& aError,
|
2015-05-18 08:40:32 +03:00
|
|
|
const char* aMethodName) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
2016-09-10 09:48:53 +03:00
|
|
|
mPromise.Reject(aError, aMethodName);
|
2016-05-05 08:11:21 +03:00
|
|
|
mHasPromise = false;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2016-05-05 08:11:21 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
MozPromiseHolder<MediaDataPromise> mPromise;
|
|
|
|
Atomic<bool> mHasPromise;
|
2015-05-18 08:40:32 +03:00
|
|
|
};
|
|
|
|
|
2016-04-22 09:16:56 +03:00
|
|
|
DecoderDataWithPromise mAudio;
|
|
|
|
DecoderDataWithPromise mVideo;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
// Returns true when the decoder for this track needs input.
|
|
|
|
bool NeedInput(DecoderData& aDecoder);
|
|
|
|
|
|
|
|
DecoderData& GetDecoderData(TrackType aTrack);
|
|
|
|
|
|
|
|
// Demuxer objects.
|
2016-11-28 13:08:01 +03:00
|
|
|
class DemuxerProxy;
|
|
|
|
UniquePtr<DemuxerProxy> mDemuxer;
|
2015-10-07 04:00:52 +03:00
|
|
|
bool mDemuxerInitDone;
|
2015-05-18 08:40:32 +03:00
|
|
|
void OnDemuxerInitDone(nsresult);
|
2016-09-12 05:22:20 +03:00
|
|
|
void OnDemuxerInitFailed(const MediaResult& aError);
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseRequestHolder<MediaDataDemuxer::InitPromise> mDemuxerInitRequest;
|
2016-11-28 13:08:01 +03:00
|
|
|
MozPromiseRequestHolder<NotifyDataArrivedPromise> mNotifyDataArrivedPromise;
|
|
|
|
void OnDemuxFailed(TrackType aTrack, const MediaResult &aError);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
void DoDemuxVideo();
|
2015-10-18 08:24:48 +03:00
|
|
|
void OnVideoDemuxCompleted(RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples);
|
2016-09-12 05:22:20 +03:00
|
|
|
void OnVideoDemuxFailed(const MediaResult& aError)
|
2015-05-18 08:40:32 +03:00
|
|
|
{
|
2016-09-12 05:22:20 +03:00
|
|
|
OnDemuxFailed(TrackType::kVideoTrack, aError);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoDemuxAudio();
|
2015-10-18 08:24:48 +03:00
|
|
|
void OnAudioDemuxCompleted(RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples);
|
2016-09-12 05:22:20 +03:00
|
|
|
void OnAudioDemuxFailed(const MediaResult& aError)
|
2015-05-18 08:40:32 +03:00
|
|
|
{
|
2016-09-12 05:22:20 +03:00
|
|
|
OnDemuxFailed(TrackType::kAudioTrack, aError);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkipVideoDemuxToNextKeyFrame(media::TimeUnit aTimeThreshold);
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseRequestHolder<MediaTrackDemuxer::SkipAccessPointPromise> mSkipRequest;
|
2016-05-19 10:02:43 +03:00
|
|
|
void VideoSkipReset(uint32_t aSkipped);
|
2015-05-18 08:40:32 +03: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;
|
|
|
|
|
2016-07-26 02:36:55 +03:00
|
|
|
// Timestamp of the previous decoded keyframe, in microseconds.
|
|
|
|
int64_t mPreviousDecodedKeyframeTime_us;
|
|
|
|
// Default mLastDecodedKeyframeTime_us value, must be bigger than anything.
|
|
|
|
static const int64_t sNoPreviousDecodedKeyframe = INT64_MAX;
|
|
|
|
|
2016-10-07 11:13:33 +03:00
|
|
|
RefPtr<layers::KnowsCompositor> mKnowsCompositor;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
// Metadata objects
|
|
|
|
// True if we've read the streams' metadata.
|
|
|
|
bool mInitDone;
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseHolder<MetadataPromise> mMetadataPromise;
|
2016-09-28 03:34:57 +03:00
|
|
|
bool IsEncrypted() const;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-06-12 02:26:58 +03:00
|
|
|
// Set to true if any of our track buffers may be blocking.
|
|
|
|
bool mTrackDemuxersMayBlock;
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
// Seeking objects.
|
2016-05-16 13:15:17 +03:00
|
|
|
void SetSeekTarget(const SeekTarget& aTarget);
|
2015-05-18 08:40:32 +03:00
|
|
|
bool IsSeeking() const { return mPendingSeekTime.isSome(); }
|
2016-05-16 11:15:45 +03:00
|
|
|
bool IsVideoSeeking() const
|
|
|
|
{
|
|
|
|
return IsSeeking() && mOriginalSeekTarget.IsVideoOnly();
|
|
|
|
}
|
2016-05-05 08:01:51 +03:00
|
|
|
void ScheduleSeek();
|
2015-05-18 08:40:32 +03:00
|
|
|
void AttemptSeek();
|
2016-09-12 05:22:20 +03:00
|
|
|
void OnSeekFailed(TrackType aTrack, const MediaResult& aError);
|
2015-05-18 08:40:32 +03:00
|
|
|
void DoVideoSeek();
|
|
|
|
void OnVideoSeekCompleted(media::TimeUnit aTime);
|
2016-09-12 05:22:20 +03:00
|
|
|
void OnVideoSeekFailed(const MediaResult& aError);
|
2016-05-05 08:01:51 +03:00
|
|
|
bool mSeekScheduled;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-11-08 05:23:12 +03:00
|
|
|
void NotifyCompositorUpdated(RefPtr<layers::KnowsCompositor> aKnowsCompositor)
|
|
|
|
{
|
2016-11-15 01:15:53 +03:00
|
|
|
mKnowsCompositor = aKnowsCompositor.forget();
|
2016-11-08 05:23:12 +03:00
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
void DoAudioSeek();
|
|
|
|
void OnAudioSeekCompleted(media::TimeUnit aTime);
|
2016-09-12 05:22:20 +03:00
|
|
|
void OnAudioSeekFailed(const MediaResult& aError);
|
2016-05-16 09:47:57 +03:00
|
|
|
// The SeekTarget that was last given to Seek()
|
|
|
|
SeekTarget mOriginalSeekTarget;
|
2015-05-18 08:40:32 +03:00
|
|
|
// Temporary seek information while we wait for the data
|
2016-05-16 09:47:57 +03:00
|
|
|
Maybe<media::TimeUnit> mFallbackSeekTime;
|
2015-05-18 08:40:32 +03:00
|
|
|
Maybe<media::TimeUnit> mPendingSeekTime;
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseHolder<SeekPromise> mSeekPromise;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VideoFrameContainer> mVideoFrameContainer;
|
2015-10-15 03:04:00 +03:00
|
|
|
layers::ImageContainer* GetImageContainer();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CDMProxy> mCDMProxy;
|
2016-09-08 13:06:20 +03:00
|
|
|
|
2016-06-29 02:42:07 +03:00
|
|
|
RefPtr<GMPCrashHelper> mCrashHelper;
|
2016-07-29 09:51:18 +03:00
|
|
|
|
|
|
|
void SetBlankDecode(TrackType aTrack, bool aIsBlankDecode);
|
2016-10-26 12:37:19 +03:00
|
|
|
|
|
|
|
class DecoderFactory;
|
|
|
|
UniquePtr<DecoderFactory> mDecoderFactory;
|
2016-11-08 05:23:12 +03:00
|
|
|
|
2017-02-17 14:29:43 +03:00
|
|
|
class ShutdownPromisePool;
|
|
|
|
UniquePtr<ShutdownPromisePool> mShutdownPromisePool;
|
|
|
|
|
2016-11-08 05:23:12 +03:00
|
|
|
MediaEventListener mCompositorUpdatedListener;
|
2017-01-27 13:48:00 +03:00
|
|
|
MediaEventListener mOnTrackWaitingForKeyListener;
|
2016-10-27 10:21:05 +03:00
|
|
|
|
|
|
|
void OnFirstDemuxCompleted(TrackInfo::TrackType aType,
|
|
|
|
RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples);
|
|
|
|
|
|
|
|
void OnFirstDemuxFailed(TrackInfo::TrackType aType, const MediaResult& aError);
|
|
|
|
|
|
|
|
void MaybeResolveMetadataPromise();
|
|
|
|
|
|
|
|
UniquePtr<MetadataTags> mTags;
|
2016-11-25 11:47:02 +03:00
|
|
|
|
|
|
|
// A flag indicating if the start time is known or not.
|
|
|
|
bool mHasStartTime = false;
|
2017-01-26 15:56:46 +03:00
|
|
|
|
|
|
|
void ShutdownDecoder(TrackType aTrack);
|
2017-02-17 14:34:03 +03:00
|
|
|
RefPtr<ShutdownPromise> TearDownDecoders();
|
2015-05-18 08:40:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|