updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / darkice-pulse / pulseaudio_2.patch
blobfba386b6dbd2b8433bdadcd5c556905f64557e68
1 Index: configure.in
2 ===================================================================
3 --- configure.in (revisão 480)
4 +++ configure.in (cópia de trabalho)
5 @@ -266,6 +266,42 @@
8 dnl-----------------------------------------------------------------------------
9 +dnl link PULSEAUDIO sound system if requested
10 +dnl-----------------------------------------------------------------------------
11 +AC_SUBST(PULSEAUDIO_INCFLAGS)
12 +AC_SUBST(PULSEAUDIO_LDFLAGS)
14 +AC_ARG_WITH(pulseaudio,
15 +[ --with-pulseaudio use PULSEAUDIO sound system [yes] ],
16 + USE_PULSEAUDIO=${withval}, USE_PULSEAUDIO="yes" )
17 +AC_ARG_WITH(pulseaudio-prefix,
18 +[ --with-pulseaudio-prefix=DIR alternate location for PULSEAUDIO [/usr]
19 + look for libraries in PULSEAUDIO-PREFIX/lib,
20 + for headers in PULSEAUDIO-PREFIX/include],
21 + CONFIG_PULSEAUDIO_PREFIX="${withval}", CONFIG_PULSEAUDIO_PREFIX="/usr")
23 +if test "x${USE_PULSEAUDIO}" = "xyes" ; then
24 + AC_MSG_CHECKING( [for pulseaudio libraries at ${CONFIG_PULSEAUDIO_PREFIX}] )
25 + LA_SEARCH_LIB( PULSEAUDIO_LIB_LOC, PULSEAUDIO_INC_LOC, libasound.so, pulseaudio/asoundlib.h,
26 + ${CONFIG_PULSEAUDIO_PREFIX})
28 + if test "x${PULSEAUDIO_LIB_LOC}" != "x" ; then
30 + AC_DEFINE( HAVE_PULSEAUDIO_LIB, 1, [build with PULSEAUDIO sound system] )
31 + if test "x${PULSEAUDIO_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
32 + PULSEAUDIO_INCFLAGS="-I${PULSEAUDIO_INC_LOC}"
33 + fi
34 + PULSEAUDIO_LDFLAGS="-L${PULSEAUDIO_LIB_LOC} -lpulse-simple"
35 + AC_MSG_RESULT( [found at ${CONFIG_PULSEAUDIO_PREFIX}] )
36 + else
37 + AC_MSG_WARN( [not found, building without PULSEAUDIO support])
38 + fi
39 +else
40 + AC_MSG_RESULT( [building without PULSEAUDIO support] )
41 +fi
44 +dnl-----------------------------------------------------------------------------
45 dnl link JACK sound server if requested
46 dnl-----------------------------------------------------------------------------
47 AC_SUBST(JACK_CFLAGS)
48 Index: src/PulseAudioDspSource.cpp
49 ===================================================================
50 --- src/PulseAudioDspSource.cpp (revisão 0)
51 +++ src/PulseAudioDspSource.cpp (revisão 0)
52 @@ -0,0 +1,220 @@
53 +/*------------------------------------------------------------------------------
55 + Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved.
57 + Copyright (c) 2004
58 + LS Informationstechnik (LIKE)
59 + University of Erlangen Nuremberg
60 + All rights reserved.
62 + Tyrell DarkIce
64 + File : PulseAudioDspSource.cpp
65 + Version : $Revision: 461 $
66 + Author : $Author: rafael@riseup.net $
67 + Location : $HeadURL$
69 + Copyright notice:
71 + This program is free software; you can redistribute it and/or
72 + modify it under the terms of the GNU General Public License
73 + as published by the Free Software Foundation; either version 2
74 + of the License, or (at your option) any later version.
76 + This program is distributed in the hope that it will be useful,
77 + but WITHOUT ANY WARRANTY; without even the implied warranty of
78 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79 + GNU General Public License for more details.
81 + You should have received a copy of the GNU General Public License
82 + along with this program; if not, write to the Free Software
83 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
85 +------------------------------------------------------------------------------*/
87 +/* ============================================================ include files */
89 +#include "AudioSource.h"
91 +// compile only if configured for PULSEAUDIO
92 +#ifdef SUPPORT_PULSEAUDIO_DSP
94 +#ifdef HAVE_CONFIG_H
95 +#include "config.h"
96 +#endif
98 +#include "Util.h"
99 +#include "Exception.h"
100 +#include "PulseAudioDspSource.h"
103 +/* =================================================== local data structures */
106 +/* ================================================ local constants & macros */
108 +/*------------------------------------------------------------------------------
109 + * File identity
110 + *----------------------------------------------------------------------------*/
111 +static const char fileid[] = "$Id: PulseAudioDspSource.cpp 461 2009-12-01 12:57:31Z rafael@riseup.net $";
114 +/* =============================================== local function prototypes */
117 +/* ============================================================= module code */
120 +/*------------------------------------------------------------------------------
121 + * Initialize the object
122 + *----------------------------------------------------------------------------*/
123 +void
124 +PulseAudioDspSource :: init ( const char * paSourceName ) throw ( Exception )
127 + if (paSourceName == NULL)
129 + throw Exception( __FILE__, __LINE__, "no paSourceName specified");
131 + Reporter::reportEvent( 1, "Using PulseAudio source: ", paSourceName);
132 + Util::strEq( paSourceName , "default" );
133 + if (Util::strEq( paSourceName , "default" ))
135 + sourceName = NULL;
137 + else
139 + sourceName = Util::strDup( paSourceName);
141 + ss.channels = getChannel();
142 + ss.rate = getSampleRate();
144 + //Supported for some bits per sample, both Big and Little endian
145 + if (isBigEndian())
147 + switch (getBitsPerSample())
149 + case 8:
150 + ss.format = PA_SAMPLE_U8;
151 + break;
152 + case 16:
153 + ss.format = PA_SAMPLE_S16BE;
154 + break;
155 + case 24:
156 + ss.format = PA_SAMPLE_S24BE;
157 + break;
158 + case 32:
159 + ss.format = PA_SAMPLE_S32BE;
160 + break;
161 + default:
162 + ss.format = PA_SAMPLE_INVALID;
165 + else
167 + switch (getBitsPerSample())
169 + case 8:
170 + ss.format = PA_SAMPLE_U8;
171 + break;
172 + case 16:
173 + ss.format = PA_SAMPLE_S16LE;
174 + break;
175 + case 24:
176 + ss.format = PA_SAMPLE_S24LE;
177 + break;
178 + case 32:
179 + ss.format = PA_SAMPLE_S32LE;
180 + break;
181 + default:
182 + ss.format = PA_SAMPLE_INVALID;
188 +/*------------------------------------------------------------------------------
189 + * De-initialize the object
190 + *----------------------------------------------------------------------------*/
191 +void
192 +PulseAudioDspSource :: strip ( void ) throw ( Exception )
194 + if ( isOpen() ) {
195 + close();
198 + delete[] sourceName;
202 +/*------------------------------------------------------------------------------
203 + * Open the audio source
204 + *----------------------------------------------------------------------------*/
205 +bool
206 +PulseAudioDspSource :: open ( void ) throw ( Exception )
208 + char client_name[255];
210 + //to identify each darkice on pulseaudio server
211 + snprintf(client_name, 255, "darkice-%d", getpid());
213 + if (!(s = pa_simple_new(NULL, client_name, PA_STREAM_RECORD, sourceName, "darkice record", &ss, NULL, NULL, &error))) {
214 + throw Exception( __FILE__, __LINE__, ": pa_simple_new() failed: %s\n", pa_strerror(error));
217 + return true;
221 +/*------------------------------------------------------------------------------
222 + * Check wether read() would return anything
223 + *----------------------------------------------------------------------------*/
224 +bool
225 +PulseAudioDspSource :: canRead ( unsigned int sec,
226 + unsigned int usec ) throw ( Exception )
228 +//this seems to be a problem.
229 +//to explore in the future
230 +/* if ( !isOpen() ) {
231 + return false;
235 + /*
236 + * FIXME How to check if it can read?
237 + */
238 + return true; // bad!!
242 +/*------------------------------------------------------------------------------
243 + * Read from the audio source
244 + *----------------------------------------------------------------------------*/
245 +unsigned int
246 +PulseAudioDspSource :: read ( void * buf,
247 + unsigned int len ) throw ( Exception )
249 + int ret;
251 + ret = pa_simple_read(s, buf, len, &error);
252 + if ( ret < 0) {
253 + throw Exception(__FILE__, __LINE__, ": pa_simple_read() failed: %s\n", pa_strerror(error));
255 + return len;
259 +/*------------------------------------------------------------------------------
260 + * Close the audio source
261 + *----------------------------------------------------------------------------*/
262 +void
263 +PulseAudioDspSource :: close ( void ) throw ( Exception )
265 + if ( !isOpen() ) {
266 + return;
269 + pa_simple_free(s);
272 +#endif // HAVE_PULSEAUDIO_LIB
273 Index: src/AudioSource.h
274 ===================================================================
275 --- src/AudioSource.h (revisão 480)
276 +++ src/AudioSource.h (cópia de trabalho)
277 @@ -56,6 +56,11 @@
278 #define SUPPORT_ALSA_DSP 1
279 #endif
281 +#if defined( HAVE_PULSEAUDIO_LIB )
282 +// we have an PULSEAUDIO sound system available
283 +#define SUPPORT_PULSEAUDIO_DSP 1
284 +#endif
286 #if defined( HAVE_SYS_SOUNDCARD_H )
287 // we have an OSS DSP sound source device available
288 #define SUPPORT_OSS_DSP 1
289 @@ -76,6 +81,7 @@
290 #endif
292 #if !defined( SUPPORT_ALSA_DSP ) \
293 + && !defined( SUPPORT_PULSEAUDIO_DSP ) \
294 && !defined( SUPPORT_OSS_DSP ) \
295 && !defined( SUPPORT_JACK_DSP ) \
296 && !defined( SUPPORT_SOLARIS_DSP ) \
297 @@ -264,6 +270,8 @@
298 * the supplied DSP name parameter.
300 * @param deviceName the audio device (/dev/dspX, hwplug:0,0, etc)
301 + * @param jackClientName the source name for jack server
302 + * @param paSourceName the pulse audio source
303 * @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
304 * @param bitsPerSample bits per sample (e.g. 16 bits).
305 * @param channel number of channels of the audio source
306 @@ -273,6 +281,7 @@
307 static AudioSource *
308 createDspSource( const char * deviceName,
309 const char * jackClientName,
310 + const char * paSourceName,
311 int sampleRate = 44100,
312 int bitsPerSample = 16,
313 int channel = 2) throw ( Exception );
314 @@ -289,6 +298,10 @@
315 #include "AlsaDspSource.h"
316 #endif
318 +#if defined( SUPPORT_PULSEAUDIO_DSP )
319 +#include "PulseAudioDspSource.h"
320 +#endif
322 #if defined( SUPPORT_OSS_DSP )
323 #include "OssDspSource.h"
324 #endif
325 Index: src/PulseAudioDspSource.h
326 ===================================================================
327 --- src/PulseAudioDspSource.h (revisão 0)
328 +++ src/PulseAudioDspSource.h (revisão 0)
329 @@ -0,0 +1,247 @@
330 +/*------------------------------------------------------------------------------
332 + Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved.
334 + Copyright (c) 2004
335 + LS Informationstechnik (LIKE)
336 + University of Erlangen Nuremberg
337 + All rights reserved.
339 + Tyrell DarkIce
341 + File : PulseAudioDspSource.h
342 + Version : $Revision: 394 $
343 + Author : $Author: darkeye $
344 + Location : $HeadURL$
346 + Copyright notice:
348 + This program is free software; you can redistribute it and/or
349 + modify it under the terms of the GNU General Public License
350 + as published by the Free Software Foundation; either version 2
351 + of the License, or (at your option) any later version.
353 + This program is distributed in the hope that it will be useful,
354 + but WITHOUT ANY WARRANTY; without even the implied warranty of
355 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356 + GNU General Public License for more details.
358 + You should have received a copy of the GNU General Public License
359 + along with this program; if not, write to the Free Software
360 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
362 +------------------------------------------------------------------------------*/
363 +#ifndef PULSEAUDIO_SOURCE_H
364 +#define PULSEAUDIO_SOURCE_H
366 +#ifndef __cplusplus
367 +#error This is a C++ include file
368 +#endif
370 +/* ============================================================ include files */
372 +#ifdef HAVE_CONFIG_H
373 +#include "config.h"
374 +#endif
376 +#include "Reporter.h"
377 +#include "AudioSource.h"
379 +#ifdef HAVE_PULSEAUDIO_LIB
381 +#include <pulse/simple.h>
382 +#include <pulse/error.h>
383 +#include <pulse/gccmacro.h>
384 +#else
385 +#error configure for PULSEAUDIO
386 +#endif
388 +/* ================================================================ constants */
390 +/* =================================================================== macros */
392 +/* =============================================================== data types */
394 +/**
395 + * An audio input based on the PULSEAUDIO sound system
397 + * @author $Author: darkeye $
398 + * @version $Revision: 394 $
399 + */
400 +class PulseAudioDspSource : public AudioSource, public virtual Reporter
402 + private:
404 + /**
405 + * Name of the capture PCM stream.
406 + */
407 + char *sourceName;
409 + /**
410 + * Handle for PulseAudio
411 + */
412 + pa_simple *s ;
414 + /**
415 + * format definitions for pulseaudio
416 + */
417 + pa_sample_spec ss;
419 + int error;
421 + protected:
423 + /**
424 + * Default constructor. Always throws an Exception.
426 + * @exception Exception
427 + */
428 + inline
429 + PulseAudioDspSource ( void ) throw ( Exception )
431 + throw Exception( __FILE__, __LINE__);
434 + /**
435 + * Initialize the object
437 + * @param name the PCM to open.
438 + * @exception Exception
439 + */
440 + void
441 + init ( const char * name ) throw ( Exception );
443 + /**
444 + * De-iitialize the object
446 + * @exception Exception
447 + */
448 + void
449 + strip ( void ) throw ( Exception );
452 + public:
454 + /**
455 + * Constructor.
457 + * @param name the PCM (e.g. "hwplug:0,0").
458 + * @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
459 + * @param bitsPerSample bits per sample (e.g. 16 bits).
460 + * @param channel number of channels of the audio source
461 + * (e.g. 1 for mono, 2 for stereo, etc.).
462 + * @exception Exception
463 + */
464 + inline
465 + PulseAudioDspSource ( const char * paSourceName,
466 + int sampleRate = 44100,
467 + int bitsPerSample = 16,
468 + int channel = 2 )
469 + throw ( Exception )
470 + : AudioSource( sampleRate, bitsPerSample, channel)
472 + init( paSourceName);
475 + /**
476 + * Copy Constructor.
478 + * @param ds the object to copy.
479 + * @exception Exception
480 + */
481 + inline
482 + PulseAudioDspSource ( const PulseAudioDspSource & ds ) throw ( Exception )
483 + : AudioSource( ds )
485 + init( ds.sourceName);
488 + /**
489 + * Destructor.
491 + * @exception Exception
492 + */
493 + inline virtual
494 + ~PulseAudioDspSource ( void ) throw ( Exception )
496 + strip();
499 + /**
500 + * Assignment operator.
502 + * @param ds the object to assign to this one.
503 + * @return a reference to this object.
504 + * @exception Exception
505 + */
506 + inline virtual PulseAudioDspSource &
507 + operator= ( const PulseAudioDspSource & ds ) throw ( Exception )
509 + if ( this != &ds ) {
510 + strip();
511 + AudioSource::operator=( ds);
512 + init( ds.sourceName);
514 + return *this;
517 + /**
518 + * Open the PulseAudioDspSource.
520 + * @return true if opening was successful, false otherwise
521 + * @exception Exception
522 + */
523 + virtual bool
524 + open ( void ) throw ( Exception );
526 + /**
527 + * Check if the PulseAudioDspSource is open.
529 + * @return true if the PulseAudioDspSource is open, false otherwise.
530 + */
531 + inline virtual bool
532 + isOpen ( void ) const throw ()
534 + return s==NULL;
537 + /**
538 + * Check if the PulseAudioDspSource can be read from.
540 + * @param sec the maximum seconds to block.
541 + * @param usec micro seconds to block after the full seconds.
542 + * @return true if the PulseAudioDspSource is ready to be read from,
543 + * false otherwise.
544 + * @exception Exception
545 + */
546 + virtual bool
547 + canRead ( unsigned int sec,
548 + unsigned int usec ) throw ( Exception );
550 + /**
551 + * Read from the PulseAudioDspSource.
553 + * @param buf the buffer to read into.
554 + * @param len the number of bytes to read into buf
555 + * @return the number of bytes read (may be less than len).
556 + * @exception Exception
557 + */
558 + virtual unsigned int
559 + read ( void * buf,
560 + unsigned int len ) throw ( Exception );
562 + /**
563 + * Close the PulseAudioDspSource.
565 + * @exception Exception
566 + */
567 + virtual void
568 + close ( void ) throw ( Exception );
572 +/* ================================================= external data structures */
574 +/* ====================================================== function prototypes */
576 +#endif /* PULSEAUDIO_SOURCE_H */
577 Index: src/DarkIce.cpp
578 ===================================================================
579 --- src/DarkIce.cpp (revisão 480)
580 +++ src/DarkIce.cpp (cópia de trabalho)
581 @@ -144,6 +144,7 @@
582 bool reconnect;
583 const char * device;
584 const char * jackClientName;
585 + const char * paSourceName;
587 // the [general] section
588 if ( !(cs = config.get( "general")) ) {
589 @@ -178,9 +179,11 @@
590 channel = Util::strToL( str);
591 device = cs->getForSure( "device", " missing in section [input]");
592 jackClientName = cs->get ( "jackClientName");
593 + paSourceName = cs->get ( "paSourceName");
595 dsp = AudioSource::createDspSource( device,
596 jackClientName,
597 + paSourceName,
598 sampleRate,
599 bitsPerSample,
600 channel );
601 @@ -1191,7 +1194,7 @@
602 (dsp->getBitsPerSample() / 8UL) *
603 dsp->getChannel() *
604 duration;
607 len = encConnector->transfer( bytes, 4096, 1, 0 );
609 reportEvent( 1, len, "bytes transfered to the encoders");
610 Index: src/AudioSource.cpp
611 ===================================================================
612 --- src/AudioSource.cpp (revisão 480)
613 +++ src/AudioSource.cpp (cópia de trabalho)
614 @@ -61,6 +61,7 @@
615 AudioSource *
616 AudioSource :: createDspSource( const char * deviceName,
617 const char * jackClientName,
618 + const char * paSourceName,
619 int sampleRate,
620 int bitsPerSample,
621 int channel)
622 @@ -111,6 +112,18 @@
623 "trying to open JACK device without "
624 "support compiled", deviceName);
625 #endif
626 + } else if ( Util::strEq( deviceName, "pulseaudio", 10) ) {
627 +#if defined( SUPPORT_PULSEAUDIO_DSP )
628 + Reporter::reportEvent( 1, "Using PulseAudio audio server as input device.");
629 + return new PulseAudioDspSource( paSourceName,
630 + sampleRate,
631 + bitsPerSample,
632 + channel);
633 +#else
634 + throw Exception( __FILE__, __LINE__,
635 + "trying to open PulseAudio device without "
636 + "support compiled", deviceName);
637 +#endif
638 } else {
639 #if defined( SUPPORT_ALSA_DSP )
640 Reporter::reportEvent( 1, "Using ALSA DSP input device:", deviceName);
641 Index: src/Makefile.am
642 ===================================================================
643 --- src/Makefile.am (revisão 480)
644 +++ src/Makefile.am (cópia de trabalho)
645 @@ -2,9 +2,9 @@
646 AM_CXXFLAGS = -O2 -pedantic -Wall @DEBUG_CXXFLAGS@ @PTHREAD_CFLAGS@
647 @JACK_CFLAGS@
648 INCLUDES = @LAME_INCFLAGS@ @VORBIS_INCFLAGS@ @FAAC_INCFLAGS@ @AACPLUS_INCFLAGS@ @TWOLAME_INCFLAGS@ \
649 - @ALSA_INCFLAGS@ @JACK_INCFLAGS@ @SRC_INCFLAGS@
650 + @ALSA_INCFLAGS@ @PULSEAUDIO_INCFLAGS@ @JACK_INCFLAGS@ @SRC_INCFLAGS@
651 LDADD = @PTHREAD_LIBS@ @LAME_LDFLAGS@ @VORBIS_LDFLAGS@ @FAAC_LDFLAGS@ @AACPLUS_LDFLAGS@ @TWOLAME_LDFLAGS@ \
652 - @ALSA_LDFLAGS@ @JACK_LDFLAGS@ @SRC_LDFLAGS@
653 + @ALSA_LDFLAGS@ @PULSEAUDIO_LDFLAGS@ @JACK_LDFLAGS@ @SRC_LDFLAGS@
655 if HAVE_SRC_LIB
656 AFLIB_SOURCE =
657 @@ -74,6 +74,8 @@
658 Reporter.cpp\
659 AlsaDspSource.h\
660 AlsaDspSource.cpp\
661 + PulseAudioDspSource.h\
662 + PulseAudioDspSource.cpp\
663 JackDspSource.h\
664 JackDspSource.cpp\
665 main.cpp \
666 Index: man/darkice.1
667 ===================================================================
668 --- man/darkice.1 (revisão 480)
669 +++ man/darkice.1 (cópia de trabalho)
670 @@ -13,6 +13,7 @@
671 * ALSA audio devices
672 * Solaris audio interface
673 * Jack sources
674 + * PulseAudio sources
676 DarkIce can encode in the following formats:
678 Index: man/darkice.cfg.5
679 ===================================================================
680 --- man/darkice.cfg.5 (revisão 480)
681 +++ man/darkice.cfg.5 (cópia de trabalho)
682 @@ -74,9 +74,10 @@
684 .I device
685 Specify the device to record from, which can be an OSS DSP device,
686 -an ALSA source or you can use Jack audio.
687 +an ALSA source, PulseAudio source or you can use Jack audio.
688 - OSS DSP audio device to record from (e.g. /dev/dsp)
689 - ALSA DSP device name (e.g. hwplug:0,0)
690 +- for PulseAudio use "pulseaudio"
691 - the string 'jack', to have an unconnected Jack port, or
692 'jack_auto' to automatically make Jack connect to the first source.
694 @@ -94,6 +95,9 @@
695 .I jackClientName
696 The name of the jack input channel created by darkice if device=jack
697 is specified.
698 +.TP
699 +.I paSourceName
700 +The name of the PulseAudio source to use. It can be "default", an index or a device string obtained from running "pactl list"
703 .B [icecast-x]