#include <QUrl>
#include "qthelper.hpp"
-#include <mpv/client.h>
-#include <mpv/opengl_cb.h>
+
+#include <mpv/render.h>
+#include <mpv/render_gl.h>
#include <QLoggingCategory>
<< "Client API version: " << (mpv_client_api_version() >> 16) << '.'
<< (mpv_client_api_version() & ~(~0u << 16));
- mpv_set_option_string(m_handle, "vo", "opengl-cb");
-
int error = mpv_initialize(m_handle);
if (error) {
qCCritical(mpvBackend) << "Error initializing mpv"
VideoUpdateInterface *vui)
: m_handle{handle} {
qCDebug(mpvBackend, "VideoRendererMpv::VideoRendererMpv");
- m_oglCtx = static_cast<mpv_opengl_cb_context *>(
- mpv_get_sub_api(handle, MPV_SUB_API_OPENGL_CB));
- qCDebug(mpvBackend) << "created ogl ctx" << m_oglCtx;
- if (!m_oglCtx) {
- qCDebug(mpvBackend) << "Error obtaining mpv ogl context";
+ mpv_opengl_init_params opengl_init_params;
+ opengl_init_params.get_proc_address = getProcAddress;
+ opengl_init_params.get_proc_address_ctx = nullptr;
+ mpv_render_param render_params[] = {
+ {MPV_RENDER_PARAM_API_TYPE,
+ const_cast<char *>(MPV_RENDER_API_TYPE_OPENGL)},
+ {MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &opengl_init_params},
+ {MPV_RENDER_PARAM_INVALID, nullptr}};
+
+ int error = mpv_render_context_create(&m_renderCtx, m_handle, render_params);
+ if (error) {
+ qCCritical(mpvBackend())
+ << "Error initializing mpv ogl context:" << mpv_error_string(error);
+ m_renderCtx = nullptr;
+ }
+ if (!m_renderCtx) {
+ qCDebug(mpvBackend) << "Error obtaining mpv render context";
return;
}
qCDebug(mpvBackend, "setting callback");
- mpv_opengl_cb_set_update_callback(m_oglCtx, mpvUpdate, vui);
+ mpv_render_context_set_update_callback(m_renderCtx, mpvUpdate, vui);
qCDebug(mpvBackend, "initializing gl context");
- int error = mpv_opengl_cb_init_gl(m_oglCtx, NULL, getProcAddress, this);
- if (error) {
- qCCritical(mpvBackend())
- << "Error initializing mpv ogl context:" << mpv_error_string(error);
- m_oglCtx = nullptr;
- }
+
qCDebug(mpvBackend, "all done");
}
VideoRendererMpv::~VideoRendererMpv() {
- if (m_oglCtx) {
- int error = mpv_opengl_cb_uninit_gl(m_oglCtx);
- if (error)
- qCWarning(mpvBackend)
- << "Error uninitializing mpv ogl context:" << mpv_error_string(error);
+ if (m_renderCtx) {
+ mpv_render_context_free(m_renderCtx);
+ m_renderCtx = nullptr;
}
}
void VideoRendererMpv::render(QOpenGLFramebufferObject *fbo) {
- int error =
- mpv_opengl_cb_draw(m_oglCtx,
- static_cast<int>(fbo->handle()), // GLuint is unsigned
- fbo->width(), fbo->height());
+ if (!m_renderCtx) {
+ return;
+ }
+ mpv_opengl_fbo opengl_fbo;
+ opengl_fbo.fbo = static_cast<int>(fbo->handle());
+ opengl_fbo.w = fbo->width();
+ opengl_fbo.h = fbo->height();
+ opengl_fbo.internal_format = fbo->format().internalTextureFormat();
+ mpv_render_param render_param{MPV_RENDER_PARAM_OPENGL_FBO, &opengl_fbo};
+
+ int error = mpv_render_context_render(m_renderCtx, &render_param);
if (error)
qCCritical(mpvBackend) << "Error rendering mpv frame:"
<< mpv_error_string(error);