vendetta / libvendetta / mpv / android / include / mpv / client.h
2033 lines · 1954 sloc · 84.12 KB · 77754ad9e6dc749afefba326ff89abc5ddd8c9c9
Raw
1/* Copyright (C) 2017 the mpv developers
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 */
15
16/*
17 * Note: the client API is licensed under ISC (see above) to enable
18 * other wrappers outside of mpv. But keep in mind that the
19 * mpv core is by default still GPLv2+ - unless built with
20 * -Dgpl=false, which makes it LGPLv2+.
21 */
22
23#ifndef MPV_CLIENT_API_H_
24#define MPV_CLIENT_API_H_
25
26#include <stddef.h>
27#include <stdint.h>
28
29#ifdef _WIN32
30#define MPV_EXPORT __declspec(dllexport)
31#define MPV_SELECTANY __declspec(selectany)
32#elif defined(__GNUC__) || defined(__clang__)
33#define MPV_EXPORT __attribute__((visibility("default")))
34#define MPV_SELECTANY
35#else
36#define MPV_EXPORT
37#define MPV_SELECTANY
38#endif
39
40#ifdef __cpp_decltype
41#define MPV_DECLTYPE decltype
42#else
43#define MPV_DECLTYPE __typeof__
44#endif
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
51 * Mechanisms provided by this API
52 * -------------------------------
53 *
54 * This API provides general control over mpv playback. It does not give you
55 * direct access to individual components of the player, only the whole thing.
56 * It's somewhat equivalent to MPlayer's slave mode. You can send commands,
57 * retrieve or set playback status or settings with properties, and receive
58 * events.
59 *
60 * The API can be used in two ways:
61 * 1) Internally in mpv, to provide additional features to the command line
62 * player. Lua scripting uses this. (Currently there is no plugin API to
63 * get a client API handle in external user code. It has to be a fixed
64 * part of the player at compilation time.)
65 * 2) Using mpv as a library with mpv_create(). This basically allows embedding
66 * mpv in other applications.
67 *
68 * Documentation
69 * -------------
70 *
71 * The libmpv C API is documented directly in this header. Note that most
72 * actual interaction with this player is done through
73 * options/commands/properties, which can be accessed through this API.
74 * Essentially everything is done with them, including loading a file,
75 * retrieving playback progress, and so on.
76 *
77 * These are documented elsewhere:
78 * * http://mpv.io/manual/master/#options
79 * * http://mpv.io/manual/master/#list-of-input-commands
80 * * http://mpv.io/manual/master/#properties
81 *
82 * You can also look at the examples here:
83 * * https://github.com/mpv-player/mpv-examples/tree/master/libmpv
84 *
85 * Event loop
86 * ----------
87 *
88 * In general, the API user should run an event loop in order to receive events.
89 * This event loop should call mpv_wait_event(), which will return once a new
90 * mpv client API is available. It is also possible to integrate client API
91 * usage in other event loops (e.g. GUI toolkits) with the
92 * mpv_set_wakeup_callback() function, and then polling for events by calling
93 * mpv_wait_event() with a 0 timeout.
94 *
95 * Note that the event loop is detached from the actual player. Not calling
96 * mpv_wait_event() will not stop playback. It will eventually congest the
97 * event queue of your API handle, though.
98 *
99 * Synchronous vs. asynchronous calls
100 * ----------------------------------
101 *
102 * The API allows both synchronous and asynchronous calls. Synchronous calls
103 * have to wait until the playback core is ready, which currently can take
104 * an unbounded time (e.g. if network is slow or unresponsive). Asynchronous
105 * calls just queue operations as requests, and return the result of the
106 * operation as events.
107 *
108 * Asynchronous calls
109 * ------------------
110 *
111 * The client API includes asynchronous functions. These allow you to send
112 * requests instantly, and get replies as events at a later point. The
113 * requests are made with functions carrying the _async suffix, and replies
114 * are returned by mpv_wait_event() (interleaved with the normal event stream).
115 *
116 * A 64 bit userdata value is used to allow the user to associate requests
117 * with replies. The value is passed as reply_userdata parameter to the request
118 * function. The reply to the request will have the reply
119 * mpv_event->reply_userdata field set to the same value as the
120 * reply_userdata parameter of the corresponding request.
121 *
122 * This userdata value is arbitrary and is never interpreted by the API. Note
123 * that the userdata value 0 is also allowed, but then the client must be
124 * careful not accidentally interpret the mpv_event->reply_userdata if an
125 * event is not a reply. (For non-replies, this field is set to 0.)
126 *
127 * Asynchronous calls may be reordered in arbitrarily with other synchronous
128 * and asynchronous calls. If you want a guaranteed order, you need to wait
129 * until asynchronous calls report completion before doing the next call.
130 *
131 * See also the section "Asynchronous command details" in the manpage.
132 *
133 * Multithreading
134 * --------------
135 *
136 * The client API is generally fully thread-safe, unless otherwise noted.
137 * Currently, there is no real advantage in using more than 1 thread to access
138 * the client API, since everything is serialized through a single lock in the
139 * playback core.
140 *
141 * Basic environment requirements
142 * ------------------------------
143 *
144 * This documents basic requirements on the C environment. This is especially
145 * important if mpv is used as library with mpv_create().
146 *
147 * - The LC_NUMERIC locale category must be set to "C". If your program calls
148 * setlocale(), be sure not to use LC_ALL, or if you do, reset LC_NUMERIC
149 * to its sane default: setlocale(LC_NUMERIC, "C").
150 * - If a X11 based VO is used, mpv will set the xlib error handler. This error
151 * handler is process-wide, and there's no proper way to share it with other
152 * xlib users within the same process. This might confuse GUI toolkits.
153 * - mpv uses some other libraries that are not library-safe, such as Fribidi
154 * (used through libass), ALSA, FFmpeg, and possibly more.
155 * - The FPU precision must be set at least to double precision.
156 * - On Windows, mpv will call timeBeginPeriod(1).
157 * - On memory exhaustion, mpv will kill the process.
158 * - In certain cases, mpv may start sub processes (such as with the ytdl
159 * wrapper script).
160 * - Using UNIX IPC (off by default) will override the SIGPIPE signal handler,
161 * and set it to SIG_IGN. Some invocations of the "subprocess" command will
162 * also do that.
163 * - mpv may start sub processes, so overriding SIGCHLD, or waiting on all PIDs
164 * (such as calling wait()) by the parent process or any other library within
165 * the process must be avoided. libmpv itself only waits for its own PIDs.
166 * - If anything in the process registers signal handlers, they must set the
167 * SA_RESTART flag. Otherwise you WILL get random failures on signals.
168 *
169 * Encoding of filenames
170 * ---------------------
171 *
172 * mpv uses UTF-8 everywhere.
173 *
174 * On some platforms (like Linux), filenames actually do not have to be UTF-8;
175 * for this reason libmpv supports non-UTF-8 strings. libmpv uses what the
176 * kernel uses and does not recode filenames. At least on Linux, passing a
177 * string to libmpv is like passing a string to the fopen() function.
178 *
179 * On Windows, filenames are always UTF-8, libmpv converts between UTF-8 and
180 * UTF-16 when using win32 API functions. libmpv never uses or accepts
181 * filenames in the local 8 bit encoding. It does not use fopen() either;
182 * it uses _wfopen().
183 *
184 * On macOS, filenames and other strings taken/returned by libmpv can have
185 * inconsistent unicode normalization. This can sometimes lead to problems.
186 * You have to hope for the best.
187 *
188 * Also see the remarks for MPV_FORMAT_STRING.
189 *
190 * Embedding the video window
191 * --------------------------
192 *
193 * Using the render API (in render.h) is recommended. This API requires
194 * you to create and maintain an OpenGL context, to which you can render
195 * video using a specific API call. This API does not include keyboard or mouse
196 * input directly.
197 *
198 * There is an older way to embed the native mpv window into your own. You have
199 * to get the raw window handle, and set it as "wid" option. This works on X11,
200 * win32, and macOS only. It's much easier to use than the render API, but
201 * also has various problems.
202 *
203 * Also see client API examples and the mpv manpage. There is an extensive
204 * discussion here:
205 * https://github.com/mpv-player/mpv-examples/tree/master/libmpv#methods-of-embedding-the-video-window
206 *
207 * Compatibility
208 * -------------
209 *
210 * mpv development doesn't stand still, and changes to mpv internals as well as
211 * to its interface can cause compatibility issues to client API users.
212 *
213 * The API is versioned (see MPV_CLIENT_API_VERSION), and changes to it are
214 * documented in DOCS/client-api-changes.rst. The C API itself will probably
215 * remain compatible for a long time, but the functionality exposed by it
216 * could change more rapidly. For example, it's possible that options are
217 * renamed, or change the set of allowed values.
218 *
219 * Defensive programming should be used to potentially deal with the fact that
220 * options, commands, and properties could disappear, change their value range,
221 * or change the underlying datatypes. It might be a good idea to prefer
222 * MPV_FORMAT_STRING over other types to decouple your code from potential
223 * mpv changes.
224 *
225 * Also see: DOCS/compatibility.rst
226 *
227 * Future changes
228 * --------------
229 *
230 * This are the planned changes that will most likely be done on the next major
231 * bump of the library:
232 *
233 * - remove all symbols that are marked as deprecated
234 * - reassign enum numerical values to remove gaps
235 * - disabling all events by default
236 */
237
238/**
239 * The version is incremented on each API change. The 16 lower bits form the
240 * minor version number, and the 16 higher bits the major version number. If
241 * the API becomes incompatible to previous versions, the major version
242 * number is incremented. This affects only C part, and not properties and
243 * options.
244 *
245 * Every API bump is described in DOCS/client-api-changes.rst
246 *
247 * You can use MPV_MAKE_VERSION() and compare the result with integer
248 * relational operators (<, >, <=, >=).
249 */
250#define MPV_MAKE_VERSION(major, minor) (((major) << 16) | (minor) | 0UL)
251#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(2, 6)
252
253/**
254 * The API user is allowed to "#define MPV_ENABLE_DEPRECATED 0" before
255 * including any libmpv headers. Then deprecated symbols will be excluded
256 * from the headers. (Of course, deprecated properties and commands and
257 * other functionality will still work.)
258 */
259#ifndef MPV_ENABLE_DEPRECATED
260#define MPV_ENABLE_DEPRECATED 1
261#endif
262
263/**
264 * Return the MPV_CLIENT_API_VERSION the mpv source has been compiled with.
265 */
266MPV_EXPORT unsigned long mpv_client_api_version(void);
267
268/**
269 * Client context used by the client API. Every client has its own private
270 * handle.
271 */
272typedef struct mpv_handle mpv_handle;
273
274/**
275 * List of error codes than can be returned by API functions. 0 and positive
276 * return values always mean success, negative values are always errors.
277 */
278typedef enum mpv_error {
279 /**
280 * No error happened (used to signal successful operation).
281 * Keep in mind that many API functions returning error codes can also
282 * return positive values, which also indicate success. API users can
283 * hardcode the fact that ">= 0" means success.
284 */
285 MPV_ERROR_SUCCESS = 0,
286 /**
287 * The event ringbuffer is full. This means the client is choked, and can't
288 * receive any events. This can happen when too many asynchronous requests
289 * have been made, but not answered. Probably never happens in practice,
290 * unless the mpv core is frozen for some reason, and the client keeps
291 * making asynchronous requests. (Bugs in the client API implementation
292 * could also trigger this, e.g. if events become "lost".)
293 */
294 MPV_ERROR_EVENT_QUEUE_FULL = -1,
295 /**
296 * Memory allocation failed.
297 */
298 MPV_ERROR_NOMEM = -2,
299 /**
300 * The mpv core wasn't configured and initialized yet. See the notes in
301 * mpv_create().
302 */
303 MPV_ERROR_UNINITIALIZED = -3,
304 /**
305 * Generic catch-all error if a parameter is set to an invalid or
306 * unsupported value. This is used if there is no better error code.
307 */
308 MPV_ERROR_INVALID_PARAMETER = -4,
309 /**
310 * Trying to set an option that doesn't exist.
311 */
312 MPV_ERROR_OPTION_NOT_FOUND = -5,
313 /**
314 * Trying to set an option using an unsupported MPV_FORMAT.
315 */
316 MPV_ERROR_OPTION_FORMAT = -6,
317 /**
318 * Setting the option failed. Typically this happens if the provided option
319 * value could not be parsed.
320 */
321 MPV_ERROR_OPTION_ERROR = -7,
322 /**
323 * The accessed property doesn't exist.
324 */
325 MPV_ERROR_PROPERTY_NOT_FOUND = -8,
326 /**
327 * Trying to set or get a property using an unsupported MPV_FORMAT.
328 */
329 MPV_ERROR_PROPERTY_FORMAT = -9,
330 /**
331 * The property exists, but is not available. This usually happens when the
332 * associated subsystem is not active, e.g. querying audio parameters while
333 * audio is disabled.
334 */
335 MPV_ERROR_PROPERTY_UNAVAILABLE = -10,
336 /**
337 * Error setting or getting a property.
338 */
339 MPV_ERROR_PROPERTY_ERROR = -11,
340 /**
341 * General error when running a command with mpv_command and similar.
342 */
343 MPV_ERROR_COMMAND = -12,
344 /**
345 * Generic error on loading (usually used with mpv_event_end_file.error).
346 */
347 MPV_ERROR_LOADING_FAILED = -13,
348 /**
349 * Initializing the audio output failed.
350 */
351 MPV_ERROR_AO_INIT_FAILED = -14,
352 /**
353 * Initializing the video output failed.
354 */
355 MPV_ERROR_VO_INIT_FAILED = -15,
356 /**
357 * There was no audio or video data to play. This also happens if the
358 * file was recognized, but did not contain any audio or video streams,
359 * or no streams were selected.
360 */
361 MPV_ERROR_NOTHING_TO_PLAY = -16,
362 /**
363 * When trying to load the file, the file format could not be determined,
364 * or the file was too broken to open it.
365 */
366 MPV_ERROR_UNKNOWN_FORMAT = -17,
367 /**
368 * Generic error for signaling that certain system requirements are not
369 * fulfilled.
370 */
371 MPV_ERROR_UNSUPPORTED = -18,
372 /**
373 * The API function which was called is a stub only.
374 */
375 MPV_ERROR_NOT_IMPLEMENTED = -19,
376 /**
377 * Unspecified error.
378 */
379 MPV_ERROR_GENERIC = -20
380} mpv_error;
381
382/**
383 * Return a string describing the error. For unknown errors, the string
384 * "unknown error" is returned.
385 *
386 * @param error error number, see enum mpv_error
387 * @return A static string describing the error. The string is completely
388 * static, i.e. doesn't need to be deallocated, and is valid forever.
389 */
390MPV_EXPORT const char *mpv_error_string(int error);
391
392/**
393 * General function to deallocate memory returned by some of the API functions.
394 * Call this only if it's explicitly documented as allowed. Calling this on
395 * mpv memory not owned by the caller will lead to undefined behavior.
396 *
397 * @param data A valid pointer returned by the API, or NULL.
398 */
399MPV_EXPORT void mpv_free(void *data);
400
401/**
402 * Return the name of this client handle. Every client has its own unique
403 * name, which is mostly used for user interface purposes.
404 *
405 * @return The client name. The string is read-only and is valid until the
406 * mpv_handle is destroyed.
407 */
408MPV_EXPORT const char *mpv_client_name(mpv_handle *ctx);
409
410/**
411 * Return the ID of this client handle. Every client has its own unique ID. This
412 * ID is never reused by the core, even if the mpv_handle at hand gets destroyed
413 * and new handles get allocated.
414 *
415 * IDs are never 0 or negative.
416 *
417 * Some mpv APIs (not necessarily all) accept a name in the form "@<id>" in
418 * addition of the proper mpv_client_name(), where "<id>" is the ID in decimal
419 * form (e.g. "@123"). For example, the "script-message-to" command takes the
420 * client name as first argument, but also accepts the client ID formatted in
421 * this manner.
422 *
423 * @return The client ID.
424 */
425MPV_EXPORT int64_t mpv_client_id(mpv_handle *ctx);
426
427/**
428 * Create a new mpv instance and an associated client API handle to control
429 * the mpv instance. This instance is in a pre-initialized state,
430 * and needs to be initialized to be actually used with most other API
431 * functions.
432 *
433 * Some API functions will return MPV_ERROR_UNINITIALIZED in the uninitialized
434 * state. You can call mpv_set_property() (or mpv_set_property_string() and
435 * other variants, and before mpv 0.21.0 mpv_set_option() etc.) to set initial
436 * options. After this, call mpv_initialize() to start the player, and then use
437 * e.g. mpv_command() to start playback of a file.
438 *
439 * The point of separating handle creation and actual initialization is that
440 * you can configure things which can't be changed during runtime.
441 *
442 * Unlike the command line player, this will have initial settings suitable
443 * for embedding in applications. The following settings are different:
444 * - stdin/stdout/stderr and the terminal will never be accessed. This is
445 * equivalent to setting the --no-terminal option.
446 * (Technically, this also suppresses C signal handling.)
447 * - No config files will be loaded. This is roughly equivalent to using
448 * --config=no. Since libmpv 1.15, you can actually re-enable this option,
449 * which will make libmpv load config files during mpv_initialize(). If you
450 * do this, you are strongly encouraged to set the "config-dir" option too.
451 * (Otherwise it will load the mpv command line player's config.)
452 * For example:
453 * mpv_set_option_string(mpv, "config-dir", "/my/path"); // set config root
454 * mpv_set_option_string(mpv, "config", "yes"); // enable config loading
455 * (call mpv_initialize() _after_ this)
456 * - Idle mode is enabled, which means the playback core will enter idle mode
457 * if there are no more files to play on the internal playlist, instead of
458 * exiting. This is equivalent to the --idle option.
459 * - Disable parts of input handling.
460 * - Most of the different settings can be viewed with the command line player
461 * by running "mpv --show-profile=libmpv".
462 *
463 * All this assumes that API users want a mpv instance that is strictly
464 * isolated from the command line player's configuration, user settings, and
465 * so on. You can re-enable disabled features by setting the appropriate
466 * options.
467 *
468 * The mpv command line parser is not available through this API, but you can
469 * set individual options with mpv_set_property(). Files for playback must be
470 * loaded with mpv_command() or others.
471 *
472 * Note that you should avoid doing concurrent accesses on the uninitialized
473 * client handle. (Whether concurrent access is definitely allowed or not has
474 * yet to be decided.)
475 *
476 * @return a new mpv client API handle. Returns NULL on error. Currently, this
477 * can happen in the following situations:
478 * - out of memory
479 * - LC_NUMERIC is not set to "C" (see general remarks)
480 */
481MPV_EXPORT mpv_handle *mpv_create(void);
482
483/**
484 * Initialize an uninitialized mpv instance. If the mpv instance is already
485 * running, an error is returned.
486 *
487 * This function needs to be called to make full use of the client API if the
488 * client API handle was created with mpv_create().
489 *
490 * Only the following options are required to be set _before_ mpv_initialize():
491 * - options which are only read at initialization time:
492 * - config
493 * - config-dir
494 * - input-conf
495 * - load-scripts
496 * - script
497 * - player-operation-mode
498 * - input-app-events (macOS)
499 * - all encoding mode options
500 *
501 * @return error code
502 */
503MPV_EXPORT int mpv_initialize(mpv_handle *ctx);
504
505/**
506 * Disconnect and destroy the mpv_handle. ctx will be deallocated with this
507 * API call.
508 *
509 * If the last mpv_handle is detached, the core player is destroyed. In
510 * addition, if there are only weak mpv_handles (such as created by
511 * mpv_create_weak_client() or internal scripts), these mpv_handles will
512 * be sent MPV_EVENT_SHUTDOWN. This function may block until these clients
513 * have responded to the shutdown event, and the core is finally destroyed.
514 */
515MPV_EXPORT void mpv_destroy(mpv_handle *ctx);
516
517/**
518 * Similar to mpv_destroy(), but brings the player and all clients down
519 * as well, and waits until all of them are destroyed. This function blocks. The
520 * advantage over mpv_destroy() is that while mpv_destroy() merely
521 * detaches the client handle from the player, this function quits the player,
522 * waits until all other clients are destroyed (i.e. all mpv_handles are
523 * detached), and also waits for the final termination of the player.
524 *
525 * Since mpv_destroy() is called somewhere on the way, it's not safe to
526 * call other functions concurrently on the same context.
527 *
528 * Since mpv client API version 1.29:
529 * The first call on any mpv_handle will block until the core is destroyed.
530 * This means it will wait until other mpv_handle have been destroyed. If you
531 * want asynchronous destruction, just run the "quit" command, and then react
532 * to the MPV_EVENT_SHUTDOWN event.
533 * If another mpv_handle already called mpv_terminate_destroy(), this call will
534 * not actually block. It will destroy the mpv_handle, and exit immediately,
535 * while other mpv_handles might still be uninitializing.
536 *
537 * Before mpv client API version 1.29:
538 * If this is called on a mpv_handle that was not created with mpv_create(),
539 * this function will merely send a quit command and then call
540 * mpv_destroy(), without waiting for the actual shutdown.
541 */
542MPV_EXPORT void mpv_terminate_destroy(mpv_handle *ctx);
543
544/**
545 * Create a new client handle connected to the same player core as ctx. This
546 * context has its own event queue, its own mpv_request_event() state, its own
547 * mpv_request_log_messages() state, its own set of observed properties, and
548 * its own state for asynchronous operations. Otherwise, everything is shared.
549 *
550 * This handle should be destroyed with mpv_destroy() if no longer
551 * needed. The core will live as long as there is at least 1 handle referencing
552 * it. Any handle can make the core quit, which will result in every handle
553 * receiving MPV_EVENT_SHUTDOWN.
554 *
555 * This function can not be called before the main handle was initialized with
556 * mpv_initialize(). The new handle is always initialized, unless ctx=NULL was
557 * passed.
558 *
559 * @param ctx Used to get the reference to the mpv core; handle-specific
560 * settings and parameters are not used.
561 * If NULL, this function behaves like mpv_create() (ignores name).
562 * @param name The client name. This will be returned by mpv_client_name(). If
563 * the name is already in use, or contains non-alphanumeric
564 * characters (other than '_'), the name is modified to fit.
565 * If NULL, an arbitrary name is automatically chosen.
566 * @return a new handle, or NULL on error
567 */
568MPV_EXPORT mpv_handle *mpv_create_client(mpv_handle *ctx, const char *name);
569
570/**
571 * This is the same as mpv_create_client(), but the created mpv_handle is
572 * treated as a weak reference. If all mpv_handles referencing a core are
573 * weak references, the core is automatically destroyed. (This still goes
574 * through normal uninit of course. Effectively, if the last non-weak mpv_handle
575 * is destroyed, then the weak mpv_handles receive MPV_EVENT_SHUTDOWN and are
576 * asked to terminate as well.)
577 *
578 * Note if you want to use this like refcounting: you have to be aware that
579 * mpv_terminate_destroy() _and_ mpv_destroy() for the last non-weak
580 * mpv_handle will block until all weak mpv_handles are destroyed.
581 */
582MPV_EXPORT mpv_handle *mpv_create_weak_client(mpv_handle *ctx, const char *name);
583
584/**
585 * Load a config file. This loads and parses the file, and sets every entry in
586 * the config file's default section as if mpv_set_option_string() is called.
587 *
588 * The filename should be an absolute path. If it isn't, the actual path used
589 * is unspecified. (Note: an absolute path starts with '/' on UNIX.) If the
590 * file wasn't found, MPV_ERROR_INVALID_PARAMETER is returned.
591 *
592 * If a fatal error happens when parsing a config file, MPV_ERROR_OPTION_ERROR
593 * is returned. Errors when setting options as well as other types or errors
594 * are ignored (even if options do not exist). You can still try to capture
595 * the resulting error messages with mpv_request_log_messages(). Note that it's
596 * possible that some options were successfully set even if any of these errors
597 * happen.
598 *
599 * @param filename absolute path to the config file on the local filesystem
600 * @return error code
601 */
602MPV_EXPORT int mpv_load_config_file(mpv_handle *ctx, const char *filename);
603
604/**
605 * Return the internal time in nanoseconds. This has an arbitrary start offset,
606 * but will never wrap or go backwards.
607 *
608 * Note that this is always the real time, and doesn't necessarily have to do
609 * with playback time. For example, playback could go faster or slower due to
610 * playback speed, or due to playback being paused. Use the "time-pos" property
611 * instead to get the playback status.
612 *
613 * Unlike other libmpv APIs, this can be called at absolutely any time (even
614 * within wakeup callbacks), as long as the context is valid.
615 *
616 * Safe to be called from mpv render API threads.
617 */
618MPV_EXPORT int64_t mpv_get_time_ns(mpv_handle *ctx);
619
620/**
621 * Same as mpv_get_time_ns but in microseconds.
622 */
623MPV_EXPORT int64_t mpv_get_time_us(mpv_handle *ctx);
624
625/**
626 * Data format for options and properties. The API functions to get/set
627 * properties and options support multiple formats, and this enum describes
628 * them.
629 */
630typedef enum mpv_format {
631 /**
632 * Invalid. Sometimes used for empty values. This is always defined to 0,
633 * so a normal 0-init of mpv_format (or e.g. mpv_node) is guaranteed to set
634 * this it to MPV_FORMAT_NONE (which makes some things saner as consequence).
635 */
636 MPV_FORMAT_NONE = 0,
637 /**
638 * The basic type is char*. It returns the raw property string, like
639 * using ${=property} in input.conf (see input.rst).
640 *
641 * NULL isn't an allowed value.
642 *
643 * Warning: although the encoding is usually UTF-8, this is not always the
644 * case. File tags often store strings in some legacy codepage,
645 * and even filenames don't necessarily have to be in UTF-8 (at
646 * least on Linux). If you pass the strings to code that requires
647 * valid UTF-8, you have to sanitize it in some way.
648 * On Windows, filenames are always UTF-8, and libmpv converts
649 * between UTF-8 and UTF-16 when using win32 API functions. See
650 * the "Encoding of filenames" section for details.
651 *
652 * Example for reading:
653 *
654 * char *result = NULL;
655 * if (mpv_get_property(ctx, "property", MPV_FORMAT_STRING, &result) < 0)
656 * goto error;
657 * printf("%s\n", result);
658 * mpv_free(result);
659 *
660 * Or just use mpv_get_property_string().
661 *
662 * Example for writing:
663 *
664 * char *value = "the new value";
665 * // yep, you pass the address to the variable
666 * // (needed for symmetry with other types and mpv_get_property)
667 * mpv_set_property(ctx, "property", MPV_FORMAT_STRING, &value);
668 *
669 * Or just use mpv_set_property_string().
670 *
671 */
672 MPV_FORMAT_STRING = 1,
673 /**
674 * The basic type is char*. It returns the OSD property string, like
675 * using ${property} in input.conf (see input.rst). In many cases, this
676 * is the same as the raw string, but in other cases it's formatted for
677 * display on OSD. It's intended to be human readable. Do not attempt to
678 * parse these strings.
679 *
680 * Only valid when doing read access. The rest works like MPV_FORMAT_STRING.
681 */
682 MPV_FORMAT_OSD_STRING = 2,
683 /**
684 * The basic type is int. The only allowed values are 0 ("no")
685 * and 1 ("yes").
686 *
687 * Example for reading:
688 *
689 * int result;
690 * if (mpv_get_property(ctx, "property", MPV_FORMAT_FLAG, &result) < 0)
691 * goto error;
692 * printf("%s\n", result ? "true" : "false");
693 *
694 * Example for writing:
695 *
696 * int flag = 1;
697 * mpv_set_property(ctx, "property", MPV_FORMAT_FLAG, &flag);
698 */
699 MPV_FORMAT_FLAG = 3,
700 /**
701 * The basic type is int64_t.
702 */
703 MPV_FORMAT_INT64 = 4,
704 /**
705 * The basic type is double.
706 */
707 MPV_FORMAT_DOUBLE = 5,
708 /**
709 * The type is mpv_node.
710 *
711 * For reading, you usually would pass a pointer to a stack-allocated
712 * mpv_node value to mpv, and when you're done you call
713 * mpv_free_node_contents(&node).
714 * You're expected not to write to the data - if you have to, copy it
715 * first (which you have to do manually).
716 *
717 * For writing, you construct your own mpv_node, and pass a pointer to the
718 * API. The API will never write to your data (and copy it if needed), so
719 * you're free to use any form of allocation or memory management you like.
720 *
721 * Warning: when reading, always check the mpv_node.format member. For
722 * example, properties might change their type in future versions
723 * of mpv, or sometimes even during runtime.
724 *
725 * Example for reading:
726 *
727 * mpv_node result;
728 * if (mpv_get_property(ctx, "property", MPV_FORMAT_NODE, &result) < 0)
729 * goto error;
730 * printf("format=%d\n", (int)result.format);
731 * mpv_free_node_contents(&result).
732 *
733 * Example for writing:
734 *
735 * mpv_node value;
736 * value.format = MPV_FORMAT_STRING;
737 * value.u.string = "hello";
738 * mpv_set_property(ctx, "property", MPV_FORMAT_NODE, &value);
739 */
740 MPV_FORMAT_NODE = 6,
741 /**
742 * Used with mpv_node only. Can usually not be used directly.
743 */
744 MPV_FORMAT_NODE_ARRAY = 7,
745 /**
746 * See MPV_FORMAT_NODE_ARRAY.
747 */
748 MPV_FORMAT_NODE_MAP = 8,
749 /**
750 * A raw, untyped byte array. Only used only with mpv_node, and only in
751 * some very specific situations. (Some commands use it.)
752 */
753 MPV_FORMAT_BYTE_ARRAY = 9
754} mpv_format;
755
756/**
757 * Generic data storage.
758 *
759 * If mpv writes this struct (e.g. via mpv_get_property()), you must not change
760 * the data. In some cases (mpv_get_property()), you have to free it with
761 * mpv_free_node_contents(). If you fill this struct yourself, you're also
762 * responsible for freeing it, and you must not call mpv_free_node_contents().
763 */
764typedef struct mpv_node {
765 union {
766 char *string; /** valid if format==MPV_FORMAT_STRING */
767 int flag; /** valid if format==MPV_FORMAT_FLAG */
768 int64_t int64; /** valid if format==MPV_FORMAT_INT64 */
769 double double_; /** valid if format==MPV_FORMAT_DOUBLE */
770 /**
771 * valid if format==MPV_FORMAT_NODE_ARRAY
772 * or if format==MPV_FORMAT_NODE_MAP
773 */
774 struct mpv_node_list *list;
775 /**
776 * valid if format==MPV_FORMAT_BYTE_ARRAY
777 */
778 struct mpv_byte_array *ba;
779 } u;
780 /**
781 * Type of the data stored in this struct. This value rules what members in
782 * the given union can be accessed. The following formats are currently
783 * defined to be allowed in mpv_node:
784 *
785 * MPV_FORMAT_STRING (u.string)
786 * MPV_FORMAT_FLAG (u.flag)
787 * MPV_FORMAT_INT64 (u.int64)
788 * MPV_FORMAT_DOUBLE (u.double_)
789 * MPV_FORMAT_NODE_ARRAY (u.list)
790 * MPV_FORMAT_NODE_MAP (u.list)
791 * MPV_FORMAT_BYTE_ARRAY (u.ba)
792 * MPV_FORMAT_NONE (no member)
793 *
794 * If you encounter a value you don't know, you must not make any
795 * assumptions about the contents of union u.
796 */
797 mpv_format format;
798} mpv_node;
799
800/**
801 * (see mpv_node)
802 */
803typedef struct mpv_node_list {
804 /**
805 * Number of entries. Negative values are not allowed.
806 */
807 int num;
808 /**
809 * MPV_FORMAT_NODE_ARRAY:
810 * values[N] refers to value of the Nth item
811 *
812 * MPV_FORMAT_NODE_MAP:
813 * values[N] refers to value of the Nth key/value pair
814 *
815 * If num > 0, values[0] to values[num-1] (inclusive) are valid.
816 * Otherwise, this can be NULL.
817 */
818 mpv_node *values;
819 /**
820 * MPV_FORMAT_NODE_ARRAY:
821 * unused (typically NULL), access is not allowed
822 *
823 * MPV_FORMAT_NODE_MAP:
824 * keys[N] refers to key of the Nth key/value pair. If num > 0, keys[0] to
825 * keys[num-1] (inclusive) are valid. Otherwise, this can be NULL.
826 * The keys are in random order. The only guarantee is that keys[N] belongs
827 * to the value values[N]. NULL keys are not allowed.
828 */
829 char **keys;
830} mpv_node_list;
831
832/**
833 * (see mpv_node)
834 */
835typedef struct mpv_byte_array {
836 /**
837 * Pointer to the data. In what format the data is stored is up to whatever
838 * uses MPV_FORMAT_BYTE_ARRAY.
839 */
840 void *data;
841 /**
842 * Size of the data pointed to by ptr.
843 */
844 size_t size;
845} mpv_byte_array;
846
847/**
848 * Frees any data referenced by the node. It doesn't free the node itself.
849 * Call this only if the mpv client API set the node. If you constructed the
850 * node yourself (manually), you have to free it yourself.
851 *
852 * If node->format is MPV_FORMAT_NONE, this call does nothing. Likewise, if
853 * the client API sets a node with this format, this function doesn't need to
854 * be called. (This is just a clarification that there's no danger of anything
855 * strange happening in these cases.)
856 */
857MPV_EXPORT void mpv_free_node_contents(mpv_node *node);
858
859/**
860 * Set an option. Note that you can't normally set options during runtime. It
861 * works in uninitialized state (see mpv_create()), and in some cases in at
862 * runtime.
863 *
864 * Using a format other than MPV_FORMAT_NODE is equivalent to constructing a
865 * mpv_node with the given format and data, and passing the mpv_node to this
866 * function.
867 *
868 * Note: this is semi-deprecated. For most purposes, this is not needed anymore.
869 * Starting with mpv version 0.21.0 (version 1.23) most options can be set
870 * with mpv_set_property() (and related functions), and even before
871 * mpv_initialize(). In some obscure corner cases, using this function
872 * to set options might still be required (see
873 * "Inconsistencies between options and properties" in the manpage). Once
874 * these are resolved, the option setting functions might be fully
875 * deprecated.
876 *
877 * @param name Option name. This is the same as on the mpv command line, but
878 * without the leading "--".
879 * @param format see enum mpv_format.
880 * @param[in] data Option value (according to the format).
881 * @return error code
882 */
883MPV_EXPORT int mpv_set_option(mpv_handle *ctx, const char *name, mpv_format format,
884 void *data);
885
886/**
887 * Convenience function to set an option to a string value. This is like
888 * calling mpv_set_option() with MPV_FORMAT_STRING.
889 *
890 * @return error code
891 */
892MPV_EXPORT int mpv_set_option_string(mpv_handle *ctx, const char *name, const char *data);
893
894/**
895 * Send a command to the player. Commands are the same as those used in
896 * input.conf, except that this function takes parameters in a pre-split
897 * form.
898 *
899 * The commands and their parameters are documented in input.rst.
900 *
901 * Does not use OSD and string expansion by default (unlike mpv_command_string()
902 * and input.conf).
903 *
904 * @param[in] args NULL-terminated list of strings. Usually, the first item
905 * is the command, and the following items are arguments.
906 * @return error code
907 */
908MPV_EXPORT int mpv_command(mpv_handle *ctx, const char **args);
909
910/**
911 * Same as mpv_command(), but allows passing structured data in any format.
912 * In particular, calling mpv_command() is exactly like calling
913 * mpv_command_node() with the format set to MPV_FORMAT_NODE_ARRAY, and
914 * every arg passed in order as MPV_FORMAT_STRING.
915 *
916 * Does not use OSD and string expansion by default.
917 *
918 * The args argument can have one of the following formats:
919 *
920 * MPV_FORMAT_NODE_ARRAY:
921 * Positional arguments. Each entry is an argument using an arbitrary
922 * format (the format must be compatible to the used command). Usually,
923 * the first item is the command name (as MPV_FORMAT_STRING). The order
924 * of arguments is as documented in each command description.
925 *
926 * MPV_FORMAT_NODE_MAP:
927 * Named arguments. This requires at least a special entry with the key
928 * "_name" to be present, which must be a string, and contains the command
929 * name. For compatibility, if the key "_name" does not exist, then the
930 * entry with the key "name" will be used instead.
931 * The special entry "_flags" is optional, and if present, must be an
932 * array of strings, each being a command prefix to apply. All other
933 * entries are interpreted as arguments. They must use the argument names
934 * as documented in each command description. Some commands do not
935 * support named arguments at all, and must use MPV_FORMAT_NODE_ARRAY.
936 * Some commands have arguments named "name", and can only be used if
937 * the command name is specified with key "_name" instead of "name".
938 *
939 * @param[in] args mpv_node with format set to one of the values documented
940 * above (see there for details)
941 * @param[out] result Optional, pass NULL if unused. If not NULL, and if the
942 * function succeeds, this is set to command-specific return
943 * data. You must call mpv_free_node_contents() to free it
944 * (again, only if the command actually succeeds).
945 * Not many commands actually use this at all.
946 * @return error code (the result parameter is not set on error)
947 */
948MPV_EXPORT int mpv_command_node(mpv_handle *ctx, mpv_node *args, mpv_node *result);
949
950/**
951 * This is essentially identical to mpv_command() but it also returns a result.
952 *
953 * Does not use OSD and string expansion by default.
954 *
955 * @param[in] args NULL-terminated list of strings. Usually, the first item
956 * is the command, and the following items are arguments.
957 * @param[out] result Optional, pass NULL if unused. If not NULL, and if the
958 * function succeeds, this is set to command-specific return
959 * data. You must call mpv_free_node_contents() to free it
960 * (again, only if the command actually succeeds).
961 * Not many commands actually use this at all.
962 * @return error code (the result parameter is not set on error)
963 */
964MPV_EXPORT int mpv_command_ret(mpv_handle *ctx, const char **args, mpv_node *result);
965
966/**
967 * Same as mpv_command, but use input.conf parsing for splitting arguments.
968 * This is slightly simpler, but also more error prone, since arguments may
969 * need quoting/escaping.
970 *
971 * This also has OSD and string expansion enabled by default.
972 */
973MPV_EXPORT int mpv_command_string(mpv_handle *ctx, const char *args);
974
975/**
976 * Same as mpv_command, but run the command asynchronously.
977 *
978 * Commands are executed asynchronously. You will receive a
979 * MPV_EVENT_COMMAND_REPLY event. This event will also have an
980 * error code set if running the command failed. For commands that
981 * return data, the data is put into mpv_event_command.result.
982 *
983 * The only case when you do not receive an event is when the function call
984 * itself fails. This happens only if parsing the command itself (or otherwise
985 * validating it) fails, i.e. the return code of the API call is not 0 or
986 * positive.
987 *
988 * Safe to be called from mpv render API threads.
989 *
990 * @param reply_userdata the value mpv_event.reply_userdata of the reply will
991 * be set to (see section about asynchronous calls)
992 * @param args NULL-terminated list of strings (see mpv_command())
993 * @return error code (if parsing or queuing the command fails)
994 */
995MPV_EXPORT int mpv_command_async(mpv_handle *ctx, uint64_t reply_userdata,
996 const char **args);
997
998/**
999 * Same as mpv_command_node(), but run it asynchronously. Basically, this
1000 * function is to mpv_command_node() what mpv_command_async() is to
1001 * mpv_command().
1002 *
1003 * See mpv_command_async() for details.
1004 *
1005 * Safe to be called from mpv render API threads.
1006 *
1007 * @param reply_userdata the value mpv_event.reply_userdata of the reply will
1008 * be set to (see section about asynchronous calls)
1009 * @param args as in mpv_command_node()
1010 * @return error code (if parsing or queuing the command fails)
1011 */
1012MPV_EXPORT int mpv_command_node_async(mpv_handle *ctx, uint64_t reply_userdata,
1013 mpv_node *args);
1014
1015/**
1016 * Signal to all async requests with the matching ID to abort. This affects
1017 * the following API calls:
1018 *
1019 * mpv_command_async
1020 * mpv_command_node_async
1021 *
1022 * All of these functions take a reply_userdata parameter. This API function
1023 * tells all requests with the matching reply_userdata value to try to return
1024 * as soon as possible. If there are multiple requests with matching ID, it
1025 * aborts all of them.
1026 *
1027 * This API function is mostly asynchronous itself. It will not wait until the
1028 * command is aborted. Instead, the command will terminate as usual, but with
1029 * some work not done. How this is signaled depends on the specific command (for
1030 * example, the "subprocess" command will indicate it by "killed_by_us" set to
1031 * true in the result). How long it takes also depends on the situation. The
1032 * aborting process is completely asynchronous.
1033 *
1034 * Not all commands may support this functionality. In this case, this function
1035 * will have no effect. The same is true if the request using the passed
1036 * reply_userdata has already terminated, has not been started yet, or was
1037 * never in use at all.
1038 *
1039 * You have to be careful of race conditions: the time during which the abort
1040 * request will be effective is _after_ e.g. mpv_command_async() has returned,
1041 * and before the command has signaled completion with MPV_EVENT_COMMAND_REPLY.
1042 *
1043 * @param reply_userdata ID of the request to be aborted (see above)
1044 */
1045MPV_EXPORT void mpv_abort_async_command(mpv_handle *ctx, uint64_t reply_userdata);
1046
1047/**
1048 * Set a property to a given value. Properties are essentially variables which
1049 * can be queried or set at runtime. For example, writing to the pause property
1050 * will actually pause or unpause playback.
1051 *
1052 * If the format doesn't match with the internal format of the property, access
1053 * usually will fail with MPV_ERROR_PROPERTY_FORMAT. In some cases, the data
1054 * is automatically converted and access succeeds. For example, MPV_FORMAT_INT64
1055 * is always converted to MPV_FORMAT_DOUBLE, and access using MPV_FORMAT_STRING
1056 * usually invokes a string parser. The same happens when calling this function
1057 * with MPV_FORMAT_NODE: the underlying format may be converted to another
1058 * type if possible.
1059 *
1060 * Using a format other than MPV_FORMAT_NODE is equivalent to constructing a
1061 * mpv_node with the given format and data, and passing the mpv_node to this
1062 * function. (Before API version 1.21, this was different.)
1063 *
1064 * Note: starting with mpv 0.21.0 (client API version 1.23), this can be used to
1065 * set options in general. It even can be used before mpv_initialize()
1066 * has been called. If called before mpv_initialize(), setting properties
1067 * not backed by options will result in MPV_ERROR_PROPERTY_UNAVAILABLE.
1068 * In some cases, properties and options still conflict. In these cases,
1069 * mpv_set_property() accesses the options before mpv_initialize(), and
1070 * the properties after mpv_initialize(). These conflicts will be removed
1071 * in mpv 0.23.0. See mpv_set_option() for further remarks.
1072 *
1073 * @param name The property name. See input.rst for a list of properties.
1074 * @param format see enum mpv_format.
1075 * @param[in] data Option value.
1076 * @return error code
1077 */
1078MPV_EXPORT int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format,
1079 void *data);
1080
1081/**
1082 * Convenience function to set a property to a string value.
1083 *
1084 * This is like calling mpv_set_property() with MPV_FORMAT_STRING.
1085 */
1086MPV_EXPORT int mpv_set_property_string(mpv_handle *ctx, const char *name, const char *data);
1087
1088/**
1089 * Convenience function to delete a property.
1090 *
1091 * This is equivalent to running the command "del [name]".
1092 *
1093 * @param name The property name. See input.rst for a list of properties.
1094 * @return error code
1095 */
1096MPV_EXPORT int mpv_del_property(mpv_handle *ctx, const char *name);
1097
1098/**
1099 * Set a property asynchronously. You will receive the result of the operation
1100 * as MPV_EVENT_SET_PROPERTY_REPLY event. The mpv_event.error field will contain
1101 * the result status of the operation. Otherwise, this function is similar to
1102 * mpv_set_property().
1103 *
1104 * Safe to be called from mpv render API threads.
1105 *
1106 * @param reply_userdata see section about asynchronous calls
1107 * @param name The property name.
1108 * @param format see enum mpv_format.
1109 * @param[in] data Option value. The value will be copied by the function. It
1110 * will never be modified by the client API.
1111 * @return error code if sending the request failed
1112 */
1113MPV_EXPORT int mpv_set_property_async(mpv_handle *ctx, uint64_t reply_userdata,
1114 const char *name, mpv_format format, void *data);
1115
1116/**
1117 * Read the value of the given property.
1118 *
1119 * If the format doesn't match with the internal format of the property, access
1120 * usually will fail with MPV_ERROR_PROPERTY_FORMAT. In some cases, the data
1121 * is automatically converted and access succeeds. For example, MPV_FORMAT_INT64
1122 * is always converted to MPV_FORMAT_DOUBLE, and access using MPV_FORMAT_STRING
1123 * usually invokes a string formatter.
1124 *
1125 * @param name The property name.
1126 * @param format see enum mpv_format.
1127 * @param[out] data Pointer to the variable holding the option value. On
1128 * success, the variable will be set to a copy of the option
1129 * value. For formats that require dynamic memory allocation,
1130 * you can free the value with mpv_free() (strings) or
1131 * mpv_free_node_contents() (MPV_FORMAT_NODE).
1132 * @return error code
1133 */
1134MPV_EXPORT int mpv_get_property(mpv_handle *ctx, const char *name, mpv_format format,
1135 void *data);
1136
1137/**
1138 * Return the value of the property with the given name as string. This is
1139 * equivalent to mpv_get_property() with MPV_FORMAT_STRING.
1140 *
1141 * See MPV_FORMAT_STRING for character encoding issues.
1142 *
1143 * On error, NULL is returned. Use mpv_get_property() if you want fine-grained
1144 * error reporting.
1145 *
1146 * @param name The property name.
1147 * @return Property value, or NULL if the property can't be retrieved. Free
1148 * the string with mpv_free().
1149 */
1150MPV_EXPORT char *mpv_get_property_string(mpv_handle *ctx, const char *name);
1151
1152/**
1153 * Return the property as "OSD" formatted string. This is the same as
1154 * mpv_get_property_string, but using MPV_FORMAT_OSD_STRING.
1155 *
1156 * @return Property value, or NULL if the property can't be retrieved. Free
1157 * the string with mpv_free().
1158 */
1159MPV_EXPORT char *mpv_get_property_osd_string(mpv_handle *ctx, const char *name);
1160
1161/**
1162 * Get a property asynchronously. You will receive the result of the operation
1163 * as well as the property data with the MPV_EVENT_GET_PROPERTY_REPLY event.
1164 * You should check the mpv_event.error field on the reply event.
1165 *
1166 * Safe to be called from mpv render API threads.
1167 *
1168 * @param reply_userdata see section about asynchronous calls
1169 * @param name The property name.
1170 * @param format see enum mpv_format.
1171 * @return error code if sending the request failed
1172 */
1173MPV_EXPORT int mpv_get_property_async(mpv_handle *ctx, uint64_t reply_userdata,
1174 const char *name, mpv_format format);
1175
1176/**
1177 * Get a notification whenever the given property changes. You will receive
1178 * updates as MPV_EVENT_PROPERTY_CHANGE. Note that this is not very precise:
1179 * for some properties, it may not send updates even if the property changed.
1180 * This depends on the property, and it's a valid feature request to ask for
1181 * better update handling of a specific property. (For some properties, like
1182 * ``clock``, which shows the wall clock, this mechanism doesn't make too
1183 * much sense anyway.)
1184 *
1185 * Property changes are coalesced: the change events are returned only once the
1186 * event queue becomes empty (e.g. mpv_wait_event() would block or return
1187 * MPV_EVENT_NONE), and then only one event per changed property is returned.
1188 *
1189 * You always get an initial change notification. This is meant to initialize
1190 * the user's state to the current value of the property.
1191 *
1192 * Normally, change events are sent only if the property value changes according
1193 * to the requested format. mpv_event_property will contain the property value
1194 * as data member.
1195 *
1196 * Warning: if a property is unavailable or retrieving it caused an error,
1197 * MPV_FORMAT_NONE will be set in mpv_event_property, even if the
1198 * format parameter was set to a different value. In this case, the
1199 * mpv_event_property.data field is invalid.
1200 *
1201 * If the property is observed with the format parameter set to MPV_FORMAT_NONE,
1202 * you get low-level notifications whether the property _may_ have changed, and
1203 * the data member in mpv_event_property will be unset. With this mode, you
1204 * will have to determine yourself whether the property really changed. On the
1205 * other hand, this mechanism can be faster and uses less resources.
1206 *
1207 * Observing a property that doesn't exist is allowed. (Although it may still
1208 * cause some sporadic change events.)
1209 *
1210 * Keep in mind that you will get change notifications even if you change a
1211 * property yourself. Try to avoid endless feedback loops, which could happen
1212 * if you react to the change notifications triggered by your own change.
1213 *
1214 * Only the mpv_handle on which this was called will receive the property
1215 * change events, or can unobserve them.
1216 *
1217 * Safe to be called from mpv render API threads.
1218 *
1219 * @param reply_userdata This will be used for the mpv_event.reply_userdata
1220 * field for the received MPV_EVENT_PROPERTY_CHANGE
1221 * events. (Also see section about asynchronous calls,
1222 * although this function is somewhat different from
1223 * actual asynchronous calls.)
1224 * If you have no use for this, pass 0.
1225 * Also see mpv_unobserve_property().
1226 * @param name The property name.
1227 * @param format see enum mpv_format. Can be MPV_FORMAT_NONE to omit values
1228 * from the change events.
1229 * @return error code (usually fails only on OOM or unsupported format)
1230 */
1231MPV_EXPORT int mpv_observe_property(mpv_handle *mpv, uint64_t reply_userdata,
1232 const char *name, mpv_format format);
1233
1234/**
1235 * Undo mpv_observe_property(). This will remove all observed properties for
1236 * which the given number was passed as reply_userdata to mpv_observe_property.
1237 *
1238 * Safe to be called from mpv render API threads.
1239 *
1240 * @param registered_reply_userdata ID that was passed to mpv_observe_property
1241 * @return negative value is an error code, >=0 is number of removed properties
1242 * on success (includes the case when 0 were removed)
1243 */
1244MPV_EXPORT int mpv_unobserve_property(mpv_handle *mpv, uint64_t registered_reply_userdata);
1245
1246typedef enum mpv_event_id {
1247 /**
1248 * Nothing happened. Happens on timeouts or sporadic wakeups.
1249 */
1250 MPV_EVENT_NONE = 0,
1251 /**
1252 * Happens when the player quits. The player enters a state where it tries
1253 * to disconnect all clients. Most requests to the player will fail, and
1254 * the client should react to this and quit with mpv_destroy() as soon as
1255 * possible.
1256 */
1257 MPV_EVENT_SHUTDOWN = 1,
1258 /**
1259 * See mpv_request_log_messages().
1260 */
1261 MPV_EVENT_LOG_MESSAGE = 2,
1262 /**
1263 * Reply to a mpv_get_property_async() request.
1264 * See also mpv_event and mpv_event_property.
1265 */
1266 MPV_EVENT_GET_PROPERTY_REPLY = 3,
1267 /**
1268 * Reply to a mpv_set_property_async() request.
1269 * (Unlike MPV_EVENT_GET_PROPERTY, mpv_event_property is not used.)
1270 */
1271 MPV_EVENT_SET_PROPERTY_REPLY = 4,
1272 /**
1273 * Reply to a mpv_command_async() or mpv_command_node_async() request.
1274 * See also mpv_event and mpv_event_command.
1275 */
1276 MPV_EVENT_COMMAND_REPLY = 5,
1277 /**
1278 * Notification before playback start of a file (before the file is loaded).
1279 * See also mpv_event and mpv_event_start_file.
1280 */
1281 MPV_EVENT_START_FILE = 6,
1282 /**
1283 * Notification after playback end (after the file was unloaded).
1284 * See also mpv_event and mpv_event_end_file.
1285 */
1286 MPV_EVENT_END_FILE = 7,
1287 /**
1288 * Notification when the file has been loaded (headers were read etc.), and
1289 * decoding starts.
1290 */
1291 MPV_EVENT_FILE_LOADED = 8,
1292#if MPV_ENABLE_DEPRECATED
1293 /**
1294 * Idle mode was entered. In this mode, no file is played, and the playback
1295 * core waits for new commands. (The command line player normally quits
1296 * instead of entering idle mode, unless --idle was specified. If mpv
1297 * was started with mpv_create(), idle mode is enabled by default.)
1298 *
1299 * @deprecated This is equivalent to using mpv_observe_property() on the
1300 * "idle-active" property. The event is redundant, and might be
1301 * removed in the far future. As a further warning, this event
1302 * is not necessarily sent at the right point anymore (at the
1303 * start of the program), while the property behaves correctly.
1304 */
1305 MPV_EVENT_IDLE = 11,
1306 /**
1307 * Sent every time after a video frame is displayed. Note that currently,
1308 * this will be sent in lower frequency if there is no video, or playback
1309 * is paused - but that will be removed in the future, and it will be
1310 * restricted to video frames only.
1311 *
1312 * @deprecated Use mpv_observe_property() with relevant properties instead
1313 * (such as "playback-time").
1314 */
1315 MPV_EVENT_TICK = 14,
1316#endif
1317 /**
1318 * Triggered by the script-message input command. The command uses the
1319 * first argument of the command as client name (see mpv_client_name()) to
1320 * dispatch the message, and passes along all arguments starting from the
1321 * second argument as strings.
1322 * See also mpv_event and mpv_event_client_message.
1323 */
1324 MPV_EVENT_CLIENT_MESSAGE = 16,
1325 /**
1326 * Happens after video changed in some way. This can happen on resolution
1327 * changes, pixel format changes, or video filter changes. The event is
1328 * sent after the video filters and the VO are reconfigured. Applications
1329 * embedding a mpv window should listen to this event in order to resize
1330 * the window if needed.
1331 * Note that this event can happen sporadically, and you should check
1332 * yourself whether the video parameters really changed before doing
1333 * something expensive.
1334 */
1335 MPV_EVENT_VIDEO_RECONFIG = 17,
1336 /**
1337 * Similar to MPV_EVENT_VIDEO_RECONFIG. This is relatively uninteresting,
1338 * because there is no such thing as audio output embedding.
1339 */
1340 MPV_EVENT_AUDIO_RECONFIG = 18,
1341 /**
1342 * Happens when a seek was initiated. Playback stops. Usually it will
1343 * resume with MPV_EVENT_PLAYBACK_RESTART as soon as the seek is finished.
1344 */
1345 MPV_EVENT_SEEK = 20,
1346 /**
1347 * There was a discontinuity of some sort (like a seek), and playback
1348 * was reinitialized. Usually happens on start of playback and after
1349 * seeking. The main purpose is allowing the client to detect when a seek
1350 * request is finished.
1351 */
1352 MPV_EVENT_PLAYBACK_RESTART = 21,
1353 /**
1354 * Event sent due to mpv_observe_property().
1355 * See also mpv_event and mpv_event_property.
1356 */
1357 MPV_EVENT_PROPERTY_CHANGE = 22,
1358 /**
1359 * Happens if the internal per-mpv_handle ringbuffer overflows, and at
1360 * least 1 event had to be dropped. This can happen if the client doesn't
1361 * read the event queue quickly enough with mpv_wait_event(), or if the
1362 * client makes a very large number of asynchronous calls at once.
1363 *
1364 * Event delivery will continue normally once this event was returned
1365 * (this forces the client to empty the queue completely).
1366 */
1367 MPV_EVENT_QUEUE_OVERFLOW = 24,
1368 /**
1369 * Triggered if a hook handler was registered with mpv_hook_add(), and the
1370 * hook is invoked. If you receive this, you must handle it, and continue
1371 * the hook with mpv_hook_continue().
1372 * See also mpv_event and mpv_event_hook.
1373 */
1374 MPV_EVENT_HOOK = 25,
1375 // Internal note: adjust INTERNAL_EVENT_BASE when adding new events.
1376} mpv_event_id;
1377
1378/**
1379 * Return a string describing the event. For unknown events, NULL is returned.
1380 *
1381 * Note that all events actually returned by the API will also yield a non-NULL
1382 * string with this function.
1383 *
1384 * @param event event ID, see see enum mpv_event_id
1385 * @return A static string giving a short symbolic name of the event. It
1386 * consists of lower-case alphanumeric characters and can include "-"
1387 * characters. This string is suitable for use in e.g. scripting
1388 * interfaces.
1389 * The string is completely static, i.e. doesn't need to be deallocated,
1390 * and is valid forever.
1391 */
1392MPV_EXPORT const char *mpv_event_name(mpv_event_id event);
1393
1394typedef struct mpv_event_property {
1395 /**
1396 * Name of the property.
1397 */
1398 const char *name;
1399 /**
1400 * Format of the data field in the same struct. See enum mpv_format.
1401 * This is always the same format as the requested format, except when
1402 * the property could not be retrieved (unavailable, or an error happened),
1403 * in which case the format is MPV_FORMAT_NONE.
1404 */
1405 mpv_format format;
1406 /**
1407 * Received property value. Depends on the format. This is like the
1408 * pointer argument passed to mpv_get_property().
1409 *
1410 * For example, for MPV_FORMAT_STRING you get the string with:
1411 *
1412 * char *value = *(char **)(event_property->data);
1413 *
1414 * Note that this is set to NULL if retrieving the property failed (the
1415 * format will be MPV_FORMAT_NONE).
1416 */
1417 void *data;
1418} mpv_event_property;
1419
1420/**
1421 * Numeric log levels. The lower the number, the more important the message is.
1422 * MPV_LOG_LEVEL_NONE is never used when receiving messages. The string in
1423 * the comment after the value is the name of the log level as used for the
1424 * mpv_request_log_messages() function.
1425 * Unused numeric values are unused, but reserved for future use.
1426 */
1427typedef enum mpv_log_level {
1428 MPV_LOG_LEVEL_NONE = 0, /// "no" - disable absolutely all messages
1429 MPV_LOG_LEVEL_FATAL = 10, /// "fatal" - critical/aborting errors
1430 MPV_LOG_LEVEL_ERROR = 20, /// "error" - simple errors
1431 MPV_LOG_LEVEL_WARN = 30, /// "warn" - possible problems
1432 MPV_LOG_LEVEL_INFO = 40, /// "info" - informational message
1433 MPV_LOG_LEVEL_V = 50, /// "v" - noisy informational message
1434 MPV_LOG_LEVEL_DEBUG = 60, /// "debug" - very noisy technical information
1435 MPV_LOG_LEVEL_TRACE = 70, /// "trace" - extremely noisy
1436} mpv_log_level;
1437
1438typedef struct mpv_event_log_message {
1439 /**
1440 * The module prefix, identifies the sender of the message. As a special
1441 * case, if the message buffer overflows, this will be set to the string
1442 * "overflow" (which doesn't appear as prefix otherwise), and the text
1443 * field will contain an informative message.
1444 */
1445 const char *prefix;
1446 /**
1447 * The log level as string. See mpv_request_log_messages() for possible
1448 * values. The level "no" is never used here.
1449 */
1450 const char *level;
1451 /**
1452 * The log message. It consists of 1 line of text, and is terminated with
1453 * a newline character. (Before API version 1.6, it could contain multiple
1454 * or partial lines.)
1455 */
1456 const char *text;
1457 /**
1458 * The same contents as the level field, but as a numeric ID.
1459 * Since API version 1.6.
1460 */
1461 mpv_log_level log_level;
1462} mpv_event_log_message;
1463
1464/// Since API version 1.9.
1465typedef enum mpv_end_file_reason {
1466 /**
1467 * The end of file was reached. Sometimes this may also happen on
1468 * incomplete or corrupted files, or if the network connection was
1469 * interrupted when playing a remote file. It also happens if the
1470 * playback range was restricted with --end or --frames or similar.
1471 */
1472 MPV_END_FILE_REASON_EOF = 0,
1473 /**
1474 * Playback was stopped by an external action (e.g. playlist controls).
1475 */
1476 MPV_END_FILE_REASON_STOP = 2,
1477 /**
1478 * Playback was stopped by the quit command or player shutdown.
1479 */
1480 MPV_END_FILE_REASON_QUIT = 3,
1481 /**
1482 * Some kind of error happened that lead to playback abort. Does not
1483 * necessarily happen on incomplete or broken files (in these cases, both
1484 * MPV_END_FILE_REASON_ERROR or MPV_END_FILE_REASON_EOF are possible).
1485 *
1486 * mpv_event_end_file.error will be set.
1487 */
1488 MPV_END_FILE_REASON_ERROR = 4,
1489 /**
1490 * The file was a playlist or similar. When the playlist is read, its
1491 * entries will be appended to the playlist after the entry of the current
1492 * file, the entry of the current file is removed, and a MPV_EVENT_END_FILE
1493 * event is sent with reason set to MPV_END_FILE_REASON_REDIRECT. Then
1494 * playback continues with the playlist contents.
1495 * Since API version 1.18.
1496 */
1497 MPV_END_FILE_REASON_REDIRECT = 5,
1498} mpv_end_file_reason;
1499
1500/// Since API version 1.108.
1501typedef struct mpv_event_start_file {
1502 /**
1503 * Playlist entry ID of the file being loaded now.
1504 */
1505 int64_t playlist_entry_id;
1506} mpv_event_start_file;
1507
1508typedef struct mpv_event_end_file {
1509 /**
1510 * Corresponds to the values in enum mpv_end_file_reason.
1511 *
1512 * Unknown values should be treated as unknown.
1513 */
1514 mpv_end_file_reason reason;
1515 /**
1516 * If reason==MPV_END_FILE_REASON_ERROR, this contains a mpv error code
1517 * (one of MPV_ERROR_...) giving an approximate reason why playback
1518 * failed. In other cases, this field is 0 (no error).
1519 * Since API version 1.9.
1520 */
1521 int error;
1522 /**
1523 * Playlist entry ID of the file that was being played or attempted to be
1524 * played. This has the same value as the playlist_entry_id field in the
1525 * corresponding mpv_event_start_file event.
1526 * Since API version 1.108.
1527 */
1528 int64_t playlist_entry_id;
1529 /**
1530 * If loading ended, because the playlist entry to be played was for example
1531 * a playlist, and the current playlist entry is replaced with a number of
1532 * other entries. This may happen at least with MPV_END_FILE_REASON_REDIRECT
1533 * (other event types may use this for similar but different purposes in the
1534 * future). In this case, playlist_insert_id will be set to the playlist
1535 * entry ID of the first inserted entry, and playlist_insert_num_entries to
1536 * the total number of inserted playlist entries. Note this in this specific
1537 * case, the ID of the last inserted entry is playlist_insert_id+num-1.
1538 * Beware that depending on circumstances, you may observe the new playlist
1539 * entries before seeing the event (e.g. reading the "playlist" property or
1540 * getting a property change notification before receiving the event).
1541 * Since API version 1.108.
1542 */
1543 int64_t playlist_insert_id;
1544 /**
1545 * See playlist_insert_id. Only non-0 if playlist_insert_id is valid. Never
1546 * negative.
1547 * Since API version 1.108.
1548 */
1549 int playlist_insert_num_entries;
1550} mpv_event_end_file;
1551
1552typedef struct mpv_event_client_message {
1553 /**
1554 * Arbitrary arguments chosen by the sender of the message. If num_args > 0,
1555 * you can access args[0] through args[num_args - 1] (inclusive). What
1556 * these arguments mean is up to the sender and receiver.
1557 * None of the valid items are NULL.
1558 */
1559 int num_args;
1560 const char **args;
1561} mpv_event_client_message;
1562
1563typedef struct mpv_event_hook {
1564 /**
1565 * The hook name as passed to mpv_hook_add().
1566 */
1567 const char *name;
1568 /**
1569 * Internal ID that must be passed to mpv_hook_continue().
1570 */
1571 uint64_t id;
1572} mpv_event_hook;
1573
1574// Since API version 1.102.
1575typedef struct mpv_event_command {
1576 /**
1577 * Result data of the command. Note that success/failure is signaled
1578 * separately via mpv_event.error. This field is only for result data
1579 * in case of success. Most commands leave it at MPV_FORMAT_NONE. Set
1580 * to MPV_FORMAT_NONE on failure.
1581 */
1582 mpv_node result;
1583} mpv_event_command;
1584
1585typedef struct mpv_event {
1586 /**
1587 * One of mpv_event. Keep in mind that later ABI compatible releases might
1588 * add new event types. These should be ignored by the API user.
1589 */
1590 mpv_event_id event_id;
1591 /**
1592 * This is mainly used for events that are replies to (asynchronous)
1593 * requests. It contains a status code, which is >= 0 on success, or < 0
1594 * on error (a mpv_error value). Usually, this will be set if an
1595 * asynchronous request fails.
1596 * Used for:
1597 * MPV_EVENT_GET_PROPERTY_REPLY
1598 * MPV_EVENT_SET_PROPERTY_REPLY
1599 * MPV_EVENT_COMMAND_REPLY
1600 */
1601 int error;
1602 /**
1603 * If the event is in reply to a request (made with this API and this
1604 * API handle), this is set to the reply_userdata parameter of the request
1605 * call. Otherwise, this field is 0.
1606 * Used for:
1607 * MPV_EVENT_GET_PROPERTY_REPLY
1608 * MPV_EVENT_SET_PROPERTY_REPLY
1609 * MPV_EVENT_COMMAND_REPLY
1610 * MPV_EVENT_PROPERTY_CHANGE
1611 * MPV_EVENT_HOOK
1612 */
1613 uint64_t reply_userdata;
1614 /**
1615 * The meaning and contents of the data member depend on the event_id:
1616 * MPV_EVENT_GET_PROPERTY_REPLY: mpv_event_property*
1617 * MPV_EVENT_PROPERTY_CHANGE: mpv_event_property*
1618 * MPV_EVENT_LOG_MESSAGE: mpv_event_log_message*
1619 * MPV_EVENT_CLIENT_MESSAGE: mpv_event_client_message*
1620 * MPV_EVENT_START_FILE: mpv_event_start_file* (since v1.108)
1621 * MPV_EVENT_END_FILE: mpv_event_end_file*
1622 * MPV_EVENT_HOOK: mpv_event_hook*
1623 * MPV_EVENT_COMMAND_REPLY* mpv_event_command*
1624 * other: NULL
1625 *
1626 * Note: future enhancements might add new event structs for existing or new
1627 * event types.
1628 */
1629 void *data;
1630} mpv_event;
1631
1632/**
1633 * Convert the given src event to a mpv_node, and set *dst to the result. *dst
1634 * is set to a MPV_FORMAT_NODE_MAP, with fields for corresponding mpv_event and
1635 * mpv_event.data/mpv_event_* fields.
1636 *
1637 * The exact details are not completely documented out of laziness. A start
1638 * is located in the "Events" section of the manpage.
1639 *
1640 * *dst may point to newly allocated memory, or pointers in mpv_event. You must
1641 * copy the entire mpv_node if you want to reference it after mpv_event becomes
1642 * invalid (such as making a new mpv_wait_event() call, or destroying the
1643 * mpv_handle from which it was returned). Call mpv_free_node_contents() to free
1644 * any memory allocations made by this API function.
1645 *
1646 * Safe to be called from mpv render API threads.
1647 *
1648 * @param dst Target. This is not read and fully overwritten. Must be released
1649 * with mpv_free_node_contents(). Do not write to pointers returned
1650 * by it. (On error, this may be left as an empty node.)
1651 * @param src The source event. Not modified (it's not const due to the author's
1652 * prejudice of the C version of const).
1653 * @return error code (MPV_ERROR_NOMEM only, if at all)
1654 */
1655MPV_EXPORT int mpv_event_to_node(mpv_node *dst, mpv_event *src);
1656
1657/**
1658 * Enable or disable the given event.
1659 *
1660 * Some events are enabled by default. Some events can't be disabled.
1661 *
1662 * (Informational note: currently, all events are enabled by default, except
1663 * MPV_EVENT_TICK.)
1664 *
1665 * Safe to be called from mpv render API threads.
1666 *
1667 * @param event See enum mpv_event_id.
1668 * @param enable 1 to enable receiving this event, 0 to disable it.
1669 * @return error code
1670 */
1671MPV_EXPORT int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable);
1672
1673/**
1674 * Enable or disable receiving of log messages. These are the messages the
1675 * command line player prints to the terminal. This call sets the minimum
1676 * required log level for a message to be received with MPV_EVENT_LOG_MESSAGE.
1677 *
1678 * @param min_level Minimal log level as string. Valid log levels:
1679 * no fatal error warn info v debug trace
1680 * The value "no" disables all messages. This is the default.
1681 * An exception is the value "terminal-default", which uses the
1682 * log level as set by the "--msg-level" option. This works
1683 * even if the terminal is disabled. (Since API version 1.19.)
1684 * Also see mpv_log_level.
1685 * @return error code
1686 */
1687MPV_EXPORT int mpv_request_log_messages(mpv_handle *ctx, const char *min_level);
1688
1689/**
1690 * Wait for the next event, or until the timeout expires, or if another thread
1691 * makes a call to mpv_wakeup(). Passing 0 as timeout will never wait, and
1692 * is suitable for polling.
1693 *
1694 * The internal event queue has a limited size (per client handle). If you
1695 * don't empty the event queue quickly enough with mpv_wait_event(), it will
1696 * overflow and silently discard further events. If this happens, making
1697 * asynchronous requests will fail as well (with MPV_ERROR_EVENT_QUEUE_FULL).
1698 *
1699 * Only one thread is allowed to call this on the same mpv_handle at a time.
1700 * The API won't complain if more than one thread calls this, but it will cause
1701 * race conditions in the client when accessing the shared mpv_event struct.
1702 * Note that most other API functions are not restricted by this, and no API
1703 * function internally calls mpv_wait_event(). Additionally, concurrent calls
1704 * to different mpv_handles are always safe.
1705 *
1706 * As long as the timeout is 0, this is safe to be called from mpv render API
1707 * threads.
1708 *
1709 * @param timeout Timeout in seconds, after which the function returns even if
1710 * no event was received. A MPV_EVENT_NONE is returned on
1711 * timeout. A value of 0 will disable waiting. Negative values
1712 * will wait with an infinite timeout.
1713 * @return A struct containing the event ID and other data. The pointer (and
1714 * fields in the struct) stay valid until the next mpv_wait_event()
1715 * call, or until the mpv_handle is destroyed. You must not write to
1716 * the struct, and all memory referenced by it will be automatically
1717 * released by the API on the next mpv_wait_event() call, or when the
1718 * context is destroyed. The return value is never NULL.
1719 */
1720MPV_EXPORT mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout);
1721
1722/**
1723 * Interrupt the current mpv_wait_event() call. This will wake up the thread
1724 * currently waiting in mpv_wait_event(). If no thread is waiting, the next
1725 * mpv_wait_event() call will return immediately (this is to avoid lost
1726 * wakeups).
1727 *
1728 * mpv_wait_event() will receive a MPV_EVENT_NONE if it's woken up due to
1729 * this call. But note that this dummy event might be skipped if there are
1730 * already other events queued. All what counts is that the waiting thread
1731 * is woken up at all.
1732 *
1733 * Safe to be called from mpv render API threads.
1734 */
1735MPV_EXPORT void mpv_wakeup(mpv_handle *ctx);
1736
1737/**
1738 * Set a custom function that should be called when there are new events. Use
1739 * this if blocking in mpv_wait_event() to wait for new events is not feasible.
1740 *
1741 * Keep in mind that the callback will be called from foreign threads. You
1742 * must not make any assumptions of the environment, and you must return as
1743 * soon as possible (i.e. no long blocking waits). Exiting the callback through
1744 * any other means than a normal return is forbidden (no throwing exceptions,
1745 * no longjmp() calls). You must not change any local thread state (such as
1746 * the C floating point environment).
1747 *
1748 * You are not allowed to call any client API functions inside of the callback.
1749 * In particular, you should not do any processing in the callback, but wake up
1750 * another thread that does all the work. The callback is meant strictly for
1751 * notification only, and is called from arbitrary core parts of the player,
1752 * that make no considerations for reentrant API use or allowing the callee to
1753 * spend a lot of time doing other things. Keep in mind that it's also possible
1754 * that the callback is called from a thread while a mpv API function is called
1755 * (i.e. it can be reentrant).
1756 *
1757 * In general, the client API expects you to call mpv_wait_event() to receive
1758 * notifications, and the wakeup callback is merely a helper utility to make
1759 * this easier in certain situations. Note that it's possible that there's
1760 * only one wakeup callback invocation for multiple events. You should call
1761 * mpv_wait_event() with no timeout until MPV_EVENT_NONE is reached, at which
1762 * point the event queue is empty.
1763 *
1764 * If you actually want to do processing in a callback, spawn a thread that
1765 * does nothing but call mpv_wait_event() in a loop and dispatches the result
1766 * to a callback.
1767 *
1768 * Only one wakeup callback can be set.
1769 *
1770 * @param cb function that should be called if a wakeup is required
1771 * @param d arbitrary userdata passed to cb
1772 */
1773MPV_EXPORT void mpv_set_wakeup_callback(mpv_handle *ctx, void (*cb)(void *d), void *d);
1774
1775/**
1776 * Block until all asynchronous requests are done. This affects functions like
1777 * mpv_command_async(), which return immediately and return their result as
1778 * events.
1779 *
1780 * This is a helper, and somewhat equivalent to calling mpv_wait_event() in a
1781 * loop until all known asynchronous requests have sent their reply as event,
1782 * except that the event queue is not emptied.
1783 */
1784MPV_EXPORT void mpv_wait_async_requests(mpv_handle *ctx);
1785
1786/**
1787 * A hook is like a synchronous event that blocks the player. You register
1788 * a hook handler with this function. You will get an event, which you need
1789 * to handle, and once things are ready, you can let the player continue with
1790 * mpv_hook_continue().
1791 *
1792 * Currently, hooks can't be removed explicitly. But they will be implicitly
1793 * removed if the mpv_handle it was registered with is destroyed. This also
1794 * continues the hook if it was being handled by the destroyed mpv_handle (but
1795 * this should be avoided, as it might mess up order of hook execution).
1796 *
1797 * Hook handlers are ordered globally by priority and order of registration.
1798 * Handlers for the same hook with same priority are invoked in order of
1799 * registration (the handler registered first is run first). Handlers with
1800 * lower priority are run first (which seems backward).
1801 *
1802 * See the "Hooks" section in the manpage to see which hooks are currently
1803 * defined.
1804 *
1805 * Some hooks might be reentrant (so you get multiple MPV_EVENT_HOOK for the
1806 * same hook). If this can happen for a specific hook type, it will be
1807 * explicitly documented in the manpage.
1808 *
1809 * Only the mpv_handle on which this was called will receive the hook events,
1810 * or can "continue" them.
1811 *
1812 * @param reply_userdata This will be used for the mpv_event.reply_userdata
1813 * field for the received MPV_EVENT_HOOK events.
1814 * If you have no use for this, pass 0.
1815 * @param name The hook name. This should be one of the documented names. But
1816 * if the name is unknown, the hook event will simply be never
1817 * raised.
1818 * @param priority See remarks above. Use 0 as a neutral default.
1819 * @return error code (usually fails only on OOM)
1820 */
1821MPV_EXPORT int mpv_hook_add(mpv_handle *ctx, uint64_t reply_userdata,
1822 const char *name, int priority);
1823
1824/**
1825 * Respond to a MPV_EVENT_HOOK event. You must call this after you have handled
1826 * the event. There is no way to "cancel" or "stop" the hook.
1827 *
1828 * Calling this will will typically unblock the player for whatever the hook
1829 * is responsible for (e.g. for the "on_load" hook it lets it continue
1830 * playback).
1831 *
1832 * It is explicitly undefined behavior to call this more than once for each
1833 * MPV_EVENT_HOOK, to pass an incorrect ID, or to call this on a mpv_handle
1834 * different from the one that registered the handler and received the event.
1835 *
1836 * @param id This must be the value of the mpv_event_hook.id field for the
1837 * corresponding MPV_EVENT_HOOK.
1838 * @return error code
1839 */
1840MPV_EXPORT int mpv_hook_continue(mpv_handle *ctx, uint64_t id);
1841
1842#if MPV_ENABLE_DEPRECATED
1843
1844/**
1845 * Return a UNIX file descriptor referring to the read end of a pipe. This
1846 * pipe can be used to wake up a poll() based processing loop. The purpose of
1847 * this function is very similar to mpv_set_wakeup_callback(), and provides
1848 * a primitive mechanism to handle coordinating a foreign event loop and the
1849 * libmpv event loop. The pipe is non-blocking. It's closed when the mpv_handle
1850 * is destroyed. This function always returns the same value (on success).
1851 *
1852 * This is in fact implemented using the same underlying code as for
1853 * mpv_set_wakeup_callback() (though they don't conflict), and it is as if each
1854 * callback invocation writes a single 0 byte to the pipe. When the pipe
1855 * becomes readable, the code calling poll() (or select()) on the pipe should
1856 * read all contents of the pipe and then call mpv_wait_event(c, 0) until
1857 * no new events are returned. The pipe contents do not matter and can just
1858 * be discarded. There is not necessarily one byte per readable event in the
1859 * pipe. For example, the pipes are non-blocking, and mpv won't block if the
1860 * pipe is full. Pipes are normally limited to 4096 bytes, so if there are
1861 * more than 4096 events, the number of readable bytes can not equal the number
1862 * of events queued. Also, it's possible that mpv does not write to the pipe
1863 * once it's guaranteed that the client was already signaled. See the example
1864 * below how to do it correctly.
1865 *
1866 * Example:
1867 *
1868 * int pipefd = mpv_get_wakeup_pipe(mpv);
1869 * if (pipefd < 0)
1870 * error();
1871 * while (1) {
1872 * struct pollfd pfds[1] = {
1873 * { .fd = pipefd, .events = POLLIN },
1874 * };
1875 * // Wait until there are possibly new mpv events.
1876 * poll(pfds, 1, -1);
1877 * if (pfds[0].revents & POLLIN) {
1878 * // Empty the pipe. Doing this before calling mpv_wait_event()
1879 * // ensures that no wakeups are missed. It's not so important to
1880 * // make sure the pipe is really empty (it will just cause some
1881 * // additional wakeups in unlikely corner cases).
1882 * char unused[256];
1883 * read(pipefd, unused, sizeof(unused));
1884 * while (1) {
1885 * mpv_event *ev = mpv_wait_event(mpv, 0);
1886 * // If MPV_EVENT_NONE is received, the event queue is empty.
1887 * if (ev->event_id == MPV_EVENT_NONE)
1888 * break;
1889 * // Process the event.
1890 * ...
1891 * }
1892 * }
1893 * }
1894 *
1895 * @deprecated this function will be removed in the future. If you need this
1896 * functionality, use mpv_set_wakeup_callback(), create a pipe
1897 * manually, and call write() on your pipe in the callback.
1898 *
1899 * @return A UNIX FD of the read end of the wakeup pipe, or -1 on error.
1900 * On MS Windows/MinGW, this will always return -1.
1901 */
1902MPV_EXPORT int mpv_get_wakeup_pipe(mpv_handle *ctx);
1903
1904#endif
1905
1906/**
1907 * Defining MPV_CPLUGIN_DYNAMIC_SYM during plugin compilation will replace mpv_*
1908 * functions with function pointers. Those pointer will be initialized when
1909 * loading the plugin.
1910 *
1911 * It is recommended to use this symbol table when targeting Windows. The loader
1912 * does not have notion of global symbols. Loading cplugin into mpv process will
1913 * not allow this plugin to call any of the symbols that may be available in
1914 * other modules. Instead cplugin has to link explicitly to specific PE binary,
1915 * libmpv-2.dll/mpv.exe or any other binary that may have linked mpv statically.
1916 * This limits portability of cplugin as it would need to be compiled separately
1917 * for each of target PE binary that includes mpv's symbols. Which in practice
1918 * is unrealistic, as we want one cplugin to be loaded without those restrictions.
1919 *
1920 * Instead of linking to any PE binary, we create function pointers for all mpv's
1921 * exported symbols. For convenience names of entrypoints are redefined to those
1922 * pointer, so no changes are required in cplugin source code, except of defining
1923 * MPV_CPLUGIN_DYNAMIC_SYM. Those function pointer are exported to make them
1924 * available for mpv to init with correct values during runtime, before calling
1925 * `mpv_open_cplugin`.
1926 *
1927 * Note that those pointers are decorated with `selectany` attribute, so no need
1928 * to worry about multiple definitions, linker will keep only single instance.
1929 */
1930#ifdef MPV_CPLUGIN_DYNAMIC_SYM
1931
1932#define MPV_DEFINE_SYM_PTR(name) \
1933 MPV_SELECTANY MPV_EXPORT \
1934 MPV_DECLTYPE(name) *pfn_##name;
1935
1936MPV_DEFINE_SYM_PTR(mpv_client_api_version)
1937#define mpv_client_api_version pfn_mpv_client_api_version
1938MPV_DEFINE_SYM_PTR(mpv_error_string)
1939#define mpv_error_string pfn_mpv_error_string
1940MPV_DEFINE_SYM_PTR(mpv_free)
1941#define mpv_free pfn_mpv_free
1942MPV_DEFINE_SYM_PTR(mpv_client_name)
1943#define mpv_client_name pfn_mpv_client_name
1944MPV_DEFINE_SYM_PTR(mpv_client_id)
1945#define mpv_client_id pfn_mpv_client_id
1946MPV_DEFINE_SYM_PTR(mpv_create)
1947#define mpv_create pfn_mpv_create
1948MPV_DEFINE_SYM_PTR(mpv_initialize)
1949#define mpv_initialize pfn_mpv_initialize
1950MPV_DEFINE_SYM_PTR(mpv_destroy)
1951#define mpv_destroy pfn_mpv_destroy
1952MPV_DEFINE_SYM_PTR(mpv_terminate_destroy)
1953#define mpv_terminate_destroy pfn_mpv_terminate_destroy
1954MPV_DEFINE_SYM_PTR(mpv_create_client)
1955#define mpv_create_client pfn_mpv_create_client
1956MPV_DEFINE_SYM_PTR(mpv_create_weak_client)
1957#define mpv_create_weak_client pfn_mpv_create_weak_client
1958MPV_DEFINE_SYM_PTR(mpv_load_config_file)
1959#define mpv_load_config_file pfn_mpv_load_config_file
1960MPV_DEFINE_SYM_PTR(mpv_get_time_ns)
1961#define mpv_get_time_ns pfn_mpv_get_time_ns
1962MPV_DEFINE_SYM_PTR(mpv_get_time_us)
1963#define mpv_get_time_us pfn_mpv_get_time_us
1964MPV_DEFINE_SYM_PTR(mpv_free_node_contents)
1965#define mpv_free_node_contents pfn_mpv_free_node_contents
1966MPV_DEFINE_SYM_PTR(mpv_set_option)
1967#define mpv_set_option pfn_mpv_set_option
1968MPV_DEFINE_SYM_PTR(mpv_set_option_string)
1969#define mpv_set_option_string pfn_mpv_set_option_string
1970MPV_DEFINE_SYM_PTR(mpv_command)
1971#define mpv_command pfn_mpv_command
1972MPV_DEFINE_SYM_PTR(mpv_command_node)
1973#define mpv_command_node pfn_mpv_command_node
1974MPV_DEFINE_SYM_PTR(mpv_command_ret)
1975#define mpv_command_ret pfn_mpv_command_ret
1976MPV_DEFINE_SYM_PTR(mpv_command_string)
1977#define mpv_command_string pfn_mpv_command_string
1978MPV_DEFINE_SYM_PTR(mpv_command_async)
1979#define mpv_command_async pfn_mpv_command_async
1980MPV_DEFINE_SYM_PTR(mpv_command_node_async)
1981#define mpv_command_node_async pfn_mpv_command_node_async
1982MPV_DEFINE_SYM_PTR(mpv_abort_async_command)
1983#define mpv_abort_async_command pfn_mpv_abort_async_command
1984MPV_DEFINE_SYM_PTR(mpv_set_property)
1985#define mpv_set_property pfn_mpv_set_property
1986MPV_DEFINE_SYM_PTR(mpv_set_property_string)
1987#define mpv_set_property_string pfn_mpv_set_property_string
1988MPV_DEFINE_SYM_PTR(mpv_del_property)
1989#define mpv_del_property pfn_mpv_del_property
1990MPV_DEFINE_SYM_PTR(mpv_set_property_async)
1991#define mpv_set_property_async pfn_mpv_set_property_async
1992MPV_DEFINE_SYM_PTR(mpv_get_property)
1993#define mpv_get_property pfn_mpv_get_property
1994MPV_DEFINE_SYM_PTR(mpv_get_property_string)
1995#define mpv_get_property_string pfn_mpv_get_property_string
1996MPV_DEFINE_SYM_PTR(mpv_get_property_osd_string)
1997#define mpv_get_property_osd_string pfn_mpv_get_property_osd_string
1998MPV_DEFINE_SYM_PTR(mpv_get_property_async)
1999#define mpv_get_property_async pfn_mpv_get_property_async
2000MPV_DEFINE_SYM_PTR(mpv_observe_property)
2001#define mpv_observe_property pfn_mpv_observe_property
2002MPV_DEFINE_SYM_PTR(mpv_unobserve_property)
2003#define mpv_unobserve_property pfn_mpv_unobserve_property
2004MPV_DEFINE_SYM_PTR(mpv_event_name)
2005#define mpv_event_name pfn_mpv_event_name
2006MPV_DEFINE_SYM_PTR(mpv_event_to_node)
2007#define mpv_event_to_node pfn_mpv_event_to_node
2008MPV_DEFINE_SYM_PTR(mpv_request_event)
2009#define mpv_request_event pfn_mpv_request_event
2010MPV_DEFINE_SYM_PTR(mpv_request_log_messages)
2011#define mpv_request_log_messages pfn_mpv_request_log_messages
2012MPV_DEFINE_SYM_PTR(mpv_wait_event)
2013#define mpv_wait_event pfn_mpv_wait_event
2014MPV_DEFINE_SYM_PTR(mpv_wakeup)
2015#define mpv_wakeup pfn_mpv_wakeup
2016MPV_DEFINE_SYM_PTR(mpv_set_wakeup_callback)
2017#define mpv_set_wakeup_callback pfn_mpv_set_wakeup_callback
2018MPV_DEFINE_SYM_PTR(mpv_wait_async_requests)
2019#define mpv_wait_async_requests pfn_mpv_wait_async_requests
2020MPV_DEFINE_SYM_PTR(mpv_hook_add)
2021#define mpv_hook_add pfn_mpv_hook_add
2022MPV_DEFINE_SYM_PTR(mpv_hook_continue)
2023#define mpv_hook_continue pfn_mpv_hook_continue
2024MPV_DEFINE_SYM_PTR(mpv_get_wakeup_pipe)
2025#define mpv_get_wakeup_pipe pfn_mpv_get_wakeup_pipe
2026
2027#endif
2028
2029#ifdef __cplusplus
2030}
2031#endif
2032
2033#endif
2034