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