summaryrefslogtreecommitdiff
path: root/dxr3audiodecoder.c
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2010-02-02 15:30:50 +0100
committerChristian Gmeiner <christian.gmeiner@gmail.com>2010-02-02 15:30:50 +0100
commit2d99f670594e6d14ffdfd23b3ccadb47101d1f00 (patch)
tree857acb9f88fdd602e00da145880f8c0face782d9 /dxr3audiodecoder.c
parent009b7d2a7e16c0485d655f28a8a3594f2838a02f (diff)
downloadvdr-plugin-dxr3-2d99f670594e6d14ffdfd23b3ccadb47101d1f00.tar.gz
vdr-plugin-dxr3-2d99f670594e6d14ffdfd23b3ccadb47101d1f00.tar.bz2
add method to decode a given frame
The method decode(...) will write the decoded audio frame directly to the card via oss or alsa audio interface.
Diffstat (limited to 'dxr3audiodecoder.c')
-rw-r--r--dxr3audiodecoder.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/dxr3audiodecoder.c b/dxr3audiodecoder.c
index 6ad774e..d80d235 100644
--- a/dxr3audiodecoder.c
+++ b/dxr3audiodecoder.c
@@ -86,6 +86,59 @@ void cDxr3AudioDecoder::Init()
}
}
+void cDxr3AudioDecoder::decode(cDxr3PesFrame *frame, iAudio *audio)
+{
+ int len, out_size;
+
+ const uint8_t *buf = frame->GetPayload();
+ int length = frame->GetPayloadLength();
+
+ if (checkMpegAudioHdr(buf)) {
+
+ // look if Bitrate has changed
+ if ((buf[2] & 0xf0) != (lastBitrate & 0xf0)) {
+ dsyslog("[dxr3-audiodecoder] found new audio header");
+
+ // recalculate used framesize
+ frameSize = calcFrameSize(buf);
+ dsyslog("[dxr3-audiodecoder] calculated frame size %d", frameSize);
+
+ // we need now to reinit the deocder and to store the new
+ // part from the audio header
+ Init();
+ lastBitrate = buf[2];
+ }
+ }
+
+ // setup AVPacket
+ avpkt.data = const_cast<uint8_t *>(buf);
+ avpkt.size = frameSize;
+
+ while (length > 0) {
+ out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(51, 29, 0)
+ len = avcodec_decode_audio(contextAudio, (short *)(&pcmbuf), &out_size, avpkt.data, frameSize);
+#elif LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52, 26, 0)
+ len = avcodec_decode_audio2(contextAudio, (short *)(&pcmbuf), &out_size, avpkt.data, frameSize);
+#else
+ len = avcodec_decode_audio3(contextAudio, (short *)(&pcmbuf), &out_size, &avpkt);
+#endif
+
+ if (len <= 0) {
+ esyslog("[dxr3-decoder] failed to decode audio");
+ return;
+ }
+
+ if (out_size) {
+ audio->write(pcmbuf, out_size);
+ }
+
+ length -= len;
+ avpkt.data += len;
+ }
+}
+
#if 0
// ==================================
//! decode given buffer