summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-06-27 15:00:20 +0200
committerwm4 <wm4@nowhere>2016-06-27 15:12:21 +0200
commit3e58ce96acaec14adb840875c10b2b543be0b1e3 (patch)
treee2b60a8e6ffa55cef49b7f66095b58ef164b4d70
parentacb74236ac9e48ccc653207a22428d3811b0a2cd (diff)
downloadmpv-3e58ce96acaec14adb840875c10b2b543be0b1e3.tar.bz2
mpv-3e58ce96acaec14adb840875c10b2b543be0b1e3.tar.xz
dec_audio: fix segment boudnary switching
Some bugs in this code are exposed by e.g. playing lossless audio files with --ad-lavc-threads=16. (libavcodec doesn't really support threaded audio decoding, except for lossless files.) In these cases, a major amount of audio can be buffered, which makes incorrect handling of this buffering obvious. For one, draining the decoder can take a while, so if there's a new segment, we shouldn't read audio. The segment end check was completely wrong, and used the start value.
-rw-r--r--audio/decode/dec_audio.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index e60ebe370f..d455770a74 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -200,7 +200,9 @@ void audio_work(struct dec_audio *da)
if (da->current_frame)
return;
- if (!da->packet && demux_read_packet_async(da->header, &da->packet) == 0) {
+ if (!da->packet && !da->new_segment &&
+ demux_read_packet_async(da->header, &da->packet) == 0)
+ {
da->current_state = DATA_WAIT;
return;
}
@@ -211,6 +213,7 @@ void audio_work(struct dec_audio *da)
da->packet = NULL;
}
+ bool had_input_packet = !!da->packet;
bool had_packet = da->packet || da->new_segment;
int ret = da->ad_driver->decode_packet(da, da->packet, &da->current_frame);
@@ -233,12 +236,12 @@ void audio_work(struct dec_audio *da)
fix_audio_pts(da);
- bool segment_end = true;
+ bool segment_end = !da->current_frame && !had_input_packet;
if (da->current_frame) {
mp_audio_clip_timestamps(da->current_frame, da->start, da->end);
if (da->current_frame->pts != MP_NOPTS_VALUE && da->start != MP_NOPTS_VALUE)
- segment_end = da->current_frame->pts >= da->start;
+ segment_end = da->current_frame->pts >= da->end;
if (da->current_frame->samples == 0) {
talloc_free(da->current_frame);
da->current_frame = NULL;