aboutsummaryrefslogtreecommitdiff
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
parent7e7dfd227eacaa80b21ca8ed99e8a99ccbd47769 (diff)
Revert to opengl_cb for mpv until render_gl becomes common
-rw-r--r--include/Video.hpp4
-rw-r--r--project.conf4
-rw-r--r--src/Video.cpp41
-rw-r--r--src/main.cpp3
4 files changed, 25 insertions, 27 deletions
diff --git a/include/Video.hpp b/include/Video.hpp
index f148c07..05c8396 100644
--- a/include/Video.hpp
+++ b/include/Video.hpp
@@ -10,7 +10,7 @@
#include <stdexcept>
class mpv_handle;
-class mpv_render_context;
+class mpv_opengl_cb_context;
namespace dchat
{
@@ -35,7 +35,7 @@ namespace dchat
private:
sf::Context context;
mpv_handle *mpv;
- mpv_render_context *mpvGl;
+ mpv_opengl_cb_context *mpvGl;
std::thread renderThread;
std::mutex renderMutex;
sf::Sprite sprite;
diff --git a/project.conf b/project.conf
index f2d4c9f..eaf5266 100644
--- a/project.conf
+++ b/project.conf
@@ -10,7 +10,7 @@ sfml-graphics = "2.4.2"
sfml-system = "2.4.2"
boost-filesystem = "1.66.0"
tiny-process = "2.0.0"
-mpv = "1.100.0"
-gl = "18.0"
+mpv = "1.25.0"
+gl = "17.3"
x11 = "1.6.5"
libnsgif = "0.2.0"
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();
}