summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY1
-rw-r--r--Makefile2
-rw-r--r--dxr3audiodecoder.c52
-rw-r--r--dxr3audiodecoder.h8
-rw-r--r--dxr3ffmpeg.c93
-rw-r--r--dxr3ffmpeg.h72
6 files changed, 45 insertions, 183 deletions
diff --git a/HISTORY b/HISTORY
index fa4622a..65302e5 100644
--- a/HISTORY
+++ b/HISTORY
@@ -358,3 +358,4 @@ NOTE: I havent found time to include all of the languages, will be done in pre2
- Add French translation (#55, Michaël Nival)
- Better defaults for FFmpeg and EM8300 in Makefile (#53, Ville Skyttä,
Michaël Nival).
+- Code cleanups (Christian Gmeiner)
diff --git a/Makefile b/Makefile
index 9a19a21..cccbccf 100644
--- a/Makefile
+++ b/Makefile
@@ -72,7 +72,7 @@ DEFINES += -DUSE_XINE_SCALER
OBJS = $(PLUGIN).o dxr3multichannelaudio.o dxr3sysclock.o dxr3colormanager.o \
dxr3syncbuffer.o dxr3audiodecoder.o dxr3blackframe.o dxr3audio.o \
- dxr3pesframe.o dxr3demuxdevice.o dxr3configdata.o dxr3ffmpeg.o \
+ dxr3pesframe.o dxr3demuxdevice.o dxr3configdata.o \
dxr3interface_spu_encoder.o dxr3interface.o dxr3device.o \
dxr3output.o dxr3output-video.o dxr3output-audio.o dxr3osd.o dxr3spudecoder.o \
dxr3audio-oss.o dxr3audio-alsa.o
diff --git a/dxr3audiodecoder.c b/dxr3audiodecoder.c
index 03d113b..10b62a3 100644
--- a/dxr3audiodecoder.c
+++ b/dxr3audiodecoder.c
@@ -38,15 +38,29 @@ const int LPCM_HEADER_LENGTH = 7;
//! constructor
cDxr3AudioDecoder::cDxr3AudioDecoder() : rbuf(50000), ac3dtsDecoder(&rbuf)
{
+ // setup ffmpeg
+ avcodec_init();
+ avcodec_register_all();
+
audioSynched = false;
- Codec.id = CODEC_ID_MP2;
- // check if codec is available
- if (!cDxr3Ffmpeg::Instance().FindCodec(Codec)) {
+ // look for decoder
+ audio = avcodec_find_decoder(CODEC_ID_MP3);
+
+ if (!audio) {
+ esyslog("[dxr3-decoder] no suitable audio codec found.");
+ esyslog("[dxr3-decoder] check your ffmpeg installation.");
exit(-1);
}
- Init();
+ // create a new codec context
+ contextAudio = avcodec_alloc_context();
+ int ret = avcodec_open(contextAudio, audio);
+
+ if (ret < 0) {
+ esyslog("[dxr3-decoder] failed to open codec %s.", audio->name);
+ exit(-1);
+ }
lastHeader[0] = 0xFF;
lastHeader[1] = lastHeader[2] = lastHeader[3] = 0;
@@ -57,16 +71,24 @@ cDxr3AudioDecoder::cDxr3AudioDecoder() : rbuf(50000), ac3dtsDecoder(&rbuf)
cDxr3AudioDecoder::~cDxr3AudioDecoder()
{
// close codec, if it is open
- cDxr3Ffmpeg::Instance().CloseCodec(Codec);
+ avcodec_close(contextAudio);
}
// ==================================
//! (re)init ffmpeg codec
void cDxr3AudioDecoder::Init()
{
- // (re)init codec
- cDxr3Ffmpeg::Instance().CloseCodec(Codec);
- cDxr3Ffmpeg::Instance().OpenCodec(Codec);
+ avcodec_close(contextAudio);
+
+ // create a new codec context
+ contextAudio = avcodec_alloc_context();
+ int ret = avcodec_open(contextAudio, audio);
+
+ if (ret < 0) {
+ esyslog("[dxr3-decoder] failed to open codec %s.", audio->name);
+ exit(-1);
+ }
+
rate = channels = -1;
foundHeader = false;
decodeAudio = true;
@@ -134,25 +156,25 @@ void cDxr3AudioDecoder::Decode(const uint8_t* buf, int length, uint32_t pts,
#else
len = avcodec_decode_audio2(
#endif
- &Codec.codec_context, (short *)(&pcmbuf), &out_size,
+ contextAudio, (short *)(&pcmbuf), &out_size,
const_cast<uint8_t *>(buf), length);
if (len < 0 || out_size < 0)
throw WRONG_LENGTH;
- if (Codec.codec_context.sample_rate != rate)
+ if (contextAudio->sample_rate != rate)
{
dsyslog("dxr3: audiodecoder: sample rate=%d",
- Codec.codec_context.sample_rate);
+ contextAudio->sample_rate);
if (rate != -1) throw UNEXPECTED_PARAMETER_CHANGE;
- rate = Codec.codec_context.sample_rate;
+ rate = contextAudio->sample_rate;
}
- if (Codec.codec_context.channels != channels)
+ if (contextAudio->channels != channels)
{
dsyslog("dxr3: audiodecoder: channels=%d",
- Codec.codec_context.channels);
+ contextAudio->channels);
if (channels != -1)
throw UNEXPECTED_PARAMETER_CHANGE;
- channels = Codec.codec_context.channels;
+ channels = contextAudio->channels;
}
if (out_size)
{
diff --git a/dxr3audiodecoder.h b/dxr3audiodecoder.h
index f2063b9..81b9bc4 100644
--- a/dxr3audiodecoder.h
+++ b/dxr3audiodecoder.h
@@ -26,7 +26,10 @@
#include <stdlib.h>
#include <stdint.h>
-#include "dxr3ffmpeg.h"
+extern "C" {
+# include <libavcodec/avcodec.h>
+}
+
#include "dxr3syncbuffer.h"
#include "dxr3multichannelaudio.h"
#include "Uncopyable.h"
@@ -59,7 +62,8 @@ public:
private:
bool HeadCheck(unsigned long head);
- struct Dxr3Codec Codec;
+ AVCodec *audio;
+ AVCodecContext *contextAudio;
cRingBufferFrame rbuf;
cMultichannelAudio ac3dtsDecoder;
diff --git a/dxr3ffmpeg.c b/dxr3ffmpeg.c
deleted file mode 100644
index 7940000..0000000
--- a/dxr3ffmpeg.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * dxr3ffmpeg.c
- *
- * Copyright (C) 2004 Christian Gmeiner
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include "dxr3ffmpeg.h"
-#include "dxr3configdata.h"
-#include <vdr/tools.h>
-
-// ==================================
-//! constructor
-cDxr3Ffmpeg::cDxr3Ffmpeg()
-{
- avcodec_init();
- // Only the MP2 decoder would be needed, but individual registration of
- // codecs bundled with ffmpeg itself does not appear to be really supported
- // as of ffmpeg 2007-07-xx and later.
- avcodec_register_all();
-}
-
-// ==================================
-//! look if Codec is supported by ffmpeg
-bool cDxr3Ffmpeg::FindCodec(struct Dxr3Codec& Codec)
-{
- // find codec
- Codec.codec = avcodec_find_decoder(Codec.id);
-
- if (!Codec.codec)
- {
- esyslog("dxr3: ffmpeg: codec %#.5x not found - not supported"
- " by FFmpeg?", Codec.id);
- return false;
- }
-
- // init codec_context
- memset(&Codec.codec_context, 0, sizeof(Codec.codec_context));
-
- return true;
-}
-
-// ==================================
-//! try to open Codec
-bool cDxr3Ffmpeg::OpenCodec(struct Dxr3Codec& Codec)
-{
- // try to open codec
- int result = avcodec_open(&Codec.codec_context, Codec.codec);
-
- if (result < 0)
- {
- esyslog("dxr3: ffmpeg: couldn't open codec %#.5x", Codec.id);
- return false;
- }
- else
- {
- Codec.Open = true;
- }
-
- return true;
-}
-
-// ==================================
-//! close codec
-void cDxr3Ffmpeg::CloseCodec(struct Dxr3Codec& Codec)
-{
- if (Codec.Open)
- {
- avcodec_close(&Codec.codec_context);
- Codec.Open = false;
- }
-}
-
-// Local variables:
-// mode: c++
-// c-file-style: "stroustrup"
-// c-file-offsets: ((inline-open . 0))
-// indent-tabs-mode: t
-// End:
diff --git a/dxr3ffmpeg.h b/dxr3ffmpeg.h
deleted file mode 100644
index 8772144..0000000
--- a/dxr3ffmpeg.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * dxr3ffmpeg.h
- *
- * Copyright (C) 2004 Christian Gmeiner
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifndef _DXR3_FFMPEG_H_
-#define _DXR3_FFMPEG_H_
-
-extern "C"
-{
-#include <libavcodec/avcodec.h>
-}
-
-#include <string.h>
-#include "dxr3singleton.h"
-#include "Uncopyable.h"
-
-// ==================================
-//! a codec used by this plugin
-struct Dxr3Codec
-{
- Dxr3Codec() : Open(false) {}
-
- AVCodec* codec; ///< ffmpeg's AVCodec
- AVCodecContext codec_context; ///< ffmpeg's AVCodecContext
- enum CodecID id; ///< id's from ffmpeg, eg. CODEC_ID_MP2
- bool Open; ///< is codec open?
-};
-
-// ==================================
-// class to work with ffmpeg
-/*!
- With cDxr3Ffmpeg you can easily handle as many
- codecs as you want.
- At the moment we need this only for
- the audiodecoder, but in future i want to use
- it for ohter nice stuff :)
-*/
-class cDxr3Ffmpeg : public Singleton<cDxr3Ffmpeg>, private Uncopyable {
-public:
- cDxr3Ffmpeg();
- ~cDxr3Ffmpeg() {}
-
- bool FindCodec(struct Dxr3Codec& Codec);
- bool OpenCodec(struct Dxr3Codec& Codec);
- void CloseCodec(struct Dxr3Codec& Codec);
-};
-
-#endif /*_DXR3_FFMPEG_H_*/
-
-// Local variables:
-// mode: c++
-// c-file-style: "stroustrup"
-// c-file-offsets: ((inline-open . 0))
-// indent-tabs-mode: t
-// End: