* Use a static global object to initialize libavformat and libavcodec.

* Turn off tracing in the AVCodecDecoder which I accidentally turned on in
  a previous commit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31366 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2009-07-01 21:16:55 +00:00
parent 53db45b7d3
commit 668ed70bd0
4 changed files with 39 additions and 24 deletions

View File

@ -20,7 +20,7 @@
#define DO_PROFILING 0
#undef TRACE
#define TRACE_AV_CODEC
//#define TRACE_AV_CODEC
#ifdef TRACE_AV_CODEC
# define TRACE(x...) printf(x)
#else
@ -64,20 +64,6 @@ AVCodecDecoder::AVCodecDecoder()
{
TRACE("AVCodecDecoder::AVCodecDecoder()\n");
// prevent multiple inits
static volatile vint32 ff_init_count = 0;
static bool ff_init_done = false;
if (atomic_add(&ff_init_count, 1) > 1) {
atomic_add(&ff_init_count, -1);
// spin until the thread that is initing is done
while (!ff_init_done)
snooze(20000);
} else {
avcodec_init();
avcodec_register_all();
ff_init_done = true;
}
ffc = avcodec_alloc_context();
ffpicture = avcodec_alloc_frame();
opicture = avcodec_alloc_frame();

View File

@ -77,7 +77,7 @@ position_io_close(URLContext *h)
}
static URLProtocol position_io_protocol = {
URLProtocol sPositionIOProtocol = {
"position_io",
position_io_open,
position_io_read,
@ -87,14 +87,6 @@ static URLProtocol position_io_protocol = {
};
static int
init_libavformat()
{
av_register_all();
return av_register_protocol(&position_io_protocol);
}
// #pragma mark - AVFormatReader

View File

@ -12,13 +12,41 @@
#include "FFmpegPlugin.h"
#include <stdio.h>
#include <new>
extern "C" {
#include "avformat.h"
}
#include "AVCodecDecoder.h"
#include "AVFormatReader.h"
#include "CodecTable.h"
FFmpegPlugin::GlobalInitilizer::GlobalInitilizer()
{
av_register_all();
// This will also call av_codec_init() by registering codecs.
extern URLProtocol sPositionIOProtocol;
av_register_protocol(&sPositionIOProtocol);
}
FFmpegPlugin::GlobalInitilizer::~GlobalInitilizer()
{
// TODO: uninit anything here?
}
FFmpegPlugin::GlobalInitilizer FFmpegPlugin::sInitilizer;
// #pragma mark -
Decoder*
FFmpegPlugin::NewDecoder(uint index)
{

View File

@ -24,6 +24,15 @@ public:
virtual Decoder* NewDecoder(uint index);
virtual status_t GetSupportedFormats(media_format** formats,
size_t* count);
private:
class GlobalInitilizer {
public:
GlobalInitilizer();
~GlobalInitilizer();
};
static GlobalInitilizer sInitilizer;
};