1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-24 00:23:27 +00:00

audio: fix race condition in EOF code

Don't return an EOF code if there's still buffered data.

Also, don't call demux_stream_eof() in the playloop. There's probably
nothing wrong with it, but it's cleaner not to use it.

Also give AD_EOF its own value, so that a decoding error doesn't drain
audio by causing an EOF condition.
This commit is contained in:
wm4 2014-07-24 15:26:07 +02:00
parent b77dab0f6e
commit 986099d323
3 changed files with 4 additions and 4 deletions

View File

@ -274,13 +274,13 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
filter_data.rate = da->afilter->input.rate; // due to playback speed change
len = MPMIN(filter_data.samples, len);
filter_data.samples = len;
bool eof = filter_data.samples == 0 && error < 0;
bool eof = error == AD_EOF && filter_data.samples == 0;
if (af_filter(da->afilter, &filter_data, eof ? AF_FILTER_FLAG_EOF : 0) < 0)
return AD_ERR;
mp_audio_buffer_append(outbuf, &filter_data);
if (eof && filter_data.samples > 0)
if (error == AD_EOF && filter_data.samples > 0)
error = 0; // don't end playback yet
// remove processed data from decoder buffer:

View File

@ -51,9 +51,9 @@ struct dec_audio {
enum {
AD_OK = 0,
AD_ERR = -1,
AD_EOF = -1, // same as AD_ERR for now
AD_NEW_FMT = -2,
AD_ASYNC_PLAY_DONE = -3,
AD_EOF = -4,
};
struct mp_decoder_list *audio_decoder_list(void);

View File

@ -427,7 +427,7 @@ int fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
return -1;
} else if (res == AD_ASYNC_PLAY_DONE)
return 0;
else if (demux_stream_eof(d_audio->header))
else if (res == AD_EOF)
audio_eof = true;
}