[vlc-devel] [PATCH 10/15] qml: expose video and audio description as separate properties in mlvideo

Prince Gupta guptaprince8832 at gmail.com
Tue Jul 21 15:47:08 CEST 2020


---
 modules/gui/qt/medialibrary/mlvideo.cpp | 81 +++++++++++++++++++++----
 modules/gui/qt/medialibrary/mlvideo.hpp | 58 ++++++++++++++++--
 2 files changed, 121 insertions(+), 18 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index 075bc2adc0..3092d9b3ce 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -22,6 +22,58 @@
 
 #include <vlc_thumbnailer.h>
 
+VideoDescription::VideoDescription(const QString &codec, const QString &language, const unsigned int fps, QObject *parent)
+    : QObject(parent)
+    , m_codec(codec)
+    , m_language(language)
+    , m_fps(fps)
+{
+}
+
+QString VideoDescription::getCodec() const
+{
+    return m_codec;
+}
+
+QString VideoDescription::getLanguage() const
+{
+    return m_language;
+}
+
+unsigned int VideoDescription::getFps() const
+{
+    return m_fps;
+}
+
+AudioDescription::AudioDescription(const QString &codec, const QString &language, const unsigned int nbChannels, const unsigned int sampleRate, QObject *parent)
+    : QObject(parent)
+    , m_codec(codec)
+    , m_language(language)
+    , m_nbchannels(nbChannels)
+    , m_sampleRate(sampleRate)
+{
+}
+
+QString AudioDescription::getCodec() const
+{
+    return m_codec;
+}
+
+QString AudioDescription::getLanguage() const
+{
+    return m_language;
+}
+
+unsigned int AudioDescription::getNbChannels() const
+{
+    return m_nbchannels;
+}
+
+unsigned int AudioDescription::getSampleRate() const
+{
+    return m_sampleRate;
+}
+
 MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* parent)
     : QObject( parent )
     , m_ml( ml )
@@ -60,20 +112,22 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
         if ( track.i_type == VLC_ML_TRACK_TYPE_AUDIO ) {
             numChannel = std::max( numChannel , track.a.i_nbChannels );
 
-            audioDesc += qtr( "\n\tCodec: %1\n\tLanguage: %2\n\tChannels: %3\n\tSample Rate: %4" )
-                    .arg( QString::fromUtf8( track.psz_codec ))
-                    .arg( QString::fromUtf8( track.psz_language  ) )
-                    .arg( QString::number( track.a.i_nbChannels) )
-                    .arg( QString::number( track.a.i_sampleRate ) );
+            m_audioDesc.push_back( new AudioDescription ( QString::fromUtf8( track.psz_codec ) ,
+                                                         QString::fromUtf8( track.psz_language  ) ,
+                                                         track.a.i_nbChannels ,
+                                                         track.a.i_sampleRate ,
+                                                         this )
+                                   );
         }
         else if ( track.i_type == VLC_ML_TRACK_TYPE_VIDEO ){
             maxWidth = std::max( maxWidth, track.v.i_width );
             maxHeight = std::max( maxHeight, track.v.i_height );
 
-            videoDesc += qtr( "\n\tCodec: %1\n\tLanguage: %2\n\tFPS: %3" )
-                    .arg( QString::fromUtf8( track.psz_codec ) )
-                    .arg( QString::fromUtf8( track.psz_language ) )
-                    .arg( QString::number( track.v.i_fpsNum ) );
+            m_videoDesc.push_back(  new VideoDescription( QString::fromUtf8( track.psz_codec ) ,
+                                                        QString::fromUtf8( track.psz_language ) ,
+                                                        track.v.i_fpsNum,
+                                                        this )
+                                  );
         }
     }
 
@@ -190,19 +244,20 @@ unsigned int MLVideo::getPlayCount() const
 {
     return m_playCount;
 }
+
 QString MLVideo::getProgressTime() const
 {
     return MsToString(m_duration * m_progress);
 }
 
-QString MLVideo::getVideoDesc() const
+QObjectList MLVideo::getVideoDesc() const
 {
-    return videoDesc;
+    return m_videoDesc;
 }
 
-QString MLVideo::getAudioDesc() const
+QObjectList MLVideo::getAudioDesc() const
 {
-    return audioDesc;
+    return m_audioDesc;
 }
 
 MLVideo*MLVideo::clone(QObject* parent) const
diff --git a/modules/gui/qt/medialibrary/mlvideo.hpp b/modules/gui/qt/medialibrary/mlvideo.hpp
index c5f6bbb23b..a32ba1fa59 100644
--- a/modules/gui/qt/medialibrary/mlvideo.hpp
+++ b/modules/gui/qt/medialibrary/mlvideo.hpp
@@ -32,6 +32,53 @@
 
 #include <functional>
 
+class VideoDescription : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QString codec READ getCodec CONSTANT)
+    Q_PROPERTY(QString language READ getLanguage CONSTANT)
+    Q_PROPERTY(unsigned int fps READ getFps CONSTANT)
+
+public:
+    VideoDescription(const QString& codec, const QString& language, unsigned int fps, QObject *parent = nullptr);
+
+    QString getCodec() const;
+    QString getLanguage() const;
+    unsigned int getFps() const;
+
+private:
+
+    QString m_codec;
+    QString m_language;
+    unsigned int m_fps;
+};
+
+class AudioDescription : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QString codec READ getCodec CONSTANT)
+    Q_PROPERTY(QString language READ getLanguage CONSTANT)
+    Q_PROPERTY(unsigned int nbchannels READ getNbChannels CONSTANT)
+    Q_PROPERTY(unsigned int sampleRate READ getSampleRate CONSTANT)
+
+public:
+    AudioDescription(const QString& codec, const QString& language, unsigned int nbChannels, unsigned int sampleRate, QObject *parent = nullptr);
+
+    QString getCodec() const;
+    QString getLanguage() const;
+    unsigned int getNbChannels() const;
+    unsigned int getSampleRate() const;
+
+private:
+
+    QString m_codec;
+    QString m_language;
+    unsigned int m_nbchannels;
+    unsigned int m_sampleRate;
+};
+
 class MLVideo : public QObject
 {
     Q_OBJECT
@@ -48,8 +95,8 @@ class MLVideo : public QObject
     Q_PROPERTY(QString resolution_name READ getResolutionName CONSTANT);
     Q_PROPERTY(QString channel READ getChannel CONSTANT);
     Q_PROPERTY(QString progressTime READ getProgressTime CONSTANT);
-    Q_PROPERTY(QString audioDesc READ getAudioDesc CONSTANT);
-    Q_PROPERTY(QString videoDesc READ getVideoDesc CONSTANT);
+    Q_PROPERTY(QObjectList audioDesc READ getAudioDesc CONSTANT);
+    Q_PROPERTY(QObjectList videoDesc READ getVideoDesc CONSTANT);
 
 public:
     MLVideo(vlc_medialibrary_t *ml, const vlc_ml_media_t *data, QObject *parent = nullptr);
@@ -66,8 +113,8 @@ public:
     float getProgress() const;
     unsigned int getPlayCount() const;
     QString getProgressTime() const;
-    QString getAudioDesc() const;
-    QString getVideoDesc() const;
+    QObjectList getAudioDesc() const;
+    QObjectList getVideoDesc() const;
 
     MLVideo* clone(QObject* parent = nullptr) const;
 
@@ -93,7 +140,8 @@ private:
     QString m_progressTime;
     unsigned int m_playCount;
     bool m_thumbnailGenerated;
-    QString audioDesc,videoDesc;
+    QObjectList m_audioDesc;
+    QObjectList m_videoDesc;
 
     std::unique_ptr<vlc_ml_event_callback_t,
                     std::function<void(vlc_ml_event_callback_t*)>> m_ml_event_handle;
-- 
2.25.1



More information about the vlc-devel mailing list