1
0
Fork 0

Add humanSize.

This commit is contained in:
namedkitten 2020-04-26 03:17:48 +01:00
parent a97ef5f9e3
commit 2f5a451c10
3 changed files with 26 additions and 11 deletions

View file

@ -6,7 +6,6 @@ set(CMAKE_AUTOMOC ON)
include(ExternalProject) include(ExternalProject)
find_package(Qt5Core REQUIRED) find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED) find_package(Qt5Gui REQUIRED)
find_package(Qt5Concurrent REQUIRED) find_package(Qt5Concurrent REQUIRED)
@ -93,6 +92,8 @@ add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
endif(DEFINED ENV{TRAVIS}) endif(DEFINED ENV{TRAVIS})
add_executable(KittehPlayer ${SOURCES} ${qml_QRC}) add_executable(KittehPlayer ${SOURCES} ${qml_QRC})
set_property(TARGET KittehPlayer PROPERTY CXX_STANDARD 14)
# Use the Qml/Quick modules from Qt 5. # Use the Qml/Quick modules from Qt 5.
target_link_libraries(KittehPlayer ${MPV_LIBRARIES} ${X11_LIBRARIES} ${Xext_LIBRARIES} Qt5::X11Extras) target_link_libraries(KittehPlayer ${MPV_LIBRARIES} ${X11_LIBRARIES} ${Xext_LIBRARIES} Qt5::X11Extras)

View file

@ -20,6 +20,24 @@
auto mpvLogger = initLogger("mpv"); auto mpvLogger = initLogger("mpv");
QString humanSize(uint64_t bytes)
{
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
char length = sizeof(suffix) / sizeof(suffix[0]);
int i = 0;
double dblBytes = bytes;
if (bytes > 1024) {
for (i = 0; (bytes / 1024) > 0 && i<length-1; i++, bytes /= 1024)
dblBytes = bytes / 1024.0;
}
static char output[200];
sprintf(output, "%.02lf %s", dblBytes, suffix[i]);
return QString(output);
}
static inline QVariant mpvnode_to_variant(const mpv_node *node) static inline QVariant mpvnode_to_variant(const mpv_node *node)
{ {
if (!node) { if (!node) {
@ -75,10 +93,7 @@ QString getStats(BackendInterface *b) {
} }
QString fileFormat = b->getProperty("file-format").toString(); QString fileFormat = b->getProperty("file-format").toString();
stats += "<b>Format/Protocol:</b> " + fileFormat + "<br>"; stats += "<b>Format/Protocol:</b> " + fileFormat + "<br>";
QLocale a;
// a.formattedDataSize(
double cacheUsed = b->getProperty("cache-used").toDouble(); double cacheUsed = b->getProperty("cache-used").toDouble();
// Utils::createTimestamp(
int demuxerSecs = b->getProperty("demuxer-cache-duration").toInt(); int demuxerSecs = b->getProperty("demuxer-cache-duration").toInt();
QVariantMap demuxerState = b->getProperty("demuxer-cache-state").toMap(); QVariantMap demuxerState = b->getProperty("demuxer-cache-state").toMap();
int demuxerCache = demuxerState.value("fw-bytes", QVariant(0)).toInt(); int demuxerCache = demuxerState.value("fw-bytes", QVariant(0)).toInt();
@ -86,23 +101,23 @@ QString getStats(BackendInterface *b) {
if (demuxerSecs + demuxerCache + cacheUsed > 0) { if (demuxerSecs + demuxerCache + cacheUsed > 0) {
QString cacheStats; QString cacheStats;
cacheStats += "<b>Total Cache:</b> "; cacheStats += "<b>Total Cache:</b> ";
cacheStats += a.formattedDataSize(demuxerCache + cacheUsed); cacheStats += humanSize(demuxerCache + cacheUsed);
cacheStats += " (<b>Demuxer:</b> "; cacheStats += " (<b>Demuxer:</b> ";
cacheStats += a.formattedDataSize(demuxerCache); cacheStats += humanSize(demuxerCache);
cacheStats += ", "; cacheStats += ", ";
cacheStats += QString::number(demuxerSecs) + "s) "; cacheStats += QString::number(demuxerSecs) + "s) ";
double cacheSpeed = b->getProperty("cache-speed").toDouble(); double cacheSpeed = b->getProperty("cache-speed").toDouble();
if (cacheSpeed > 0) { if (cacheSpeed > 0) {
cacheStats += "<b>Speed:</b> "; cacheStats += "<b>Speed:</b> ";
cacheStats += a.formattedDataSize(demuxerSecs); cacheStats += humanSize(demuxerSecs);
cacheStats += "/s"; cacheStats += "/s";
} }
cacheStats += "<br>"; cacheStats += "<br>";
stats += cacheStats; stats += cacheStats;
} }
QString fileSize = QString fileSize =
a.formattedDataSize(b->getProperty("file-size").toInt()).remove("-"); humanSize(b->getProperty("file-size").toInt()).remove("-");
stats += "<b>Size:</b> " + fileSize + "<br>"; stats += "<b>Size:</b> " + fileSize + "<br>";
stats += "</blockquote>"; stats += "</blockquote>";
@ -197,7 +212,7 @@ QString getStats(BackendInterface *b) {
int pVB = b->getProperty("packet-video-bitrate").toInt(); int pVB = b->getProperty("packet-video-bitrate").toInt();
if (pVB > 0) { if (pVB > 0) {
stats += "<b>Bitrate:</b> "; stats += "<b>Bitrate:</b> ";
stats += a.formattedDataSize(pVB) + "/s"; stats += humanSize(pVB) + "/s";
stats += "<br>"; stats += "<br>";
} }
@ -227,7 +242,7 @@ QString getStats(BackendInterface *b) {
int pAB = b->getProperty("packet-audio-bitrate").toInt(); int pAB = b->getProperty("packet-audio-bitrate").toInt();
if (pAB > 0) { if (pAB > 0) {
stats += "<b>Bitrate:</b> "; stats += "<b>Bitrate:</b> ";
stats += a.formattedDataSize(pAB) + "/s"; stats += humanSize(pAB) + "/s";
stats += "<br>"; stats += "<br>";
} }

View file

@ -5,7 +5,6 @@
#include <QObject> #include <QObject>
#include <QProcess> #include <QProcess>
#include <QString> #include <QString>
class QObject;
class Process : public QProcess class Process : public QProcess
{ {