mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out changeset 07e06fefa4c7 (bug 1240630) for webgl leaks
This commit is contained in:
parent
5437d31d81
commit
3192733cf9
@ -101,7 +101,7 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePacket(MediaRawData* aSample)
|
|||||||
{
|
{
|
||||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
AV_CALL(av_init_packet(&packet));
|
av_init_packet(&packet);
|
||||||
|
|
||||||
packet.data = const_cast<uint8_t*>(aSample->Data());
|
packet.data = const_cast<uint8_t*>(aSample->Data());
|
||||||
packet.size = aSample->Size();
|
packet.size = aSample->Size();
|
||||||
@ -118,7 +118,7 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePacket(MediaRawData* aSample)
|
|||||||
while (packet.size > 0) {
|
while (packet.size > 0) {
|
||||||
int decoded;
|
int decoded;
|
||||||
int bytesConsumed =
|
int bytesConsumed =
|
||||||
AV_CALL(avcodec_decode_audio4(mCodecContext, mFrame, &decoded, &packet));
|
avcodec_decode_audio4(mCodecContext, mFrame, &decoded, &packet);
|
||||||
|
|
||||||
if (bytesConsumed < 0) {
|
if (bytesConsumed < 0) {
|
||||||
NS_WARNING("FFmpeg audio decoder error.");
|
NS_WARNING("FFmpeg audio decoder error.");
|
||||||
|
@ -54,7 +54,7 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecoder()
|
|||||||
|
|
||||||
StaticMutexAutoLock mon(sMonitor);
|
StaticMutexAutoLock mon(sMonitor);
|
||||||
|
|
||||||
if (!(mCodecContext = AV_CALL(avcodec_alloc_context3(codec)))) {
|
if (!(mCodecContext = avcodec_alloc_context3(codec))) {
|
||||||
NS_WARNING("Couldn't init ffmpeg context");
|
NS_WARNING("Couldn't init ffmpeg context");
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
@ -77,10 +77,10 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecoder()
|
|||||||
mCodecContext->flags |= CODEC_FLAG_EMU_EDGE;
|
mCodecContext->flags |= CODEC_FLAG_EMU_EDGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AV_CALL(avcodec_open2(mCodecContext, codec, nullptr)) < 0) {
|
if (avcodec_open2(mCodecContext, codec, nullptr) < 0) {
|
||||||
NS_WARNING("Couldn't initialise ffmpeg decoder");
|
NS_WARNING("Couldn't initialise ffmpeg decoder");
|
||||||
AV_CALL(avcodec_close(mCodecContext));
|
avcodec_close(mCodecContext);
|
||||||
AV_CALL(av_freep(&mCodecContext));
|
av_freep(&mCodecContext);
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessFlush()
|
|||||||
{
|
{
|
||||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||||
if (mCodecContext) {
|
if (mCodecContext) {
|
||||||
AV_CALL(avcodec_flush_buffers(mCodecContext));
|
avcodec_flush_buffers(mCodecContext);
|
||||||
}
|
}
|
||||||
MonitorAutoLock mon(mMonitor);
|
MonitorAutoLock mon(mMonitor);
|
||||||
mIsFlushing = false;
|
mIsFlushing = false;
|
||||||
@ -154,12 +154,12 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessShutdown()
|
|||||||
StaticMutexAutoLock mon(sMonitor);
|
StaticMutexAutoLock mon(sMonitor);
|
||||||
|
|
||||||
if (sFFmpegInitDone && mCodecContext) {
|
if (sFFmpegInitDone && mCodecContext) {
|
||||||
AV_CALL(avcodec_close(mCodecContext));
|
avcodec_close(mCodecContext);
|
||||||
AV_CALL(av_freep(&mCodecContext));
|
av_freep(&mCodecContext);
|
||||||
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
||||||
AV_CALL(av_frame_free(&mFrame));
|
av_frame_free(&mFrame);
|
||||||
#elif LIBAVCODEC_VERSION_MAJOR == 54
|
#elif LIBAVCODEC_VERSION_MAJOR == 54
|
||||||
AV_CALL(avcodec_free_frame(&mFrame));
|
avcodec_free_frame(&mFrame);
|
||||||
#else
|
#else
|
||||||
delete mFrame;
|
delete mFrame;
|
||||||
mFrame = nullptr;
|
mFrame = nullptr;
|
||||||
@ -173,20 +173,20 @@ FFmpegDataDecoder<LIBAV_VER>::PrepareFrame()
|
|||||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||||
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
||||||
if (mFrame) {
|
if (mFrame) {
|
||||||
AV_CALL(av_frame_unref(mFrame));
|
av_frame_unref(mFrame);
|
||||||
} else {
|
} else {
|
||||||
mFrame = AV_CALL(av_frame_alloc());
|
mFrame = av_frame_alloc();
|
||||||
}
|
}
|
||||||
#elif LIBAVCODEC_VERSION_MAJOR == 54
|
#elif LIBAVCODEC_VERSION_MAJOR == 54
|
||||||
if (mFrame) {
|
if (mFrame) {
|
||||||
AV_CALL(avcodec_get_frame_defaults(mFrame));
|
avcodec_get_frame_defaults(mFrame);
|
||||||
} else {
|
} else {
|
||||||
mFrame = AV_CALL(avcodec_alloc_frame());
|
mFrame = avcodec_alloc_frame();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
delete mFrame;
|
delete mFrame;
|
||||||
mFrame = new AVFrame;
|
mFrame = new AVFrame;
|
||||||
AV_CALL(avcodec_get_frame_defaults(mFrame));
|
avcodec_get_frame_defaults(mFrame);
|
||||||
#endif
|
#endif
|
||||||
return mFrame;
|
return mFrame;
|
||||||
}
|
}
|
||||||
@ -196,13 +196,13 @@ FFmpegDataDecoder<LIBAV_VER>::FindAVCodec(AVCodecID aCodec)
|
|||||||
{
|
{
|
||||||
StaticMutexAutoLock mon(sMonitor);
|
StaticMutexAutoLock mon(sMonitor);
|
||||||
if (!sFFmpegInitDone) {
|
if (!sFFmpegInitDone) {
|
||||||
AV_CALL(avcodec_register_all());
|
avcodec_register_all();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
AV_CALL(av_log_set_level(AV_LOG_DEBUG));
|
av_log_set_level(AV_LOG_DEBUG);
|
||||||
#endif
|
#endif
|
||||||
sFFmpegInitDone = true;
|
sFFmpegInitDone = true;
|
||||||
}
|
}
|
||||||
return AV_CALL(avcodec_find_decoder(aCodec));
|
return avcodec_find_decoder(aCodec);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
@ -47,22 +47,14 @@ public:
|
|||||||
FlushableTaskQueue* aAudioTaskQueue,
|
FlushableTaskQueue* aAudioTaskQueue,
|
||||||
MediaDataDecoderCallback* aCallback) override
|
MediaDataDecoderCallback* aCallback) override
|
||||||
{
|
{
|
||||||
#ifdef USING_MOZFFVPX
|
|
||||||
return nullptr;
|
|
||||||
#else
|
|
||||||
RefPtr<MediaDataDecoder> decoder =
|
RefPtr<MediaDataDecoder> decoder =
|
||||||
new FFmpegAudioDecoder<V>(aAudioTaskQueue, aCallback, aConfig);
|
new FFmpegAudioDecoder<V>(aAudioTaskQueue, aCallback, aConfig);
|
||||||
return decoder.forget();
|
return decoder.forget();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SupportsMimeType(const nsACString& aMimeType) const override
|
bool SupportsMimeType(const nsACString& aMimeType) const override
|
||||||
{
|
{
|
||||||
#ifdef USING_MOZFFVPX
|
|
||||||
AVCodecID audioCodec = AV_CODEC_ID_NONE;
|
|
||||||
#else
|
|
||||||
AVCodecID audioCodec = FFmpegAudioDecoder<V>::GetCodecId(aMimeType);
|
AVCodecID audioCodec = FFmpegAudioDecoder<V>::GetCodecId(aMimeType);
|
||||||
#endif
|
|
||||||
AVCodecID videoCodec = FFmpegH264Decoder<V>::GetCodecId(aMimeType);
|
AVCodecID videoCodec = FFmpegH264Decoder<V>::GetCodecId(aMimeType);
|
||||||
if (audioCodec == AV_CODEC_ID_NONE && videoCodec == AV_CODEC_ID_NONE) {
|
if (audioCodec == AV_CODEC_ID_NONE && videoCodec == AV_CODEC_ID_NONE) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -151,7 +151,7 @@ FFmpegH264Decoder<LIBAV_VER>::InitCodecContext()
|
|||||||
// FFmpeg will call back to this to negotiate a video pixel format.
|
// FFmpeg will call back to this to negotiate a video pixel format.
|
||||||
mCodecContext->get_format = ChoosePixelFormat;
|
mCodecContext->get_format = ChoosePixelFormat;
|
||||||
|
|
||||||
mCodecParser = AV_CALL(av_parser_init(mCodecID));
|
mCodecParser = av_parser_init(mCodecID);
|
||||||
if (mCodecParser) {
|
if (mCodecParser) {
|
||||||
mCodecParser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
|
mCodecParser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
|
||||||
}
|
}
|
||||||
@ -175,10 +175,10 @@ FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample)
|
|||||||
while (inputSize) {
|
while (inputSize) {
|
||||||
uint8_t* data;
|
uint8_t* data;
|
||||||
int size;
|
int size;
|
||||||
int len = AV_CALL(av_parser_parse2(mCodecParser, mCodecContext, &data, &size,
|
int len = av_parser_parse2(mCodecParser, mCodecContext, &data, &size,
|
||||||
inputData, inputSize,
|
inputData, inputSize,
|
||||||
aSample->mTime, aSample->mTimecode,
|
aSample->mTime, aSample->mTimecode,
|
||||||
aSample->mOffset));
|
aSample->mOffset);
|
||||||
if (size_t(len) > inputSize) {
|
if (size_t(len) > inputSize) {
|
||||||
mCallback->Error();
|
mCallback->Error();
|
||||||
return DecodeResult::DECODE_ERROR;
|
return DecodeResult::DECODE_ERROR;
|
||||||
@ -210,7 +210,7 @@ FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample,
|
|||||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||||
|
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
AV_CALL(av_init_packet(&packet));
|
av_init_packet(&packet);
|
||||||
|
|
||||||
packet.data = aData;
|
packet.data = aData;
|
||||||
packet.size = aSize;
|
packet.size = aSize;
|
||||||
@ -237,7 +237,7 @@ FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample,
|
|||||||
|
|
||||||
int decoded;
|
int decoded;
|
||||||
int bytesConsumed =
|
int bytesConsumed =
|
||||||
AV_CALL(avcodec_decode_video2(mCodecContext, mFrame, &decoded, &packet));
|
avcodec_decode_video2(mCodecContext, mFrame, &decoded, &packet);
|
||||||
|
|
||||||
FFMPEG_LOG("DoDecodeFrame:decode_video: rv=%d decoded=%d "
|
FFMPEG_LOG("DoDecodeFrame:decode_video: rv=%d decoded=%d "
|
||||||
"(Input: pts(%lld) dts(%lld) Output: pts(%lld) "
|
"(Input: pts(%lld) dts(%lld) Output: pts(%lld) "
|
||||||
@ -361,7 +361,7 @@ FFmpegH264Decoder<LIBAV_VER>::~FFmpegH264Decoder()
|
|||||||
{
|
{
|
||||||
MOZ_COUNT_DTOR(FFmpegH264Decoder);
|
MOZ_COUNT_DTOR(FFmpegH264Decoder);
|
||||||
if (mCodecParser) {
|
if (mCodecParser) {
|
||||||
AV_CALL(av_parser_close(mCodecParser));
|
av_parser_close(mCodecParser);
|
||||||
mCodecParser = nullptr;
|
mCodecParser = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,29 +31,14 @@ extern "C" {
|
|||||||
typedef CodecID AVCodecID;
|
typedef CodecID AVCodecID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FFVPX_VERSION
|
|
||||||
enum { LIBAV_VER = FFVPX_VERSION };
|
|
||||||
#else
|
|
||||||
enum { LIBAV_VER = LIBAVCODEC_VERSION_MAJOR };
|
enum { LIBAV_VER = LIBAVCODEC_VERSION_MAJOR };
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
#ifdef USING_MOZFFVPX
|
|
||||||
namespace ffvpx {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define AV_FUNC(func, ver) extern decltype(func)* func;
|
#define AV_FUNC(func, ver) extern decltype(func)* func;
|
||||||
#include "FFmpegFunctionList.h"
|
#include "FFmpegFunctionList.h"
|
||||||
#undef AV_FUNC
|
#undef AV_FUNC
|
||||||
|
|
||||||
#ifdef USING_MOZFFVPX
|
|
||||||
} // namespace ffvpx
|
|
||||||
#define AV_CALL(func) mozilla::ffvpx::func
|
|
||||||
#else
|
|
||||||
#define AV_CALL(func) mozilla::func
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __FFmpegLibs_h__
|
#endif // __FFmpegLibs_h__
|
||||||
|
@ -7,9 +7,18 @@
|
|||||||
#include "FFmpegRuntimeLinker.h"
|
#include "FFmpegRuntimeLinker.h"
|
||||||
#include "mozilla/ArrayUtils.h"
|
#include "mozilla/ArrayUtils.h"
|
||||||
#include "FFmpegLog.h"
|
#include "FFmpegLog.h"
|
||||||
|
#include "mozilla/Preferences.h"
|
||||||
#include "mozilla/Types.h"
|
#include "mozilla/Types.h"
|
||||||
|
#include "nsIFile.h"
|
||||||
|
#include "nsXPCOMPrivate.h" // for XUL_DLL
|
||||||
|
#include "prmem.h"
|
||||||
#include "prlink.h"
|
#include "prlink.h"
|
||||||
|
|
||||||
|
#if defined(XP_WIN)
|
||||||
|
#include "libavcodec/avcodec.h"
|
||||||
|
#include "libavutil/avutil.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mozilla
|
namespace mozilla
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -44,7 +53,6 @@ PRLibrary* FFmpegRuntimeLinker::sLinkedLib = nullptr;
|
|||||||
PRLibrary* FFmpegRuntimeLinker::sLinkedUtilLib = nullptr;
|
PRLibrary* FFmpegRuntimeLinker::sLinkedUtilLib = nullptr;
|
||||||
static unsigned (*avcodec_version)() = nullptr;
|
static unsigned (*avcodec_version)() = nullptr;
|
||||||
|
|
||||||
#if !defined(XP_WIN)
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define AV_FUNC(func, ver) void (*func)();
|
#define AV_FUNC(func, ver) void (*func)();
|
||||||
#define LIBAVCODEC_ALLVERSION
|
#define LIBAVCODEC_ALLVERSION
|
||||||
@ -53,7 +61,6 @@ static unsigned (*avcodec_version)() = nullptr;
|
|||||||
#endif
|
#endif
|
||||||
#include "FFmpegFunctionList.h"
|
#include "FFmpegFunctionList.h"
|
||||||
#undef AV_FUNC
|
#undef AV_FUNC
|
||||||
#endif
|
|
||||||
|
|
||||||
static PRLibrary*
|
static PRLibrary*
|
||||||
MozAVLink(const char* aName)
|
MozAVLink(const char* aName)
|
||||||
@ -70,7 +77,7 @@ FFmpegRuntimeLinker::Link()
|
|||||||
if (sLinkStatus) {
|
if (sLinkStatus) {
|
||||||
return sLinkStatus == LinkStatus_SUCCEEDED;
|
return sLinkStatus == LinkStatus_SUCCEEDED;
|
||||||
}
|
}
|
||||||
#if !defined(XP_WIN)
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
for (size_t i = 0; i < ArrayLength(sLibs); i++) {
|
for (size_t i = 0; i < ArrayLength(sLibs); i++) {
|
||||||
@ -93,9 +100,56 @@ FFmpegRuntimeLinker::Link()
|
|||||||
}
|
}
|
||||||
FFMPEG_LOG(" ]\n");
|
FFMPEG_LOG(" ]\n");
|
||||||
|
|
||||||
Unlink();
|
#ifdef MOZ_FFVPX
|
||||||
|
// We retrieve the path of the XUL library as this is where mozavcodec and
|
||||||
|
// mozavutil libs are located.
|
||||||
|
char* path =
|
||||||
|
PR_GetLibraryFilePathname(XUL_DLL, (PRFuncPtr)&FFmpegRuntimeLinker::Link);
|
||||||
|
if (!path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
nsCOMPtr<nsIFile> xulFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||||
|
if (!xulFile ||
|
||||||
|
NS_FAILED(xulFile->InitWithNativePath(nsDependentCString(path)))) {
|
||||||
|
PR_Free(path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PR_Free(path);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIFile> rootDir;
|
||||||
|
if (NS_FAILED(xulFile->GetParent(getter_AddRefs(rootDir))) || !rootDir) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
nsAutoCString rootPath;
|
||||||
|
if (NS_FAILED(rootDir->GetNativePath(rootPath))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* libname = NULL;
|
||||||
|
/* Get the platform-dependent library name of the module */
|
||||||
|
libname = PR_GetLibraryName(rootPath.get(), "mozavutil");
|
||||||
|
if (!libname) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sLinkedUtilLib = MozAVLink(libname);
|
||||||
|
PR_FreeLibraryName(libname);
|
||||||
|
libname = PR_GetLibraryName(rootPath.get(), "mozavcodec");
|
||||||
|
if (!libname) {
|
||||||
|
Unlink();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sLinkedLib = MozAVLink(libname);
|
||||||
|
PR_FreeLibraryName(libname);
|
||||||
|
if (sLinkedLib && sLinkedUtilLib) {
|
||||||
|
if (Bind("mozavcodec")) {
|
||||||
|
sLinkStatus = LinkStatus_SUCCEEDED;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Unlink();
|
||||||
|
|
||||||
sLinkStatus = LinkStatus_FAILED;
|
sLinkStatus = LinkStatus_FAILED;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -103,9 +157,6 @@ FFmpegRuntimeLinker::Link()
|
|||||||
/* static */ bool
|
/* static */ bool
|
||||||
FFmpegRuntimeLinker::Bind(const char* aLibName)
|
FFmpegRuntimeLinker::Bind(const char* aLibName)
|
||||||
{
|
{
|
||||||
#if defined(XP_WIN)
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
avcodec_version = (decltype(avcodec_version))PR_FindSymbol(sLinkedLib,
|
avcodec_version = (decltype(avcodec_version))PR_FindSymbol(sLinkedLib,
|
||||||
"avcodec_version");
|
"avcodec_version");
|
||||||
uint32_t major, minor, micro;
|
uint32_t major, minor, micro;
|
||||||
@ -152,15 +203,11 @@ FFmpegRuntimeLinker::Bind(const char* aLibName)
|
|||||||
#include "FFmpegFunctionList.h"
|
#include "FFmpegFunctionList.h"
|
||||||
#undef AV_FUNC
|
#undef AV_FUNC
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ already_AddRefed<PlatformDecoderModule>
|
/* static */ already_AddRefed<PlatformDecoderModule>
|
||||||
FFmpegRuntimeLinker::CreateDecoderModule()
|
FFmpegRuntimeLinker::CreateDecoderModule()
|
||||||
{
|
{
|
||||||
#if defined(XP_WIN)
|
|
||||||
return nullptr;
|
|
||||||
#else
|
|
||||||
if (!Link()) {
|
if (!Link()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -171,15 +218,16 @@ FFmpegRuntimeLinker::CreateDecoderModule()
|
|||||||
|
|
||||||
RefPtr<PlatformDecoderModule> module;
|
RefPtr<PlatformDecoderModule> module;
|
||||||
switch (major) {
|
switch (major) {
|
||||||
|
#ifndef XP_WIN
|
||||||
case 53: module = FFmpegDecoderModule<53>::Create(); break;
|
case 53: module = FFmpegDecoderModule<53>::Create(); break;
|
||||||
case 54: module = FFmpegDecoderModule<54>::Create(); break;
|
case 54: module = FFmpegDecoderModule<54>::Create(); break;
|
||||||
case 55:
|
case 55:
|
||||||
case 56: module = FFmpegDecoderModule<55>::Create(); break;
|
case 56: module = FFmpegDecoderModule<55>::Create(); break;
|
||||||
|
#endif
|
||||||
case 57: module = FFmpegDecoderModule<57>::Create(); break;
|
case 57: module = FFmpegDecoderModule<57>::Create(); break;
|
||||||
default: module = nullptr;
|
default: module = nullptr;
|
||||||
}
|
}
|
||||||
return module.forget();
|
return module.forget();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
|
@ -1,162 +0,0 @@
|
|||||||
/* -*- 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 "FFVPXRuntimeLinker.h"
|
|
||||||
#include "FFmpegRuntimeLinker.h"
|
|
||||||
#include "FFmpegLog.h"
|
|
||||||
#include "mozilla/Types.h"
|
|
||||||
#include "nsIFile.h"
|
|
||||||
#include "nsXPCOMPrivate.h" // for XUL_DLL
|
|
||||||
#include "prmem.h"
|
|
||||||
#include "prlink.h"
|
|
||||||
|
|
||||||
#if defined(XP_WIN)
|
|
||||||
#include "libavcodec/avcodec.h"
|
|
||||||
#include "libavutil/avutil.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace mozilla
|
|
||||||
{
|
|
||||||
|
|
||||||
template <int V> class FFmpegDecoderModule
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static already_AddRefed<PlatformDecoderModule> Create();
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ffvpx
|
|
||||||
{
|
|
||||||
|
|
||||||
FFVPXRuntimeLinker::LinkStatus FFVPXRuntimeLinker::sLinkStatus =
|
|
||||||
LinkStatus_INIT;
|
|
||||||
|
|
||||||
PRLibrary* FFVPXRuntimeLinker::sLinkedLib = nullptr;
|
|
||||||
PRLibrary* FFVPXRuntimeLinker::sLinkedUtilLib = nullptr;
|
|
||||||
static unsigned (*avcodec_version)() = nullptr;
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define AV_FUNC(func, ver) void (*func)();
|
|
||||||
#define LIBAVCODEC_ALLVERSION
|
|
||||||
#else
|
|
||||||
#define AV_FUNC(func, ver) decltype(func)* func;
|
|
||||||
#endif
|
|
||||||
#include "FFmpegFunctionList.h"
|
|
||||||
#undef AV_FUNC
|
|
||||||
|
|
||||||
static PRLibrary*
|
|
||||||
MozAVLink(const char* aName)
|
|
||||||
{
|
|
||||||
PRLibSpec lspec;
|
|
||||||
lspec.type = PR_LibSpec_Pathname;
|
|
||||||
lspec.value.pathname = aName;
|
|
||||||
return PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ bool
|
|
||||||
FFVPXRuntimeLinker::Link()
|
|
||||||
{
|
|
||||||
if (sLinkStatus) {
|
|
||||||
return sLinkStatus == LinkStatus_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
|
||||||
|
|
||||||
// We retrieve the path of the XUL library as this is where mozavcodec and
|
|
||||||
// mozavutil libs are located.
|
|
||||||
char* path =
|
|
||||||
PR_GetLibraryFilePathname(XUL_DLL, (PRFuncPtr)&FFVPXRuntimeLinker::Link);
|
|
||||||
if (!path) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
nsCOMPtr<nsIFile> xulFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
|
||||||
if (!xulFile ||
|
|
||||||
NS_FAILED(xulFile->InitWithNativePath(nsDependentCString(path)))) {
|
|
||||||
PR_Free(path);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
PR_Free(path);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIFile> rootDir;
|
|
||||||
if (NS_FAILED(xulFile->GetParent(getter_AddRefs(rootDir))) || !rootDir) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
nsAutoCString rootPath;
|
|
||||||
if (NS_FAILED(rootDir->GetNativePath(rootPath))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* libname = NULL;
|
|
||||||
/* Get the platform-dependent library name of the module */
|
|
||||||
libname = PR_GetLibraryName(rootPath.get(), "mozavutil");
|
|
||||||
if (!libname) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
sLinkedUtilLib = MozAVLink(libname);
|
|
||||||
PR_FreeLibraryName(libname);
|
|
||||||
libname = PR_GetLibraryName(rootPath.get(), "mozavcodec");
|
|
||||||
if (libname) {
|
|
||||||
sLinkedLib = MozAVLink(libname);
|
|
||||||
PR_FreeLibraryName(libname);
|
|
||||||
if (sLinkedLib && sLinkedUtilLib) {
|
|
||||||
if (Bind("mozavcodec")) {
|
|
||||||
sLinkStatus = LinkStatus_SUCCEEDED;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Unlink();
|
|
||||||
|
|
||||||
sLinkStatus = LinkStatus_FAILED;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ bool
|
|
||||||
FFVPXRuntimeLinker::Bind(const char* aLibName)
|
|
||||||
{
|
|
||||||
int version = AV_FUNC_57;
|
|
||||||
|
|
||||||
#define AV_FUNC(func, ver) \
|
|
||||||
if ((ver) & version) { \
|
|
||||||
if (!(func = (decltype(func))PR_FindSymbol(((ver) & AV_FUNC_AVUTIL_MASK) ? sLinkedUtilLib : sLinkedLib, #func))) { \
|
|
||||||
FFMPEG_LOG("Couldn't load function " #func " from %s.", aLibName); \
|
|
||||||
return false; \
|
|
||||||
} \
|
|
||||||
} else { \
|
|
||||||
func = (decltype(func))nullptr; \
|
|
||||||
}
|
|
||||||
#include "FFmpegFunctionList.h"
|
|
||||||
#undef AV_FUNC
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ already_AddRefed<PlatformDecoderModule>
|
|
||||||
FFVPXRuntimeLinker::CreateDecoderModule()
|
|
||||||
{
|
|
||||||
if (!Link()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return FFmpegDecoderModule<FFVPX_VERSION>::Create();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ void
|
|
||||||
FFVPXRuntimeLinker::Unlink()
|
|
||||||
{
|
|
||||||
if (sLinkedUtilLib && sLinkedUtilLib != sLinkedLib) {
|
|
||||||
PR_UnloadLibrary(sLinkedUtilLib);
|
|
||||||
}
|
|
||||||
if (sLinkedLib) {
|
|
||||||
PR_UnloadLibrary(sLinkedLib);
|
|
||||||
sLinkedLib = nullptr;
|
|
||||||
sLinkStatus = LinkStatus_INIT;
|
|
||||||
avcodec_version = nullptr;
|
|
||||||
}
|
|
||||||
sLinkedUtilLib = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef LIBAVCODEC_ALLVERSION
|
|
||||||
} // namespace ffvpx
|
|
||||||
} // namespace mozilla
|
|
@ -1,43 +0,0 @@
|
|||||||
/* -*- 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/. */
|
|
||||||
|
|
||||||
#ifndef __FFVPXRuntimeLinker_h__
|
|
||||||
#define __FFVPXRuntimeLinker_h__
|
|
||||||
|
|
||||||
#include "PlatformDecoderModule.h"
|
|
||||||
|
|
||||||
struct PRLibrary;
|
|
||||||
|
|
||||||
namespace mozilla
|
|
||||||
{
|
|
||||||
namespace ffvpx
|
|
||||||
{
|
|
||||||
|
|
||||||
class FFVPXRuntimeLinker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static bool Link();
|
|
||||||
static void Unlink();
|
|
||||||
static already_AddRefed<PlatformDecoderModule> CreateDecoderModule();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static PRLibrary* sLinkedLib;
|
|
||||||
static PRLibrary* sLinkedUtilLib;
|
|
||||||
static enum LinkStatus {
|
|
||||||
LinkStatus_INIT = 0,
|
|
||||||
LinkStatus_FAILED,
|
|
||||||
LinkStatus_SUCCEEDED
|
|
||||||
} sLinkStatus;
|
|
||||||
|
|
||||||
static bool Bind(const char* aLibName);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __FFVPXRuntimeLinker_h__ */
|
|
@ -1,44 +0,0 @@
|
|||||||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
|
||||||
# vim: set filetype=python:
|
|
||||||
# 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/.
|
|
||||||
|
|
||||||
LOCAL_INCLUDES += ['/xpcom/build']
|
|
||||||
EXPORTS += [
|
|
||||||
'FFVPXRuntimeLinker.h',
|
|
||||||
]
|
|
||||||
|
|
||||||
UNIFIED_SOURCES += [
|
|
||||||
'../FFmpegDataDecoder.cpp',
|
|
||||||
'../FFmpegDecoderModule.cpp',
|
|
||||||
'../FFmpegH264Decoder.cpp',
|
|
||||||
]
|
|
||||||
SOURCES += [
|
|
||||||
'FFVPXRuntimeLinker.cpp',
|
|
||||||
]
|
|
||||||
LOCAL_INCLUDES += [
|
|
||||||
'..',
|
|
||||||
'../ffmpeg57/include',
|
|
||||||
]
|
|
||||||
|
|
||||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
|
||||||
LOCAL_INCLUDES += [
|
|
||||||
'../ffmpeg57/include',
|
|
||||||
]
|
|
||||||
|
|
||||||
if CONFIG['GNU_CXX']:
|
|
||||||
CXXFLAGS += [ '-Wno-deprecated-declarations' ]
|
|
||||||
if CONFIG['CLANG_CXX']:
|
|
||||||
CXXFLAGS += [
|
|
||||||
'-Wno-unknown-attributes',
|
|
||||||
]
|
|
||||||
if CONFIG['_MSC_VER']:
|
|
||||||
CXXFLAGS += [
|
|
||||||
'-wd4996', # deprecated declaration
|
|
||||||
]
|
|
||||||
|
|
||||||
DEFINES['FFVPX_VERSION'] = 46465650
|
|
||||||
DEFINES['USING_MOZFFVPX'] = True
|
|
||||||
|
|
||||||
FINAL_LIBRARY = 'xul'
|
|
@ -39,23 +39,27 @@ if CONFIG['MOZ_EME']:
|
|||||||
DIRS += ['agnostic/eme']
|
DIRS += ['agnostic/eme']
|
||||||
|
|
||||||
if CONFIG['MOZ_FFMPEG']:
|
if CONFIG['MOZ_FFMPEG']:
|
||||||
|
LOCAL_INCLUDES += ['/xpcom/build']
|
||||||
EXPORTS += [
|
EXPORTS += [
|
||||||
'ffmpeg/FFmpegRuntimeLinker.h',
|
'ffmpeg/FFmpegRuntimeLinker.h',
|
||||||
]
|
]
|
||||||
UNIFIED_SOURCES += [
|
UNIFIED_SOURCES += [
|
||||||
'ffmpeg/FFmpegRuntimeLinker.cpp',
|
'ffmpeg/FFmpegRuntimeLinker.cpp',
|
||||||
]
|
]
|
||||||
if CONFIG['MOZ_FFVPX']:
|
|
||||||
DIRS += [
|
|
||||||
'ffmpeg/ffvpx',
|
|
||||||
]
|
|
||||||
if CONFIG['OS_ARCH'] != 'WINNT':
|
if CONFIG['OS_ARCH'] != 'WINNT':
|
||||||
DIRS += [
|
DIRS += [
|
||||||
'ffmpeg/libav53',
|
'ffmpeg/libav53',
|
||||||
'ffmpeg/libav54',
|
'ffmpeg/libav54',
|
||||||
'ffmpeg/libav55',
|
'ffmpeg/libav55',
|
||||||
'ffmpeg/ffmpeg57',
|
|
||||||
]
|
]
|
||||||
|
else:
|
||||||
|
LOCAL_INCLUDES += [
|
||||||
|
'ffmpeg/ffmpeg57/include',
|
||||||
|
]
|
||||||
|
|
||||||
|
DIRS += [
|
||||||
|
'ffmpeg/ffmpeg57',
|
||||||
|
]
|
||||||
|
|
||||||
if CONFIG['MOZ_APPLEMEDIA']:
|
if CONFIG['MOZ_APPLEMEDIA']:
|
||||||
EXPORTS += [
|
EXPORTS += [
|
||||||
|
Loading…
Reference in New Issue
Block a user