[vlmc-devel] VLCMedia: Allow video and audio codec to be queried.

Hugo Beauzée-Luyssen git at videolan.org
Mon Sep 24 22:35:36 CEST 2012


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Mon Sep 24 22:34:20 2012 +0300| [43fa9b20cdd7668a0456f551982b3a1b987c2d00] | committer: Hugo Beauzée-Luyssen

VLCMedia: Allow video and audio codec to be queried.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=43fa9b20cdd7668a0456f551982b3a1b987c2d00
---

 src/LibVLCpp/VLCMedia.cpp       |   35 ++++++++++++++++++++++++++++++++++-
 src/LibVLCpp/VLCMedia.h         |   10 +++++++++-
 src/Metadata/MetaDataWorker.cpp |    4 ++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/LibVLCpp/VLCMedia.cpp b/src/LibVLCpp/VLCMedia.cpp
index 5586e3e..2bbafef 100644
--- a/src/LibVLCpp/VLCMedia.cpp
+++ b/src/LibVLCpp/VLCMedia.cpp
@@ -31,7 +31,8 @@
 using namespace LibVLCpp;
 
 Media::Media( const QString& filename ) :
-    m_fileName( filename )
+    m_fileName( filename ),
+    m_tracksInfo( NULL )
 {
     m_internalPtr = libvlc_media_new_location( *(LibVLCpp::Instance::getInstance()),
                                                filename.toLocal8Bit() );
@@ -39,6 +40,8 @@ Media::Media( const QString& filename ) :
 
 Media::~Media()
 {
+    // tracks info gets allocated by vlc, so we use free.
+    free( m_tracksInfo );
     libvlc_media_release( m_internalPtr );
 }
 
@@ -108,3 +111,33 @@ Media::getFileName() const
 {
     return m_fileName;
 }
+
+void
+Media::parse()
+{
+    libvlc_media_parse( *this );
+}
+
+void
+Media::fetchTrackInfo()
+{
+    m_nbTracks = libvlc_media_get_tracks_info( *this, &m_tracksInfo );
+}
+
+unsigned int
+Media::videoCodec() const
+{
+    for ( int i = 0; i < m_nbTracks; ++i )
+        if ( m_tracksInfo[i].i_type == libvlc_track_video )
+            return m_tracksInfo[i].i_codec;
+    return 0;
+}
+
+unsigned int
+Media::audioCodec() const
+{
+    for ( int i = 0; i < m_nbTracks; ++i )
+        if ( m_tracksInfo[i].i_type == libvlc_track_video )
+            return m_tracksInfo[i].i_codec;
+    return 0;
+}
diff --git a/src/LibVLCpp/VLCMedia.h b/src/LibVLCpp/VLCMedia.h
index d7cb0d7..9260f3d 100644
--- a/src/LibVLCpp/VLCMedia.h
+++ b/src/LibVLCpp/VLCMedia.h
@@ -46,9 +46,17 @@ namespace LibVLCpp
         void                setVideoDataCtx( void* dataCtx );
         void                setAudioDataCtx( void* dataCtx );
         const QString&      getFileName() const;
+        void                parse();
+        void                fetchTrackInfo();
+        unsigned int videoCodec() const;
+        unsigned int audioCodec() const;
 
     private:
-        QString             m_fileName;
+        QString                     m_fileName;
+        libvlc_media_track_info_t   *m_tracksInfo;
+        // this has not to be equal to nb video tracks + nb audio tracks.
+        // it is only meant to use when iterating over m_tracksInfo
+        int                         m_nbTracks;
     };
 }
 
diff --git a/src/Metadata/MetaDataWorker.cpp b/src/Metadata/MetaDataWorker.cpp
index 878fe3a..f2d15f3 100644
--- a/src/Metadata/MetaDataWorker.cpp
+++ b/src/Metadata/MetaDataWorker.cpp
@@ -82,7 +82,11 @@ MetaDataWorker::run()
         emit failed( m_media );
     }
     else
+    {
+        // parse some extra meta data from the media itself :
+        m_media->vlcMedia()->parse();
         metaDataAvailable();
+    }
 }
 
 void



More information about the Vlmc-devel mailing list