summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-10 22:45:07 +0100
committerwm4 <wm4@nowhere>2015-02-10 22:48:15 +0100
commitabbaaaa6e7b565758822fb6aa90ebbb10353f699 (patch)
treea5d2f209d30cc682cc78d0de6e876533189dd07d /player
parent81d8c5d519828b1d5de9a30d23ceeb6c4c9a1d15 (diff)
downloadmpv-abbaaaa6e7b565758822fb6aa90ebbb10353f699.tar.bz2
mpv-abbaaaa6e7b565758822fb6aa90ebbb10353f699.tar.xz
player: skip audio filter reinit on some types of speed changes
This avoids potentially dropping some small amount of audio data buffered in filters. Reinit can be skipped only if the filter is af_scaletempo (which maps to AF_CONTROL_SET_PLAYBACK_SPEED). The other case using af_lavrresample is much more complicated due to filter chain politics. Also, changing speed between 1.0 and something higher typically inserts or removes the filter, so this obviously requires reinitialization. It can be prevented by forcing the filter with --af=scaletempo.
Diffstat (limited to 'player')
-rw-r--r--player/audio.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/player/audio.c b/player/audio.c
index 5e0497c84e..b63201029f 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -66,6 +66,7 @@ static int recreate_audio_filters(struct MPContext *mpctx)
struct MPOpts *opts = mpctx->opts;
struct af_stream *afs = mpctx->d_audio->afilter;
+ bool need_reinit = false;
double speed = opts->playback_speed;
@@ -89,8 +90,15 @@ static int recreate_audio_filters(struct MPContext *mpctx)
// Try again.
if (!af_control_any_rev(afs, method, &speed))
return -1;
+ } else {
+ method = AF_CONTROL_SET_PLAYBACK_SPEED;
}
}
+ // AF_CONTROL_SET_PLAYBACK_SPEED does not require reinitialization,
+ // while AF_CONTROL_SET_PLAYBACK_SPEED_RESAMPLE requires updating
+ // the samplerate on the resampler, and possibly inserting the
+ // resampler itself.
+ need_reinit |= (method == AF_CONTROL_SET_PLAYBACK_SPEED_RESAMPLE);
} else {
if (af_remove_by_label(afs, "playback-speed") < 0)
return -1;
@@ -99,7 +107,9 @@ static int recreate_audio_filters(struct MPContext *mpctx)
af_control_any_rev(afs, AF_CONTROL_SET_PLAYBACK_SPEED_RESAMPLE, &speed);
}
- if (af_init(afs) < 0) {
+ need_reinit |= afs->initialized < 1;
+
+ if (need_reinit && af_init(afs) < 0) {
MP_ERR(mpctx, "Couldn't find matching filter/ao format!\n");
return -1;
}