diff options
author | Max Kellermann <max@duempel.org> | 2008-10-30 19:03:20 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-30 19:03:20 +0100 |
commit | 5f1df0a9273e62f6e6e4449b49f50ae010e64db2 (patch) | |
tree | 306f91d840b9a43521e16d3f3cea78f58b75f47d | |
parent | 048d62a6286ca5485f1b84bf9a181965daf698c7 (diff) | |
download | mpd-5f1df0a9273e62f6e6e4449b49f50ae010e64db2.tar.gz mpd-5f1df0a9273e62f6e6e4449b49f50ae010e64db2.tar.xz mpd-5f1df0a9273e62f6e6e4449b49f50ae010e64db2.zip |
ffmpeg: moved code to ffmpeg_send_frame()
Move code from ffmpeg_decode_internal() to make it smaller and more
readable.
Diffstat (limited to '')
-rw-r--r-- | src/decoder/ffmpeg_plugin.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c index 7c8f81a7a..327623ee7 100644 --- a/src/decoder/ffmpeg_plugin.c +++ b/src/decoder/ffmpeg_plugin.c @@ -212,6 +212,36 @@ ffmpeg_try_decode(struct input_stream *input) return input->seekable && ffmpeg_helper(input, NULL, NULL); } +static void +ffmpeg_send_packet(struct decoder *decoder, const AVPacket *packet, + AVCodecContext *codec_context, + const AVRational *time_base) +{ + int position; + uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; + int len, audio_size; + + position = av_rescale_q(packet->pts, *time_base, + (AVRational){1, 1}); + + audio_size = sizeof(audio_buf); + len = avcodec_decode_audio2(codec_context, + (int16_t *)audio_buf, + &audio_size, + packet->data, packet->size); + + if (len < 0) { + WARNING("skipping frame!\n"); + return; + } + + if (audio_size >= 0) + decoder_data(decoder, NULL, 1, + audio_buf, audio_size, + position, + codec_context->bit_rate / 1000, NULL); +} + static bool ffmpeg_decode_internal(BasePtrs *base) { @@ -219,11 +249,8 @@ ffmpeg_decode_internal(BasePtrs *base) AVCodecContext *aCodecCtx = base->aCodecCtx; AVFormatContext *pFormatCtx = base->pFormatCtx; AVPacket packet; - int len, audio_size; - int position; struct audio_format audio_format; int current, total_time; - uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; total_time = 0; @@ -242,8 +269,6 @@ ffmpeg_decode_internal(BasePtrs *base) decoder_initialized(decoder, &audio_format, total_time); - position = 0; - do { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { @@ -256,28 +281,10 @@ ffmpeg_decode_internal(BasePtrs *base) } if (av_read_frame(pFormatCtx, &packet) >= 0) { - if(packet.stream_index == base->audioStream) { - - position = av_rescale_q(packet.pts, pFormatCtx->streams[base->audioStream]->time_base, - (AVRational){1, 1}); - - audio_size = sizeof(audio_buf); - len = avcodec_decode_audio2(aCodecCtx, - (int16_t *)audio_buf, - &audio_size, - packet.data, - packet.size); - - if(len >= 0) { - if(audio_size >= 0) - decoder_data(decoder, NULL, 1, - audio_buf, audio_size, - position, //(float)current / (float)audio_format.sample_rate, - aCodecCtx->bit_rate / 1000, NULL); - } else { - WARNING("skiping frame!\n"); - } - } + if (packet.stream_index == base->audioStream) + ffmpeg_send_packet(decoder, &packet, aCodecCtx, + &pFormatCtx->streams[base->audioStream]->time_base); + av_free_packet(&packet); } else { //end of file |