1 /* 2 * This file is part of mpv. 3 * 4 * mpv is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * mpv is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with mpv. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef MPLAYER_COMMAND_H 19 #define MPLAYER_COMMAND_H 20 21 #include <stdbool.h> 22 23 #include "libmpv/client.h" 24 25 struct MPContext; 26 struct mp_cmd; 27 struct mp_log; 28 struct mpv_node; 29 struct m_config_option; 30 31 void command_init(struct MPContext *mpctx); 32 void command_uninit(struct MPContext *mpctx); 33 34 // Runtime context for a single command. 35 struct mp_cmd_ctx { 36 struct MPContext *mpctx; 37 struct mp_cmd *cmd; // original command 38 // Fields from cmd (for convenience) 39 struct mp_cmd_arg *args; 40 int num_args; 41 const void *priv; // cmd->def->priv 42 // OSD control 43 int on_osd; // MP_ON_OSD_FLAGS; 44 bool msg_osd; // OSD message requested 45 bool bar_osd; // OSD bar requested 46 bool seek_msg_osd; // same as above, but for seek commands 47 bool seek_bar_osd; 48 // If mp_cmd_def.can_abort is set, this will be set. 49 struct mp_abort_entry *abort; 50 // Return values (to be set by command implementation, read by the 51 // completion callback). 52 bool success; // true by default 53 struct mpv_node result; 54 // Command handlers can set this to false if returning from the command 55 // handler does not complete the command. It stops the common command code 56 // from signaling the completion automatically, and you can call 57 // mp_cmd_ctx_complete() to invoke on_completion() properly (including all 58 // the bookkeeping). 59 /// (Note that in no case you can call mp_cmd_ctx_complete() from within 60 // the command handler, because it frees the mp_cmd_ctx.) 61 bool completed; // true by default 62 // This is managed by the common command code. For rules about how and where 63 // this is called see run_command() comments. 64 void (*on_completion)(struct mp_cmd_ctx *cmd); 65 void *on_completion_priv; // for free use by on_completion callback 66 }; 67 68 void run_command(struct MPContext *mpctx, struct mp_cmd *cmd, 69 struct mp_abort_entry *abort, 70 void (*on_completion)(struct mp_cmd_ctx *cmd), 71 void *on_completion_priv); 72 void mp_cmd_ctx_complete(struct mp_cmd_ctx *cmd); 73 PRINTF_ATTRIBUTE(3, 4) 74 void mp_cmd_msg(struct mp_cmd_ctx *cmd, int status, const char *msg, ...); 75 char *mp_property_expand_string(struct MPContext *mpctx, const char *str); 76 char *mp_property_expand_escaped_string(struct MPContext *mpctx, const char *str); 77 void property_print_help(struct MPContext *mpctx); 78 int mp_property_do(const char* name, int action, void* val, 79 struct MPContext *mpctx); 80 81 void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, 82 bool self_update); 83 84 void mp_notify(struct MPContext *mpctx, int event, void *arg); 85 void mp_notify_property(struct MPContext *mpctx, const char *property); 86 87 void handle_command_updates(struct MPContext *mpctx); 88 89 int mp_get_property_id(struct MPContext *mpctx, const char *name); 90 uint64_t mp_get_property_event_mask(const char *name); 91 92 enum { 93 // Must start with the first unused positive value in enum mpv_event_id 94 // MPV_EVENT_* and MP_EVENT_* must not overlap. 95 INTERNAL_EVENT_BASE = 26, 96 MP_EVENT_CHANGE_ALL, 97 MP_EVENT_CACHE_UPDATE, 98 MP_EVENT_WIN_RESIZE, 99 MP_EVENT_WIN_STATE, 100 MP_EVENT_WIN_STATE2, 101 MP_EVENT_FOCUS, 102 MP_EVENT_CHANGE_PLAYLIST, 103 MP_EVENT_CORE_IDLE, 104 MP_EVENT_DURATION_UPDATE, 105 MP_EVENT_INPUT_PROCESSED, 106 }; 107 108 bool mp_hook_test_completion(struct MPContext *mpctx, char *type); 109 void mp_hook_start(struct MPContext *mpctx, char *type); 110 int mp_hook_continue(struct MPContext *mpctx, int64_t client_id, uint64_t id); 111 void mp_hook_add(struct MPContext *mpctx, char *client, int64_t client_id, 112 const char *name, uint64_t user_id, int pri); 113 114 void mark_seek(struct MPContext *mpctx); 115 116 void mp_abort_cache_dumping(struct MPContext *mpctx); 117 118 #endif /* MPLAYER_COMMAND_H */ 119