mirror of
https://github.com/mpv-player/mpv
synced 2025-03-22 19:34:14 +00:00
player: remove delayed audio seek thing
This was a hack that attempted to line up external audio tracks with video. The problem is that if you do a keyframe seek backwards, video will usually seek much farther back than audio (due to much higher keyframe aka seek point distances). The hack somehow made seeking a 2 step process. This existed in 4 different forms in the history of this code base, and it was always very cumbersome. We mostly needed this for ytdl_hook (I think?), which uses the 4th form, which is nicely confined to demux_timeline and is unrelated to the "external" audio tracks in the high level player. Since this is (probably) not really widely needed anymore, get rid of it. Better do this now, than when somehow rewriting all the seeking code (which might happen in this decade or the next or so) and when it wouldn't be easily revertable anymore in case we find we "really" need it unlike expected. There is no issue if hr-seeks are used. Also, you can still use edl files to "bundle" multiple streams as if it was a single stream (this is what ytdl_hook does now).
This commit is contained in:
parent
d32ce14d2c
commit
c10ca137a8
@ -408,10 +408,6 @@ typedef struct MPContext {
|
||||
|
||||
struct seek_params seek;
|
||||
|
||||
// Can be temporarily set to an external audio track after seeks. Then it
|
||||
// must be seeked to the video position once video is done seeking.
|
||||
struct track *seek_slave;
|
||||
|
||||
/* Heuristic for relative chapter seeks: keep track which chapter
|
||||
* the user wanted to go to, even if we aren't exactly within the
|
||||
* boundaries of that chapter due to an inaccurate seek. */
|
||||
|
@ -196,7 +196,6 @@ static void uninit_demuxer(struct MPContext *mpctx)
|
||||
for (int t = 0; t < STREAM_TYPE_COUNT; t++)
|
||||
mpctx->current_track[r][t] = NULL;
|
||||
}
|
||||
mpctx->seek_slave = NULL;
|
||||
|
||||
talloc_free(mpctx->chapters);
|
||||
mpctx->chapters = NULL;
|
||||
@ -373,8 +372,6 @@ void reselect_demux_stream(struct MPContext *mpctx, struct track *track)
|
||||
pts -= 10.0;
|
||||
}
|
||||
demuxer_select_track(track->demuxer, track->stream, pts, track->selected);
|
||||
if (track == mpctx->seek_slave)
|
||||
mpctx->seek_slave = NULL;
|
||||
}
|
||||
|
||||
static void enable_demux_thread(struct MPContext *mpctx, struct demuxer *demux)
|
||||
@ -707,9 +704,6 @@ bool mp_remove_track(struct MPContext *mpctx, struct track *track)
|
||||
|
||||
struct demuxer *d = track->demuxer;
|
||||
|
||||
if (mpctx->seek_slave == track)
|
||||
mpctx->seek_slave = NULL;
|
||||
|
||||
int index = 0;
|
||||
while (index < mpctx->num_tracks && mpctx->tracks[index] != track)
|
||||
index++;
|
||||
|
@ -244,7 +244,6 @@ void reset_playback_state(struct MPContext *mpctx)
|
||||
mpctx->restart_complete = false;
|
||||
mpctx->paused_for_cache = false;
|
||||
mpctx->cache_buffer = 100;
|
||||
mpctx->seek_slave = NULL;
|
||||
|
||||
encode_lavc_discontinuity(mpctx->encode_lavc_ctx);
|
||||
|
||||
@ -348,8 +347,6 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek)
|
||||
mpctx->play_dir = play_dir;
|
||||
|
||||
// Seek external, extra files too:
|
||||
bool has_video = false;
|
||||
struct track *external_audio = NULL;
|
||||
for (int t = 0; t < mpctx->num_tracks; t++) {
|
||||
struct track *track = mpctx->tracks[t];
|
||||
if (track->selected && track->is_external && track->demuxer) {
|
||||
@ -359,12 +356,7 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek)
|
||||
if (demux_flags & SEEK_FACTOR)
|
||||
main_new_pos = seek_pts;
|
||||
demux_seek(track->demuxer, main_new_pos, demux_flags & SEEK_SATAN);
|
||||
if (track->type == STREAM_AUDIO && !external_audio)
|
||||
external_audio = track;
|
||||
}
|
||||
if (track->selected && !track->is_external && track->stream &&
|
||||
track->type == STREAM_VIDEO && !track->stream->attached_picture)
|
||||
has_video = true;
|
||||
}
|
||||
|
||||
if (!(seek.flags & MPSEEK_FLAG_NOFLUSH))
|
||||
@ -374,19 +366,6 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek)
|
||||
if (mpctx->recorder)
|
||||
mp_recorder_mark_discontinuity(mpctx->recorder);
|
||||
|
||||
// When doing keyframe seeks (hr_seek=false) backwards (no SEEK_FORWARD),
|
||||
// then video can seek before the external audio track (because video seek
|
||||
// granularity is coarser than audio). The result would be playing video with
|
||||
// silence until the audio seek target is reached. Work around by blocking
|
||||
// the demuxer (decoders can't read) and seeking to video position later.
|
||||
if (has_video && external_audio && !hr_seek && mpctx->play_dir > 0 &&
|
||||
!(demux_flags & SEEK_FORWARD))
|
||||
{
|
||||
MP_VERBOSE(mpctx, "delayed seek for aid=%d\n", external_audio->user_tid);
|
||||
demux_block_reading(external_audio->demuxer, true);
|
||||
mpctx->seek_slave = external_audio;
|
||||
}
|
||||
|
||||
/* Use the target time as "current position" for further relative
|
||||
* seeks etc until a new video frame has been decoded */
|
||||
mpctx->last_seek_pts = seek_pts;
|
||||
@ -1087,24 +1066,6 @@ static void handle_playback_time(struct MPContext *mpctx)
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_delayed_audio_seek(struct MPContext *mpctx)
|
||||
{
|
||||
if (mpctx->seek_slave) {
|
||||
if (mpctx->video_pts != MP_NOPTS_VALUE) {
|
||||
// We know the video position now, so seek external audio to the
|
||||
// correct position.
|
||||
double pts = mpctx->video_pts +
|
||||
get_track_seek_offset(mpctx, mpctx->seek_slave);
|
||||
demux_seek(mpctx->seek_slave->demuxer, pts, 0);
|
||||
mpctx->seek_slave = NULL;
|
||||
} else if (mpctx->video_status >= STATUS_EOF) {
|
||||
// We won't get a video position; don't stall the audio stream.
|
||||
demux_block_reading(mpctx->seek_slave->demuxer, false);
|
||||
mpctx->seek_slave = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We always make sure audio and video buffers are filled before actually
|
||||
// starting playback. This code handles starting them at the same time.
|
||||
static void handle_playback_restart(struct MPContext *mpctx)
|
||||
@ -1217,8 +1178,6 @@ void run_playloop(struct MPContext *mpctx)
|
||||
fill_audio_out_buffers(mpctx);
|
||||
write_video(mpctx);
|
||||
|
||||
handle_delayed_audio_seek(mpctx);
|
||||
|
||||
handle_playback_restart(mpctx);
|
||||
|
||||
handle_playback_time(mpctx);
|
||||
|
Loading…
Reference in New Issue
Block a user