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