Re add direct support and reenable preview.
This commit is contained in:
parent
5197bfe9f2
commit
f1c8b4fd7a
|
@ -8,10 +8,10 @@
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QSequentialIterable>
|
#include <QSequentialIterable>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
#include <QtX11Extras/QX11Info>
|
#include <QtX11Extras/QX11Info>
|
||||||
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
auto mpvLogger = initLogger("mpv");
|
auto mpvLogger = initLogger("mpv");
|
||||||
|
|
||||||
|
bool usedirect = false;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -39,7 +41,8 @@ on_mpv_redraw(void* ctx)
|
||||||
static void*
|
static void*
|
||||||
get_proc_address_mpv(void* ctx, const char* name)
|
get_proc_address_mpv(void* ctx, const char* name)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<void*>(reinterpret_cast<QOpenGLContext*>(ctx)->getProcAddress(QByteArray(name)));
|
return reinterpret_cast<void*>(
|
||||||
|
reinterpret_cast<QOpenGLContext*>(ctx)->getProcAddress(QByteArray(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -51,17 +54,26 @@ class MpvRenderer : public QQuickFramebufferObject::Renderer
|
||||||
public:
|
public:
|
||||||
MpvRenderer(MPVBackend* new_obj)
|
MpvRenderer(MPVBackend* new_obj)
|
||||||
: obj{ new_obj }
|
: obj{ new_obj }
|
||||||
{}
|
{
|
||||||
|
if (usedirect) {
|
||||||
|
int r =
|
||||||
|
mpv_opengl_cb_init_gl(obj->mpv_gl_cb, NULL, get_proc_address_mpv, QOpenGLContext::currentContext());
|
||||||
|
if (r < 0) {
|
||||||
|
std::cout << "No." << std::endl;
|
||||||
|
throw std::runtime_error("failed to initialize mpv GL context");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~MpvRenderer() {}
|
virtual ~MpvRenderer() {}
|
||||||
|
|
||||||
|
|
||||||
// This function is called when a new FBO is needed.
|
// This function is called when a new FBO is needed.
|
||||||
// This happens on the initial frame.
|
// This happens on the initial frame.
|
||||||
QOpenGLFramebufferObject* createFramebufferObject(const QSize& size)
|
QOpenGLFramebufferObject* createFramebufferObject(const QSize& size)
|
||||||
{
|
{
|
||||||
// init mpv_gl:
|
// init mpv_gl:
|
||||||
if (!obj->mpv_gl) {
|
if (!obj->mpv_gl && !usedirect) {
|
||||||
mpv_opengl_init_params gl_init_params{ get_proc_address_mpv,
|
mpv_opengl_init_params gl_init_params{ get_proc_address_mpv,
|
||||||
QOpenGLContext::currentContext(),
|
QOpenGLContext::currentContext(),
|
||||||
nullptr };
|
nullptr };
|
||||||
|
@ -76,18 +88,21 @@ public:
|
||||||
if (QGuiApplication::platformName().contains("xcb")) {
|
if (QGuiApplication::platformName().contains("xcb")) {
|
||||||
params[2].type = MPV_RENDER_PARAM_X11_DISPLAY;
|
params[2].type = MPV_RENDER_PARAM_X11_DISPLAY;
|
||||||
params[2].data = QX11Info::display();
|
params[2].data = QX11Info::display();
|
||||||
} /* else if (QGuiApplication::platformName().contains("wayland")) {
|
} else if (QGuiApplication::platformName().contains("wayland")) {
|
||||||
params[2].type = MPV_RENDER_PARAM_WL_DISPLAY;
|
params[2].type = MPV_RENDER_PARAM_WL_DISPLAY;
|
||||||
auto *native = QGuiApplication::platformNativeInterface();
|
auto *native = QGuiApplication::platformNativeInterface();
|
||||||
params[2].data = native->nativeResourceForWindow("display", NULL);
|
params[2].data = native->nativeResourceForWindow("display", NULL);
|
||||||
} */
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0)
|
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0) {
|
||||||
|
std::cout << "Failed to use render API, try setting Backend/direct to true in settings." << std::endl;
|
||||||
throw std::runtime_error("failed to initialize mpv GL context");
|
throw std::runtime_error("failed to initialize mpv GL context");
|
||||||
mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj);
|
|
||||||
QMetaObject::invokeMethod(obj, "startPlayer");
|
|
||||||
}
|
}
|
||||||
|
mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj);
|
||||||
|
}
|
||||||
|
QMetaObject::invokeMethod(obj, "startPlayer");
|
||||||
|
|
||||||
|
|
||||||
return QQuickFramebufferObject::Renderer::createFramebufferObject(size);
|
return QQuickFramebufferObject::Renderer::createFramebufferObject(size);
|
||||||
}
|
}
|
||||||
|
@ -95,8 +110,10 @@ public:
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
obj->window()->resetOpenGLState();
|
obj->window()->resetOpenGLState();
|
||||||
|
|
||||||
QOpenGLFramebufferObject* fbo = framebufferObject();
|
QOpenGLFramebufferObject* fbo = framebufferObject();
|
||||||
|
if (usedirect) {
|
||||||
|
mpv_opengl_cb_draw(obj->mpv_gl_cb, fbo->handle(), fbo->width(), fbo->height());
|
||||||
|
} else {
|
||||||
mpv_opengl_fbo mpfbo{ .fbo = static_cast<int>(fbo->handle()),
|
mpv_opengl_fbo mpfbo{ .fbo = static_cast<int>(fbo->handle()),
|
||||||
.w = fbo->width(),
|
.w = fbo->width(),
|
||||||
.h = fbo->height(),
|
.h = fbo->height(),
|
||||||
|
@ -106,6 +123,8 @@ public:
|
||||||
{ MPV_RENDER_PARAM_FLIP_Y, &flip_y },
|
{ MPV_RENDER_PARAM_FLIP_Y, &flip_y },
|
||||||
{ MPV_RENDER_PARAM_INVALID, nullptr } };
|
{ MPV_RENDER_PARAM_INVALID, nullptr } };
|
||||||
mpv_render_context_render(obj->mpv_gl, params);
|
mpv_render_context_render(obj->mpv_gl, params);
|
||||||
|
}
|
||||||
|
|
||||||
obj->window()->resetOpenGLState();
|
obj->window()->resetOpenGLState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -114,16 +133,19 @@ MPVBackend::MPVBackend(QQuickItem* parent)
|
||||||
: QQuickFramebufferObject(parent)
|
: QQuickFramebufferObject(parent)
|
||||||
, mpv{ mpv_create() }
|
, mpv{ mpv_create() }
|
||||||
, mpv_gl(nullptr)
|
, mpv_gl(nullptr)
|
||||||
|
, mpv_gl_cb(nullptr)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!mpv)
|
if (!mpv)
|
||||||
throw std::runtime_error("could not create mpv context");
|
throw std::runtime_error("could not create mpv context");
|
||||||
|
QSettings settings;
|
||||||
|
usedirect = settings.value("Backend/direct", false).toBool();
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "terminal", "off");
|
mpv_set_option_string(mpv, "terminal", "on");
|
||||||
mpv_set_option_string(mpv, "msg-level", "all=v");
|
mpv_set_option_string(mpv, "msg-level", "all=v");
|
||||||
|
|
||||||
// Fix?
|
// Fix?
|
||||||
mpv_set_option_string(mpv, "ytdl", "yes");
|
mpv_set_option_string(mpv, "ytdl", "yes");
|
||||||
mpv_set_option_string(mpv, "vo", "libmpv");
|
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "slang", "en");
|
mpv_set_option_string(mpv, "slang", "en");
|
||||||
|
|
||||||
|
@ -146,13 +168,23 @@ MPVBackend::MPVBackend(QQuickItem* parent)
|
||||||
mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NODE);
|
mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NODE);
|
||||||
mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE);
|
mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE);
|
||||||
|
|
||||||
mpv_request_log_messages(mpv, "trace");
|
mpv_request_log_messages(mpv, "verbose");
|
||||||
|
|
||||||
mpv_set_wakeup_callback(mpv, wakeup, this);
|
mpv_set_wakeup_callback(mpv, wakeup, this);
|
||||||
|
|
||||||
if (mpv_initialize(mpv) < 0)
|
if (mpv_initialize(mpv) < 0)
|
||||||
throw std::runtime_error("could not initialize mpv context");
|
throw std::runtime_error("could not initialize mpv context");
|
||||||
|
|
||||||
|
if (usedirect) {
|
||||||
|
mpv_set_option_string(mpv, "vo", "libmpv");
|
||||||
|
mpv_gl_cb = (mpv_opengl_cb_context*)mpv_get_sub_api(mpv, MPV_SUB_API_OPENGL_CB);
|
||||||
|
if (!mpv_gl_cb)
|
||||||
|
throw std::runtime_error("OpenGL not compiled in");
|
||||||
|
mpv_opengl_cb_set_update_callback(mpv_gl_cb, on_mpv_redraw, (void*)this);
|
||||||
|
} else {
|
||||||
|
mpv_set_option_string(mpv, "vo", "libmpv");
|
||||||
|
}
|
||||||
|
|
||||||
connect(this,
|
connect(this,
|
||||||
&MPVBackend::onUpdate,
|
&MPVBackend::onUpdate,
|
||||||
this,
|
this,
|
||||||
|
@ -176,8 +208,10 @@ MPVBackend::~MPVBackend()
|
||||||
Utils::SetDPMS(true);
|
Utils::SetDPMS(true);
|
||||||
command("write-watch-later-config");
|
command("write-watch-later-config");
|
||||||
|
|
||||||
if (mpv_gl) {
|
if (usedirect) {
|
||||||
mpv_render_context_free(mpv_gl);
|
mpv_render_context_free(mpv_gl);
|
||||||
|
} else {
|
||||||
|
mpv_opengl_cb_set_update_callback(mpv_gl_cb, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
mpv_terminate_destroy(mpv);
|
mpv_terminate_destroy(mpv);
|
||||||
|
@ -556,10 +590,12 @@ MPVBackend::handle_mpv_event(mpv_event* event)
|
||||||
(struct mpv_event_log_message*)event->data;
|
(struct mpv_event_log_message*)event->data;
|
||||||
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
|
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
|
||||||
QString msgLevel = QString(msg->level);
|
QString msgLevel = QString(msg->level);
|
||||||
if (msgLevel.startsWith("d")) {
|
if (msgLevel.startsWith("d") || msgLevel.startsWith("t")) {
|
||||||
mpvLogger->debug("{}", logMsg.toStdString());
|
mpvLogger->info("{}", logMsg.toStdString());
|
||||||
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
|
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
|
||||||
mpvLogger->info("{}", logMsg.toStdString());
|
mpvLogger->info("{}", logMsg.toStdString());
|
||||||
|
} else {
|
||||||
|
mpvLogger->debug("{}", logMsg.toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#define MPVBackend_H
|
#define MPVBackend_H
|
||||||
|
|
||||||
#include <mpv/client.h>
|
#include <mpv/client.h>
|
||||||
|
#include <mpv/opengl_cb.h>
|
||||||
#include <mpv/qthelper.hpp>
|
#include <mpv/qthelper.hpp>
|
||||||
|
|
||||||
#include <mpv/render_gl.h>
|
#include <mpv/render_gl.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
@ -28,6 +28,8 @@ class MPVBackend
|
||||||
|
|
||||||
mpv_handle* mpv;
|
mpv_handle* mpv;
|
||||||
mpv_render_context* mpv_gl;
|
mpv_render_context* mpv_gl;
|
||||||
|
mpv_opengl_cb_context* mpv_gl_cb;
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
bool onTop = false;
|
bool onTop = false;
|
||||||
bool m_logging = true;
|
bool m_logging = true;
|
||||||
|
|
|
@ -130,7 +130,6 @@ main(int argc, char* argv[])
|
||||||
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
|
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
|
||||||
qmlRegisterType<MPVBackend>("player", 1, 0, "PlayerBackend");
|
qmlRegisterType<MPVBackend>("player", 1, 0, "PlayerBackend");
|
||||||
|
|
||||||
|
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
launcherLogger->info("Loading player...");
|
launcherLogger->info("Loading player...");
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,8 @@ Slider {
|
||||||
shouldSeek = true
|
shouldSeek = true
|
||||||
}
|
}
|
||||||
if (shouldSeek) {
|
if (shouldSeek) {
|
||||||
/*progressBarTimePreview.playerCommand(
|
progressBarTimePreview.playerCommand(
|
||||||
Enums.Commands.SeekAbsolute, a)*/
|
Enums.Commands.SeekAbsolute, a)
|
||||||
} else {
|
} else {
|
||||||
hoverProgressLabel.text = utils.createTimestamp(a)
|
hoverProgressLabel.text = utils.createTimestamp(a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ Window {
|
||||||
z: 1
|
z: 1
|
||||||
logging: loggingSettings.logBackend
|
logging: loggingSettings.logBackend
|
||||||
|
|
||||||
/*onPlaylistChanged: function (playlist) {
|
onPlaylistChanged: function (playlist) {
|
||||||
for (var thing in playlist) {
|
for (var thing in playlist) {
|
||||||
var item = playlist[thing]
|
var item = playlist[thing]
|
||||||
if (playlist[thing]["current"]) {
|
if (playlist[thing]["current"]) {
|
||||||
|
@ -213,7 +213,7 @@ Window {
|
||||||
}
|
}
|
||||||
progressBarTimePreview.playerCommand(Enums.Commands.ForcePause)
|
progressBarTimePreview.playerCommand(Enums.Commands.ForcePause)
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
|
@ -492,7 +492,7 @@ Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*PlayerBackend {
|
PlayerBackend {
|
||||||
z: 90
|
z: 90
|
||||||
id: progressBarTimePreview
|
id: progressBarTimePreview
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
@ -513,7 +513,7 @@ Window {
|
||||||
"worstvideo[height<=?" + String(
|
"worstvideo[height<=?" + String(
|
||||||
height) + "]/worst")
|
height) + "]/worst")
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue