#include "client.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 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).
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.
typedef void*(* mpv_opengl_cb_get_proc_address_fn) (void *fn_ctx, const char *name) |
Definition at line 210 of file opengl_cb.h.
typedef void(* mpv_opengl_cb_update_fn) (void *cb_ctx) |
Definition at line 209 of file opengl_cb.h.
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.
fbo | The 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. |
w | Width 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. |
h | Height 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. |
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.
exts | optional additional extension string, can be NULL |
get_proc_address | callback 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_ctx | arbitrary opaque user context passed to the get_proc_address callback |
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).
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.
time | The 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. |
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).
callback | callback(callback_ctx) is called if the frame should be redrawn |
callback_ctx | opaque argument to the callback |
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.