aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-23 19:16:05 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-23 19:16:10 +0200
commite1d5d4401f74051e747a6afb6be5d9becc4bda2a (patch)
tree9277a1c325343d862c1efa8f33abe098480c867f /src
parent7e7dfd227eacaa80b21ca8ed99e8a99ccbd47769 (diff)
Revert to opengl_cb for mpv until render_gl becomes common
Diffstat (limited to 'src')
-rw-r--r--src/Video.cpp41
-rw-r--r--src/main.cpp3
2 files changed, 21 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();
diff --git a/src/main.cpp b/src/main.cpp
index 67f4865..6d9a9c0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,6 +2,7 @@
#include "../include/ChannelSidePanel.hpp"
#include "../include/Cache.hpp"
#include "../include/ResourceCache.hpp"
+#include "../include/Video.hpp"
#include <string>
#include <SFML/Graphics.hpp>
#include <cstring>
@@ -27,6 +28,7 @@ int main(int argc, char **argv)
window.setFramerateLimit(60);
//odhtdb::Database database("bootstrap.ring.cx", 4222, Cache::getDchatDir());
+ //Video video(500, 500, "https://www.youtube.com/watch?v=bs0-EX9mJmg");
Cache cache;
@@ -52,6 +54,7 @@ int main(int argc, char **argv)
window.clear(sf::Color(40, 40, 40));
channel.draw(window, sf::Vector2f(channelSidePanel.width, 0.0f), cache);
channelSidePanel.draw(window);
+ //video.draw(window);
window.display();
}