From 2a0477bd34d9e9f16c7fe38d6b42da84959db995 Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Sat, 22 Dec 2018 19:32:30 +0000 Subject: [PATCH] [UI] Working on native stats replacement. --- format-code.sh | 2 +- src/Backends/DirectMPV/DirectMPVBackend.cpp | 5 +- src/Backends/MPV/MPVBackend.cpp | 78 ++++++++++++++------- src/Backends/MPV/MPVBackend.hpp | 1 + src/enums.hpp | 1 - src/main.cpp | 2 +- src/qml/MainMenu.qml | 2 +- src/qml/main.qml | 35 +++++++++ src/qmldebugger.cpp | 46 ++++++------ src/qmldebugger.h | 7 +- 10 files changed, 119 insertions(+), 60 deletions(-) diff --git a/format-code.sh b/format-code.sh index 88899d6..9d4f523 100755 --- a/format-code.sh +++ b/format-code.sh @@ -1,5 +1,5 @@ SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" pushd $SOURCE_DIR qmlfmt -w src/qml/*.qml src/qml/*/*.qml -clang-format -style mozilla -i src/* +clang-format -style mozilla -i src/* src/Backends/*/* popd diff --git a/src/Backends/DirectMPV/DirectMPVBackend.cpp b/src/Backends/DirectMPV/DirectMPVBackend.cpp index 1894c79..7991930 100644 --- a/src/Backends/DirectMPV/DirectMPVBackend.cpp +++ b/src/Backends/DirectMPV/DirectMPVBackend.cpp @@ -17,8 +17,7 @@ void wakeup(void* ctx) { - QCoreApplication::postEvent((DirectMPVBackend*)ctx, - new QEvent(QEvent::User)); + QCoreApplication::postEvent((DirectMPVBackend*)ctx, new QEvent(QEvent::User)); } static void* @@ -231,7 +230,7 @@ DirectMPVBackend::playerCommand(const Enums::Commands& cmd) QVariant DirectMPVBackend::playerCommand(const Enums::Commands& cmd, - const QVariant& args) + const QVariant& args) { switch (cmd) { case Enums::Commands::TogglePlayPause: { diff --git a/src/Backends/MPV/MPVBackend.cpp b/src/Backends/MPV/MPVBackend.cpp index 657bb96..d58d913 100644 --- a/src/Backends/MPV/MPVBackend.cpp +++ b/src/Backends/MPV/MPVBackend.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #endif auto mpvLogger = initLogger("mpv"); @@ -82,11 +81,6 @@ public: if (QGuiApplication::platformName().contains("xcb")) { params[2].type = MPV_RENDER_PARAM_X11_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 @@ -109,16 +103,9 @@ public: .h = fbo->height(), .internal_format = 0 }; int flip_y{ 0 }; - mpv_render_param params[] = { - { MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo }, - - // 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_param params[] = { { MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo }, + { MPV_RENDER_PARAM_FLIP_Y, &flip_y }, + { MPV_RENDER_PARAM_INVALID, nullptr } }; mpv_render_context_render(obj->mpv_gl, params); obj->window()->resetOpenGLState(); } @@ -129,7 +116,6 @@ MPVBackend::MPVBackend(QQuickItem* parent) , mpv{ mpv_create() } , mpv_gl(nullptr) { - mpvLogger->set_pattern("[%n]%v%$"); if (!mpv) throw std::runtime_error("could not create mpv context"); @@ -139,12 +125,10 @@ MPVBackend::MPVBackend(QQuickItem* parent) // Fix? mpv_set_option_string(mpv, "ytdl", "yes"); 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, "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, "chapter-list", MPV_FORMAT_NODE); 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, "speed", MPV_FORMAT_DOUBLE); - mpv_request_log_messages(mpv, "debug"); + mpv_request_log_messages(mpv, "trace"); mpv_set_wakeup_callback(mpv, wakeup, this); @@ -191,8 +175,12 @@ MPVBackend::~MPVBackend() { printf("Shutting down...\n"); Utils::SetDPMS(true); - command("quit-watch-later"); - mpv_render_context_free(mpv_gl); + command("write-watch-later-config"); + + if (mpv_gl) { + mpv_render_context_free(mpv_gl); + } + mpv_terminate_destroy(mpv); printf("MPV terminated.\n"); } @@ -244,8 +232,7 @@ MPVBackend::playerCommand(const Enums::Commands& cmd) } QVariant -MPVBackend::playerCommand(const Enums::Commands& cmd, - const QVariant& args) +MPVBackend::playerCommand(const Enums::Commands& cmd, const QVariant& args) { switch (cmd) { case Enums::Commands::TogglePlayPause: { @@ -571,9 +558,9 @@ MPVBackend::handle_mpv_event(mpv_event* event) QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text); QString msgLevel = QString(msg->level); if (msgLevel.startsWith("d")) { - mpvLogger->debug("{}", logMsg.toUtf8().constData()); + mpvLogger->debug("{}", logMsg.toStdString()); } 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 = + ""; + stats += "File: " + getProperty("filename").toString(); + stats += "
"; + stats += "Format/Protocol: " + getProperty("file-format").toString() + + "
"; + QLocale a; + + stats += + "Cache: " + + a.formattedDataSize(getProperty("cache-used").toDouble()) + " (" + + Utils::createTimestamp(getProperty("demuxer-cache-duration").toInt()) + + + ")
"; + stats += "Size: " + + a.formattedDataSize(getProperty("file-size").toInt()) + "
"; + + stats += "
"; + + stats += "Video: " + getProperty("video-codec").toString(); + stats += "
"; + QString avsync = QString::number(getProperty("avsync").toDouble(), 'f', 3); + stats += "A-V: " + QString(avsync) + "
"; + stats += "Dropped Frames: " + + getProperty("decoder-frame-drop-count").toString() + " (decoder) " + + getProperty("frame-drop-count").toString() + " (output)
"; + + stats += "
"; + + return stats; +} + QQuickFramebufferObject::Renderer* MPVBackend::createRenderer() const { diff --git a/src/Backends/MPV/MPVBackend.hpp b/src/Backends/MPV/MPVBackend.hpp index 9efc040..533568c 100644 --- a/src/Backends/MPV/MPVBackend.hpp +++ b/src/Backends/MPV/MPVBackend.hpp @@ -58,6 +58,7 @@ public slots: QVariant playerCommand(const Enums::Commands& command, const QVariant& args); QVariant playerCommand(const Enums::Commands& command); void toggleOnTop(); + QString getStats(); // Optional but handy for MPV or custom backend settings. void command(const QVariant& params); void setProperty(const QString& name, const QVariant& value); diff --git a/src/enums.hpp b/src/enums.hpp index ed439cc..4daaa7e 100644 --- a/src/enums.hpp +++ b/src/enums.hpp @@ -63,5 +63,4 @@ class Dummy : public QObject Q_OBJECT }; - #endif diff --git a/src/main.cpp b/src/main.cpp index 8286aff..da18274 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,9 +3,9 @@ #include "Backends/MPV/MPVBackend.hpp" #endif -#include "qmldebugger.h" #include "enums.hpp" #include "logger.h" +#include "qmldebugger.h" #include "utils.hpp" #include diff --git a/src/qml/MainMenu.qml b/src/qml/MainMenu.qml index fb6e013..dd701a7 100644 --- a/src/qml/MainMenu.qml +++ b/src/qml/MainMenu.qml @@ -490,7 +490,7 @@ MenuBar { Action { text: translate.getTranslation("STATS", i18n.language) onTriggered: { - player.playerCommand(Enums.Commands.ToggleStats) + statsForNerdsText.visible = !statsForNerdsText.visible } shortcut: keybinds.statsForNerds } diff --git a/src/qml/main.qml b/src/qml/main.qml index 25be1c7..b3d991d 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -377,6 +377,41 @@ Window { 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 { id: menuBar diff --git a/src/qmldebugger.cpp b/src/qmldebugger.cpp index 2da1a5e..313e1b2 100644 --- a/src/qmldebugger.cpp +++ b/src/qmldebugger.cpp @@ -3,31 +3,31 @@ #include #include -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 list; - for (int i = 0; i < meta->propertyCount(); i++) - { - QMetaProperty property = meta->property(i); - const char* name = property.name(); - QVariant value = item->property(name); - list[name] = value; - } + QHash list; + for (int i = 0; i < meta->propertyCount(); i++) { + QMetaProperty property = meta->property(i); + const char* name = property.name(); + QVariant value = item->property(name); + list[name] = value; + } - QString out; - QHashIterator i(list); - while (i.hasNext()) { - i.next(); - if (!out.isEmpty()) - { - out += ", "; - if (linebreak) out += "\n"; - } - out.append(i.key()); - out.append(": "); - out.append(i.value().toString()); + QString out; + QHashIterator i(list); + while (i.hasNext()) { + i.next(); + if (!out.isEmpty()) { + out += ", "; + if (linebreak) + out += "\n"; } - return out; + out.append(i.key()); + out.append(": "); + out.append(i.value().toString()); + } + return out; } diff --git a/src/qmldebugger.h b/src/qmldebugger.h index 00dac2c..13ed1de 100644 --- a/src/qmldebugger.h +++ b/src/qmldebugger.h @@ -6,11 +6,10 @@ class QMLDebugger : public QObject { - Q_OBJECT + Q_OBJECT public: - Q_INVOKABLE static QString properties(QQuickItem *item, bool linebreak -= true); - + Q_INVOKABLE static QString properties(QQuickItem* item, + bool linebreak = true); }; #endif // QMLDEBUGGER_H