summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-03-02 19:09:44 +0100
committerwm4 <wm4@nowhere>2015-03-02 19:09:44 +0100
commit89bc2975e951e2a20aa2d02bdb34cc268bb5c5cd (patch)
tree83db6ea5a95004fc448aa24a9af4fad7ecceac83 /player
parentd0fee0ac33a02e3dcb6c4b27b554be70e6b64e7a (diff)
downloadmpv-89bc2975e951e2a20aa2d02bdb34cc268bb5c5cd.tar.bz2
mpv-89bc2975e951e2a20aa2d02bdb34cc268bb5c5cd.tar.xz
audio: change playback speed directly in resampler
Although the libraries we use for resampling (libavresample and libswresample) do not support changing sampelrate on the fly, this makes it easier to make sure no audio buffers are implicitly dropped. In fact, this commit adds additional code to drain the resampler explicitly. Changing speed twice without feeding audio in-between made it crash with libavresample inc ertain cases (libswresample is fine). This is probably a libavresample bug. Hopefully this will be fixed, and also I attempted to workaround the situation that crashes it. (It seems to point in direction of random memory corruption, though.)
Diffstat (limited to 'player')
-rw-r--r--player/audio.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/player/audio.c b/player/audio.c
index c4329f07c6..79be29a359 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -66,7 +66,6 @@ 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;
@@ -84,7 +83,7 @@ static int recreate_audio_filters(struct MPContext *mpctx)
if (!af_control_any_rev(afs, AF_CONTROL_SET_PLAYBACK_SPEED, &speed))
{
char *filter = method == AF_CONTROL_SET_PLAYBACK_SPEED
- ? "scaletempo" : "forcespeed";
+ ? "scaletempo" : "lavrresample";
if (try_filter(mpctx, filter, "playback-speed", NULL) < 0)
return -1;
// Try again.
@@ -94,11 +93,6 @@ static int recreate_audio_filters(struct MPContext *mpctx)
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;
@@ -107,9 +101,7 @@ static int recreate_audio_filters(struct MPContext *mpctx)
af_control_any_rev(afs, AF_CONTROL_SET_PLAYBACK_SPEED_RESAMPLE, &speed);
}
- need_reinit |= afs->initialized < 1;
-
- if (need_reinit && af_init(afs) < 0) {
+ if (afs->initialized < 1 && af_init(afs) < 0) {
MP_ERR(mpctx, "Couldn't find matching filter/ao format!\n");
return -1;
}