From e1d5d4401f74051e747a6afb6be5d9becc4bda2a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 23 Apr 2018 19:16:05 +0200 Subject: Revert to opengl_cb for mpv until render_gl becomes common --- src/Video.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/Video.cpp') diff --git a/src/Video.cpp b/src/Video.cpp index 4ef16d6..681559f 100644 --- a/src/Video.cpp +++ b/src/Video.cpp @@ -1,6 +1,6 @@ #include "../include/Video.hpp" #include -#include +#include #include #include @@ -69,21 +69,17 @@ namespace dchat if(mpv_initialize(mpv) < 0) throw VideoInitializationException("Failed to initialize mpv"); - mpv_opengl_init_params openglInitParams { .get_proc_address = getProcAddressMpv }; - mpv_render_param params[] = - { - { MPV_RENDER_PARAM_API_TYPE, (void*)MPV_RENDER_API_TYPE_OPENGL }, - { MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &openglInitParams }, - { (mpv_render_param_type)0, nullptr } - }; - - if(mpv_render_context_create(&mpvGl, mpv, params) < 0) - throw VideoInitializationException("Failed to initialize mpv opengl render context"); - + mpv_set_option_string(mpv, "vo", "opengl-cb"); + mpv_set_option_string(mpv, "hwdec", "auto"); if(loop) mpv_set_option_string(mpv, "loop", "inf"); - mpv_set_option_string(mpv, "hwdec", "auto"); - mpv_render_context_set_update_callback(mpvGl, onMpvRedraw, this); + mpvGl = (mpv_opengl_cb_context*)mpv_get_sub_api(mpv, MPV_SUB_API_OPENGL_CB); + if(!mpvGl) + throw VideoInitializationException("Failed to initialize mpv opengl render context"); + + mpv_opengl_cb_set_update_callback(mpvGl, onMpvRedraw, this); + if(mpv_opengl_cb_init_gl(mpvGl, nullptr, getProcAddressMpv, nullptr) < 0) + throw VideoInitializationException("Failed to initialize mpv gl callback func"); renderThread = thread([this, width, height]() { @@ -102,19 +98,14 @@ namespace dchat if(redrawCounter > 0) { --redrawCounter; - mpv_opengl_fbo openglFbo { .fbo = 0, .w = (int)width, .h = (int)height }; - mpv_render_param params[] = - { - { MPV_RENDER_PARAM_OPENGL_FBO, &openglFbo }, - { (mpv_render_param_type)0, nullptr } - }; - context.setActive(true); renderMutex.lock(); - mpv_render_context_render(mpvGl, params); + //mpv_render_context_render(mpvGl, params); + mpv_opengl_cb_draw(mpvGl, 0, width, height); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, textureBuffer); texture.update(textureBuffer); sprite.setTexture(texture, true); + mpv_opengl_cb_report_flip(mpvGl, 0); renderMutex.unlock(); } this_thread::sleep_for(chrono::milliseconds(10)); @@ -130,8 +121,12 @@ namespace dchat Video::~Video() { lock_guard lock(renderMutex); + context.setActive(true); + if(mpvGl) + mpv_opengl_cb_set_update_callback(mpvGl, nullptr, nullptr); + delete[] textureBuffer; - mpv_render_context_free(mpvGl); + mpv_opengl_cb_uninit_gl(mpvGl); mpv_destroy(mpv); if(renderThread.joinable()) renderThread.join(); -- cgit v1.2.3