libmpv  20200718-git-96cdf53
development library for the MPV media player
Looking for a C++ dev?
I'm looking for work. Hire me!
opengl_cb.h File Reference
#include "client.h"
Include dependency graph for opengl_cb.h:

Go to the source code of this file.

Classes

struct  mpv_opengl_cb_window_pos
 
struct  mpv_opengl_cb_drm_params
 

Typedefs

typedef struct mpv_opengl_cb_context mpv_opengl_cb_context
 nVidia/Linux via VDPAU requires GLX, which does not have this problem (the GLX API can return the current X11 Display). More...
 
typedef void(* mpv_opengl_cb_update_fn) (void *cb_ctx)
 
typedef void *(* mpv_opengl_cb_get_proc_address_fn) (void *fn_ctx, const char *name)
 

Functions

void mpv_opengl_cb_set_update_callback (mpv_opengl_cb_context *ctx, mpv_opengl_cb_update_fn callback, void *callback_ctx)
 Set the callback that notifies you when a new video frame is available, or if the video display configuration somehow changed and requires a redraw. More...
 
int mpv_opengl_cb_init_gl (mpv_opengl_cb_context *ctx, const char *exts, mpv_opengl_cb_get_proc_address_fn get_proc_address, void *get_proc_address_ctx)
 Initialize the mpv OpenGL state. More...
 
int mpv_opengl_cb_draw (mpv_opengl_cb_context *ctx, int fbo, int w, int h)
 Render video. More...
 
int mpv_opengl_cb_render (mpv_opengl_cb_context *ctx, int fbo, int vp[4])
 Deprecated. More...
 
int mpv_opengl_cb_report_flip (mpv_opengl_cb_context *ctx, int64_t time)
 Tell the renderer that a frame was flipped at the given time. More...
 
int mpv_opengl_cb_uninit_gl (mpv_opengl_cb_context *ctx)
 Destroy the mpv OpenGL state. More...
 

Typedef Documentation

◆ mpv_opengl_cb_context

nVidia/Linux via VDPAU requires GLX, which does not have this problem (the GLX API can return the current X11 Display).

Windowing system interop on MS win32

You should use ANGLE, and make sure your application and libmpv are linked to the same ANGLE DLLs. libmpv will pick the device context (needed for hardware decoding) from the current ANGLE EGL context. Opaque context, returned by mpv_get_sub_api(MPV_SUB_API_OPENGL_CB).

A context is bound to the mpv_handle it was retrieved from. The context will always be the same (for the same mpv_handle), and is valid until the mpv_handle it belongs to is released.

Definition at line 207 of file opengl_cb.h.

◆ mpv_opengl_cb_get_proc_address_fn

typedef void*(* mpv_opengl_cb_get_proc_address_fn) (void *fn_ctx, const char *name)

Definition at line 210 of file opengl_cb.h.

◆ mpv_opengl_cb_update_fn

typedef void(* mpv_opengl_cb_update_fn) (void *cb_ctx)

Definition at line 209 of file opengl_cb.h.

Function Documentation

◆ mpv_opengl_cb_draw()

int mpv_opengl_cb_draw ( mpv_opengl_cb_context ctx,
int  fbo,
int  w,
int  h 
)

Render video.

Requires that the OpenGL state is initialized.

The video will use the full provided framebuffer. Options like "panscan" are applied to determine which part of the video should be visible and how the video should be scaled. You can change these options at runtime by using the mpv property API.

The renderer will reconfigure itself every time the output rectangle/size is changed. (If you want to do animations, it might be better to do the animation on a FBO instead.)

This function implicitly pulls a video frame from the internal queue and renders it. If no new frame is available, the previous frame is redrawn. The update callback set with mpv_opengl_cb_set_update_callback() notifies you when a new frame was added.

Parameters
fboThe framebuffer object to render on. Because the renderer might manage multiple FBOs internally for the purpose of video postprocessing, it will always bind and unbind FBOs itself. If you want mpv to render on the main framebuffer, pass 0.
wWidth of the framebuffer. This is either the video size if the fbo parameter is 0, or the allocated size of the texture backing the fbo. The renderer will always use the full size of the fbo.
hHeight of the framebuffer. Same as with the w parameter, except that this parameter can be negative. In this case, the video frame will be rendered flipped.
Returns
0

◆ mpv_opengl_cb_init_gl()

int mpv_opengl_cb_init_gl ( mpv_opengl_cb_context ctx,
const char *  exts,
mpv_opengl_cb_get_proc_address_fn  get_proc_address,
void *  get_proc_address_ctx 
)

Initialize the mpv OpenGL state.

This retrieves OpenGL function pointers via get_proc_address, and creates OpenGL objects needed by mpv internally. It will also call APIs needed for rendering hardware decoded video in OpenGL, according to the mpv "hwdec" option.

You must free the associated state at some point by calling the mpv_opengl_cb_uninit_gl() function. Not doing so may result in memory leaks or worse.

Parameters
extsoptional additional extension string, can be NULL
get_proc_addresscallback used to retrieve function pointers to OpenGL functions. This is used for both standard functions and extension functions. (The extension string is checked whether extensions are really available.) The callback will be called from this function only (it is not stored and never used later). Usually, GL context APIs do this for you (e.g. with glXGetProcAddressARB or wglGetProcAddress), but some APIs do not always return pointers for all standard functions (even if present); in this case you have to compensate by looking up these functions yourself.
get_proc_address_ctxarbitrary opaque user context passed to the get_proc_address callback
Returns
error code (same as normal mpv_* API), including but not limited to: MPV_ERROR_UNSUPPORTED: the OpenGL version is not supported (or required extensions are missing) MPV_ERROR_INVALID_PARAMETER: the OpenGL state was already initialized

◆ mpv_opengl_cb_render()

int mpv_opengl_cb_render ( mpv_opengl_cb_context ctx,
int  fbo,
int  vp[4] 
)

Deprecated.

Use mpv_opengl_cb_draw(). This function is equivalent to:

int mpv_opengl_cb_render(mpv_opengl_cb_context *ctx, int fbo, int vp[4]) { return mpv_opengl_cb_draw(ctx, fbo, vp[2], vp[3]); }

vp[0] and vp[1] used to have a meaning, but are ignored in newer versions.

This function will be removed in the future without version bump (this API was never marked as stable).

◆ mpv_opengl_cb_report_flip()

int mpv_opengl_cb_report_flip ( mpv_opengl_cb_context ctx,
int64_t  time 
)

Tell the renderer that a frame was flipped at the given time.

This is optional, but can help the player to achieve better timing.

Note that calling this at least once informs libmpv that you will use this function. If you use it inconsistently, expect bad video playback.

If this is called while no video or no OpenGL is initialized, it is ignored.

Parameters
timeThe mpv time (using mpv_get_time_us()) at which the flip call returned. If 0 is passed, mpv_get_time_us() is used instead. Currently, this parameter is ignored.
Returns
error code

◆ mpv_opengl_cb_set_update_callback()

void mpv_opengl_cb_set_update_callback ( mpv_opengl_cb_context ctx,
mpv_opengl_cb_update_fn  callback,
void *  callback_ctx 
)

Set the callback that notifies you when a new video frame is available, or if the video display configuration somehow changed and requires a redraw.

Similar to mpv_set_wakeup_callback(), you must not call any mpv API from the callback, and all the other listed restrictions apply (such as not exiting the callback by throwing exceptions).

Parameters
callbackcallback(callback_ctx) is called if the frame should be redrawn
callback_ctxopaque argument to the callback

◆ mpv_opengl_cb_uninit_gl()

int mpv_opengl_cb_uninit_gl ( mpv_opengl_cb_context ctx)

Destroy the mpv OpenGL state.

If video is still active (e.g. a file playing), video will be disabled forcefully.

Calling this multiple times is ok.

Returns
error code