summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-01-22 16:18:28 +0100
committerwm4 <wm4@nowhere>2016-01-22 16:18:28 +0100
commit135a7217b92c0b1c29ea40ab405566e72d23ae4b (patch)
tree491bfc975d15c4df6095a30720dd9bd404f73e70
parentce0b26c60ff31166b4b4317d269c52fe7d576c5c (diff)
downloadmpv-135a7217b92c0b1c29ea40ab405566e72d23ae4b.tar.bz2
mpv-135a7217b92c0b1c29ea40ab405566e72d23ae4b.tar.xz
command: add vf-command command
-rw-r--r--DOCS/man/input.rst6
-rw-r--r--input/cmd_list.c1
-rw-r--r--input/cmd_list.h1
-rw-r--r--player/command.c6
-rw-r--r--video/filter/vf.c11
-rw-r--r--video/filter/vf.h3
-rw-r--r--video/filter/vf_lavfi.c8
7 files changed, 36 insertions, 0 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index ed523b2135..86a80a8929 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -694,6 +694,12 @@ Input Commands that are Possibly Subject to Change
field is of type MPV_FORMAT_BYTE_ARRAY with the actual image data. The image
is freed as soon as the result node is freed.
+``vf-command "<label>" "<cmd>" "<args>"``
+ Send a command to the filter with the given ``<label>``. Use ``all`` to send
+ it to all filters at once. The command and argument string is filter
+ specific. Currently, this only works with the ``lavfi`` filter - see
+ the libavfilter documentation for which commands a filter supports.
+
Undocumented commands: ``tv-last-channel`` (TV/DVB only),
``ao-reload`` (experimental/internal).
diff --git a/input/cmd_list.c b/input/cmd_list.c
index 2f3bfb994a..a5fc342615 100644
--- a/input/cmd_list.c
+++ b/input/cmd_list.c
@@ -183,6 +183,7 @@ const struct mp_cmd_def mp_cmds[] = {
{ MP_CMD_AO_RELOAD, "ao-reload", },
{ MP_CMD_VF, "vf", { ARG_STRING, ARG_STRING } },
+ { MP_CMD_VF_COMMAND, "vf-command", { ARG_STRING, ARG_STRING, ARG_STRING } },
{ MP_CMD_VO_CMDLINE, "vo-cmdline", { ARG_STRING } },
diff --git a/input/cmd_list.h b/input/cmd_list.h
index c8c0dc3593..876fe4fd71 100644
--- a/input/cmd_list.h
+++ b/input/cmd_list.h
@@ -96,6 +96,7 @@ enum mp_command_type {
/// Video filter commands
MP_CMD_VF,
+ MP_CMD_VF_COMMAND,
/// Video output commands
MP_CMD_VO_CMDLINE,
diff --git a/player/command.c b/player/command.c
index 5be8c2d120..7bcdffc1c4 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4931,6 +4931,12 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
return edit_filters_osd(mpctx, STREAM_VIDEO, cmd->args[0].v.s,
cmd->args[1].v.s, msg_osd);
+ case MP_CMD_VF_COMMAND:
+ if (!mpctx->vo_chain)
+ return -1;
+ return vf_send_command(mpctx->vo_chain->vf, cmd->args[0].v.s,
+ cmd->args[1].v.s, cmd->args[2].v.s);
+
case MP_CMD_SCRIPT_BINDING: {
mpv_event_client_message event = {0};
char *name = cmd->args[0].v.s;
diff --git a/video/filter/vf.c b/video/filter/vf.c
index 35de0f23a7..f710d81ea7 100644
--- a/video/filter/vf.c
+++ b/video/filter/vf.c
@@ -163,6 +163,17 @@ static void vf_control_all(struct vf_chain *c, int cmd, void *arg)
}
}
+int vf_send_command(struct vf_chain *c, char *label, char *cmd, char *arg)
+{
+ char *args[2] = {cmd, arg};
+ if (strcmp(label, "all") == 0) {
+ vf_control_all(c, VFCTRL_COMMAND, args);
+ return 0;
+ } else {
+ return vf_control_by_label(c, VFCTRL_COMMAND, args, bstr0(label));
+ }
+}
+
static void vf_fix_img_params(struct mp_image *img, struct mp_image_params *p)
{
// Filters must absolutely set these correctly.
diff --git a/video/filter/vf.h b/video/filter/vf.h
index f828d4e735..c982b612e1 100644
--- a/video/filter/vf.h
+++ b/video/filter/vf.h
@@ -144,6 +144,7 @@ enum vf_ctrl {
/* Hack to make the OSD state object available to vf_sub which
* access OSD/subtitle state outside of normal OSD draw time. */
VFCTRL_INIT_OSD,
+ VFCTRL_COMMAND,
};
struct vf_chain *vf_new(struct mpv_global *global);
@@ -164,6 +165,8 @@ struct vf_instance *vf_find_by_label(struct vf_chain *c, const char *label);
void vf_print_filter_chain(struct vf_chain *c, int msglevel,
struct vf_instance *vf);
+int vf_send_command(struct vf_chain *c, char *label, char *cmd, char *arg);
+
// Filter internal API
struct mp_image *vf_alloc_out_image(struct vf_instance *vf);
bool vf_make_out_image_writeable(struct vf_instance *vf, struct mp_image *img);
diff --git a/video/filter/vf_lavfi.c b/video/filter/vf_lavfi.c
index e1705f6874..8cfd27a7bd 100644
--- a/video/filter/vf_lavfi.c
+++ b/video/filter/vf_lavfi.c
@@ -335,6 +335,14 @@ static int control(vf_instance_t *vf, int request, void *data)
case VFCTRL_SEEK_RESET:
reset(vf);
return CONTROL_OK;
+ case VFCTRL_COMMAND: {
+ if (!vf->priv->graph)
+ break;
+ char **args = data;
+ return avfilter_graph_send_command(vf->priv->graph, "all",
+ args[0], args[1], &(char){0}, 0, 0)
+ >= 0 ? CONTROL_OK : CONTROL_ERROR;
+ }
case VFCTRL_GET_METADATA:
if (vf->priv && vf->priv->metadata) {
*(struct mp_tags *)data = *vf->priv->metadata;