static int control(struct af_instance *af, int cmd, void *arg) { struct priv *p = af->priv; switch (cmd) { case AF_CONTROL_REINIT: { struct mp_audio *in = arg; struct mp_audio orig_in = *in; struct mp_audio *out = af->data; if (af_to_avformat(in->format) == AV_SAMPLE_FMT_NONE) mp_audio_set_format(in, AF_FORMAT_FLOAT); // Removing this requires fixing AVFrame.data vs. AVFrame.extended_data if (in->channels.num > AV_NUM_DATA_POINTERS) return AF_ERROR; if (!mp_chmap_is_lavc(&in->channels)) mp_chmap_reorder_to_lavc(&in->channels); // will always work if (!recreate_graph(af, in)) return AF_ERROR; AVFilterLink *l_out = p->out->inputs[0]; out->rate = l_out->sample_rate; mp_audio_set_format(out, af_from_avformat(l_out->format)); struct mp_chmap out_cm; mp_chmap_from_lavc(&out_cm, l_out->channel_layout); mp_audio_set_channels(out, &out_cm); if (!mp_audio_config_valid(out) || out->channels.num > AV_NUM_DATA_POINTERS) return AF_ERROR; p->timebase_out = l_out->time_base; return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE; } case AF_CONTROL_GET_METADATA: if (p->metadata) { *(struct mp_tags *)arg = *p->metadata; return CONTROL_OK; } return CONTROL_NA; case AF_CONTROL_RESET: reset(af); return AF_OK; } return AF_UNKNOWN; }
static int control(struct af_instance *af, int cmd, void *arg) { struct priv *p = af->priv; switch (cmd) { case AF_CONTROL_REINIT: { struct mp_audio *in = arg; struct mp_audio orig_in = *in; struct mp_audio *out = af->data; if (af_to_avformat(in->format) == AV_SAMPLE_FMT_NONE) mp_audio_set_format(in, AF_FORMAT_FLOAT); if (!mp_chmap_is_lavc(&in->channels)) mp_chmap_reorder_to_lavc(&in->channels); // will always work if (!recreate_graph(af, in)) return AF_ERROR; AVFilterLink *l_out = p->out->inputs[0]; out->rate = l_out->sample_rate; mp_audio_set_format(out, af_from_avformat(l_out->format)); struct mp_chmap out_cm; mp_chmap_from_lavc(&out_cm, l_out->channel_layout); if (!out_cm.num || out_cm.num != l_out->channels) mp_chmap_from_channels(&out_cm, l_out->channels); mp_audio_set_channels(out, &out_cm); if (!mp_audio_config_valid(out)) return AF_ERROR; p->timebase_out = l_out->time_base; // Blatantly incorrect; we don't know what the filters do. af->mul = out->rate / (double)in->rate; return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE; } } return AF_UNKNOWN; }
static void reset(struct af_instance *af) { if (!recreate_graph(af, &af->fmt_in)) MP_FATAL(af, "Can't recreate libavfilter filter after a seek reset.\n"); }