Advertisement
Guest User

Untitled

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