mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 00:24:12 +02:00
Style fixes for AudioOutput.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2015, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2014, Adrien Aubry <dridri85@gmail.com>
|
* Copyright 2014, Adrien Aubry <dridri85@gmail.com>
|
||||||
@@ -89,8 +89,10 @@ AudioOutput::AudioOutput( QObject* parent )
|
|||||||
|
|
||||||
// Create and initialize a libvlc instance (it should be done only once)
|
// Create and initialize a libvlc instance (it should be done only once)
|
||||||
m_vlcInstance = libvlc_new( sizeof(vlcArgs) / sizeof(*vlcArgs), vlcArgs );
|
m_vlcInstance = libvlc_new( sizeof(vlcArgs) / sizeof(*vlcArgs), vlcArgs );
|
||||||
if ( !m_vlcInstance ) {
|
if ( !m_vlcInstance )
|
||||||
tDebug() << "libVLC: could not initialize";
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO << "libVLC: could not initialize";
|
||||||
|
//FIXME PANIC, abort
|
||||||
}
|
}
|
||||||
libvlc_set_user_agent( m_vlcInstance, TOMAHAWK_APPLICATION_NAME,
|
libvlc_set_user_agent( m_vlcInstance, TOMAHAWK_APPLICATION_NAME,
|
||||||
TOMAHAWK_APPLICATION_NAME "/" TOMAHAWK_VERSION );
|
TOMAHAWK_APPLICATION_NAME "/" TOMAHAWK_VERSION );
|
||||||
@@ -98,10 +100,7 @@ AudioOutput::AudioOutput( QObject* parent )
|
|||||||
libvlc_set_app_id( m_vlcInstance, "org.tomahawk-player.desktop",
|
libvlc_set_app_id( m_vlcInstance, "org.tomahawk-player.desktop",
|
||||||
TOMAHAWK_VERSION, "tomahawk" );
|
TOMAHAWK_VERSION, "tomahawk" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_vlcPlayer = libvlc_media_player_new( m_vlcInstance );
|
m_vlcPlayer = libvlc_media_player_new( m_vlcInstance );
|
||||||
|
|
||||||
libvlc_event_manager_t* manager = libvlc_media_player_event_manager( m_vlcPlayer );
|
libvlc_event_manager_t* manager = libvlc_media_player_event_manager( m_vlcPlayer );
|
||||||
libvlc_event_type_t events[] = {
|
libvlc_event_type_t events[] = {
|
||||||
libvlc_MediaPlayerMediaChanged,
|
libvlc_MediaPlayerMediaChanged,
|
||||||
@@ -125,11 +124,12 @@ AudioOutput::AudioOutput( QObject* parent )
|
|||||||
libvlc_MediaPlayerVout
|
libvlc_MediaPlayerVout
|
||||||
};
|
};
|
||||||
const int eventCount = sizeof(events) / sizeof( *events );
|
const int eventCount = sizeof(events) / sizeof( *events );
|
||||||
for ( int i = 0 ; i < eventCount ; i++ ) {
|
for ( int i = 0; i < eventCount; i++ )
|
||||||
|
{
|
||||||
libvlc_event_attach( manager, events[ i ], &AudioOutput::vlcEventCallback, this );
|
libvlc_event_attach( manager, events[ i ], &AudioOutput::vlcEventCallback, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
tDebug() << "AudioOutput::AudioOutput OK !\n";
|
tDebug() << Q_FUNC_INFO << "Init OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -137,16 +137,19 @@ AudioOutput::~AudioOutput()
|
|||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( m_vlcPlayer != nullptr ) {
|
if ( m_vlcPlayer != nullptr )
|
||||||
|
{
|
||||||
libvlc_media_player_stop( m_vlcPlayer );
|
libvlc_media_player_stop( m_vlcPlayer );
|
||||||
libvlc_media_player_release( m_vlcPlayer );
|
libvlc_media_player_release( m_vlcPlayer );
|
||||||
m_vlcPlayer = nullptr;
|
m_vlcPlayer = nullptr;
|
||||||
}
|
}
|
||||||
if ( m_vlcMedia != nullptr ) {
|
if ( m_vlcMedia != nullptr )
|
||||||
|
{
|
||||||
libvlc_media_release( m_vlcMedia );
|
libvlc_media_release( m_vlcMedia );
|
||||||
m_vlcMedia = nullptr;
|
m_vlcMedia = nullptr;
|
||||||
}
|
}
|
||||||
if ( m_vlcInstance != nullptr ) {
|
if ( m_vlcInstance != nullptr )
|
||||||
|
{
|
||||||
libvlc_release( m_vlcInstance );
|
libvlc_release( m_vlcInstance );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,13 +198,15 @@ AudioOutput::setCurrentSource( MediaStream* stream )
|
|||||||
|
|
||||||
setState( Loading );
|
setState( Loading );
|
||||||
|
|
||||||
if ( m_vlcMedia != nullptr ) {
|
if ( m_vlcMedia != nullptr )
|
||||||
|
{
|
||||||
// Ensure playback is stopped, then release media
|
// Ensure playback is stopped, then release media
|
||||||
libvlc_media_player_stop( m_vlcPlayer );
|
libvlc_media_player_stop( m_vlcPlayer );
|
||||||
libvlc_media_release( m_vlcMedia );
|
libvlc_media_release( m_vlcMedia );
|
||||||
m_vlcMedia = nullptr;
|
m_vlcMedia = nullptr;
|
||||||
}
|
}
|
||||||
if ( m_autoDelete && m_currentStream != nullptr ) {
|
if ( m_autoDelete && m_currentStream != nullptr )
|
||||||
|
{
|
||||||
delete m_currentStream;
|
delete m_currentStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,17 +217,18 @@ AudioOutput::setCurrentSource( MediaStream* stream )
|
|||||||
m_seekable = true;
|
m_seekable = true;
|
||||||
|
|
||||||
QByteArray url;
|
QByteArray url;
|
||||||
switch (stream->type()) {
|
switch ( stream->type() )
|
||||||
|
{
|
||||||
case MediaStream::Unknown:
|
case MediaStream::Unknown:
|
||||||
tDebug() << "MediaStream Type is Invalid:" << stream->type();
|
tDebug() << Q_FUNC_INFO << "MediaStream Type is Invalid:" << stream->type();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MediaStream::Empty:
|
case MediaStream::Empty:
|
||||||
tDebug() << "MediaStream is empty.";
|
tDebug() << Q_FUNC_INFO << "MediaStream is empty.";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MediaStream::Url:
|
case MediaStream::Url:
|
||||||
tDebug() << "MediaStream::Url:" << stream->url();
|
tDebug() << Q_FUNC_INFO << "MediaStream::Url:" << stream->url();
|
||||||
if ( stream->url().scheme().isEmpty() ) {
|
if ( stream->url().scheme().isEmpty() ) {
|
||||||
url = "file:///";
|
url = "file:///";
|
||||||
if ( stream->url().isRelative() ) {
|
if ( stream->url().isRelative() ) {
|
||||||
@@ -238,17 +244,16 @@ AudioOutput::setCurrentSource( MediaStream* stream )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tDebug() << "MediaStream::Final Url:" << url;
|
tDebug() << Q_FUNC_INFO << "MediaStream::Final Url:" << url;
|
||||||
|
|
||||||
|
|
||||||
m_vlcMedia = libvlc_media_new_location( m_vlcInstance, url.constData() );
|
m_vlcMedia = libvlc_media_new_location( m_vlcInstance, url.constData() );
|
||||||
|
|
||||||
libvlc_event_manager_t* manager = libvlc_media_event_manager( m_vlcMedia );
|
libvlc_event_manager_t* manager = libvlc_media_event_manager( m_vlcMedia );
|
||||||
libvlc_event_type_t events[] = {
|
libvlc_event_type_t events[] = {
|
||||||
libvlc_MediaDurationChanged,
|
libvlc_MediaDurationChanged,
|
||||||
};
|
};
|
||||||
const int eventCount = sizeof(events) / sizeof( *events );
|
const int eventCount = sizeof(events) / sizeof( *events );
|
||||||
for ( int i = 0 ; i < eventCount ; i++ ) {
|
for ( int i = 0; i < eventCount; i++ )
|
||||||
|
{
|
||||||
libvlc_event_attach( manager, events[ i ], &AudioOutput::vlcEventCallback, this );
|
libvlc_event_attach( manager, events[ i ], &AudioOutput::vlcEventCallback, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +310,8 @@ AudioOutput::setCurrentTime( qint64 time )
|
|||||||
{
|
{
|
||||||
// FIXME : This is a bit hacky, but m_totalTime is only used to determine
|
// FIXME : This is a bit hacky, but m_totalTime is only used to determine
|
||||||
// if we are about to finish
|
// if we are about to finish
|
||||||
if ( m_totalTime == 0 ) {
|
if ( m_totalTime == 0 )
|
||||||
|
{
|
||||||
m_totalTime = AudioEngine::instance()->currentTrackTotalTime();
|
m_totalTime = AudioEngine::instance()->currentTrackTotalTime();
|
||||||
m_seekable = true;
|
m_seekable = true;
|
||||||
}
|
}
|
||||||
@@ -313,19 +319,22 @@ AudioOutput::setCurrentTime( qint64 time )
|
|||||||
m_currentTime = time;
|
m_currentTime = time;
|
||||||
emit tick( time );
|
emit tick( time );
|
||||||
|
|
||||||
// tDebug() << "Current time : " << m_currentTime << " / " << m_totalTime;
|
// tDebug() << Q_FUNC_INFO << "Current time : " << m_currentTime << " / " << m_totalTime;
|
||||||
|
|
||||||
// FIXME pt 2 : we use temporary variable to avoid overriding m_totalTime
|
// FIXME pt 2 : we use temporary variable to avoid overriding m_totalTime
|
||||||
// in the case it is < 0 (which means that the media is not seekable)
|
// in the case it is < 0 (which means that the media is not seekable)
|
||||||
qint64 total = m_totalTime;
|
qint64 total = m_totalTime;
|
||||||
if ( total <= 0 ) {
|
if ( total <= 0 )
|
||||||
|
{
|
||||||
total = AudioEngine::instance()->currentTrackTotalTime();
|
total = AudioEngine::instance()->currentTrackTotalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( time < total - ABOUT_TO_FINISH_TIME ) {
|
if ( time < total - ABOUT_TO_FINISH_TIME )
|
||||||
|
{
|
||||||
m_aboutToFinish = false;
|
m_aboutToFinish = false;
|
||||||
}
|
}
|
||||||
if ( !m_aboutToFinish && total > 0 && time >= total - ABOUT_TO_FINISH_TIME ) {
|
if ( !m_aboutToFinish && total > 0 && time >= total - ABOUT_TO_FINISH_TIME )
|
||||||
|
{
|
||||||
m_aboutToFinish = true;
|
m_aboutToFinish = true;
|
||||||
emit aboutToFinish();
|
emit aboutToFinish();
|
||||||
}
|
}
|
||||||
@@ -342,11 +351,13 @@ AudioOutput::totalTime() const
|
|||||||
void
|
void
|
||||||
AudioOutput::setTotalTime( qint64 time )
|
AudioOutput::setTotalTime( qint64 time )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << " " << time;
|
tDebug() << Q_FUNC_INFO << time;
|
||||||
|
|
||||||
if ( time <= 0 ) {
|
if ( time <= 0 )
|
||||||
|
{
|
||||||
m_seekable = false;
|
m_seekable = false;
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
m_totalTime = time;
|
m_totalTime = time;
|
||||||
m_seekable = true;
|
m_seekable = true;
|
||||||
// emit current time to refresh total time
|
// emit current time to refresh total time
|
||||||
@@ -360,9 +371,12 @@ AudioOutput::play()
|
|||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( libvlc_media_player_is_playing ( m_vlcPlayer ) ) {
|
if ( libvlc_media_player_is_playing( m_vlcPlayer ) )
|
||||||
|
{
|
||||||
libvlc_media_player_set_pause( m_vlcPlayer, 0 );
|
libvlc_media_player_set_pause( m_vlcPlayer, 0 );
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
libvlc_media_player_play( m_vlcPlayer );
|
libvlc_media_player_play( m_vlcPlayer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +390,6 @@ AudioOutput::pause()
|
|||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
libvlc_media_player_set_pause( m_vlcPlayer, 1 );
|
libvlc_media_player_set_pause( m_vlcPlayer, 1 );
|
||||||
|
|
||||||
setState( Paused );
|
setState( Paused );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,8 +398,8 @@ void
|
|||||||
AudioOutput::stop()
|
AudioOutput::stop()
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
libvlc_media_player_stop ( m_vlcPlayer );
|
|
||||||
|
|
||||||
|
libvlc_media_player_stop( m_vlcPlayer );
|
||||||
setState( Stopped );
|
setState( Stopped );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +415,8 @@ AudioOutput::seek( qint64 milliseconds )
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
switch ( m_currentState ) {
|
switch ( m_currentState )
|
||||||
|
{
|
||||||
case Playing:
|
case Playing:
|
||||||
case Paused:
|
case Paused:
|
||||||
case Loading:
|
case Loading:
|
||||||
@@ -412,7 +426,7 @@ AudioOutput::seek( qint64 milliseconds )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tDebug() << "AudioOutput:: seeking" << milliseconds << "msec";
|
// tDebug() << Q_FUNC_INFO << "AudioOutput:: seeking" << milliseconds << "msec";
|
||||||
|
|
||||||
m_justSeeked = true;
|
m_justSeeked = true;
|
||||||
libvlc_media_player_set_time( m_vlcPlayer, milliseconds );
|
libvlc_media_player_set_time( m_vlcPlayer, milliseconds );
|
||||||
@@ -440,9 +454,12 @@ AudioOutput::setMuted(bool m)
|
|||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_muted = m;
|
m_muted = m;
|
||||||
if ( m_muted == true ) {
|
if ( m_muted )
|
||||||
|
{
|
||||||
libvlc_audio_set_volume( m_vlcPlayer, 0 );
|
libvlc_audio_set_volume( m_vlcPlayer, 0 );
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
libvlc_audio_set_volume( m_vlcPlayer, m_volume * 100.0 );
|
libvlc_audio_set_volume( m_vlcPlayer, m_volume * 100.0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,7 +478,8 @@ AudioOutput::setVolume(qreal vol)
|
|||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_volume = vol;
|
m_volume = vol;
|
||||||
if ( !m_muted ) {
|
if ( !m_muted )
|
||||||
|
{
|
||||||
libvlc_audio_set_volume( m_vlcPlayer, m_volume * 100.0 );
|
libvlc_audio_set_volume( m_vlcPlayer, m_volume * 100.0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,7 +488,8 @@ AudioOutput::setVolume(qreal vol)
|
|||||||
void
|
void
|
||||||
AudioOutput::onVlcEvent( const libvlc_event_t* event )
|
AudioOutput::onVlcEvent( const libvlc_event_t* event )
|
||||||
{
|
{
|
||||||
switch ( event->type ) {
|
switch ( event->type )
|
||||||
|
{
|
||||||
case libvlc_MediaPlayerTimeChanged:
|
case libvlc_MediaPlayerTimeChanged:
|
||||||
setCurrentTime( event->u.media_player_time_changed.new_time );
|
setCurrentTime( event->u.media_player_time_changed.new_time );
|
||||||
break;
|
break;
|
||||||
@@ -494,8 +513,9 @@ AudioOutput::onVlcEvent( const libvlc_event_t* event )
|
|||||||
setState( Stopped );
|
setState( Stopped );
|
||||||
break;
|
break;
|
||||||
case libvlc_MediaPlayerEncounteredError:
|
case libvlc_MediaPlayerEncounteredError:
|
||||||
tDebug() << "LibVLC error : MediaPlayerEncounteredError. Stopping";
|
tDebug() << Q_FUNC_INFO << "LibVLC error : MediaPlayerEncounteredError. Stopping";
|
||||||
if ( m_vlcPlayer != nullptr ) {
|
if ( m_vlcPlayer != nullptr )
|
||||||
|
{
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
setState( Error );
|
setState( Error );
|
||||||
@@ -533,7 +553,8 @@ AudioOutput::s_dspCallback( int frameNumber, float* samples, int nb_channels, in
|
|||||||
|
|
||||||
int state = AudioOutput::instance()->m_justSeeked ? 1 : 0;
|
int state = AudioOutput::instance()->m_justSeeked ? 1 : 0;
|
||||||
AudioOutput::instance()->m_justSeeked = false;
|
AudioOutput::instance()->m_justSeeked = false;
|
||||||
if ( AudioOutput::instance()->dspPluginCallback ) {
|
if ( AudioOutput::instance()->dspPluginCallback )
|
||||||
|
{
|
||||||
AudioOutput::instance()->dspPluginCallback( state, frameNumber, samples, nb_channels, nb_samples );
|
AudioOutput::instance()->dspPluginCallback( state, frameNumber, samples, nb_channels, nb_samples );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user