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"
|
2017-07-13 12:39:42 +03:00
|
|
|
#include "mozilla/StateMirroring.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
|
|
|
|
2017-07-13 12:39:42 +03:00
|
|
|
#include "FrameStatistics.h"
|
2016-11-08 05:23:12 +03:00
|
|
|
#include "MediaEventSource.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
#include "MediaDataDemuxer.h"
|
2017-07-20 04:56:08 +03:00
|
|
|
#include "MediaMetadataManager.h"
|
2017-03-03 08:10:48 +03:00
|
|
|
#include "MediaPrefs.h"
|
2017-11-03 15:12:39 +03:00
|
|
|
#include "MediaPromiseDefs.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2015-10-06 11:56:29 +03:00
|
|
|
#include "PDMFactory.h"
|
2017-07-20 04:56:08 +03:00
|
|
|
#include "SeekTarget.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-09-27 13:40:03 +03:00
|
|
|
class CDMProxy;
|
2017-07-19 17:18:37 +03:00
|
|
|
class GMPCrashHelper;
|
2017-07-20 04:56:08 +03:00
|
|
|
class MediaResource;
|
2017-07-19 17:18:37 +03:00
|
|
|
class VideoFrameContainer;
|
2015-09-27 13:40:03 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
struct WaitForDataRejectValue
|
|
|
|
{
|
|
|
|
enum Reason
|
|
|
|
{
|
|
|
|
SHUTDOWN,
|
|
|
|
CANCELED
|
|
|
|
};
|
|
|
|
|
|
|
|
WaitForDataRejectValue(MediaData::Type aType, Reason aReason)
|
|
|
|
: mType(aType)
|
|
|
|
, mReason(aReason)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
MediaData::Type mType;
|
|
|
|
Reason mReason;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SeekRejectValue
|
|
|
|
{
|
|
|
|
MOZ_IMPLICIT SeekRejectValue(const MediaResult& aError)
|
|
|
|
: mType(MediaData::NULL_DATA)
|
|
|
|
, mError(aError)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
MOZ_IMPLICIT SeekRejectValue(nsresult aResult)
|
|
|
|
: mType(MediaData::NULL_DATA)
|
|
|
|
, mError(aResult)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
SeekRejectValue(MediaData::Type aType, const MediaResult& aError)
|
|
|
|
: mType(aType)
|
|
|
|
, mError(aError)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
MediaData::Type mType;
|
|
|
|
MediaResult mError;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MetadataHolder
|
|
|
|
{
|
|
|
|
UniquePtr<MediaInfo> mInfo;
|
|
|
|
UniquePtr<MetadataTags> mTags;
|
|
|
|
};
|
|
|
|
|
2017-08-31 12:31:51 +03:00
|
|
|
typedef void* MediaDecoderOwnerID;
|
|
|
|
|
2017-07-19 17:18:37 +03:00
|
|
|
struct MOZ_STACK_CLASS MediaFormatReaderInit
|
|
|
|
{
|
|
|
|
MediaResource* mResource = nullptr;
|
|
|
|
VideoFrameContainer* mVideoFrameContainer = nullptr;
|
2017-07-07 06:05:03 +03:00
|
|
|
FrameStatistics* mFrameStats = nullptr;
|
2017-07-19 17:18:37 +03:00
|
|
|
already_AddRefed<layers::KnowsCompositor> mKnowsCompositor;
|
|
|
|
already_AddRefed<GMPCrashHelper> mCrashHelper;
|
2017-08-31 12:31:51 +03:00
|
|
|
// Used in bug 1393399 for temporary telemetry.
|
|
|
|
MediaDecoderOwnerID mMediaDecoderOwnerID = nullptr;
|
2017-07-19 17:18:37 +03:00
|
|
|
};
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLoggedTypeDeclName(MediaFormatReader);
|
|
|
|
|
2017-07-19 17:18:37 +03:00
|
|
|
class MediaFormatReader final
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
: public DecoderDoctorLifeLogger<MediaFormatReader>
|
2015-05-18 08:40:32 +03:00
|
|
|
{
|
2017-07-19 12:34:05 +03:00
|
|
|
static const bool IsExclusive = true;
|
2015-05-18 08:40:32 +03:00
|
|
|
typedef TrackInfo::TrackType TrackType;
|
2017-07-19 12:34:05 +03:00
|
|
|
typedef MozPromise<bool, MediaResult, IsExclusive> NotifyDataArrivedPromise;
|
2017-07-19 17:18:37 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaFormatReader)
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
public:
|
2017-07-19 12:34:05 +03:00
|
|
|
using TrackSet = EnumSet<TrackInfo::TrackType>;
|
|
|
|
using MetadataPromise = MozPromise<MetadataHolder, MediaResult, IsExclusive>;
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
using DataPromise = MozPromise<RefPtr<Type>, MediaResult, IsExclusive>;
|
|
|
|
using AudioDataPromise = DataPromise<AudioData>;
|
|
|
|
using VideoDataPromise = DataPromise<VideoData>;
|
|
|
|
|
|
|
|
using SeekPromise = MozPromise<media::TimeUnit, SeekRejectValue, IsExclusive>;
|
|
|
|
|
|
|
|
// Note that, conceptually, WaitForData makes sense in a non-exclusive sense.
|
|
|
|
// But in the current architecture it's only ever used exclusively (by MDSM),
|
|
|
|
// so we mark it that way to verify our assumptions. If you have a use-case
|
|
|
|
// for multiple WaitForData consumers, feel free to flip the exclusivity here.
|
|
|
|
using WaitForDataPromise =
|
|
|
|
MozPromise<MediaData::Type, WaitForDataRejectValue, IsExclusive>;
|
|
|
|
|
2017-07-19 17:18:37 +03:00
|
|
|
MediaFormatReader(MediaFormatReaderInit& aInit, MediaDataDemuxer* aDemuxer);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
|
|
|
|
// on failure.
|
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
size_t SizeOfVideoQueueInFrames();
|
|
|
|
size_t SizeOfAudioQueueInFrames();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Requests one video sample from the reader.
|
|
|
|
RefPtr<VideoDataPromise> RequestVideoData(
|
|
|
|
const media::TimeUnit& aTimeThreshold);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Requests one audio sample from the reader.
|
|
|
|
//
|
|
|
|
// The decode should be performed asynchronously, and the promise should
|
|
|
|
// be resolved when it is complete.
|
|
|
|
RefPtr<AudioDataPromise> RequestAudioData();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// The default implementation of AsyncReadMetadata is implemented in terms of
|
|
|
|
// synchronous ReadMetadata() calls. Implementations may also
|
|
|
|
// override AsyncReadMetadata to create a more proper async implementation.
|
|
|
|
RefPtr<MetadataPromise> AsyncReadMetadata();
|
2015-10-21 05:59:56 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Fills aInfo with the latest cached data required to present the media,
|
|
|
|
// ReadUpdatedMetadata will always be called once ReadMetadata has succeeded.
|
|
|
|
void ReadUpdatedMetadata(MediaInfo* aInfo);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
RefPtr<SeekPromise> Seek(const SeekTarget& aTarget);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Called once new data has been cached by the MediaResource.
|
|
|
|
// mBuffered should be recalculated and updated accordingly.
|
|
|
|
void NotifyDataArrived();
|
2017-07-19 12:01:32 +03:00
|
|
|
|
|
|
|
protected:
|
2017-07-19 12:34:05 +03:00
|
|
|
// Recomputes mBuffered.
|
|
|
|
void UpdateBuffered();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-10-26 09:10:29 +03:00
|
|
|
public:
|
2017-07-19 12:34:05 +03:00
|
|
|
// Called by MDSM in dormant state to release resources allocated by this
|
|
|
|
// reader. The reader can resume decoding by calling Seek() to a specific
|
|
|
|
// position.
|
|
|
|
void ReleaseResources();
|
|
|
|
|
|
|
|
bool OnTaskQueue() const { return OwnerThread()->IsCurrentThreadIn(); }
|
|
|
|
|
|
|
|
// Resets all state related to decoding, emptying all buffers etc.
|
|
|
|
// Cancels all pending Request*Data() request callbacks, rejects any
|
|
|
|
// outstanding seek promises, and flushes the decode pipeline. The
|
|
|
|
// decoder must not call any of the callbacks for outstanding
|
|
|
|
// Request*Data() calls after this is called. Calls to Request*Data()
|
|
|
|
// made after this should be processed as usual.
|
|
|
|
//
|
|
|
|
// Normally this call preceedes a Seek() call, or shutdown.
|
|
|
|
//
|
|
|
|
// aParam is a set of TrackInfo::TrackType enums specifying which
|
|
|
|
// queues need to be reset, defaulting to both audio and video tracks.
|
|
|
|
nsresult ResetDecode(TrackSet aTracks);
|
|
|
|
|
|
|
|
// Destroys the decoding state. The reader cannot be made usable again.
|
|
|
|
// This is different from ReleaseMediaResources() as it is irreversable,
|
|
|
|
// whereas ReleaseMediaResources() is. Must be called on the decode
|
|
|
|
// thread.
|
|
|
|
RefPtr<ShutdownPromise> Shutdown();
|
|
|
|
|
|
|
|
// Returns true if this decoder reader uses hardware accelerated video
|
|
|
|
// decoding.
|
|
|
|
bool VideoIsHardwareAccelerated() const;
|
|
|
|
|
|
|
|
// By default, the state machine polls the reader once per second when it's
|
|
|
|
// in buffering mode. Some readers support a promise-based mechanism by which
|
|
|
|
// they notify the state machine when the data arrives.
|
|
|
|
bool IsWaitForDataSupported() const { return true; }
|
|
|
|
|
|
|
|
RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType);
|
|
|
|
|
|
|
|
// The MediaDecoderStateMachine uses various heuristics that assume that
|
|
|
|
// raw media data is arriving sequentially from a network channel. This
|
|
|
|
// makes sense in the <video src="foo"> case, but not for more advanced use
|
|
|
|
// cases like MSE.
|
|
|
|
bool UseBufferingHeuristics() const { return mTrackDemuxersMayBlock; }
|
|
|
|
|
2017-11-03 15:12:39 +03:00
|
|
|
RefPtr<SetCDMPromise> SetCDMProxy(CDMProxy* aProxy);
|
2015-10-21 09:04:20 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Returns a string describing the state of the decoder data.
|
|
|
|
// Used for debugging purposes.
|
|
|
|
void GetMozDebugReaderData(nsACString& aString);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Switch the video decoder to NullDecoderModule. It might takes effective
|
|
|
|
// since a few samples later depends on how much demuxed samples are already
|
|
|
|
// queued in the original video decoder.
|
|
|
|
void SetVideoNullDecode(bool aIsNullDecode);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
void UpdateCompositor(already_AddRefed<layers::KnowsCompositor>);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
void UpdateDuration(const media::TimeUnit& aDuration)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
UpdateBuffered();
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
AbstractCanonical<media::TimeIntervals>* CanonicalBuffered()
|
2015-06-12 02:26:58 +03:00
|
|
|
{
|
2017-07-19 12:34:05 +03:00
|
|
|
return &mBuffered;
|
2015-06-12 02:26:58 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
TaskQueue* OwnerThread() const { return mTaskQueue; }
|
2015-09-27 13:40:03 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
TimedMetadataEventSource& TimedMetadataEvent() { return mTimedMetadataEvent; }
|
2016-01-18 02:21:59 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Notified by the OggDemuxer during playback when chained ogg is detected.
|
|
|
|
MediaEventSource<void>& OnMediaNotSeekable() { return mOnMediaNotSeekable; }
|
2016-07-29 09:51:18 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
TimedMetadataEventProducer& TimedMetadataProducer()
|
|
|
|
{
|
|
|
|
return mTimedMetadataEvent;
|
|
|
|
}
|
2017-07-12 11:28:19 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
MediaEventProducer<void>& MediaNotSeekableProducer()
|
|
|
|
{
|
|
|
|
return mOnMediaNotSeekable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notified if the reader can't decode a sample due to a missing decryption
|
|
|
|
// key.
|
|
|
|
MediaEventSource<TrackInfo::TrackType>& OnTrackWaitingForKey()
|
|
|
|
{
|
|
|
|
return mOnTrackWaitingForKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaEventProducer<TrackInfo::TrackType>& OnTrackWaitingForKeyProducer()
|
|
|
|
{
|
|
|
|
return mOnTrackWaitingForKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaEventSource<nsTArray<uint8_t>, nsString>& OnEncrypted()
|
|
|
|
{
|
|
|
|
return mOnEncrypted;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaEventSource<void>& OnWaitingForKey() { return mOnWaitingForKey; }
|
|
|
|
|
|
|
|
MediaEventSource<MediaResult>& OnDecodeWarning() { return mOnDecodeWarning; }
|
2016-06-08 15:28:24 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
private:
|
2017-07-19 17:18:37 +03:00
|
|
|
~MediaFormatReader();
|
|
|
|
|
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,
|
2017-07-13 10:17:25 +03:00
|
|
|
FrameStatistics::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
|
|
|
|
2017-06-12 10:01:29 +03:00
|
|
|
bool ShouldSkip(media::TimeUnit aTimeThreshold);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
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)
|
2017-05-11 11:29:57 +03:00
|
|
|
, mFirstFrameTime(Some(media::TimeUnit::Zero()))
|
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)
|
2017-03-09 12:12:02 +03:00
|
|
|
, mIsNullDecode(false)
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LogConstruction("MediaFormatReader::DecoderData",
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~DecoderData()
|
|
|
|
{
|
|
|
|
DecoderDoctorLogger::LogDestruction("MediaFormatReader::DecoderData",
|
|
|
|
this);
|
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;
|
2017-09-01 15:25:28 +03:00
|
|
|
nsCString 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();
|
|
|
|
}
|
2017-11-14 10:20:08 +03:00
|
|
|
|
|
|
|
bool IsWaitingForData() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
return mWaitingForData;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsWaitingForKey() const
|
2016-10-27 12:25:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
2017-11-14 10:20:08 +03:00
|
|
|
return mWaitingForKey && mDecodeRequest.Exists();
|
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;
|
|
|
|
}
|
2017-03-07 12:13:39 +03:00
|
|
|
bool HasCompletedDrain() const
|
|
|
|
{
|
|
|
|
return mDrainState == DrainState::DrainCompleted ||
|
|
|
|
mDrainState == DrainState::DrainAborted;
|
|
|
|
}
|
2017-02-09 17:31:44 +03:00
|
|
|
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;
|
2017-05-11 11:29:57 +03:00
|
|
|
// Set when we haven't yet decoded the first frame.
|
|
|
|
// Cleared once the first frame has been decoded.
|
|
|
|
// This is used to determine, upon error, if we should try again to decode
|
|
|
|
// the frame, or skip to the next keyframe.
|
|
|
|
Maybe<media::TimeUnit> mFirstFrameTime;
|
2016-05-30 19:24:00 +03:00
|
|
|
|
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
|
2017-03-03 08:10:48 +03:00
|
|
|
// if we have too many, or if warnings should be treated as errors.
|
2017-09-04 12:27:43 +03:00
|
|
|
return mNumOfConsecutiveError > mMaxConsecutiveError ||
|
|
|
|
MediaPrefs::MediaWarningsAsErrors();
|
2016-11-08 05:22:37 +03:00
|
|
|
} 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;
|
2017-05-11 11:29:57 +03:00
|
|
|
// Time of last decoded sample returned.
|
|
|
|
Maybe<media::TimeInterval> mLastDecodedSampleTime;
|
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;
|
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-11-14 10:20:08 +03:00
|
|
|
if (IsWaitingForData() || !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();
|
2017-05-11 11:29:57 +03:00
|
|
|
mLastDecodedSampleTime.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;
|
2017-03-09 12:12:02 +03:00
|
|
|
// Use NullDecoderModule or not.
|
|
|
|
bool mIsNullDecode;
|
2016-07-29 09:51:18 +03:00
|
|
|
|
2017-09-12 22:20:09 +03:00
|
|
|
class
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
float Mean() const { return mMean; }
|
|
|
|
|
|
|
|
void Update(const media::TimeUnit& aValue)
|
|
|
|
{
|
|
|
|
if (aValue == media::TimeUnit::Zero()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMean += (1.0f / aValue.ToSeconds() - mMean) / ++mCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mMean = 0;
|
|
|
|
mCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float mMean = 0;
|
|
|
|
uint64_t mCount = 0;
|
|
|
|
} mMeanRate;
|
2015-05-18 08:40:32 +03:00
|
|
|
};
|
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
template <typename Type>
|
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
|
|
|
{
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LogConstructionAndBase(
|
|
|
|
"MediaFormatReader::DecoderDataWithPromise",
|
|
|
|
this,
|
|
|
|
"MediaFormatReader::DecoderData",
|
|
|
|
static_cast<const MediaFormatReader::DecoderData*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
~DecoderDataWithPromise()
|
|
|
|
{
|
|
|
|
DecoderDoctorLogger::LogDestruction(
|
|
|
|
"MediaFormatReader::DecoderDataWithPromise", this);
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
RefPtr<DataPromise<Type>> EnsurePromise(const char* aMethodName)
|
2016-05-05 08:11:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwner->OnTaskQueue());
|
|
|
|
mHasPromise = true;
|
|
|
|
return mPromise.Ensure(aMethodName);
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
void ResolvePromise(Type* aData, const char* aMethodName)
|
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:
|
2017-03-22 06:28:33 +03:00
|
|
|
MozPromiseHolder<DataPromise<Type>> mPromise;
|
2016-05-05 08:11:21 +03:00
|
|
|
Atomic<bool> mHasPromise;
|
2015-05-18 08:40:32 +03:00
|
|
|
};
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
// Decode task queue.
|
|
|
|
RefPtr<TaskQueue> mTaskQueue;
|
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
DecoderDataWithPromise<AudioData> mAudio;
|
|
|
|
DecoderDataWithPromise<VideoData> 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;
|
2017-03-06 07:22:17 +03:00
|
|
|
void OnDemuxerInitDone(const MediaResult& aResult);
|
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;
|
2017-03-15 10:20:45 +03:00
|
|
|
bool mPendingNotifyDataArrived;
|
2016-11-28 13:08:01 +03:00
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-09 12:12:02 +03:00
|
|
|
void SetNullDecode(TrackType aTrack, bool aIsNullDecode);
|
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;
|
|
|
|
|
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();
|
|
|
|
|
2017-07-19 09:27:24 +03:00
|
|
|
// Stores presentation info required for playback.
|
|
|
|
MediaInfo mInfo;
|
|
|
|
|
2016-10-27 10:21:05 +03:00
|
|
|
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();
|
2017-07-19 12:34:05 +03:00
|
|
|
|
|
|
|
bool mShutdown = false;
|
|
|
|
|
|
|
|
// Buffered range.
|
|
|
|
Canonical<media::TimeIntervals> mBuffered;
|
|
|
|
|
|
|
|
// Used to send TimedMetadata to the listener.
|
|
|
|
TimedMetadataEventProducer mTimedMetadataEvent;
|
|
|
|
|
|
|
|
// Notify if this media is not seekable.
|
|
|
|
MediaEventProducer<void> mOnMediaNotSeekable;
|
|
|
|
|
|
|
|
// Notify if we are waiting for a decryption key.
|
|
|
|
MediaEventProducer<TrackInfo::TrackType> mOnTrackWaitingForKey;
|
|
|
|
|
|
|
|
MediaEventProducer<nsTArray<uint8_t>, nsString> mOnEncrypted;
|
|
|
|
|
|
|
|
MediaEventProducer<void> mOnWaitingForKey;
|
|
|
|
|
|
|
|
MediaEventProducer<MediaResult> mOnDecodeWarning;
|
2017-07-07 06:05:03 +03:00
|
|
|
|
|
|
|
RefPtr<FrameStatistics> mFrameStats;
|
2017-08-31 12:31:51 +03:00
|
|
|
|
|
|
|
// Used in bug 1393399 for telemetry.
|
|
|
|
const MediaDecoderOwnerID mMediaDecoderOwnerID;
|
2017-11-03 15:12:39 +03:00
|
|
|
|
2017-11-03 15:14:49 +03:00
|
|
|
bool ResolveSetCDMPromiseIfDone(TrackType aTrack);
|
|
|
|
void PrepareToSetCDMForTrack(TrackType aTrack);
|
2017-11-03 15:12:39 +03:00
|
|
|
MozPromiseHolder<SetCDMPromise> mSetCDMPromise;
|
|
|
|
TrackSet mSetCDMForTracks{};
|
2017-11-03 15:14:49 +03:00
|
|
|
bool IsDecoderWaitingForCDM(TrackType aTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|