Files
palemoon27/dom/media/platforms/apple/AppleDecoderModule.cpp
T
trav90 b4302296bc Remove sync dispatch from apple's initialization
It will now do just like what it does on all the other platforms: link on first use.
2018-07-25 01:29:13 +08:00

138 lines
3.9 KiB
C++

/* -*- 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 "AppleATDecoder.h"
#include "AppleCMLinker.h"
#include "AppleDecoderModule.h"
#include "AppleVDADecoder.h"
#include "AppleVDALinker.h"
#include "AppleVTDecoder.h"
#include "AppleVTLinker.h"
#include "mozilla/Preferences.h"
#include "mozilla/DebugOnly.h"
#include "prlog.h"
#ifdef PR_LOGGING
PRLogModuleInfo* GetAppleMediaLog() {
static PRLogModuleInfo* log = nullptr;
if (!log) {
log = PR_NewLogModule("AppleMedia");
}
return log;
}
#endif
namespace mozilla {
bool AppleDecoderModule::sInitialized = false;
bool AppleDecoderModule::sIsVTAvailable = false;
bool AppleDecoderModule::sIsVTHWAvailable = false;
bool AppleDecoderModule::sIsVDAAvailable = false;
bool AppleDecoderModule::sForceVDA = false;
AppleDecoderModule::AppleDecoderModule()
{
}
AppleDecoderModule::~AppleDecoderModule()
{
}
/* static */
void
AppleDecoderModule::Init()
{
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
sForceVDA = Preferences::GetBool("media.apple.forcevda", false);
if (sInitialized) {
return;
}
// dlopen VideoDecodeAcceleration.framework if it's available.
sIsVDAAvailable = AppleVDALinker::Link();
// dlopen CoreMedia.framework if it's available.
bool haveCoreMedia = AppleCMLinker::Link();
// dlopen VideoToolbox.framework if it's available.
// We must link both CM and VideoToolbox framework to allow for proper
// paired Link/Unlink calls
bool haveVideoToolbox = AppleVTLinker::Link();
sIsVTAvailable = haveCoreMedia && haveVideoToolbox;
sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr;
sInitialized = true;
}
nsresult
AppleDecoderModule::Startup()
{
if (!sInitialized || (!sIsVDAAvailable && !sIsVTAvailable)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
already_AddRefed<MediaDataDecoder>
AppleDecoderModule::CreateVideoDecoder(const VideoInfo& aConfig,
layers::LayersBackend aLayersBackend,
layers::ImageContainer* aImageContainer,
FlushableMediaTaskQueue* aVideoTaskQueue,
MediaDataDecoderCallback* aCallback)
{
nsRefPtr<MediaDataDecoder> decoder;
if (sIsVDAAvailable && (!sIsVTHWAvailable || sForceVDA)) {
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);
}
return decoder.forget();
}
already_AddRefed<MediaDataDecoder>
AppleDecoderModule::CreateAudioDecoder(const AudioInfo& aConfig,
FlushableMediaTaskQueue* aAudioTaskQueue,
MediaDataDecoderCallback* aCallback)
{
nsRefPtr<MediaDataDecoder> decoder =
new AppleATDecoder(aConfig, aAudioTaskQueue, aCallback);
return decoder.forget();
}
bool
AppleDecoderModule::SupportsMimeType(const nsACString& aMimeType)
{
return aMimeType.EqualsLiteral("audio/mpeg") ||
PlatformDecoderModule::SupportsMimeType(aMimeType);
}
PlatformDecoderModule::ConversionRequired
AppleDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
{
if (aConfig.IsVideo()) {
return kNeedAVCC;
} else {
return kNeedNone;
}
}
} // namespace mozilla