[UI] Working on native stats replacement.
This commit is contained in:
parent
cbb7b8b618
commit
2a0477bd34
|
@ -1,5 +1,5 @@
|
||||||
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
pushd $SOURCE_DIR
|
pushd $SOURCE_DIR
|
||||||
qmlfmt -w src/qml/*.qml src/qml/*/*.qml
|
qmlfmt -w src/qml/*.qml src/qml/*/*.qml
|
||||||
clang-format -style mozilla -i src/*
|
clang-format -style mozilla -i src/* src/Backends/*/*
|
||||||
popd
|
popd
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
void
|
void
|
||||||
wakeup(void* ctx)
|
wakeup(void* ctx)
|
||||||
{
|
{
|
||||||
QCoreApplication::postEvent((DirectMPVBackend*)ctx,
|
QCoreApplication::postEvent((DirectMPVBackend*)ctx, new QEvent(QEvent::User));
|
||||||
new QEvent(QEvent::User));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void*
|
static void*
|
||||||
|
@ -231,7 +230,7 @@ DirectMPVBackend::playerCommand(const Enums::Commands& cmd)
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
DirectMPVBackend::playerCommand(const Enums::Commands& cmd,
|
DirectMPVBackend::playerCommand(const Enums::Commands& cmd,
|
||||||
const QVariant& args)
|
const QVariant& args)
|
||||||
{
|
{
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case Enums::Commands::TogglePlayPause: {
|
case Enums::Commands::TogglePlayPause: {
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <QtX11Extras/QX11Info>
|
#include <QtX11Extras/QX11Info>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <qpa/qplatformnativeinterface.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto mpvLogger = initLogger("mpv");
|
auto mpvLogger = initLogger("mpv");
|
||||||
|
@ -82,11 +81,6 @@ 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")) {
|
|
||||||
QPlatformNativeInterface* native =
|
|
||||||
QGuiApplication::platformNativeInterface();
|
|
||||||
params[2].type = MPV_RENDER_PARAM_WL_DISPLAY;
|
|
||||||
params[2].data = native->nativeResourceForWindow("display", nullptr);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -109,16 +103,9 @@ public:
|
||||||
.h = fbo->height(),
|
.h = fbo->height(),
|
||||||
.internal_format = 0 };
|
.internal_format = 0 };
|
||||||
int flip_y{ 0 };
|
int flip_y{ 0 };
|
||||||
mpv_render_param params[] = {
|
mpv_render_param params[] = { { MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo },
|
||||||
{ MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo },
|
{ MPV_RENDER_PARAM_FLIP_Y, &flip_y },
|
||||||
|
{ MPV_RENDER_PARAM_INVALID, nullptr } };
|
||||||
// Flip rendering (needed due to flipped GL coordinate system).
|
|
||||||
{ MPV_RENDER_PARAM_FLIP_Y, &flip_y },
|
|
||||||
{ MPV_RENDER_PARAM_INVALID, nullptr }
|
|
||||||
};
|
|
||||||
|
|
||||||
// See render_gl.h on what OpenGL environment mpv expects, and
|
|
||||||
// other API details.
|
|
||||||
mpv_render_context_render(obj->mpv_gl, params);
|
mpv_render_context_render(obj->mpv_gl, params);
|
||||||
obj->window()->resetOpenGLState();
|
obj->window()->resetOpenGLState();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +116,6 @@ MPVBackend::MPVBackend(QQuickItem* parent)
|
||||||
, mpv{ mpv_create() }
|
, mpv{ mpv_create() }
|
||||||
, mpv_gl(nullptr)
|
, mpv_gl(nullptr)
|
||||||
{
|
{
|
||||||
mpvLogger->set_pattern("[%n]%v%$");
|
|
||||||
if (!mpv)
|
if (!mpv)
|
||||||
throw std::runtime_error("could not create mpv context");
|
throw std::runtime_error("could not create mpv context");
|
||||||
|
|
||||||
|
@ -139,12 +125,10 @@ MPVBackend::MPVBackend(QQuickItem* parent)
|
||||||
// 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, "vo", "libmpv");
|
||||||
// mpp_set_option_string(mpv, "no-sub-ass", "yes)
|
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "slang", "en");
|
mpv_set_option_string(mpv, "slang", "en");
|
||||||
|
|
||||||
mpv_set_option_string(mpv, "config", "yes");
|
mpv_set_option_string(mpv, "config", "yes");
|
||||||
// mpv_set_option_string(mpv, "sub-visibility", "no");
|
|
||||||
mpv_observe_property(mpv, 0, "tracks-menu", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "tracks-menu", MPV_FORMAT_NONE);
|
||||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
||||||
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
|
||||||
|
@ -163,7 +147,7 @@ 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, "debug");
|
mpv_request_log_messages(mpv, "trace");
|
||||||
|
|
||||||
mpv_set_wakeup_callback(mpv, wakeup, this);
|
mpv_set_wakeup_callback(mpv, wakeup, this);
|
||||||
|
|
||||||
|
@ -191,8 +175,12 @@ MPVBackend::~MPVBackend()
|
||||||
{
|
{
|
||||||
printf("Shutting down...\n");
|
printf("Shutting down...\n");
|
||||||
Utils::SetDPMS(true);
|
Utils::SetDPMS(true);
|
||||||
command("quit-watch-later");
|
command("write-watch-later-config");
|
||||||
mpv_render_context_free(mpv_gl);
|
|
||||||
|
if (mpv_gl) {
|
||||||
|
mpv_render_context_free(mpv_gl);
|
||||||
|
}
|
||||||
|
|
||||||
mpv_terminate_destroy(mpv);
|
mpv_terminate_destroy(mpv);
|
||||||
printf("MPV terminated.\n");
|
printf("MPV terminated.\n");
|
||||||
}
|
}
|
||||||
|
@ -244,8 +232,7 @@ MPVBackend::playerCommand(const Enums::Commands& cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
MPVBackend::playerCommand(const Enums::Commands& cmd,
|
MPVBackend::playerCommand(const Enums::Commands& cmd, const QVariant& args)
|
||||||
const QVariant& args)
|
|
||||||
{
|
{
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case Enums::Commands::TogglePlayPause: {
|
case Enums::Commands::TogglePlayPause: {
|
||||||
|
@ -571,9 +558,9 @@ MPVBackend::handle_mpv_event(mpv_event* event)
|
||||||
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")) {
|
||||||
mpvLogger->debug("{}", logMsg.toUtf8().constData());
|
mpvLogger->debug("{}", logMsg.toStdString());
|
||||||
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
|
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
|
||||||
mpvLogger->info("{}", logMsg.toUtf8().constData());
|
mpvLogger->info("{}", logMsg.toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,6 +576,45 @@ MPVBackend::handle_mpv_event(mpv_event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
MPVBackend::getStats()
|
||||||
|
{
|
||||||
|
QString stats;
|
||||||
|
stats =
|
||||||
|
"<style> blockquote { text-indent: 0px; margin-left:40px; margin-top: 0px; "
|
||||||
|
"margin-bottom: 0px; padding-bottom: 0px; padding-top: 0px; padding-left: "
|
||||||
|
"0px; } b span p br { margin-bottom: 0px; margin-top: 0px; padding-top: "
|
||||||
|
"0px; padding-botom: 0px; text-indent: 0px; } </style>";
|
||||||
|
stats += "<b>File:</b> " + getProperty("filename").toString();
|
||||||
|
stats += "<blockquote>";
|
||||||
|
stats += "<b>Format/Protocol:</b> " + getProperty("file-format").toString() +
|
||||||
|
"<br>";
|
||||||
|
QLocale a;
|
||||||
|
|
||||||
|
stats +=
|
||||||
|
"<b>Cache:</b> " +
|
||||||
|
a.formattedDataSize(getProperty("cache-used").toDouble()) + " (" +
|
||||||
|
Utils::createTimestamp(getProperty("demuxer-cache-duration").toInt()) +
|
||||||
|
|
||||||
|
")<br>";
|
||||||
|
stats += "<b>Size:</b> " +
|
||||||
|
a.formattedDataSize(getProperty("file-size").toInt()) + "<br>";
|
||||||
|
|
||||||
|
stats += "</blockquote>";
|
||||||
|
|
||||||
|
stats += "<b>Video:</b> " + getProperty("video-codec").toString();
|
||||||
|
stats += "<blockquote>";
|
||||||
|
QString avsync = QString::number(getProperty("avsync").toDouble(), 'f', 3);
|
||||||
|
stats += "<b>A-V:</b> " + QString(avsync) + "<br>";
|
||||||
|
stats += "<b>Dropped Frames:</b> " +
|
||||||
|
getProperty("decoder-frame-drop-count").toString() + " (decoder) " +
|
||||||
|
getProperty("frame-drop-count").toString() + " (output)<br>";
|
||||||
|
|
||||||
|
stats += "</blockquote>";
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
QQuickFramebufferObject::Renderer*
|
QQuickFramebufferObject::Renderer*
|
||||||
MPVBackend::createRenderer() const
|
MPVBackend::createRenderer() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,6 +58,7 @@ public slots:
|
||||||
QVariant playerCommand(const Enums::Commands& command, const QVariant& args);
|
QVariant playerCommand(const Enums::Commands& command, const QVariant& args);
|
||||||
QVariant playerCommand(const Enums::Commands& command);
|
QVariant playerCommand(const Enums::Commands& command);
|
||||||
void toggleOnTop();
|
void toggleOnTop();
|
||||||
|
QString getStats();
|
||||||
// Optional but handy for MPV or custom backend settings.
|
// Optional but handy for MPV or custom backend settings.
|
||||||
void command(const QVariant& params);
|
void command(const QVariant& params);
|
||||||
void setProperty(const QString& name, const QVariant& value);
|
void setProperty(const QString& name, const QVariant& value);
|
||||||
|
|
|
@ -63,5 +63,4 @@ class Dummy : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
#include "Backends/MPV/MPVBackend.hpp"
|
#include "Backends/MPV/MPVBackend.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "qmldebugger.h"
|
|
||||||
#include "enums.hpp"
|
#include "enums.hpp"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "qmldebugger.h"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
|
@ -490,7 +490,7 @@ MenuBar {
|
||||||
Action {
|
Action {
|
||||||
text: translate.getTranslation("STATS", i18n.language)
|
text: translate.getTranslation("STATS", i18n.language)
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
player.playerCommand(Enums.Commands.ToggleStats)
|
statsForNerdsText.visible = !statsForNerdsText.visible
|
||||||
}
|
}
|
||||||
shortcut: keybinds.statsForNerds
|
shortcut: keybinds.statsForNerds
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,6 +377,41 @@ Window {
|
||||||
mouseAreaPlayerTimer.restart()
|
mouseAreaPlayerTimer.restart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: statsUpdater
|
||||||
|
interval: 1000
|
||||||
|
running: true
|
||||||
|
repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
if (statsForNerdsText.visible) {
|
||||||
|
statsForNerdsText.text = player.getStats()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: statsForNerdsText
|
||||||
|
text: ""
|
||||||
|
color: "white"
|
||||||
|
visible: false
|
||||||
|
height: parent.height
|
||||||
|
width: parent.width
|
||||||
|
anchors.fill: parent
|
||||||
|
//padding: mainWindow.virtualHeight / 20
|
||||||
|
font.family: appearance.fontName
|
||||||
|
textFormat: Text.RichText
|
||||||
|
font.pixelSize: mainWindow.virtualHeight / 50
|
||||||
|
horizontalAlignment: Text.AlignLeft
|
||||||
|
verticalAlignment: Text.AlignTop
|
||||||
|
renderType: Text.NativeRendering
|
||||||
|
lineHeight: 1
|
||||||
|
Component.onCompleted: {
|
||||||
|
console.error(statsForNerdsText.lineHeight, font.pixelSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MainMenu {
|
MainMenu {
|
||||||
id: menuBar
|
id: menuBar
|
||||||
|
|
|
@ -3,31 +3,31 @@
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
#include <QMetaProperty>
|
#include <QMetaProperty>
|
||||||
|
|
||||||
QString QMLDebugger::properties(QQuickItem *item, bool linebreak)
|
QString
|
||||||
|
QMLDebugger::properties(QQuickItem* item, bool linebreak)
|
||||||
{
|
{
|
||||||
const QMetaObject *meta = item->metaObject();
|
const QMetaObject* meta = item->metaObject();
|
||||||
|
|
||||||
QHash<QString, QVariant> list;
|
QHash<QString, QVariant> list;
|
||||||
for (int i = 0; i < meta->propertyCount(); i++)
|
for (int i = 0; i < meta->propertyCount(); i++) {
|
||||||
{
|
QMetaProperty property = meta->property(i);
|
||||||
QMetaProperty property = meta->property(i);
|
const char* name = property.name();
|
||||||
const char* name = property.name();
|
QVariant value = item->property(name);
|
||||||
QVariant value = item->property(name);
|
list[name] = value;
|
||||||
list[name] = value;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QString out;
|
QString out;
|
||||||
QHashIterator<QString, QVariant> i(list);
|
QHashIterator<QString, QVariant> i(list);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
if (!out.isEmpty())
|
if (!out.isEmpty()) {
|
||||||
{
|
out += ", ";
|
||||||
out += ", ";
|
if (linebreak)
|
||||||
if (linebreak) out += "\n";
|
out += "\n";
|
||||||
}
|
|
||||||
out.append(i.key());
|
|
||||||
out.append(": ");
|
|
||||||
out.append(i.value().toString());
|
|
||||||
}
|
}
|
||||||
return out;
|
out.append(i.key());
|
||||||
|
out.append(": ");
|
||||||
|
out.append(i.value().toString());
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
|
|
||||||
class QMLDebugger : public QObject
|
class QMLDebugger : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE static QString properties(QQuickItem *item, bool linebreak
|
Q_INVOKABLE static QString properties(QQuickItem* item,
|
||||||
= true);
|
bool linebreak = true);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QMLDEBUGGER_H
|
#endif // QMLDEBUGGER_H
|
||||||
|
|
Loading…
Reference in a new issue