From: APTX Date: Sat, 19 Feb 2022 09:02:57 +0000 (+0900) Subject: Use new MPV render API X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=5137146b933503227494f1330e59d4b71793f5c6;p=aniplayer.git Use new MPV render API --- diff --git a/backendplugins/backend_mpv/backendmpv.cpp b/backendplugins/backend_mpv/backendmpv.cpp index fbc55f8..ef9c3d2 100644 --- a/backendplugins/backend_mpv/backendmpv.cpp +++ b/backendplugins/backend_mpv/backendmpv.cpp @@ -6,8 +6,9 @@ #include #include "qthelper.hpp" -#include -#include + +#include +#include #include @@ -39,8 +40,6 @@ MpvInstance::MpvInstance(PlayerPluginInterface *playerInterface, << "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" @@ -422,40 +421,52 @@ VideoRendererMpv::VideoRendererMpv(mpv_handle *handle, VideoUpdateInterface *vui) : m_handle{handle} { qCDebug(mpvBackend, "VideoRendererMpv::VideoRendererMpv"); - m_oglCtx = static_cast( - 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(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(fbo->handle()), // GLuint is unsigned - fbo->width(), fbo->height()); + if (!m_renderCtx) { + return; + } + mpv_opengl_fbo opengl_fbo; + opengl_fbo.fbo = static_cast(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); diff --git a/backendplugins/backend_mpv/backendmpv.h b/backendplugins/backend_mpv/backendmpv.h index ab4f0e9..2afb0ba 100644 --- a/backendplugins/backend_mpv/backendmpv.h +++ b/backendplugins/backend_mpv/backendmpv.h @@ -8,8 +8,8 @@ #include "aniplayer/backendpluginbase.h" struct mpv_handle; -struct mpv_opengl_cb_context; struct mpv_event_property; +struct mpv_render_context; class BACKEND_MPVSHARED_EXPORT BackendMpv : public QObject, public BackendPluginBase { @@ -71,7 +71,7 @@ public: private: mpv_handle *m_handle = nullptr; - mpv_opengl_cb_context *m_oglCtx = nullptr; + mpv_render_context *m_renderCtx = nullptr; static void *getProcAddress(void *, const char *name); static void mpvUpdate(void *);