2014-07-24 13:47:00 -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/. */
|
|
|
|
|
2014-07-24 16:30:00 -07:00
|
|
|
#include "AppleATDecoder.h"
|
2014-07-24 13:47:00 -07:00
|
|
|
#include "AppleCMLinker.h"
|
|
|
|
#include "AppleDecoderModule.h"
|
2014-09-16 19:54:26 -07:00
|
|
|
#include "AppleVDADecoder.h"
|
|
|
|
#include "AppleVDALinker.h"
|
2014-07-24 13:47:00 -07:00
|
|
|
#include "AppleVTDecoder.h"
|
|
|
|
#include "AppleVTLinker.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-11-27 13:23:00 -08:00
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
PRLogModuleInfo* GetAppleMediaLog() {
|
|
|
|
static PRLogModuleInfo* log = nullptr;
|
|
|
|
if (!log) {
|
|
|
|
log = PR_NewLogModule("AppleMedia");
|
|
|
|
}
|
|
|
|
return log;
|
|
|
|
}
|
2014-07-24 13:47:00 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-09-11 17:53:19 -07:00
|
|
|
bool AppleDecoderModule::sInitialized = false;
|
2014-09-16 19:54:26 -07:00
|
|
|
bool AppleDecoderModule::sIsVTAvailable = false;
|
2014-09-11 17:53:19 -07:00
|
|
|
bool AppleDecoderModule::sIsVTHWAvailable = false;
|
2014-09-16 19:54:26 -07:00
|
|
|
bool AppleDecoderModule::sIsVDAAvailable = false;
|
2014-09-11 17:53:19 -07:00
|
|
|
bool AppleDecoderModule::sForceVDA = false;
|
2014-07-24 13:47:00 -07:00
|
|
|
|
2015-03-22 17:12:59 -07:00
|
|
|
class LinkTask : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
|
|
|
MOZ_ASSERT(AppleDecoderModule::sInitialized);
|
|
|
|
if (AppleDecoderModule::sIsVDAAvailable) {
|
|
|
|
AppleVDALinker::Link();
|
|
|
|
}
|
|
|
|
if (AppleDecoderModule::sIsVTAvailable) {
|
|
|
|
AppleVTLinker::Link();
|
|
|
|
AppleCMLinker::Link();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class UnlinkTask : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
|
|
|
MOZ_ASSERT(AppleDecoderModule::sInitialized);
|
|
|
|
if (AppleDecoderModule::sIsVDAAvailable) {
|
|
|
|
AppleVDALinker::Unlink();
|
|
|
|
}
|
|
|
|
if (AppleDecoderModule::sIsVTAvailable) {
|
|
|
|
AppleVTLinker::Unlink();
|
|
|
|
AppleCMLinker::Unlink();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-24 13:47:00 -07:00
|
|
|
AppleDecoderModule::AppleDecoderModule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppleDecoderModule::~AppleDecoderModule()
|
|
|
|
{
|
2015-03-22 17:12:59 -07:00
|
|
|
nsCOMPtr<nsIRunnable> task(new UnlinkTask());
|
2015-05-07 18:36:32 -07:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_DispatchToMainThread(task);
|
|
|
|
} else {
|
|
|
|
task->Run();
|
|
|
|
}
|
2014-07-24 13:47:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
AppleDecoderModule::Init()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
|
|
|
|
2014-09-11 17:53:19 -07:00
|
|
|
if (sInitialized) {
|
2014-07-24 13:47:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-01 15:48:28 -08:00
|
|
|
Preferences::AddBoolVarCache(&sForceVDA, "media.apple.forcevda", false);
|
|
|
|
|
2014-09-16 19:54:26 -07:00
|
|
|
// dlopen VideoDecodeAcceleration.framework if it's available.
|
|
|
|
sIsVDAAvailable = AppleVDALinker::Link();
|
|
|
|
|
|
|
|
// dlopen CoreMedia.framework if it's available.
|
|
|
|
bool haveCoreMedia = AppleCMLinker::Link();
|
2014-07-24 13:47:00 -07:00
|
|
|
// dlopen VideoToolbox.framework if it's available.
|
2014-09-16 19:54:26 -07:00
|
|
|
// We must link both CM and VideoToolbox framework to allow for proper
|
|
|
|
// paired Link/Unlink calls
|
2014-09-11 17:53:19 -07:00
|
|
|
bool haveVideoToolbox = AppleVTLinker::Link();
|
|
|
|
sIsVTAvailable = haveCoreMedia && haveVideoToolbox;
|
|
|
|
|
2015-02-18 18:37:08 -08:00
|
|
|
sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr;
|
2014-09-11 17:53:19 -07:00
|
|
|
|
|
|
|
if (sIsVDAAvailable) {
|
|
|
|
AppleVDALinker::Unlink();
|
|
|
|
}
|
|
|
|
if (sIsVTAvailable) {
|
|
|
|
AppleVTLinker::Unlink();
|
|
|
|
AppleCMLinker::Unlink();
|
|
|
|
}
|
|
|
|
sInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
class InitTask : public nsRunnable {
|
|
|
|
public:
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Run() override {
|
2014-09-11 17:53:19 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
|
|
|
AppleDecoderModule::Init();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-24 13:47:00 -07:00
|
|
|
nsresult
|
|
|
|
AppleDecoderModule::Startup()
|
|
|
|
{
|
2014-09-16 19:54:26 -07:00
|
|
|
if (!sIsVDAAvailable && !sIsVTAvailable) {
|
2014-07-24 13:47:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-09-11 17:53:19 -07:00
|
|
|
|
2015-05-07 18:36:32 -07:00
|
|
|
// Note: We can be called on the main thread from MP4Decoder::CanHandleMediaType().
|
2015-03-17 09:29:17 -07:00
|
|
|
nsCOMPtr<nsIRunnable> task(new LinkTask());
|
2015-05-07 18:36:32 -07:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_DispatchToMainThread(task, NS_DISPATCH_SYNC);
|
|
|
|
} else {
|
|
|
|
task->Run();
|
|
|
|
}
|
2014-09-11 17:53:19 -07:00
|
|
|
|
2014-07-24 13:47:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-30 18:40:21 -07:00
|
|
|
already_AddRefed<MediaDataDecoder>
|
2015-04-13 22:16:32 -07:00
|
|
|
AppleDecoderModule::CreateVideoDecoder(const VideoInfo& aConfig,
|
2014-11-10 19:30:52 -08:00
|
|
|
layers::LayersBackend aLayersBackend,
|
|
|
|
layers::ImageContainer* aImageContainer,
|
2015-02-14 19:08:15 -08:00
|
|
|
FlushableMediaTaskQueue* aVideoTaskQueue,
|
2014-11-10 19:30:52 -08:00
|
|
|
MediaDataDecoderCallback* aCallback)
|
2014-07-24 13:47:00 -07:00
|
|
|
{
|
2014-09-16 19:54:26 -07:00
|
|
|
nsRefPtr<MediaDataDecoder> decoder;
|
|
|
|
|
2015-04-12 02:16:33 -07:00
|
|
|
if (sIsVDAAvailable && (!sIsVTHWAvailable || sForceVDA)) {
|
2014-09-16 19:54:26 -07:00
|
|
|
decoder =
|
|
|
|
AppleVDADecoder::CreateVDADecoder(aConfig,
|
|
|
|
aVideoTaskQueue,
|
|
|
|
aCallback,
|
|
|
|
aImageContainer);
|
|
|
|
if (decoder) {
|
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We fallback here if VDA isn't available, or is available but isn't
|
|
|
|
// supported by the current platform.
|
|
|
|
if (sIsVTAvailable) {
|
|
|
|
decoder =
|
|
|
|
new AppleVTDecoder(aConfig, aVideoTaskQueue, aCallback, aImageContainer);
|
|
|
|
}
|
2014-07-30 18:40:21 -07:00
|
|
|
return decoder.forget();
|
2014-07-24 13:47:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-30 18:40:21 -07:00
|
|
|
already_AddRefed<MediaDataDecoder>
|
2015-04-13 22:16:32 -07:00
|
|
|
AppleDecoderModule::CreateAudioDecoder(const AudioInfo& aConfig,
|
2015-02-14 19:08:15 -08:00
|
|
|
FlushableMediaTaskQueue* aAudioTaskQueue,
|
2014-08-14 23:25:06 -07:00
|
|
|
MediaDataDecoderCallback* aCallback)
|
2014-07-24 13:47:00 -07:00
|
|
|
{
|
2014-07-30 18:40:21 -07:00
|
|
|
nsRefPtr<MediaDataDecoder> decoder =
|
|
|
|
new AppleATDecoder(aConfig, aAudioTaskQueue, aCallback);
|
|
|
|
return decoder.forget();
|
2014-07-24 13:47:00 -07:00
|
|
|
}
|
|
|
|
|
2014-08-14 23:25:06 -07:00
|
|
|
bool
|
2015-04-07 03:33:17 -07:00
|
|
|
AppleDecoderModule::SupportsMimeType(const nsACString& aMimeType)
|
2014-08-14 23:25:06 -07:00
|
|
|
{
|
2015-04-07 03:33:17 -07:00
|
|
|
return aMimeType.EqualsLiteral("audio/mpeg") ||
|
|
|
|
PlatformDecoderModule::SupportsMimeType(aMimeType);
|
2014-08-14 23:25:06 -07:00
|
|
|
}
|
|
|
|
|
2015-04-07 03:33:17 -07:00
|
|
|
PlatformDecoderModule::ConversionRequired
|
2015-04-13 22:16:32 -07:00
|
|
|
AppleDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
|
2014-12-22 19:36:10 -08:00
|
|
|
{
|
2015-04-13 22:16:32 -07:00
|
|
|
if (aConfig.IsVideo()) {
|
2015-04-07 03:33:17 -07:00
|
|
|
return kNeedAVCC;
|
|
|
|
} else {
|
|
|
|
return kNeedNone;
|
|
|
|
}
|
2014-12-22 19:36:10 -08:00
|
|
|
}
|
|
|
|
|
2014-07-24 13:47:00 -07:00
|
|
|
} // namespace mozilla
|