1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-17 22:38:33 +01:00

clean code, use boost::function for callbacks

This commit is contained in:
dridri 2014-10-18 20:02:27 +02:00 committed by Uwe L. Korn
parent eb1ef86452
commit ead0ecc808
13 changed files with 185 additions and 184 deletions

View File

@ -10,7 +10,7 @@
# LIBVLC_VERSION
if(NOT LIBVLC_MIN_VERSION)
set(LIBVLC_MIN_VERSION "0.0")
set(LIBVLC_MIN_VERSION "2.1")
endif(NOT LIBVLC_MIN_VERSION)
# find_path and find_library normally search standard locations
@ -43,6 +43,15 @@ PATHS
find_path(LIBVLC_INCLUDE_DIR PATHS "${CMAKE_INCLUDE_PATH}/vlc" NAMES vlc.h
HINTS ${PC_LIBVLC_INCLUDEDIR} ${PC_LIBVLC_INCLUDE_DIRS})
find_path(LIBVLCCORE_INCLUDE_DIR vlc_plugin.h
PATHS
"$ENV{LIB_DIR}/include/vlc/plugins"
"/usr/include/vlc/plugins"
"/usr/local/include/vlc/plugins"
#mingw
c:/msys/local/include/vlc/plugins
)
#Put here path to custom location
#example: /home/user/vlc/lib etc..
find_library(LIBVLC_LIBRARY NAMES vlc libvlc

View File

@ -215,7 +215,7 @@ list(APPEND libSources
audio/AudioEngine.cpp
audio/AudioOutput.cpp
audio/VlcDspHack.cpp
audio/VlcDsp.cpp
collection/Collection.cpp
collection/ArtistsRequest.cpp
@ -393,7 +393,8 @@ include_directories(
${ECHONEST_INCLUDE_DIR}
${LUCENEPP_INCLUDE_DIRS}
${PHONON_INCLUDES}
${LIBVLC_INCLUDES}
${LIBVLC_INCLUDE_DIR}
${LIBVLCCORE_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${LIBPORTFWD_INCLUDE_DIR}

View File

@ -76,7 +76,7 @@ AudioEnginePrivate::onStateChanged( AudioOutput::AudioState newState, AudioOutpu
{
q_ptr->stop( AudioEngine::UnknownError );
//TODO tDebug() << "Phonon Error:" << audioOutput->errorString() << audioOutput->errorType();
//TODO tDebug() << "AudioOutput Error:" << audioOutput->errorString() << audioOutput->errorType();
emit q_ptr->error( AudioEngine::UnknownError );
q_ptr->setState( AudioEngine::Error );
@ -97,7 +97,6 @@ AudioEnginePrivate::onStateChanged( AudioOutput::AudioState newState, AudioOutpu
}
if ( newState == AudioOutput::Stopped && oldState == AudioOutput::Paused )
{
// GStreamer backend hack: instead of going from PlayingState to StoppedState, it traverses PausedState
q_ptr->setState( AudioEngine::Stopped );
}
@ -508,7 +507,6 @@ bool
AudioEngine::isMuted() const
{
return d_func()->audioOutput->isMuted();
return 0;
}
@ -1248,8 +1246,8 @@ AudioEngine::currentTrackTotalTime() const
{
// TODO : This is too hacky. The problem is that I don't know why
// libVLC doesn't report total duration for stream data (imem://)
// But it's not a real problem for playback, since
// EndOfStream is emitted by libVLC itself
// But it's not a real problem for playback, since EndOfStream is emitted by libVLC itself
// This value is only used by AudioOutput to evaluate if it's close to end of stream
if ( d_func()->audioOutput->totalTime() <= 0 && d_func()->currentTrack && d_func()->currentTrack->track() ) {
return d_func()->currentTrack->track()->duration() * 1000 + 1000;
}
@ -1341,7 +1339,7 @@ AudioEngine::setCurrentTrackPlaylist( const playlistinterface_ptr& playlist )
void
AudioEngine::setDspCallback( void ( *cb ) ( float*, int, int ) )
AudioEngine::setDspCallback( boost::function< void( int state, int frameNumber, float* samples, int nb_channels, int nb_samples ) > cb )
{
Q_D( AudioEngine );

View File

@ -24,6 +24,7 @@
#include "../Typedefs.h"
#include <QStringList>
#include <boost/function.hpp>
#include "DllMacro.h"
@ -109,7 +110,7 @@ public:
*/
qint64 currentTrackTotalTime() const;
void setDspCallback( void ( *cb ) ( float* samples, int nb_channels, int nb_samples ) );
void setDspCallback( boost::function< void( int state, int frameNumber, float* samples, int nb_channels, int nb_samples ) > cb );
public slots:
void playPause();

View File

@ -59,7 +59,5 @@ private:
QTemporaryFile* coverTempFile;
void (* dspPluginCallback )( signed short* samples, int nb_channels, int nb_samples );
static AudioEngine* s_instance;
};

View File

@ -2,7 +2,7 @@
*
* Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2014, Adrien Aubry <dridri85@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
#include "AudioEngine.h"
#include "AudioOutput.h"
#include "VlcDspHack.h"
#include "VlcDsp.h"
#include "utils/Logger.h"
@ -61,6 +61,7 @@ AudioOutput::AudioOutput( QObject* parent )
, m_currentTime( 0 )
, m_totalTime( 0 )
, m_aboutToFinish( false )
, m_justSeeked( false )
, dspPluginCallback( 0 )
, vlcInstance( 0 )
, vlcPlayer( 0 )
@ -177,6 +178,7 @@ AudioOutput::setCurrentSource(MediaStream* stream)
currentStream = stream;
m_totalTime = 0;
m_currentTime = 0;
m_justSeeked = false;
seekable = true;
QByteArray url;
@ -223,8 +225,7 @@ AudioOutput::setCurrentSource(MediaStream* stream)
libvlc_media_player_set_media( vlcPlayer, vlcMedia );
#ifdef VLC_DSP_PLUGIN_ENABLED
// This is very, very tricky
VlcDspHackInstall( vlcPlayer );
VlcDspSetup( vlcPlayer );
#endif
if ( stream->type() == MediaStream::Url ) {
@ -378,8 +379,9 @@ AudioOutput::seek( qint64 milliseconds )
return;
}
tDebug() << "AudioOutput:: seeking" << milliseconds << "msec";
// tDebug() << "AudioOutput:: seeking" << milliseconds << "msec";
m_justSeeked = true;
libvlc_media_player_set_time ( vlcPlayer, milliseconds );
setCurrentTime( milliseconds );
}
@ -487,18 +489,20 @@ AudioOutput::vlcEventCallback( const libvlc_event_t* event, void* opaque )
void
AudioOutput::s_dspCallback( float* samples, int nb_channels, int nb_samples )
AudioOutput::s_dspCallback( int frameNumber, float* samples, int nb_channels, int nb_samples )
{
// tDebug() << Q_FUNC_INFO;
int state = AudioOutput::instance()->m_justSeeked ? 1 : 0;
AudioOutput::instance()->m_justSeeked = false;
if ( AudioOutput::instance()->dspPluginCallback ) {
AudioOutput::instance()->dspPluginCallback( samples, nb_channels, nb_samples );
AudioOutput::instance()->dspPluginCallback( state, frameNumber, samples, nb_channels, nb_samples );
}
}
void
AudioOutput::setDspCallback( void ( *cb ) ( float*, int, int ) )
AudioOutput::setDspCallback( boost::function< void( int, int, float*, int, int ) > cb )
{
dspPluginCallback = cb;
}

View File

@ -2,7 +2,7 @@
*
* Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2014, Adrien Aubry <dridri85@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,9 +24,10 @@
#include "../Typedefs.h"
#include "DllMacro.h"
#include "utils/MediaStream.h"
#include <boost/function.hpp>
struct libvlc_instance_t;
struct libvlc_media_player_t;
struct libvlc_media_t;
@ -61,7 +62,7 @@ public:
qint64 totalTime();
void setAutoDelete ( bool ad );
void setDspCallback( void ( *cb ) ( float*, int, int ) );
void setDspCallback( boost::function< void( int, int, float*, int, int ) > cb );
static AudioOutput* instance();
@ -78,7 +79,7 @@ private:
void setTotalTime( qint64 time );
static void vlcEventCallback( const libvlc_event_t *event, void *opaque );
static void s_dspCallback( float* samples, int nb_channels, int nb_samples );
static void s_dspCallback( int frameNumber, float* samples, int nb_channels, int nb_samples );
static AudioOutput* s_instance;
AudioState currentState;
@ -90,8 +91,9 @@ private:
qint64 m_currentTime;
qint64 m_totalTime;
bool m_aboutToFinish;
bool m_justSeeked;
void ( *dspPluginCallback ) ( float* samples, int nb_channels, int nb_samples );
boost::function< void( int state, int frameNumber, float* samples, int nb_channels, int nb_samples ) > dspPluginCallback;
libvlc_instance_t* vlcInstance;
libvlc_media_player_t* vlcPlayer;

View File

@ -0,0 +1,38 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "VlcDsp_p.h"
#ifdef VLC_DSP_PLUGIN_ENABLED
void
VlcDspSetup( libvlc_media_player_t* vlcPlayer )
{
vlc_value_t val;
if ( vlcPlayer->input.p_resource != 0 ) {
audio_output_t *aout = input_resource_GetAout( vlcPlayer->input.p_resource );
if ( aout != 0 ) {
var_Create( ( vlc_object_t* )aout, "audio-filter", VLC_VAR_STRING );
val.psz_string = (char*)"dsp";
var_SetChecked( ( vlc_object_t* )aout, "audio-filter", VLC_VAR_STRING, val );
aout->event.restart_request( aout, AOUT_RESTART_FILTERS );
input_resource_PutAout( vlcPlayer->input.p_resource, aout );
}
}
}
#endif // VLC_DSP_PLUGIN_ENABLED

View File

@ -0,0 +1,47 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VLCDSP_H
#define VLCDSP_H
/*
* Very tricky technique to enable DSP plugin support
* There is no other way to do this with libvlc for the moment
*
* A VLC audio filter plugin specificaly made for Tomahawk
* is necessary to get it functionning
*
* TODO : Check thoroughly if libvlc_media_player_t
* structure is identical to the one in running libvlccore.so
* (checking if libVLC version is >= than the one used to compile Tomahawk
* and verifying pointers integrity should be enough.
* + check if audio filter "dsp" is present in libVLC plugins list)
*
* The define 'VLC_DSP_PLUGIN_ENABLED' better should be a CMake option
*/
// Maybe later :)
//#define VLC_DSP_PLUGIN_ENABLED
#ifdef VLC_DSP_PLUGIN_ENABLED
struct libvlc_media_player_t;
void VlcDspSetup( libvlc_media_player_t* vlcPlayer );
#endif // VLC_DSP_PLUGIN_ENABLED
#endif // VLCDSP_H

View File

@ -1,24 +0,0 @@
#include "VlcDspHack_p.h"
#ifdef VLC_DSP_PLUGIN_ENABLED
void
VlcDspHackInstall( libvlc_media_player_t* vlcPlayer )
{
if ( vlcPlayer->input.p_resource != 0 ) {
audio_output_t *aout = input_resource_GetAout( vlcPlayer->input.p_resource );
if ( aout != 0 ) {
var_Create( (vlc_object_t*)aout, "audio-filter", 0x0040 /*VLC_VAR_STRING*/ );
vlc_value_t val;
val.psz_string = (char*)"dsp";
var_SetChecked( (vlc_object_t*)aout, "audio-filter", 0x0040 /*VLC_VAR_STRING*/, val );
aout->event.restart_request( aout, 1 /*AOUT_RESTART_FILTERS*/ );
input_resource_PutAout( vlcPlayer->input.p_resource, aout );
}
}
}
#endif // VLC_DSP_PLUGIN_ENABLED

View File

@ -1,28 +0,0 @@
#ifndef VLCDSPHACK_H
#define VLCDSPHACK_H
/*
* Very tricky technique to enable DSP plugin support
* There is no other way to do this with libvlc for the moment
*
* A VLC audio filter plugin specificaly made for Tomahawk
* is necessary to get it functionning
*
* TODO : Check thoroughly if both libvlc_media_player_t and audio_output
* structures are identical to those in the running libvlccore.so
* (checking if libVLC version is >= than the one used to compile Tomahawk
* and verifying pointers integrity should be enough.
* + check if audio filter "dsp" is present in libVLC plugins list)
*/
//#define VLC_DSP_PLUGIN_ENABLED
#ifdef VLC_DSP_PLUGIN_ENABLED
struct libvlc_media_player_t;
void VlcDspHackInstall( libvlc_media_player_t* vlcPlayer );
#endif // VLC_DSP_PLUGIN_ENABLED
#endif // VLCDSPHACK_H

View File

@ -1,107 +0,0 @@
#ifndef VLCDSPHACK_P_H
#define VLCDSPHACK_P_H
#include "VlcDspHack.h"
#ifdef VLC_DSP_PLUGIN_ENABLED
#include <pthread.h>
#include <vlc/libvlc.h>
#include <vlc/libvlc_media.h>
#include <vlc/libvlc_media_player.h>
#include <vlc/libvlc_events.h>
#include <vlc/libvlc_version.h>
// TODO : Replace all these copy-pasted strutures by vlc/plugins/?.h includes
typedef struct audio_output audio_output_t;
typedef struct input_resource_t input_resource_t;
typedef struct vlc_object_t vlc_object_t;
typedef struct vlc_list_t vlc_list_t;
typedef int64_t mtime_t;
typedef pthread_mutex_t vlc_mutex_t;
typedef union
{
int64_t i_int;
bool b_bool;
float f_float;
char * psz_string;
void * p_address;
vlc_object_t * p_object;
vlc_list_t * p_list;
mtime_t i_time;
struct { int32_t x; int32_t y; } coords;
} vlc_value_t;
struct audio_output
{
const char *psz_object_type;
char *psz_header;
int i_flags;
bool b_force;
void *p_libvlc;
void * p_parent;
void *sys;
int (*start)(audio_output_t *, void *fmt);
void (*stop)(audio_output_t *);
int (*time_get)(audio_output_t *, void *delay);
void (*play)(audio_output_t *, void *);
void (*pause)( audio_output_t *, bool pause, mtime_t date);
void (*flush)( audio_output_t *, bool wait);
int (*volume_set)(audio_output_t *, float volume);
int (*mute_set)(audio_output_t *, bool mute);
int (*device_select)(audio_output_t *, const char *id);
struct {
void (*volume_report)(audio_output_t *, float);
void (*mute_report)(audio_output_t *, bool);
void (*policy_report)(audio_output_t *, bool);
void (*device_report)(audio_output_t *, const char *);
void (*hotplug_report)(audio_output_t *, const char *, const char *);
int (*gain_request)(audio_output_t *, float);
void (*restart_request)(audio_output_t *, unsigned);
} event;
};
struct libvlc_media_player_t
{
const char *psz_object_type;
char *psz_header;
int i_flags;
bool b_force;
void *p_libvlc;
void *p_parent;
int i_refcount;
vlc_mutex_t object_lock;
struct
{
void *p_thread;
input_resource_t *p_resource;
vlc_mutex_t lock;
} input;
void *p_libvlc_instance;
void *p_md;
void *p_event_manager;
int state;
};
extern "C" {
audio_output_t* input_resource_GetAout(input_resource_t*);
void input_resource_PutAout(input_resource_t*, audio_output_t*);
int var_Create(vlc_object_t *, const char *, int );
int var_SetChecked( vlc_object_t *, const char *, int, vlc_value_t );
static inline void aout_RestartRequest(audio_output_t *aout, unsigned mode){
aout->event.restart_request(aout, mode);
}
};
#endif // VLC_DSP_PLUGIN_ENABLED
#endif // VLCDSPHACK_P_H

View File

@ -0,0 +1,62 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VLCDSP_P_H
#define VLCDSP_P_H
#include "VlcDsp.h"
#ifdef VLC_DSP_PLUGIN_ENABLED
#include <pthread.h>
#include <vlc/libvlc.h>
#include <vlc/libvlc_media.h>
#include <vlc/libvlc_media_player.h>
#include <vlc/libvlc_events.h>
#include <vlc/libvlc_version.h>
#define restrict
#define _(s) s
#include <vlc/plugins/vlc_aout.h>
#include <vlc/plugins/vlc_input.h>
typedef struct libvlc_media_player_t
{
const char *psz_object_type;
char *psz_header;
int i_flags;
bool b_force;
void *p_libvlc;
void *p_parent;
int i_refcount;
vlc_mutex_t object_lock;
struct
{
void *p_thread;
input_resource_t *p_resource;
vlc_mutex_t lock;
} input;
void *p_libvlc_instance;
void *p_md;
void *p_event_manager;
int state;
} libvlc_media_player_t;
#endif // VLC_DSP_PLUGIN_ENABLED
#endif // VLCDSP_P_H