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"
|
2015-10-11 20:20:11 -07:00
|
|
|
#include "MacIOSurfaceImage.h"
|
2014-07-24 13:47:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-05-19 11:15:34 -07:00
|
|
|
#include "mozilla/Logging.h"
|
2014-11-27 13:23:00 -08:00
|
|
|
|
2014-07-24 13:47:00 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-09-11 17:53:19 -07:00
|
|
|
bool AppleDecoderModule::sInitialized = false;
|
2015-10-11 20:20:11 -07:00
|
|
|
bool AppleDecoderModule::sIsCoreMediaAvailable = 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;
|
2015-10-08 22:47:53 -07:00
|
|
|
bool AppleDecoderModule::sCanUseHardwareVideoDecoder = true;
|
2014-07-24 13:47:00 -07:00
|
|
|
|
|
|
|
AppleDecoderModule::AppleDecoderModule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppleDecoderModule::~AppleDecoderModule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2015-10-08 23:35:30 -07:00
|
|
|
// Ensure IOSurface framework is loaded.
|
|
|
|
MacIOSurfaceLib::LoadLibrary();
|
2015-10-11 20:20:11 -07:00
|
|
|
const bool loaded = MacIOSurfaceLib::isInit();
|
2015-10-08 23:35:30 -07:00
|
|
|
|
2014-09-16 19:54:26 -07:00
|
|
|
// dlopen VideoDecodeAcceleration.framework if it's available.
|
2015-10-11 20:20:11 -07:00
|
|
|
sIsVDAAvailable = loaded && AppleVDALinker::Link();
|
2014-09-16 19:54:26 -07:00
|
|
|
|
|
|
|
// dlopen CoreMedia.framework if it's available.
|
2015-10-11 20:20:11 -07:00
|
|
|
sIsCoreMediaAvailable = 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
|
2015-10-11 20:20:11 -07:00
|
|
|
bool haveVideoToolbox = loaded && AppleVTLinker::Link();
|
|
|
|
sIsVTAvailable = sIsCoreMediaAvailable && haveVideoToolbox;
|
2014-09-11 17:53:19 -07:00
|
|
|
|
2015-02-18 18:37:08 -08:00
|
|
|
sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr;
|
2014-09-11 17:53:19 -07:00
|
|
|
|
2015-10-11 20:20:11 -07:00
|
|
|
sCanUseHardwareVideoDecoder = loaded &&
|
2015-10-08 22:47:53 -07:00
|
|
|
gfxPlatform::GetPlatform()->CanUseHardwareVideoDecoding();
|
|
|
|
|
2014-09-11 17:53:19 -07:00
|
|
|
sInitialized = true;
|
|
|
|
}
|
|
|
|
|
2014-07-24 13:47:00 -07:00
|
|
|
nsresult
|
|
|
|
AppleDecoderModule::Startup()
|
|
|
|
{
|
2015-05-17 22:42:32 -07:00
|
|
|
if (!sInitialized || (!sIsVDAAvailable && !sIsVTAvailable)) {
|
2014-07-24 13:47:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
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-07-16 11:13:49 -07:00
|
|
|
FlushableTaskQueue* 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-07-16 11:13:49 -07:00
|
|
|
FlushableTaskQueue* 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-10-11 20:20:11 -07:00
|
|
|
return (sIsCoreMediaAvailable &&
|
|
|
|
(aMimeType.EqualsLiteral("audio/mpeg") ||
|
|
|
|
aMimeType.EqualsLiteral("audio/mp4a-latm"))) ||
|
|
|
|
((sIsVTAvailable || sIsVDAAvailable) &&
|
|
|
|
(aMimeType.EqualsLiteral("video/mp4") ||
|
|
|
|
aMimeType.EqualsLiteral("video/avc")));
|
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
|