mirror of
https://github.com/mpv-player/mpv
synced 2025-03-21 18:57:35 +00: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:
parent
fa75ae96e1
commit
6bfbca9912
@ -443,8 +443,12 @@ static void preselect_demux_streams(struct MPContext *mpctx)
|
|||||||
{
|
{
|
||||||
// Disable all streams, just to be sure no unwanted streams are selected.
|
// Disable all streams, just to be sure no unwanted streams are selected.
|
||||||
for (int n = 0; n < mpctx->num_sources; n++) {
|
for (int n = 0; n < mpctx->num_sources; n++) {
|
||||||
for (int type = 0; type < STREAM_TYPE_COUNT; type++)
|
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
|
||||||
demuxer_switch_track(mpctx->sources[n], type, NULL);
|
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++) {
|
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
|
||||||
|
@ -1214,6 +1214,10 @@ void demuxer_switch_track(struct demuxer *demuxer, enum stream_type type,
|
|||||||
{
|
{
|
||||||
assert(!stream || 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;
|
int old_id = demuxer->ds[type]->id;
|
||||||
|
|
||||||
// legacy
|
// legacy
|
||||||
|
Loading…
Reference in New Issue
Block a user