diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2010-02-02 15:30:50 +0100 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2010-02-02 15:30:50 +0100 |
commit | 2d99f670594e6d14ffdfd23b3ccadb47101d1f00 (patch) | |
tree | 857acb9f88fdd602e00da145880f8c0face782d9 | |
parent | 009b7d2a7e16c0485d655f28a8a3594f2838a02f (diff) | |
download | vdr-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.
-rw-r--r-- | dxr3audiodecoder.c | 53 | ||||
-rw-r--r-- | dxr3audiodecoder.h | 3 |
2 files changed, 56 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 diff --git a/dxr3audiodecoder.h b/dxr3audiodecoder.h index b4d004b..24f5721 100644 --- a/dxr3audiodecoder.h +++ b/dxr3audiodecoder.h @@ -33,6 +33,7 @@ extern "C" { #include "uncopyable.h" class cDxr3PesFrame; +class iAudio; // ================================== // decode audio to mp2 or use DD :) @@ -40,6 +41,8 @@ class cDxr3AudioDecoder : private Uncopyable { public: cDxr3AudioDecoder(); ~cDxr3AudioDecoder(); + + void decode(cDxr3PesFrame *frame, iAudio *audio); /* void Decode(cDxr3PesFrame *frame, uint32_t pts, cDxr3SyncBuffer &aBuf); void DecodeLpcm(cDxr3PesFrame *frame, uint32_t pts, cDxr3SyncBuffer &aBuf); |