Skip to content
Browse files

Make mythmusic work right with new ffmpeg API

  • Loading branch information...
1 parent e23cc71 commit eaa903e83946615c373996e49fe72a68a18721ab @Beirdo Beirdo committed Apr 3, 2012
Showing with 14 additions and 28 deletions.
  1. +14 −27 mythplugins/mythmusic/mythmusic/avfdecoder.cpp
  2. +0 −1 mythplugins/mythmusic/mythmusic/avfdecoder.h
View
41 mythplugins/mythmusic/mythmusic/avfdecoder.cpp
@@ -89,7 +89,7 @@ avfDecoder::avfDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
m_codec(NULL),
m_audioDec(NULL), m_inputIsFile(false),
m_buffer(NULL), m_byteIOContext(NULL),
- errcode(0), m_samples(NULL)
+ errcode(0)
{
setObjectName("avfDecoder");
setFilename(file);
@@ -99,8 +99,6 @@ avfDecoder::~avfDecoder(void)
{
if (inited)
deinit();
-
- av_freep((void *)&m_samples);
}
void avfDecoder::stop()
@@ -184,20 +182,6 @@ bool avfDecoder::initialize()
.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
// this should populate the input context
int err;
@@ -379,7 +363,7 @@ void avfDecoder::run()
}
AVPacket pkt, tmp_pkt;
- char *s;
+ AVFrame *frame = avcodec_alloc_frame();
int data_size, dec_len;
uint fill, total;
// account for possible frame expansion in aobase (upmix, float conv)
@@ -423,30 +407,31 @@ void avfDecoder::run()
break;
}
+ av_init_packet(&tmp_pkt);
tmp_pkt.data = pkt.data;
tmp_pkt.size = pkt.size;
while (tmp_pkt.size > 0 && !finish &&
!user_stop && seekTime <= 0.0)
{
// 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;
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);
if (dec_len < 0 || !got_frame)
break;
- memcpy(m_samples, frame.extended_data[0], data_size);
-
- s = (char *)m_samples;
+ data_size =
+ av_samples_get_buffer_size(NULL,
+ m_audioDec->channels,
+ frame->nb_samples,
+ m_audioDec->sample_fmt,
+ 1);
// 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
output_at += data_size;
@@ -502,6 +487,8 @@ void avfDecoder::run()
dispatch(e);
}
+ av_free(frame);
+
deinit();
RunEpilog();
}
View
1 mythplugins/mythmusic/mythmusic/avfdecoder.h
@@ -57,7 +57,6 @@ class avfDecoder : public Decoder
AVIOContext *m_byteIOContext;
int errcode;
- int16_t *m_samples;
};
#endif

0 comments on commit eaa903e

Please sign in to comment.
Something went wrong with that request. Please try again.