Skip to content

Commit

Permalink
Make mythmusic work right with new ffmpeg API
Browse files Browse the repository at this point in the history
  • Loading branch information
Beirdo committed Apr 4, 2012
1 parent e23cc71 commit eaa903e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
41 changes: 14 additions & 27 deletions mythplugins/mythmusic/mythmusic/avfdecoder.cpp
Expand Up @@ -89,7 +89,7 @@ avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
m_codec(NULL), m_codec(NULL),
m_audioDec(NULL), m_inputIsFile(false), m_audioDec(NULL), m_inputIsFile(false),
m_buffer(NULL), m_byteIOContext(NULL), m_buffer(NULL), m_byteIOContext(NULL),
errcode(0), m_samples(NULL) errcode(0)
{ {
setObjectName("avfDecoder"); setObjectName("avfDecoder");
setFilename(file); setFilename(file);
Expand All @@ -99,8 +99,6 @@ avfDecoder::~avfDecoder(void)
{ {
if (inited) if (inited)
deinit(); deinit();

av_freep((void *)&m_samples);
} }


void avfDecoder::stop() void avfDecoder::stop()
Expand Down Expand Up @@ -184,20 +182,6 @@ bool avfDecoder::initialize()
.arg(m_inputFormat->long_name)); .arg(m_inputFormat->long_name));
} }


if (!m_samples)
{
m_samples = (int16_t *)av_mallocz(AVCODEC_MAX_AUDIO_FRAME_SIZE *
sizeof(int32_t));
if (!m_samples)
{
error("Could not allocate output buffer in "
"avfDecoder::initialize");

deinit();
return false;
}
}

// open the media file // open the media file
// this should populate the input context // this should populate the input context
int err; int err;
Expand Down Expand Up @@ -379,7 +363,7 @@ void avfDecoder::run()
} }


AVPacket pkt, tmp_pkt; AVPacket pkt, tmp_pkt;
char *s; AVFrame *frame = avcodec_alloc_frame();
int data_size, dec_len; int data_size, dec_len;
uint fill, total; uint fill, total;
// account for possible frame expansion in aobase (upmix, float conv) // account for possible frame expansion in aobase (upmix, float conv)
Expand Down Expand Up @@ -423,30 +407,31 @@ void avfDecoder::run()
break; break;
} }


av_init_packet(&tmp_pkt);
tmp_pkt.data = pkt.data; tmp_pkt.data = pkt.data;
tmp_pkt.size = pkt.size; tmp_pkt.size = pkt.size;


while (tmp_pkt.size > 0 && !finish && while (tmp_pkt.size > 0 && !finish &&
!user_stop && seekTime <= 0.0) !user_stop && seekTime <= 0.0)
{ {
// Decode the stream to the output codec // Decode the stream to the output codec
// m_samples is the output buffer
// data_size is the size in bytes of the frame
// tmp_pkt is the input buffer
AVFrame frame;
int got_frame = 0; int got_frame = 0;


data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
dec_len = avcodec_decode_audio4(m_audioDec, &frame, dec_len = avcodec_decode_audio4(m_audioDec, frame,
&got_frame, &tmp_pkt); &got_frame, &tmp_pkt);
if (dec_len < 0 || !got_frame) if (dec_len < 0 || !got_frame)
break; break;


memcpy(m_samples, frame.extended_data[0], data_size); data_size =

av_samples_get_buffer_size(NULL,
s = (char *)m_samples; m_audioDec->channels,
frame->nb_samples,
m_audioDec->sample_fmt,
1);
// Copy the data to the output buffer // Copy the data to the output buffer
memcpy((char *)(output_buf + output_at), s, data_size); memcpy((char *)(output_buf + output_at),
frame->extended_data[0], data_size);


// Increment the output pointer and count // Increment the output pointer and count
output_at += data_size; output_at += data_size;
Expand Down Expand Up @@ -502,6 +487,8 @@ void avfDecoder::run()
dispatch(e); dispatch(e);
} }


av_free(frame);

deinit(); deinit();
RunEpilog(); RunEpilog();
} }
Expand Down
1 change: 0 additions & 1 deletion mythplugins/mythmusic/mythmusic/avfdecoder.h
Expand Up @@ -57,7 +57,6 @@ class avfDecoder : public Decoder
AVIOContext *m_byteIOContext; AVIOContext *m_byteIOContext;


int errcode; int errcode;
int16_t *m_samples;
}; };


#endif #endif
Expand Down

0 comments on commit eaa903e

Please sign in to comment.