summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-22 14:47:46 +0200
committerwm4 <wm4@nowhere>2013-07-22 15:11:04 +0200
commit74146a855c25444c91297614804e444312478ceb (patch)
treea97aa9a7d3c5b6761a81617cab336a6d022603d4
parent465b162d1386e94a45699094914045b0ef8e2e0f (diff)
downloadmpv-74146a855c25444c91297614804e444312478ceb.tar.bz2
mpv-74146a855c25444c91297614804e444312478ceb.tar.xz
af_lavfi: switch to new option API
This makes it actually possible to use the filter with more complicated filter graphs (such as graphs containing the "," character).
-rw-r--r--DOCS/man/en/af.rst8
-rw-r--r--audio/filter/af_lavfi.c32
2 files changed, 30 insertions, 10 deletions
diff --git a/DOCS/man/en/af.rst b/DOCS/man/en/af.rst
index 63630fd591..01efd4119d 100644
--- a/DOCS/man/en/af.rst
+++ b/DOCS/man/en/af.rst
@@ -565,5 +565,9 @@ Available filters are:
.. warning::
- Due to shortcomings in the current ``-af`` option parser code,
- the filter graph must not contain any ``,``.
+ Don't forget to quote libavfilter graphs as described in the lavfi
+ video filter section.
+
+ ``o=<string>``
+ AVOptions.
+
diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c
index 6fe0853d07..3a0929b622 100644
--- a/audio/filter/af_lavfi.c
+++ b/audio/filter/af_lavfi.c
@@ -38,6 +38,9 @@
#include "audio/fmt-conversion.h"
#include "af.h"
+#include "core/m_option.h"
+#include "core/av_opts.h"
+
#define IS_LIBAV_FORK (LIBAVFILTER_VERSION_MICRO < 100)
// FFmpeg and Libav have slightly different APIs, just enough to cause us
@@ -68,11 +71,12 @@ struct priv {
// options
char *cfg_graph;
+ char *cfg_avopts;
};
static void destroy_graph(struct af_instance *af)
{
- struct priv *p = af->setup;
+ struct priv *p = af->priv;
avfilter_graph_free(&p->graph);
p->in = p->out = NULL;
}
@@ -80,7 +84,7 @@ static void destroy_graph(struct af_instance *af)
static bool recreate_graph(struct af_instance *af, struct mp_audio *config)
{
void *tmp = talloc_new(NULL);
- struct priv *p = af->setup;
+ struct priv *p = af->priv;
AVFilterContext *in = NULL, *out = NULL;
int r;
@@ -96,6 +100,12 @@ static bool recreate_graph(struct af_instance *af, struct mp_audio *config)
if (!graph)
goto error;
+ if (parse_avopts(graph, p->cfg_avopts) < 0) {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "lavfi: could not set opts: '%s'\n",
+ p->cfg_avopts);
+ goto error;
+ }
+
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
if (!outputs || !inputs)
@@ -161,7 +171,7 @@ error:
static int control(struct af_instance *af, int cmd, void *arg)
{
- struct priv *p = af->setup;
+ struct priv *p = af->priv;
switch (cmd) {
case AF_CONTROL_REINIT: {
@@ -207,7 +217,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
{
- struct priv *p = af->setup;
+ struct priv *p = af->priv;
AVFilterLink *l_in = p->in->outputs[0];
@@ -281,7 +291,6 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
static void uninit(struct af_instance *af)
{
- talloc_free(af->setup);
}
static int af_open(struct af_instance *af)
@@ -290,17 +299,24 @@ static int af_open(struct af_instance *af)
af->uninit = uninit;
af->play = play;
af->mul = 1;
- struct priv *priv = talloc_zero(NULL, struct priv);
- af->setup = priv;
+ struct priv *priv = af->priv;
af->data = &priv->data;
return AF_OK;
}
+#define OPT_BASE_STRUCT struct priv
+
struct af_info af_info_lavfi = {
"libavfilter bridge",
"lavfi",
"",
"",
0,
- af_open
+ af_open,
+ .priv_size = sizeof(struct priv),
+ .options = (const struct m_option[]) {
+ OPT_STRING("graph", cfg_graph, 0),
+ OPT_STRING("o", cfg_avopts, 0),
+ {0}
+ },
};