aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-06-22 14:41:44 +0200
committerMax Kellermann <max@duempel.org>2015-06-22 14:42:19 +0200
commit94c037821ba26a040006568a103b770571fda140 (patch)
tree5b47227327e8d4642a42ef5e31fe5e2a2e12b417 /src/decoder
parente38e8eb6365e6c5534a5362b25746279a79c8a1a (diff)
downloadmpd-94c037821ba26a040006568a103b770571fda140.tar.gz
mpd-94c037821ba26a040006568a103b770571fda140.tar.xz
mpd-94c037821ba26a040006568a103b770571fda140.zip
decoder/ffmpeg: check for commands earlier
Improve initial seek by not reading/decoding the first frame before checking for the seek command.
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/plugins/FfmpegDecoderPlugin.cxx44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
index 90699ef5e..88352bbb0 100644
--- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
@@ -543,8 +543,27 @@ FfmpegDecode(Decoder &decoder, InputStream &input,
uint64_t min_frame = 0;
- DecoderCommand cmd;
- do {
+ DecoderCommand cmd = decoder_get_command(decoder);
+ while (cmd != DecoderCommand::STOP) {
+ if (cmd == DecoderCommand::SEEK) {
+ int64_t where =
+ ToFfmpegTime(decoder_seek_time(decoder),
+ av_stream.time_base) +
+ start_time_fallback(av_stream);
+
+ /* AVSEEK_FLAG_BACKWARD asks FFmpeg to seek to
+ the packet boundary before the seek time
+ stamp, not after */
+ if (av_seek_frame(&format_context, audio_stream, where,
+ AVSEEK_FLAG_ANY|AVSEEK_FLAG_BACKWARD) < 0)
+ decoder_seek_error(decoder);
+ else {
+ avcodec_flush_buffers(&codec_context);
+ min_frame = decoder_seek_where_frame(decoder);
+ decoder_command_finished(decoder);
+ }
+ }
+
AVPacket packet;
if (av_read_frame(&format_context, &packet) < 0)
/* end of file */
@@ -566,26 +585,7 @@ FfmpegDecode(Decoder &decoder, InputStream &input,
cmd = decoder_get_command(decoder);
av_free_packet(&packet);
-
- if (cmd == DecoderCommand::SEEK) {
- int64_t where =
- ToFfmpegTime(decoder_seek_time(decoder),
- av_stream.time_base) +
- start_time_fallback(av_stream);
-
- /* AVSEEK_FLAG_BACKWARD asks FFmpeg to seek to
- the packet boundary before the seek time
- stamp, not after */
- if (av_seek_frame(&format_context, audio_stream, where,
- AVSEEK_FLAG_ANY|AVSEEK_FLAG_BACKWARD) < 0)
- decoder_seek_error(decoder);
- else {
- avcodec_flush_buffers(&codec_context);
- min_frame = decoder_seek_where_frame(decoder);
- decoder_command_finished(decoder);
- }
- }
- } while (cmd != DecoderCommand::STOP);
+ }
#if LIBAVUTIL_VERSION_MAJOR >= 53
av_frame_free(&frame);