diff options
Diffstat (limited to 'plugins/audiooutput')
-rw-r--r-- | plugins/audiooutput/Makefile.am | 9 | ||||
-rw-r--r-- | plugins/audiooutput/alsa/Makefile.am | 14 | ||||
-rw-r--r-- | plugins/audiooutput/alsa/configure.in.bot | 7 | ||||
-rw-r--r-- | plugins/audiooutput/alsa/configure.in.in | 26 | ||||
-rw-r--r-- | plugins/audiooutput/alsa/k3balsaoutputplugin.cpp | 293 | ||||
-rw-r--r-- | plugins/audiooutput/alsa/k3balsaoutputplugin.h | 69 | ||||
-rw-r--r-- | plugins/audiooutput/alsa/k3balsaoutputplugin.plugin | 9 | ||||
-rw-r--r-- | plugins/audiooutput/arts/Makefile.am | 13 | ||||
-rw-r--r-- | plugins/audiooutput/arts/k3bartsoutputplugin.cpp | 90 | ||||
-rw-r--r-- | plugins/audiooutput/arts/k3bartsoutputplugin.h | 47 | ||||
-rw-r--r-- | plugins/audiooutput/arts/k3bartsoutputplugin.plugin | 9 |
11 files changed, 586 insertions, 0 deletions
diff --git a/plugins/audiooutput/Makefile.am b/plugins/audiooutput/Makefile.am new file mode 100644 index 0000000..d8335ad --- /dev/null +++ b/plugins/audiooutput/Makefile.am @@ -0,0 +1,9 @@ +if include_arts +ARTSDIR=arts +endif + +if include_ALSA +ALSADIR=alsa +endif + +SUBDIRS = $(ARTSDIR) $(ALSADIR) diff --git a/plugins/audiooutput/alsa/Makefile.am b/plugins/audiooutput/alsa/Makefile.am new file mode 100644 index 0000000..5cc7f06 --- /dev/null +++ b/plugins/audiooutput/alsa/Makefile.am @@ -0,0 +1,14 @@ +AM_CPPFLAGS = -I$(srcdir)/../../../libk3b/core -I$(srcdir)/../../../libk3b/plugin $(all_includes) + +kde_module_LTLIBRARIES = libk3balsaoutputplugin.la + +libk3balsaoutputplugin_la_SOURCES = k3balsaoutputplugin.cpp + +libk3balsaoutputplugin_la_CFLAGS = $(ALSA_CFLAGS) +libk3balsaoutputplugin_la_LIBADD = ../../../libk3b/libk3b.la $(ALSA_LIBS) +libk3balsaoutputplugin_la_LDFLAGS = -avoid-version -module -no-undefined $(all_libraries) + +pluginsdir = $(kde_datadir)/k3b/plugins +plugins_DATA = k3balsaoutputplugin.plugin + +METASOURCES = AUTO diff --git a/plugins/audiooutput/alsa/configure.in.bot b/plugins/audiooutput/alsa/configure.in.bot new file mode 100644 index 0000000..d5c8d17 --- /dev/null +++ b/plugins/audiooutput/alsa/configure.in.bot @@ -0,0 +1,7 @@ +echo "" + +if test "x$have_alsa" = xyes; then + echo "K3b - Audioplayer available (alsa) yes" +else + echo "K3b - Audioplayer available (alsa) no" +fi diff --git a/plugins/audiooutput/alsa/configure.in.in b/plugins/audiooutput/alsa/configure.in.in new file mode 100644 index 0000000..244dce4 --- /dev/null +++ b/plugins/audiooutput/alsa/configure.in.in @@ -0,0 +1,26 @@ +dnl --------- ALSA CHECK BEGIN ------------- + +AC_DEFUN([KDE_CHECK_ALSA], +[ + PKG_CHECK_MODULES([ALSA], [alsa >= 0.9], [have_alsa=yes], [have_alsa=no]) + AC_SUBST([ALSA_CFLAGS]) + AC_SUBST([ALSA_LIBS]) +]) + +AC_ARG_WITH(alsa, + [AS_HELP_STRING(--with-alsa, + [enable support for ALSA output @<:@default=check@:>@])], + [], with_alsa=check) + +have_alsa=no +if test "x$with_alsa" != xno; then + KDE_CHECK_ALSA + + if test "x$with_alsa" != xcheck && test "x$have_alsa" != xyes; then + AC_MSG_FAILURE([--with-alsa was given, but test for ALSA failed]) + fi +fi + +AM_CONDITIONAL(include_ALSA, [test "x$have_alsa" = "xyes"]) + +dnl --------- ALSA CHECK END --------------- diff --git a/plugins/audiooutput/alsa/k3balsaoutputplugin.cpp b/plugins/audiooutput/alsa/k3balsaoutputplugin.cpp new file mode 100644 index 0000000..7351ffc --- /dev/null +++ b/plugins/audiooutput/alsa/k3balsaoutputplugin.cpp @@ -0,0 +1,293 @@ +/* + * + * $Id: k3bartsoutputplugin.cpp 369057 2004-12-07 14:05:11Z trueg $ + * Copyright (C) 2004 Sebastian Trueg <[email protected]> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#include <config.h> + +#include "k3balsaoutputplugin.h" +#include <k3bpluginfactory.h> +#include <k3bcore.h> + +#include <kdebug.h> +#include <kcombobox.h> +#include <klocale.h> +#include <kconfig.h> +#include <kdialog.h> + +#include <qlayout.h> +#include <qlabel.h> + +#include <alsa/asoundlib.h> +#include <alsa/pcm.h> + + +K_EXPORT_COMPONENT_FACTORY( libk3balsaoutputplugin, K3bPluginFactory<K3bAlsaOutputPlugin>( "k3balsaoutputplugin" ) ) + + +class K3bAlsaOutputPlugin::Private +{ +public: + Private() + : pcm_playback(0), + error(false) { + } + + snd_pcm_t *pcm_playback; + + bool error; + QString lastErrorMessage; + + bool swap; + + unsigned int sampleRate; +}; + + +K3bAlsaOutputPlugin::K3bAlsaOutputPlugin( QObject* parent, const char* name ) + : K3bAudioOutputPlugin( parent, name ) +{ + d = new Private; +} + + +K3bAlsaOutputPlugin::~K3bAlsaOutputPlugin() +{ + cleanup(); + + delete d; +} + + +int K3bAlsaOutputPlugin::write( char* data, int len ) +{ + if( d->error ) + return -1; + + char* buffer = data; + if( d->swap ) { + buffer = new char[len]; + for( int i = 0; i < len-1; i+=2 ) { + buffer[i] = data[i+1]; + buffer[i+1] = data[i]; + } + } + + int written = 0; + while( written < len ) { + snd_pcm_sframes_t frames = snd_pcm_writei( d->pcm_playback, + buffer+written, + snd_pcm_bytes_to_frames( d->pcm_playback, len-written ) ); + + if( frames < 0 ) { + if( !recoverFromError( frames ) ) { + d->error = true; + return -1; + } + } + else { + written += snd_pcm_frames_to_bytes( d->pcm_playback, frames ); + } + } + + return written; +} + + +bool K3bAlsaOutputPlugin::recoverFromError( int err ) +{ + if( err == -EPIPE ) { + err = snd_pcm_prepare( d->pcm_playback ); + if( err < 0 ) { + d->lastErrorMessage = i18n("Internal Alsa problem: %1").arg(snd_strerror(err)); + return false; + } + } + else if( err == -ESTRPIPE ) { + while( ( err = snd_pcm_resume( d->pcm_playback ) ) == -EAGAIN ) + sleep( 1 ); + + if (err < 0) { + // unable to wake up pcm device, restart it + err = snd_pcm_prepare( d->pcm_playback ); + if( err < 0 ) { + d->lastErrorMessage = i18n("Internal Alsa problem: %1").arg(snd_strerror(err)); + return false; + } + } + + return true; + } + + return false; +} + + +void K3bAlsaOutputPlugin::cleanup() +{ + if( d->pcm_playback ) { + snd_pcm_drain( d->pcm_playback ); + snd_pcm_close( d->pcm_playback ); + } + d->pcm_playback = 0; + d->error = false; +} + + +bool K3bAlsaOutputPlugin::init() +{ + cleanup(); + + KConfigGroup c( k3bcore->config(), "Alsa Output Plugin" ); + QString alsaDevice = c.readEntry( "output device", "default" ); + + int err = snd_pcm_open( &d->pcm_playback, alsaDevice.local8Bit(), SND_PCM_STREAM_PLAYBACK, 0 ); + if( err < 0 ) { + d->lastErrorMessage = i18n("Could not open alsa audio device '%1' (%2).").arg(alsaDevice).arg(snd_strerror(err)); + d->error = true; + return false; + } + + if( !setupHwParams() ) { + d->error = true; + return false; + } + + d->error = false; + return true; +} + + +bool K3bAlsaOutputPlugin::setupHwParams() +{ + snd_pcm_hw_params_t* hw_params; + int err = 0; + + if( ( err = snd_pcm_hw_params_malloc( &hw_params ) ) < 0 ) { + d->lastErrorMessage = i18n("Could not allocate hardware parameter structure (%1)").arg(snd_strerror(err)); + d->error = true; + return false; + } + + if( (err = snd_pcm_hw_params_any( d->pcm_playback, hw_params )) < 0) { + d->lastErrorMessage = i18n("Could not initialize hardware parameter structure (%1).").arg(snd_strerror(err)); + snd_pcm_hw_params_free( hw_params ); + d->error = true; + return false; + } + + if( (err = snd_pcm_hw_params_set_access( d->pcm_playback, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { + d->lastErrorMessage = i18n("Could not set access type (%1).").arg(snd_strerror(err)); + snd_pcm_hw_params_free( hw_params ); + d->error = true; + return false; + } + + if( (err = snd_pcm_hw_params_set_format( d->pcm_playback, hw_params, SND_PCM_FORMAT_S16_BE)) < 0) { + if( (err = snd_pcm_hw_params_set_format( d->pcm_playback, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) { + d->lastErrorMessage = i18n("Could not set sample format (%1).").arg(snd_strerror(err)); + snd_pcm_hw_params_free( hw_params ); + d->error = true; + return false; + } + else + d->swap = true; + } + else + d->swap = false; + + d->sampleRate = 44100; + if( (err = snd_pcm_hw_params_set_rate_near( d->pcm_playback, hw_params, &d->sampleRate, 0)) < 0) { + d->lastErrorMessage = i18n("Could not set sample rate (%1).").arg(snd_strerror(err)); + snd_pcm_hw_params_free( hw_params ); + d->error = true; + return false; + } + + kdDebug() << "(K3bAlsaOutputPlugin) samplerate set to " << d->sampleRate << endl; + + if( (err = snd_pcm_hw_params_set_channels( d->pcm_playback, hw_params, 2)) < 0) { + d->lastErrorMessage = i18n("Could not set channel count (%1).").arg(snd_strerror(err)); + snd_pcm_hw_params_free( hw_params ); + d->error = true; + return false; + } + + if( (err = snd_pcm_hw_params( d->pcm_playback, hw_params )) < 0) { + d->lastErrorMessage = i18n("Could not set parameters (%1).").arg(snd_strerror(err)); + snd_pcm_hw_params_free( hw_params ); + d->error = true; + return false; + } + + snd_pcm_hw_params_free(hw_params); + + return true; +} + + +QString K3bAlsaOutputPlugin::lastErrorMessage() const +{ + return d->lastErrorMessage; +} + + +K3bPluginConfigWidget* K3bAlsaOutputPlugin::createConfigWidget( QWidget* parent, + const char* name ) const +{ + return new K3bAlsaOutputPluginConfigWidget( parent, name ); +} + + + +K3bAlsaOutputPluginConfigWidget::K3bAlsaOutputPluginConfigWidget( QWidget* parent, const char* name ) + : K3bPluginConfigWidget( parent, name ) +{ + QHBoxLayout* l = new QHBoxLayout( this ); + l->setSpacing( KDialog::spacingHint() ); + l->setAutoAdd( true ); + + (void)new QLabel( i18n("Alsa device:"), this ); + + m_comboDevice = new KComboBox( this ); + m_comboDevice->setEditable( true ); + // enable completion + m_comboDevice->completionObject(); + + // FIXME: initialize the list of devices + m_comboDevice->insertItem( "default" ); +} + + +K3bAlsaOutputPluginConfigWidget::~K3bAlsaOutputPluginConfigWidget() +{ +} + + +void K3bAlsaOutputPluginConfigWidget::loadConfig() +{ + KConfigGroup c( k3bcore->config(), "Alsa Output Plugin" ); + + m_comboDevice->setCurrentText( c.readEntry( "output device", "default" ) ); +} + + +void K3bAlsaOutputPluginConfigWidget::saveConfig() +{ + KConfigGroup c( k3bcore->config(), "Alsa Output Plugin" ); + + c.writeEntry( "output device", m_comboDevice->currentText() ); +} + + +#include "k3balsaoutputplugin.moc" diff --git a/plugins/audiooutput/alsa/k3balsaoutputplugin.h b/plugins/audiooutput/alsa/k3balsaoutputplugin.h new file mode 100644 index 0000000..7e59b1e --- /dev/null +++ b/plugins/audiooutput/alsa/k3balsaoutputplugin.h @@ -0,0 +1,69 @@ +/* + * + * $Id: k3bartsoutputplugin.h 369057 2004-12-07 14:05:11Z trueg $ + * Copyright (C) 2004 Sebastian Trueg <[email protected]> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_ALSA_AUDIO_OUTPUT_H_ +#define _K3B_ALSA_AUDIO_OUTPUT_H_ + +#include <k3baudiooutputplugin.h> +#include <k3bpluginconfigwidget.h> + +class KComboBox; + + +class K3bAlsaOutputPlugin : public K3bAudioOutputPlugin +{ + public: + K3bAlsaOutputPlugin( QObject* parent = 0, const char* name = 0 ); + ~K3bAlsaOutputPlugin(); + + int pluginSystemVersion() const { return 3; } + QCString soundSystem() const { return "alsa"; } + + bool init(); + void cleanup(); + + QString lastErrorMessage() const; + + int write( char* data, int len ); + + K3bPluginConfigWidget* createConfigWidget( QWidget* parent = 0, + const char* name = 0 ) const; + + private: + bool setupHwParams(); + bool recoverFromError( int err ); + + class Private; + Private* d; +}; + + +class K3bAlsaOutputPluginConfigWidget : public K3bPluginConfigWidget +{ + Q_OBJECT + + public: + K3bAlsaOutputPluginConfigWidget( QWidget* parent = 0, const char* name = 0 ); + ~K3bAlsaOutputPluginConfigWidget(); + + public slots: + void loadConfig(); + void saveConfig(); + + private: + KComboBox* m_comboDevice; +}; + +#endif diff --git a/plugins/audiooutput/alsa/k3balsaoutputplugin.plugin b/plugins/audiooutput/alsa/k3balsaoutputplugin.plugin new file mode 100644 index 0000000..b5957d7 --- /dev/null +++ b/plugins/audiooutput/alsa/k3balsaoutputplugin.plugin @@ -0,0 +1,9 @@ +[K3b Plugin] +Lib=libk3balsaoutputplugin +Group=AudioOutput +Name=K3b Alsa Audio Output Plugin +Author=Sebastian Trueg +Version=1.0 +Comment=Audio Output plugin which plays through alsa +License=GPL diff --git a/plugins/audiooutput/arts/Makefile.am b/plugins/audiooutput/arts/Makefile.am new file mode 100644 index 0000000..6d5adf5 --- /dev/null +++ b/plugins/audiooutput/arts/Makefile.am @@ -0,0 +1,13 @@ +AM_CPPFLAGS = -I$(srcdir)/../../../libk3b/core -I$(srcdir)/../../../libk3b/plugin $(all_includes) + +kde_module_LTLIBRARIES = libk3bartsoutputplugin.la + +libk3bartsoutputplugin_la_SOURCES = k3bartsoutputplugin.cpp + +libk3bartsoutputplugin_la_LIBADD = ../../../libk3b/libk3b.la -lartsc +libk3bartsoutputplugin_la_LDFLAGS = -avoid-version -module -no-undefined $(all_libraries) + +pluginsdir = $(kde_datadir)/k3b/plugins +plugins_DATA = k3bartsoutputplugin.plugin + +METASOURCES = AUTO diff --git a/plugins/audiooutput/arts/k3bartsoutputplugin.cpp b/plugins/audiooutput/arts/k3bartsoutputplugin.cpp new file mode 100644 index 0000000..893571a --- /dev/null +++ b/plugins/audiooutput/arts/k3bartsoutputplugin.cpp @@ -0,0 +1,90 @@ +/* + * + * $Id: k3bartsoutputplugin.cpp 619556 2007-01-03 17:38:12Z trueg $ + * Copyright (C) 2004 Sebastian Trueg <[email protected]> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#include <config.h> + +#include "k3bartsoutputplugin.h" +#include <k3bpluginfactory.h> + +#include <kdebug.h> + + +K_EXPORT_COMPONENT_FACTORY( libk3bartsoutputplugin, K3bPluginFactory<K3bArtsOutputPlugin>( "k3bartsoutputplugin" ) ) + + +K3bArtsOutputPlugin::K3bArtsOutputPlugin( QObject* parent, const char* name ) + : K3bAudioOutputPlugin( parent, name ), + m_initialized(false), + m_lastErrorCode(0) +{ +} + + +K3bArtsOutputPlugin::~K3bArtsOutputPlugin() +{ + cleanup(); +} + + +int K3bArtsOutputPlugin::write( char* data, int len ) +{ + for( int i = 0; i < len-1; i+=2 ) { + char b = data[i]; + data[i] = data[i+1]; + data[i+1] = b; + } + + m_lastErrorCode = arts_write( m_stream, data, len ); + + if( m_lastErrorCode < 0 ) + return -1; + else + return len; +} + + +void K3bArtsOutputPlugin::cleanup() +{ + if( m_initialized ) { + arts_close_stream( m_stream ); + kdDebug() << "(K3bArtsOutputPlugin::cleanup) arts_free()" << endl; + arts_free(); + kdDebug() << "(K3bArtsOutputPlugin::cleanup) arts_free() done" << endl; + m_initialized = false; + } +} + + +bool K3bArtsOutputPlugin::init() +{ + kdDebug() << "(K3bArtsOutputPlugin::init)" << endl; + if( !m_initialized ) { + kdDebug() << "(K3bArtsOutputPlugin::init) arts_init()" << endl; + m_lastErrorCode = arts_init(); + m_initialized = ( m_lastErrorCode == 0 ); + kdDebug() << "(K3bArtsOutputPlugin::init) arts_init() done: " << m_lastErrorCode << endl; + if( m_initialized ) + m_stream = arts_play_stream( 44100, 16, 2, "K3bArtsOutputPlugin" ); + } + + return m_initialized; +} + + +QString K3bArtsOutputPlugin::lastErrorMessage() const +{ + return QString::fromLocal8Bit( arts_error_text(m_lastErrorCode) ); +} + diff --git a/plugins/audiooutput/arts/k3bartsoutputplugin.h b/plugins/audiooutput/arts/k3bartsoutputplugin.h new file mode 100644 index 0000000..57a2b22 --- /dev/null +++ b/plugins/audiooutput/arts/k3bartsoutputplugin.h @@ -0,0 +1,47 @@ +/* + * + * $Id: k3bartsoutputplugin.h 619556 2007-01-03 17:38:12Z trueg $ + * Copyright (C) 2004 Sebastian Trueg <[email protected]> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_ARTS_AUDIO_OUTPUT_H_ +#define _K3B_ARTS_AUDIO_OUTPUT_H_ + +#include <k3baudiooutputplugin.h> + +#include <artsc/artsc.h> + + +class K3bArtsOutputPlugin : public K3bAudioOutputPlugin +{ + public: + K3bArtsOutputPlugin( QObject* parent = 0, const char* name = 0 ); + ~K3bArtsOutputPlugin(); + + int pluginSystemVersion() const { return 3; } + QCString soundSystem() const { return "arts"; } + + bool init(); + void cleanup(); + + QString lastErrorMessage() const; + + int write( char* data, int len ); + + private: + bool m_initialized; + int m_lastErrorCode; + + arts_stream_t m_stream; +}; + +#endif diff --git a/plugins/audiooutput/arts/k3bartsoutputplugin.plugin b/plugins/audiooutput/arts/k3bartsoutputplugin.plugin new file mode 100644 index 0000000..599869f --- /dev/null +++ b/plugins/audiooutput/arts/k3bartsoutputplugin.plugin @@ -0,0 +1,9 @@ +[K3b Plugin] +Lib=libk3bartsoutputplugin +Group=AudioOutput +Name=K3b Arts Audio Output Plugin +Author=Sebastian Trueg +Version=1.0 +Comment=Audio Output plugin which plays through arts +License=GPL |