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"
|
2014-12-23 03:36:10 +00:00
|
|
|
#include "AVCCDecoderModule.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
|
2014-10-21 13:53:01 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidDecoderModule.h"
|
|
|
|
#endif
|
2014-08-07 10:23:45 +00:00
|
|
|
|
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 {
|
|
|
|
|
2014-12-23 03:36:10 +00:00
|
|
|
extern already_AddRefed<PlatformDecoderModule> CreateBlankDecoderModule();
|
2013-11-20 21:04:33 +00:00
|
|
|
|
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;
|
2014-10-21 13:53:01 +00:00
|
|
|
bool PlatformDecoderModule::sAndroidMCDecoderEnabled = false;
|
|
|
|
bool PlatformDecoderModule::sAndroidMCDecoderPreferred = 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-10-21 13:53:01 +00:00
|
|
|
|
2014-08-07 10:23:45 +00:00
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
Preferences::AddBoolVarCache(&sGonkDecoderEnabled,
|
|
|
|
"media.fragmented-mp4.gonk.enabled", false);
|
|
|
|
#endif
|
2014-10-21 13:53:01 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
Preferences::AddBoolVarCache(&sAndroidMCDecoderEnabled,
|
|
|
|
"media.fragmented-mp4.android-media-codec.enabled", false);
|
|
|
|
Preferences::AddBoolVarCache(&sAndroidMCDecoderPreferred,
|
|
|
|
"media.fragmented-mp4.android-media-codec.preferred", 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-10-13 22:05:00 +00:00
|
|
|
#ifdef MOZ_EME
|
2014-07-30 06:53:34 +00:00
|
|
|
/* static */
|
2014-12-23 03:36:10 +00:00
|
|
|
already_AddRefed<PlatformDecoderModule>
|
2014-07-30 06:53:34 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> pdm;
|
2014-07-30 06:53:34 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> emepdm(
|
|
|
|
new AVCCDecoderModule(new EMEDecoderModule(aProxy,
|
|
|
|
pdm,
|
|
|
|
cdmDecodesAudio,
|
|
|
|
cdmDecodesVideo)));
|
2014-12-23 03:36:10 +00:00
|
|
|
return emepdm.forget();
|
2014-07-30 06:53:34 +00:00
|
|
|
}
|
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 */
|
2014-12-23 03:36:10 +00:00
|
|
|
already_AddRefed<PlatformDecoderModule>
|
2013-11-20 21:04:33 +00:00
|
|
|
PlatformDecoderModule::Create()
|
|
|
|
{
|
2014-08-03 07:28:39 +00:00
|
|
|
// Note: This runs on the decode thread.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(CreatePDM());
|
|
|
|
|
|
|
|
if (m && NS_SUCCEEDED(m->Startup())) {
|
|
|
|
return m.forget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<PlatformDecoderModule>
|
|
|
|
PlatformDecoderModule::CreatePDM()
|
|
|
|
{
|
2014-10-21 13:53:01 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if(sAndroidMCDecoderPreferred && sAndroidMCDecoderEnabled){
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(new AndroidDecoderModule());
|
|
|
|
return m.forget();
|
2014-10-21 13:53:01 +00:00
|
|
|
}
|
|
|
|
#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
|
|
|
if (sUseBlankDecoder) {
|
2013-11-20 21:04:33 +00:00
|
|
|
return CreateBlankDecoderModule();
|
|
|
|
}
|
2013-11-20 21:04:33 +00:00
|
|
|
#ifdef XP_WIN
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(new WMFDecoderModule());
|
|
|
|
return m.forget();
|
2014-03-21 06:35:15 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_FFMPEG
|
|
|
|
if (sFFmpegDecoderEnabled) {
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(FFmpegRuntimeLinker::CreateDecoderModule());
|
2014-08-05 06:13:05 +00:00
|
|
|
if (m) {
|
|
|
|
return m.forget();
|
|
|
|
}
|
2014-07-28 22:36:00 +00:00
|
|
|
}
|
2014-07-24 20:47:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_APPLEMEDIA
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(new AVCCDecoderModule(new AppleDecoderModule()));
|
2014-12-23 03:36:10 +00:00
|
|
|
return m.forget();
|
2014-08-07 10:23:45 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GONK_MEDIACODEC
|
|
|
|
if (sGonkDecoderEnabled) {
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(new GonkDecoderModule());
|
|
|
|
return m.forget();
|
2014-08-07 10:23:45 +00:00
|
|
|
}
|
2014-10-21 13:53:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if(sAndroidMCDecoderEnabled){
|
2014-12-23 03:36:10 +00:00
|
|
|
nsRefPtr<PlatformDecoderModule> m(new AndroidDecoderModule());
|
|
|
|
return m.forget();
|
2014-10-21 13:53:01 +00:00
|
|
|
}
|
2013-11-20 21:04:33 +00:00
|
|
|
#endif
|
2013-11-20 21:04:33 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-15 06:25:06 +00:00
|
|
|
bool
|
|
|
|
PlatformDecoderModule::SupportsAudioMimeType(const char* aMimeType)
|
|
|
|
{
|
|
|
|
return !strcmp(aMimeType, "audio/mp4a-latm");
|
|
|
|
}
|
|
|
|
|
2014-11-11 03:30:52 +00:00
|
|
|
bool
|
|
|
|
PlatformDecoderModule::SupportsVideoMimeType(const char* aMimeType)
|
|
|
|
{
|
|
|
|
return !strcmp(aMimeType, "video/mp4") || !strcmp(aMimeType, "video/avc");
|
|
|
|
}
|
|
|
|
|
2014-12-23 03:36:10 +00:00
|
|
|
bool
|
|
|
|
PlatformDecoderModule::DecoderNeedsAVCC(const mp4_demuxer::VideoDecoderConfig& aConfig)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
} // namespace mozilla
|