2013-12-26 16:10:35 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2013-12-26 16:10:35 +00:00
|
|
|
*
|
input: change license to LGPL
cehoyos adds the step_property command in 7a71da01d, and it could be
argued that copyright of this still applies to the later add/cycle
commands (a668ae0ff90c4). While I'm not sure if this is really the case,
stay conservative for now and mark these commands as GPL-only. Mark the
command.c code too, although that is not being relicensed yet.
I'm leaving the MP_CMD_* enum items, as they are obviously different.
In commit 116ca0c7682, "veal" (essentially an anonymous author) adds an
"osd_show_property_text" command (well, the commit message says "based
on" that person's code, so it's not clear how much is from him or from
albeu, who agreed to LGPL). This was later merged again with the
"osd_show_text" command, and then all original code was removed in
commit 58cc0f637f, so I claim that no copyright applies anymore. (Though
technically the input.conf addition still might be copyrighted, so I'm
just dropping it to get rid of the thought.)
"kiriuja" added 2f376d1b39 (sub_load etc.) and be54f4813 (switch_audio).
The latter is gone. I would argue that the former is fully rewritten
with commits b7052b431c9 and 0f155921b0. But like in the step_property
case, I will be overly conservative for now, and mark them as GPL-only,
as this is potentially shaky and should be thought through first. (Not
bothering with the command define/enum in the header, as it will be
unused in LGPL mode anyway.)
keycodes.c/h can be GPL, except for commit 2b1f95dcc2f8, which is a
patch by someone who wasn't asked yet. Before doing something radical, I
will wait for a reply.
2017-06-19 11:02:35 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-12-26 16:10:35 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2013-12-26 16:10:35 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
input: change license to LGPL
cehoyos adds the step_property command in 7a71da01d, and it could be
argued that copyright of this still applies to the later add/cycle
commands (a668ae0ff90c4). While I'm not sure if this is really the case,
stay conservative for now and mark these commands as GPL-only. Mark the
command.c code too, although that is not being relicensed yet.
I'm leaving the MP_CMD_* enum items, as they are obviously different.
In commit 116ca0c7682, "veal" (essentially an anonymous author) adds an
"osd_show_property_text" command (well, the commit message says "based
on" that person's code, so it's not clear how much is from him or from
albeu, who agreed to LGPL). This was later merged again with the
"osd_show_text" command, and then all original code was removed in
commit 58cc0f637f, so I claim that no copyright applies anymore. (Though
technically the input.conf addition still might be copyrighted, so I'm
just dropping it to get rid of the thought.)
"kiriuja" added 2f376d1b39 (sub_load etc.) and be54f4813 (switch_audio).
The latter is gone. I would argue that the former is fully rewritten
with commits b7052b431c9 and 0f155921b0. But like in the step_property
case, I will be overly conservative for now, and mark them as GPL-only,
as this is potentially shaky and should be thought through first. (Not
bothering with the command define/enum in the header, as it will be
unused in LGPL mode anyway.)
keycodes.c/h can be GPL, except for commit 2b1f95dcc2f8, which is a
patch by someone who wasn't asked yet. Before doing something radical, I
will wait for a reply.
2017-06-19 11:02:35 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-12-26 16:10:35 +00:00
|
|
|
*
|
input: change license to LGPL
cehoyos adds the step_property command in 7a71da01d, and it could be
argued that copyright of this still applies to the later add/cycle
commands (a668ae0ff90c4). While I'm not sure if this is really the case,
stay conservative for now and mark these commands as GPL-only. Mark the
command.c code too, although that is not being relicensed yet.
I'm leaving the MP_CMD_* enum items, as they are obviously different.
In commit 116ca0c7682, "veal" (essentially an anonymous author) adds an
"osd_show_property_text" command (well, the commit message says "based
on" that person's code, so it's not clear how much is from him or from
albeu, who agreed to LGPL). This was later merged again with the
"osd_show_text" command, and then all original code was removed in
commit 58cc0f637f, so I claim that no copyright applies anymore. (Though
technically the input.conf addition still might be copyrighted, so I'm
just dropping it to get rid of the thought.)
"kiriuja" added 2f376d1b39 (sub_load etc.) and be54f4813 (switch_audio).
The latter is gone. I would argue that the former is fully rewritten
with commits b7052b431c9 and 0f155921b0. But like in the step_property
case, I will be overly conservative for now, and mark them as GPL-only,
as this is potentially shaky and should be thought through first. (Not
bothering with the command define/enum in the header, as it will be
unused in LGPL mode anyway.)
keycodes.c/h can be GPL, except for commit 2b1f95dcc2f8, which is a
patch by someone who wasn't asked yet. Before doing something radical, I
will wait for a reply.
2017-06-19 11:02:35 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-26 16:10:35 +00:00
|
|
|
*/
|
2015-04-13 07:36:54 +00:00
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
#ifndef MP_PARSE_COMMAND_H
|
|
|
|
#define MP_PARSE_COMMAND_H
|
|
|
|
|
2018-05-01 01:19:50 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2014-10-10 20:58:28 +00:00
|
|
|
#include "misc/bstr.h"
|
2018-05-01 01:19:50 +00:00
|
|
|
#include "options/m_option.h"
|
|
|
|
|
2022-10-03 18:58:45 +00:00
|
|
|
#define MP_CMD_DEF_MAX_ARGS 11
|
2018-05-17 18:40:53 +00:00
|
|
|
#define MP_CMD_OPT_ARG M_OPT_OPTIONAL_PARAM
|
2014-10-10 20:58:28 +00:00
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
struct mp_log;
|
|
|
|
struct mp_cmd;
|
2014-10-10 20:37:11 +00:00
|
|
|
struct mpv_node;
|
2013-12-26 16:10:35 +00:00
|
|
|
|
2018-05-01 01:19:50 +00:00
|
|
|
struct mp_cmd_def {
|
|
|
|
const char *name; // user-visible name (as used in input.conf)
|
|
|
|
void (*handler)(void *ctx);
|
|
|
|
const struct m_option args[MP_CMD_DEF_MAX_ARGS];
|
|
|
|
const void *priv; // for free use by handler()
|
|
|
|
bool allow_auto_repeat; // react to repeated key events
|
|
|
|
bool on_updown; // always emit it on both up and down key events
|
|
|
|
bool vararg; // last argument can be given 0 to multiple times
|
|
|
|
bool scalable;
|
|
|
|
bool is_ignore;
|
2019-12-19 11:50:10 +00:00
|
|
|
bool is_noisy; // reduce log level
|
2018-05-06 16:27:18 +00:00
|
|
|
bool default_async; // default to MP_ASYNC flag if none set by user
|
|
|
|
// If you set this, handler() must ensure mp_cmd_ctx_complete() is called
|
|
|
|
// at some point (can be after handler() returns). If you don't set it, the
|
|
|
|
// common code will call mp_cmd_ctx_complete() when handler() returns.
|
|
|
|
// You must make sure that the core cannot disappear while you do work. The
|
|
|
|
// common code keeps the core referenced only until handler() returns.
|
|
|
|
bool exec_async;
|
|
|
|
// If set, handler() is run on a separate worker thread. This means you can
|
|
|
|
// use mp_core_[un]lock() to temporarily unlock and re-lock the core (while
|
|
|
|
// unlocked, you have no synchronized access to mpctx, but you can do long
|
|
|
|
// running operations without blocking playback or input handling).
|
|
|
|
bool spawn_thread;
|
2018-05-12 16:46:37 +00:00
|
|
|
// If this is set, mp_cmd_ctx.abort is set. Set this if handler() can do
|
|
|
|
// asynchronous abort of the command, and explicitly uses mp_cmd_ctx.abort.
|
|
|
|
// (Not setting it when it's not needed can save resources.)
|
|
|
|
bool can_abort;
|
player: make various commands for managing external tracks abortable
Until now, they could be aborted only by ending playback, and calling
mpv_abort_async_command didn't do anything.
This requires furthering the mess how playback abort is done. The main
reason why mp_cancel exists at all is to avoid that a "frozen" demuxer
(blocked on network I/O or whatever) cannot freeze the core. The core
should always get its way. Previously, there was a single mp_cancel
handle, that could be signaled, and all demuxers would unfreeze. With
external files, we might want to abort loading of a certain external
file, which automatically means they need a separate mp_cancel. So give
every demuxer its own mp_cancel, and "slave" it to whatever parent
mp_cancel handles aborting.
Since the mpv demuxer API conflates creating the demuxer and reading the
file headers, mp_cancel strictly need to be created before the demuxer
is created (or we couldn't abort loading). Although we give every
demuxer its own mp_cancel (as "enforced" by cancel_and_free_demuxer),
it's still rather messy to create/destroy it along with the demuxer.
2018-05-18 19:38:17 +00:00
|
|
|
// If playback ends, and the command is still running, an abort is
|
|
|
|
// automatically triggered.
|
|
|
|
bool abort_on_playback_end;
|
2018-05-01 01:19:50 +00:00
|
|
|
};
|
|
|
|
|
2018-05-01 01:25:39 +00:00
|
|
|
enum mp_cmd_flags {
|
|
|
|
MP_ON_OSD_NO = 0, // prefer not using OSD
|
|
|
|
MP_ON_OSD_AUTO = 1, // use default behavior of the specific command
|
|
|
|
MP_ON_OSD_BAR = 2, // force a bar, if applicable
|
|
|
|
MP_ON_OSD_MSG = 4, // force a message, if applicable
|
|
|
|
MP_EXPAND_PROPERTIES = 8, // expand strings as properties
|
|
|
|
MP_ALLOW_REPEAT = 16, // if used as keybinding, allow key repeat
|
2018-05-06 16:27:18 +00:00
|
|
|
|
|
|
|
// Exactly one of the following 2 bits is set. Which one is used depends on
|
|
|
|
// the command parser (prefixes and mp_cmd_def.default_async).
|
|
|
|
MP_ASYNC_CMD = 32, // do not wait for command to complete
|
|
|
|
MP_SYNC_CMD = 64, // block on command completion
|
2018-05-01 01:25:39 +00:00
|
|
|
|
2024-05-18 02:32:43 +00:00
|
|
|
MP_DISALLOW_REPEAT = 128, // if used as keybinding, disallow key repeat
|
|
|
|
|
2018-05-01 01:25:39 +00:00
|
|
|
MP_ON_OSD_FLAGS = MP_ON_OSD_NO | MP_ON_OSD_AUTO |
|
|
|
|
MP_ON_OSD_BAR | MP_ON_OSD_MSG,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Arbitrary upper bound for sanity.
|
|
|
|
#define MP_CMD_MAX_ARGS 100
|
|
|
|
|
|
|
|
struct mp_cmd_arg {
|
|
|
|
const struct m_option *type;
|
|
|
|
union {
|
2023-02-20 05:44:22 +00:00
|
|
|
bool b;
|
2018-05-01 01:25:39 +00:00
|
|
|
int i;
|
2018-05-12 13:14:07 +00:00
|
|
|
int64_t i64;
|
2018-05-01 01:25:39 +00:00
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
char *s;
|
|
|
|
char **str_list;
|
|
|
|
void *p;
|
|
|
|
} v;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct mp_cmd {
|
|
|
|
char *name;
|
|
|
|
struct mp_cmd_arg *args;
|
|
|
|
int nargs;
|
|
|
|
int flags; // mp_cmd_flags bitfield
|
2019-11-22 17:21:33 +00:00
|
|
|
char *original;
|
2019-11-23 00:09:09 +00:00
|
|
|
char *desc; // (usually NULL since stripped away later)
|
2024-08-03 08:27:22 +00:00
|
|
|
bstr input_section;
|
2018-05-01 01:25:39 +00:00
|
|
|
bool is_up_down : 1;
|
|
|
|
bool is_up : 1;
|
|
|
|
bool emit_on_up : 1;
|
|
|
|
bool is_mouse_button : 1;
|
|
|
|
bool repeated : 1;
|
|
|
|
bool mouse_move : 1;
|
2024-06-06 04:35:37 +00:00
|
|
|
bool canceled : 1;
|
2018-05-01 01:25:39 +00:00
|
|
|
int mouse_x, mouse_y;
|
|
|
|
struct mp_cmd *queue_next;
|
|
|
|
double scale; // for scaling numeric arguments
|
|
|
|
int scale_units;
|
|
|
|
const struct mp_cmd_def *def;
|
|
|
|
char *sender; // name of the client API user which sent this
|
|
|
|
char *key_name; // string representation of the key binding
|
2019-11-21 22:01:56 +00:00
|
|
|
char *key_text; // text if key is a text key
|
2018-05-01 01:25:39 +00:00
|
|
|
} mp_cmd_t;
|
|
|
|
|
2018-05-01 01:19:50 +00:00
|
|
|
extern const struct mp_cmd_def mp_cmds[];
|
2018-04-30 18:33:05 +00:00
|
|
|
extern const struct mp_cmd_def mp_cmd_list;
|
|
|
|
|
2018-05-01 01:19:50 +00:00
|
|
|
bool mp_input_is_repeatable_cmd(struct mp_cmd *cmd);
|
|
|
|
|
|
|
|
bool mp_input_is_scalable_cmd(struct mp_cmd *cmd);
|
|
|
|
|
|
|
|
void mp_print_cmd_list(struct mp_log *out);
|
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
// Parse text and return corresponding struct mp_cmd.
|
|
|
|
// The location parameter is for error messages.
|
2018-05-01 01:36:39 +00:00
|
|
|
struct mp_cmd *mp_input_parse_cmd_str(struct mp_log *log, bstr str,
|
|
|
|
const char *loc);
|
2013-12-26 16:10:35 +00:00
|
|
|
|
|
|
|
// Similar to mp_input_parse_cmd(), but takes a list of strings instead.
|
2014-10-10 20:58:28 +00:00
|
|
|
// Also, MP_ON_OSD_AUTO | MP_EXPAND_PROPERTIES are not set by default.
|
2013-12-26 16:10:35 +00:00
|
|
|
// Keep in mind that these functions (naturally) don't take multiple commands,
|
|
|
|
// i.e. a ";" argument does not start a new command.
|
2014-10-10 20:58:28 +00:00
|
|
|
struct mp_cmd *mp_input_parse_cmd_strv(struct mp_log *log, const char **argv);
|
|
|
|
|
2014-10-10 20:37:11 +00:00
|
|
|
struct mp_cmd *mp_input_parse_cmd_node(struct mp_log *log, struct mpv_node *node);
|
2013-12-26 16:10:35 +00:00
|
|
|
|
|
|
|
// After getting a command from mp_input_get_cmd you need to free it using this
|
|
|
|
// function
|
|
|
|
void mp_cmd_free(struct mp_cmd *cmd);
|
|
|
|
|
2014-10-23 12:40:38 +00:00
|
|
|
void mp_cmd_dump(struct mp_log *log, int msgl, char *header, struct mp_cmd *cmd);
|
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
// This creates a copy of a command (used by the auto repeat stuff).
|
|
|
|
struct mp_cmd *mp_cmd_clone(struct mp_cmd *cmd);
|
|
|
|
|
|
|
|
#endif
|