Commit 43fa9b20 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

VLCMedia: Allow video and audio codec to be queried.

parent c8fb73a1
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
using namespace LibVLCpp; using namespace LibVLCpp;
Media::Media( const QString& filename ) : Media::Media( const QString& filename ) :
m_fileName( filename ) m_fileName( filename ),
m_tracksInfo( NULL )
{ {
m_internalPtr = libvlc_media_new_location( *(LibVLCpp::Instance::getInstance()), m_internalPtr = libvlc_media_new_location( *(LibVLCpp::Instance::getInstance()),
filename.toLocal8Bit() ); filename.toLocal8Bit() );
...@@ -39,6 +40,8 @@ Media::Media( const QString& filename ) : ...@@ -39,6 +40,8 @@ Media::Media( const QString& filename ) :
Media::~Media() Media::~Media()
{ {
// tracks info gets allocated by vlc, so we use free.
free( m_tracksInfo );
libvlc_media_release( m_internalPtr ); libvlc_media_release( m_internalPtr );
} }
...@@ -108,3 +111,33 @@ Media::getFileName() const ...@@ -108,3 +111,33 @@ Media::getFileName() const
{ {
return m_fileName; 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;
}
...@@ -46,9 +46,17 @@ namespace LibVLCpp ...@@ -46,9 +46,17 @@ namespace LibVLCpp
void setVideoDataCtx( void* dataCtx ); void setVideoDataCtx( void* dataCtx );
void setAudioDataCtx( void* dataCtx ); void setAudioDataCtx( void* dataCtx );
const QString& getFileName() const; const QString& getFileName() const;
void parse();
void fetchTrackInfo();
unsigned int videoCodec() const;
unsigned int audioCodec() const;
private: 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;
}; };
} }
......
...@@ -82,7 +82,11 @@ MetaDataWorker::run() ...@@ -82,7 +82,11 @@ MetaDataWorker::run()
emit failed( m_media ); emit failed( m_media );
} }
else else
{
// parse some extra meta data from the media itself :
m_media->vlcMedia()->parse();
metaDataAvailable(); metaDataAvailable();
}
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment