Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix planar audio for nuv container.
Additionally, properly handle errors and potential issues should an AVPacket contains more than one audio frame

Fixes #11194
  • Loading branch information
jyavenard committed Apr 29, 2013
1 parent 56bd4a2 commit 709a6f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions mythtv/libs/libmythtv/nuppeldecoder.cpp
Expand Up @@ -22,6 +22,7 @@ using namespace std;
#include "mythlogging.h"
#include "myth_imgconvert.h"
#include "programinfo.h"
#include "audiooutpututil.h"

#include "minilzo.h"

Expand Down Expand Up @@ -56,7 +57,8 @@ NuppelDecoder::NuppelDecoder(MythPlayer *parent,
memset(&extradata, 0, sizeof(extendeddata));
memset(&tmppicture, 0, sizeof(AVPicture));
planes[0] = planes[1] = planes[2] = 0;
m_audioFrame = avcodec_alloc_frame();
m_audioSamples = (uint8_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE *
sizeof(int32_t));

// set parent class variables
positionMapType = MARK_KEYFRAME;
Expand Down Expand Up @@ -95,7 +97,7 @@ NuppelDecoder::~NuppelDecoder()
if (strm_buf)
delete [] strm_buf;

av_free(m_audioFrame);
av_free(m_audioSamples);

while (!StoredData.empty())
{
Expand Down Expand Up @@ -1273,25 +1275,23 @@ bool NuppelDecoder::GetFrame(DecodeType decodetype)

while (pkt.size > 0)
{
int got_frame = 0;
ret = avcodec_decode_audio4(mpa_audctx, m_audioFrame,
&got_frame, &pkt);
int data_size = 0;

if (got_frame && ret > 0)
ret = AudioOutputUtil::DecodeAudio(mpa_audctx, m_audioSamples,
data_size, &pkt);
if (ret < 0)
{
int data_size =
av_samples_get_buffer_size(NULL,
mpa_audctx->channels,
m_audioFrame->nb_samples,
mpa_audctx->sample_fmt,
1);
m_audio->AddAudioData(
(char *)m_audioFrame->extended_data[0],
data_size, frameheader.timecode, 0);
LOG(VB_GENERAL, LOG_ERR, LOC + "Unknown audio decoding error");
return false;
}

pkt.size -= ret;
pkt.data += ret;
if (data_size <= 0)
continue;

m_audio->AddAudioData((char *)m_audioSamples, data_size,
frameheader.timecode, 0);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/nuppeldecoder.h
Expand Up @@ -110,7 +110,7 @@ class NuppelDecoder : public DecoderBase
AVCodec *mpa_audcodec;
AVCodecContext *mpa_audctx;
AVPicture tmppicture;
AVFrame *m_audioFrame;
uint8_t *m_audioSamples;

bool directrendering;

Expand Down

0 comments on commit 709a6f6

Please sign in to comment.