2013-11-21 01:04:33 +04: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_
|
|
|
|
|
2015-08-08 02:58:43 +03:00
|
|
|
#include "FlushableTaskQueue.h"
|
2013-11-21 01:04:33 +04:00
|
|
|
#include "MediaDecoderReader.h"
|
2015-08-11 06:50:07 +03:00
|
|
|
#include "mozilla/MozPromise.h"
|
2013-11-21 01:04:33 +04:00
|
|
|
#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-15 07:13:54 +04:00
|
|
|
#include "nsTArray.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-02-05 05:29:28 +04:00
|
|
|
#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-15 07:13:54 +04:00
|
|
|
|
2013-11-21 01:04:33 +04:00
|
|
|
namespace mozilla {
|
2015-04-14 08:16:32 +03:00
|
|
|
class TrackInfo;
|
|
|
|
class AudioInfo;
|
|
|
|
class VideoInfo;
|
2015-04-09 14:14:55 +03:00
|
|
|
class MediaRawData;
|
2013-11-21 01:04:33 +04:00
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2013-11-21 01:04:33 +04:00
|
|
|
|
2013-12-04 04:47:12 +04:00
|
|
|
class MediaDataDecoder;
|
2014-02-05 05:29:28 +04:00
|
|
|
class MediaDataDecoderCallback;
|
2015-07-16 21:13:49 +03:00
|
|
|
class FlushableTaskQueue;
|
2014-07-30 10:53:34 +04:00
|
|
|
class CDMProxy;
|
2013-11-21 01:04:33 +04:00
|
|
|
|
2015-10-06 02:17:12 +03:00
|
|
|
// The PlatformDecoderModule interface is used by the MediaFormatReader to
|
|
|
|
// abstract access to decoders provided by various
|
|
|
|
// platforms.
|
|
|
|
// Each platform (Windows, MacOSX, Linux, B2G etc) must implement a
|
|
|
|
// PlatformDecoderModule to provide access to its decoders in order to get
|
|
|
|
// decompressed H.264/AAC from the MediaFormatReader.
|
2014-02-05 05:29:28 +04:00
|
|
|
//
|
2015-10-06 02:17:12 +03:00
|
|
|
// Decoding is asynchronous, and should be performed on the task queue
|
2014-02-05 05:29:28 +04:00
|
|
|
// provided if the underlying platform isn't already exposing an async API.
|
2013-12-04 04:47:12 +04:00
|
|
|
//
|
|
|
|
// A cross-platform decoder module that discards input and produces "blank"
|
2014-02-05 05:29:28 +04:00
|
|
|
// output samples exists for testing, and is created when the pref
|
2015-10-15 04:51:28 +03:00
|
|
|
// "media.use-blank-decoder" is true.
|
2015-10-06 02:17:12 +03:00
|
|
|
|
2013-12-04 04:47:12 +04:00
|
|
|
class PlatformDecoderModule {
|
|
|
|
public:
|
2014-12-23 06:36:10 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PlatformDecoderModule)
|
|
|
|
|
2014-12-23 06:36:10 +03:00
|
|
|
// Perform any per-instance initialization.
|
|
|
|
// This is called on the decode task queue.
|
|
|
|
virtual nsresult Startup() { return NS_OK; };
|
2013-12-04 04:47:12 +04:00
|
|
|
|
2015-10-06 02:17:12 +03:00
|
|
|
// Indicates if the PlatformDecoderModule supports decoding of aMimeType.
|
2015-10-30 00:04:25 +03:00
|
|
|
virtual bool SupportsMimeType(const nsACString& aMimeType) const = 0;
|
2015-10-07 11:13:39 +03:00
|
|
|
|
2015-04-07 13:33:17 +03:00
|
|
|
enum ConversionRequired {
|
|
|
|
kNeedNone,
|
|
|
|
kNeedAVCC,
|
|
|
|
kNeedAnnexB,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Indicates that the decoder requires a specific format.
|
|
|
|
// The PlatformDecoderModule will convert the demuxed data accordingly before
|
|
|
|
// feeding it to MediaDataDecoder::Input.
|
2015-04-14 08:16:32 +03:00
|
|
|
virtual ConversionRequired DecoderNeedsConversion(const TrackInfo& aConfig) const = 0;
|
2015-04-07 13:33:17 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PlatformDecoderModule() {}
|
|
|
|
virtual ~PlatformDecoderModule() {}
|
|
|
|
|
|
|
|
friend class H264Converter;
|
2015-10-05 13:08:56 +03:00
|
|
|
friend class PDMFactory;
|
|
|
|
|
2015-04-07 13:33:17 +03:00
|
|
|
// Creates a Video decoder. The layers backend is passed in so that
|
2014-02-05 05:29:28 +04:00
|
|
|
// 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.
|
2014-08-03 11:28:39 +04:00
|
|
|
// This is called on the decode task queue.
|
2014-07-31 05:40:21 +04:00
|
|
|
virtual already_AddRefed<MediaDataDecoder>
|
2015-04-14 08:16:32 +03:00
|
|
|
CreateVideoDecoder(const VideoInfo& aConfig,
|
2015-04-07 13:33:17 +03:00
|
|
|
layers::LayersBackend aLayersBackend,
|
|
|
|
layers::ImageContainer* aImageContainer,
|
2015-07-16 21:13:49 +03:00
|
|
|
FlushableTaskQueue* aVideoTaskQueue,
|
2015-04-07 13:33:17 +03:00
|
|
|
MediaDataDecoderCallback* aCallback) = 0;
|
2014-02-05 05:29:28 +04:00
|
|
|
|
2014-08-15 10:25:06 +04:00
|
|
|
// Creates an Audio decoder with the specified properties.
|
2014-02-05 05:29:28 +04:00
|
|
|
// 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.
|
2014-08-03 11:28:39 +04:00
|
|
|
// This is called on the decode task queue.
|
2014-07-31 05:40:21 +04:00
|
|
|
virtual already_AddRefed<MediaDataDecoder>
|
2015-04-14 08:16:32 +03:00
|
|
|
CreateAudioDecoder(const AudioInfo& aConfig,
|
2015-07-16 21:13:49 +03:00
|
|
|
FlushableTaskQueue* aAudioTaskQueue,
|
2014-08-15 10:25:06 +04:00
|
|
|
MediaDataDecoderCallback* aCallback) = 0;
|
2013-12-04 04:47:12 +04:00
|
|
|
};
|
|
|
|
|
2014-02-05 05:29:28 +04:00
|
|
|
// A callback used by MediaDataDecoder to return output/errors to the
|
2015-10-06 02:17:12 +03:00
|
|
|
// MediaFormatReader.
|
|
|
|
// Implementation is threadsafe, and can be called on any thread.
|
2014-02-05 05:29:28 +04:00
|
|
|
class MediaDataDecoderCallback {
|
|
|
|
public:
|
|
|
|
virtual ~MediaDataDecoderCallback() {}
|
|
|
|
|
2014-11-20 00:01:10 +03:00
|
|
|
// Called by MediaDataDecoder when a sample has been decoded.
|
2014-02-05 05:29:28 +04:00
|
|
|
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-25 06:57:25 +04:00
|
|
|
|
|
|
|
virtual void DrainComplete() = 0;
|
2014-08-07 14:23:45 +04:00
|
|
|
|
|
|
|
virtual void ReleaseMediaResources() {};
|
2015-05-01 03:03:32 +03:00
|
|
|
|
|
|
|
virtual bool OnReaderTaskQueue() = 0;
|
2013-11-21 01:04:33 +04:00
|
|
|
};
|
|
|
|
|
2013-12-04 04:47:12 +04: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-05 05:29:28 +04:00
|
|
|
//
|
2015-05-04 00:53:04 +03:00
|
|
|
// Unless otherwise noted, all functions are only called on the decode task
|
2015-05-06 07:43:52 +03:00
|
|
|
// queue. An exception is the MediaDataDecoder in
|
2015-10-06 02:17:12 +03:00
|
|
|
// MediaFormatReader::IsVideoAccelerated() for which all calls (Init(),
|
2015-05-06 07:43:52 +03:00
|
|
|
// IsHardwareAccelerated(), and Shutdown()) are from the main thread.
|
|
|
|
//
|
|
|
|
// Don't block inside these functions, unless it's explicitly noted that you
|
|
|
|
// should (like in Flush()).
|
2014-02-05 05:29:28 +04:00
|
|
|
//
|
|
|
|
// Decoding is done asynchronously. Any async work can be done on the
|
2015-07-16 21:13:49 +03:00
|
|
|
// TaskQueue passed into the PlatformDecoderModules's Create*Decoder()
|
2014-02-05 05:29:28 +04:00
|
|
|
// function. This may not be necessary for platforms with async APIs
|
|
|
|
// for decoding.
|
2014-04-14 23:04:25 +04:00
|
|
|
class MediaDataDecoder {
|
|
|
|
protected:
|
2014-04-15 00:16:18 +04:00
|
|
|
virtual ~MediaDataDecoder() {};
|
2014-04-14 23:04:25 +04:00
|
|
|
|
2014-04-14 23:04:25 +04:00
|
|
|
public:
|
2015-08-11 06:50:07 +03:00
|
|
|
enum DecoderFailureReason {
|
|
|
|
INIT_ERROR,
|
|
|
|
CANCELED
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef TrackInfo::TrackType TrackType;
|
|
|
|
typedef MozPromise<TrackType, DecoderFailureReason, /* IsExclusive = */ true> InitPromise;
|
|
|
|
|
2014-04-14 23:04:25 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDataDecoder)
|
|
|
|
|
2015-08-11 06:50:07 +03:00
|
|
|
// Initialize the decoder. The decoder should be ready to decode once
|
|
|
|
// promise resolves. The decoder should do any initialization here, rather
|
2014-02-05 05:29:28 +04:00
|
|
|
// than in its constructor or PlatformDecoderModule::Create*Decoder(),
|
2015-10-06 02:17:12 +03:00
|
|
|
// so that if the MediaFormatReader needs to shutdown during initialization,
|
2014-02-05 05:29:28 +04:00
|
|
|
// 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-15 07:13:54 +04:00
|
|
|
// be done here so that it can be canceled by calling Shutdown()!
|
2015-10-18 08:24:48 +03:00
|
|
|
virtual RefPtr<InitPromise> Init() = 0;
|
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-15 07:13:54 +04:00
|
|
|
|
2015-04-09 14:14:55 +03:00
|
|
|
// Inserts a sample into the decoder's decode pipeline.
|
|
|
|
virtual nsresult Input(MediaRawData* aSample) = 0;
|
2013-11-21 01:04:33 +04:00
|
|
|
|
2013-12-04 04:47:12 +04: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-05 05:29:28 +04: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.
|
2015-10-06 02:17:12 +03:00
|
|
|
// The MediaFormatReader will not call Input() while it's calling Flush().
|
2014-02-05 05:29:28 +04:00
|
|
|
virtual nsresult Flush() = 0;
|
|
|
|
|
|
|
|
// 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.
|
2015-10-06 02:17:12 +03:00
|
|
|
// The MediaFormatReader will not call Input() while it's calling Drain().
|
2014-07-25 06:57:25 +04:00
|
|
|
// This function is asynchronous. The MediaDataDecoder must call
|
|
|
|
// MediaDataDecoderCallback::DrainComplete() once all remaining
|
|
|
|
// samples have been output.
|
2014-02-05 05:29:28 +04: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-21 01:04:33 +04:00
|
|
|
virtual nsresult Shutdown() = 0;
|
|
|
|
|
2015-05-06 07:43:52 +03:00
|
|
|
// Called from the state machine task queue or main thread.
|
2015-08-11 06:50:07 +03:00
|
|
|
// Decoder needs to decide whether or not hardware accelearation is supported
|
|
|
|
// after creating. It doesn't need to call Init() before calling this function.
|
2015-07-13 23:12:23 +03:00
|
|
|
virtual bool IsHardwareAccelerated(nsACString& aFailureReason) const { return false; }
|
2015-04-07 13:33:17 +03:00
|
|
|
|
|
|
|
// ConfigurationChanged will be called to inform the video or audio decoder
|
|
|
|
// that the format of the next input sample is about to change.
|
2015-04-14 08:16:32 +03:00
|
|
|
// If video decoder, aConfig will be a VideoInfo object.
|
|
|
|
// If audio decoder, aConfig will be a AudioInfo object.
|
2015-10-28 16:46:31 +03:00
|
|
|
// It is not safe to store a reference to this object and the decoder must
|
|
|
|
// make a copy.
|
2015-04-14 08:16:32 +03:00
|
|
|
virtual nsresult ConfigurationChanged(const TrackInfo& aConfig)
|
2015-04-07 13:33:17 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-11-21 01:04:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|