summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-08-12 12:12:52 +0200
committerwm4 <wm4@nowhere>2017-08-12 12:12:52 +0200
commitbaead23ea06307af0d0a7acd21307d8f723b3a1b (patch)
tree6ad5dd4c1ac46df30a01eed8f714ed960a6900db /audio
parentc20df5b3e16eba790b7419d2338600c7b4a0e79d (diff)
downloadmpv-baead23ea06307af0d0a7acd21307d8f723b3a1b.tar.bz2
mpv-baead23ea06307af0d0a7acd21307d8f723b3a1b.tar.xz
af_lavrresample: don't call swr_set_compensation() unless necessary
This was _always_ called, even if the resampling was static, or the filter was inserted for format conversion only. This should have been fine, as I expected the function not to enable resampling when the compensation is unset, and the source/target rates are the same. But this is not the case, and it always enables resampling. So explicitly avoid the call. If we have already called it successfully, it's better not do avoid it (to overwrite the previous compensation value), but it will also be cheap/no-op then. Probably fixes #4716.
Diffstat (limited to 'audio')
-rw-r--r--audio/filter/af_lavrresample.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c
index ce991fa4fe..c18f8cc28a 100644
--- a/audio/filter/af_lavrresample.c
+++ b/audio/filter/af_lavrresample.c
@@ -76,6 +76,7 @@ struct af_resample {
int allow_detach;
char **avopts;
double playback_speed;
+ bool is_resampling;
struct AVAudioResampleContext *avrctx;
struct mp_audio avrctx_fmt; // output format of avrctx
struct mp_audio pool_fmt; // format used to allocate frames for avrctx output
@@ -332,6 +333,8 @@ static int configure_lavrr(struct af_instance *af, struct mp_audio *in,
// * Also, the input channel layout must have already been set.
avresample_set_channel_mapping(s->avrctx, s->reorder_in);
+ s->is_resampling = false;
+
if (avresample_open(s->avrctx) < 0 || avresample_open(s->avrctx_out) < 0) {
MP_ERR(af, "Cannot open Libavresample Context. \n");
goto error;
@@ -518,9 +521,7 @@ static int filter(struct af_instance *af, struct mp_audio *in)
struct af_resample *s = af->priv;
int new_rate = rate_from_speed(s->in_rate_af, s->playback_speed);
- bool need_reinit = fabs(new_rate / (double)s->in_rate - 1) > 0.01;
-
- if (s->avrctx) {
+ if (s->avrctx && !(!s->is_resampling && new_rate == s->in_rate)) {
AVRational r = av_d2q(s->playback_speed * s->in_rate_af / s->in_rate,
INT_MAX / 2);
// Essentially, swr/avresample_set_compensation() does 2 things:
@@ -531,10 +532,13 @@ static int filter(struct af_instance *af, struct mp_audio *in)
// feeding it, until the next filter() call.
int mult = INT_MAX / 2 / MPMAX(MPMAX(abs(r.num), abs(r.den)), 1);
r = (AVRational){ r.num * mult, r.den * mult };
- if (avresample_set_compensation(s->avrctx, r.den - r.num, r.den) < 0)
- need_reinit = true;
+ if (avresample_set_compensation(s->avrctx, r.den - r.num, r.den) >= 0) {
+ new_rate = s->in_rate;
+ s->is_resampling = true;
+ }
}
+ bool need_reinit = fabs(new_rate / (double)s->in_rate - 1) > 0.01;
if (need_reinit && new_rate != s->in_rate) {
// Before reconfiguring, drain the audio that is still buffered
// in the resampler.