libmpv  20200718-git-96cdf53
development library for the MPV media player
Looking for a C++ dev?
I'm looking for work. Hire me!
render.h
Go to the documentation of this file.
1 /* Copyright (C) 2018 the mpv developers
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14  */
15 
16 #ifndef MPV_CLIENT_API_RENDER_H_
17 #define MPV_CLIENT_API_RENDER_H_
18 
19 #include "client.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * Overview
27  * --------
28  *
29  * This API can be used to make mpv render using supported graphic APIs (such
30  * as OpenGL). It can be used to handle video display.
31  *
32  * The renderer needs to be created with mpv_render_context_create() before
33  * you start playback (or otherwise cause a VO to be created). Then (with most
34  * backends) mpv_render_context_render() can be used to explicitly render the
35  * current video frame. Use mpv_render_context_set_update_callback() to get
36  * notified when there is a new frame to draw.
37  *
38  * Preferably rendering should be done in a separate thread. If you call
39  * normal libmpv API functions on the renderer thread, deadlocks can result
40  * (these are made non-fatal with timeouts, but user experience will obviously
41  * suffer). See "Threading" section below.
42  *
43  * You can output and embed video without this API by setting the mpv "wid"
44  * option to a native window handle (see "Embedding the video window" section
45  * in the client.h header). In general, using the render API is recommended,
46  * because window embedding can cause various issues, especially with GUI
47  * toolkits and certain platforms.
48  *
49  * Supported backends
50  * ------------------
51  *
52  * OpenGL: via MPV_RENDER_API_TYPE_OPENGL, see render_gl.h header.
53  * Software: via MPV_RENDER_API_TYPE_SW, see section "Software renderer"
54  *
55  * Threading
56  * ---------
57  *
58  * You are recommended to do rendering on a separate thread than normal libmpv
59  * use.
60  *
61  * The mpv_render_* functions can be called from any thread, under the
62  * following conditions:
63  * - only one of the mpv_render_* functions can be called at the same time
64  * (unless they belong to different mpv cores created by mpv_create())
65  * - never can be called from within the callbacks set with
66  * mpv_set_wakeup_callback() or mpv_render_context_set_update_callback()
67  * - if the OpenGL backend is used, for all functions the OpenGL context
68  * must be "current" in the calling thread, and it must be the same OpenGL
69  * context as the mpv_render_context was created with. Otherwise, undefined
70  * behavior will occur.
71  * - the thread does not call libmpv API functions other than the mpv_render_*
72  * functions, except APIs which are declared as safe (see below). Likewise,
73  * there must be no lock or wait dependency from the render thread to a
74  * thread using other libmpv functions. Basically, the situation that your
75  * render thread waits for a "not safe" libmpv API function to return must
76  * not happen. If you ignore this requirement, deadlocks can happen, which
77  * are made non-fatal with timeouts; then playback quality will be degraded,
78  * and the message
79  * mpv_render_context_render() not being called or stuck.
80  * is logged. If you set MPV_RENDER_PARAM_ADVANCED_CONTROL, you promise that
81  * this won't happen, and must absolutely guarantee it, or a real deadlock
82  * will freeze the mpv core thread forever.
83  *
84  * libmpv functions which are safe to call from a render thread are:
85  * - functions marked with "Safe to be called from mpv render API threads."
86  * - client.h functions which don't have an explicit or implicit mpv_handle
87  * parameter
88  * - mpv_render_* functions; but only for the same mpv_render_context pointer.
89  * If the pointer is different, mpv_render_context_free() is not safe. (The
90  * reason is that if MPV_RENDER_PARAM_ADVANCED_CONTROL is set, it may have
91  * to process still queued requests from the core, which it can do only for
92  * the current context, while requests for other contexts would deadlock.
93  * Also, it may have to wait and block for the core to terminate the video
94  * chain to make sure no resources are used after context destruction.)
95  * - if the mpv_handle parameter refers to a different mpv core than the one
96  * you're rendering for (very obscure, but allowed)
97  *
98  * Note about old libmpv version:
99  *
100  * Before API version 1.105 (basically in mpv 0.29.x), simply enabling
101  * MPV_RENDER_PARAM_ADVANCED_CONTROL could cause deadlock issues. This can
102  * be worked around by setting the "vd-lavc-dr" option to "no".
103  * In addition, you were required to call all mpv_render*() API functions
104  * from the same thread on which mpv_render_context_create() was originally
105  * run (for the same the mpv_render_context). Not honoring it led to UB
106  * (deadlocks, use of invalid pthread_t handles), even if you moved your GL
107  * context to a different thread correctly.
108  * These problems were addressed in API version 1.105 (mpv 0.30.0).
109  *
110  * Context and handle lifecycle
111  * ----------------------------
112  *
113  * Video initialization will fail if the render context was not initialized yet
114  * (with mpv_render_context_create()), or it will revert to a VO that creates
115  * its own window.
116  *
117  * Currently, there can be only 1 mpv_render_context at a time per mpv core.
118  *
119  * Calling mpv_render_context_free() while a VO is using the render context is
120  * active will disable video.
121  *
122  * You must free the context with mpv_render_context_free() before the mpv core
123  * is destroyed. If this doesn't happen, undefined behavior will result.
124  *
125  * Software renderer
126  * -----------------
127  *
128  * MPV_RENDER_API_TYPE_SW provides an extremely simple (but slow) renderer to
129  * memory surfaces. You probably don't want to use this. Use other render API
130  * types, or other methods of video embedding.
131  *
132  * Use mpv_render_context_create() with MPV_RENDER_PARAM_API_TYPE set to
133  * MPV_RENDER_API_TYPE_SW.
134  *
135  * Call mpv_render_context_render() with various MPV_RENDER_PARAM_SW_* fields
136  * to render the video frame to an in-memory surface. The following fields are
137  * required: MPV_RENDER_PARAM_SW_SIZE, MPV_RENDER_PARAM_SW_FORMAT,
138  * MPV_RENDER_PARAM_SW_STRIDE, MPV_RENDER_PARAM_SW_POINTER.
139  *
140  * This method of rendering is very slow, because everything, including color
141  * conversion, scaling, and OSD rendering, is done on the CPU, single-threaded.
142  * In particular, large video or display sizes, as well as presence of OSD or
143  * subtitles can make it too slow for realtime. As with other software rendering
144  * VOs, setting "sw-fast" may help. Enabling or disabling zimg may help,
145  * depending on the platform.
146  *
147  * In addition, certain multimedia job creation measures like HDR may not work
148  * properly, and will have to be manually handled by for example inserting
149  * filters.
150  *
151  * This API is not really suitable to extract individual frames from video etc.
152  * (basically non-playback uses) - there are better libraries for this. It can
153  * be used this way, but it may be clunky and tricky.
154  *
155  * Further notes:
156  * - MPV_RENDER_PARAM_FLIP_Y is currently ignored (unsupported)
157  * - MPV_RENDER_PARAM_DEPTH is ignored (meaningless)
158  */
159 
160 /**
161  * Opaque context, returned by mpv_render_context_create().
162  */
164 
165 /**
166  * Parameters for mpv_render_param (which is used in a few places such as
167  * mpv_render_context_create().
168  *
169  * Also see mpv_render_param for conventions and how to use it.
170  */
171 typedef enum mpv_render_param_type {
172  /**
173  * Not a valid value, but also used to terminate a params array. Its value
174  * is always guaranteed to be 0 (even if the ABI changes in the future).
175  */
177  /**
178  * The render API to use. Valid for mpv_render_context_create().
179  *
180  * Type: char*
181  *
182  * Defined APIs:
183  *
184  * MPV_RENDER_API_TYPE_OPENGL:
185  * OpenGL desktop 2.1 or later (preferably core profile compatible to
186  * OpenGL 3.2), or OpenGLES 2.0 or later.
187  * Providing MPV_RENDER_PARAM_OPENGL_INIT_PARAMS is required.
188  * It is expected that an OpenGL context is valid and "current" when
189  * calling mpv_render_* functions (unless specified otherwise). It
190  * must be the same context for the same mpv_render_context.
191  */
193  /**
194  * Required parameters for initializing the OpenGL renderer. Valid for
195  * mpv_render_context_create().
196  * Type: mpv_opengl_init_params*
197  */
199  /**
200  * Describes a GL render target. Valid for mpv_render_context_render().
201  * Type: mpv_opengl_fbo*
202  */
204  /**
205  * Control flipped rendering. Valid for mpv_render_context_render().
206  * Type: int*
207  * If the value is set to 0, render normally. Otherwise, render it flipped,
208  * which is needed e.g. when rendering to an OpenGL default framebuffer
209  * (which has a flipped coordinate system).
210  */
212  /**
213  * Control surface depth. Valid for mpv_render_context_render().
214  * Type: int*
215  * This implies the depth of the surface passed to the render function in
216  * bits per channel. If omitted or set to 0, the renderer will assume 8.
217  * Typically used to control dithering.
218  */
220  /**
221  * ICC profile blob. Valid for mpv_render_context_set_parameter().
222  * Type: mpv_byte_array*
223  * Set an ICC profile for use with the "icc-profile-auto" option. (If the
224  * option is not enabled, the ICC data will not be used.)
225  */
227  /**
228  * Ambient light in lux. Valid for mpv_render_context_set_parameter().
229  * Type: int*
230  * This can be used for automatic gamma correction.
231  */
233  /**
234  * X11 Display, sometimes used for hwdec. Valid for
235  * mpv_render_context_create(). The Display must stay valid for the lifetime
236  * of the mpv_render_context.
237  * Type: Display*
238  */
240  /**
241  * Wayland display, sometimes used for hwdec. Valid for
242  * mpv_render_context_create(). The wl_display must stay valid for the
243  * lifetime of the mpv_render_context.
244  * Type: struct wl_display*
245  */
247  /**
248  * Better control about rendering and enabling some advanced features. Valid
249  * for mpv_render_context_create().
250  *
251  * This conflates multiple requirements the API user promises to abide if
252  * this option is enabled:
253  *
254  * - The API user's render thread, which is calling the mpv_render_*()
255  * functions, never waits for the core. Otherwise deadlocks can happen.
256  * See "Threading" section.
257  * - The callback set with mpv_render_context_set_update_callback() can now
258  * be called even if there is no new frame. The API user should call the
259  * mpv_render_context_update() function, and interpret the return value
260  * for whether a new frame should be rendered.
261  * - Correct functionality is impossible if the update callback is not set,
262  * or not set soon enough after mpv_render_context_create() (the core can
263  * block while waiting for you to call mpv_render_context_update(), and
264  * if the update callback is not correctly set, it will deadlock, or
265  * block for too long).
266  *
267  * In general, setting this option will enable the following features (and
268  * possibly more):
269  *
270  * - "Direct rendering", which means the player decodes directly to a
271  * texture, which saves a copy per video frame ("vd-lavc-dr" option
272  * needs to be enabled, and the rendering backend as well as the
273  * underlying GPU API/driver needs to have support for it).
274  * - Rendering screenshots with the GPU API if supported by the backend
275  * (instead of using a suboptimal software fallback via libswscale).
276  *
277  * Warning: do not just add this without reading the "Threading" section
278  * above, and then wondering that deadlocks happen. The
279  * requirements are tricky. But also note that even if advanced
280  * control is disabled, not adhering to the rules will lead to
281  * playback problems. Enabling advanced controls simply makes
282  * violating these rules fatal.
283  *
284  * Type: int*: 0 for disable (default), 1 for enable
285  */
287  /**
288  * Return information about the next frame to render. Valid for
289  * mpv_render_context_get_info().
290  *
291  * Type: mpv_render_frame_info*
292  *
293  * It strictly returns information about the _next_ frame. The implication
294  * is that e.g. mpv_render_context_update()'s return value will have
295  * MPV_RENDER_UPDATE_FRAME set, and the user is supposed to call
296  * mpv_render_context_render(). If there is no next frame, then the
297  * return value will have is_valid set to 0.
298  */
300  /**
301  * Enable or disable video timing. Valid for mpv_render_context_render().
302  *
303  * Type: int*: 0 for disable, 1 for enable (default)
304  *
305  * When video is timed to audio, the player attempts to render video a bit
306  * ahead, and then do a blocking wait until the target display time is
307  * reached. This blocks mpv_render_context_render() for up to the amount
308  * specified with the "video-timing-offset" global option. You can set
309  * this parameter to 0 to disable this kind of waiting. If you do, it's
310  * recommended to use the target time value in mpv_render_frame_info to
311  * wait yourself, or to set the "video-timing-offset" to 0 instead.
312  *
313  * Disabling this without doing anything in addition will result in A/V sync
314  * being slightly off.
315  */
317  /**
318  * Use to skip rendering in mpv_render_context_render().
319  *
320  * Type: int*: 0 for rendering (default), 1 for skipping
321  *
322  * If this is set, you don't need to pass a target surface to the render
323  * function (and if you do, it's completely ignored). This can still call
324  * into the lower level APIs (i.e. if you use OpenGL, the OpenGL context
325  * must be set).
326  *
327  * Be aware that the render API will consider this frame as having been
328  * rendered. All other normal rules also apply, for example about whether
329  * you have to call mpv_render_context_report_swap(). It also does timing
330  * in the same way.
331  */
333  /**
334  * Deprecated. Not supported. Use MPV_RENDER_PARAM_DRM_DISPLAY_V2 instead.
335  * Type : struct mpv_opengl_drm_params*
336  */
338  /**
339  * DRM draw surface size, contains draw surface dimensions.
340  * Valid for mpv_render_context_create().
341  * Type : struct mpv_opengl_drm_draw_surface_size*
342  */
344  /**
345  * DRM display, contains drm display handles.
346  * Valid for mpv_render_context_create().
347  * Type : struct mpv_opengl_drm_params_v2*
348  */
350  /**
351  * MPV_RENDER_API_TYPE_SW only: rendering target surface size, mandatory.
352  * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_create().
353  * Type: int[2] (e.g.: int s[2] = {w, h}; param.data = &s[0];)
354  *
355  * The video frame is transformed as with other VOs. Typically, this means
356  * the video gets scaled and black bars are added if the video size or
357  * aspect ratio mismatches with the target size.
358  */
360  /**
361  * MPV_RENDER_API_TYPE_SW only: rendering target surface pixel format,
362  * mandatory.
363  * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_create().
364  * Type: char* (e.g.: char *f = "rgb0"; param.data = f;)
365  *
366  * Valid values are:
367  * "rgb0", "bgr0", "0bgr", "0rgb"
368  * 4 bytes per pixel RGB, 1 byte (8 bit) per component, component bytes
369  * with increasing address from left to right (e.g. "rgb0" has r at
370  * address 0), the "0" component contains uninitialized garbage (often
371  * the value 0, but not necessarily; the bad naming is inherited from
372  * FFmpeg)
373  * "rgb24"
374  * 3 bytes per pixel RGB. This is strongly discouraged because it is
375  * very slow.
376  * other
377  * The API may accept other pixel formats, using mpv internal format
378  * names, as long as it's internally marked as RGB, has exactly 1
379  * plane, and is supported as conversion output. It is not a good idea
380  * to rely on any of these. Their semantics and handling could change.
381  */
383  /**
384  * MPV_RENDER_API_TYPE_SW only: rendering target surface bytes per line,
385  * mandatory.
386  * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_create().
387  * Type: size_t*
388  *
389  * This is the number of bytes between a pixel (x, y) and (x, y + 1) on the
390  * target surface. It must be a multiple of the pixel size, and have space
391  * for the surface width as specified by MPV_RENDER_PARAM_SW_SIZE.
392  *
393  * It should be a multiple of 64 to facilitate fast SIMD operation.
394  */
396  /*
397  * MPV_RENDER_API_TYPE_SW only: rendering target surface pixel data pointer,
398  * mandatory.
399  * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_create().
400  * Type: void*
401  *
402  * This points to the first pixel at the left/top corner (0, 0). In
403  * particular, each line y starts at (pointer + stride * y). Upon rendering,
404  * all data between pointer and (pointer + stride * h) is overwritten.
405  * Whether the padding between (w, y) and (0, y + 1) is overwritten is left
406  * unspecified (it should not be, but unfortunately some scaler backends
407  * will do it anyway). It is assumed that even the padding after the last
408  * line (starting at bytepos(w, h) until (pointer + stride * h)) is
409  * writable.
410  */
413 
414 /**
415  * For backwards compatibility with the old naming of
416  * MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
417  */
418 #define MPV_RENDER_PARAM_DRM_OSD_SIZE MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
419 
420 /**
421  * Used to pass arbitrary parameters to some mpv_render_* functions. The
422  * meaning of the data parameter is determined by the type, and each
423  * MPV_RENDER_PARAM_* documents what type the value must point to.
424  *
425  * Each value documents the required data type as the pointer you cast to
426  * void* and set on mpv_render_param.data. For example, if MPV_RENDER_PARAM_FOO
427  * documents the type as Something* , then the code should look like this:
428  *
429  * Something foo = {...};
430  * mpv_render_param param;
431  * param.type = MPV_RENDER_PARAM_FOO;
432  * param.data = & foo;
433  *
434  * Normally, the data field points to exactly 1 object. If the type is char*,
435  * it points to a 0-terminated string.
436  *
437  * In all cases (unless documented otherwise) the pointers need to remain
438  * valid during the call only. Unless otherwise documented, the API functions
439  * will not write to the params array or any data pointed to it.
440  *
441  * As a convention, parameter arrays are always terminated by type==0. There
442  * is no specific order of the parameters required. The order of the 2 fields in
443  * this struct is guaranteed (even after ABI changes).
444  */
445 typedef struct mpv_render_param {
447  void *data;
449 
450 
451 /**
452  * Predefined values for MPV_RENDER_PARAM_API_TYPE.
453  */
454 // See render_gl.h
455 #define MPV_RENDER_API_TYPE_OPENGL "opengl"
456 // See section "Software renderer"
457 #define MPV_RENDER_API_TYPE_SW "sw"
458 
459 /**
460  * Flags used in mpv_render_frame_info.flags. Each value represents a bit in it.
461  */
463  /**
464  * Set if there is actually a next frame. If unset, there is no next frame
465  * yet, and other flags and fields that require a frame to be queued will
466  * be unset.
467  *
468  * This is set for _any_ kind of frame, even for redraw requests.
469  *
470  * Note that when this is unset, it simply means no new frame was
471  * decoded/queued yet, not necessarily that the end of the video was
472  * reached. A new frame can be queued after some time.
473  *
474  * If the return value of mpv_render_context_render() had the
475  * MPV_RENDER_UPDATE_FRAME flag set, this flag will usually be set as well,
476  * unless the frame is rendered, or discarded by other asynchronous events.
477  */
479  /**
480  * If set, the frame is not an actual new video frame, but a redraw request.
481  * For example if the video is paused, and an option that affects video
482  * rendering was changed (or any other reason), an update request can be
483  * issued and this flag will be set.
484  *
485  * Typically, redraw frames will not be subject to video timing.
486  *
487  * Implies MPV_RENDER_FRAME_INFO_PRESENT.
488  */
490  /**
491  * If set, this is supposed to reproduce the previous frame perfectly. This
492  * is usually used for certain "video-sync" options ("display-..." modes).
493  * Typically the renderer will blit the video from a FBO. Unset otherwise.
494  *
495  * Implies MPV_RENDER_FRAME_INFO_PRESENT.
496  */
498  /**
499  * If set, the player timing code expects that the user thread blocks on
500  * vsync (by either delaying the render call, or by making a call to
501  * mpv_render_context_report_swap() at vsync time).
502  *
503  * Implies MPV_RENDER_FRAME_INFO_PRESENT.
504  */
507 
508 /**
509  * Information about the next video frame that will be rendered. Can be
510  * retrieved with MPV_RENDER_PARAM_NEXT_FRAME_INFO.
511  */
512 typedef struct mpv_render_frame_info {
513  /**
514  * A bitset of mpv_render_frame_info_flag values (i.e. multiple flags are
515  * combined with bitwise or).
516  */
517  uint64_t flags;
518  /**
519  * Absolute time at which the frame is supposed to be displayed. This is in
520  * the same unit and base as the time returned by mpv_get_time_us(). For
521  * frames that are redrawn, or if vsync locked video timing is used (see
522  * "video-sync" option), then this can be 0. The "video-timing-offset"
523  * option determines how much "headroom" the render thread gets (but a high
524  * enough frame rate can reduce it anyway). mpv_render_context_render() will
525  * normally block until the time is elapsed, unless you pass it
526  * MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME = 0.
527  */
528  int64_t target_time;
530 
531 /**
532  * Initialize the renderer state. Depending on the backend used, this will
533  * access the underlying GPU API and initialize its own objects.
534  *
535  * You must free the context with mpv_render_context_free(). Not doing so before
536  * the mpv core is destroyed may result in memory leaks or crashes.
537  *
538  * Currently, only at most 1 context can exists per mpv core (it represents the
539  * main video output).
540  *
541  * You should pass the following parameters:
542  * - MPV_RENDER_PARAM_API_TYPE to select the underlying backend/GPU API.
543  * - Backend-specific init parameter, like MPV_RENDER_PARAM_OPENGL_INIT_PARAMS.
544  * - Setting MPV_RENDER_PARAM_ADVANCED_CONTROL and following its rules is
545  * strongly recommended.
546  * - If you want to use hwdec, possibly hwdec interop resources.
547  *
548  * @param res set to the context (on success) or NULL (on failure). The value
549  * is never read and always overwritten.
550  * @param mpv handle used to get the core (the mpv_render_context won't depend
551  * on this specific handle, only the core referenced by it)
552  * @param params an array of parameters, terminated by type==0. It's left
553  * unspecified what happens with unknown parameters. At least
554  * MPV_RENDER_PARAM_API_TYPE is required, and most backends will
555  * require another backend-specific parameter.
556  * @return error code, including but not limited to:
557  * MPV_ERROR_UNSUPPORTED: the OpenGL version is not supported
558  * (or required extensions are missing)
559  * MPV_ERROR_NOT_IMPLEMENTED: an unknown API type was provided, or
560  * support for the requested API was not
561  * built in the used libmpv binary.
562  * MPV_ERROR_INVALID_PARAMETER: at least one of the provided parameters was
563  * not valid.
564  */
566  mpv_render_param *params);
567 
568 /**
569  * Attempt to change a single parameter. Not all backends and parameter types
570  * support all kinds of changes.
571  *
572  * @param ctx a valid render context
573  * @param param the parameter type and data that should be set
574  * @return error code. If a parameter could actually be changed, this returns
575  * success, otherwise an error code depending on the parameter type
576  * and situation.
577  */
579  mpv_render_param param);
580 
581 /**
582  * Retrieve information from the render context. This is NOT a counterpart to
583  * mpv_render_context_set_parameter(), because you generally can't read
584  * parameters set with it, and this function is not meant for this purpose.
585  * Instead, this is for communicating information from the renderer back to the
586  * user. See mpv_render_param_type; entries which support this function
587  * explicitly mention it, and for other entries you can assume it will fail.
588  *
589  * You pass param with param.type set and param.data pointing to a variable
590  * of the required data type. The function will then overwrite that variable
591  * with the returned value (at least on success).
592  *
593  * @param ctx a valid render context
594  * @param param the parameter type and data that should be retrieved
595  * @return error code. If a parameter could actually be retrieved, this returns
596  * success, otherwise an error code depending on the parameter type
597  * and situation. MPV_ERROR_NOT_IMPLEMENTED is used for unknown
598  * param.type, or if retrieving it is not supported.
599  */
601  mpv_render_param param);
602 
603 typedef void (*mpv_render_update_fn)(void *cb_ctx);
604 
605 /**
606  * Set the callback that notifies you when a new video frame is available, or
607  * if the video display configuration somehow changed and requires a redraw.
608  * Similar to mpv_set_wakeup_callback(), you must not call any mpv API from
609  * the callback, and all the other listed restrictions apply (such as not
610  * exiting the callback by throwing exceptions).
611  *
612  * This can be called from any thread, except from an update callback. In case
613  * of the OpenGL backend, no OpenGL state or API is accessed.
614  *
615  * Calling this will raise an update callback immediately.
616  *
617  * @param callback callback(callback_ctx) is called if the frame should be
618  * redrawn
619  * @param callback_ctx opaque argument to the callback
620  */
622  mpv_render_update_fn callback,
623  void *callback_ctx);
624 
625 /**
626  * The API user is supposed to call this when the update callback was invoked
627  * (like all mpv_render_* functions, this has to happen on the render thread,
628  * and _not_ from the update callback itself).
629  *
630  * This is optional if MPV_RENDER_PARAM_ADVANCED_CONTROL was not set (default).
631  * Otherwise, it's a hard requirement that this is called after each update
632  * callback. If multiple update callback happened, and the function could not
633  * be called sooner, it's OK to call it once after the last callback.
634  *
635  * If an update callback happens during or after this function, the function
636  * must be called again at the soonest possible time.
637  *
638  * If MPV_RENDER_PARAM_ADVANCED_CONTROL was set, this will do additional work
639  * such as allocating textures for the video decoder.
640  *
641  * @return a bitset of mpv_render_update_flag values (i.e. multiple flags are
642  * combined with bitwise or). Typically, this will tell the API user
643  * what should happen next. E.g. if the MPV_RENDER_UPDATE_FRAME flag is
644  * set, mpv_render_context_render() should be called. If flags unknown
645  * to the API user are set, or if the return value is 0, nothing needs
646  * to be done.
647  */
649 
650 /**
651  * Flags returned by mpv_render_context_update(). Each value represents a bit
652  * in the function's return value.
653  */
655  /**
656  * A new video frame must be rendered. mpv_render_context_render() must be
657  * called.
658  */
661 
662 /**
663  * Render video.
664  *
665  * Typically renders the video to a target surface provided via mpv_render_param
666  * (the details depend on the backend in use). Options like "panscan" are
667  * applied to determine which part of the video should be visible and how the
668  * video should be scaled. You can change these options at runtime by using the
669  * mpv property API.
670  *
671  * The renderer will reconfigure itself every time the target surface
672  * configuration (such as size) is changed.
673  *
674  * This function implicitly pulls a video frame from the internal queue and
675  * renders it. If no new frame is available, the previous frame is redrawn.
676  * The update callback set with mpv_render_context_set_update_callback()
677  * notifies you when a new frame was added. The details potentially depend on
678  * the backends and the provided parameters.
679  *
680  * Generally, libmpv will invoke your update callback some time before the video
681  * frame should be shown, and then lets this function block until the supposed
682  * display time. This will limit your rendering to video FPS. You can prevent
683  * this by setting the "video-timing-offset" global option to 0. (This applies
684  * only to "audio" video sync mode.)
685  *
686  * You should pass the following parameters:
687  * - Backend-specific target object, such as MPV_RENDER_PARAM_OPENGL_FBO.
688  * - Possibly transformations, such as MPV_RENDER_PARAM_FLIP_Y.
689  *
690  * @param ctx a valid render context
691  * @param params an array of parameters, terminated by type==0. Which parameters
692  * are required depends on the backend. It's left unspecified what
693  * happens with unknown parameters.
694  * @return error code
695  */
697 
698 /**
699  * Tell the renderer that a frame was flipped at the given time. This is
700  * optional, but can help the player to achieve better timing.
701  *
702  * Note that calling this at least once informs libmpv that you will use this
703  * function. If you use it inconsistently, expect bad video playback.
704  *
705  * If this is called while no video is initialized, it is ignored.
706  *
707  * @param ctx a valid render context
708  */
710 
711 /**
712  * Destroy the mpv renderer state.
713  *
714  * If video is still active (e.g. a file playing), video will be disabled
715  * forcefully.
716  *
717  * @param ctx a valid render context. After this function returns, this is not
718  * a valid pointer anymore. NULL is also allowed and does nothing.
719  */
721 
722 #ifdef __cplusplus
723 }
724 #endif
725 
726 #endif
MPV_RENDER_PARAM_SKIP_RENDERING
@ MPV_RENDER_PARAM_SKIP_RENDERING
Use to skip rendering in mpv_render_context_render().
Definition: render.h:332
MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
@ MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
DRM draw surface size, contains draw surface dimensions.
Definition: render.h:343
MPV_RENDER_PARAM_ADVANCED_CONTROL
@ MPV_RENDER_PARAM_ADVANCED_CONTROL
Better control about rendering and enabling some advanced features.
Definition: render.h:286
mpv_render_frame_info
struct mpv_render_frame_info mpv_render_frame_info
Information about the next video frame that will be rendered.
mpv_render_context
struct mpv_render_context mpv_render_context
Opaque context, returned by mpv_render_context_create().
Definition: render.h:163
mpv_render_frame_info::target_time
int64_t target_time
Absolute time at which the frame is supposed to be displayed.
Definition: render.h:528
mpv_render_context_update
uint64_t mpv_render_context_update(mpv_render_context *ctx)
The API user is supposed to call this when the update callback was invoked (like all mpv_render_* fun...
MPV_RENDER_PARAM_WL_DISPLAY
@ MPV_RENDER_PARAM_WL_DISPLAY
Wayland display, sometimes used for hwdec.
Definition: render.h:246
MPV_RENDER_PARAM_SW_FORMAT
@ MPV_RENDER_PARAM_SW_FORMAT
MPV_RENDER_API_TYPE_SW only: rendering target surface pixel format, mandatory.
Definition: render.h:382
mpv_render_param::data
void * data
Definition: render.h:447
mpv_render_param_type
mpv_render_param_type
Parameters for mpv_render_param (which is used in a few places such as mpv_render_context_create().
Definition: render.h:171
MPV_RENDER_PARAM_API_TYPE
@ MPV_RENDER_PARAM_API_TYPE
The render API to use.
Definition: render.h:192
MPV_RENDER_PARAM_AMBIENT_LIGHT
@ MPV_RENDER_PARAM_AMBIENT_LIGHT
Ambient light in lux.
Definition: render.h:232
mpv_render_frame_info::flags
uint64_t flags
A bitset of mpv_render_frame_info_flag values (i.e.
Definition: render.h:517
mpv_render_frame_info_flag
mpv_render_frame_info_flag
Flags used in mpv_render_frame_info.flags.
Definition: render.h:462
mpv_render_context_create
int mpv_render_context_create(mpv_render_context **res, mpv_handle *mpv, mpv_render_param *params)
Initialize the renderer state.
MPV_RENDER_UPDATE_FRAME
@ MPV_RENDER_UPDATE_FRAME
A new video frame must be rendered.
Definition: render.h:659
MPV_RENDER_FRAME_INFO_PRESENT
@ MPV_RENDER_FRAME_INFO_PRESENT
Set if there is actually a next frame.
Definition: render.h:478
MPV_RENDER_PARAM_DRM_DISPLAY_V2
@ MPV_RENDER_PARAM_DRM_DISPLAY_V2
DRM display, contains drm display handles.
Definition: render.h:349
mpv_render_context_render
int mpv_render_context_render(mpv_render_context *ctx, mpv_render_param *params)
Render video.
MPV_RENDER_PARAM_DEPTH
@ MPV_RENDER_PARAM_DEPTH
Control surface depth.
Definition: render.h:219
mpv_render_frame_info
Information about the next video frame that will be rendered.
Definition: render.h:512
MPV_RENDER_PARAM_ICC_PROFILE
@ MPV_RENDER_PARAM_ICC_PROFILE
ICC profile blob.
Definition: render.h:226
mpv_render_context_report_swap
void mpv_render_context_report_swap(mpv_render_context *ctx)
Tell the renderer that a frame was flipped at the given time.
mpv_render_param::type
enum mpv_render_param_type type
Definition: render.h:446
mpv_render_update_fn
void(* mpv_render_update_fn)(void *cb_ctx)
Definition: render.h:603
MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME
@ MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME
Enable or disable video timing.
Definition: render.h:316
mpv_render_update_flag
mpv_render_update_flag
Flags returned by mpv_render_context_update().
Definition: render.h:654
MPV_RENDER_PARAM_NEXT_FRAME_INFO
@ MPV_RENDER_PARAM_NEXT_FRAME_INFO
Return information about the next frame to render.
Definition: render.h:299
mpv_render_context_get_info
int mpv_render_context_get_info(mpv_render_context *ctx, mpv_render_param param)
Retrieve information from the render context.
MPV_RENDER_FRAME_INFO_REPEAT
@ MPV_RENDER_FRAME_INFO_REPEAT
If set, this is supposed to reproduce the previous frame perfectly.
Definition: render.h:497
mpv_render_context_free
void mpv_render_context_free(mpv_render_context *ctx)
Destroy the mpv renderer state.
mpv_render_context_set_parameter
int mpv_render_context_set_parameter(mpv_render_context *ctx, mpv_render_param param)
Attempt to change a single parameter.
mpv_render_context_flag
enum mpv_render_update_flag mpv_render_context_flag
Flags returned by mpv_render_context_update().
MPV_RENDER_PARAM_X11_DISPLAY
@ MPV_RENDER_PARAM_X11_DISPLAY
X11 Display, sometimes used for hwdec.
Definition: render.h:239
mpv_handle
struct mpv_handle mpv_handle
Client context used by the client API.
Definition: client.h:256
MPV_RENDER_PARAM_DRM_DISPLAY
@ MPV_RENDER_PARAM_DRM_DISPLAY
Deprecated.
Definition: render.h:337
mpv_render_context_set_update_callback
void mpv_render_context_set_update_callback(mpv_render_context *ctx, mpv_render_update_fn callback, void *callback_ctx)
Set the callback that notifies you when a new video frame is available, or if the video display confi...
MPV_RENDER_PARAM_OPENGL_INIT_PARAMS
@ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS
Required parameters for initializing the OpenGL renderer.
Definition: render.h:198
mpv_render_param
struct mpv_render_param mpv_render_param
Used to pass arbitrary parameters to some mpv_render_* functions.
mpv_render_param
Used to pass arbitrary parameters to some mpv_render_* functions.
Definition: render.h:445
MPV_RENDER_PARAM_INVALID
@ MPV_RENDER_PARAM_INVALID
Not a valid value, but also used to terminate a params array.
Definition: render.h:176
MPV_RENDER_FRAME_INFO_REDRAW
@ MPV_RENDER_FRAME_INFO_REDRAW
If set, the frame is not an actual new video frame, but a redraw request.
Definition: render.h:489
MPV_RENDER_PARAM_SW_SIZE
@ MPV_RENDER_PARAM_SW_SIZE
MPV_RENDER_API_TYPE_SW only: rendering target surface size, mandatory.
Definition: render.h:359
MPV_RENDER_PARAM_FLIP_Y
@ MPV_RENDER_PARAM_FLIP_Y
Control flipped rendering.
Definition: render.h:211
MPV_RENDER_PARAM_SW_STRIDE
@ MPV_RENDER_PARAM_SW_STRIDE
MPV_RENDER_API_TYPE_SW only: rendering target surface bytes per line, mandatory.
Definition: render.h:395
client.h
MPV_RENDER_PARAM_OPENGL_FBO
@ MPV_RENDER_PARAM_OPENGL_FBO
Describes a GL render target.
Definition: render.h:203
MPV_RENDER_PARAM_SW_POINTER
@ MPV_RENDER_PARAM_SW_POINTER
Definition: render.h:411
MPV_RENDER_FRAME_INFO_BLOCK_VSYNC
@ MPV_RENDER_FRAME_INFO_BLOCK_VSYNC
If set, the player timing code expects that the user thread blocks on vsync (by either delaying the r...
Definition: render.h:505