Scope support for the VLC engine

This commit is contained in:
David Sansome 2010-04-05 02:21:53 +00:00
parent b77a64a2f1
commit c7f58b9618
5 changed files with 157 additions and 1 deletions

View File

@ -37,6 +37,7 @@ if(WIN32)
else(WIN32)
pkg_check_modules(TAGLIB taglib)
pkg_check_modules(LIBVLC libvlc)
pkg_check_modules(VLC_PLUGIN vlc-plugin)
if (TAGLIB_VERSION VERSION_LESS 1.6)
message(FATAL_ERROR "Taglib version 1.6 or greater is required")
@ -69,6 +70,7 @@ include(${QT_USE_FILE})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${TAGLIB_INCLUDE_DIRS})
include_directories(${LIBVLC_INCLUDE_DIRS})
include_directories(${VLC_PLUGIN_INCLUDE_DIRS})
include_directories(${LASTFM_INCLUDE_DIRS})
include_directories("3rdparty/qsqlite")
@ -88,6 +90,7 @@ add_definitions(-DQXT_STATIC -DBUILD_QXT_GUI -DBUILD_QXT_CORE)
# Subdirectories
add_subdirectory(3rdparty/qtsingleapplication)
add_subdirectory(3rdparty/qxt)
add_subdirectory(vlcplugins)
add_subdirectory(src)
add_subdirectory(tests)
@ -97,6 +100,14 @@ if (WIN32)
add_subdirectory(3rdparty/qsqlite)
endif(WIN32)
# Install libraries to the right place
set (LIBRARY_INSTALL_DIR lib)
if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set (LIBRARY_INSTALL_DIR lib32)
elif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set (LIBRARY_INSTALL_DIR lib64)
endif ()
# Uninstall support
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"

View File

@ -19,12 +19,17 @@
#include <QTimer>
#include <QtDebug>
#include <QMutexLocker>
#include <QTime>
#include <boost/bind.hpp>
VlcEngine* VlcEngine::sInstance = NULL;
VlcEngine::VlcEngine()
: instance_(NULL),
player_(NULL),
scope_data_(4096),
state_(Engine::Empty)
{
static const char * const args[] = {
@ -32,7 +37,10 @@ VlcEngine::VlcEngine()
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // log anything
"--verbose=2", // be much more verbose then normal for debugging purpose
//"--plugin-path=C:\\vlc-0.9.9-win32\\plugins\\"
// Our scope plugin
"--audio-filter=clementine_scope",
"--no-plugins-cache",
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
"--aout=alsa", // The default, pulseaudio, is buggy
@ -62,6 +70,8 @@ VlcEngine::VlcEngine()
AttachCallback(player_em, libvlc_MediaPlayerStopped, StateChangedCallback);
AttachCallback(player_em, libvlc_MediaPlayerEndReached, StateChangedCallback);
HandleErrors();
sInstance = this;
}
VlcEngine::~VlcEngine() {
@ -204,3 +214,33 @@ void VlcEngine::HandleErrors() const {
qFatal("libvlc error: %s", libvlc_exception_get_message(&exception_));
}
}
void VlcEngine::SetScopeData(float* data, int size) {
if (!sInstance)
return;
QMutexLocker l(&sInstance->scope_mutex_);
// This gets called by our VLC plugin. Just push the data on to the end of
// the circular buffer and let it get consumed by scope()
for (int i=0 ; i<size ; ++i) {
sInstance->scope_data_.push_back(data[i]);
}
}
const Engine::Scope& VlcEngine::scope() {
QMutexLocker l(&scope_mutex_);
// Leave the scope unchanged if there's not enough data
if (scope_data_.size() < SCOPESIZE)
return m_scope;
// Take the samples off the front of the circular buffer
for (uint i=0 ; i<SCOPESIZE ; ++i)
m_scope[i] = scope_data_[i] * (1 << 15);
// Remove the samples from the buffer. Unfortunately I think this is O(n) :(
scope_data_.rresize(qMax(0, int(scope_data_.size()) - SCOPESIZE*2));
return m_scope;
}

View File

@ -20,6 +20,9 @@
#include "enginebase.h"
#include <vlc/vlc.h>
#include <boost/circular_buffer.hpp>
#include <QMutex>
class QTimer;
@ -46,6 +49,9 @@ class VlcEngine : public Engine::Base {
void seek( uint ms );
static void SetScopeData(float* data, int size);
const Engine::Scope& scope();
protected:
void setVolumeSW( uint percent );
@ -56,10 +62,15 @@ class VlcEngine : public Engine::Base {
static void StateChangedCallback(const libvlc_event_t* e, void* data);
private:
static VlcEngine* sInstance;
libvlc_exception_t exception_;
libvlc_instance_t* instance_;
libvlc_media_player_t* player_;
QMutex scope_mutex_;
boost::circular_buffer<float> scope_data_;
Engine::State state_;
};

24
vlcplugins/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 2.6)
set(CMAKE_C_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS "-Wnon-virtual-dtor -Woverloaded-virtual -Wall")
# Source files
set(CLEMENTINE-SCOPE-SOURCES
clementinescope.cpp
)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../src")
add_library(clementine_scope SHARED
${CLEMENTINE-SCOPE-SOURCES}
)
target_link_libraries(clementine_scope
${VLC_PLUGIN_LIBRARIES}
${QT_LIBRARIES}
)
install(TARGETS clementine_scope
LIBRARY DESTINATION ${VLC_PLUGIN_LIBDIR}/vlc/clementine
)

View File

@ -0,0 +1,70 @@
/* This file is part of Clementine.
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#define __PLUGIN__
#define MODULE_STRING "clementine_scope"
#define MODULE_NAME clementine_scope
#include "engines/vlcengine.h"
#include <vlc/vlc.h>
#include <vlc/plugins/vlc_common.h>
#include <vlc/plugins/vlc_plugin.h>
#include <vlc/plugins/vlc_aout.h>
#include <QtGlobal>
// Forward declarations
static int Open ( vlc_object_t * );
static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf );
// Module definition
vlc_module_begin ()
set_description("Internal plugin for Clementine's analyzer")
set_shortname("clementine_scope")
set_category( CAT_AUDIO )
set_subcategory( SUBCAT_AUDIO_VISUAL )
set_capability( "audio filter", 0 )
set_callbacks( Open, 0 )
add_shortcut( "clementine_scope")
vlc_module_end ()
// Called once for every track
static int Open( vlc_object_t *p_this ) {
aout_filter_t *p_filter = (aout_filter_t *)p_this;
if( ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2') &&
p_filter->input.i_format != VLC_FOURCC('f','i','3','2') ) ) {
return VLC_EGENERIC;
}
p_filter->pf_do_work = DoWork;
p_filter->b_in_place= 1;
return VLC_SUCCESS;
}
// Called continuously while a track is playing
static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf ) {
Q_UNUSED(p_aout);
Q_UNUSED(p_out_buf);
VlcEngine::SetScopeData(
reinterpret_cast<float*>(p_in_buf->p_buffer),
p_in_buf->i_nb_samples * aout_FormatNbChannels(&p_filter->input));
}