Skip to content
Extraits de code Groupes Projets
Vérifiée Valider f6fd1206 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

FMT

parent 85821e2e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #2621 en échec
......@@ -20,7 +20,6 @@ static bool module_qt_window_new(struct module_qt_window_s **, struct queue *, l
* Private functions *
*********************/
/********************************
* va_list version of functions *
********************************/
......@@ -30,7 +29,8 @@ mod_new(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win= reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct queue *queue = va_arg(copy, struct queue *);
lkt_db *db = va_arg(copy, lkt_db *);
bool ret = module_qt_window_new(win, queue, db);
......@@ -43,7 +43,8 @@ mod_close(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
module_qt_window_close(*win);
va_end(copy);
return 0;
......@@ -54,7 +55,8 @@ mod_free(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
module_qt_window_free(*win);
va_end(copy);
return 0;
......@@ -65,7 +67,8 @@ mod_toggle_pause(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win= reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
bool ret = ___module_qt_window_toggle_pause(*win);
va_end(copy);
return !ret;
......@@ -76,7 +79,8 @@ mod_load_file(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
const char *file = va_arg(copy, const char *);
const bool ret = ___module_qt_window_load_file(*win, file);
va_end(copy);
......@@ -88,7 +92,8 @@ mod_set_volume(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
const int volume = va_arg(copy, int);
const bool ret = ___module_qt_window_set_volume(*win, volume);
va_end(copy);
......@@ -100,7 +105,8 @@ mod_set_paused(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
const int state = va_arg(copy, int);
const bool ret = ___module_qt_window_set_paussed(*win, state);
va_end(copy);
......@@ -112,7 +118,8 @@ mod_set_position(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
const int seconds = va_arg(copy, int);
const bool ret = ___module_qt_window_set_position(*win, seconds);
va_end(copy);
......@@ -124,7 +131,8 @@ mod_get_duration(va_list *va)
{
va_list copy;
va_copy(copy, *va);
struct module_qt_window_s **win= reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
struct module_qt_window_s **win =
reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **));
int *duration = va_arg(copy, int *);
bool ret = ___module_qt_window_get_duration(*win, duration);
va_end(copy);
......@@ -170,7 +178,6 @@ REG_EXPORT(qt_window_reg)
* Private helper functions *
****************************/
/***************************
* Function implementation *
***************************/
......@@ -196,8 +203,8 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d
arg = LKT_ALLOC_STRUCT(poller_thread_arg);
RETURN_UNLESS(arg, "Out of memory", false);
arg->args = *win;
RETURN_IF(poller_new(&(*win)->self, ___create_mpv_widget, arg), "Failed to launch the SDL thread",
false);
RETURN_IF(poller_new(&(*win)->self, ___create_mpv_widget, arg),
"Failed to launch the SDL thread", false);
}
return true;
......
#include "mainwindow.hh"
MainWindow::MainWindow(struct module_qt_window_s* qt_window, QWidget *parent) :
QMainWindow(parent)
MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent)
: QMainWindow(parent)
{
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, this);
}
......@@ -7,12 +7,15 @@
#include "qthelper.hh"
#include "../mpv.h"
static void wakeup(void *ctx)
static void
wakeup(void *ctx)
{
QMetaObject::invokeMethod(static_cast<MpvWidget *>(ctx), "on_mpv_events", Qt::QueuedConnection);
}
static void *get_proc_address(void *ctx, const char *name) {
static void *
get_proc_address(void *ctx, const char *name)
{
Q_UNUSED(ctx);
QOpenGLContext *glctx = QOpenGLContext::currentContext();
if (!glctx)
......@@ -21,9 +24,9 @@ static void *get_proc_address(void *ctx, const char *name) {
}
MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent)
: QOpenGLWidget(parent),
m_queue(queue),
m_db(db)
: QOpenGLWidget(parent)
, m_queue(queue)
, m_db(db)
{
setFocusPolicy(Qt::StrongFocus);
mpv = mpv_create();
......@@ -56,51 +59,55 @@ MpvWidget::~MpvWidget()
mpv_terminate_destroy(mpv);
}
void MpvWidget::command(const QVariant& params)
void
MpvWidget::command(const QVariant &params)
{
mpv::qt::command(mpv, params);
}
void MpvWidget::setProperty(const QString& name, const QVariant& value)
void
MpvWidget::setProperty(const QString &name, const QVariant &value)
{
mpv::qt::set_property(mpv, name, value);
}
QVariant MpvWidget::getProperty(const QString &name) const
QVariant
MpvWidget::getProperty(const QString &name) const
{
return mpv::qt::get_property(mpv, name);
}
void MpvWidget::initializeGL()
void
MpvWidget::initializeGL()
{
mpv_opengl_init_params gl_init_params{ get_proc_address, nullptr, nullptr };
mpv_render_param params[]{
{MPV_RENDER_PARAM_API_TYPE, const_cast<char *>(MPV_RENDER_API_TYPE_OPENGL)},
mpv_render_param params[]{ { MPV_RENDER_PARAM_API_TYPE,
const_cast<char *>(MPV_RENDER_API_TYPE_OPENGL) },
{ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params },
{MPV_RENDER_PARAM_INVALID, nullptr}
};
{ MPV_RENDER_PARAM_INVALID, nullptr } };
if (mpv_render_context_create(&mpv_gl, mpv, params) < 0)
throw std::runtime_error("failed to initialize mpv GL context");
mpv_render_context_set_update_callback(mpv_gl, MpvWidget::on_update, reinterpret_cast<void *>(this));
mpv_render_context_set_update_callback(mpv_gl, MpvWidget::on_update,
reinterpret_cast<void *>(this));
}
void MpvWidget::paintGL()
void
MpvWidget::paintGL()
{
mpv_opengl_fbo mpfbo{ static_cast<int>(defaultFramebufferObject()), width(), height(), 0 };
int flip_y{ 1 };
mpv_render_param params[] = {
{MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo},
mpv_render_param params[] = { { MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo },
{ MPV_RENDER_PARAM_FLIP_Y, &flip_y },
{MPV_RENDER_PARAM_INVALID, nullptr}
};
{ MPV_RENDER_PARAM_INVALID, nullptr } };
// See render_gl.h on what OpenGL environment mpv expects, and
// other API details.
mpv_render_context_render(mpv_gl, params);
}
void MpvWidget::on_mpv_events()
void
MpvWidget::on_mpv_events()
{
// Process all events, until the event queue is empty.
while (mpv) {
......@@ -112,7 +119,8 @@ void MpvWidget::on_mpv_events()
}
}
void MpvWidget::handle_mpv_event(mpv_event *event)
void
MpvWidget::handle_mpv_event(mpv_event *event)
{
switch (event->event_id) {
case MPV_EVENT_PROPERTY_CHANGE: {
......@@ -155,13 +163,16 @@ void MpvWidget::handle_mpv_event(mpv_event *event)
case MPV_EVENT_CHAPTER_CHANGE:
case MPV_EVENT_PLAYBACK_RESTART:
case MPV_EVENT_QUEUE_OVERFLOW:
case MPV_EVENT_HOOK:{ break; }
case MPV_EVENT_HOOK: {
break;
}
// Ignore uninteresting or unknown events.
}
}
// Make Qt invoke mpv_render_context_render() to draw a new/updated video frame.
void MpvWidget::maybeUpdate()
void
MpvWidget::maybeUpdate()
{
// If the Qt window is not visible, Qt's update() will just skip rendering.
// This confuses mpv's render API, and may lead to small occasional
......@@ -180,7 +191,8 @@ void MpvWidget::maybeUpdate()
}
}
void MpvWidget::on_update(void *ctx)
void
MpvWidget::on_update(void *ctx)
{
QMetaObject::invokeMethod(static_cast<MpvWidget *>(ctx), "maybeUpdate");
}
......
......@@ -4,7 +4,8 @@
#include <QApplication>
void *
___create_mpv_widget(struct poller_thread_arg *arg){
___create_mpv_widget(struct poller_thread_arg *arg)
{
lkt_thread_set_name("lektord/qt-win");
/* Unsage reinterpret cast, but isok */
......
......@@ -34,7 +34,8 @@ struct ___poller_thread_args {
void *___poller_thread_start(void *args__);
UNUSED int poller_new(struct poller_thread *th, void *(*func)(struct poller_thread_arg *), void *args);
UNUSED int poller_new(struct poller_thread *th, void *(*func)(struct poller_thread_arg *),
void *args);
UNUSED int poller_join(struct poller_thread *th, void **ret);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter