From eeaec187cb6d49128d305e7bad97632c0969bd77 Mon Sep 17 00:00:00 2001 From: bissen21 Date: Sat, 28 Oct 2023 16:17:30 -0500 Subject: [PATCH] Register mediainfo with QML. Display HDR type --- DoViGUI/Main.qml | 35 ++++++++++++++++++++++++++++++++--- DoViGUI/main.cpp | 7 +++++-- DoViGUI/myMediaInfo.cpp | 10 +++++++--- DoViGUI/myMediaInfo.h | 13 ++++++++----- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/DoViGUI/Main.qml b/DoViGUI/Main.qml index da8f0d6..a6a6af4 100644 --- a/DoViGUI/Main.qml +++ b/DoViGUI/Main.qml @@ -31,18 +31,31 @@ Window { anchors.rightMargin: 25 color: "lightgrey" height: txtVideoFile.font.pixelSize + 10 + id: txtBackground + TextEdit { id: txtVideoFile text: "" - anchors.fill: parent - anchors.leftMargin: 15 verticalAlignment: TextEdit.AlignVCenter + anchors.fill: parent readOnly: false selectByMouse: true font.pixelSize: 14 + anchors.leftMargin: 15 + anchors.rightMargin: 15 } } + Text { + //TODO Need to scroll and clip long text + id: hdrType + anchors.left: btnVideoFile.left + anchors.top: txtBackground.bottom + width: 200 + text: "None" + wrapMode: TextEdit.Wrap + } + FileDialog { @@ -50,6 +63,22 @@ Window { fileMode: FileDialog.OpenFile nameFilters: ["Video files (*.mkv *.mp4)", "All files (*)"] onAccepted: { const reg = /^file:\/\/\// //Remove "file:/// at start of URL - txtVideoFile.text = videoFileDialog.selectedFile.toString().replace(reg, "") } + var fileName = videoFileDialog.selectedFile.toString().replace(reg, "") + txtVideoFile.text = fileName + + switch (mediaInfo.getHDRType(fileName)) { + case 0: + hdrType.text = "SDR" + break + case 1: + hdrType.text = "HDR" + break + case 2: + hdrType.text = "Dolby Vision" + break + default: + hdrType.text = "Error" + } + } } } diff --git a/DoViGUI/main.cpp b/DoViGUI/main.cpp index f9ed8bf..f45228c 100644 --- a/DoViGUI/main.cpp +++ b/DoViGUI/main.cpp @@ -3,16 +3,17 @@ #include #include +#include int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - myMediaInfo mInfo; + myMediaInfo mInfo(&app); //Check if HDR/DolbyVision - enum myMediaInfo::HDR hdrType = mInfo.getHDR(__T("Cosmos.mkv")); + enum myMediaInfo::HDR_Type hdrType = mInfo.getHDRType(__T("Cosmos.mkv")); if (hdrType >= 0) { qInfo() << hdrType; } else { @@ -21,6 +22,8 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("mediaInfo", &mInfo); + const QUrl url(u"qrc:/DoViGUI/Main.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, diff --git a/DoViGUI/myMediaInfo.cpp b/DoViGUI/myMediaInfo.cpp index d6ff7dd..8fb236e 100644 --- a/DoViGUI/myMediaInfo.cpp +++ b/DoViGUI/myMediaInfo.cpp @@ -1,14 +1,14 @@ #include "myMediaInfo.h" #include "MediaInfoDLL.h" +#include "qvariant.h" #include -myMediaInfo::myMediaInfo() { -} +myMediaInfo::myMediaInfo(QObject *parent){} -enum myMediaInfo::HDR myMediaInfo::getHDR(const MediaInfoDLL::String fileName) { +enum myMediaInfo::HDR_Type myMediaInfo::getHDRType(const MediaInfoDLL::String fileName) { if (Open(fileName)) { MediaInfoDLL::String HDRtext = Get(MediaInfoDLL::Stream_Video, 0, __T("HDR_Format"), MediaInfoDLL::Info_Text, MediaInfoDLL::Info_Name); Close(); @@ -23,3 +23,7 @@ enum myMediaInfo::HDR myMediaInfo::getHDR(const MediaInfoDLL::String fileName) { } return ERR; } + +enum myMediaInfo::HDR_Type myMediaInfo::getHDRType(const QString fileName) { + return getHDRType(fileName.toStdWString()); +} diff --git a/DoViGUI/myMediaInfo.h b/DoViGUI/myMediaInfo.h index 94104cb..966ea89 100644 --- a/DoViGUI/myMediaInfo.h +++ b/DoViGUI/myMediaInfo.h @@ -2,16 +2,19 @@ #define MYMEDIAINFO_H #include +//#include "qvariant.h" #include -class myMediaInfo : public MediaInfoDLL::MediaInfo{ -// Q_OBJECT +class myMediaInfo : public QObject, public MediaInfoDLL::MediaInfo { + Q_OBJECT public: - myMediaInfo(); - enum HDR{ERR = -1, SDR = 0, HDR = 1, DOVI = 2}; + myMediaInfo(QObject* parent = nullptr); + enum HDR_Type{ERR = -1, SDR = 0, HDR = 1, DOVI = 2}; + Q_ENUM(HDR_Type) - enum HDR getHDR(const MediaInfoDLL::String fileName); + enum HDR_Type getHDRType(const MediaInfoDLL::String fileName); + Q_INVOKABLE enum HDR_Type getHDRType(QString fileName); private: