2015-10-05 03:08:56 -07: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 "PDMFactory.h"
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "WMFDecoderModule.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_FFMPEG
|
|
|
|
#include "FFmpegRuntimeLinker.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
#include "AppleDecoderModule.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
#include "GonkDecoderModule.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidDecoderModule.h"
|
|
|
|
#endif
|
|
|
|
#include "GMPDecoderModule.h"
|
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/TaskQueue.h"
|
|
|
|
|
|
|
|
#include "mozilla/SharedThreadPool.h"
|
|
|
|
|
|
|
|
#include "MediaInfo.h"
|
|
|
|
#include "FuzzingWrapper.h"
|
|
|
|
#include "H264Converter.h"
|
|
|
|
|
2015-10-05 15:53:02 -07:00
|
|
|
#include "AgnosticDecoderModule.h"
|
2015-10-05 03:08:56 -07:00
|
|
|
|
2015-10-06 01:56:29 -07:00
|
|
|
#ifdef MOZ_EME
|
|
|
|
#include "EMEDecoderModule.h"
|
|
|
|
#include "mozilla/CDMProxy.h"
|
|
|
|
#endif
|
|
|
|
|
2015-10-05 03:08:56 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
extern already_AddRefed<PlatformDecoderModule> CreateAgnosticDecoderModule();
|
|
|
|
extern already_AddRefed<PlatformDecoderModule> CreateBlankDecoderModule();
|
|
|
|
|
|
|
|
bool PDMFactory::sUseBlankDecoder = false;
|
2015-10-14 18:51:31 -07:00
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
2015-10-05 03:08:56 -07:00
|
|
|
bool PDMFactory::sGonkDecoderEnabled = false;
|
2015-10-14 18:51:31 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2015-10-05 03:08:56 -07:00
|
|
|
bool PDMFactory::sAndroidMCDecoderEnabled = false;
|
|
|
|
bool PDMFactory::sAndroidMCDecoderPreferred = false;
|
2015-10-14 18:51:31 -07:00
|
|
|
#endif
|
2015-10-05 03:08:56 -07:00
|
|
|
bool PDMFactory::sGMPDecoderEnabled = false;
|
2015-10-14 18:51:31 -07:00
|
|
|
#ifdef MOZ_FFMPEG
|
2015-10-11 16:00:04 -07:00
|
|
|
bool PDMFactory::sFFmpegDecoderEnabled = false;
|
2015-10-14 18:51:31 -07:00
|
|
|
#endif
|
2015-10-14 18:51:34 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
bool PDMFactory::sWMFDecoderEnabled = false;
|
|
|
|
#endif
|
2015-10-11 16:00:04 -07:00
|
|
|
|
2015-10-05 03:08:56 -07:00
|
|
|
bool PDMFactory::sEnableFuzzingWrapper = false;
|
|
|
|
uint32_t PDMFactory::sVideoOutputMinimumInterval_ms = 0;
|
|
|
|
bool PDMFactory::sDontDelayInputExhausted = false;
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
PDMFactory::Init()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
static bool alreadyInitialized = false;
|
|
|
|
if (alreadyInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
alreadyInitialized = true;
|
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sUseBlankDecoder,
|
2015-10-14 18:51:28 -07:00
|
|
|
"media.use-blank-decoder");
|
2015-10-05 03:08:56 -07:00
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
Preferences::AddBoolVarCache(&sGonkDecoderEnabled,
|
2015-10-14 18:51:28 -07:00
|
|
|
"media.gonk.enabled", false);
|
2015-10-05 03:08:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
Preferences::AddBoolVarCache(&sAndroidMCDecoderEnabled,
|
2015-10-14 18:51:28 -07:00
|
|
|
"media.android-media-codec.enabled", false);
|
2015-10-05 03:08:56 -07:00
|
|
|
Preferences::AddBoolVarCache(&sAndroidMCDecoderPreferred,
|
2015-10-14 18:51:28 -07:00
|
|
|
"media.android-media-codec.preferred", false);
|
2015-10-05 03:08:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sGMPDecoderEnabled,
|
2015-10-14 18:51:28 -07:00
|
|
|
"media.gmp.decoder.enabled", false);
|
2015-10-14 18:51:31 -07:00
|
|
|
#ifdef MOZ_FFMPEG
|
2015-10-11 16:00:04 -07:00
|
|
|
Preferences::AddBoolVarCache(&sFFmpegDecoderEnabled,
|
2015-10-14 18:51:28 -07:00
|
|
|
"media.ffmpeg.enabled", false);
|
2015-10-14 18:51:31 -07:00
|
|
|
#endif
|
2015-10-14 18:51:34 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
Preferences::AddBoolVarCache(&sWMFDecoderEnabled,
|
|
|
|
"media.wmf.enabled", false);
|
|
|
|
#endif
|
2015-10-05 03:08:56 -07:00
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sEnableFuzzingWrapper,
|
|
|
|
"media.decoder.fuzzing.enabled", false);
|
|
|
|
Preferences::AddUintVarCache(&sVideoOutputMinimumInterval_ms,
|
|
|
|
"media.decoder.fuzzing.video-output-minimum-interval-ms", 0);
|
|
|
|
Preferences::AddBoolVarCache(&sDontDelayInputExhausted,
|
|
|
|
"media.decoder.fuzzing.dont-delay-inputexhausted", false);
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
WMFDecoderModule::Init();
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
AppleDecoderModule::Init();
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_FFMPEG
|
|
|
|
FFmpegRuntimeLinker::Link();
|
|
|
|
#endif
|
2015-10-08 00:40:09 -07:00
|
|
|
GMPDecoderModule::Init();
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PDMFactory::PDMFactory()
|
|
|
|
{
|
2015-10-05 15:08:03 -07:00
|
|
|
CreatePDMs();
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PDMFactory::~PDMFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<MediaDataDecoder>
|
|
|
|
PDMFactory::CreateDecoder(const TrackInfo& aConfig,
|
|
|
|
FlushableTaskQueue* aTaskQueue,
|
|
|
|
MediaDataDecoderCallback* aCallback,
|
|
|
|
layers::LayersBackend aLayersBackend,
|
|
|
|
layers::ImageContainer* aImageContainer)
|
|
|
|
{
|
2015-10-28 06:46:30 -07:00
|
|
|
bool isEncrypted = mEMEPDM && aConfig.mCrypto.mValid;
|
|
|
|
|
|
|
|
if (isEncrypted) {
|
|
|
|
return CreateDecoderWithPDM(mEMEPDM,
|
|
|
|
aConfig,
|
|
|
|
aTaskQueue,
|
|
|
|
aCallback,
|
|
|
|
aLayersBackend,
|
|
|
|
aImageContainer);
|
|
|
|
}
|
2015-10-06 01:56:29 -07:00
|
|
|
|
2015-10-28 06:46:30 -07:00
|
|
|
for (auto& current : mCurrentPDMs) {
|
|
|
|
if (!current->SupportsMimeType(aConfig.mMimeType)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RefPtr<MediaDataDecoder> m =
|
|
|
|
CreateDecoderWithPDM(current,
|
|
|
|
aConfig,
|
|
|
|
aTaskQueue,
|
|
|
|
aCallback,
|
|
|
|
aLayersBackend,
|
|
|
|
aImageContainer);
|
|
|
|
if (m) {
|
|
|
|
return m.forget();
|
|
|
|
}
|
2015-10-05 15:53:02 -07:00
|
|
|
}
|
2015-10-28 06:46:30 -07:00
|
|
|
NS_WARNING("Unable to create a decoder, no platform found.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<MediaDataDecoder>
|
|
|
|
PDMFactory::CreateDecoderWithPDM(PlatformDecoderModule* aPDM,
|
|
|
|
const TrackInfo& aConfig,
|
|
|
|
FlushableTaskQueue* aTaskQueue,
|
|
|
|
MediaDataDecoderCallback* aCallback,
|
|
|
|
layers::LayersBackend aLayersBackend,
|
|
|
|
layers::ImageContainer* aImageContainer)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPDM);
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<MediaDataDecoder> m;
|
2015-10-05 03:08:56 -07:00
|
|
|
|
|
|
|
if (aConfig.GetAsAudioInfo()) {
|
2015-10-28 06:46:30 -07:00
|
|
|
m = aPDM->CreateAudioDecoder(*aConfig.GetAsAudioInfo(),
|
|
|
|
aTaskQueue,
|
|
|
|
aCallback);
|
2015-10-05 03:08:56 -07:00
|
|
|
return m.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aConfig.GetAsVideoInfo()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaDataDecoderCallback* callback = aCallback;
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<DecoderCallbackFuzzingWrapper> callbackWrapper;
|
2015-10-05 03:08:56 -07:00
|
|
|
if (sEnableFuzzingWrapper) {
|
|
|
|
callbackWrapper = new DecoderCallbackFuzzingWrapper(aCallback);
|
|
|
|
callbackWrapper->SetVideoOutputMinimumInterval(
|
|
|
|
TimeDuration::FromMilliseconds(sVideoOutputMinimumInterval_ms));
|
|
|
|
callbackWrapper->SetDontDelayInputExhausted(sDontDelayInputExhausted);
|
|
|
|
callback = callbackWrapper.get();
|
|
|
|
}
|
|
|
|
|
2015-10-05 15:53:02 -07:00
|
|
|
if (H264Converter::IsH264(aConfig)) {
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<H264Converter> h
|
2015-10-28 06:46:30 -07:00
|
|
|
= new H264Converter(aPDM,
|
2015-10-05 15:53:02 -07:00
|
|
|
*aConfig.GetAsVideoInfo(),
|
|
|
|
aLayersBackend,
|
|
|
|
aImageContainer,
|
|
|
|
aTaskQueue,
|
|
|
|
callback);
|
|
|
|
const nsresult rv = h->GetLastError();
|
|
|
|
if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) {
|
|
|
|
// The H264Converter either successfully created the wrapped decoder,
|
|
|
|
// or there wasn't enough AVCC data to do so. Otherwise, there was some
|
|
|
|
// problem, for example WMF DLLs were missing.
|
|
|
|
m = h.forget();
|
2015-10-05 15:08:03 -07:00
|
|
|
}
|
2015-10-05 15:53:02 -07:00
|
|
|
} else {
|
2015-10-28 06:46:30 -07:00
|
|
|
m = aPDM->CreateVideoDecoder(*aConfig.GetAsVideoInfo(),
|
|
|
|
aLayersBackend,
|
|
|
|
aImageContainer,
|
|
|
|
aTaskQueue,
|
|
|
|
callback);
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (callbackWrapper && m) {
|
|
|
|
m = new DecoderFuzzingWrapper(m.forget(), callbackWrapper.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-11-04 07:01:51 -08:00
|
|
|
PDMFactory::SupportsMimeType(const nsACString& aMimeType) const
|
2015-10-05 03:08:56 -07:00
|
|
|
{
|
2015-10-06 01:56:29 -07:00
|
|
|
if (mEMEPDM) {
|
|
|
|
return mEMEPDM->SupportsMimeType(aMimeType);
|
|
|
|
}
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<PlatformDecoderModule> current = GetDecoder(aMimeType);
|
2015-10-05 15:53:02 -07:00
|
|
|
return !!current;
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
|
2015-10-05 15:08:03 -07:00
|
|
|
void
|
|
|
|
PDMFactory::CreatePDMs()
|
2015-10-05 03:08:56 -07:00
|
|
|
{
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<PlatformDecoderModule> m;
|
2015-10-05 15:08:03 -07:00
|
|
|
|
2015-10-26 14:49:03 -07:00
|
|
|
if (sUseBlankDecoder) {
|
|
|
|
m = CreateBlankDecoderModule();
|
|
|
|
StartupPDM(m);
|
|
|
|
// The Blank PDM SupportsMimeType reports true for all codecs; the creation
|
|
|
|
// of its decoder is infallible. As such it will be used for all media, we
|
|
|
|
// can stop creating more PDM from this point.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-05 03:08:56 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2015-10-05 15:08:03 -07:00
|
|
|
if(sAndroidMCDecoderPreferred && sAndroidMCDecoderEnabled) {
|
|
|
|
m = new AndroidDecoderModule();
|
|
|
|
StartupPDM(m);
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef XP_WIN
|
2015-10-14 18:51:34 -07:00
|
|
|
if (sWMFDecoderEnabled) {
|
|
|
|
m = new WMFDecoderModule();
|
|
|
|
StartupPDM(m);
|
|
|
|
}
|
2015-10-05 03:08:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_FFMPEG
|
2015-10-11 16:00:04 -07:00
|
|
|
if (sFFmpegDecoderEnabled) {
|
|
|
|
m = FFmpegRuntimeLinker::CreateDecoderModule();
|
|
|
|
StartupPDM(m);
|
|
|
|
}
|
2015-10-05 03:08:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_APPLEMEDIA
|
2015-10-05 15:08:03 -07:00
|
|
|
m = new AppleDecoderModule();
|
|
|
|
StartupPDM(m);
|
2015-10-05 03:08:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
if (sGonkDecoderEnabled) {
|
2015-10-05 15:08:03 -07:00
|
|
|
m = new GonkDecoderModule();
|
|
|
|
StartupPDM(m);
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if(sAndroidMCDecoderEnabled){
|
2015-10-05 15:08:03 -07:00
|
|
|
m = new AndroidDecoderModule();
|
|
|
|
StartupPDM(m);
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
#endif
|
2015-10-05 15:53:02 -07:00
|
|
|
|
|
|
|
m = new AgnosticDecoderModule();
|
|
|
|
StartupPDM(m);
|
2015-10-29 01:54:38 -07:00
|
|
|
|
|
|
|
if (sGMPDecoderEnabled) {
|
|
|
|
m = new GMPDecoderModule();
|
|
|
|
StartupPDM(m);
|
|
|
|
}
|
2015-10-05 15:08:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PDMFactory::StartupPDM(PlatformDecoderModule* aPDM)
|
|
|
|
{
|
|
|
|
if (aPDM && NS_SUCCEEDED(aPDM->Startup())) {
|
|
|
|
mCurrentPDMs.AppendElement(aPDM);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<PlatformDecoderModule>
|
2015-11-04 07:01:51 -08:00
|
|
|
PDMFactory::GetDecoder(const nsACString& aMimeType) const
|
2015-10-05 15:08:03 -07:00
|
|
|
{
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<PlatformDecoderModule> pdm;
|
2015-10-05 15:08:03 -07:00
|
|
|
for (auto& current : mCurrentPDMs) {
|
|
|
|
if (current->SupportsMimeType(aMimeType)) {
|
|
|
|
pdm = current;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pdm.forget();
|
2015-10-05 03:08:56 -07:00
|
|
|
}
|
|
|
|
|
2015-10-06 01:56:29 -07:00
|
|
|
#ifdef MOZ_EME
|
|
|
|
void
|
|
|
|
PDMFactory::SetCDMProxy(CDMProxy* aProxy)
|
|
|
|
{
|
|
|
|
bool cdmDecodesAudio;
|
|
|
|
bool cdmDecodesVideo;
|
|
|
|
{
|
|
|
|
CDMCaps::AutoLock caps(aProxy->Capabilites());
|
|
|
|
cdmDecodesAudio = caps.CanDecryptAndDecodeAudio();
|
|
|
|
cdmDecodesVideo = caps.CanDecryptAndDecodeVideo();
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<PDMFactory> m = new PDMFactory();
|
2015-10-06 01:56:29 -07:00
|
|
|
mEMEPDM = new EMEDecoderModule(aProxy, m, cdmDecodesAudio, cdmDecodesVideo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-05 03:08:56 -07:00
|
|
|
} // namespace mozilla
|