diff options
author | Max Kellermann <max@duempel.org> | 2011-09-15 21:48:33 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-09-15 21:48:33 +0200 |
commit | f804a739b1c4dd96efe268a84d58bfe4750b3378 (patch) | |
tree | 6abfb38026191f3b0c720a1ffea069769df1ec53 /src/decoder/ffmpeg_decoder_plugin.c | |
parent | 8751783a1b4fe8c61ac63b718be1df5f1d77d339 (diff) | |
parent | 2ed870c8546ce4654f956beea60546260d98a85c (diff) | |
download | mpd-f804a739b1c4dd96efe268a84d58bfe4750b3378.tar.gz mpd-f804a739b1c4dd96efe268a84d58bfe4750b3378.tar.xz mpd-f804a739b1c4dd96efe268a84d58bfe4750b3378.zip |
Merge branch 'v0.16.x'
Conflicts:
NEWS
configure.ac
Diffstat (limited to 'src/decoder/ffmpeg_decoder_plugin.c')
-rw-r--r-- | src/decoder/ffmpeg_decoder_plugin.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 78e874d9e..b4f1f0b51 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -211,6 +211,24 @@ align16(void *p, size_t *length_p) return (char *)p + add; } +G_GNUC_CONST +static double +time_from_ffmpeg(int64_t t, const AVRational time_base) +{ + assert(t != (int64_t)AV_NOPTS_VALUE); + + return (double)av_rescale_q(t, time_base, (AVRational){1, 1024}) + / (double)1024; +} + +G_GNUC_CONST +static int64_t +time_to_ffmpeg(double t, const AVRational time_base) +{ + return av_rescale_q((int64_t)(t * 1024), (AVRational){1, 1024}, + time_base); +} + static enum decoder_command ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, const AVPacket *packet, @@ -219,8 +237,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, { if (packet->pts != (int64_t)AV_NOPTS_VALUE) decoder_timestamp(decoder, - av_rescale_q(packet->pts, *time_base, - (AVRational){1, 1})); + time_from_ffmpeg(packet->pts, *time_base)); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,25,0) AVPacket packet2 = *packet; @@ -367,8 +384,9 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) return; } - AVCodecContext *codec_context = - format_context->streams[audio_stream]->codec; + AVStream *av_stream = format_context->streams[audio_stream]; + + AVCodecContext *codec_context = av_stream->codec; if (codec_context->codec_name[0] != 0) g_debug("codec '%s'", codec_context->codec_name); @@ -419,7 +437,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) if (packet.stream_index == audio_stream) cmd = ffmpeg_send_packet(decoder, input, &packet, codec_context, - &format_context->streams[audio_stream]->time_base); + &av_stream->time_base); else cmd = decoder_get_command(decoder); @@ -427,12 +445,16 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) if (cmd == DECODE_COMMAND_SEEK) { int64_t where = - decoder_seek_where(decoder) * AV_TIME_BASE; + time_to_ffmpeg(decoder_seek_where(decoder), + av_stream->time_base); - if (av_seek_frame(format_context, -1, where, 0) < 0) + if (av_seek_frame(format_context, audio_stream, where, + AV_TIME_BASE) < 0) decoder_seek_error(decoder); - else + else { + avcodec_flush_buffers(codec_context); decoder_command_finished(decoder); + } } } while (cmd != DECODE_COMMAND_STOP); |