2014-02-04 05:49:21 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2012-11-14 23:46:40 +04:00
|
|
|
#if !defined(MediaDecoderReader_h_)
|
|
|
|
#define MediaDecoderReader_h_
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2015-07-16 21:52:43 +03:00
|
|
|
#include "mozilla/MozPromise.h"
|
|
|
|
|
2013-09-06 00:25:17 +04:00
|
|
|
#include "AbstractMediaDecoder.h"
|
2014-02-04 05:49:21 +04:00
|
|
|
#include "MediaInfo.h"
|
|
|
|
#include "MediaData.h"
|
2015-09-07 06:37:32 +03:00
|
|
|
#include "MediaMetadataManager.h"
|
2014-02-04 05:49:21 +04:00
|
|
|
#include "MediaQueue.h"
|
2015-06-19 23:45:09 +03:00
|
|
|
#include "MediaTimer.h"
|
2014-02-06 03:11:25 +04:00
|
|
|
#include "AudioCompactor.h"
|
2015-06-19 23:45:09 +03:00
|
|
|
#include "Intervals.h"
|
2015-05-18 09:15:47 +03:00
|
|
|
#include "TimeUnits.h"
|
2012-11-07 02:33:01 +04:00
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2015-09-27 13:40:03 +03:00
|
|
|
class CDMProxy;
|
2014-06-20 15:08:24 +04:00
|
|
|
class MediaDecoderReader;
|
|
|
|
|
2015-03-20 22:53:32 +03:00
|
|
|
struct WaitForDataRejectValue
|
|
|
|
{
|
2014-12-22 11:20:31 +03:00
|
|
|
enum Reason {
|
2015-02-04 05:17:56 +03:00
|
|
|
SHUTDOWN,
|
|
|
|
CANCELED
|
2014-12-22 11:20:31 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
WaitForDataRejectValue(MediaData::Type aType, Reason aReason)
|
|
|
|
:mType(aType), mReason(aReason) {}
|
|
|
|
MediaData::Type mType;
|
|
|
|
Reason mReason;
|
|
|
|
};
|
|
|
|
|
2015-03-20 22:53:32 +03:00
|
|
|
class MetadataHolder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MetadataHolder)
|
|
|
|
MediaInfo mInfo;
|
|
|
|
nsAutoPtr<MetadataTags> mTags;
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~MetadataHolder() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ReadMetadataFailureReason : int8_t
|
|
|
|
{
|
|
|
|
METADATA_ERROR
|
|
|
|
};
|
|
|
|
|
2014-06-18 09:07:02 +04:00
|
|
|
// Encapsulates the decoding and reading of media data. Reading can either
|
|
|
|
// synchronous and done on the calling "decode" thread, or asynchronous and
|
|
|
|
// performed on a background thread, with the result being returned by
|
|
|
|
// callback. Never hold the decoder monitor when calling into this class.
|
|
|
|
// Unless otherwise specified, methods and fields of this class can only
|
|
|
|
// be accessed on the decode task queue.
|
2012-11-16 23:30:34 +04:00
|
|
|
class MediaDecoderReader {
|
2015-10-26 06:25:25 +03:00
|
|
|
friend class ReRequestVideoWithSkipTask;
|
|
|
|
friend class ReRequestAudioTask;
|
|
|
|
|
2015-10-26 06:29:48 +03:00
|
|
|
static const bool IsExclusive = true;
|
|
|
|
|
2010-04-02 07:03:07 +04:00
|
|
|
public:
|
2014-12-09 01:45:36 +03:00
|
|
|
enum NotDecodedReason {
|
|
|
|
END_OF_STREAM,
|
|
|
|
DECODE_ERROR,
|
|
|
|
WAITING_FOR_DATA,
|
|
|
|
CANCELED
|
|
|
|
};
|
|
|
|
|
2015-10-26 06:29:48 +03:00
|
|
|
using MetadataPromise =
|
|
|
|
MozPromise<RefPtr<MetadataHolder>, ReadMetadataFailureReason, IsExclusive>;
|
|
|
|
using AudioDataPromise =
|
|
|
|
MozPromise<RefPtr<MediaData>, NotDecodedReason, IsExclusive>;
|
|
|
|
using VideoDataPromise =
|
|
|
|
MozPromise<RefPtr<MediaData>, NotDecodedReason, IsExclusive>;
|
|
|
|
using SeekPromise = MozPromise<int64_t, nsresult, IsExclusive>;
|
2015-01-22 01:34:26 +03:00
|
|
|
|
|
|
|
// 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.
|
2015-10-26 06:29:48 +03:00
|
|
|
using WaitForDataPromise =
|
|
|
|
MozPromise<MediaData::Type, WaitForDataRejectValue, IsExclusive>;
|
2014-12-11 01:03:56 +03:00
|
|
|
|
2014-06-18 09:07:02 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderReader)
|
|
|
|
|
2015-02-10 05:50:02 +03:00
|
|
|
// The caller must ensure that Shutdown() is called before aDecoder is
|
|
|
|
// destroyed.
|
2015-10-09 04:25:23 +03:00
|
|
|
explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder);
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2010-05-06 06:31:02 +04:00
|
|
|
// Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
|
|
|
|
// on failure.
|
2015-10-13 10:28:57 +03:00
|
|
|
virtual nsresult Init() { return NS_OK; }
|
2010-05-06 06:31:02 +04:00
|
|
|
|
2013-06-10 16:22:05 +04:00
|
|
|
// Release media resources they should be released in dormant state
|
2014-06-18 09:07:02 +04:00
|
|
|
// The reader can be made usable again by calling ReadMetadata().
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual void ReleaseMediaResources() {}
|
2014-06-18 09:07:02 +04:00
|
|
|
// Breaks reference-counted cycles. Called during shutdown.
|
|
|
|
// WARNING: If you override this, you must call the base implementation
|
|
|
|
// in your override.
|
|
|
|
virtual void BreakCycles();
|
|
|
|
|
|
|
|
// Destroys the decoding state. The reader cannot be made usable again.
|
|
|
|
// This is different from ReleaseMediaResources() as it is irreversable,
|
2014-11-25 04:09:19 +03:00
|
|
|
// whereas ReleaseMediaResources() is. Must be called on the decode
|
|
|
|
// thread.
|
2015-10-18 08:24:48 +03:00
|
|
|
virtual RefPtr<ShutdownPromise> Shutdown();
|
2014-06-18 09:07:02 +04:00
|
|
|
|
2015-09-30 01:55:20 +03:00
|
|
|
virtual bool OnTaskQueue() const
|
2014-12-02 08:51:03 +03:00
|
|
|
{
|
2015-07-16 21:31:21 +03:00
|
|
|
return OwnerThread()->IsCurrentThreadIn();
|
2014-12-02 08:51:03 +03:00
|
|
|
}
|
2013-06-10 16:22:05 +04:00
|
|
|
|
2010-05-06 06:31:02 +04:00
|
|
|
// Resets all state related to decoding, emptying all buffers etc.
|
2015-02-21 02:34:34 +03:00
|
|
|
// 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.
|
|
|
|
//
|
2014-06-18 09:07:02 +04:00
|
|
|
// Normally this call preceedes a Seek() call, or shutdown.
|
2015-02-21 02:34:34 +03:00
|
|
|
//
|
2014-06-18 09:07:02 +04:00
|
|
|
// The first samples of every stream produced after a ResetDecode() call
|
|
|
|
// *must* be marked as "discontinuities". If it's not, seeking work won't
|
|
|
|
// properly!
|
2010-05-06 06:31:02 +04:00
|
|
|
virtual nsresult ResetDecode();
|
|
|
|
|
2014-12-11 01:03:56 +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. Don't hold the decoder
|
2014-06-18 09:07:02 +04:00
|
|
|
// monitor while calling this, as the implementation may try to wait
|
|
|
|
// on something that needs the monitor and deadlock.
|
2015-10-18 08:24:48 +03:00
|
|
|
virtual RefPtr<AudioDataPromise> RequestAudioData();
|
2014-06-18 09:07:02 +04:00
|
|
|
|
2014-12-11 01:03:56 +03:00
|
|
|
// Requests one video sample from the reader.
|
|
|
|
//
|
|
|
|
// Don't hold the decoder monitor while calling this, as the implementation
|
|
|
|
// may try to wait on something that needs the monitor and deadlock.
|
2014-06-18 09:07:02 +04:00
|
|
|
// If aSkipToKeyframe is true, the decode should skip ahead to the
|
|
|
|
// the next keyframe at or after aTimeThreshold microseconds.
|
2015-10-18 08:24:48 +03:00
|
|
|
virtual RefPtr<VideoDataPromise>
|
2015-08-24 04:32:49 +03:00
|
|
|
RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThreshold);
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2014-12-22 11:20:31 +03:00
|
|
|
// 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.
|
|
|
|
virtual bool IsWaitForDataSupported() { return false; }
|
2015-10-26 06:29:48 +03:00
|
|
|
|
|
|
|
virtual RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType)
|
|
|
|
{
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2014-12-22 11:20:31 +03:00
|
|
|
|
2015-10-20 12:33:00 +03:00
|
|
|
// By default, the reader return the decoded data. Some readers support
|
|
|
|
// retuning demuxed data.
|
|
|
|
virtual bool IsDemuxOnlySupported() const { return false; }
|
|
|
|
|
|
|
|
// Configure the reader to return demuxed or decoded data
|
|
|
|
// upon calls to Request{Audio,Video}Data.
|
|
|
|
virtual void SetDemuxOnly(bool /*aDemuxedOnly*/) {}
|
|
|
|
|
2015-10-21 05:59:56 +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.
|
|
|
|
virtual RefPtr<MetadataPromise> AsyncReadMetadata();
|
|
|
|
|
2014-11-06 12:52:44 +03:00
|
|
|
// Fills aInfo with the latest cached data required to present the media,
|
|
|
|
// ReadUpdatedMetadata will always be called once ReadMetadata has succeeded.
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual void ReadUpdatedMetadata(MediaInfo* aInfo) {}
|
2014-11-06 12:52:44 +03:00
|
|
|
|
2015-01-16 21:57:59 +03:00
|
|
|
// Moves the decode head to aTime microseconds. aEndTime denotes the end
|
|
|
|
// time of the media in usecs. This is only needed for OggReader, and should
|
|
|
|
// probably be removed somehow.
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual RefPtr<SeekPromise> Seek(int64_t aTime, int64_t aEndTime) = 0;
|
2013-01-24 16:38:32 +04:00
|
|
|
|
2014-05-19 06:23:00 +04:00
|
|
|
// Called to move the reader into idle state. When the reader is
|
2014-03-11 07:44:10 +04:00
|
|
|
// created it is assumed to be active (i.e. not idle). When the media
|
|
|
|
// element is paused and we don't need to decode any more data, the state
|
|
|
|
// machine calls SetIdle() to inform the reader that its decoder won't be
|
2014-05-19 06:23:00 +04:00
|
|
|
// needed for a while. The reader can use these notifications to enter
|
|
|
|
// a low power state when the decoder isn't needed, if desired.
|
|
|
|
// This is most useful on mobile.
|
|
|
|
// Note: DecodeVideoFrame, DecodeAudioData, ReadMetadata and Seek should
|
|
|
|
// activate the decoder if necessary. The state machine only needs to know
|
|
|
|
// when to call SetIdle().
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual void SetIdle() {}
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2015-09-27 13:40:03 +03:00
|
|
|
#ifdef MOZ_EME
|
|
|
|
virtual void SetCDMProxy(CDMProxy* aProxy) {}
|
|
|
|
#endif
|
|
|
|
|
2013-08-29 13:43:44 +04:00
|
|
|
// Tell the reader that the data decoded are not for direct playback, so it
|
|
|
|
// can accept more files, in particular those which have more channels than
|
|
|
|
// available in the audio output.
|
|
|
|
void SetIgnoreAudioOutputFormat()
|
|
|
|
{
|
|
|
|
mIgnoreAudioOutputFormat = true;
|
|
|
|
}
|
|
|
|
|
2015-06-07 00:42:40 +03:00
|
|
|
// MediaSourceReader opts out of the start-time-guessing mechanism.
|
|
|
|
virtual bool ForceZeroStartTime() const { return false; }
|
|
|
|
|
2014-12-22 11:20:30 +03:00
|
|
|
// 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.
|
|
|
|
virtual bool UseBufferingHeuristics() { return true; }
|
2014-11-12 07:50:22 +03:00
|
|
|
|
2014-03-20 01:33:12 +04:00
|
|
|
// Returns the number of bytes of memory allocated by structures/frames in
|
|
|
|
// the video queue.
|
|
|
|
size_t SizeOfVideoQueueInBytes() const;
|
2011-07-22 07:17:23 +04:00
|
|
|
|
2014-03-20 01:33:12 +04:00
|
|
|
// Returns the number of bytes of memory allocated by structures/frames in
|
|
|
|
// the audio queue.
|
|
|
|
size_t SizeOfAudioQueueInBytes() const;
|
2011-07-22 07:17:23 +04:00
|
|
|
|
2014-12-18 02:41:19 +03:00
|
|
|
virtual size_t SizeOfVideoQueueInFrames();
|
|
|
|
virtual size_t SizeOfAudioQueueInFrames();
|
|
|
|
|
2015-11-11 02:43:38 +03:00
|
|
|
void NotifyDataArrived()
|
2015-10-26 06:25:25 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
NS_ENSURE_TRUE_VOID(!mShutdown);
|
2015-11-02 16:28:57 +03:00
|
|
|
NotifyDataArrivedInternal();
|
2015-10-26 06:25:25 +03:00
|
|
|
UpdateBuffered();
|
|
|
|
}
|
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
virtual MediaQueue<AudioData>& AudioQueue() { return mAudioQueue; }
|
|
|
|
virtual MediaQueue<VideoData>& VideoQueue() { return mVideoQueue; }
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2015-10-26 06:29:48 +03:00
|
|
|
AbstractCanonical<media::TimeIntervals>* CanonicalBuffered()
|
|
|
|
{
|
|
|
|
return &mBuffered;
|
|
|
|
}
|
2015-10-26 06:25:25 +03:00
|
|
|
|
2014-06-23 14:08:34 +04:00
|
|
|
// Indicates if the media is seekable.
|
|
|
|
// ReadMetada should be called before calling this method.
|
|
|
|
virtual bool IsMediaSeekable() = 0;
|
2015-06-18 00:22:10 +03:00
|
|
|
|
|
|
|
void DispatchSetStartTime(int64_t aStartTime)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaDecoderReader> self = this;
|
2015-06-18 00:22:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r =
|
|
|
|
NS_NewRunnableFunction([self, aStartTime] () -> void
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(self->OnTaskQueue());
|
2015-07-02 02:28:47 +03:00
|
|
|
MOZ_ASSERT(!self->HaveStartTime());
|
|
|
|
self->mStartTime.emplace(aStartTime);
|
2015-06-18 00:22:10 +03:00
|
|
|
self->UpdateBuffered();
|
|
|
|
});
|
2015-07-16 21:31:21 +03:00
|
|
|
OwnerThread()->Dispatch(r.forget());
|
2015-06-18 00:22:10 +03:00
|
|
|
}
|
2014-07-30 10:53:34 +04:00
|
|
|
|
2015-10-26 06:29:48 +03:00
|
|
|
TaskQueue* OwnerThread() const
|
|
|
|
{
|
2014-11-04 01:16:34 +03:00
|
|
|
return mTaskQueue;
|
|
|
|
}
|
|
|
|
|
2015-01-13 12:31:03 +03:00
|
|
|
// Returns true if the reader implements RequestAudioData()
|
|
|
|
// and RequestVideoData() asynchronously, rather than using the
|
|
|
|
// implementation in this class to adapt the old synchronous to
|
|
|
|
// the newer async model.
|
|
|
|
virtual bool IsAsync() const { return false; }
|
|
|
|
|
2015-03-09 06:17:30 +03:00
|
|
|
// Returns true if this decoder reader uses hardware accelerated video
|
|
|
|
// decoding.
|
|
|
|
virtual bool VideoIsHardwareAccelerated() const { return false; }
|
|
|
|
|
2015-10-21 06:45:53 +03:00
|
|
|
virtual void DisableHardwareAcceleration() {}
|
|
|
|
|
2015-10-26 06:29:48 +03:00
|
|
|
TimedMetadataEventSource& TimedMetadataEvent()
|
|
|
|
{
|
2015-09-07 06:37:32 +03:00
|
|
|
return mTimedMetadataEvent;
|
|
|
|
}
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
protected:
|
2014-06-22 08:44:00 +04:00
|
|
|
virtual ~MediaDecoderReader();
|
2014-04-01 07:39:04 +04:00
|
|
|
|
2015-10-26 06:25:25 +03:00
|
|
|
// Populates aBuffered with the time ranges which are buffered. This may only
|
|
|
|
// be called on the decode task queue, and should only be used internally by
|
|
|
|
// UpdateBuffered - mBuffered (or mirrors of it) should be used for everything
|
|
|
|
// else.
|
|
|
|
//
|
|
|
|
// This base implementation in MediaDecoderReader estimates the time ranges
|
|
|
|
// buffered by interpolating the cached byte ranges with the duration
|
|
|
|
// of the media. Reader subclasses should override this method if they
|
|
|
|
// can quickly calculate the buffered ranges more accurately.
|
|
|
|
//
|
|
|
|
// The primary advantage of this implementation in the reader base class
|
|
|
|
// is that it's a fast approximation, which does not perform any I/O.
|
|
|
|
//
|
|
|
|
// The OggReader relies on this base implementation not performing I/O,
|
|
|
|
// since in FirefoxOS we can't do I/O on the main thread, where this is
|
|
|
|
// called.
|
|
|
|
virtual media::TimeIntervals GetBuffered();
|
2014-06-18 09:07:02 +04:00
|
|
|
|
2015-10-26 06:25:25 +03:00
|
|
|
RefPtr<VideoDataPromise> DecodeToFirstVideoData();
|
|
|
|
|
2015-10-26 06:29:48 +03:00
|
|
|
bool HaveStartTime()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
return mStartTime.isSome();
|
|
|
|
}
|
|
|
|
|
2015-10-26 06:25:25 +03:00
|
|
|
int64_t StartTime() { MOZ_ASSERT(HaveStartTime()); return mStartTime.ref(); }
|
2014-06-18 09:07:02 +04:00
|
|
|
|
|
|
|
// Queue of audio frames. This queue is threadsafe, and is accessed from
|
|
|
|
// the audio, decoder, state machine, and main threads.
|
|
|
|
MediaQueue<AudioData> mAudioQueue;
|
|
|
|
|
|
|
|
// Queue of video frames. This queue is threadsafe, and is accessed from
|
|
|
|
// the decoder, state machine, and main threads.
|
|
|
|
MediaQueue<VideoData> mVideoQueue;
|
|
|
|
|
|
|
|
// An adapter to the audio queue which first copies data to buffers with
|
|
|
|
// minimal allocation slop and then pushes them to the queue. This is
|
|
|
|
// useful for decoders working with formats that give awkward numbers of
|
|
|
|
// frames such as mp3.
|
|
|
|
AudioCompactor mAudioCompactor;
|
|
|
|
|
2011-07-12 07:39:28 +04:00
|
|
|
// Reference to the owning decoder object.
|
2012-11-19 19:11:21 +04:00
|
|
|
AbstractMediaDecoder* mDecoder;
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2015-06-09 03:16:42 +03:00
|
|
|
// Decode task queue.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TaskQueue> mTaskQueue;
|
2015-06-09 03:16:42 +03:00
|
|
|
|
2015-06-18 00:22:10 +03:00
|
|
|
// State-watching manager.
|
|
|
|
WatchManager<MediaDecoderReader> mWatchManager;
|
|
|
|
|
|
|
|
// Buffered range.
|
|
|
|
Canonical<media::TimeIntervals> mBuffered;
|
|
|
|
|
2011-07-12 07:39:28 +04:00
|
|
|
// Stores presentation info required for playback.
|
2013-09-27 09:22:38 +04:00
|
|
|
MediaInfo mInfo;
|
2013-08-29 13:43:44 +04:00
|
|
|
|
2015-06-09 22:41:24 +03:00
|
|
|
// Duration, mirrored from the state machine task queue.
|
|
|
|
Mirror<media::NullableTimeUnit> mDuration;
|
|
|
|
|
2013-08-29 13:43:44 +04:00
|
|
|
// Whether we should accept media that we know we can't play
|
|
|
|
// directly, because they have a number of channel higher than
|
|
|
|
// what we support.
|
|
|
|
bool mIgnoreAudioOutputFormat;
|
2014-06-18 09:07:02 +04:00
|
|
|
|
2014-11-12 07:50:20 +03:00
|
|
|
// The start time of the media, in microseconds. This is the presentation
|
|
|
|
// time of the first frame decoded from the media. This is initialized to -1,
|
|
|
|
// and then set to a value >= by MediaDecoderStateMachine::SetStartTime(),
|
2015-06-07 01:00:36 +03:00
|
|
|
// after which point it never changes (though SetStartTime may be called
|
|
|
|
// multiple times with the same value).
|
|
|
|
//
|
|
|
|
// This is an ugly breach of abstractions - it's currently necessary for the
|
|
|
|
// readers to return the correct value of GetBuffered. We should refactor
|
|
|
|
// things such that all GetBuffered calls go through the MDSM, which would
|
|
|
|
// offset the range accordingly.
|
2015-07-02 02:28:47 +03:00
|
|
|
Maybe<int64_t> mStartTime;
|
2014-12-08 04:09:08 +03:00
|
|
|
|
2014-12-11 01:03:56 +03:00
|
|
|
// This is a quick-and-dirty way for DecodeAudioData implementations to
|
|
|
|
// communicate the presence of a decoding error to RequestAudioData. We should
|
|
|
|
// replace this with a promise-y mechanism as we make this stuff properly
|
|
|
|
// async.
|
|
|
|
bool mHitAudioDecodeError;
|
2015-01-11 23:43:11 +03:00
|
|
|
bool mShutdown;
|
2014-12-11 01:03:56 +03:00
|
|
|
|
2015-09-07 06:37:32 +03:00
|
|
|
// Used to send TimedMetadata to the listener.
|
|
|
|
TimedMetadataEventProducer mTimedMetadataEvent;
|
|
|
|
|
2014-12-11 01:03:56 +03:00
|
|
|
private:
|
2015-10-26 06:25:25 +03:00
|
|
|
// Does any spinup that needs to happen on this task queue. This runs on a
|
|
|
|
// different thread than Init, and there should not be ordering dependencies
|
|
|
|
// between the two (even though in practice, Init will always run first right
|
|
|
|
// now thanks to the tail dispatcher).
|
|
|
|
void InitializationTask();
|
|
|
|
|
|
|
|
// Read header data for all bitstreams in the file. Fills aInfo with
|
|
|
|
// the data required to present the media, and optionally fills *aTags
|
|
|
|
// with tag metadata from the file.
|
|
|
|
// Returns NS_OK on success, or NS_ERROR_FAILURE on failure.
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual nsresult ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags)
|
|
|
|
{
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2015-10-26 06:25:25 +03:00
|
|
|
|
|
|
|
// Recomputes mBuffered.
|
|
|
|
virtual void UpdateBuffered();
|
|
|
|
|
2015-11-02 16:28:57 +03:00
|
|
|
virtual void NotifyDataArrivedInternal() {}
|
2015-10-26 06:25:25 +03:00
|
|
|
|
|
|
|
// Overrides of this function should decodes an unspecified amount of
|
|
|
|
// audio data, enqueuing the audio data in mAudioQueue. Returns true
|
|
|
|
// when there's more audio to decode, false if the audio is finished,
|
|
|
|
// end of file has been reached, or an un-recoverable read error has
|
|
|
|
// occured. This function blocks until the decode is complete.
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual bool DecodeAudioData()
|
|
|
|
{
|
2015-10-26 06:25:25 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overrides of this function should read and decodes one video frame.
|
|
|
|
// Packets with a timestamp less than aTimeThreshold will be decoded
|
|
|
|
// (unless they're not keyframes and aKeyframeSkip is true), but will
|
|
|
|
// not be added to the queue. This function blocks until the decode
|
|
|
|
// is complete.
|
2015-10-26 06:29:48 +03:00
|
|
|
virtual bool DecodeVideoFrame(bool &aKeyframeSkip, int64_t aTimeThreshold)
|
|
|
|
{
|
2015-10-26 06:25:25 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 01:03:56 +03:00
|
|
|
// Promises used only for the base-class (sync->async adapter) implementation
|
|
|
|
// of Request{Audio,Video}Data.
|
2015-07-16 21:06:49 +03:00
|
|
|
MozPromiseHolder<AudioDataPromise> mBaseAudioPromise;
|
|
|
|
MozPromiseHolder<VideoDataPromise> mBaseVideoPromise;
|
2014-12-11 01:03:56 +03:00
|
|
|
|
2014-06-18 09:07:02 +04:00
|
|
|
// Flags whether a the next audio/video sample comes after a "gap" or
|
|
|
|
// "discontinuity" in the stream. For example after a seek.
|
|
|
|
bool mAudioDiscontinuity;
|
|
|
|
bool mVideoDiscontinuity;
|
2015-11-18 04:00:56 +03:00
|
|
|
|
|
|
|
MediaEventListener mDataArrivedListener;
|
2014-06-18 09:07:02 +04:00
|
|
|
};
|
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-04-02 07:03:07 +04:00
|
|
|
#endif
|