mirror of
https://github.com/mpv-player/mpv
synced 2024-08-04 14:59:58 +02:00
core/hrseek: support precise seeks in audio-only case
Before, precise seeking only worked if there was a video stream; in the audio-only case playback always started from the demuxer seek position. Add code to cut away samples from the demuxer seek position to the seek target position.
This commit is contained in:
parent
32b2242d67
commit
0aa8df2b7d
22
mplayer.c
22
mplayer.c
@ -2464,10 +2464,16 @@ static int audio_start_sync(struct MPContext *mpctx, int playsize)
|
||||
bool did_retry = false;
|
||||
double written_pts;
|
||||
double bps = ao->bps / opts->playback_speed;
|
||||
bool hrseek = mpctx->hrseek_active; // audio only hrseek
|
||||
mpctx->hrseek_active = false;
|
||||
while (1) {
|
||||
written_pts = written_audio_pts(mpctx);
|
||||
double ptsdiff = written_pts - mpctx->sh_video->pts - mpctx->delay
|
||||
- audio_delay;
|
||||
double ptsdiff;
|
||||
if (hrseek)
|
||||
ptsdiff = written_pts - mpctx->hrseek_pts;
|
||||
else
|
||||
ptsdiff = written_pts - mpctx->sh_video->pts - mpctx->delay
|
||||
- audio_delay;
|
||||
bytes = ptsdiff * bps;
|
||||
bytes -= bytes % (ao->channels * af_fmt2bits(ao->format) / 8);
|
||||
|
||||
@ -2506,6 +2512,9 @@ static int audio_start_sync(struct MPContext *mpctx, int playsize)
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
if (hrseek)
|
||||
// Don't add silence in audio-only case even if position is too late
|
||||
return 0;
|
||||
int fillbyte = 0;
|
||||
if ((ao->format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
|
||||
fillbyte = 0x80;
|
||||
@ -2557,11 +2566,16 @@ static int fill_audio_out_buffers(struct MPContext *mpctx)
|
||||
current_module = "decode_audio";
|
||||
t = GetTimer();
|
||||
|
||||
if (!opts->initial_audio_sync || !modifiable_audio_format)
|
||||
// Coming here with hrseek_active still set means audio-only
|
||||
if (!mpctx->sh_video)
|
||||
mpctx->syncing_audio = false;
|
||||
if (!opts->initial_audio_sync || !modifiable_audio_format) {
|
||||
mpctx->syncing_audio = false;
|
||||
mpctx->hrseek_active = false;
|
||||
}
|
||||
|
||||
int res;
|
||||
if (mpctx->syncing_audio && mpctx->sh_video)
|
||||
if (mpctx->syncing_audio || mpctx->hrseek_active)
|
||||
res = audio_start_sync(mpctx, playsize);
|
||||
else
|
||||
res = decode_audio(sh_audio, &ao->buffer, playsize);
|
||||
|
Loading…
Reference in New Issue
Block a user