2013-11-20 13:04:33 -08: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(PlatformDecoderModule_h_)
|
|
|
|
#define PlatformDecoderModule_h_
|
|
|
|
|
|
|
|
#include "MediaDecoderReader.h"
|
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
#include "nsTArray.h"
|
2014-02-04 17:29:28 -08:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include <queue>
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
|
|
|
|
namespace mp4_demuxer {
|
|
|
|
class VideoDecoderConfig;
|
|
|
|
class AudioDecoderConfig;
|
2014-06-18 17:57:51 -07:00
|
|
|
class MP4Sample;
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
}
|
2013-11-20 13:04:33 -08:00
|
|
|
|
2014-02-04 17:29:28 -08:00
|
|
|
class nsIThreadPool;
|
|
|
|
|
2013-11-20 13:04:33 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
|
|
|
}
|
|
|
|
|
2013-12-03 16:47:12 -08:00
|
|
|
class MediaDataDecoder;
|
2014-02-04 17:29:28 -08:00
|
|
|
class MediaDataDecoderCallback;
|
|
|
|
class MediaInputQueue;
|
|
|
|
class MediaTaskQueue;
|
2014-07-29 23:53:34 -07:00
|
|
|
class CDMProxy;
|
2013-11-20 13:04:33 -08:00
|
|
|
typedef int64_t Microseconds;
|
|
|
|
|
2013-12-03 16:47:12 -08:00
|
|
|
// The PlatformDecoderModule interface is used by the MP4Reader to abstract
|
|
|
|
// access to the H264 and AAC decoders provided by various platforms. It
|
|
|
|
// may be extended to support other codecs in future. Each platform (Windows,
|
2014-02-04 17:29:28 -08:00
|
|
|
// MacOSX, Linux, B2G etc) must implement a PlatformDecoderModule to provide
|
|
|
|
// access to its decoders in order to get decompressed H.264/AAC from the
|
|
|
|
// MP4Reader.
|
|
|
|
//
|
|
|
|
// Video decoding is asynchronous, and should be performed on the task queue
|
|
|
|
// provided if the underlying platform isn't already exposing an async API.
|
2013-12-03 16:47:12 -08:00
|
|
|
//
|
|
|
|
// Platforms that don't have a corresponding PlatformDecoderModule won't be
|
|
|
|
// able to play the H.264/AAC data output by the MP4Reader. In practice this
|
|
|
|
// means that we won't have fragmented MP4 supported in Media Source
|
2014-02-04 17:29:28 -08:00
|
|
|
// Extensions.
|
2013-12-03 16:47:12 -08:00
|
|
|
//
|
|
|
|
// A cross-platform decoder module that discards input and produces "blank"
|
2014-02-04 17:29:28 -08:00
|
|
|
// output samples exists for testing, and is created when the pref
|
2013-12-03 16:47:12 -08:00
|
|
|
// "media.fragmented-mp4.use-blank-decoder" is true.
|
|
|
|
class PlatformDecoderModule {
|
|
|
|
public:
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
// Call on the main thread to initialize the static state
|
|
|
|
// needed by Create().
|
|
|
|
static void Init();
|
2013-12-03 16:47:12 -08:00
|
|
|
|
|
|
|
// Factory method that creates the appropriate PlatformDecoderModule for
|
|
|
|
// the platform we're running on. Caller is responsible for deleting this
|
|
|
|
// instance. It's expected that there will be multiple
|
|
|
|
// PlatformDecoderModules alive at the same time. There is one
|
2014-02-04 17:29:28 -08:00
|
|
|
// PlatformDecoderModule created per MP4Reader.
|
|
|
|
// This is called on the decode thread.
|
2013-12-03 16:47:12 -08:00
|
|
|
static PlatformDecoderModule* Create();
|
|
|
|
|
2014-07-29 23:53:34 -07:00
|
|
|
// Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or
|
|
|
|
// decrypt-and-decode EME encrypted content. If the CDM only decrypts and
|
|
|
|
// does not decode, we create a PDM and use that to create MediaDataDecoders
|
|
|
|
// that we use on on aTaskQueue to decode the decrypted stream.
|
|
|
|
static PlatformDecoderModule* CreateCDMWrapper(CDMProxy* aProxy,
|
|
|
|
bool aHasAudio,
|
|
|
|
bool aHasVideo,
|
|
|
|
MediaTaskQueue* aTaskQueue);
|
|
|
|
|
2013-12-03 16:47:12 -08:00
|
|
|
// Called to shutdown the decoder module and cleanup state. This should
|
|
|
|
// block until shutdown is complete. This is called after Shutdown() has
|
|
|
|
// been called on all MediaDataDecoders created from this
|
|
|
|
// PlatformDecoderModule.
|
|
|
|
// Called on the main thread only.
|
|
|
|
virtual nsresult Shutdown() = 0;
|
|
|
|
|
2014-02-04 17:29:28 -08:00
|
|
|
// Creates an H.264 decoder. The layers backend is passed in so that
|
|
|
|
// decoders can determine whether hardware accelerated decoding can be used.
|
|
|
|
// Asynchronous decoding of video should be done in runnables dispatched
|
|
|
|
// to aVideoTaskQueue. If the task queue isn't needed, the decoder should
|
|
|
|
// not hold a reference to it.
|
|
|
|
// Output and errors should be returned to the reader via aCallback.
|
|
|
|
// On Windows the task queue's threads in have MSCOM initialized with
|
|
|
|
// COINIT_MULTITHREADED.
|
|
|
|
// Returns nullptr if the decoder can't be created.
|
|
|
|
// It is safe to store a reference to aConfig.
|
2013-12-03 16:47:12 -08:00
|
|
|
// Called on decode thread.
|
2014-07-30 18:40:21 -07:00
|
|
|
virtual already_AddRefed<MediaDataDecoder>
|
2014-07-30 18:40:14 -07:00
|
|
|
CreateH264Decoder(const mp4_demuxer::VideoDecoderConfig& aConfig,
|
|
|
|
layers::LayersBackend aLayersBackend,
|
|
|
|
layers::ImageContainer* aImageContainer,
|
|
|
|
MediaTaskQueue* aVideoTaskQueue,
|
|
|
|
MediaDataDecoderCallback* aCallback) = 0;
|
2014-02-04 17:29:28 -08:00
|
|
|
|
|
|
|
// Creates an AAC decoder with the specified properties.
|
|
|
|
// Asynchronous decoding of audio should be done in runnables dispatched to
|
|
|
|
// aAudioTaskQueue. If the task queue isn't needed, the decoder should
|
|
|
|
// not hold a reference to it.
|
|
|
|
// Output and errors should be returned to the reader via aCallback.
|
|
|
|
// Returns nullptr if the decoder can't be created.
|
|
|
|
// On Windows the task queue's threads in have MSCOM initialized with
|
|
|
|
// COINIT_MULTITHREADED.
|
|
|
|
// It is safe to store a reference to aConfig.
|
2013-12-03 16:47:12 -08:00
|
|
|
// Called on decode thread.
|
2014-07-30 18:40:21 -07:00
|
|
|
virtual already_AddRefed<MediaDataDecoder>
|
2014-07-30 18:40:14 -07:00
|
|
|
CreateAACDecoder(const mp4_demuxer::AudioDecoderConfig& aConfig,
|
|
|
|
MediaTaskQueue* aAudioTaskQueue,
|
|
|
|
MediaDataDecoderCallback* aCallback) = 0;
|
2013-12-03 16:47:12 -08:00
|
|
|
|
|
|
|
virtual ~PlatformDecoderModule() {}
|
2014-02-04 17:29:28 -08:00
|
|
|
|
2013-12-03 16:47:12 -08:00
|
|
|
protected:
|
|
|
|
PlatformDecoderModule() {}
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
// Caches pref media.fragmented-mp4.use-blank-decoder
|
|
|
|
static bool sUseBlankDecoder;
|
2014-03-20 23:35:15 -07:00
|
|
|
static bool sFFmpegDecoderEnabled;
|
2013-12-03 16:47:12 -08:00
|
|
|
};
|
|
|
|
|
2014-02-04 17:29:28 -08:00
|
|
|
// A callback used by MediaDataDecoder to return output/errors to the
|
|
|
|
// MP4Reader. Implementation is threadsafe, and can be called on any thread.
|
|
|
|
class MediaDataDecoderCallback {
|
|
|
|
public:
|
|
|
|
virtual ~MediaDataDecoderCallback() {}
|
|
|
|
|
|
|
|
// Called by MediaDataDecoder when a sample has been decoded. Callee is
|
|
|
|
// responsibile for deleting aData.
|
|
|
|
virtual void Output(MediaData* aData) = 0;
|
|
|
|
|
|
|
|
// Denotes an error in the decoding process. The reader will stop calling
|
|
|
|
// the decoder.
|
|
|
|
virtual void Error() = 0;
|
|
|
|
|
|
|
|
// Denotes that the last input sample has been inserted into the decoder,
|
|
|
|
// and no more output can be produced unless more input is sent.
|
|
|
|
virtual void InputExhausted() = 0;
|
2014-07-24 19:57:25 -07:00
|
|
|
|
|
|
|
virtual void DrainComplete() = 0;
|
2013-11-20 13:04:33 -08:00
|
|
|
};
|
|
|
|
|
2013-12-03 16:47:12 -08:00
|
|
|
// MediaDataDecoder is the interface exposed by decoders created by the
|
|
|
|
// PlatformDecoderModule's Create*Decoder() functions. The type of
|
|
|
|
// media data that the decoder accepts as valid input and produces as
|
|
|
|
// output is determined when the MediaDataDecoder is created.
|
2014-02-04 17:29:28 -08:00
|
|
|
//
|
|
|
|
// All functions must be threadsafe, and be able to be called on an
|
|
|
|
// arbitrary thread.
|
|
|
|
//
|
|
|
|
// Decoding is done asynchronously. Any async work can be done on the
|
|
|
|
// MediaTaskQueue passed into the PlatformDecoderModules's Create*Decoder()
|
|
|
|
// function. This may not be necessary for platforms with async APIs
|
|
|
|
// for decoding.
|
2014-04-14 12:04:25 -07:00
|
|
|
class MediaDataDecoder {
|
|
|
|
protected:
|
2014-04-14 13:16:18 -07:00
|
|
|
virtual ~MediaDataDecoder() {};
|
2014-04-14 12:04:25 -07:00
|
|
|
|
2014-04-14 12:04:25 -07:00
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDataDecoder)
|
|
|
|
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
// Initialize the decoder. The decoder should be ready to decode after
|
|
|
|
// this returns. The decoder should do any initialization here, rather
|
2014-02-04 17:29:28 -08:00
|
|
|
// than in its constructor or PlatformDecoderModule::Create*Decoder(),
|
|
|
|
// so that if the MP4Reader needs to shutdown during initialization,
|
|
|
|
// it can call Shutdown() to cancel this operation. Any initialization
|
|
|
|
// that requires blocking the calling thread in this function *must*
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-14 19:13:54 -08:00
|
|
|
// be done here so that it can be canceled by calling Shutdown()!
|
|
|
|
virtual nsresult Init() = 0;
|
|
|
|
|
2014-02-04 17:29:28 -08:00
|
|
|
// Inserts a sample into the decoder's decode pipeline. The decoder must
|
|
|
|
// delete the sample once its been decoded. If Input() returns an error,
|
|
|
|
// aSample will be deleted by the caller.
|
|
|
|
virtual nsresult Input(mp4_demuxer::MP4Sample* aSample) = 0;
|
2013-11-20 13:04:33 -08:00
|
|
|
|
2013-12-03 16:47:12 -08:00
|
|
|
// Causes all samples in the decoding pipeline to be discarded. When
|
|
|
|
// this function returns, the decoder must be ready to accept new input
|
|
|
|
// for decoding. This function is called when the demuxer seeks, before
|
|
|
|
// decoding resumes after the seek.
|
2014-02-04 17:29:28 -08:00
|
|
|
// While the reader calls Flush(), it ignores all output sent to it;
|
|
|
|
// it is safe (but pointless) to send output while Flush is called.
|
|
|
|
// The MP4Reader will not call Input() while it's calling Flush().
|
|
|
|
virtual nsresult Flush() = 0;
|
|
|
|
|
2014-07-24 19:57:25 -07:00
|
|
|
|
2014-02-04 17:29:28 -08:00
|
|
|
// Causes all complete samples in the pipeline that can be decoded to be
|
|
|
|
// output. If the decoder can't produce samples from the current output,
|
|
|
|
// it drops the input samples. The decoder may be holding onto samples
|
|
|
|
// that are required to decode samples that it expects to get in future.
|
|
|
|
// This is called when the demuxer reaches end of stream.
|
|
|
|
// The MP4Reader will not call Input() while it's calling Drain().
|
2014-07-24 19:57:25 -07:00
|
|
|
// This function is asynchronous. The MediaDataDecoder must call
|
|
|
|
// MediaDataDecoderCallback::DrainComplete() once all remaining
|
|
|
|
// samples have been output.
|
2014-02-04 17:29:28 -08:00
|
|
|
virtual nsresult Drain() = 0;
|
|
|
|
|
|
|
|
// Cancels all init/input/drain operations, and shuts down the
|
|
|
|
// decoder. The platform decoder should clean up any resources it's using
|
|
|
|
// and release memory etc. Shutdown() must block until the decoder has
|
|
|
|
// completed shutdown. The reader calls Flush() before calling Shutdown().
|
|
|
|
// The reader will delete the decoder once Shutdown() returns.
|
|
|
|
// The MediaDataDecoderCallback *must* not be called after Shutdown() has
|
|
|
|
// returned.
|
2013-11-20 13:04:33 -08:00
|
|
|
virtual nsresult Shutdown() = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|