Skip to content

Commit

Permalink
Added ability to get media file metadata (artist name, album, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickelson committed Sep 6, 2014
1 parent df950f5 commit 8d41878
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
9 changes: 9 additions & 0 deletions src/fe_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,12 @@ int FeSound::get_time()
return 0;
#endif
}

const char *FeSound::get_metadata( const char *tag )
{
#ifndef NO_MOVIE
return m_sound.get_metadata( tag );
#else
return "";
#endif
}
1 change: 1 addition & 0 deletions src/fe_sound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class FeSound

int get_duration();
int get_time();
const char *get_metadata( const char * );
};

class FeSoundSystem
Expand Down
42 changes: 20 additions & 22 deletions src/media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ class FeBaseStream
sf::Mutex m_packetq_mutex;

public:
virtual ~FeBaseStream();

bool at_end; // set when at the end of our input
AVCodecContext *codec_ctx;
AVCodec *codec;
int stream_id;

FeBaseStream();
void close();
void stop();
virtual void stop();
AVPacket *pop_packet();
void push_packet( AVPacket *pkt );
void clear_packet_queue();
Expand All @@ -137,7 +138,6 @@ class FeAudioImp : public FeBaseStream

FeAudioImp();
~FeAudioImp();
void close();
};

//
Expand Down Expand Up @@ -169,9 +169,10 @@ class FeVideoImp : public FeBaseStream
sf::Uint8 *display_frame;

FeVideoImp( FeMedia *parent );
~FeVideoImp();

void play();
void stop();
void close();

void preload();
void video_thread();
Expand All @@ -185,7 +186,7 @@ FeBaseStream::FeBaseStream()
{
}

void FeBaseStream::close()
FeBaseStream::~FeBaseStream()
{
if ( codec_ctx )
{
Expand Down Expand Up @@ -267,29 +268,21 @@ FeAudioImp::FeAudioImp()

FeAudioImp::~FeAudioImp()
{
close();
}
sf::Lock l( buffer_mutex );

void FeAudioImp::close()
{
#ifdef DO_RESAMPLE
if ( resample_ctx )
{
sf::Lock l( buffer_mutex );
resample_free( &resample_ctx );
resample_ctx = NULL;
}
#endif

if ( buffer )
{
sf::Lock l( buffer_mutex );

av_free( buffer );
buffer=NULL;
}

FeBaseStream::close();
}

FeVideoImp::FeVideoImp( FeMedia *p )
Expand All @@ -301,6 +294,11 @@ FeVideoImp::FeVideoImp( FeMedia *p )
{
}

FeVideoImp::~FeVideoImp()
{
stop();
}

void FeVideoImp::play()
{
run_video_thread = true;
Expand All @@ -319,12 +317,6 @@ void FeVideoImp::stop()
FeBaseStream::stop();
}

void FeVideoImp::close()
{
stop();
FeBaseStream::close();
}

namespace
{
void set_avdiscard_from_qscore( AVCodecContext *c, int qscore )
Expand Down Expand Up @@ -747,14 +739,12 @@ void FeMedia::close()

if (m_audio)
{
m_audio->close();
delete m_audio;
m_audio=NULL;
}

if (m_video)
{
m_video->close();
delete m_video;
m_video=NULL;
}
Expand Down Expand Up @@ -1187,3 +1177,11 @@ sf::Time FeMedia::get_duration() const

return sf::Time::Zero;
}

const char *FeMedia::get_metadata( const char *tag )
{
AVDictionaryEntry *entry = NULL;
entry = av_dict_get( m_format_ctx->metadata, tag, NULL, AV_DICT_IGNORE_SUFFIX );

return ( entry ? entry->value : "" );
}
2 changes: 2 additions & 0 deletions src/media.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ friend class FeVideoImp;
sf::Time get_video_time();
sf::Time get_duration() const;

const char *get_metadata( const char *tag );

//
// return true if the given filename is a media file that can be opened
// by FeMedia
Expand Down

0 comments on commit 8d41878

Please sign in to comment.