command: move setting playback speed to a separate function

This commit is contained in:
wm4 2014-10-02 02:49:05 +02:00
parent 7dd3822d09
commit c3e2a1febc
3 changed files with 19 additions and 10 deletions

View File

@ -88,6 +88,19 @@ int reinit_audio_filters(struct MPContext *mpctx)
return 1;
}
void set_playback_speed(struct MPContext *mpctx, double new_speed)
{
struct MPOpts *opts = mpctx->opts;
// Adjust time until next frame flip for nosound mode
mpctx->time_frame *= opts->playback_speed / new_speed;
opts->playback_speed = new_speed;
if (mpctx->d_audio)
recreate_audio_filters(mpctx);
}
void reset_audio_state(struct MPContext *mpctx)
{
if (mpctx->d_audio)

View File

@ -165,21 +165,16 @@ static int mp_property_playback_speed(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
double orig_speed = opts->playback_speed;
double speed = mpctx->opts->playback_speed;
switch (action) {
case M_PROPERTY_SET: {
opts->playback_speed = *(double *) arg;
if (opts->playback_speed == orig_speed)
return M_PROPERTY_OK;
// Adjust time until next frame flip for nosound mode
mpctx->time_frame *= orig_speed / opts->playback_speed;
if (mpctx->d_audio)
reinit_audio_chain(mpctx);
double new_speed = *(double *)arg;
if (speed != new_speed)
set_playback_speed(mpctx, new_speed);
return M_PROPERTY_OK;
}
case M_PROPERTY_PRINT:
*(char **)arg = talloc_asprintf(NULL, "%.2f", orig_speed);
*(char **)arg = talloc_asprintf(NULL, "%.2f", speed);
return M_PROPERTY_OK;
}
return mp_property_generic_option(mpctx, prop, action, arg);

View File

@ -367,6 +367,7 @@ double playing_audio_pts(struct MPContext *mpctx);
void fill_audio_out_buffers(struct MPContext *mpctx, double endpts);
double written_audio_pts(struct MPContext *mpctx);
void clear_audio_output_buffers(struct MPContext *mpctx);
void set_playback_speed(struct MPContext *mpctx, double new_speed);
// configfiles.c
void mp_parse_cfgfiles(struct MPContext *mpctx);