aboutsummaryrefslogtreecommitdiff
path: root/src/Video.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Video.cpp')
-rw-r--r--src/Video.cpp41
1 files changed, 18 insertions, 23 deletions
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 <mpv/client.h>
-#include <mpv/render_gl.h>
+#include <mpv/opengl_cb.h>
#include <clocale>
#include <SFML/Config.hpp>
@@ -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<mutex> 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();