From 41f0211ca48e2c5a5af1fe41f9af644012fe91c4 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Sat, 5 Dec 2009 21:38:47 +0100 Subject: fix audio problems with vdr 1.7.10 --- dxr3audiodecoder.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'dxr3audiodecoder.c') diff --git a/dxr3audiodecoder.c b/dxr3audiodecoder.c index 8eeb68a..f3dd0ca 100644 --- a/dxr3audiodecoder.c +++ b/dxr3audiodecoder.c @@ -90,8 +90,7 @@ void cDxr3AudioDecoder::Init() //! decode given buffer void cDxr3AudioDecoder::Decode(cDxr3PesFrame *frame, uint32_t pts, cDxr3SyncBuffer &aBuf) { - int len; - int out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; + int len, out_size; const uint8_t *buf = frame->GetPayload(); int length = frame->GetPayloadLength(); @@ -109,31 +108,33 @@ void cDxr3AudioDecoder::Decode(cDxr3PesFrame *frame, uint32_t pts, cDxr3SyncBuff } } + uint8_t *ptr = const_cast(buf); + + while (length > 0) { + out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; + #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(51, 29, 0) - len = avcodec_decode_audio( + len = avcodec_decode_audio(contextAudio, (short *)(&pcmbuf), &out_size, ptr, length); #else - len = avcodec_decode_audio2( + len = avcodec_decode_audio2(contextAudio, (short *)(&pcmbuf), &out_size, ptr, length); #endif - contextAudio, (short *)(&pcmbuf), &out_size, const_cast(buf), length); - - if (len < 0) { - esyslog("[dxr3-decoder] failed to decode audio"); - return; - } - // can this happen? - if ((length - len) > 0) { - esyslog("[dxr3-decoder] TODO: more to decode"); - } + if (len < 0) { + esyslog("[dxr3-decoder] failed to decode audio"); + return; + } - if (out_size) { - cFixedLengthFrame* pTempFrame = aBuf.Push(pcmbuf, - out_size, pts); - if (pTempFrame) { - // TODO: should we break out of the loop on push timeout? - pTempFrame->SetChannelCount(contextAudio->channels); - pTempFrame->SetSampleRate(contextAudio->sample_rate); + if (out_size) { + cFixedLengthFrame* pTempFrame = aBuf.Push(pcmbuf, + out_size, pts); + if (pTempFrame) { + pTempFrame->SetChannelCount(contextAudio->channels); + pTempFrame->SetSampleRate(contextAudio->sample_rate); + } } + + length -= len; + ptr += len; } } -- cgit v1.2.3