1
mirror of https://github.com/mpv-player/mpv synced 2025-01-13 00:06:25 +01:00

core: avoid deselecting and reselecting stream needlessly

The core deselected all streams on initialization, and then selected the
streams it actually wanted. This was no problem for
demux_mkv/demux_lavf, but old demuxers (like demux_asf) could lose some
packets. The problem is that these demuxers can buffer some data on
initialization, which then is flushed on track switching. Fix this by
explicitly avoiding deselecting a wanted stream.
This commit is contained in:
wm4 2013-05-29 14:54:51 +02:00
parent fa75ae96e1
commit 6bfbca9912
2 changed files with 10 additions and 2 deletions

View File

@ -443,8 +443,12 @@ static void preselect_demux_streams(struct MPContext *mpctx)
{
// Disable all streams, just to be sure no unwanted streams are selected.
for (int n = 0; n < mpctx->num_sources; n++) {
for (int type = 0; type < STREAM_TYPE_COUNT; type++)
demuxer_switch_track(mpctx->sources[n], type, NULL);
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
struct track *track = mpctx->current_track[type];
if (!(track && track->demuxer == mpctx->sources[n] &&
demuxer_stream_is_selected(track->demuxer, track->stream)))
demuxer_switch_track(mpctx->sources[n], type, NULL);
}
}
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {

View File

@ -1214,6 +1214,10 @@ void demuxer_switch_track(struct demuxer *demuxer, enum stream_type type,
{
assert(!stream || stream->type == type);
// don't flush buffers if stream is already selected
if (stream && demuxer_stream_is_selected(demuxer, stream))
return;
int old_id = demuxer->ds[type]->id;
// legacy