summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-02 20:30:30 +0200
committerwm4 <wm4@nowhere>2015-06-02 20:30:30 +0200
commitfe8634ea901e73d65350b90f735c08c75716dacf (patch)
treebbf38eb00e6691da9e0f43ff97795df2479f83fb
parentf14a3df778b3fa95d8996ca09fd23e1e6ddef16e (diff)
downloadmpv-fe8634ea901e73d65350b90f735c08c75716dacf.tar.bz2
mpv-fe8634ea901e73d65350b90f735c08c75716dacf.tar.xz
af_lavrresample: fix and simplify flushing on playback speed change
This manually retrieved the remaining audio from the resampler. It subtly missed a conversion which could leave to an unsubtle crash. This could happen if reorder_planes() was supposed to insert NA channels, and the resampler/actual output format were different. Simplify it by reusing the normal drain path. One oddness is that the filter will add an output frame outside of normal filtering, but that should be fine.
-rw-r--r--audio/filter/af_lavrresample.c24
1 files changed, 1 insertions, 23 deletions
diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c
index f18b7e10a2..1f5e0fc575 100644
--- a/audio/filter/af_lavrresample.c
+++ b/audio/filter/af_lavrresample.c
@@ -78,7 +78,6 @@ struct af_resample {
int allow_detach;
char **avopts;
double playback_speed;
- struct mp_audio *pending;
bool avrctx_ok;
struct AVAudioResampleContext *avrctx;
struct mp_audio avrctx_fmt; // output format of avrctx
@@ -200,9 +199,6 @@ static int configure_lavrr(struct af_instance *af, struct mp_audio *in,
avresample_close(s->avrctx);
avresample_close(s->avrctx_out);
- talloc_free(s->pending);
- s->pending = NULL;
-
s->ctx.out_rate = out->rate;
s->ctx.in_rate_af = in->rate;
s->ctx.in_rate = rate_from_speed(in->rate, s->playback_speed);
@@ -363,17 +359,9 @@ static int control(struct af_instance *af, int cmd, void *arg)
if (new_rate != s->ctx.in_rate && s->avrctx_ok && af->fmt_out.format) {
// Before reconfiguring, drain the audio that is still buffered
// in the resampler.
- struct mp_audio *pending = talloc_zero(NULL, struct mp_audio);
- mp_audio_copy_config(pending, &af->fmt_out);
- pending->samples = get_drain_samples(s);
- if (pending->samples > 0) {
- mp_audio_realloc_min(pending, pending->samples);
- int r = resample_frame(s->avrctx, pending, NULL);
- pending->samples = MPMAX(r, 0);
- }
+ af->filter_frame(af, NULL);
// Reinitialize resampler.
configure_lavrr(af, &af->fmt_in, &af->fmt_out);
- s->pending = pending;
}
return AF_OK;
}
@@ -393,7 +381,6 @@ static void uninit(struct af_instance *af)
if (s->avrctx_out)
avresample_close(s->avrctx_out);
avresample_free(&s->avrctx_out);
- talloc_free(s->pending);
}
static void reorder_planes(struct mp_audio *mpa, int *reorder,
@@ -418,15 +405,6 @@ static int filter(struct af_instance *af, struct mp_audio *in)
{
struct af_resample *s = af->priv;
- if (s->pending) {
- if (s->pending->samples) {
- af_add_output_frame(af, s->pending);
- } else {
- talloc_free(s->pending);
- }
- s->pending = NULL;
- }
-
int samples = avresample_available(s->avrctx) +
av_rescale_rnd(get_delay(s) + (in ? in->samples : 0),
s->ctx.out_rate, s->ctx.in_rate, AV_ROUND_UP);