diff options
Diffstat (limited to 'src/decoder/ffmpeg_plugin.c')
-rw-r--r-- | src/decoder/ffmpeg_plugin.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c index f9e40e2f5..7f7978b9d 100644 --- a/src/decoder/ffmpeg_plugin.c +++ b/src/decoder/ffmpeg_plugin.c @@ -106,7 +106,7 @@ static int64_t mpd_ffmpeg_seek(URLContext *h, int64_t pos, int whence) static int mpd_ffmpeg_close(URLContext *h) { - h->priv_data = 0; + h->priv_data = NULL; return 0; } @@ -208,30 +208,46 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, AVCodecContext *codec_context, const AVRational *time_base) { + enum decoder_command cmd = DECODE_COMMAND_NONE; int position; uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; int len, audio_size; + uint8_t *packet_data; + int packet_size; - position = av_rescale_q(packet->pts, *time_base, - (AVRational){1, 1}); + packet_data = packet->data; + packet_size = packet->size; - audio_size = sizeof(audio_buf); - len = avcodec_decode_audio2(codec_context, - (int16_t *)audio_buf, - &audio_size, - packet->data, packet->size); + while ((packet_size > 0) && (cmd == DECODE_COMMAND_NONE)) { + audio_size = sizeof(audio_buf); + len = avcodec_decode_audio2(codec_context, + (int16_t *)audio_buf, + &audio_size, + packet_data, packet_size); - if (len < 0) { - g_message("skipping frame\n"); - return decoder_get_command(decoder); - } - assert(audio_size >= 0); + position = av_rescale_q(packet->pts, *time_base, + (AVRational){1, 1}); + + if (len < 0) { + /* if error, we skip the frame */ + g_message("decoding failed\n"); + break; + } - return decoder_data(decoder, is, - audio_buf, audio_size, - position, - codec_context->bit_rate / 1000, NULL); + packet_data += len; + packet_size -= len; + + if (audio_size <= 0) { + g_message("no audio frame\n"); + continue; + } + cmd = decoder_data(decoder, is, + audio_buf, audio_size, + position, + codec_context->bit_rate / 1000, NULL); + } + return cmd; } static bool @@ -263,7 +279,7 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx) } //there is some problem with this on some demux (mp3 at least) - if (format_context->duration != (int)AV_NOPTS_VALUE) { + if (format_context->duration != (int64_t)AV_NOPTS_VALUE) { total_time = format_context->duration / AV_TIME_BASE; } @@ -314,7 +330,7 @@ static bool ffmpeg_tag_internal(struct ffmpeg_context *ctx) const AVFormatContext *f = ctx->format_context; tag->time = 0; - if (f->duration != (int)AV_NOPTS_VALUE) + if (f->duration != (int64_t)AV_NOPTS_VALUE) tag->time = f->duration / AV_TIME_BASE; if (f->author[0]) tag_add_item(tag, TAG_ITEM_ARTIST, f->author); @@ -368,8 +384,9 @@ static struct tag *ffmpeg_tag(const char *file) */ static const char *const ffmpeg_suffixes[] = { - "wma", "asf", "wmv", "mpeg", "mpg", "avi", "vob", "mov", "qt", "swf", "rm", "swf", - "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc", + "wma", "asf", "wmv", "mpeg", "mpg", "avi", "vob", "mov", "qt", "swf", + "rm", "swf", "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", + "au", "aiff", "aif", "ac3", "aac", "mpc", "ape", NULL }; |