2013-11-20 21:04:33 +00: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/. */
|
|
|
|
|
|
|
|
#include "PlatformDecoderModule.h"
|
2013-11-20 21:04:33 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "WMFDecoderModule.h"
|
|
|
|
#endif
|
2014-03-21 06:35:15 +00:00
|
|
|
#ifdef MOZ_FFMPEG
|
2014-07-03 02:43:13 +00:00
|
|
|
#include "FFmpegRuntimeLinker.h"
|
2014-03-21 06:35:15 +00:00
|
|
|
#endif
|
2014-07-24 20:47:00 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
#include "AppleDecoderModule.h"
|
|
|
|
#endif
|
2014-08-07 10:23:45 +00:00
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
#include "GonkDecoderModule.h"
|
|
|
|
#endif
|
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-08-08 02:44:04 +00:00
|
|
|
#ifdef MOZ_EME
|
2014-07-30 06:53:34 +00:00
|
|
|
#include "EMEDecoderModule.h"
|
|
|
|
#include "mozilla/CDMProxy.h"
|
2014-08-08 02:44:04 +00:00
|
|
|
#endif
|
2014-07-30 06:53:34 +00:00
|
|
|
#include "SharedThreadPool.h"
|
|
|
|
#include "MediaTaskQueue.h"
|
2013-11-20 21:04:33 +00:00
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
extern PlatformDecoderModule* CreateBlankDecoderModule();
|
|
|
|
|
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 03:13:54 +00:00
|
|
|
bool PlatformDecoderModule::sUseBlankDecoder = false;
|
2014-03-21 06:35:15 +00:00
|
|
|
bool PlatformDecoderModule::sFFmpegDecoderEnabled = false;
|
2014-08-07 10:23:45 +00:00
|
|
|
bool PlatformDecoderModule::sGonkDecoderEnabled = false;
|
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 03:13:54 +00:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
PlatformDecoderModule::Init()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
static bool alreadyInitialized = false;
|
|
|
|
if (alreadyInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
alreadyInitialized = true;
|
2014-03-21 06:35:15 +00:00
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sUseBlankDecoder,
|
|
|
|
"media.fragmented-mp4.use-blank-decoder");
|
|
|
|
Preferences::AddBoolVarCache(&sFFmpegDecoderEnabled,
|
|
|
|
"media.fragmented-mp4.ffmpeg.enabled", false);
|
2014-08-07 10:23:45 +00:00
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
Preferences::AddBoolVarCache(&sGonkDecoderEnabled,
|
|
|
|
"media.fragmented-mp4.gonk.enabled", false);
|
|
|
|
#endif
|
2014-01-15 03:14:15 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
WMFDecoderModule::Init();
|
|
|
|
#endif
|
2014-07-24 20:47:00 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
AppleDecoderModule::Init();
|
|
|
|
#endif
|
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 03:13:54 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 06:53:34 +00:00
|
|
|
class CreateTaskQueueTask : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mTaskQueue = new MediaTaskQueue(GetMediaDecodeThreadPool());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsRefPtr<MediaTaskQueue> mTaskQueue;
|
|
|
|
};
|
|
|
|
|
|
|
|
static already_AddRefed<MediaTaskQueue>
|
|
|
|
CreateTaskQueue()
|
|
|
|
{
|
|
|
|
// We must create the MediaTaskQueue/SharedThreadPool on the main thread.
|
|
|
|
nsRefPtr<CreateTaskQueueTask> t(new CreateTaskQueueTask());
|
|
|
|
nsresult rv = NS_DispatchToMainThread(t, NS_DISPATCH_SYNC);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
return t->mTaskQueue.forget();
|
|
|
|
}
|
|
|
|
|
2014-08-08 02:44:04 +00:00
|
|
|
#ifdef MOZ_EME
|
2014-07-30 06:53:34 +00:00
|
|
|
/* static */
|
|
|
|
PlatformDecoderModule*
|
|
|
|
PlatformDecoderModule::CreateCDMWrapper(CDMProxy* aProxy,
|
|
|
|
bool aHasAudio,
|
|
|
|
bool aHasVideo,
|
|
|
|
MediaTaskQueue* aTaskQueue)
|
|
|
|
{
|
|
|
|
bool cdmDecodesAudio;
|
|
|
|
bool cdmDecodesVideo;
|
|
|
|
{
|
|
|
|
CDMCaps::AutoLock caps(aProxy->Capabilites());
|
|
|
|
cdmDecodesAudio = caps.CanDecryptAndDecodeAudio();
|
|
|
|
cdmDecodesVideo = caps.CanDecryptAndDecodeVideo();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<PlatformDecoderModule> pdm;
|
|
|
|
if ((!cdmDecodesAudio && aHasAudio) || (!cdmDecodesVideo && aHasVideo)) {
|
|
|
|
// The CDM itself can't decode. We need to wrap a PDM to decode the
|
|
|
|
// decrypted output of the CDM.
|
|
|
|
pdm = Create();
|
|
|
|
if (!pdm) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new EMEDecoderModule(aProxy,
|
|
|
|
pdm.forget(),
|
|
|
|
cdmDecodesAudio,
|
|
|
|
cdmDecodesVideo,
|
|
|
|
CreateTaskQueue());
|
|
|
|
}
|
2014-08-08 02:44:04 +00:00
|
|
|
#endif
|
2014-07-30 06:53:34 +00:00
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
/* static */
|
|
|
|
PlatformDecoderModule*
|
|
|
|
PlatformDecoderModule::Create()
|
|
|
|
{
|
2014-08-03 07:28:39 +00:00
|
|
|
// Note: This runs on the decode thread.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
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 03:13:54 +00:00
|
|
|
if (sUseBlankDecoder) {
|
2013-11-20 21:04:33 +00:00
|
|
|
return CreateBlankDecoderModule();
|
|
|
|
}
|
2013-11-20 21:04:33 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsAutoPtr<WMFDecoderModule> m(new WMFDecoderModule());
|
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 03:13:54 +00:00
|
|
|
if (NS_SUCCEEDED(m->Startup())) {
|
2013-11-20 21:04:33 +00:00
|
|
|
return m.forget();
|
|
|
|
}
|
2014-03-21 06:35:15 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_FFMPEG
|
|
|
|
if (sFFmpegDecoderEnabled) {
|
2014-07-03 02:43:13 +00:00
|
|
|
return FFmpegRuntimeLinker::CreateDecoderModule();
|
2014-07-28 22:36:00 +00:00
|
|
|
}
|
2014-07-24 20:47:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
nsAutoPtr<AppleDecoderModule> m(new AppleDecoderModule());
|
|
|
|
if (NS_SUCCEEDED(m->Startup())) {
|
|
|
|
return m.forget();
|
2014-03-21 06:35:15 +00:00
|
|
|
}
|
2014-08-07 10:23:45 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
if (sGonkDecoderEnabled) {
|
|
|
|
return new GonkDecoderModule();
|
|
|
|
}
|
2013-11-20 21:04:33 +00:00
|
|
|
#endif
|
2013-11-20 21:04:33 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|