зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 4ab338518d02 (bug 1240995)
--HG-- extra : rebase_source : d2f8dc3044190a827fb0b747f71a3cbf741767e9
This commit is contained in:
Родитель
5e1ff117ed
Коммит
45991d1b24
|
@ -58,6 +58,7 @@ bool PDMFactory::sAndroidMCDecoderPreferred = false;
|
|||
bool PDMFactory::sGMPDecoderEnabled = false;
|
||||
#ifdef MOZ_FFVPX
|
||||
bool PDMFactory::sFFVPXDecoderEnabled = false;
|
||||
using namespace ffvpx;
|
||||
#endif
|
||||
#ifdef MOZ_FFMPEG
|
||||
bool PDMFactory::sFFmpegDecoderEnabled = false;
|
||||
|
@ -123,10 +124,10 @@ PDMFactory::Init()
|
|||
AppleDecoderModule::Init();
|
||||
#endif
|
||||
#ifdef MOZ_FFVPX
|
||||
FFVPXRuntimeLinker::Init();
|
||||
FFVPXRuntimeLinker::Link();
|
||||
#endif
|
||||
#ifdef MOZ_FFMPEG
|
||||
FFmpegRuntimeLinker::Init();
|
||||
FFmpegRuntimeLinker::Link();
|
||||
#endif
|
||||
GMPDecoderModule::Init();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "mozilla/TaskQueue.h"
|
||||
|
||||
#include "FFmpegRuntimeLinker.h"
|
||||
#include "FFmpegAudioDecoder.h"
|
||||
#include "TimeUnits.h"
|
||||
|
||||
|
@ -14,10 +15,10 @@
|
|||
namespace mozilla
|
||||
{
|
||||
|
||||
FFmpegAudioDecoder<LIBAV_VER>::FFmpegAudioDecoder(FFmpegLibWrapper* aLib,
|
||||
FFmpegAudioDecoder<LIBAV_VER>::FFmpegAudioDecoder(
|
||||
FlushableTaskQueue* aTaskQueue, MediaDataDecoderCallback* aCallback,
|
||||
const AudioInfo& aConfig)
|
||||
: FFmpegDataDecoder(aLib, aTaskQueue, aCallback, GetCodecId(aConfig.mMimeType))
|
||||
: FFmpegDataDecoder(aTaskQueue, aCallback, GetCodecId(aConfig.mMimeType))
|
||||
{
|
||||
MOZ_COUNT_CTOR(FFmpegAudioDecoder);
|
||||
// Use a new MediaByteBuffer as the object will be modified during initialization.
|
||||
|
@ -43,9 +44,11 @@ FFmpegAudioDecoder<LIBAV_VER>::InitCodecContext()
|
|||
// isn't implemented.
|
||||
mCodecContext->thread_count = 1;
|
||||
// FFmpeg takes this as a suggestion for what format to use for audio samples.
|
||||
uint32_t major, minor, micro;
|
||||
FFmpegRuntimeLinker::GetVersion(major, minor, micro);
|
||||
// LibAV 0.8 produces rubbish float interleaved samples, request 16 bits audio.
|
||||
mCodecContext->request_sample_fmt =
|
||||
(mLib->mVersion == 53) ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_FLT;
|
||||
(major == 53) ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_FLT;
|
||||
}
|
||||
|
||||
static UniquePtr<AudioDataValue[]>
|
||||
|
@ -98,7 +101,7 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePacket(MediaRawData* aSample)
|
|||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
AVPacket packet;
|
||||
mLib->av_init_packet(&packet);
|
||||
AV_CALL(av_init_packet(&packet));
|
||||
|
||||
packet.data = const_cast<uint8_t*>(aSample->Data());
|
||||
packet.size = aSample->Size();
|
||||
|
@ -115,7 +118,7 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePacket(MediaRawData* aSample)
|
|||
while (packet.size > 0) {
|
||||
int decoded;
|
||||
int bytesConsumed =
|
||||
mLib->avcodec_decode_audio4(mCodecContext, mFrame, &decoded, &packet);
|
||||
AV_CALL(avcodec_decode_audio4(mCodecContext, mFrame, &decoded, &packet));
|
||||
|
||||
if (bytesConsumed < 0) {
|
||||
NS_WARNING("FFmpeg audio decoder error.");
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef __FFmpegAACDecoder_h__
|
||||
#define __FFmpegAACDecoder_h__
|
||||
|
||||
#include "FFmpegLibWrapper.h"
|
||||
#include "FFmpegDataDecoder.h"
|
||||
|
||||
namespace mozilla
|
||||
|
@ -21,7 +20,7 @@ template <>
|
|||
class FFmpegAudioDecoder<LIBAV_VER> : public FFmpegDataDecoder<LIBAV_VER>
|
||||
{
|
||||
public:
|
||||
FFmpegAudioDecoder(FFmpegLibWrapper* aLib, FlushableTaskQueue* aTaskQueue,
|
||||
FFmpegAudioDecoder(FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
const AudioInfo& aConfig);
|
||||
virtual ~FFmpegAudioDecoder();
|
||||
|
|
|
@ -21,12 +21,10 @@ namespace mozilla
|
|||
bool FFmpegDataDecoder<LIBAV_VER>::sFFmpegInitDone = false;
|
||||
StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
|
||||
|
||||
FFmpegDataDecoder<LIBAV_VER>::FFmpegDataDecoder(FFmpegLibWrapper* aLib,
|
||||
FlushableTaskQueue* aTaskQueue,
|
||||
FFmpegDataDecoder<LIBAV_VER>::FFmpegDataDecoder(FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
AVCodecID aCodecID)
|
||||
: mLib(aLib)
|
||||
, mTaskQueue(aTaskQueue)
|
||||
: mTaskQueue(aTaskQueue)
|
||||
, mCallback(aCallback)
|
||||
, mCodecContext(nullptr)
|
||||
, mFrame(NULL)
|
||||
|
@ -35,7 +33,6 @@ StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
|
|||
, mMonitor("FFMpegaDataDecoder")
|
||||
, mIsFlushing(false)
|
||||
{
|
||||
MOZ_ASSERT(aLib);
|
||||
MOZ_COUNT_CTOR(FFmpegDataDecoder);
|
||||
}
|
||||
|
||||
|
@ -49,7 +46,7 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecoder()
|
|||
{
|
||||
FFMPEG_LOG("Initialising FFmpeg decoder.");
|
||||
|
||||
AVCodec* codec = FindAVCodec(mLib, mCodecID);
|
||||
AVCodec* codec = FindAVCodec(mCodecID);
|
||||
if (!codec) {
|
||||
NS_WARNING("Couldn't find ffmpeg decoder");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -57,7 +54,7 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecoder()
|
|||
|
||||
StaticMutexAutoLock mon(sMonitor);
|
||||
|
||||
if (!(mCodecContext = mLib->avcodec_alloc_context3(codec))) {
|
||||
if (!(mCodecContext = AV_CALL(avcodec_alloc_context3(codec)))) {
|
||||
NS_WARNING("Couldn't init ffmpeg context");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -80,10 +77,10 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecoder()
|
|||
mCodecContext->flags |= CODEC_FLAG_EMU_EDGE;
|
||||
}
|
||||
|
||||
if (mLib->avcodec_open2(mCodecContext, codec, nullptr) < 0) {
|
||||
if (AV_CALL(avcodec_open2(mCodecContext, codec, nullptr)) < 0) {
|
||||
NS_WARNING("Couldn't initialise ffmpeg decoder");
|
||||
mLib->avcodec_close(mCodecContext);
|
||||
mLib->av_freep(&mCodecContext);
|
||||
AV_CALL(avcodec_close(mCodecContext));
|
||||
AV_CALL(av_freep(&mCodecContext));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -144,7 +141,7 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessFlush()
|
|||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
if (mCodecContext) {
|
||||
mLib->avcodec_flush_buffers(mCodecContext);
|
||||
AV_CALL(avcodec_flush_buffers(mCodecContext));
|
||||
}
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
mIsFlushing = false;
|
||||
|
@ -157,12 +154,12 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessShutdown()
|
|||
StaticMutexAutoLock mon(sMonitor);
|
||||
|
||||
if (sFFmpegInitDone && mCodecContext) {
|
||||
mLib->avcodec_close(mCodecContext);
|
||||
mLib->av_freep(&mCodecContext);
|
||||
AV_CALL(avcodec_close(mCodecContext));
|
||||
AV_CALL(av_freep(&mCodecContext));
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
||||
mLib->av_frame_free(&mFrame);
|
||||
AV_CALL(av_frame_free(&mFrame));
|
||||
#elif LIBAVCODEC_VERSION_MAJOR == 54
|
||||
mLib->avcodec_free_frame(&mFrame);
|
||||
AV_CALL(avcodec_free_frame(&mFrame));
|
||||
#else
|
||||
delete mFrame;
|
||||
mFrame = nullptr;
|
||||
|
@ -176,29 +173,36 @@ FFmpegDataDecoder<LIBAV_VER>::PrepareFrame()
|
|||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
||||
if (mFrame) {
|
||||
mLib->av_frame_unref(mFrame);
|
||||
AV_CALL(av_frame_unref(mFrame));
|
||||
} else {
|
||||
mFrame = mLib->av_frame_alloc();
|
||||
mFrame = AV_CALL(av_frame_alloc());
|
||||
}
|
||||
#elif LIBAVCODEC_VERSION_MAJOR == 54
|
||||
if (mFrame) {
|
||||
mLib->avcodec_get_frame_defaults(mFrame);
|
||||
AV_CALL(avcodec_get_frame_defaults(mFrame));
|
||||
} else {
|
||||
mFrame = mLib->avcodec_alloc_frame();
|
||||
mFrame = AV_CALL(avcodec_alloc_frame());
|
||||
}
|
||||
#else
|
||||
delete mFrame;
|
||||
mFrame = new AVFrame;
|
||||
mLib->avcodec_get_frame_defaults(mFrame);
|
||||
AV_CALL(avcodec_get_frame_defaults(mFrame));
|
||||
#endif
|
||||
return mFrame;
|
||||
}
|
||||
|
||||
/* static */ AVCodec*
|
||||
FFmpegDataDecoder<LIBAV_VER>::FindAVCodec(FFmpegLibWrapper* aLib,
|
||||
AVCodecID aCodec)
|
||||
FFmpegDataDecoder<LIBAV_VER>::FindAVCodec(AVCodecID aCodec)
|
||||
{
|
||||
return aLib->avcodec_find_decoder(aCodec);
|
||||
StaticMutexAutoLock mon(sMonitor);
|
||||
if (!sFFmpegInitDone) {
|
||||
AV_CALL(avcodec_register_all());
|
||||
#ifdef DEBUG
|
||||
AV_CALL(av_log_set_level(AV_LOG_DEBUG));
|
||||
#endif
|
||||
sFFmpegInitDone = true;
|
||||
}
|
||||
return AV_CALL(avcodec_find_decoder(aCodec));
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#define __FFmpegDataDecoder_h__
|
||||
|
||||
#include "PlatformDecoderModule.h"
|
||||
#include "FFmpegLibWrapper.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "FFmpegLibs.h"
|
||||
#include "FFmpegRuntimeLinker.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ template <>
|
|||
class FFmpegDataDecoder<LIBAV_VER> : public MediaDataDecoder
|
||||
{
|
||||
public:
|
||||
FFmpegDataDecoder(FFmpegLibWrapper* aLib, FlushableTaskQueue* aTaskQueue,
|
||||
FFmpegDataDecoder(FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
AVCodecID aCodecID);
|
||||
virtual ~FFmpegDataDecoder();
|
||||
|
@ -37,7 +37,7 @@ public:
|
|||
nsresult Drain() override;
|
||||
nsresult Shutdown() override;
|
||||
|
||||
static AVCodec* FindAVCodec(FFmpegLibWrapper* aLib, AVCodecID aCodec);
|
||||
static AVCodec* FindAVCodec(AVCodecID aCodec);
|
||||
|
||||
protected:
|
||||
// Flush and Drain operation, always run
|
||||
|
@ -48,7 +48,6 @@ protected:
|
|||
AVFrame* PrepareFrame();
|
||||
nsresult InitDecoder();
|
||||
|
||||
FFmpegLibWrapper* mLib;
|
||||
RefPtr<FlushableTaskQueue> mTaskQueue;
|
||||
MediaDataDecoderCallback* mCallback;
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#define __FFmpegDecoderModule_h__
|
||||
|
||||
#include "PlatformDecoderModule.h"
|
||||
#include "FFmpegLibWrapper.h"
|
||||
#include "FFmpegAudioDecoder.h"
|
||||
#include "FFmpegVideoDecoder.h"
|
||||
|
||||
|
@ -20,14 +19,14 @@ class FFmpegDecoderModule : public PlatformDecoderModule
|
|||
{
|
||||
public:
|
||||
static already_AddRefed<PlatformDecoderModule>
|
||||
Create(FFmpegLibWrapper* aLib)
|
||||
Create()
|
||||
{
|
||||
RefPtr<PlatformDecoderModule> pdm = new FFmpegDecoderModule(aLib);
|
||||
RefPtr<PlatformDecoderModule> pdm = new FFmpegDecoderModule();
|
||||
|
||||
return pdm.forget();
|
||||
}
|
||||
|
||||
FFmpegDecoderModule(FFmpegLibWrapper* aLib) : mLib(aLib) {}
|
||||
FFmpegDecoderModule() {}
|
||||
virtual ~FFmpegDecoderModule() {}
|
||||
|
||||
already_AddRefed<MediaDataDecoder>
|
||||
|
@ -38,7 +37,7 @@ public:
|
|||
MediaDataDecoderCallback* aCallback) override
|
||||
{
|
||||
RefPtr<MediaDataDecoder> decoder =
|
||||
new FFmpegVideoDecoder<V>(mLib, aVideoTaskQueue, aCallback, aConfig,
|
||||
new FFmpegVideoDecoder<V>(aVideoTaskQueue, aCallback, aConfig,
|
||||
aImageContainer);
|
||||
return decoder.forget();
|
||||
}
|
||||
|
@ -52,7 +51,7 @@ public:
|
|||
return nullptr;
|
||||
#else
|
||||
RefPtr<MediaDataDecoder> decoder =
|
||||
new FFmpegAudioDecoder<V>(mLib, aAudioTaskQueue, aCallback, aConfig);
|
||||
new FFmpegAudioDecoder<V>(aAudioTaskQueue, aCallback, aConfig);
|
||||
return decoder.forget();
|
||||
#endif
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
AVCodecID codec = audioCodec != AV_CODEC_ID_NONE ? audioCodec : videoCodec;
|
||||
return !!FFmpegDataDecoder<V>::FindAVCodec(mLib, codec);
|
||||
return !!FFmpegDataDecoder<V>::FindAVCodec(codec);
|
||||
}
|
||||
|
||||
ConversionRequired
|
||||
|
@ -84,8 +83,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
private:
|
||||
FFmpegLibWrapper* mLib;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* 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/. */
|
||||
|
||||
/* libavcodec */
|
||||
AV_FUNC(avcodec_alloc_context3, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_close, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_decode_audio4, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_decode_video2, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_find_decoder, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_flush_buffers, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_open2, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_register_all, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_init_packet, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_parser_init, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_parser_close, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_parser_parse2, AV_FUNC_AVCODEC_ALL)
|
||||
#if LIBAVCODEC_VERSION_MAJOR <= 54 || defined(LIBAVCODEC_ALLVERSION)
|
||||
AV_FUNC(avcodec_get_frame_defaults, (AV_FUNC_53 | AV_FUNC_54))
|
||||
#endif
|
||||
|
||||
/* libavutil */
|
||||
AV_FUNC(av_log_set_level, AV_FUNC_AVUTIL_ALL)
|
||||
AV_FUNC(av_malloc, AV_FUNC_AVUTIL_ALL)
|
||||
AV_FUNC(av_freep, AV_FUNC_AVUTIL_ALL)
|
||||
|
||||
#if defined(LIBAVCODEC_VERSION_MAJOR) || defined(LIBAVCODEC_ALLVERSION)
|
||||
#if LIBAVCODEC_VERSION_MAJOR == 54 || defined(LIBAVCODEC_ALLVERSION)
|
||||
/* libavutil v54 only */
|
||||
AV_FUNC(avcodec_alloc_frame, AV_FUNC_AVUTIL_54)
|
||||
AV_FUNC(avcodec_free_frame, AV_FUNC_AVUTIL_54)
|
||||
#endif
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 55 || defined(LIBAVCODEC_ALLVERSION)
|
||||
/* libavutil v55 and later only */
|
||||
AV_FUNC(av_frame_alloc, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
|
||||
AV_FUNC(av_frame_free, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
|
||||
AV_FUNC(av_frame_unref, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
|
||||
#endif
|
||||
#endif
|
|
@ -1,142 +0,0 @@
|
|||
/* 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 "FFmpegLibWrapper.h"
|
||||
#include "FFmpegLog.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/Types.h"
|
||||
#include "prlink.h"
|
||||
|
||||
#define AV_LOG_DEBUG 48
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
FFmpegLibWrapper::FFmpegLibWrapper()
|
||||
{
|
||||
PodZero(this);
|
||||
}
|
||||
|
||||
FFmpegLibWrapper::~FFmpegLibWrapper()
|
||||
{
|
||||
Unlink();
|
||||
}
|
||||
|
||||
bool
|
||||
FFmpegLibWrapper::Link()
|
||||
{
|
||||
if (!mAVCodecLib || !mAVUtilLib) {
|
||||
Unlink();
|
||||
return false;
|
||||
}
|
||||
|
||||
avcodec_version =
|
||||
(decltype(avcodec_version))PR_FindSymbol(mAVCodecLib, "avcodec_version");
|
||||
if (!avcodec_version) {
|
||||
Unlink();
|
||||
return false;
|
||||
}
|
||||
uint32_t version = avcodec_version();
|
||||
mVersion = (version >> 16) & 0xff;
|
||||
uint32_t micro = version & 0xff;
|
||||
if (mVersion == 57 && micro != 100) {
|
||||
// a micro version of 100 indicates that it's FFmpeg (as opposed to LibAV).
|
||||
// Due to current AVCodecContext binary incompatibility we can only
|
||||
// support FFmpeg 57 at this stage.
|
||||
Unlink();
|
||||
return false;
|
||||
}
|
||||
|
||||
enum {
|
||||
AV_FUNC_AVUTIL_MASK = 1 << 8,
|
||||
AV_FUNC_53 = 1 << 0,
|
||||
AV_FUNC_54 = 1 << 1,
|
||||
AV_FUNC_55 = 1 << 2,
|
||||
AV_FUNC_56 = 1 << 3,
|
||||
AV_FUNC_57 = 1 << 4,
|
||||
AV_FUNC_AVUTIL_53 = AV_FUNC_53 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_54 = AV_FUNC_54 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_55 = AV_FUNC_55 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_56 = AV_FUNC_56 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_57 = AV_FUNC_57 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVCODEC_ALL = AV_FUNC_53 | AV_FUNC_54 | AV_FUNC_55 | AV_FUNC_56 | AV_FUNC_57,
|
||||
AV_FUNC_AVUTIL_ALL = AV_FUNC_AVCODEC_ALL | AV_FUNC_AVUTIL_MASK
|
||||
};
|
||||
|
||||
switch (mVersion) {
|
||||
case 53:
|
||||
version = AV_FUNC_53;
|
||||
break;
|
||||
case 54:
|
||||
version = AV_FUNC_54;
|
||||
break;
|
||||
case 55:
|
||||
version = AV_FUNC_55;
|
||||
break;
|
||||
case 56:
|
||||
version = AV_FUNC_56;
|
||||
break;
|
||||
case 57:
|
||||
version = AV_FUNC_57;
|
||||
break;
|
||||
default:
|
||||
FFMPEG_LOG("Unknown avcodec version");
|
||||
Unlink();
|
||||
return false;
|
||||
}
|
||||
|
||||
#define AV_FUNC(func, ver) \
|
||||
if ((ver) & version) { \
|
||||
if (!(func = (decltype(func))PR_FindSymbol(((ver) & AV_FUNC_AVUTIL_MASK) ? mAVUtilLib : mAVCodecLib, #func))) { \
|
||||
FFMPEG_LOG("Couldn't load function " # func); \
|
||||
Unlink(); \
|
||||
return false; \
|
||||
} \
|
||||
} else { \
|
||||
func = (decltype(func))nullptr; \
|
||||
}
|
||||
AV_FUNC(avcodec_alloc_context3, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_close, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_decode_audio4, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_decode_video2, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_find_decoder, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_flush_buffers, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_open2, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_register_all, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_init_packet, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_parser_init, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_parser_close, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(av_parser_parse2, AV_FUNC_AVCODEC_ALL)
|
||||
AV_FUNC(avcodec_get_frame_defaults, (AV_FUNC_53 | AV_FUNC_54))
|
||||
AV_FUNC(av_log_set_level, AV_FUNC_AVUTIL_ALL)
|
||||
AV_FUNC(av_malloc, AV_FUNC_AVUTIL_ALL)
|
||||
AV_FUNC(av_freep, AV_FUNC_AVUTIL_ALL)
|
||||
AV_FUNC(avcodec_alloc_frame, AV_FUNC_AVUTIL_54)
|
||||
AV_FUNC(avcodec_free_frame, AV_FUNC_AVUTIL_54)
|
||||
AV_FUNC(av_frame_alloc, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
|
||||
AV_FUNC(av_frame_free, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
|
||||
AV_FUNC(av_frame_unref, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
|
||||
#undef AV_FUNC
|
||||
|
||||
avcodec_register_all();
|
||||
#ifdef DEBUG
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FFmpegLibWrapper::Unlink()
|
||||
{
|
||||
if (mAVUtilLib && mAVUtilLib != mAVCodecLib) {
|
||||
PR_UnloadLibrary(mAVUtilLib);
|
||||
}
|
||||
if (mAVCodecLib) {
|
||||
PR_UnloadLibrary(mAVCodecLib);
|
||||
}
|
||||
PodZero(this);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -1,78 +0,0 @@
|
|||
/* 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 __FFmpegLibWrapper_h__
|
||||
#define __FFmpegLibWrapper_h__
|
||||
|
||||
#include "mozilla/Types.h"
|
||||
|
||||
struct AVCodec;
|
||||
struct AVCodecContext;
|
||||
struct AVFrame;
|
||||
struct AVPacket;
|
||||
struct AVDictionary;
|
||||
struct AVCodecParserContext;
|
||||
struct PRLibrary;
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
struct FFmpegLibWrapper
|
||||
{
|
||||
FFmpegLibWrapper();
|
||||
~FFmpegLibWrapper();
|
||||
|
||||
// Attempt to resolve all symbols. Return true of successful.
|
||||
// Upon failure, the entire object will be reset and any attached libraries
|
||||
// will be unlinked.
|
||||
bool Link();
|
||||
|
||||
// Reset the wrapper and unlink all attached libraries.
|
||||
void Unlink();
|
||||
|
||||
// indicate the version of libavcodec linked to.
|
||||
// 0 indicates that the function wasn't initialized with Link().
|
||||
int mVersion;
|
||||
|
||||
// libavcodec
|
||||
unsigned (*avcodec_version)();
|
||||
AVCodecContext* (*avcodec_alloc_context3)(const AVCodec* codec);
|
||||
int (*avcodec_close)(AVCodecContext* avctx);
|
||||
int (*avcodec_decode_audio4)(AVCodecContext* avctx, AVFrame* frame, int* got_frame_ptr, const AVPacket* avpkt);
|
||||
int (*avcodec_decode_video2)(AVCodecContext* avctx, AVFrame* picture, int* got_picture_ptr, const AVPacket* avpkt);
|
||||
AVCodec* (*avcodec_find_decoder)(int id);
|
||||
void (*avcodec_flush_buffers)(AVCodecContext *avctx);
|
||||
int (*avcodec_open2)(AVCodecContext *avctx, const AVCodec* codec, AVDictionary** options);
|
||||
void (*avcodec_register_all)();
|
||||
void (*av_init_packet)(AVPacket* pkt);
|
||||
AVCodecParserContext* (*av_parser_init)(int codec_id);
|
||||
void (*av_parser_close)(AVCodecParserContext* s);
|
||||
int (*av_parser_parse2)(AVCodecParserContext* s, AVCodecContext* avctx, uint8_t** poutbuf, int* poutbuf_size, const uint8_t* buf, int buf_size, int64_t pts, int64_t dts, int64_t pos);
|
||||
|
||||
// only used in libavcodec <= 54
|
||||
void (*avcodec_get_frame_defaults)(AVFrame* pic);
|
||||
|
||||
// libavutil
|
||||
void (*av_log_set_level)(int level);
|
||||
void* (*av_malloc)(size_t size);
|
||||
void (*av_freep)(void *ptr);
|
||||
|
||||
// libavutil v54 only
|
||||
AVFrame* (*avcodec_alloc_frame)();
|
||||
void (*avcodec_free_frame)(AVFrame** frame);
|
||||
|
||||
// libavutil v55 and later only
|
||||
AVFrame* (*av_frame_alloc)();
|
||||
void (*av_frame_free)(AVFrame** frame);
|
||||
void (*av_frame_unref)(AVFrame* frame);
|
||||
|
||||
PRLibrary* mAVCodecLib;
|
||||
PRLibrary* mAVUtilLib;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // FFmpegLibWrapper
|
|
@ -7,6 +7,8 @@
|
|||
#ifndef __FFmpegLibs_h__
|
||||
#define __FFmpegLibs_h__
|
||||
|
||||
#include "mozilla/Types.h"
|
||||
|
||||
extern "C" {
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC visibility push(default)
|
||||
|
@ -35,4 +37,23 @@ enum { LIBAV_VER = FFVPX_VERSION };
|
|||
enum { LIBAV_VER = LIBAVCODEC_VERSION_MAJOR };
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
#ifdef USING_MOZFFVPX
|
||||
namespace ffvpx {
|
||||
#endif
|
||||
|
||||
#define AV_FUNC(func, ver) extern decltype(func)* func;
|
||||
#include "FFmpegFunctionList.h"
|
||||
#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__
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
#ifndef __FFmpegLog_h__
|
||||
#define __FFmpegLog_h__
|
||||
|
||||
#include "mozilla/Logging.h"
|
||||
|
||||
extern mozilla::LogModule* GetPDMLog();
|
||||
#define FFMPEG_LOG(...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "FFmpegRuntimeLinker.h"
|
||||
#include "FFmpegLibWrapper.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "FFmpegLog.h"
|
||||
#include "mozilla/Types.h"
|
||||
#include "prlink.h"
|
||||
|
||||
namespace mozilla
|
||||
|
@ -19,11 +19,9 @@ FFmpegRuntimeLinker::LinkStatus FFmpegRuntimeLinker::sLinkStatus =
|
|||
template <int V> class FFmpegDecoderModule
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<PlatformDecoderModule> Create(FFmpegLibWrapper*);
|
||||
static already_AddRefed<PlatformDecoderModule> Create();
|
||||
};
|
||||
|
||||
static FFmpegLibWrapper sLibAV;
|
||||
|
||||
static const char* sLibs[] = {
|
||||
#if defined(XP_DARWIN)
|
||||
"libavcodec.57.dylib",
|
||||
|
@ -42,8 +40,30 @@ static const char* sLibs[] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
PRLibrary* FFmpegRuntimeLinker::sLinkedLib = nullptr;
|
||||
PRLibrary* FFmpegRuntimeLinker::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
|
||||
FFmpegRuntimeLinker::Init()
|
||||
FFmpegRuntimeLinker::Link()
|
||||
{
|
||||
if (sLinkStatus) {
|
||||
return sLinkStatus == LinkStatus_SUCCEEDED;
|
||||
|
@ -52,16 +72,15 @@ FFmpegRuntimeLinker::Init()
|
|||
|
||||
for (size_t i = 0; i < ArrayLength(sLibs); i++) {
|
||||
const char* lib = sLibs[i];
|
||||
PRLibSpec lspec;
|
||||
lspec.type = PR_LibSpec_Pathname;
|
||||
lspec.value.pathname = lib;
|
||||
sLibAV.mAVCodecLib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
|
||||
if (sLibAV.mAVCodecLib) {
|
||||
sLibAV.mAVUtilLib = sLibAV.mAVCodecLib;
|
||||
if (sLibAV.Link()) {
|
||||
sLinkedLib = MozAVLink(lib);
|
||||
if (sLinkedLib) {
|
||||
sLinkedUtilLib = sLinkedLib;
|
||||
if (Bind(lib)) {
|
||||
sLinkStatus = LinkStatus_SUCCEEDED;
|
||||
return true;
|
||||
}
|
||||
// Shouldn't happen but if it does then we try the next lib..
|
||||
Unlink();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,26 +90,113 @@ FFmpegRuntimeLinker::Init()
|
|||
}
|
||||
FFMPEG_LOG(" ]\n");
|
||||
|
||||
Unlink();
|
||||
|
||||
sLinkStatus = LinkStatus_FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
FFmpegRuntimeLinker::Bind(const char* aLibName)
|
||||
{
|
||||
avcodec_version = (decltype(avcodec_version))PR_FindSymbol(sLinkedLib,
|
||||
"avcodec_version");
|
||||
uint32_t major, minor, micro;
|
||||
if (!GetVersion(major, minor, micro)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int version;
|
||||
switch (major) {
|
||||
case 53:
|
||||
version = AV_FUNC_53;
|
||||
break;
|
||||
case 54:
|
||||
version = AV_FUNC_54;
|
||||
break;
|
||||
case 56:
|
||||
// We use libavcodec 55 code instead. Fallback
|
||||
case 55:
|
||||
version = AV_FUNC_55;
|
||||
break;
|
||||
case 57:
|
||||
if (micro != 100) {
|
||||
// a micro version of 100 indicates that it's FFmpeg (as opposed to LibAV.
|
||||
// Due to current AVCodecContext binary incompatibility we can only
|
||||
// support FFmpeg at this stage.
|
||||
return false;
|
||||
}
|
||||
version = AV_FUNC_57;
|
||||
break;
|
||||
default:
|
||||
// Not supported at this stage.
|
||||
return false;
|
||||
}
|
||||
|
||||
#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>
|
||||
FFmpegRuntimeLinker::CreateDecoderModule()
|
||||
{
|
||||
if (!Init()) {
|
||||
if (!Link()) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t major, minor, micro;
|
||||
if (!GetVersion(major, minor, micro)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<PlatformDecoderModule> module;
|
||||
switch (sLibAV.mVersion) {
|
||||
case 53: module = FFmpegDecoderModule<53>::Create(&sLibAV); break;
|
||||
case 54: module = FFmpegDecoderModule<54>::Create(&sLibAV); break;
|
||||
switch (major) {
|
||||
case 53: module = FFmpegDecoderModule<53>::Create(); break;
|
||||
case 54: module = FFmpegDecoderModule<54>::Create(); break;
|
||||
case 55:
|
||||
case 56: module = FFmpegDecoderModule<55>::Create(&sLibAV); break;
|
||||
case 57: module = FFmpegDecoderModule<57>::Create(&sLibAV); break;
|
||||
case 56: module = FFmpegDecoderModule<55>::Create(); break;
|
||||
case 57: module = FFmpegDecoderModule<57>::Create(); break;
|
||||
default: module = nullptr;
|
||||
}
|
||||
return module.forget();
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
FFmpegRuntimeLinker::Unlink()
|
||||
{
|
||||
if (sLinkedUtilLib && sLinkedUtilLib != sLinkedLib) {
|
||||
PR_UnloadLibrary(sLinkedUtilLib);
|
||||
}
|
||||
if (sLinkedLib) {
|
||||
PR_UnloadLibrary(sLinkedLib);
|
||||
sLinkedLib = nullptr;
|
||||
sLinkStatus = LinkStatus_INIT;
|
||||
avcodec_version = nullptr;
|
||||
}
|
||||
sLinkedUtilLib = nullptr;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
FFmpegRuntimeLinker::GetVersion(uint32_t& aMajor, uint32_t& aMinor, uint32_t& aMicro)
|
||||
{
|
||||
if (!avcodec_version) {
|
||||
return false;
|
||||
}
|
||||
uint32_t version = avcodec_version();
|
||||
aMajor = (version >> 16) & 0xff;
|
||||
aMinor = (version >> 8) & 0xff;
|
||||
aMicro = version & 0xff;
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef LIBAVCODEC_ALLVERSION
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -8,17 +8,43 @@
|
|||
#define __FFmpegRuntimeLinker_h__
|
||||
|
||||
#include "PlatformDecoderModule.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct PRLibrary;
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
enum {
|
||||
AV_FUNC_AVUTIL_MASK = 1 << 8,
|
||||
AV_FUNC_53 = 1 << 0,
|
||||
AV_FUNC_54 = 1 << 1,
|
||||
AV_FUNC_55 = 1 << 2,
|
||||
AV_FUNC_56 = 1 << 3,
|
||||
AV_FUNC_57 = 1 << 4,
|
||||
AV_FUNC_AVUTIL_53 = AV_FUNC_53 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_54 = AV_FUNC_54 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_55 = AV_FUNC_55 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_56 = AV_FUNC_56 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVUTIL_57 = AV_FUNC_57 | AV_FUNC_AVUTIL_MASK,
|
||||
AV_FUNC_AVCODEC_ALL = AV_FUNC_53 | AV_FUNC_54 | AV_FUNC_55 | AV_FUNC_56 | AV_FUNC_57,
|
||||
AV_FUNC_AVUTIL_ALL = AV_FUNC_AVCODEC_ALL | AV_FUNC_AVUTIL_MASK
|
||||
};
|
||||
|
||||
class FFmpegRuntimeLinker
|
||||
{
|
||||
public:
|
||||
static bool Init();
|
||||
static bool Link();
|
||||
static void Unlink();
|
||||
static already_AddRefed<PlatformDecoderModule> CreateDecoderModule();
|
||||
static bool GetVersion(uint32_t& aMajor, uint32_t& aMinor, uint32_t& aMicro);
|
||||
|
||||
private:
|
||||
static PRLibrary* sLinkedLib;
|
||||
static PRLibrary* sLinkedUtilLib;
|
||||
|
||||
static bool Bind(const char* aLibName);
|
||||
|
||||
static enum LinkStatus {
|
||||
LinkStatus_INIT = 0,
|
||||
LinkStatus_FAILED,
|
||||
|
|
|
@ -98,11 +98,11 @@ FFmpegVideoDecoder<LIBAV_VER>::PtsCorrectionContext::Reset()
|
|||
mLastDts = INT64_MIN;
|
||||
}
|
||||
|
||||
FFmpegVideoDecoder<LIBAV_VER>::FFmpegVideoDecoder(FFmpegLibWrapper* aLib,
|
||||
FFmpegVideoDecoder<LIBAV_VER>::FFmpegVideoDecoder(
|
||||
FlushableTaskQueue* aTaskQueue, MediaDataDecoderCallback* aCallback,
|
||||
const VideoInfo& aConfig,
|
||||
ImageContainer* aImageContainer)
|
||||
: FFmpegDataDecoder(aLib, aTaskQueue, aCallback, GetCodecId(aConfig.mMimeType))
|
||||
: FFmpegDataDecoder(aTaskQueue, aCallback, GetCodecId(aConfig.mMimeType))
|
||||
, mImageContainer(aImageContainer)
|
||||
, mDisplay(aConfig.mDisplay)
|
||||
, mImage(aConfig.mImage)
|
||||
|
@ -151,7 +151,7 @@ FFmpegVideoDecoder<LIBAV_VER>::InitCodecContext()
|
|||
// FFmpeg will call back to this to negotiate a video pixel format.
|
||||
mCodecContext->get_format = ChoosePixelFormat;
|
||||
|
||||
mCodecParser = mLib->av_parser_init(mCodecID);
|
||||
mCodecParser = AV_CALL(av_parser_init(mCodecID));
|
||||
if (mCodecParser) {
|
||||
mCodecParser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
|
||||
}
|
||||
|
@ -175,10 +175,10 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample)
|
|||
while (inputSize) {
|
||||
uint8_t* data;
|
||||
int size;
|
||||
int len = mLib->av_parser_parse2(mCodecParser, mCodecContext, &data, &size,
|
||||
int len = AV_CALL(av_parser_parse2(mCodecParser, mCodecContext, &data, &size,
|
||||
inputData, inputSize,
|
||||
aSample->mTime, aSample->mTimecode,
|
||||
aSample->mOffset);
|
||||
aSample->mOffset));
|
||||
if (size_t(len) > inputSize) {
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
|
@ -210,7 +210,7 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample,
|
|||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
|
||||
AVPacket packet;
|
||||
mLib->av_init_packet(&packet);
|
||||
AV_CALL(av_init_packet(&packet));
|
||||
|
||||
packet.data = aData;
|
||||
packet.size = aSize;
|
||||
|
@ -237,7 +237,7 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample,
|
|||
|
||||
int decoded;
|
||||
int bytesConsumed =
|
||||
mLib->avcodec_decode_video2(mCodecContext, mFrame, &decoded, &packet);
|
||||
AV_CALL(avcodec_decode_video2(mCodecContext, mFrame, &decoded, &packet));
|
||||
|
||||
FFMPEG_LOG("DoDecodeFrame:decode_video: rv=%d decoded=%d "
|
||||
"(Input: pts(%lld) dts(%lld) Output: pts(%lld) "
|
||||
|
@ -361,7 +361,7 @@ FFmpegVideoDecoder<LIBAV_VER>::~FFmpegVideoDecoder()
|
|||
{
|
||||
MOZ_COUNT_DTOR(FFmpegVideoDecoder);
|
||||
if (mCodecParser) {
|
||||
mLib->av_parser_close(mCodecParser);
|
||||
AV_CALL(av_parser_close(mCodecParser));
|
||||
mCodecParser = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef __FFmpegVideoDecoder_h__
|
||||
#define __FFmpegVideoDecoder_h__
|
||||
|
||||
#include "FFmpegLibWrapper.h"
|
||||
#include "FFmpegDataDecoder.h"
|
||||
#include "mozilla/Pair.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -33,7 +32,7 @@ class FFmpegVideoDecoder<LIBAV_VER> : public FFmpegDataDecoder<LIBAV_VER>
|
|||
};
|
||||
|
||||
public:
|
||||
FFmpegVideoDecoder(FFmpegLibWrapper* aLib, FlushableTaskQueue* aTaskQueue,
|
||||
FFmpegVideoDecoder(FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
const VideoInfo& aConfig,
|
||||
ImageContainer* aImageContainer);
|
||||
|
|
|
@ -5,27 +5,47 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "FFVPXRuntimeLinker.h"
|
||||
#include "FFmpegLibWrapper.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(FFmpegLibWrapper*);
|
||||
static already_AddRefed<PlatformDecoderModule> Create();
|
||||
};
|
||||
|
||||
static FFmpegLibWrapper sFFVPXLib;
|
||||
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)
|
||||
{
|
||||
|
@ -36,7 +56,7 @@ MozAVLink(const char* aName)
|
|||
}
|
||||
|
||||
/* static */ bool
|
||||
FFVPXRuntimeLinker::Init()
|
||||
FFVPXRuntimeLinker::Link()
|
||||
{
|
||||
if (sLinkStatus) {
|
||||
return sLinkStatus == LinkStatus_SUCCEEDED;
|
||||
|
@ -47,7 +67,7 @@ FFVPXRuntimeLinker::Init()
|
|||
// 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::Init);
|
||||
PR_GetLibraryFilePathname(XUL_DLL, (PRFuncPtr)&FFVPXRuntimeLinker::Link);
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
@ -74,29 +94,69 @@ FFVPXRuntimeLinker::Init()
|
|||
if (!libname) {
|
||||
return false;
|
||||
}
|
||||
sFFVPXLib.mAVUtilLib = MozAVLink(libname);
|
||||
sLinkedUtilLib = MozAVLink(libname);
|
||||
PR_FreeLibraryName(libname);
|
||||
libname = PR_GetLibraryName(rootPath.get(), "mozavcodec");
|
||||
if (libname) {
|
||||
sFFVPXLib.mAVCodecLib = MozAVLink(libname);
|
||||
sLinkedLib = MozAVLink(libname);
|
||||
PR_FreeLibraryName(libname);
|
||||
}
|
||||
if (sFFVPXLib.Link()) {
|
||||
if (sLinkedLib && sLinkedUtilLib) {
|
||||
if (Bind("mozavcodec")) {
|
||||
sLinkStatus = LinkStatus_SUCCEEDED;
|
||||
return true;
|
||||
}
|
||||
sLinkStatus = LinkStatus_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
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 (!Init()) {
|
||||
if (!Link()) {
|
||||
return nullptr;
|
||||
}
|
||||
return FFmpegDecoderModule<FFVPX_VERSION>::Create(&sFFVPXLib);
|
||||
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
|
||||
|
|
|
@ -9,23 +9,35 @@
|
|||
|
||||
#include "PlatformDecoderModule.h"
|
||||
|
||||
struct PRLibrary;
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
namespace ffvpx
|
||||
{
|
||||
|
||||
class FFVPXRuntimeLinker
|
||||
{
|
||||
public:
|
||||
static bool Init();
|
||||
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,22 +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/.
|
||||
|
||||
EXPORTS += [
|
||||
'FFmpegRuntimeLinker.h',
|
||||
]
|
||||
|
||||
DIRS += [
|
||||
'libav53',
|
||||
'libav54',
|
||||
'libav55',
|
||||
'ffmpeg57',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'FFmpegRuntimeLinker.cpp',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
|
@ -38,20 +38,23 @@ if CONFIG['MOZ_WMF']:
|
|||
if CONFIG['MOZ_EME']:
|
||||
DIRS += ['agnostic/eme']
|
||||
|
||||
if CONFIG['MOZ_FFVPX'] or CONFIG['MOZ_FFMPEG']:
|
||||
# common code to either FFmpeg or FFVPX
|
||||
UNIFIED_SOURCES += [
|
||||
'ffmpeg/FFmpegLibWrapper.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_FFVPX']:
|
||||
DIRS += [
|
||||
'ffmpeg/ffvpx',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_FFMPEG']:
|
||||
EXPORTS += [
|
||||
'ffmpeg/FFmpegRuntimeLinker.h',
|
||||
]
|
||||
UNIFIED_SOURCES += [
|
||||
'ffmpeg/FFmpegRuntimeLinker.cpp',
|
||||
]
|
||||
DIRS += [
|
||||
'ffmpeg',
|
||||
'ffmpeg/libav53',
|
||||
'ffmpeg/libav54',
|
||||
'ffmpeg/libav55',
|
||||
'ffmpeg/ffmpeg57',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_APPLEMEDIA']:
|
||||
|
|
|
@ -97,6 +97,10 @@
|
|||
#include "AndroidMediaPluginHost.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_FFMPEG
|
||||
#include "FFmpegRuntimeLinker.h"
|
||||
#endif
|
||||
|
||||
#include "CubebUtils.h"
|
||||
#include "Latency.h"
|
||||
#include "WebAudioUtils.h"
|
||||
|
@ -390,6 +394,10 @@ nsLayoutStatics::Shutdown()
|
|||
AndroidMediaPluginHost::Shutdown();
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_FFMPEG
|
||||
FFmpegRuntimeLinker::Unlink();
|
||||
#endif
|
||||
|
||||
CubebUtils::ShutdownLibrary();
|
||||
AsyncLatencyLogger::ShutdownLogger();
|
||||
WebAudioUtils::Shutdown();
|
||||
|
|
Загрузка…
Ссылка в новой задаче