diff options
author | wm4 <wm4@nowhere> | 2020-05-23 04:04:46 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-05-23 04:04:46 +0200 |
commit | ab4e0c42fbb11f2e7459fe9fe98265e0323b1ef4 (patch) | |
tree | 8d202d9a8d7aecf3f305c0311d5115b46ba009d9 /player | |
parent | 43a67970b6c17f8d0525f90fac25923cd4a989bf (diff) | |
download | mpv-ab4e0c42fbb11f2e7459fe9fe98265e0323b1ef4.tar.bz2 mpv-ab4e0c42fbb11f2e7459fe9fe98265e0323b1ef4.tar.xz |
audio: redo video-sync=display-adrop
This mode drops or repeats audio data to adapt to video speed, instead
of resampling it or such. It was added to deal with SPDIF. The
implementation was part of fill_audio_out_buffers() - the entire
function is something whose complexity exploded in my face, and which I
want to clean up, and this is hopefully a first step.
Put it in a filter, and mess with the shitty glue code. It's all sort of
roundabout and illogical, but that can be rectified later. The important
part is that it works much like the resample or scaletempo filters.
For PCM audio, this does not work on samples anymore. This makes it much
worse. But for PCM you can use saner mechanisms that sound better. Also,
something about PTS tracking is wrong. But not wasting more time on
this.
Diffstat (limited to 'player')
-rw-r--r-- | player/audio.c | 41 | ||||
-rw-r--r-- | player/video.c | 2 |
2 files changed, 8 insertions, 35 deletions
diff --git a/player/audio.c b/player/audio.c index cde444ffb4..7bc1b8ac86 100644 --- a/player/audio.c +++ b/player/audio.c @@ -54,13 +54,19 @@ static void update_speed_filters(struct MPContext *mpctx) double speed = mpctx->opts->playback_speed; double resample = mpctx->speed_factor_a; + double drop = 1.0; if (!mpctx->opts->pitch_correction) { resample *= speed; speed = 1.0; } - mp_output_chain_set_audio_speed(ao_c->filter, speed, resample); + if (mpctx->display_sync_active && mpctx->opts->video_sync == VS_DISP_ADROP) { + drop *= speed * resample; + resample = speed = 1.0; + } + + mp_output_chain_set_audio_speed(ao_c->filter, speed, resample, drop); } static int recreate_audio_filters(struct MPContext *mpctx) @@ -878,24 +884,6 @@ void fill_audio_out_buffers(struct MPContext *mpctx) playsize = MPMAX(1, playsize + skip); // silence will be prepended } - int skip_duplicate = 0; // >0: skip, <0: duplicate - double drop_limit = - (opts->sync_max_audio_change + opts->sync_max_video_change) / 100; - if (mpctx->display_sync_active && opts->video_sync == VS_DISP_ADROP && - fabs(mpctx->last_av_difference) >= opts->sync_audio_drop_size && - mpctx->audio_drop_throttle < drop_limit && - mpctx->audio_status == STATUS_PLAYING) - { - int samples = ceil(opts->sync_audio_drop_size * play_samplerate); - samples = (samples + align / 2) / align * align; - - skip_duplicate = mpctx->last_av_difference >= 0 ? -samples : samples; - - playsize = MPMAX(playsize, samples); - - mpctx->audio_drop_throttle += 1 - drop_limit - samples / play_samplerate; - } - playsize = playsize / align * align; int status = mpctx->audio_status >= STATUS_DRAINING ? AD_EOF : AD_OK; @@ -940,21 +928,6 @@ void fill_audio_out_buffers(struct MPContext *mpctx) end_sync = true; } - if (skip_duplicate) { - int max = mp_audio_buffer_samples(ao_c->ao_buffer); - if (abs(skip_duplicate) > max) - skip_duplicate = skip_duplicate >= 0 ? max : -max; - mpctx->last_av_difference += skip_duplicate / play_samplerate; - if (skip_duplicate >= 0) { - mp_audio_buffer_skip(ao_c->ao_buffer, skip_duplicate); - MP_STATS(mpctx, "drop-audio"); - } else { - mp_audio_buffer_duplicate(ao_c->ao_buffer, -skip_duplicate); - MP_STATS(mpctx, "duplicate-audio"); - } - MP_VERBOSE(mpctx, "audio skip_duplicate=%d\n", skip_duplicate); - } - if (mpctx->audio_status == STATUS_SYNCING) { if (end_sync) mpctx->audio_status = STATUS_FILLING; diff --git a/player/video.c b/player/video.c index 5102ddf656..b82999f403 100644 --- a/player/video.c +++ b/player/video.c @@ -898,7 +898,7 @@ static void handle_display_sync_frame(struct MPContext *mpctx, mpctx->past_frames[0].num_vsyncs = num_vsyncs; mpctx->past_frames[0].av_diff = mpctx->last_av_difference; - if (resample) { + if (resample || mode == VS_DISP_ADROP) { adjust_audio_resample_speed(mpctx, vsync); } else { mpctx->speed_factor_a = 1.0; |