[vlc-devel] [PATCH 1/3] Qt: Add libVLC abtraction layer classes
Francois Cartegnie
fcvlcdev at free.fr
Wed Mar 3 21:51:10 CET 2010
---
modules/gui/qt4/Modules.am | 6 ++
modules/gui/qt4/adapters/audiothreadadapter.cpp | 85 +++++++++++++++++++++++
modules/gui/qt4/adapters/audiothreadadapter.hpp | 63 +++++++++++++++++
modules/gui/qt4/adapters/prefsadapter.cpp | 44 ++++++++++++
modules/gui/qt4/adapters/prefsadapter.hpp | 48 +++++++++++++
modules/gui/qt4/qt4.cpp | 5 ++
6 files changed, 251 insertions(+), 0 deletions(-)
create mode 100644 modules/gui/qt4/adapters/audiothreadadapter.cpp
create mode 100644 modules/gui/qt4/adapters/audiothreadadapter.hpp
create mode 100644 modules/gui/qt4/adapters/prefsadapter.cpp
create mode 100644 modules/gui/qt4/adapters/prefsadapter.hpp
diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am
index d2c032e..639871a 100644
--- a/modules/gui/qt4/Modules.am
+++ b/modules/gui/qt4/Modules.am
@@ -23,6 +23,8 @@ nodist_SOURCES_qt4 = \
extensions_manager.moc.cpp \
recents.moc.cpp \
variables.moc.cpp \
+ adapters/audiothreadadapter.moc.cpp \
+ adapters/prefsadapter.moc.cpp \
dialogs/playlist.moc.cpp \
dialogs/bookmarks.moc.cpp \
dialogs/mediainfo.moc.cpp \
@@ -221,6 +223,8 @@ SOURCES_qt4 = qt4.cpp \
extensions_manager.cpp \
recents.cpp \
variables.cpp \
+ adapters/audiothreadadapter.cpp \
+ adapters/prefsadapter.cpp \
dialogs/playlist.cpp \
dialogs/bookmarks.cpp \
dialogs/preferences.cpp \
@@ -277,6 +281,8 @@ noinst_HEADERS = \
extensions_manager.hpp \
recents.hpp \
variables.hpp \
+ adapters/audiothreadadapter.hpp \
+ adapters/prefsadapter.hpp \
dialogs/playlist.hpp \
dialogs/bookmarks.hpp \
dialogs/mediainfo.hpp \
diff --git a/modules/gui/qt4/adapters/audiothreadadapter.cpp b/modules/gui/qt4/adapters/audiothreadadapter.cpp
new file mode 100644
index 0000000..fb86434
--- /dev/null
+++ b/modules/gui/qt4/adapters/audiothreadadapter.cpp
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * audiothreadadapter.cpp : LibVLC audio abstraction class
+ ****************************************************************************
+ * Copyright (C) 2006-2010 the VideoLAN team
+ *
+ * Authors: Francois Cartegnie <fcvlcdev at free.fr>
+ *
+ * This program 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 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "audiothreadadapter.hpp"
+ /* required for MIM/InputManager. Maybe we could plug directly lib's events ?*/
+#include "input_manager.hpp"
+
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QDebug>
+
+/**********************************************************************
+ * AudioThreadAdapter implementation
+ **********************************************************************/
+
+AudioThreadAdapter::AudioThreadAdapter( intf_thread_t * _p_intf )
+ : QObject(), p_intf( _p_intf )
+{
+ Q_CHECK_PTR( p_intf );
+ CONNECT( THEMIM, volumeChanged( ), this, onLibUpdateVolumeHandler( ) );
+ CONNECT( THEMIM, soundMuteChanged( ), this, onLibUpdateMuteStatusHandler( ) );
+}
+
+void AudioThreadAdapter::setLibVolume( int i_volume )
+{
+ playlist_t *p_playlist = pl_Get( p_intf );
+ int i_res = ( (float) i_volume / 100 ) * LIB_VOLUME_CPC;
+ aout_VolumeSet( p_playlist, i_res );
+}
+
+int AudioThreadAdapter::getLibVolume( )
+{
+ audio_volume_t i_volume;
+ playlist_t *p_playlist = pl_Get( p_intf );
+ aout_VolumeGet( p_playlist, &i_volume );
+ i_volume = (float) i_volume / LIB_VOLUME_CPC * 100.0;
+ return i_volume;
+}
+
+void AudioThreadAdapter::setLibMuteState( bool b_mute )
+{
+ playlist_t *p_playlist = pl_Get( p_intf );
+ aout_SetMute( VLC_OBJECT(p_playlist), NULL, b_mute );
+}
+
+bool AudioThreadAdapter::getLibMuteState( )
+{
+ bool b_is_muted;
+ playlist_t *p_playlist = pl_Get( p_intf );
+ b_is_muted = aout_IsMuted( VLC_OBJECT(p_playlist) );
+ return b_is_muted;
+}
+
+void AudioThreadAdapter::onLibUpdateVolumeHandler( )
+{
+ emit libUpdatedVolume( getLibVolume() );
+}
+
+void AudioThreadAdapter::onLibUpdateMuteStatusHandler( )
+{
+ emit libUpdatedMuteStatus( getLibMuteState() );
+}
diff --git a/modules/gui/qt4/adapters/audiothreadadapter.hpp b/modules/gui/qt4/adapters/audiothreadadapter.hpp
new file mode 100644
index 0000000..46b0cdc
--- /dev/null
+++ b/modules/gui/qt4/adapters/audiothreadadapter.hpp
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * audiothreadadapter.cpp : LibVLC audio abstraction class
+ ****************************************************************************
+ * Copyright (C) 2006-2010 the VideoLAN team
+ *
+ * Authors: Francois Cartegnie <fcvlcdev at free.fr>
+ *
+ * This program 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 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef AUDIOTHREADADAPTER_HPP
+#define AUDIOTHREADADAPTER_HPP
+
+#include "qt4.hpp"
+#include "../util/singleton.hpp"
+#include <QObject>
+#include <vlc_aout.h>
+
+/**********************************************************************
+ * AudioThreadAdapter
+ **********************************************************************
+ * The Audio Thread Adapter wraps libVLC calls for audio
+ * functions. Also handles values translation.
+ **********************************************************************/
+
+class AudioThreadAdapter : public QObject,
+ public Singleton< AudioThreadAdapter >
+{
+ friend class Singleton< AudioThreadAdapter >;
+Q_OBJECT
+public:
+ void setLibVolume( int );
+ void setLibMuteState( bool );
+ int getLibVolume( );
+ bool getLibMuteState( );
+signals:
+ /* Emitted after handling & value translation */
+ void libUpdatedVolume( int );
+ void libUpdatedMuteStatus( bool );
+public slots:
+ /* targets for libVLC events */
+ void onLibUpdateVolumeHandler( );
+ void onLibUpdateMuteStatusHandler( );
+private:
+ explicit AudioThreadAdapter( intf_thread_t * _p_intf );
+ intf_thread_t * p_intf;
+ static const int LIB_VOLUME_CPC = 256; /* libVLC value for 100% volume */
+};
+
+
+#endif // AUDIOTHREADADAPTER_HPP
diff --git a/modules/gui/qt4/adapters/prefsadapter.cpp b/modules/gui/qt4/adapters/prefsadapter.cpp
new file mode 100644
index 0000000..632d124
--- /dev/null
+++ b/modules/gui/qt4/adapters/prefsadapter.cpp
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * prefsadapter.cpp : LibVLC variables abstraction class
+ ****************************************************************************
+ * Copyright (C) 2006-2010 the VideoLAN team
+ *
+ * Authors: Francois Cartegnie <fcvlcdev at free.fr>
+ *
+ * This program 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 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "prefsadapter.hpp"
+
+PrefsAdapter::PrefsAdapter( intf_thread_t * _p_intf ) :
+ QObject(), p_intf( _p_intf )
+{
+ Q_CHECK_PTR( p_intf );
+}
+
+char * PrefsAdapter::getString( const char * s_keyname )
+{
+ return var_InheritString( p_intf, s_keyname );
+}
+
+int PrefsAdapter::getInteger( const char * s_keyname )
+{
+ return var_InheritInteger( p_intf, s_keyname );
+}
+
+bool PrefsAdapter::getBool( const char * s_keyname )
+{
+ return var_InheritBool( p_intf, s_keyname );
+}
diff --git a/modules/gui/qt4/adapters/prefsadapter.hpp b/modules/gui/qt4/adapters/prefsadapter.hpp
new file mode 100644
index 0000000..5ea4c8a
--- /dev/null
+++ b/modules/gui/qt4/adapters/prefsadapter.hpp
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * prefsadapter.hpp : LibVLC variables abstraction class
+ ****************************************************************************
+ * Copyright (C) 2006-2010 the VideoLAN team
+ *
+ * Authors: Francois Cartegnie <fcvlcdev at free.fr>
+ *
+ * This program 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 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef PREFSADAPTER_HPP
+#define PREFSADAPTER_HPP
+
+#include "../util/singleton.hpp"
+
+#include <QObject>
+#include <vlc_variables.h>
+
+
+class PrefsAdapter : public QObject, public Singleton< PrefsAdapter >
+{
+ friend class Singleton< PrefsAdapter >;
+Q_OBJECT
+public:
+ char * getString( const char * );
+ int getInteger( const char * );
+ bool getBool( const char * );
+signals:
+
+public slots:
+private:
+ explicit PrefsAdapter( intf_thread_t * _p_intf );
+ intf_thread_t * p_intf;
+};
+
+#endif // PREFSADAPTER_HPP
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 4fde7ed..5ccb5ce 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -37,6 +37,8 @@
#include "dialogs/help.hpp" /* Launch Update */
#include "recents.hpp" /* Recents Item destruction */
#include "util/qvlcapp.hpp" /* QVLCApplication definition */
+#include "adapters/audiothreadadapter.hpp"
+#include "adapters/prefsadapter.hpp"
#ifdef Q_WS_X11
#include <X11/Xlib.h>
@@ -503,6 +505,9 @@ static void *Thread( void *obj )
/* Destroy the MainInputManager */
MainInputManager::killInstance();
+ /* Abstraction adapters */
+ AudioThreadAdapter::killInstance();
+ PrefsAdapter::killInstance();
/* Delete the application automatically */
#ifdef Q_WS_X11
--
1.6.4.4
More information about the vlc-devel
mailing list