├── debian ├── compat ├── dirs ├── source │ └── format ├── clean ├── watch ├── patches │ ├── series │ ├── 03_gcc-43.diff │ ├── 05_fix_crlf.diff │ ├── 04_gcc44.diff │ └── 02_errno_range.diff ├── default ├── changelog ├── README.debian ├── rules ├── control ├── copyright └── init ├── src ├── .deps │ ├── aflibDebug.Po │ ├── aflibConverter.Po │ └── Exception.Po ├── stamp-h1 ├── Reporter.cpp ├── Makefile.am ├── aflibDebug.h ├── CastSink.cpp ├── Referable.h ├── Source.h ├── config.h.in ├── DarkIceConfig.cpp ├── Sink.h ├── config.h ├── ConfigSection.h ├── AudioSource.cpp ├── ConfigSection.cpp ├── DarkIceConfig.h ├── Exception.cpp ├── aflibDebug.cc ├── main.cpp ├── aflibConverter.h ├── PulseAudioDspSource.cpp ├── SolarisDspSource.cpp ├── OssDspSource.h ├── SerialUlaw.h ├── SolarisDspSource.h ├── IceCast2.h ├── Connector.h └── Ref.h ├── README.md ├── man ├── Makefile.am └── darkice.1 ├── Makefile.am ├── TODO ├── FAQ ├── INSTALL.vorbis ├── LICENSE ├── AUTHORS ├── README ├── INSTALL.lame ├── AUTHORS~ ├── rc.darkice ├── NEWS └── darkice.cfg /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/dirs: -------------------------------------------------------------------------------- 1 | usr/bin 2 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /src/.deps/aflibDebug.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/.deps/aflibConverter.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for src/config.h 2 | -------------------------------------------------------------------------------- /debian/clean: -------------------------------------------------------------------------------- 1 | config.guess 2 | config.sub 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RaspIce 2 | ======= 3 | 4 | DarkIce on RaspberryPI 5 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | man_MANS = darkice.1 darkice.cfg.5 2 | 3 | EXTRA_DIST = ${man_MANS} 4 | 5 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | version=3 2 | http://googlecode.debian.net/p/darkice/darkice-(\d+.*)\.tar\.gz 3 | -------------------------------------------------------------------------------- /debian/patches/series: -------------------------------------------------------------------------------- 1 | 02_errno_range.diff 2 | 03_gcc-43.diff 3 | 04_gcc44.diff 4 | 05_fix_crlf.diff 5 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src man 2 | 3 | sysconf_DATA = darkice.cfg 4 | 5 | EXTRA_DIST = darkice.cfg INSTALL.lame INSTALL.vorbis FAQ rc.darkice 6 | 7 | 8 | -------------------------------------------------------------------------------- /debian/default: -------------------------------------------------------------------------------- 1 | # Defaults for darkice initscript 2 | # sourced by /etc/init.d/darkice 3 | # installed at /etc/default/darkice by the maintainer scripts 4 | 5 | # 6 | # This is a POSIX shell fragment 7 | # 8 | RUN=no 9 | # Additional options that are passed to the Daemon. 10 | DAEMON_OPTS="" 11 | USER=nobody 12 | GROUP=nogroup 13 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | raspice (1) STABLE; urgency=low 2 | 3 | * Initial release. 4 | * files used are from darkice 1.2 5 | * supports raspberry pi and plays only mp3 files and streams throughs icecast2 streaming server only 6 | * all the unrelated streaming server files and library files are removed and few mods to run the package are added 7 | 8 | -- Sat, 08 Feb 2014 07:11:56 +0000 9 | -------------------------------------------------------------------------------- /debian/patches/03_gcc-43.diff: -------------------------------------------------------------------------------- 1 | Index: darkice-0.20.1/src/JackDspSource.cpp 2 | =================================================================== 3 | --- darkice-0.20.1.orig/src/JackDspSource.cpp 2010-05-07 16:06:51.000000000 +0200 4 | +++ darkice-0.20.1/src/JackDspSource.cpp 2010-05-07 16:06:56.000000000 +0200 5 | @@ -76,6 +76,8 @@ 6 | #error need limits.h 7 | #endif 8 | 9 | +#include 10 | + 11 | #include "Util.h" 12 | #include "Exception.h" 13 | #include "JackDspSource.h" 14 | -------------------------------------------------------------------------------- /debian/patches/05_fix_crlf.diff: -------------------------------------------------------------------------------- 1 | Index: darkice-0.20.1/src/IceCast2.cpp 2 | =================================================================== 3 | --- darkice-0.20.1.orig/src/IceCast2.cpp 2010-05-07 16:06:49.000000000 +0200 4 | +++ darkice-0.20.1/src/IceCast2.cpp 2010-05-07 16:07:05.000000000 +0200 5 | @@ -236,7 +236,7 @@ 6 | sink->write( str, strlen( str)); 7 | } 8 | 9 | - str = "\n\n"; 10 | + str = "\r\n\r\n"; 11 | sink->write( str, strlen( str)); 12 | sink->flush(); 13 | 14 | -------------------------------------------------------------------------------- /debian/README.debian: -------------------------------------------------------------------------------- 1 | DarkIce for Debian 2 | ---------------------- 3 | 4 | This package was built with Ogg Vorbis support but without mp3 (lame) 5 | support for patent reasons. 6 | 7 | A sample configuration in installed into /usr/share/doc/darkice/examples. 8 | In order to use DarkIce, please copy this example to your preferred 9 | configuration directory, make any required changes for your site and reference 10 | it using darkice -c . 11 | 12 | Jochen Friedrich , Wed, 20 Aug 2003 21:02:26 +0200 13 | -------------------------------------------------------------------------------- /debian/patches/04_gcc44.diff: -------------------------------------------------------------------------------- 1 | --- a/src/SerialUlaw.cpp 2 | +++ b/src/SerialUlaw.cpp 3 | @@ -88,6 +88,10 @@ 4 | #error need termios.h 5 | #endif 6 | 7 | +#ifdef HAVE_STDIO_H 8 | +#include 9 | +#endif 10 | + 11 | 12 | #include "Util.h" 13 | #include "Exception.h" 14 | --- a/src/JackDspSource.cpp 15 | +++ b/src/JackDspSource.cpp 16 | @@ -76,6 +76,10 @@ 17 | #error need limits.h 18 | #endif 19 | 20 | +#ifdef HAVE_STDIO_H 21 | +#include 22 | +#endif 23 | + 24 | #include 25 | 26 | #include "Util.h" 27 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | o Add samplerate conversion for samplerate audio output different from audio source 2 | o Add Coreaudio support 3 | o change Ref to follow inheritance 4 | o make a master config file, and a small one ? 5 | o add support for multiple servers for one stream ? 6 | o revisit real-time scheduling 7 | o look into performance 8 | o create proper error-reporting module 9 | o set comment fields for Ogg Vorbis streams as in 10 | http://www.xiph.org/ogg/vorbis/doc/v-comment.html 11 | o change config file to separate descriptions of input, streams and 12 | stream targets (servers, files, etc.) 13 | o add support for 24 and 32 bit input and higher sample rates (up to 96kHz) 14 | -------------------------------------------------------------------------------- /debian/patches/02_errno_range.diff: -------------------------------------------------------------------------------- 1 | diff -urNad darkice-0.19~/src/Util.cpp darkice-0.19/src/Util.cpp 2 | --- darkice-0.19~/src/Util.cpp 2007-02-25 17:38:33.000000000 +0100 3 | +++ darkice-0.19/src/Util.cpp 2008-07-14 18:36:59.000000000 +0200 4 | @@ -81,6 +81,9 @@ 5 | #error need signal.h 6 | #endif 7 | 8 | +#ifdef HAVE_ERRNO_H 9 | +#include 10 | +#endif 11 | 12 | #include "Util.h" 13 | 14 | @@ -278,7 +281,7 @@ 15 | } 16 | 17 | val = strtod( str, &s); 18 | - if ( s == str || val == HUGE_VAL ) { 19 | + if ( s == str || errno == ERANGE ) { 20 | throw Exception( __FILE__, __LINE__, "number conversion error"); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /FAQ: -------------------------------------------------------------------------------- 1 | DarkIce Frequenty Asked Questions 2 | 3 | 4 | Q: I get the following error: 5 | 6 | DarkIce: LameLibEncoder.cpp:75: lame lib opening underlying sink error [0] 7 | 8 | What am I doing wrong? 9 | 10 | 11 | A: This error means (quite anti-intuitively), that darkice coulnd't connect 12 | to the streaming server. Please double-check the following values in 13 | your config file: 14 | - server 15 | - port 16 | - password 17 | 18 | If you're streaming to a shoutcast server, make sure that the port 19 | you use is the _source_ port, which is usually 1 above the _client_ 20 | port for shoutcast (the defaults are 8000 for client, 8001 for source). 21 | 22 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ 5 | 6 | .PHONY: override_dh_auto_configure 7 | override_dh_auto_configure: 8 | ln -s /usr/share/misc/config.guess . 9 | ln -s /usr/share/misc/config.sub . 10 | dh_auto_configure -- --prefix=/usr --sysconfdir=/usr/share/doc/darkice/examples --with-vorbis-prefix=/usr/lib/arm-linux-gnueabihf/ --with-jack-prefix=/usr/lib/arm-linux-gnueabihf/ --with-alsa-prefix=/usr/lib/arm-linux-gnueabihf/ --with-faac-prefix=/usr/lib/arm-linux-gnueabihf/ --with-aacplus-prefix=/usr/lib/arm-linux-gnueabihf/ --with-samplerate-prefix=/usr/lib/arm-linux-gnueabihf/ --with-lame-prefix=/usr/lib/arm-linux-gnueabihf/ CFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard' 11 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: raspice 2 | Section: sound 3 | Priority: optional 4 | Maintainer: Jochen Friedrich 5 | Standards-Version: 3.9.2 6 | Build-Depends: debhelper (>= 7.0.50~), libvorbis-dev, libasound2-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], libjack-dev, libtwolame-dev, autotools-dev 7 | Homepage: https://github.com/MicroPyramid/RaspIce 8 | 9 | Package: raspice 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends}, lsb-base (>= 3.0-6) 12 | Suggests: darksnow 13 | Description: Live audio streamer 14 | raspice is an IceCast2 live audio streamer. It takes audio input from a sound card, encodes it into mp3 and sends the mp3 stream to one or more IceCast servers, DarkIce uses lame as a shared object as its mp3 encoder. 15 | NOTE: The Debian version of RaspIce is only compiled with lame support and therefore only work with IceCast2 servers! 16 | -------------------------------------------------------------------------------- /INSTALL.vorbis: -------------------------------------------------------------------------------- 1 | Installing Ogg Vorbis 2 | --------------------- 3 | 4 | To install DarkIce, you need the following Ogg Vorbis 1.0 or later 5 | libraries (and related header files): 6 | 7 | - libogg 8 | - libvoribs 9 | - libvorbisenc 10 | 11 | installed on your system. 12 | 13 | It is recommended that use install these to the usual system locations, 14 | /usr/lib, /usr/include, so that DarkIce will find the header files and 15 | libraries. Thus when configuring, add --prefix=/usr to the configure 16 | options. 17 | 18 | Grab the latest Ogg Vorbis tarballs from 19 | http://www.xiph.org/ogg/vorbis/download.html 20 | 21 | I took libogg-1.0.tar.gz and libvorbis-1.0.tar.gz. Go to the 22 | directory where you saved them, and issue the following commands: 23 | 24 | tar xfz libogg-1.0.tar.gz 25 | cd libogg-1.0 26 | ./configure --prefix=/usr 27 | make 28 | make install 29 | cd .. 30 | 31 | tar xfz libvorbis-1.0.tar.gz 32 | cd libvorbis-1.0 33 | ./configure --prefix=/usr 34 | make 35 | make install 36 | 37 | For the install steps, you need to be root or have write permissions in the 38 | target directories. 39 | 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 MicroPyramid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by Maitland Bottoms on 2 | Fri, 2 Aug 2002 16:43:20 -0400. 3 | 4 | It is now being maintained by Jochen Friedrich on 5 | Wed, 20 Aug 2003 22:55:52 +0200 6 | 7 | It was downloaded from http://darkice.sourceforge.net/ 8 | DarkIce is being written by Tyrell Hungary, Ákos Maróy, Rafael Diniz 9 | 10 | Copyright: 11 | 12 | Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/ 13 | Copyright (c) 2008, Ákos Maróy, akos@maroy.hu 14 | Copyright (c) 2009, Rafael Diniz, rafael@riseup.net 15 | 16 | Tyrell DarkIce 17 | 18 | Copyright notice: 19 | 20 | This program is free software; you can redistribute it and/or 21 | modify it under the terms of the GNU General Public License 22 | as published by the Free Software Foundation; either version 2 23 | of the License, or (at your option) any later version. 24 | 25 | This program is distributed in the hope that it will be useful, 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | GNU General Public License for more details. 29 | 30 | You should have received a copy of the GNU General Public License 31 | along with this program; if not, write to the Free Software 32 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 33 | MA 02110-1301, USA. 34 | 35 | the GNU GPL may be viewed on Debian systems in /usr/share/common-licenses/GPL 36 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | DarkIce initial author: 2 | 3 | Akos Maroy, 4 | 5 | DarkIce current maintainer: 6 | 7 | Rafael Diniz, 8 | 9 | with contributions by: 10 | 11 | Jim Crilly, 12 | aNa|0Gue, 13 | Robin P. Blanchard, 14 | Tom Gray, 15 | Michael Smith, 16 | Julius O. Smith, 17 | the OSALP team, http://osalp.sourceforge.net 18 | Kristjan G. Bjarnason 19 | Nicu Pavel 20 | Kai Krakow 21 | Atsuhiko Yamanaka 22 | Ricardo Galli 23 | John Hay 24 | Christian Forster 25 | John Deeny 26 | Robert Lunnon 27 | Enrico Ardizzoni 28 | Deti Fliegl 29 | Nicholas J. Humfrey 30 | Joel Ebel 31 | 32 | Alexander Vlasov 33 | Mariusz Mazur 34 | dsk 35 | Clyde Stubbs 36 | Jens Maurer 37 | Elod Horvath 38 | Pierre Souchay 39 | Daniel Hazelbaker 40 | Alessandro Beretta 41 | Roland Hermans 42 | Sergiy 43 | Clemens Ladisch 44 | Edwin van den Oetelaar 45 | Adrian Knoth 46 | Filipe Roque 47 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | DarkIce live audio streamer, http://code.google.com/p/darkice/ 2 | Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/ 3 | Copyright (c) 2008, Ákos Maróy, akos@maroy.hu 4 | Copyright (c) 2009, Rafael Diniz, rafael@riseup.net 5 | 6 | 7 | Contents 8 | -------- 9 | 10 | 1. What is DarkIce? 11 | 2. Compiling and installing 12 | 3. Reporting crashes 13 | 14 | 15 | 1. What is DarkIce? 16 | ------------------- 17 | 18 | DarkIce is an IceCast, IceCast2 and ShoutCast live audio streamer. It 19 | takes audio input from a sound card, encodes it into mp3 and/or Ogg Vorbis, 20 | and sends the mp3 stream to one or more IceCast and/or ShoutCast servers, 21 | the Ogg Vorbis stream to one or more IceCast2 servers. 22 | 23 | DarkIce website: http://code.google.com/p/darkice/ 24 | 25 | 26 | 2. Compiling and installing 27 | --------------------------- 28 | 29 | On how to compile and install, please read the file INSTALL. If you're 30 | impatient, try: 31 | 32 | ./configure 33 | make 34 | 35 | The executable built is src/darkice. 36 | To install, try as root: 37 | 38 | make install 39 | 40 | 41 | For documentation, try: 42 | 43 | man darkice 44 | 45 | 46 | 3. Reporting crashes 47 | -------------------- 48 | 49 | When DarkIce core dumps, please send the backtrace along with your error 50 | report to the darkice mailing list: http://www.freelists.org/list/darkice 51 | Alternatively you could file a bug report at http://code.google.com/p/darkice/issues/list 52 | To get the backtrace information, you need gdb, the GNU debugger: 53 | 54 | 1. configure and compile using the --with-debug option: 55 | 56 | ./configure --with-debug=yes 57 | make clean all 58 | 59 | 2. run darkice from within gdb: 60 | 61 | gdb src/darkice 62 | 63 | 3. set parameters within gdb: 64 | 65 | (gdb) set args -c darkice.cfg 66 | 67 | 4. run: 68 | 69 | (gdb) run 70 | 71 | 5. after coredump, print the backtrace: 72 | 73 | (gdb) bt 74 | 75 | 76 | -------------------------------------------------------------------------------- /INSTALL.lame: -------------------------------------------------------------------------------- 1 | Installing Lame 2 | --------------- 3 | 4 | To install DarkIce, you need the Lame 3.89 or later libraries and 5 | related header files already installed on your system. 6 | 7 | It is recommended that use install Lame to the usual system locations, 8 | /usr/lib, /usr/include, so that DarkIce will find the header files and 9 | libraries. Thus when configuring, add --prefix=/usr to the configure 10 | options. 11 | 12 | Grab the latest lame source tarball from a download site found at 13 | http://www.mp3dev.org/mp3/download/download.html 14 | or from the DarkIce SourceForge project download area 15 | http://sourceforge.net/project/showfiles.php?group_id=14111 16 | 17 | I took lame lame-3.91.tar.gz. Go to the directory where you saved it, 18 | and issue the following commands: 19 | 20 | tar xfz lame-3.91.tar.gz 21 | cd lame-3.91 22 | ./configure --with-fileio=lame --without-vorbis --disable-gtktest --enable-expopt=full --prefix=/usr 23 | make 24 | make install 25 | 26 | For the last step, you need to be root or have write permissions in the 27 | target directories. 28 | 29 | You might consider using nasm if you're on a i386 system, with the 30 | configure option --enable-nasmm, for maximum performance. 31 | 32 | 33 | On RedHat Linux 34 | --------------- 35 | 36 | Compiling Lame on RedHat Linux is a tricky issue, because of gcc 2.96 37 | packaged with the distributions 7.0 and 7.1. You either have to use 38 | the comaptibility compiler package (compat-egcs and related packages, 39 | providing gcc 2.91), or even better, gcc 3.0. 40 | 41 | It is recommended that you compile lame with gcc 3. For maximum performance, 42 | use the nasm assembler to compile assembly optimizations into lame. 43 | Try the following commands: 44 | 45 | tar xfz lame-3.91.tar.gz 46 | cd lame-3.91 47 | export CC=gcc3 48 | ./configure --with-fileio=lame --without-vorbis --disable-gtktest --enable-nasm --enable-expopt=full --prefix=/usr 49 | make 50 | make install 51 | 52 | 53 | -------------------------------------------------------------------------------- /AUTHORS~: -------------------------------------------------------------------------------- 1 | DarkIce initial author: 2 | 3 | Akos Maroy, 4 | 5 | DarkIce current maintainer: 6 | 7 | Rafael Diniz, 8 | 9 | with contributions by: 10 | 11 | Jim Crilly, 12 | aNa|0Gue, 13 | Robin P. Blanchard, 14 | Tom Gray, 15 | Michael Smith, 16 | Julius O. Smith, 17 | the OSALP team, http://osalp.sourceforge.net 18 | Kristjan G. Bjarnason 19 | Nicu Pavel 20 | Kai Krakow 21 | Atsuhiko Yamanaka 22 | Ricardo Galli 23 | John Hay 24 | Christian Forster 25 | John Deeny 26 | Robert Lunnon 27 | Enrico Ardizzoni 28 | Deti Fliegl 29 | Nicholas J. Humfrey 30 | Joel Ebel 31 | 32 | Alexander Vlasov 33 | Mariusz Mazur 34 | dsk 35 | Clyde Stubbs 36 | Jens Maurer 37 | Elod Horvath 38 | Pierre Souchay 39 | Daniel Hazelbaker 40 | Alessandro Beretta 41 | Roland Hermans 42 | Sergiy 43 | Clemens Ladisch 44 | Edwin van den Oetelaar 45 | Adrian Knoth 46 | Filipe Roque 47 | Johann Fot 48 | Alban Peignier 49 | -------------------------------------------------------------------------------- /src/Reporter.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell Reporter 6 | 7 | File : Reporter.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Reporter.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #include 33 | 34 | #include "Reporter.h" 35 | 36 | 37 | /* =================================================== local data structures */ 38 | 39 | 40 | /* ================================================ local constants & macros */ 41 | 42 | /*------------------------------------------------------------------------------ 43 | * File identity 44 | *----------------------------------------------------------------------------*/ 45 | static const char fileid[] = "$Id: Reporter.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 46 | 47 | 48 | /*------------------------------------------------------------------------------ 49 | * Initial values for static members of the class 50 | *----------------------------------------------------------------------------*/ 51 | unsigned int Reporter::verbosity = 1; 52 | std::ostream * Reporter::os = &std::cout; 53 | 54 | 55 | /* =============================================== local function prototypes */ 56 | 57 | 58 | /* ============================================================= module code */ 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = darkice 2 | AM_CXXFLAGS = -O2 -pedantic -Wall @DEBUG_CXXFLAGS@ @PTHREAD_CFLAGS@ 3 | @JACK_CFLAGS@ 4 | INCLUDES = @LAME_INCFLAGS@ @VORBIS_INCFLAGS@ @OPUS_INCFLAGS@ @FAAC_INCFLAGS@ @AACPLUS_INCFLAGS@ @TWOLAME_INCFLAGS@ \ 5 | @ALSA_INCFLAGS@ @PULSEAUDIO_INCFLAGS@ @JACK_INCFLAGS@ @SRC_INCFLAGS@ 6 | LDADD = @PTHREAD_LIBS@ @LAME_LDFLAGS@ @VORBIS_LDFLAGS@ @OPUS_LDFLAGS@ @FAAC_LDFLAGS@ @AACPLUS_LDFLAGS@ @TWOLAME_LDFLAGS@ \ 7 | @ALSA_LDFLAGS@ @PULSEAUDIO_LDFLAGS@ @JACK_LDFLAGS@ @SRC_LDFLAGS@ 8 | 9 | if HAVE_SRC_LIB 10 | AFLIB_SOURCE = 11 | else 12 | AFLIB_SOURCE = aflibDebug.h\ 13 | aflibDebug.cc\ 14 | aflibConverter.h\ 15 | aflibConverter.cc\ 16 | aflibConverterLargeFilter.h\ 17 | aflibConverterSmallFilter.h 18 | endif 19 | 20 | darkice_SOURCES = AudioEncoder.h\ 21 | AudioSource.h\ 22 | AudioSource.cpp\ 23 | BufferedSink.cpp\ 24 | BufferedSink.h\ 25 | CastSink.cpp\ 26 | CastSink.h\ 27 | FileSink.h\ 28 | FileSink.cpp\ 29 | Connector.cpp\ 30 | Connector.h\ 31 | MultiThreadedConnector.cpp\ 32 | MultiThreadedConnector.h\ 33 | DarkIce.cpp\ 34 | DarkIce.h\ 35 | Exception.cpp\ 36 | Exception.h\ 37 | IceCast2.cpp\ 38 | IceCast2.h\ 39 | LameLibEncoder.cpp\ 40 | LameLibEncoder.h\ 41 | OssDspSource.cpp\ 42 | OssDspSource.h\ 43 | SerialUlaw.cpp\ 44 | SerialUlaw.h\ 45 | SolarisDspSource.cpp\ 46 | SolarisDspSource.h\ 47 | Ref.h\ 48 | Referable.h\ 49 | Sink.h\ 50 | Source.h\ 51 | TcpSocket.cpp\ 52 | TcpSocket.h\ 53 | Util.cpp\ 54 | Util.h\ 55 | ConfigSection.h\ 56 | ConfigSection.cpp\ 57 | DarkIceConfig.h\ 58 | DarkIceConfig.cpp\ 59 | Reporter.h\ 60 | Reporter.cpp\ 61 | AlsaDspSource.h\ 62 | AlsaDspSource.cpp\ 63 | PulseAudioDspSource.h\ 64 | PulseAudioDspSource.cpp\ 65 | JackDspSource.h\ 66 | JackDspSource.cpp\ 67 | main.cpp \ 68 | $(AFLIB_SOURCE) 69 | 70 | EXTRA_darkice_SOURCES = aflibDebug.h\ 71 | aflibDebug.cc\ 72 | aflibConverter.h\ 73 | aflibConverter.cc\ 74 | aflibConverterLargeFilter.h\ 75 | aflibConverterSmallFilter.h 76 | -------------------------------------------------------------------------------- /rc.darkice: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # generic init file for darkice 3 | # 4 | # Niels Dettenbach - nd@syndicat.com - 2009-11-05 5 | # Last Change: 2010-12-21 6 | # 7 | # thanks to: 8 | # - Roland Whitehead 9 | # GPL (2009) 10 | # 0.7 11 | 12 | ## settings ## 13 | # check your paths! 14 | 15 | program=/usr/bin/darkice 16 | pidfile=/var/run/darkice.pid 17 | configfile=/etc/darkice.cfg 18 | logfile=/var/log/darkice.log 19 | progname="darkice" 20 | restart_delay=2 21 | verbose="5" 22 | 23 | ## end of settings ## 24 | 25 | RETVAL=0 26 | if [ ! -f $configfile ] 27 | then 28 | echo "$progname: config file not found" 29 | exit 30 | fi 31 | 32 | if [ ! -f $program ] 33 | then 34 | echo "$progname: programm file $program not found" 35 | exit 36 | fi 37 | 38 | case $1 in 39 | 'start') 40 | if [ -f $pidfile ]; then 41 | PID=`cat $pidfile` 42 | running=`ps --no-headers -o "%c" -p $PID` 43 | if ( [ "$progname" == "$running" ] ); then 44 | echo "$progname is still running" 45 | else 46 | echo "$progname seems crashed - PID ($PID) does not match the deamon" 47 | echo "removing stale PID File $pidfile" 48 | rm -f $pidfile 49 | $0 start 50 | exit $? 51 | fi 52 | exit 0 53 | else 54 | echo -n $"Starting $progname " 55 | RETVAL=1 56 | $program -v $verbose -c $configfile 2>%1 >> $logfile & 57 | echo 58 | RETVAL=$? 59 | if [ $RETVAL -eq 0 ]; then 60 | echo $! > $pidfile 61 | echo " started" 62 | else 63 | echo " not started" 64 | echo $RETVAL 65 | exit 0 66 | fi 67 | RETVAL=$? 68 | fi 69 | ;; 70 | 'stop') 71 | if [ -f $pidfile ]; then 72 | echo -n $"Stop $progname " 73 | PID=`cat $pidfile` 74 | kill -s TERM $PID 2> /dev/null 75 | echo 76 | sleep $restart_delay 77 | rm -f $pidfile 78 | echo " stopped" 79 | else 80 | echo "$progname not running" 81 | fi 82 | RETVAL=$? 83 | ;; 84 | 'status') 85 | if [ -f $pidfile ]; then 86 | PID=`cat $pidfile` 87 | running=`ps --no-headers -o "%c" -p $PID` 88 | if ( [ "$progname" == "$running" ] ); then 89 | echo "$progname IS running with PID `cat $pidfile`." 90 | else 91 | echo "$progname process is dead or stale PID File $pidfile" 92 | exit 0 93 | fi 94 | else 95 | echo "$progname is not running" 96 | exit 0 97 | fi 98 | ;; 99 | 'restart') 100 | $0 stop 101 | $0 start 102 | RETVAL=$? 103 | ;; 104 | 105 | 'restartifdown') 106 | if [ -f $pidfile ]; then 107 | PID=`cat $pidfile` 108 | running=`ps --no-headers -o "%c" -p $PID` 109 | if ( [ "$progname" == "$running" ] ); then 110 | echo "$progname IS running with PID `cat $pidfile` - no restart." 111 | else 112 | echo "$progname PID $PID seems dead - restart" 113 | $0 stop 114 | $0 start 115 | RETVAL=$? 116 | fi 117 | else 118 | echo "PID file $pidfile found - restart" 119 | $0 stop 120 | $0 start 121 | RETVAL=$? 122 | fi 123 | ;; 124 | 125 | *) 126 | echo "Usage: $0 {start|stop|restart|status|restartifdown} " 127 | exit 1; 128 | ;; 129 | esac 130 | 131 | exit $RETVAL 132 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 14-11-2009, Rafael Diniz, rafael@riseup.net 2 | 3 | Released version 0.20.1. See ChangeLog for changes. 4 | 5 | 05-11-2009, Rafael Diniz, rafael@riseup.net 6 | 7 | Released version 0.20. See ChangeLog for changes. 8 | 9 | 07-07-2008, Akos Maroy, darkeye@tyrell.hu 10 | 11 | Released version 0.19. See ChangeLog for changes. 12 | 13 | 26-04-2007, Akos Maroy, darkeye@tyrell.hu 14 | 15 | Released version 0.18.1. See ChangeLog for changes. 16 | 17 | 05-03-2007, Akos Maroy, darkeye@users.sourceforge.net 18 | 19 | Released version 0.18. See ChangeLog for changes. 20 | 21 | 22 | 19-05-2006, Akos Maroy, darkeye@users.sourceforge.net 23 | 24 | Released version 0.17.1. See ChangeLog for changes. 25 | 26 | 27 | 26-01-2006, Akos Maroy, darkeye@users.sourceforge.net 28 | 29 | Released version 0.17. See ChangeLog for changes. 30 | 31 | 32 | 22-10-2005, Akos Maroy, darkeye@users.sourceforge.net 33 | 34 | Released version 0.16. See ChangeLog for changes. 35 | 36 | 37 | 14-04-2005, Akos Maroy, darkeye@users.sourceforge.net 38 | 39 | Released version 0.15. See ChangeLog for changes. 40 | 41 | 42 | 15-02-2004, Akos Maroy, darkeye@users.sourceforge.net 43 | 44 | Released version 0.14. See ChangeLog for changes. 45 | 46 | 47 | 07-01-2004, Akos Maroy, darkeye@users.sourceforge.net 48 | 49 | Released version 0.13.2. See ChangeLog for changes. 50 | 51 | 52 | 12-02-2003, Akos Maroy, darkeye@users.sourceforge.net 53 | 54 | Released version 0.13.1. See ChangeLog for changes. 55 | 56 | 57 | 09-02-2003, Akos Maroy, darkeye@users.sourceforge.net 58 | 59 | Released version 0.13. See ChangeLog for changes. 60 | 61 | 62 | 20-10-2002, Akos Maroy, darkeye@users.sourceforge.net 63 | 64 | Released version 0.12. See ChangeLog for changes. 65 | 66 | 67 | 20-08-2002, Akos Maroy, darkeye@users.sourceforge.net 68 | 69 | Released version 0.11. See ChangeLog for changes. 70 | 71 | 72 | 02-08-2002, Akos Maroy, darkeye@users.sourceforge.net 73 | 74 | Released version 0.10.1. See ChangeLog for changes. 75 | 76 | 77 | 20-07-2002, Akos Maroy, darkeye@users.sourceforge.net 78 | 79 | Released version 0.10. See ChangeLog for changes. 80 | 81 | 82 | 09-04-2002, Akos Maroy, darkeye@users.sourceforge.net 83 | 84 | Released version 0.9.1. See ChangeLog for changes. 85 | 86 | 87 | 28-03-2002, Akos Maroy, darkeye@users.sourceforge.net 88 | 89 | Released version 0.9. See ChangeLog for changes. 90 | 91 | 92 | 20-02-2002, Akos Maroy, darkeye@users.sourceforge.net 93 | 94 | Released version 0.8. See ChangeLog for changes. 95 | 96 | 97 | 19-10-2001, Akos Maroy, darkeye@users.sourceforge.net 98 | 99 | Released version 0.7. See ChangeLog for changes. 100 | 101 | 102 | 18-09-2001, Akos Maroy, darkeye@users.sourceforge.net 103 | 104 | Released version 0.6. See ChangeLog for changes. 105 | 106 | 107 | 09-09-2001, Akos Maroy, darkeye@users.sourceforge.net 108 | 109 | Released version 0.5. See ChangeLog for changes. 110 | 111 | 112 | 02-09-2001, Akos Maroy, darkeye@users.sourceforge.net 113 | 114 | Released version 0.4. See ChangeLog for changes. 115 | 116 | 117 | 26-08-2001, Akos Maroy, darkeye@users.sourceforge.net 118 | 119 | Released version 0.3.1. See ChangeLog for changes. 120 | 121 | 122 | 20-12-2000, Akos Maroy, darkeye@users.sourceforge.net 123 | 124 | Released version 0.3. See ChangeLog for changes. 125 | 126 | 127 | 18-11-2000, Akos Maroy, darkeye@users.sourceforge.net 128 | 129 | Released version 0.2. See ChangeLog for changes. 130 | 131 | 132 | 13-11-2000, Akos Maroy, darkeye@users.sourceforge.net 133 | 134 | Initial release. Supports the lame encoder. 135 | 136 | 137 | -------------------------------------------------------------------------------- /src/aflibDebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2000 Stefan Westerfeld 4 | stefan@space.twc.de 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public 8 | License as published by the Free Software Foundation; either 9 | version 2 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public License 17 | along with this library; see the file COPYING.LIB. If not, write to 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. 20 | 21 | 22 | Some inspiration taken from glib. 23 | Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 24 | Modified by the GLib Team and others 1997-1999. 25 | 26 | */ 27 | 28 | #ifndef _AFLIBDEBUG_H_ 29 | #define _AFLIBDEBUG_H_ 30 | 31 | /* 32 | * BC - Status (2000-09-30): Debug. 33 | * 34 | * Collection class, no instance, no members. Thus binary compatible (will 35 | * be kept). 36 | */ 37 | 38 | #define aflib_fatal ::aflibDebug::fatal 39 | #define aflib_warning ::aflibDebug::warning 40 | #define aflib_info ::aflibDebug::info 41 | #define aflib_debug ::aflibDebug::debug 42 | 43 | /* source compatibility with older sources */ 44 | #define aflibdebug ::aflibDebug::debug 45 | #define setaflibdebug(x) aflib_warning("setaflibdebug is obsolete") 46 | 47 | #ifdef __GNUC__ 48 | 49 | #define aflib_return_if_fail(expr) \ 50 | if (!(expr)) \ 51 | { \ 52 | aflib_warning ("file %s: line %d (%s): assertion failed: (%s)", \ 53 | __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \ 54 | return; \ 55 | } 56 | 57 | #define aflib_return_val_if_fail(expr,val) \ 58 | if (!(expr)) \ 59 | { \ 60 | aflib_warning ("file %s: line %d (%s): assertion failed: (%s)", \ 61 | __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \ 62 | return (val); \ 63 | } 64 | 65 | #define aflib_assert(expr) \ 66 | if (!(expr)) \ 67 | aflib_fatal ("file %s: line %d (%s): assertion failed: (%s)", \ 68 | __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \ 69 | 70 | #else 71 | 72 | #define aflib_return_if_fail(expr) \ 73 | if (!(expr)) \ 74 | { \ 75 | aflib_warning ("file %s: line %d: assertion failed: (%s)", \ 76 | __FILE__, __LINE__, #expr); \ 77 | return; \ 78 | } 79 | 80 | #define aflib_return_val_if_fail(expr,val) \ 81 | if (!(expr)) \ 82 | { \ 83 | aflib_warning ("file %s: line %d: assertion failed: (%s)", \ 84 | __FILE__, __LINE__, #expr); \ 85 | return (val); \ 86 | } 87 | 88 | #define aflib_assert(expr) \ 89 | if (!(expr)) \ 90 | aflib_fatal ("file %s: line %d: assertion failed: (%s)", \ 91 | __FILE__, __LINE__, #expr); \ 92 | 93 | #endif 94 | 95 | class aflibDebug { 96 | public: 97 | enum Level { lFatal = 3, lWarning = 2, lInfo = 1, lDebug = 0 }; 98 | 99 | /** 100 | * Initializes at which is the minimum level to react to. If you 101 | * call this, call this before creating the Arts::Dispatcher object. 102 | */ 103 | static void init(const char *prefix, Level level); 104 | 105 | static void fatal(const char *fmt,...); // print on stderr & abort 106 | static void warning(const char *fmt,...); // print on stderr 107 | static void info(const char *fmt,...); // print on stdout 108 | static void debug(const char *fmt,...); // print on stdout 109 | 110 | /** 111 | * This method sets the name of an external application to 112 | * display messages graphically. 113 | */ 114 | static void messageApp(const char *appName); 115 | 116 | }; 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /darkice.cfg: -------------------------------------------------------------------------------- 1 | # sample DarkIce configuration file, edit for your needs before using 2 | # see the darkice.cfg man page for details 3 | 4 | # this section describes general aspects of the live streaming session 5 | [general] 6 | duration = 60 # duration of encoding, in seconds. 0 means forever 7 | bufferSecs = 5 # size of internal slip buffer, in seconds 8 | reconnect = yes # reconnect to the server(s) if disconnected 9 | realtime = yes # run the encoder with POSIX realtime priority 10 | rtprio = 3 # scheduling priority for the realtime threads 11 | 12 | # this section describes the audio input that will be streamed 13 | [input] 14 | device = /dev/dsp # OSS DSP soundcard device for the audio input 15 | sampleRate = 22050 # sample rate in Hz. try 11025, 22050 or 44100 16 | bitsPerSample = 16 # bits per sample. try 16 17 | channel = 2 # channels. 1 = mono, 2 = stereo 18 | 19 | # this section describes a streaming connection to an IceCast2 server 20 | # there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7] 21 | # these can be mixed with [icecast-x] and [shoutcast-x] sections 22 | [icecast2-0] 23 | bitrateMode = abr # average bit rate 24 | format = vorbis # format of the stream: ogg vorbis 25 | bitrate = 96 # bitrate of the stream sent to the server 26 | server = yp.yourserver.com 27 | # host name of the server 28 | port = 8000 # port of the IceCast2 server, usually 8000 29 | password = hackme # source password to the IceCast2 server 30 | mountPoint = sample96 # mount point of this stream on the IceCast2 server 31 | name = DarkIce trial 32 | # name of the stream 33 | description = This is only a trial 34 | # description of the stream 35 | url = http://www.yourserver.com 36 | # URL related to the stream 37 | genre = my own # genre of the stream 38 | public = yes # advertise this stream? 39 | localDumpFile = dump.ogg # local dump file 40 | 41 | # this section describes a streaming connection to an IceCast server 42 | # there may be up to 8 of these sections, named [icecast-0] ... [icecast-7] 43 | # these can be mixed with [icecast2-x] and [shoutcast-x] sections 44 | [icecast-0] 45 | bitrateMode = cbr # constant bit rate 46 | bitrate = 96 # bitrate of the mp3 stream sent to the server 47 | quality = 0.8 # encoding quality 48 | server = yp.yourserver.com 49 | # host name of the server 50 | port = 8000 # port of the IceCast server, usually 8000 51 | password = hackme # source password to the IceCast server 52 | mountPoint = sample96 # mount point of this stream on the IceCast server 53 | name = DarkIce trial 54 | # name of the stream 55 | description = This is only a trial 56 | # description of the stream 57 | url = http://www.yourserver.com 58 | # URL related to the stream 59 | genre = my own # genre of the stream 60 | public = yes # advertise this stream? 61 | 62 | # this section describes a streaming connection to a ShoutCast server 63 | # there may be up to 8 of these sections, named [shoutcast-0] ... [shoutcast-7] 64 | # these can be mixed with [icecast-x] and [icecast2-x] sections 65 | [shoutcast-0] 66 | bitrateMode = vbr # variable bit rate mode 67 | quality = 0.5 # encoding quality 68 | server = yp.yourserver.com 69 | # host name of the server 70 | port = 8001 # source port of the ShoutCast server, usually 8001 71 | password = hackme # source password to the ShoutCast server 72 | name = DarkIce trial 73 | # name of the stream 74 | url = http://www.yourserver.com 75 | # URL related to the stream 76 | genre = my own # genre of the stream 77 | public = yes # advertise this stream? 78 | irc = irc.yourserver.com 79 | # IRC info related to the stream 80 | aim = aim here # AIM info related to the stream 81 | icq = I see you too 82 | # ICQ info related to the stream 83 | 84 | 85 | -------------------------------------------------------------------------------- /man/darkice.1: -------------------------------------------------------------------------------- 1 | .TH darkice 1 "November 20, 2007" "DarkIce" "DarkIce live audio streamer" 2 | .SH NAME 3 | darkice \- an icecast / shoutcast live audio streamer 4 | .SH SYNOPSIS 5 | .B darkice 6 | [options] -c config.file 7 | .SH DESCRIPTION 8 | .PP 9 | DarkIce as a live audio streamer. It records audio from an audio interface (e.g. sound card), encodes it and sends it to a streaming server. 10 | DarkIce can record from: 11 | 12 | * OSS audio devices 13 | * ALSA audio devices 14 | * Solaris audio interface 15 | * Jack sources 16 | * PulseAudio sources 17 | 18 | DarkIce can encode in the following formats: 19 | 20 | * mp3 - using the lame library 21 | * mp2 - using the twolame library 22 | * Ogg Vorbis 23 | * Ogg Opus 24 | * AAC - using the faac library 25 | * AAC HEv2 - using the libaacplus (3GPP reference code) 26 | 27 | DarkIce can send the encoded stream to the following streaming servers: 28 | 29 | * ShoutCast 30 | * IceCast 1.3.x and 2.x 31 | * Darwin Streaming Server 32 | 33 | Darkice runs on the following operating systems: 34 | 35 | * FreeBSD 36 | * Linux on intel and PowerPC 37 | * MacOS X 38 | * NetBSD / OpenBSD 39 | * SUN Solaris 40 | 41 | .B DarkIce 42 | uses 43 | .SM POSIX 44 | real-time scheduling to keep up with sound card input. 45 | .SM POSIX 46 | real-time scheduling is only available if the program is run as root. 47 | Therefore it is recommended that 48 | .B DarkIce 49 | is run as root. 50 | 51 | .SH OPTIONS 52 | .TP 53 | .BI "\-c " config.file 54 | Specifies what configuration file to use. 55 | If not specified, /etc/darkice.cfg will be used. 56 | 57 | .TP 58 | .BI "\-v " n 59 | Sets the verbosity level, between 0 and 10. 0 is silent, 10 is loud. 60 | Defaults to 1. 61 | 62 | .TP 63 | .BI "\-h " 64 | Prints the help page and exits. 65 | 66 | 67 | .SH BUGS 68 | .PP 69 | Lots of bugs. 70 | 71 | 72 | .SH "SEE ALSO" 73 | darkice.cfg(5) 74 | 75 | 76 | .SH AUTHOR 77 | Akos Maroy 78 | .I 79 | 80 | 81 | .SH ACKNOWLEDGEMENTS 82 | Developed with contributions by 83 | 84 | Jim Crilly, 85 | aNa|0Gue, 86 | Robin P. Blanchard, 87 | Tom Gray, 88 | Michael Smith, 89 | Julius O. Smith, 90 | the OSALP team, http://osalp.sourceforge.net 91 | Kristjan G. Bjarnason 92 | Nicu Pavel 93 | Kai Krakow 94 | Atsuhiko Yamanaka 95 | Ricardo Galli 96 | John Hay 97 | Christian Forster 98 | John Deeny 99 | Robert Lunnon 100 | Enrico Ardizzoni 101 | Deti Fliegl 102 | Nicholas J. Humfrey 103 | Joel Ebel 104 | 105 | Alexander Vlasov 106 | Mariusz Mazur 107 | dsk 108 | Clyde Stubbs 109 | Jens Maurer 110 | Elod Horvath 111 | Pierre Souchay 112 | Daniel Hazelbaker 113 | Alessandro Beretta 114 | Roland Hermans 115 | Rafael Diniz 116 | 117 | .SH LINKS 118 | Project homepage: 119 | .I http://code.google.com/p/darkice/ 120 | 121 | .B IceCast 122 | homepage: 123 | .I http://www.icecast.org/ 124 | 125 | .B ShoutCast 126 | homepage: 127 | .I http://www.shoutcast.com/ 128 | 129 | .B Darwin Streaming Server 130 | homepage: 131 | .I http://developer.apple.com/darwin/projects/streaming/ 132 | 133 | .B Lame 134 | homepage: 135 | .I http://www.mp3dev.org/mp3/ 136 | 137 | .B TwoLame 138 | homepage: 139 | .I http://www.twolame.org/ 140 | 141 | .B Ogg Vorbis 142 | homepage: 143 | .I http://www.xiph.org/ogg/vorbis/ 144 | 145 | .B Ogg Opus 146 | homepage 147 | .I http://www.opus-codec.org/ 148 | 149 | .B faac 150 | homepage: 151 | .I http://www.audiocoding.com/ 152 | 153 | .B libaacplus 154 | homepage: 155 | .I http://tipok.org.ua/node/17 156 | 157 | .B DarkSnow 158 | GTK front-end: 159 | .I http://darksnow.radiolivre.org/index.en.html 160 | written by Rafael Diniz 161 | -------------------------------------------------------------------------------- /src/CastSink.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : CastSink.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/CastSink.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #include "Util.h" 33 | #include "Exception.h" 34 | #include "CastSink.h" 35 | 36 | 37 | /* =================================================== local data structures */ 38 | 39 | 40 | /* ================================================ local constants & macros */ 41 | 42 | /*------------------------------------------------------------------------------ 43 | * File identity 44 | *----------------------------------------------------------------------------*/ 45 | static const char fileid[] = "$Id: CastSink.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 46 | 47 | 48 | /* =============================================== local function prototypes */ 49 | 50 | 51 | /* ============================================================= module code */ 52 | 53 | /*------------------------------------------------------------------------------ 54 | * Initialize the object 55 | *----------------------------------------------------------------------------*/ 56 | void 57 | CastSink :: init ( TcpSocket * socket, 58 | Sink * streamDump, 59 | const char * password, 60 | unsigned int bitRate, 61 | const char * name, 62 | const char * url, 63 | const char * genre, 64 | bool isPublic ) 65 | throw ( Exception ) 66 | { 67 | this->socket = socket; 68 | this->streamDump = streamDump; 69 | this->password = password ? Util::strDup( password) : 0; 70 | this->bitRate = bitRate; 71 | this->name = name ? Util::strDup( name) : 0; 72 | this->url = url ? Util::strDup( url) : 0; 73 | this->genre = genre ? Util::strDup( genre) : 0; 74 | this->isPublic = isPublic; 75 | } 76 | 77 | 78 | /*------------------------------------------------------------------------------ 79 | * De-initialize the object 80 | *----------------------------------------------------------------------------*/ 81 | void 82 | CastSink :: strip ( void ) throw ( Exception ) 83 | { 84 | if ( isOpen() ) { 85 | close(); 86 | } 87 | 88 | if ( password ) { 89 | delete[] password; 90 | } 91 | if ( name ) { 92 | delete[] name; 93 | } 94 | if ( url ) { 95 | delete[] url; 96 | } 97 | if ( genre ) { 98 | delete[] genre; 99 | } 100 | } 101 | 102 | 103 | /*------------------------------------------------------------------------------ 104 | * Open the connection 105 | *----------------------------------------------------------------------------*/ 106 | bool 107 | CastSink :: open ( void ) throw ( Exception ) 108 | { 109 | if ( isOpen() ) { 110 | return false; 111 | } 112 | 113 | if ( !getSink()->open() ) { 114 | return false; 115 | } 116 | 117 | if ( !sendLogin() ) { 118 | close(); 119 | return false; 120 | } 121 | 122 | if ( streamDump != 0 ) { 123 | if ( !streamDump->isOpen() ) { 124 | if ( !streamDump->open() ) { 125 | reportEvent( 2, "can't open stream dump"); 126 | } 127 | } 128 | } 129 | 130 | return true; 131 | } 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/Referable.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : Referable.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Referable.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef REFERABLE_H 30 | #define REFERABLE_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Exception.h" 40 | 41 | 42 | /* ================================================================ constants */ 43 | 44 | 45 | /* =================================================================== macros */ 46 | 47 | 48 | /* =============================================================== data types */ 49 | 50 | /** 51 | * Base class for an object for which references can be made 52 | * with the reference class Ref. 53 | * 54 | * usage: 55 | * 56 | *
 57 |  *  class A : public virtual Referable
 58 |  *  {
 59 |  *     ...
 60 |  *  };
 61 |  *  
62 | * 63 | * @ref Ref 64 | * 65 | * @author $Author: rafael@riseup.net $ 66 | * @version $Revision: 553 $ 67 | */ 68 | class Referable 69 | { 70 | private: 71 | 72 | /** 73 | * Number of references to the object. 74 | */ 75 | unsigned int referenceCount; 76 | 77 | /** 78 | * Maximum number of references before an overflow occurs. 79 | */ 80 | static const 81 | unsigned int maxCount = ~((unsigned int)0); 82 | 83 | 84 | protected: 85 | 86 | /** 87 | * Default constructor. 88 | */ 89 | inline 90 | Referable ( void ) throw () 91 | { 92 | referenceCount = 0; 93 | } 94 | 95 | 96 | /** 97 | * Desctructor. 98 | * 99 | * @exception Exception 100 | */ 101 | inline virtual 102 | ~Referable ( void ) throw ( Exception ) 103 | { 104 | if ( referenceCount > 0 ) { 105 | throw Exception( __FILE__, __LINE__, 106 | "reference count positive in destructor", 107 | referenceCount); 108 | } 109 | } 110 | 111 | 112 | public: 113 | 114 | /** 115 | * Increase reference count. 116 | * 117 | * @return the new reference count. 118 | * @exception Exception 119 | */ 120 | inline unsigned int 121 | increaseReferenceCount ( void ) throw ( Exception ) 122 | { 123 | if ( referenceCount >= maxCount ) { 124 | throw Exception( __FILE__, 125 | __LINE__, 126 | "reference count overflow", 127 | referenceCount ); 128 | } 129 | return ++referenceCount; 130 | } 131 | 132 | /** 133 | * Decrease reference count. 134 | * 135 | * @return the new reference count. 136 | * @exception Exception 137 | */ 138 | inline unsigned int 139 | decreaseReferenceCount ( void ) throw ( Exception ) 140 | { 141 | if ( referenceCount == 0 ) { 142 | throw Exception( __FILE__, __LINE__, 143 | "reference count underflow", 144 | referenceCount ); 145 | } 146 | return --referenceCount; 147 | } 148 | 149 | /** 150 | * Get the reference count. 151 | * 152 | * @return the reference count. 153 | */ 154 | inline unsigned int 155 | getReferenceCount ( void ) const throw () 156 | { 157 | return referenceCount; 158 | } 159 | }; 160 | 161 | 162 | /* ================================================= external data structures */ 163 | 164 | 165 | /* ====================================================== function prototypes */ 166 | 167 | 168 | 169 | #endif /* REFERABLE_H */ 170 | 171 | -------------------------------------------------------------------------------- /src/Source.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : Source.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Source.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef SOURCE_H 30 | #define SOURCE_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Referable.h" 40 | #include "Exception.h" 41 | 42 | 43 | /* ================================================================ constants */ 44 | 45 | 46 | /* =================================================================== macros */ 47 | 48 | 49 | /* =============================================================== data types */ 50 | 51 | /** 52 | * A general data source 53 | * 54 | * @author $Author: rafael@riseup.net $ 55 | * @version $Revision: 553 $ 56 | */ 57 | class Source : public virtual Referable 58 | { 59 | private: 60 | 61 | protected: 62 | 63 | /** 64 | * Default Constructor. 65 | * 66 | * @exception Exception 67 | */ 68 | inline 69 | Source ( void ) throw ( Exception ) 70 | { 71 | } 72 | 73 | /** 74 | * Copy Constructor. 75 | * 76 | * @param source the object to copy. 77 | * @exception Exception 78 | */ 79 | inline 80 | Source ( const Source & source ) throw ( Exception ) 81 | { 82 | } 83 | 84 | /** 85 | * Assignment operator. 86 | * 87 | * @param source the object to assign to this one. 88 | * @return a reference to this object. 89 | * @exception Exception 90 | */ 91 | inline virtual Source & 92 | operator= ( const Source & source ) throw ( Exception ) 93 | { 94 | return *this; 95 | } 96 | 97 | 98 | public: 99 | 100 | /** 101 | * Destructor. 102 | * 103 | * @exception Exception 104 | */ 105 | inline virtual 106 | ~Source ( void ) throw ( Exception ) 107 | { 108 | } 109 | 110 | /** 111 | * Open the Source. 112 | * 113 | * @return true if opening was successful, false otherwise 114 | * @exception Exception 115 | */ 116 | virtual bool 117 | open ( void ) throw ( Exception ) = 0; 118 | 119 | /** 120 | * Check if the Source is open. 121 | * 122 | * @return true if the Source is open, false otherwise. 123 | */ 124 | virtual bool 125 | isOpen ( void ) const throw () = 0; 126 | 127 | /** 128 | * Check if the Source can be read from. 129 | * Blocks until the specified time for data to be available. 130 | * 131 | * @param sec the maximum seconds to block. 132 | * @param usec micro seconds to block after the full seconds. 133 | * @return true if the Source is ready to be read from, 134 | * false otherwise. 135 | * @exception Exception 136 | */ 137 | virtual bool 138 | canRead ( unsigned int sec, 139 | unsigned int usec ) throw ( Exception ) = 0; 140 | 141 | /** 142 | * Read from the Source. 143 | * 144 | * @param buf the buffer to read into. 145 | * @param len the number of bytes to read into buf 146 | * @return the number of bytes read (may be less than len). 147 | * @exception Exception 148 | */ 149 | virtual unsigned int 150 | read ( void * buf, 151 | unsigned int len ) throw ( Exception ) = 0; 152 | 153 | /** 154 | * Close the Source. 155 | * 156 | * @exception Exception 157 | */ 158 | virtual void 159 | close ( void ) throw ( Exception ) = 0; 160 | }; 161 | 162 | 163 | /* ================================================= external data structures */ 164 | 165 | 166 | /* ====================================================== function prototypes */ 167 | 168 | 169 | 170 | #endif /* SOURCE_H */ 171 | 172 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | /* src/config.h.in. Generated from configure.in by autoheader. */ 2 | 3 | /* Define if building universal (internal helper macro) */ 4 | #undef AC_APPLE_UNIVERSAL_BUILD 5 | 6 | /* build with aacplus library */ 7 | #undef HAVE_AACPLUS_LIB 8 | 9 | /* build with ALSA sound system */ 10 | #undef HAVE_ALSA_LIB 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_ERRNO_H 14 | 15 | /* build with faac library */ 16 | #undef HAVE_FAAC_LIB 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_FCNTL_H 20 | 21 | /* Does function getaddrinfo exist? */ 22 | #undef HAVE_GETADDRINFO 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_INTTYPES_H 26 | 27 | /* build with JACK audio server support */ 28 | #undef HAVE_JACK_LIB 29 | 30 | /* build with lame library */ 31 | #undef HAVE_LAME_LIB 32 | 33 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 34 | #undef HAVE_LIBNSL 35 | 36 | /* Define to 1 if you have the `rt' library (-lrt). */ 37 | #undef HAVE_LIBRT 38 | 39 | /* Define to 1 if you have the `socket' library (-lsocket). */ 40 | #undef HAVE_LIBSOCKET 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_LIMITS_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_MATH_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_MEMORY_H 50 | 51 | /* use MSG_NOSIGNAL for send() */ 52 | #undef HAVE_MSG_NOSIGNAL 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_NETDB_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_NETINET_IN_H 59 | 60 | /* build with Ogg Opus library */ 61 | #undef HAVE_OPUS_LIB 62 | 63 | /* Define if you have POSIX threads libraries and header files. */ 64 | #undef HAVE_PTHREAD 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_PTHREAD_H 68 | 69 | /* build with PULSEAUDIO sound system */ 70 | #undef HAVE_PULSEAUDIO_LIB 71 | 72 | /* Define to 1 if you have the `sched_getparam' function. */ 73 | #undef HAVE_SCHED_GETPARAM 74 | 75 | /* Define to 1 if you have the `sched_getscheduler' function. */ 76 | #undef HAVE_SCHED_GETSCHEDULER 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_SCHED_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_SIGNAL_H 83 | 84 | /* build with samplerate conversion through libsamplerate */ 85 | #undef HAVE_SRC_LIB 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #undef HAVE_STDINT_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #undef HAVE_STDIO_H 92 | 93 | /* Define to 1 if you have the header file. */ 94 | #undef HAVE_STDLIB_H 95 | 96 | /* Define to 1 if you have the header file. */ 97 | #undef HAVE_STRINGS_H 98 | 99 | /* Define to 1 if you have the header file. */ 100 | #undef HAVE_STRING_H 101 | 102 | /* Define to 1 if you have the header file. */ 103 | #undef HAVE_SYS_AUDIOIO_H 104 | 105 | /* Define to 1 if you have the header file. */ 106 | #undef HAVE_SYS_AUDIO_H 107 | 108 | /* Define to 1 if you have the header file. */ 109 | #undef HAVE_SYS_IOCTL_H 110 | 111 | /* Define to 1 if you have the header file. */ 112 | #undef HAVE_SYS_SOCKET_H 113 | 114 | /* Define to 1 if you have the header file. */ 115 | #undef HAVE_SYS_SOUNDCARD_H 116 | 117 | /* Define to 1 if you have the header file. */ 118 | #undef HAVE_SYS_STAT_H 119 | 120 | /* Define to 1 if you have the header file. */ 121 | #undef HAVE_SYS_TIME_H 122 | 123 | /* Define to 1 if you have the header file. */ 124 | #undef HAVE_SYS_TYPES_H 125 | 126 | /* Define to 1 if you have that is POSIX.1 compatible. */ 127 | #undef HAVE_SYS_WAIT_H 128 | 129 | /* Define to 1 if you have the header file. */ 130 | #undef HAVE_TERMIOS_H 131 | 132 | /* Define to 1 if you have the header file. */ 133 | #undef HAVE_TIME_H 134 | 135 | /* build with twolame library */ 136 | #undef HAVE_TWOLAME_LIB 137 | 138 | /* Define to 1 if you have the header file. */ 139 | #undef HAVE_UNISTD_H 140 | 141 | /* build with Ogg Vorbis library */ 142 | #undef HAVE_VORBIS_LIB 143 | 144 | /* Name of package */ 145 | #undef PACKAGE 146 | 147 | /* Define to the address where bug reports for this package should be sent. */ 148 | #undef PACKAGE_BUGREPORT 149 | 150 | /* Define to the full name of this package. */ 151 | #undef PACKAGE_NAME 152 | 153 | /* Define to the full name and version of this package. */ 154 | #undef PACKAGE_STRING 155 | 156 | /* Define to the one symbol short name of this package. */ 157 | #undef PACKAGE_TARNAME 158 | 159 | /* Define to the home page for this package. */ 160 | #undef PACKAGE_URL 161 | 162 | /* Define to the version of this package. */ 163 | #undef PACKAGE_VERSION 164 | 165 | /* Define to the necessary symbol if this constant uses a non-standard name on 166 | your system. */ 167 | #undef PTHREAD_CREATE_JOINABLE 168 | 169 | /* Define to 1 if you have the ANSI C header files. */ 170 | #undef STDC_HEADERS 171 | 172 | /* Version number of package */ 173 | #undef VERSION 174 | 175 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 176 | significant byte first (like Motorola and SPARC, unlike Intel). */ 177 | #if defined AC_APPLE_UNIVERSAL_BUILD 178 | # if defined __BIG_ENDIAN__ 179 | # define WORDS_BIGENDIAN 1 180 | # endif 181 | #else 182 | # ifndef WORDS_BIGENDIAN 183 | # undef WORDS_BIGENDIAN 184 | # endif 185 | #endif 186 | 187 | /* Define to `int' if does not define. */ 188 | #undef pid_t 189 | 190 | /* Define to `unsigned int' if does not define. */ 191 | #undef size_t 192 | -------------------------------------------------------------------------------- /src/DarkIceConfig.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell Config 6 | 7 | File : DarkIceConfig.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/DarkIceConfig.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include "config.h" 34 | #endif 35 | 36 | #include 37 | 38 | #include 39 | 40 | 41 | #include "DarkIceConfig.h" 42 | 43 | 44 | /* =================================================== local data structures */ 45 | 46 | 47 | /* ================================================ local constants & macros */ 48 | 49 | /*------------------------------------------------------------------------------ 50 | * File identity 51 | *----------------------------------------------------------------------------*/ 52 | static const char fileid[] = "$Id: DarkIceConfig.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 53 | 54 | 55 | /*------------------------------------------------------------------------------ 56 | * Max line size 57 | *----------------------------------------------------------------------------*/ 58 | #define LINE_SIZE 256 59 | 60 | 61 | /*------------------------------------------------------------------------------ 62 | * string containing all white space characters 63 | *----------------------------------------------------------------------------*/ 64 | #define WHITE_SPACE_STR " \t" 65 | 66 | 67 | /* =============================================== local function prototypes */ 68 | 69 | 70 | /* ============================================================= module code */ 71 | 72 | /*------------------------------------------------------------------------------ 73 | * Get a value for a key 74 | *----------------------------------------------------------------------------*/ 75 | const ConfigSection * 76 | Config :: get ( const char * key ) const throw ( Exception ) 77 | { 78 | if ( !key ) { 79 | throw Exception( __FILE__, __LINE__, "no key"); 80 | } 81 | 82 | TableType::const_iterator it = table.find( key); 83 | if ( it == table.end() ) { 84 | return 0; 85 | } 86 | return &(it->second); 87 | } 88 | 89 | 90 | /*------------------------------------------------------------------------------ 91 | * Add a configuration line 92 | *----------------------------------------------------------------------------*/ 93 | bool 94 | Config :: addLine ( const char * line ) throw ( Exception ) 95 | { 96 | if ( !line ) { 97 | throw Exception( __FILE__, __LINE__, "no line"); 98 | } 99 | 100 | std::string::size_type ix; 101 | std::string str( line); 102 | 103 | /* delete everything after the first # */ 104 | if ( (ix = str.find( '#')) != str.npos ) { 105 | str.erase( ix); 106 | } 107 | /* eat up all white space from the front */ 108 | if ( (ix = str.find_first_not_of( WHITE_SPACE_STR)) != str.npos ) { 109 | str.erase( 0, ix); 110 | } 111 | /* eat up all white space from the end */ 112 | if ( (ix = str.find_last_not_of( WHITE_SPACE_STR)) != str.npos ) { 113 | str.erase( ix + 1); 114 | } 115 | 116 | if ( !str.length() ) { 117 | return true; 118 | } 119 | if ( str[0] == '[' && str[str.size()-1] == ']' ) { 120 | // a new section starts 121 | 122 | std::string section( str, 1, str.size()-2); 123 | ConfigSection cSection; 124 | std::pair 125 | element( section, cSection); 126 | std::pair res; 127 | 128 | res = table.insert( element); 129 | 130 | currentSection = section; 131 | return res.second; 132 | } else { 133 | // it's a line for the current section 134 | 135 | TableType::iterator it = table.find( currentSection); 136 | if ( it == table.end() ) { 137 | throw Exception( __FILE__, __LINE__, "no current section"); 138 | } 139 | 140 | return it->second.addLine( line); 141 | } 142 | } 143 | 144 | 145 | /*------------------------------------------------------------------------------ 146 | * Add a configuration line 147 | *----------------------------------------------------------------------------*/ 148 | void 149 | Config :: read ( std::istream & is ) throw ( Exception ) 150 | { 151 | char line[LINE_SIZE]; 152 | unsigned int num; 153 | 154 | for ( num = 0; !is.fail() && !is.eof(); ++num ) { 155 | is.getline( line, LINE_SIZE); 156 | if ( is.eof() ) { 157 | break; 158 | } else if ( is.fail() ) { 159 | throw Exception( __FILE__, __LINE__, "line too long", num); 160 | } 161 | 162 | addLine( line); 163 | } 164 | } 165 | 166 | 167 | -------------------------------------------------------------------------------- /src/Sink.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : Sink.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Sink.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef SINK_H 30 | #define SINK_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Referable.h" 40 | #include "Exception.h" 41 | 42 | 43 | /* ================================================================ constants */ 44 | 45 | 46 | /* =================================================================== macros */ 47 | 48 | 49 | /* =============================================================== data types */ 50 | 51 | /** 52 | * A general data sink 53 | * 54 | * @author $Author: rafael@riseup.net $ 55 | * @version $Revision: 553 $ 56 | */ 57 | class Sink : public virtual Referable 58 | { 59 | private: 60 | 61 | 62 | protected: 63 | 64 | /** 65 | * Default constructor. 66 | */ 67 | inline 68 | Sink ( void ) throw () 69 | { 70 | } 71 | 72 | /** 73 | * Copy constructor. 74 | * 75 | * @param sink the Sink to copy. 76 | */ 77 | inline 78 | Sink ( const Sink & sink ) throw () 79 | { 80 | } 81 | 82 | /** 83 | * Assignment operator. 84 | * 85 | * @param sink the Sink to assign this to. 86 | * @return a reference to this Sink. 87 | * @exception Exception 88 | */ 89 | inline virtual Sink & 90 | operator= ( const Sink & sink ) throw ( Exception ) 91 | { 92 | return *this; 93 | } 94 | 95 | 96 | public: 97 | 98 | /** 99 | * Destructor. 100 | * 101 | * @exception Exception 102 | */ 103 | inline virtual 104 | ~Sink ( void ) throw ( Exception ) 105 | { 106 | } 107 | 108 | /** 109 | * Open the sink. 110 | * 111 | * @return true if opening was successfull, false otherwise. 112 | * @exception Exception 113 | */ 114 | virtual bool 115 | open ( void ) throw ( Exception ) = 0; 116 | 117 | /** 118 | * Check if the Sink is open. 119 | * 120 | * @return true if the Sink is open, false otherwise. 121 | */ 122 | virtual bool 123 | isOpen ( void ) const throw () = 0; 124 | 125 | /** 126 | * Check if the Sink is ready to accept data. 127 | * Blocks until the specified time for data to be available. 128 | * 129 | * @param sec the maximum seconds to block. 130 | * @param usec micro seconds to block after the full seconds. 131 | * @return true if the Sink is ready to accept data, false otherwise. 132 | * @exception Exception 133 | */ 134 | virtual bool 135 | canWrite ( unsigned int sec, 136 | unsigned int usec ) throw ( Exception ) = 0; 137 | 138 | /** 139 | * Write data to the Sink. 140 | * 141 | * @param buf the data to write. 142 | * @param len number of bytes to write from buf. 143 | * @return the number of bytes written (may be less than len). 144 | * @exception Exception 145 | */ 146 | virtual unsigned int 147 | write ( const void * buf, 148 | unsigned int len ) throw ( Exception ) = 0; 149 | 150 | /** 151 | * Flush all data that was written to the Sink to the underlying 152 | * construct. 153 | * 154 | * @exception Exception 155 | */ 156 | virtual void 157 | flush ( void ) throw ( Exception ) = 0; 158 | 159 | /** 160 | * Cut what the sink has been doing so far, and start anew. 161 | * This usually means separating the data sent to the sink up 162 | * until now, and start saving a new chunk of data. 163 | */ 164 | virtual void 165 | cut ( void ) throw () = 0; 166 | 167 | /** 168 | * Close the Sink. 169 | * 170 | * @exception Exception 171 | */ 172 | virtual void 173 | close ( void ) throw ( Exception ) = 0; 174 | }; 175 | 176 | 177 | /* ================================================= external data structures */ 178 | 179 | 180 | /* ====================================================== function prototypes */ 181 | 182 | 183 | 184 | #endif /* SINK_H */ 185 | 186 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* src/config.h. Generated from config.h.in by configure. */ 2 | /* src/config.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* Define if building universal (internal helper macro) */ 5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 6 | 7 | /* build with aacplus library */ 8 | /* #undef HAVE_AACPLUS_LIB */ 9 | 10 | /* build with ALSA sound system */ 11 | #define HAVE_ALSA_LIB 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_ERRNO_H 1 15 | 16 | /* build with faac library */ 17 | /* #undef HAVE_FAAC_LIB */ 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_FCNTL_H 1 21 | 22 | /* Does function getaddrinfo exist? */ 23 | #define HAVE_GETADDRINFO 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* build with JACK audio server support */ 29 | #define HAVE_JACK_LIB 1 30 | 31 | /* build with lame library */ 32 | #define HAVE_LAME_LIB 1 33 | 34 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 35 | #define HAVE_LIBNSL 1 36 | 37 | /* Define to 1 if you have the `rt' library (-lrt). */ 38 | #define HAVE_LIBRT 1 39 | 40 | /* Define to 1 if you have the `socket' library (-lsocket). */ 41 | /* #undef HAVE_LIBSOCKET */ 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_LIMITS_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_MATH_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_MEMORY_H 1 51 | 52 | /* use MSG_NOSIGNAL for send() */ 53 | #define HAVE_MSG_NOSIGNAL 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_NETDB_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_NETINET_IN_H 1 60 | 61 | /* build with Ogg Opus library */ 62 | /* #undef HAVE_OPUS_LIB */ 63 | 64 | /* Define if you have POSIX threads libraries and header files. */ 65 | #define HAVE_PTHREAD 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_PTHREAD_H 1 69 | 70 | /* build with PULSEAUDIO sound system */ 71 | #define HAVE_PULSEAUDIO_LIB 1 72 | 73 | /* Define to 1 if you have the `sched_getparam' function. */ 74 | #define HAVE_SCHED_GETPARAM 1 75 | 76 | /* Define to 1 if you have the `sched_getscheduler' function. */ 77 | #define HAVE_SCHED_GETSCHEDULER 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_SCHED_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_SIGNAL_H 1 84 | 85 | /* build with samplerate conversion through libsamplerate */ 86 | #define HAVE_SRC_LIB 1 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #define HAVE_STDINT_H 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_STDIO_H 1 93 | 94 | /* Define to 1 if you have the header file. */ 95 | #define HAVE_STDLIB_H 1 96 | 97 | /* Define to 1 if you have the header file. */ 98 | #define HAVE_STRINGS_H 1 99 | 100 | /* Define to 1 if you have the header file. */ 101 | #define HAVE_STRING_H 1 102 | 103 | /* Define to 1 if you have the header file. */ 104 | /* #undef HAVE_SYS_AUDIOIO_H */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | /* #undef HAVE_SYS_AUDIO_H */ 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #define HAVE_SYS_IOCTL_H 1 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #define HAVE_SYS_SOCKET_H 1 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_SYS_SOUNDCARD_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_SYS_STAT_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_SYS_TIME_H 1 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #define HAVE_SYS_TYPES_H 1 126 | 127 | /* Define to 1 if you have that is POSIX.1 compatible. */ 128 | #define HAVE_SYS_WAIT_H 1 129 | 130 | /* Define to 1 if you have the header file. */ 131 | #define HAVE_TERMIOS_H 1 132 | 133 | /* Define to 1 if you have the header file. */ 134 | #define HAVE_TIME_H 1 135 | 136 | /* build with twolame library */ 137 | /* #undef HAVE_TWOLAME_LIB */ 138 | 139 | /* Define to 1 if you have the header file. */ 140 | #define HAVE_UNISTD_H 1 141 | 142 | /* build with Ogg Vorbis library */ 143 | /* #undef HAVE_VORBIS_LIB */ 144 | 145 | /* Name of package */ 146 | #define PACKAGE "darkice" 147 | 148 | /* Define to the address where bug reports for this package should be sent. */ 149 | #define PACKAGE_BUGREPORT "" 150 | 151 | /* Define to the full name of this package. */ 152 | #define PACKAGE_NAME "darkice" 153 | 154 | /* Define to the full name and version of this package. */ 155 | #define PACKAGE_STRING "darkice 1.2" 156 | 157 | /* Define to the one symbol short name of this package. */ 158 | #define PACKAGE_TARNAME "darkice" 159 | 160 | /* Define to the home page for this package. */ 161 | #define PACKAGE_URL "" 162 | 163 | /* Define to the version of this package. */ 164 | #define PACKAGE_VERSION "1.2" 165 | 166 | /* Define to the necessary symbol if this constant uses a non-standard name on 167 | your system. */ 168 | /* #undef PTHREAD_CREATE_JOINABLE */ 169 | 170 | /* Define to 1 if you have the ANSI C header files. */ 171 | #define STDC_HEADERS 1 172 | 173 | /* Version number of package */ 174 | #define VERSION "1.2" 175 | 176 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 177 | significant byte first (like Motorola and SPARC, unlike Intel). */ 178 | #if defined AC_APPLE_UNIVERSAL_BUILD 179 | # if defined __BIG_ENDIAN__ 180 | # define WORDS_BIGENDIAN 1 181 | # endif 182 | #else 183 | # ifndef WORDS_BIGENDIAN 184 | /* # undef WORDS_BIGENDIAN */ 185 | # endif 186 | #endif 187 | 188 | /* Define to `int' if does not define. */ 189 | /* #undef pid_t */ 190 | 191 | /* Define to `unsigned int' if does not define. */ 192 | /* #undef size_t */ 193 | -------------------------------------------------------------------------------- /src/ConfigSection.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell ConfigSection 6 | 7 | File : ConfigSection.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/ConfigSection.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef CONFIG_SECTION_H 30 | #define CONFIG_SECTION_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include 40 | #include 41 | 42 | #include "Referable.h" 43 | 44 | 45 | /* ================================================================ constants */ 46 | 47 | 48 | /* =================================================================== macros */ 49 | 50 | 51 | /* =============================================================== data types */ 52 | 53 | /** 54 | * A configuration file representation. The file is of the syntax: 55 | * 56 | *
 57 |  *  # this is a whole line comment
 58 |  *  key = value
 59 |  *  an ugly key name = long value    # this end is a comment too
 60 |  *  
61 | * 62 | * also empty lines are ignored and all white space is removed 63 | * from the front and end of keys / values 64 | * 65 | * Knwon problem: you can't use '#' in any part of a key / value pair 66 | * 67 | * @author $Author: rafael@riseup.net $ 68 | * @version $Revision: 553 $ 69 | */ 70 | class ConfigSection : public virtual Referable 71 | { 72 | private: 73 | 74 | /** 75 | * Type of the hash table used in this class. 76 | */ 77 | typedef std::map TableType; 78 | 79 | /** 80 | * Hash table holding the configuration information. 81 | */ 82 | TableType table; 83 | 84 | 85 | protected: 86 | 87 | 88 | public: 89 | 90 | /** 91 | * Default constructor. 92 | * 93 | * @exception Exception 94 | */ 95 | inline 96 | ConfigSection ( void ) throw ( Exception ) 97 | { 98 | } 99 | 100 | /** 101 | * Destructor. 102 | * 103 | * @exception Exception 104 | */ 105 | inline virtual 106 | ~ConfigSection ( void ) throw ( Exception ) 107 | { 108 | } 109 | 110 | 111 | /* TODO 112 | 113 | inline 114 | ConfigSection ( const ConfigSection & di ) throw ( Exception ) 115 | { 116 | } 117 | 118 | 119 | inline ConfigSection & 120 | operator= ( const ConfigSection * di ) throw ( Exception ) 121 | { 122 | } 123 | */ 124 | 125 | /** 126 | * Add a key / value pair to the configuration information. 127 | * 128 | * @param key the key to add the value by 129 | * @param value the value to add for the key 130 | * @return true if adding was successful, false otherwise 131 | * @exception Exception 132 | */ 133 | virtual bool 134 | add ( const char * key, 135 | const char * value ) throw ( Exception ); 136 | 137 | /** 138 | * Get a value for a key. 139 | * 140 | * @param key the key to get the value for 141 | * @return the value for the key, or NULL if the key doesn't exist. 142 | * @exception Exception 143 | */ 144 | virtual const char * 145 | get ( const char * key ) const throw ( Exception ); 146 | 147 | /** 148 | * Get a value for a key, or throw an Exception. 149 | * 150 | * @param key the key to get the value for 151 | * @param message1 message part 1 of the Exception to be thrown. 152 | * @param message2 message part 2 of the Exception to be thrown. 153 | * @param code error code of the Exception to be thrown. 154 | * @return the value for the key. The return value is never NULL. 155 | * @exception Exception 156 | */ 157 | virtual const char * 158 | getForSure ( const char * key, 159 | const char * message1 = 0, 160 | const char * message2 = 0, 161 | int code = 0 ) const 162 | throw ( Exception ); 163 | 164 | /** 165 | * Add a line of configuration information. 166 | * 167 | * @param line the line to add. 168 | * @return true if a new key was added, false otherwise. 169 | * @exception Exception 170 | */ 171 | virtual bool 172 | addLine ( const char * line ) throw ( Exception ); 173 | }; 174 | 175 | 176 | /* ================================================= external data structures */ 177 | 178 | 179 | /* ====================================================== function prototypes */ 180 | 181 | 182 | 183 | #endif /* CONFIG_SECTION_H */ 184 | 185 | -------------------------------------------------------------------------------- /src/AudioSource.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : AudioSource.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/AudioSource.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include "config.h" 34 | #endif 35 | 36 | #include "AudioSource.h" 37 | #include "Util.h" 38 | #include "Exception.h" 39 | 40 | 41 | /* =================================================== local data structures */ 42 | 43 | 44 | /* ================================================ local constants & macros */ 45 | 46 | /*------------------------------------------------------------------------------ 47 | * File identity 48 | *----------------------------------------------------------------------------*/ 49 | static const char fileid[] = "$Id: AudioSource.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 50 | 51 | 52 | /* =============================================== local function prototypes */ 53 | 54 | 55 | /* ============================================================= module code */ 56 | 57 | /*------------------------------------------------------------------------------ 58 | * Return an audio source based on the compiled DSP supports and the 59 | * supplied device name parameter. 60 | *----------------------------------------------------------------------------*/ 61 | AudioSource * 62 | AudioSource :: createDspSource( const char * deviceName, 63 | const char * jackClientName, 64 | const char * paSourceName, 65 | int sampleRate, 66 | int bitsPerSample, 67 | int channel) 68 | throw ( Exception ) 69 | { 70 | 71 | if ( Util::strEq( deviceName, "/dev/tty", 8) ) { 72 | #if defined( SUPPORT_SERIAL_ULAW ) 73 | Reporter::reportEvent( 1, "Using Serial Ulaw input device:", 74 | deviceName); 75 | return new SerialUlaw( deviceName, 76 | sampleRate, 77 | bitsPerSample, 78 | channel); 79 | #else 80 | throw Exception( __FILE__, __LINE__, 81 | "trying to open Serial ULaw device " 82 | "without support compiled", deviceName); 83 | #endif 84 | } else if ( Util::strEq( deviceName, "/dev", 4) ) { 85 | #if defined( SUPPORT_OSS_DSP ) 86 | Reporter::reportEvent( 1, "Using OSS DSP input device:", deviceName); 87 | return new OssDspSource( deviceName, 88 | sampleRate, 89 | bitsPerSample, 90 | channel); 91 | #elif defined( SUPPORT_SOLARIS_DSP ) 92 | Reporter::reportEvent( 1, "Using Solaris DSP input device:",deviceName); 93 | return new SolarisDspSource( deviceName, 94 | sampleRate, 95 | bitsPerSample, 96 | channel); 97 | #else 98 | throw Exception( __FILE__, __LINE__, 99 | "trying to open OSS or Solaris DSP device " 100 | "without support compiled", deviceName); 101 | #endif 102 | } else if ( Util::strEq( deviceName, "jack", 4) ) { 103 | #if defined( SUPPORT_JACK_DSP ) 104 | Reporter::reportEvent( 1, "Using JACK audio server as input device."); 105 | return new JackDspSource( deviceName, 106 | jackClientName, 107 | sampleRate, 108 | bitsPerSample, 109 | channel); 110 | #else 111 | throw Exception( __FILE__, __LINE__, 112 | "trying to open JACK device without " 113 | "support compiled", deviceName); 114 | #endif 115 | } else if ( Util::strEq( deviceName, "pulseaudio", 10) ) { 116 | #if defined( SUPPORT_PULSEAUDIO_DSP ) 117 | Reporter::reportEvent( 1, "Using PulseAudio audio server as input device."); 118 | return new PulseAudioDspSource( paSourceName, 119 | sampleRate, 120 | bitsPerSample, 121 | channel); 122 | #else 123 | throw Exception( __FILE__, __LINE__, 124 | "trying to open PulseAudio device without " 125 | "support compiled", deviceName); 126 | #endif 127 | } else { 128 | #if defined( SUPPORT_ALSA_DSP ) 129 | Reporter::reportEvent( 1, "Using ALSA DSP input device:", deviceName); 130 | return new AlsaDspSource( deviceName, 131 | sampleRate, 132 | bitsPerSample, 133 | channel); 134 | #else 135 | throw Exception( __FILE__, __LINE__, 136 | "trying to open ALSA DSP device without " 137 | "support compiled", deviceName); 138 | #endif 139 | } 140 | } 141 | 142 | -------------------------------------------------------------------------------- /src/ConfigSection.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell ConfigSection 6 | 7 | File : ConfigSection.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/ConfigSection.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include "config.h" 34 | #endif 35 | 36 | #include 37 | 38 | #include 39 | 40 | 41 | #include "ConfigSection.h" 42 | 43 | 44 | /* =================================================== local data structures */ 45 | 46 | 47 | /* ================================================ local constants & macros */ 48 | 49 | /*------------------------------------------------------------------------------ 50 | * File identity 51 | *----------------------------------------------------------------------------*/ 52 | static const char fileid[] = "$Id: ConfigSection.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 53 | 54 | 55 | /*------------------------------------------------------------------------------ 56 | * string containing all white space characters 57 | *----------------------------------------------------------------------------*/ 58 | #define WHITE_SPACE_STR " \t" 59 | 60 | 61 | /* =============================================== local function prototypes */ 62 | 63 | 64 | /* ============================================================= module code */ 65 | 66 | /*------------------------------------------------------------------------------ 67 | * Add a key / value pair 68 | *----------------------------------------------------------------------------*/ 69 | bool 70 | ConfigSection :: add ( const char * key, 71 | const char * value ) throw ( Exception ) 72 | { 73 | if ( !key || !value ) { 74 | throw Exception( __FILE__, __LINE__, "no key or value"); 75 | } 76 | 77 | std::pair element( key, value); 78 | std::pair res; 79 | 80 | res = table.insert( element); 81 | 82 | return res.second; 83 | } 84 | 85 | 86 | /*------------------------------------------------------------------------------ 87 | * Get a value for a key 88 | *----------------------------------------------------------------------------*/ 89 | const char * 90 | ConfigSection :: get ( const char * key ) const throw ( Exception ) 91 | { 92 | if ( !key ) { 93 | throw Exception( __FILE__, __LINE__, "no key"); 94 | } 95 | 96 | TableType::const_iterator it = table.find( key); 97 | if ( it == table.end() ) { 98 | return 0; 99 | } 100 | return it->second.c_str(); 101 | } 102 | 103 | 104 | /*------------------------------------------------------------------------------ 105 | * Get a value for a key, in the key does not exist, throw an exception 106 | *----------------------------------------------------------------------------*/ 107 | const char * 108 | ConfigSection :: getForSure ( const char * key, 109 | const char * message1, 110 | const char * message2, 111 | int code ) const 112 | throw ( Exception ) 113 | { 114 | const char * value; 115 | 116 | if ( !(value = get( key)) ) { 117 | throw Exception( __FILE__, __LINE__, key, message1, message2, code); 118 | } 119 | 120 | return value; 121 | } 122 | 123 | 124 | /*------------------------------------------------------------------------------ 125 | * Add a configuration line 126 | *----------------------------------------------------------------------------*/ 127 | bool 128 | ConfigSection :: addLine ( const char * line ) throw ( Exception ) 129 | { 130 | if ( !line ) { 131 | throw Exception( __FILE__, __LINE__, "no line"); 132 | } 133 | 134 | std::string::size_type ix; 135 | std::string str( line); 136 | 137 | /* delete everything after the first # */ 138 | if ( (ix = str.find( '#')) != str.npos ) { 139 | str.erase( ix); 140 | } 141 | /* eat up all white space from the front */ 142 | if ( (ix = str.find_first_not_of( WHITE_SPACE_STR)) != str.npos ) { 143 | str.erase( 0, ix); 144 | } 145 | /* eat up all white space from the end */ 146 | if ( (ix = str.find_last_not_of( WHITE_SPACE_STR)) != str.npos ) { 147 | str.erase( ix + 1); 148 | } 149 | if ( !str.length() ) { 150 | return true; 151 | } 152 | 153 | /* find the '=' delimiter between key and value */ 154 | if ( (ix = str.find( '=')) == str.npos ) { 155 | return false; 156 | } 157 | 158 | std::string key( str, 0, ix); 159 | std::string value( str, ix + 1); 160 | 161 | /* eat up all white space from the front of value */ 162 | if ( (ix = value.find_first_not_of( WHITE_SPACE_STR)) != value.npos ) { 163 | value.erase( 0, ix); 164 | } 165 | /* eat up all white space from the end of key */ 166 | if ( (ix = key.find_last_not_of( WHITE_SPACE_STR)) != key.npos ) { 167 | key.erase( ix + 1); 168 | } 169 | 170 | /* now add the new key / value pair */ 171 | return add( key.c_str(), value.c_str()); 172 | } 173 | 174 | -------------------------------------------------------------------------------- /src/DarkIceConfig.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell Config 6 | 7 | File : DarkIceConfig.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/DarkIceConfig.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef CONFIG_H 30 | #define CONFIG_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | 44 | #include "Referable.h" 45 | #include "ConfigSection.h" 46 | 47 | 48 | /* ================================================================ constants */ 49 | 50 | 51 | /* =================================================================== macros */ 52 | 53 | 54 | /* =============================================================== data types */ 55 | 56 | /** 57 | * A configuration file representation. The file is of the syntax: 58 | * 59 | *
 60 |  *  [section1]
 61 |  *  # this is a whole line comment
 62 |  *  key = value
 63 |  *  an ugly key name = long value    # this end is a comment too
 64 |  *
 65 |  *  [section2]
 66 |  *  # this is a whole line comment in section 2
 67 |  *  key = value
 68 |  *  an ugly key name = long value    # this end is a comment too
 69 |  *  
70 | * 71 | * also empty lines are ignored and all white space is removed 72 | * from the front and end of keys / values 73 | * 74 | * Knwon problem: you can't use '#' in any part of a key / value pair 75 | * 76 | * @author $Author: rafael@riseup.net $ 77 | * @version $Revision: 553 $ 78 | */ 79 | class Config : public virtual Referable 80 | { 81 | private: 82 | 83 | /** 84 | * Type declaration of the hash table type. 85 | */ 86 | typedef std::map TableType; 87 | 88 | /** 89 | * Hash table holding the configuration sections. 90 | * 91 | * @see ConfigSection 92 | */ 93 | TableType table; 94 | 95 | /** 96 | * Hash table holding the configuration sections. 97 | * 98 | * @see ConfigSection 99 | */ 100 | std::string currentSection; 101 | 102 | 103 | protected: 104 | 105 | 106 | public: 107 | 108 | /** 109 | * Default constructor. 110 | * 111 | * @exception Exception 112 | */ 113 | inline 114 | Config ( void ) throw ( Exception ) 115 | { 116 | } 117 | 118 | /** 119 | * Constructor based on an input stream. 120 | * 121 | * @param is configuration will be read from this input stream 122 | * until end of stream is reached. 123 | * @exception Exception 124 | */ 125 | inline 126 | Config ( std::istream & is ) throw ( Exception ) 127 | { 128 | read( is ); 129 | } 130 | 131 | /** 132 | * Destructor. 133 | * 134 | * @exception Exception 135 | */ 136 | inline virtual 137 | ~Config ( void ) throw ( Exception ) 138 | { 139 | } 140 | 141 | 142 | /* TODO 143 | 144 | inline 145 | Config ( const Config & di ) throw ( Exception ) 146 | { 147 | } 148 | 149 | 150 | inline Config & 151 | operator= ( const Config * di ) throw ( Exception ) 152 | { 153 | } 154 | */ 155 | 156 | /** 157 | * Delete the configuration information stored in the object. 158 | * Resets the object to a clean state. 159 | * 160 | * @exception Exception 161 | */ 162 | inline virtual void 163 | reset ( void ) throw ( Exception ) 164 | { 165 | table.clear(); 166 | currentSection = ""; 167 | } 168 | 169 | /** 170 | * Read a line of confiugration information. 171 | * 172 | * @param line the line to read. 173 | * @return true if the line was correct, false otherwise. 174 | * @exception Exception 175 | */ 176 | virtual bool 177 | addLine ( const char * line ) throw ( Exception ); 178 | 179 | /** 180 | * Read a line of confiugration information. 181 | * 182 | * @param is the input stream to read from 183 | * @return true if the line was correct, false otherwise. 184 | * @exception Exception 185 | */ 186 | virtual void 187 | read ( std::istream & is ) throw ( Exception ); 188 | 189 | /** 190 | * Get a ConfigSection by name. 191 | * 192 | * @param key the name of the ConfigSection 193 | * @return the ConfigSection requested, or NULL if it doesn't exists. 194 | * @exception Exception 195 | */ 196 | virtual const ConfigSection * 197 | get ( const char * key ) const throw ( Exception ); 198 | }; 199 | 200 | 201 | /* ================================================= external data structures */ 202 | 203 | 204 | /* ====================================================== function prototypes */ 205 | 206 | 207 | 208 | #endif /* CONFIG_H */ 209 | 210 | -------------------------------------------------------------------------------- /debian/init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2007 Javier Fernandez-Sanguino 4 | # Copyright (c) 2009 Jochen Friedrich 5 | # 6 | # This is free software; you may redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as 8 | # published by the Free Software Foundation; either version 2, 9 | # or (at your option) any later version. 10 | # 11 | # This is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License with 17 | # the Debian operating system, in /usr/share/common-licenses/GPL; if 18 | # not, write to the Free Software Foundation, Inc., 59 Temple Place, 19 | # Suite 330, Boston, MA 02111-1307 USA 20 | # 21 | ### BEGIN INIT INFO 22 | # Provides: darkice 23 | # Required-Start: $network $local_fs $remote_fs 24 | # Required-Stop: $network $local_fs $remote_fs 25 | # Should-Start: 26 | # Should-Stop: 27 | # Default-Start: 2 3 4 5 28 | # Default-Stop: 0 1 6 29 | # Short-Description: Live audio streamer 30 | # Description: DarkIce is an IceCast, IceCast2 and ShoutCast 31 | # live audio streamer. 32 | ### END INIT INFO 33 | 34 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 35 | 36 | NAME=darkice 37 | DAEMON=/usr/bin/$NAME 38 | DESC="Live audio streamer" 39 | LOGDIR=/var/log 40 | USER=nobody 41 | GROUP=nogroup 42 | 43 | PIDFILE=/var/run/$NAME.pid 44 | 45 | test -x $DAEMON || exit 0 46 | 47 | . /lib/lsb/init-functions 48 | 49 | # Default options, these can be overriden by the information 50 | # at /etc/default/$NAME 51 | DAEMON_OPTS="" # Additional options given to the server 52 | 53 | DIETIME=2 # Time to wait for the server to die, in seconds 54 | # If this value is set too low you might not 55 | # let some servers to die gracefully and 56 | # 'restart' will not work 57 | 58 | # Include defaults if available 59 | if [ -f /etc/default/$NAME ] ; then 60 | . /etc/default/$NAME 61 | fi 62 | 63 | # Use this if you want the user to explicitly set 'RUN' in 64 | # /etc/default/ 65 | if [ "x$RUN" != "xyes" ] ; then 66 | exit 0 67 | fi 68 | 69 | set -e 70 | 71 | running_pid() { 72 | # Check if a given process pid's cmdline matches a given name 73 | pid=$1 74 | name=$2 75 | [ -z "$pid" ] && return 1 76 | [ ! -d /proc/$pid ] && return 1 77 | cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1` 78 | # Is this the expected server 79 | [ "$cmd" != "$name" ] && return 1 80 | return 0 81 | } 82 | 83 | running() { 84 | # Check if the process is running looking at /proc 85 | # (works for all users) 86 | 87 | # No pidfile, probably no daemon present 88 | [ ! -f "$PIDFILE" ] && return 1 89 | pid=`cat $PIDFILE` 90 | running_pid $pid $DAEMON || return 1 91 | return 0 92 | } 93 | 94 | start_server() { 95 | # Start the process using the wrapper 96 | start-stop-daemon --start --quiet --pidfile $PIDFILE \ 97 | --background --chuid $USER:$GROUP --exec $DAEMON -- $DAEMON_OPTS 98 | errcode=$? 99 | return $errcode 100 | } 101 | 102 | stop_server() { 103 | # Stop the process using the wrapper 104 | start-stop-daemon --stop --quiet --pidfile $PIDFILE \ 105 | --exec $DAEMON 106 | errcode=$? 107 | return $errcode 108 | } 109 | 110 | force_stop() { 111 | # Force the process to die killing it manually 112 | [ ! -e "$PIDFILE" ] && return 113 | if running ; then 114 | kill -15 $pid 115 | # Is it really dead? 116 | sleep "$DIETIME"s 117 | if running ; then 118 | kill -9 $pid 119 | sleep "$DIETIME"s 120 | if running ; then 121 | echo "Cannot kill $NAME (pid=$pid)!" 122 | exit 1 123 | fi 124 | fi 125 | fi 126 | rm -f $PIDFILE 127 | } 128 | 129 | 130 | case "$1" in 131 | start) 132 | log_daemon_msg "Starting $DESC " "$NAME" 133 | # Check if it's running first 134 | if running ; then 135 | log_progress_msg "apparently already running" 136 | log_end_msg 0 137 | exit 0 138 | fi 139 | if start_server && running ; then 140 | # It's ok, the server started and is running 141 | log_end_msg 0 142 | else 143 | # Either we could not start it or it is not running 144 | # after we did 145 | # NOTE: Some servers might die some time after they start, 146 | # this code does not try to detect this and might give 147 | # a false positive (use 'status' for that) 148 | log_end_msg 1 149 | fi 150 | ;; 151 | stop) 152 | log_daemon_msg "Stopping $DESC" "$NAME" 153 | if running ; then 154 | # Only stop the server if we see it running 155 | stop_server 156 | log_end_msg $? 157 | else 158 | # If it's not running don't do anything 159 | log_progress_msg "apparently not running" 160 | log_end_msg 0 161 | exit 0 162 | fi 163 | ;; 164 | force-stop) 165 | # First try to stop gracefully the program 166 | $0 stop 167 | if running; then 168 | # If it's still running try to kill it more forcefully 169 | log_daemon_msg "Stopping (force) $DESC" "$NAME" 170 | force_stop 171 | log_end_msg $? 172 | fi 173 | ;; 174 | restart|force-reload) 175 | log_daemon_msg "Restarting $DESC" "$NAME" 176 | stop_server 177 | # Wait some sensible amount, some server need this 178 | [ -n "$DIETIME" ] && sleep $DIETIME 179 | start_server 180 | running 181 | log_end_msg $? 182 | ;; 183 | status) 184 | 185 | log_daemon_msg "Checking status of $DESC" "$NAME" 186 | if running ; then 187 | log_progress_msg "running" 188 | log_end_msg 0 189 | else 190 | log_progress_msg "apparently not running" 191 | log_end_msg 1 192 | exit 1 193 | fi 194 | ;; 195 | reload) 196 | log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon" 197 | log_warning_msg "cannot re-read the config file (use restart)." 198 | ;; 199 | 200 | *) 201 | N=/etc/init.d/$NAME 202 | echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2 203 | exit 1 204 | ;; 205 | esac 206 | 207 | exit 0 208 | -------------------------------------------------------------------------------- /src/Exception.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : Exception.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Exception.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include "config.h" 34 | #endif 35 | 36 | #ifdef HAVE_STRING_H 37 | #include 38 | #else 39 | #error need string.h 40 | #endif 41 | 42 | 43 | #include "Exception.h" 44 | 45 | 46 | /* =================================================== local data structures */ 47 | 48 | 49 | /* ================================================ local constants & macros */ 50 | 51 | /*------------------------------------------------------------------------------ 52 | * File identity 53 | *----------------------------------------------------------------------------*/ 54 | static const char fileid[] = "$Id: Exception.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 55 | 56 | 57 | /* =============================================== local function prototypes */ 58 | 59 | 60 | /* ============================================================= module code */ 61 | 62 | /*------------------------------------------------------------------------------ 63 | * Constructor 64 | *----------------------------------------------------------------------------*/ 65 | Exception :: Exception ( const char * file, 66 | unsigned int line, 67 | const char * description1, 68 | const char * description2, 69 | int code ) throw () 70 | { 71 | size_t len = 0; 72 | 73 | if ( description1 ) { 74 | len += strlen( description1); 75 | } 76 | if ( description2 ) { 77 | len += strlen( description2); 78 | } 79 | 80 | if ( len ) { 81 | char * str = new char[len+1]; 82 | 83 | str[0] = '\0'; 84 | if ( description1 ) { 85 | strcat( str, description1); 86 | } 87 | if ( description2 ) { 88 | strcat( str, description2); 89 | } 90 | 91 | init( file, line, str, code); 92 | delete[] str; 93 | 94 | } else { 95 | 96 | init( file, line, 0, code); 97 | } 98 | } 99 | 100 | 101 | /*------------------------------------------------------------------------------ 102 | * Constructor 103 | *----------------------------------------------------------------------------*/ 104 | Exception :: Exception ( const char * file, 105 | unsigned int line, 106 | const char * description1, 107 | const char * description2, 108 | const char * description3, 109 | int code ) throw () 110 | { 111 | size_t len = 0; 112 | 113 | if ( description1 ) { 114 | len += strlen( description1); 115 | } 116 | if ( description2 ) { 117 | len += strlen( description2); 118 | } 119 | if ( description3 ) { 120 | len += strlen( description3); 121 | } 122 | 123 | if ( len ) { 124 | char * str = new char[len+1]; 125 | 126 | str[0] = '\0'; 127 | if ( description1 ) { 128 | strcat( str, description1); 129 | } 130 | if ( description2 ) { 131 | strcat( str, description2); 132 | } 133 | if ( description3 ) { 134 | strcat( str, description3); 135 | } 136 | 137 | init( file, line, str, code); 138 | delete[] str; 139 | 140 | } else { 141 | 142 | init( file, line, 0, code); 143 | } 144 | } 145 | 146 | 147 | /*------------------------------------------------------------------------------ 148 | * Initialize the class 149 | *----------------------------------------------------------------------------*/ 150 | void 151 | Exception :: init ( const char * file, 152 | unsigned int line, 153 | const char * description = 0, 154 | int code = 0 ) throw () 155 | { 156 | if ( !file ) { 157 | this->file = 0; 158 | } else { 159 | size_t len; 160 | 161 | len = strlen( file ) + 1; 162 | this->file = new char[len]; 163 | if ( this->file ) { 164 | memcpy( this->file, file, len); 165 | } 166 | } 167 | 168 | if ( !description ) { 169 | this->description = 0; 170 | } else { 171 | size_t len; 172 | 173 | len = strlen( description ) + 1; 174 | this->description = new char[len]; 175 | if ( this->description ) { 176 | memcpy( this->description, description, len); 177 | } 178 | } 179 | 180 | this->line = line; 181 | this->code = code; 182 | } 183 | 184 | 185 | /*------------------------------------------------------------------------------ 186 | * De-initialize the class 187 | *----------------------------------------------------------------------------*/ 188 | void 189 | Exception :: strip ( void ) throw () 190 | { 191 | if ( description ) { 192 | delete[] description; 193 | } 194 | 195 | if ( file ) { 196 | delete[] file; 197 | } 198 | } 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /src/aflibDebug.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2000 Stefan Westerfeld 4 | stefan@space.twc.de 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public 8 | License as published by the Free Software Foundation; either 9 | version 2 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public License 17 | along with this library; see the file COPYING.LIB. If not, write to 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. 20 | 21 | */ 22 | 23 | #include "aflibDebug.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | static int aflib_debug_level = ::aflibDebug::lInfo; 30 | static bool aflib_debug_abort = false; 31 | static const char *aflib_debug_prefix = ""; 32 | static char *messageAppName = 0; 33 | 34 | 35 | /* 36 | static char* status_strs[] = 37 | { 38 | "Success", 39 | "Error Open", 40 | "Unsupported", 41 | "AFLIB_ERROR_INITIALIZATION_FAILURE", 42 | "AFLIB_NOT_FOUND", 43 | "AFLIB_END_OF_FILE", 44 | "AFLIB_NO_DATA", 45 | 0 46 | }; 47 | 48 | 49 | static char* data_size_strs[] = 50 | { 51 | "UNDEFINED", 52 | "8 bit signed", 53 | "8 bit unsigned", 54 | "16 bit signed", 55 | "16 bit unsigned", 56 | "32 bit signed", 57 | "32 bit unsigned", 58 | 0 59 | }; 60 | 61 | static char* data_endian_strs[] = 62 | { 63 | "UNDEFINED", 64 | "ENDIAN_LITTLE", 65 | "ENDIAN_BIG", 66 | 0 67 | }; 68 | */ 69 | 70 | /* 71 | * Call the graphical application to display a message, if 72 | * defined. Otherwise, send to standard error. Debug messages are 73 | * always sent to standard error because they tend to be very verbose. 74 | * Note that the external application is run in the background to 75 | * avoid blocking the sound server. 76 | */ 77 | void output_message(::aflibDebug::Level level, const char *msg) { 78 | char buff[1024]; 79 | 80 | /* default to text output if no message app is defined or if it is a debug message. */ 81 | if (messageAppName == 0 || !strcmp(messageAppName, "") || (level == ::aflibDebug::lDebug)) 82 | { 83 | fprintf(stderr, "%s\n", msg); 84 | return; 85 | } 86 | 87 | switch (level) { 88 | case ::aflibDebug::lFatal: 89 | sprintf(buff, "%s -e \"aflib fatal error:\n\n%s\" &", messageAppName, msg); 90 | break; 91 | case ::aflibDebug::lWarning: 92 | sprintf(buff, "%s -w \"aflib warning message:\n\n%s\" &", messageAppName, msg); 93 | break; 94 | case ::aflibDebug::lInfo: 95 | sprintf(buff, "%s -i \"aflib informational message:\n\n%s\" &", messageAppName, msg); 96 | break; 97 | default: 98 | break; // avoid compile warning 99 | } 100 | int r = system(buff); 101 | if (r<0) fprintf(stderr, "aflibDebug, system() failed\n"); 102 | } 103 | 104 | /* 105 | * Display a message using output_message. If the message is the same 106 | * as the previous one, just increment a count but don't display 107 | * it. This prevents flooding the user with duplicate warnings. If the 108 | * message is not the same as the previous one, then we report the 109 | * previously repeated message (if any) and reset the last message and 110 | * count. 111 | */ 112 | void display_message(::aflibDebug::Level level, const char *msg) { 113 | static char lastMsg[1024]; 114 | static ::aflibDebug::Level lastLevel; 115 | static int msgCount = 0; 116 | 117 | if (!strncmp(msg, lastMsg, 1024)) 118 | { 119 | msgCount++; 120 | } else { 121 | if (msgCount > 0) 122 | { 123 | char buff[1024]; 124 | sprintf(buff, "%s\n(The previous message was repeated %d times.)", lastMsg, msgCount); 125 | output_message(lastLevel, buff); 126 | } 127 | 128 | strncpy(lastMsg, msg, 1024); 129 | lastLevel = level; 130 | msgCount = 0; 131 | output_message(level, msg); 132 | } 133 | 134 | } 135 | 136 | static class DebugInitFromEnv { 137 | 138 | public: 139 | DebugInitFromEnv() { 140 | const char *env = getenv("AFLIB_DEBUG"); 141 | if(env) 142 | { 143 | if(strcmp(env,"debug") == 0) 144 | aflib_debug_level = ::aflibDebug::lDebug; 145 | else if(strcmp(env,"info") == 0) 146 | aflib_debug_level = ::aflibDebug::lInfo; 147 | else if(strcmp(env,"warning") == 0) 148 | aflib_debug_level = ::aflibDebug::lWarning; 149 | else if(strcmp(env,"quiet") == 0) 150 | aflib_debug_level = ::aflibDebug::lFatal; 151 | else 152 | { 153 | fprintf(stderr, 154 | "AFLIB_DEBUG must be one of debug,info,warning,quiet\n"); 155 | } 156 | } 157 | 158 | env = getenv("AFLIB_DEBUG_ABORT"); 159 | if(env) 160 | aflib_debug_abort = true; 161 | } 162 | } 163 | 164 | debugInitFromEnv; 165 | 166 | 167 | void aflibDebug::init(const char *prefix, Level level) 168 | { 169 | aflib_debug_level = level; 170 | aflib_debug_prefix = prefix; 171 | } 172 | 173 | void aflibDebug::fatal(const char *fmt, ...) 174 | { 175 | char buff[1024]; 176 | va_list ap; 177 | va_start(ap, fmt); 178 | vsprintf(buff, fmt, ap); 179 | va_end(ap); 180 | display_message(::aflibDebug::lFatal, buff); 181 | 182 | if(aflib_debug_abort) abort(); 183 | exit(1); 184 | } 185 | 186 | void aflibDebug::warning(const char *fmt, ...) 187 | { 188 | if(lWarning >= aflib_debug_level) 189 | { 190 | char buff[1024]; 191 | va_list ap; 192 | va_start(ap, fmt); 193 | vsprintf(buff, fmt, ap); 194 | va_end(ap); 195 | display_message(::aflibDebug::lWarning, buff); 196 | } 197 | } 198 | 199 | void aflibDebug::info(const char *fmt, ...) 200 | { 201 | if(lInfo >= aflib_debug_level) 202 | { 203 | char buff[1024]; 204 | va_list ap; 205 | va_start(ap, fmt); 206 | vsprintf(buff, fmt, ap); 207 | va_end(ap); 208 | display_message(::aflibDebug::lInfo, buff); 209 | } 210 | } 211 | 212 | void aflibDebug::debug(const char *fmt, ...) 213 | { 214 | if(lDebug >= aflib_debug_level) 215 | { 216 | char buff[1024]; 217 | va_list ap; 218 | va_start(ap, fmt); 219 | vsprintf(buff, fmt, ap); 220 | va_end(ap); 221 | display_message(::aflibDebug::lDebug, buff); 222 | } 223 | } 224 | 225 | void aflibDebug::messageApp(const char *appName) 226 | { 227 | messageAppName = (char*) realloc(messageAppName, strlen(appName)+1); 228 | strcpy(messageAppName, appName); 229 | } 230 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : main.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/main.cpp $ 11 | 12 | Abstract : 13 | 14 | Program entry point 15 | 16 | Copyright notice: 17 | 18 | This program is free software; you can redistribute it and/or 19 | modify it under the terms of the GNU General Public License 20 | as published by the Free Software Foundation; either version 3 21 | of the License, or (at your option) any later version. 22 | 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU General Public License for more details. 27 | 28 | You should have received a copy of the GNU General Public License 29 | along with this program; if not, write to the Free Software 30 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | 32 | ------------------------------------------------------------------------------*/ 33 | 34 | /* ============================================================ include files */ 35 | 36 | #ifdef HAVE_CONFIG_H 37 | #include "config.h" 38 | #endif 39 | 40 | #ifdef HAVE_STDLIB_H 41 | #include 42 | #else 43 | #error needs stdlib.h 44 | #endif 45 | 46 | #ifdef HAVE_SIGNAL_H 47 | #include 48 | #else 49 | #error needs signal.h 50 | #endif 51 | 52 | #include 53 | #include 54 | 55 | #include "Ref.h" 56 | #include "Exception.h" 57 | #include "Util.h" 58 | #include "DarkIce.h" 59 | 60 | 61 | /* =================================================== local data structures */ 62 | 63 | /*------------------------------------------------------------------------------ 64 | * The DarkIce object we're running 65 | *----------------------------------------------------------------------------*/ 66 | static Ref darkice; 67 | 68 | 69 | /* ================================================ local constants & macros */ 70 | 71 | /*------------------------------------------------------------------------------ 72 | * File identity 73 | *----------------------------------------------------------------------------*/ 74 | static const char fileid[] = "$Id: main.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 75 | 76 | /*------------------------------------------------------------------------------ 77 | * Default config file name 78 | *----------------------------------------------------------------------------*/ 79 | static const char *DEFAULT_CONFIG_FILE = "/etc/darkice.cfg"; 80 | 81 | 82 | /* =============================================== local function prototypes */ 83 | 84 | /*------------------------------------------------------------------------------ 85 | * Show program usage 86 | *----------------------------------------------------------------------------*/ 87 | static void 88 | showUsage ( std::ostream & os ); 89 | 90 | /*------------------------------------------------------------------------------ 91 | * Handler for the SIGUSR1 signal 92 | *----------------------------------------------------------------------------*/ 93 | static void 94 | sigusr1Handler(int value); 95 | 96 | 97 | /* ============================================================= module code */ 98 | 99 | /*------------------------------------------------------------------------------ 100 | * Program entry point 101 | *----------------------------------------------------------------------------*/ 102 | int 103 | main ( 104 | int argc, 105 | char * argv[] ) 106 | { 107 | int res = -1; 108 | 109 | std::cout << "DarkIce " << VERSION 110 | << " live audio streamer, http://code.google.com/p/darkice/" 111 | << std::endl 112 | << "Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/" 113 | << std::endl 114 | << "Copyright (c) 2008-2013, Akos Maroy and Rafael Diniz" 115 | << std::endl 116 | << "This is free software, and you are welcome to redistribute it " 117 | << std::endl 118 | << "under the terms of The GNU General Public License version 3 or" 119 | << std::endl 120 | << "any later version." 121 | << std::endl << std::endl; 122 | 123 | try { 124 | const char * configFileName = DEFAULT_CONFIG_FILE; 125 | unsigned int verbosity = 1; 126 | int i; 127 | const char opts[] = "hc:v:"; 128 | 129 | while ( (i = getopt( argc, argv, opts)) != -1 ) { 130 | switch ( i ) { 131 | case 'c': 132 | configFileName = optarg; 133 | break; 134 | 135 | case 'v': 136 | verbosity = Util::strToL( optarg); 137 | break; 138 | 139 | default: 140 | case ':': 141 | case '?': 142 | case 'h': 143 | showUsage( std::cout); 144 | return 1; 145 | } 146 | } 147 | 148 | std::cout << "Using config file: " << configFileName << std::endl; 149 | 150 | std::ifstream configFile( configFileName); 151 | Reporter::setReportVerbosity( verbosity ); 152 | Reporter::setReportOutputStream( std::cout ); 153 | Config config( configFile); 154 | 155 | darkice = new DarkIce( config); 156 | 157 | signal(SIGUSR1, sigusr1Handler); 158 | 159 | res = darkice->run(); 160 | 161 | } catch ( Exception & e ) { 162 | std::cout << "DarkIce: " << e << std::endl << std::flush; 163 | } 164 | 165 | return res; 166 | } 167 | 168 | 169 | /*------------------------------------------------------------------------------ 170 | * Show program usage 171 | *----------------------------------------------------------------------------*/ 172 | static void 173 | showUsage ( std::ostream & os ) 174 | { 175 | os 176 | << "usage: darkice [-v n] -c config.file" 177 | << std::endl 178 | << std::endl 179 | << "options:" 180 | << std::endl 181 | << " -c config.file use configuration file config.file" 182 | << std::endl 183 | << " if not specified, /etc/darkice.cfg is used" 184 | << std::endl 185 | << " -v n verbosity level (0 = silent, 10 = loud)" 186 | << std::endl 187 | << " -h print this message and exit" 188 | << std::endl 189 | << std::endl; 190 | } 191 | 192 | 193 | /*------------------------------------------------------------------------------ 194 | * Handle the SIGUSR1 signal here 195 | *----------------------------------------------------------------------------*/ 196 | static void 197 | sigusr1Handler(int value) 198 | { 199 | darkice->cut(); 200 | } 201 | 202 | -------------------------------------------------------------------------------- /src/aflibConverter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright: (C) 2000 Julius O. Smith 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | * Julius O. Smith jos@ccrma.stanford.edu 19 | * 20 | */ 21 | /* This code was modified by Bruce Forsberg (forsberg@tns.net) to make it 22 | into a C++ class 23 | */ 24 | 25 | 26 | #ifndef _AFLIBCONVERTER_H_ 27 | #define _AFLIBCONVERTER_H_ 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include "config.h" 31 | #endif 32 | 33 | #ifndef MAX 34 | #define MAX(x,y) ((x)>(y) ?(x):(y)) 35 | #endif 36 | #ifndef MIN 37 | #define MIN(x,y) ((x)<(y) ?(x):(y)) 38 | #endif 39 | 40 | #define MAX_HWORD (32767) 41 | #define MIN_HWORD (-32768) 42 | 43 | #define IBUFFSIZE 4096 /* Input buffer size */ 44 | 45 | /*! \class aflibConverter 46 | \brief Provides sample rate conversion. 47 | 48 | This class will perform audio resampling. With the constructor you can choose the 49 | type of resampling to be done. Simple linear interpolation can be done by setting 50 | linear_interpolation to be TRUE in the constructor. The other two flags are 51 | ignored if this is set. If linear_interpolation is FALSE then some form of filtering 52 | will be done. IF high_quality is FALSE then a small filter will be performed. 53 | If high_quality is TRUE then a large filter (higher quality) will be performed. For 54 | both the small and large filters another parameter can be specified, filter_interpolation. 55 | With filter_interpolation set then the filter coefficients used for both the small and 56 | large filtering will be interpolated as well. 57 | 58 | This class was designed to stream audio data. It also expects audio data as 16 bit values. 59 | Each time a new stream is started some initialization needs to be done. Thus the function 60 | initialize should be called to initialize everything. This initialize function will set 61 | the conversion factor as well as a multiplecation factor for volume. The volume only 62 | applies to the small and large filter. Since this filter uses a history of the audio data 63 | it is possible for it to vary in amplitude. This allows users to scale the data. This 64 | class will work on any number of channels. Once everything is specified then resample 65 | should be called as many times as is necessary to process all the data. The value 66 | inCount will be returned indicating how many inArray samples were actually used to 67 | produce the output. This value can be used to indicate where the next block of 68 | inArray data should start. The resample function is driven by the outCount value 69 | specified. The inArray should contain at least: 70 | outCount / factor + extra_samples. 71 | extra_samples depends on the type of filtering done. As a rule of thumb 50 should be 72 | adequate for any type of filter. 73 | */ 74 | 75 | class aflibData; 76 | 77 | class aflibConverter { 78 | 79 | public: 80 | 81 | // Available contructors and destructors 82 | aflibConverter ( 83 | bool high_quality, 84 | bool linear_interpolation, 85 | bool filter_interpolation); 86 | 87 | ~aflibConverter(); 88 | 89 | void 90 | initialize( 91 | double factor, /* factor = Sndout/Sndin */ 92 | int channels, /* number of sound channels */ 93 | double volume = 1.0); /* factor to multiply amplitude */ 94 | 95 | int 96 | resample( /* number of output samples returned */ 97 | int& inCount, /* number of input samples to convert */ 98 | int outCount, /* number of output samples to compute */ 99 | short inArray[], /* input array data (length inCount * nChans) */ 100 | short outArray[]);/* output array data (length outCount * nChans) */ 101 | 102 | 103 | private: 104 | 105 | aflibConverter(); 106 | 107 | aflibConverter(const aflibConverter& op); 108 | 109 | const aflibConverter& 110 | operator=(const aflibConverter& op); 111 | 112 | int 113 | err_ret(const char *s); 114 | 115 | void 116 | deleteMemory(); 117 | 118 | int 119 | readData( 120 | int inCount, /* _total_ number of frames in input file */ 121 | short inArray[], /* input data */ 122 | short *outPtr[], /* array receiving chan samps */ 123 | int dataArraySize, /* size of these arrays */ 124 | int Xoff, /* read into input array starting at this index */ 125 | bool init_count); 126 | 127 | 128 | inline short 129 | WordToHword(int v, int scl) 130 | { 131 | short out; 132 | int llsb = (1<<(scl-1)); 133 | v += llsb; /* round */ 134 | v >>= scl; 135 | if (v>MAX_HWORD) { 136 | v = MAX_HWORD; 137 | } else if (v < MIN_HWORD) { 138 | v = MIN_HWORD; 139 | } 140 | out = (short) v; 141 | return out; 142 | }; 143 | 144 | int 145 | SrcLinear( 146 | short X[], 147 | short Y[], 148 | double factor, 149 | unsigned int *Time, 150 | unsigned short& Nx, 151 | unsigned short Nout); 152 | 153 | int 154 | SrcUp( 155 | short X[], 156 | short Y[], 157 | double factor, 158 | unsigned int *Time, 159 | unsigned short& Nx, 160 | unsigned short Nout, 161 | unsigned short Nwing, 162 | unsigned short LpScl, 163 | short Imp[], 164 | short ImpD[], 165 | bool Interp); 166 | 167 | int 168 | SrcUD( 169 | short X[], 170 | short Y[], 171 | double factor, 172 | unsigned int *Time, 173 | unsigned short& Nx, 174 | unsigned short Nout, 175 | unsigned short Nwing, 176 | unsigned short LpScl, 177 | short Imp[], 178 | short ImpD[], 179 | bool Interp); 180 | 181 | int 182 | FilterUp( 183 | short Imp[], 184 | short ImpD[], 185 | unsigned short Nwing, 186 | bool Interp, 187 | short *Xp, 188 | short Ph, 189 | short Inc); 190 | 191 | int 192 | FilterUD( 193 | short Imp[], 194 | short ImpD[], 195 | unsigned short Nwing, 196 | bool Interp, 197 | short *Xp, 198 | short Ph, 199 | short Inc, 200 | unsigned short dhb); 201 | 202 | int 203 | resampleFast( /* number of output samples returned */ 204 | int& inCount, /* number of input samples to convert */ 205 | int outCount, /* number of output samples to compute */ 206 | short inArray[], /* input array data (length inCount * nChans) */ 207 | short outArray[]);/* output array data (length outCount * nChans) */ 208 | 209 | int 210 | resampleWithFilter( /* number of output samples returned */ 211 | int& inCount, /* number of input samples to convert */ 212 | int outCount, /* number of output samples to compute */ 213 | short inArray[], /* input array data (length inCount * nChans) */ 214 | short outArray[], /* output array data (length outCount * nChans) */ 215 | short Imp[], short ImpD[], 216 | unsigned short LpScl, unsigned short Nmult, unsigned short Nwing); 217 | 218 | 219 | static short SMALL_FILTER_IMP[]; 220 | static short LARGE_FILTER_IMP[]; 221 | 222 | bool interpFilt; 223 | bool largeFilter; 224 | bool linearInterp; 225 | short ** _II; 226 | short ** _JJ; 227 | unsigned int _Time; 228 | double _factor; 229 | int _nChans; 230 | bool _initial; 231 | double _vol; 232 | 233 | }; 234 | 235 | 236 | #endif 237 | -------------------------------------------------------------------------------- /src/PulseAudioDspSource.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Copyright (c) 2004 6 | LS Informationstechnik (LIKE) 7 | University of Erlangen Nuremberg 8 | All rights reserved. 9 | 10 | Tyrell DarkIce 11 | 12 | File : PulseAudioDspSource.cpp 13 | Version : $Revision: 553 $ 14 | Author : $Author: rafael@riseup.net $ 15 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/PulseAudioDspSource.cpp $ 16 | 17 | Copyright notice: 18 | 19 | This program is free software; you can redistribute it and/or 20 | modify it under the terms of the GNU General Public License 21 | as published by the Free Software Foundation; either version 2 22 | of the License, or (at your option) any later version. 23 | 24 | This program is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU General Public License for more details. 28 | 29 | You should have received a copy of the GNU General Public License 30 | along with this program; if not, write to the Free Software 31 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 32 | 33 | ------------------------------------------------------------------------------*/ 34 | 35 | /* ============================================================ include files */ 36 | 37 | #include "AudioSource.h" 38 | 39 | // compile only if configured for PULSEAUDIO 40 | #ifdef SUPPORT_PULSEAUDIO_DSP 41 | 42 | #ifdef HAVE_CONFIG_H 43 | #include "config.h" 44 | #endif 45 | 46 | #include "Util.h" 47 | #include "Exception.h" 48 | #include "PulseAudioDspSource.h" 49 | 50 | 51 | /* =================================================== local data structures */ 52 | 53 | 54 | /* ================================================ local constants & macros */ 55 | 56 | /*------------------------------------------------------------------------------ 57 | * File identity 58 | *----------------------------------------------------------------------------*/ 59 | static const char fileid[] = "$Id: PulseAudioDspSource.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 60 | 61 | 62 | /* =============================================== local function prototypes */ 63 | 64 | 65 | /* ============================================================= module code */ 66 | 67 | 68 | /*------------------------------------------------------------------------------ 69 | * Initialize the object 70 | *----------------------------------------------------------------------------*/ 71 | void 72 | PulseAudioDspSource :: init ( const char * paSourceName ) throw ( Exception ) 73 | { 74 | 75 | if (paSourceName == NULL) 76 | { 77 | throw Exception( __FILE__, __LINE__, "no paSourceName specified"); 78 | } 79 | Reporter::reportEvent( 1, "Using PulseAudio source: ", paSourceName); 80 | Util::strEq( paSourceName , "default" ); 81 | if (Util::strEq( paSourceName , "default" )) 82 | { 83 | sourceName = NULL; 84 | } 85 | else 86 | { 87 | sourceName = Util::strDup( paSourceName); 88 | } 89 | ss.channels = getChannel(); 90 | ss.rate = getSampleRate(); 91 | 92 | running = 0; 93 | 94 | //Supported for some bits per sample, both Big and Little endian 95 | if (isBigEndian()) 96 | { 97 | switch (getBitsPerSample()) 98 | { 99 | case 8: 100 | ss.format = PA_SAMPLE_U8; 101 | break; 102 | case 16: 103 | ss.format = PA_SAMPLE_S16BE; 104 | break; 105 | case 24: 106 | ss.format = PA_SAMPLE_S24BE; 107 | break; 108 | case 32: 109 | ss.format = PA_SAMPLE_S32BE; 110 | break; 111 | default: 112 | ss.format = PA_SAMPLE_INVALID; 113 | } 114 | } 115 | else 116 | { 117 | switch (getBitsPerSample()) 118 | { 119 | case 8: 120 | ss.format = PA_SAMPLE_U8; 121 | break; 122 | case 16: 123 | ss.format = PA_SAMPLE_S16LE; 124 | break; 125 | case 24: 126 | ss.format = PA_SAMPLE_S24LE; 127 | break; 128 | case 32: 129 | ss.format = PA_SAMPLE_S32LE; 130 | break; 131 | default: 132 | ss.format = PA_SAMPLE_INVALID; 133 | } 134 | } 135 | } 136 | 137 | 138 | /*------------------------------------------------------------------------------ 139 | * De-initialize the object 140 | *----------------------------------------------------------------------------*/ 141 | void 142 | PulseAudioDspSource :: strip ( void ) throw ( Exception ) 143 | { 144 | if ( isOpen() ) { 145 | close(); 146 | } 147 | 148 | delete[] sourceName; 149 | } 150 | 151 | 152 | /*------------------------------------------------------------------------------ 153 | * Open the audio source 154 | *----------------------------------------------------------------------------*/ 155 | bool 156 | PulseAudioDspSource :: open ( void ) throw ( Exception ) 157 | { 158 | 159 | char client_name[255]; 160 | 161 | //to identify each darkice on pulseaudio server 162 | snprintf(client_name, 255, "darkice-%d", getpid()); 163 | 164 | if (!(s = pa_simple_new(NULL, client_name, PA_STREAM_RECORD, sourceName, "darkice record", &ss, NULL, NULL, &error))) { 165 | throw Exception( __FILE__, __LINE__, ": pa_simple_new() failed: %s\n", pa_strerror(error)); 166 | } 167 | 168 | running = 1; 169 | 170 | return true; 171 | } 172 | 173 | 174 | /*------------------------------------------------------------------------------ 175 | * Check wether read() would return anything 176 | *----------------------------------------------------------------------------*/ 177 | bool 178 | PulseAudioDspSource :: canRead ( unsigned int sec, 179 | unsigned int usec ) throw ( Exception ) 180 | { 181 | 182 | /** Strange have to remove this, need to investigate... */ 183 | /* if ( !isOpen() ) { 184 | return false; 185 | } 186 | */ 187 | 188 | if (running == 0) { 189 | char client_name[255]; 190 | 191 | //to identify each darkice on pulseaudio server 192 | snprintf(client_name, 255, "darkice-%d", getpid()); 193 | 194 | if (!(s = pa_simple_new(NULL, client_name, PA_STREAM_RECORD, sourceName, "darkice record", &ss, NULL, NULL, &error))) { 195 | throw Exception( __FILE__, __LINE__, ": pa_simple_new() failed: %s\n", pa_strerror(error)); 196 | } 197 | 198 | running = 1; 199 | } 200 | 201 | return true; 202 | } 203 | 204 | 205 | /*------------------------------------------------------------------------------ 206 | * Read from the audio source 207 | *----------------------------------------------------------------------------*/ 208 | unsigned int 209 | PulseAudioDspSource :: read ( void * buf, 210 | unsigned int len ) throw ( Exception ) 211 | { 212 | int ret; 213 | 214 | ret = pa_simple_read(s, buf, len, &error); 215 | if ( ret < 0) { 216 | throw Exception(__FILE__, __LINE__, ": pa_simple_read() failed: %s\n", pa_strerror(error)); 217 | } 218 | return len; 219 | } 220 | 221 | 222 | /*------------------------------------------------------------------------------ 223 | * Close the audio source 224 | *----------------------------------------------------------------------------*/ 225 | void 226 | PulseAudioDspSource :: close ( void ) throw ( Exception ) 227 | { 228 | if ( !isOpen() ) { 229 | return; 230 | } 231 | 232 | pa_simple_free(s); 233 | running = 0; 234 | } 235 | 236 | #endif // HAVE_PULSEAUDIO_LIB 237 | -------------------------------------------------------------------------------- /src/SolarisDspSource.cpp: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : SolarisDspSource.cpp 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/SolarisDspSource.cpp $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | 30 | /* ============================================================ include files */ 31 | 32 | #include "SolarisDspSource.h" 33 | 34 | #ifdef SUPPORT_SOLARIS_DSP 35 | // only compile this code if there is support for it 36 | 37 | #ifdef HAVE_CONFIG_H 38 | #include "config.h" 39 | #endif 40 | 41 | #ifdef HAVE_UNISTD_H 42 | #include 43 | #else 44 | #error need unistd.h 45 | #endif 46 | 47 | #ifdef HAVE_STRING_H 48 | #include 49 | #else 50 | #error need string.h 51 | #endif 52 | 53 | #ifdef HAVE_SYS_TYPES_H 54 | #include 55 | #else 56 | #error need sys/types.h 57 | #endif 58 | 59 | #ifdef HAVE_SYS_STAT_H 60 | #include 61 | #else 62 | #error need sys/stat.h 63 | #endif 64 | 65 | #ifdef HAVE_FCNTL_H 66 | #include 67 | #else 68 | #error need fcntl.h 69 | #endif 70 | 71 | #ifdef HAVE_SYS_TIME_H 72 | #include 73 | #else 74 | #error need sys/time.h 75 | #endif 76 | 77 | #ifdef HAVE_SYS_IOCTL_H 78 | #include 79 | #else 80 | #error need sys/ioctl.h 81 | #endif 82 | 83 | #ifdef HAVE_SIGNAL_H 84 | #include 85 | #else 86 | #error need signal.h 87 | #endif 88 | 89 | #if defined( HAVE_SYS_AUDIO_H ) 90 | #include 91 | #elif defined( HAVE_SYS_AUDIOIO_H ) 92 | #include 93 | #else 94 | #error need sys/audio.h or sys/audioio.h 95 | #endif 96 | 97 | 98 | #include "Util.h" 99 | #include "Exception.h" 100 | #include "SolarisDspSource.h" 101 | 102 | 103 | /* =================================================== local data structures */ 104 | 105 | 106 | /* ================================================ local constants & macros */ 107 | 108 | /*------------------------------------------------------------------------------ 109 | * File identity 110 | *----------------------------------------------------------------------------*/ 111 | static const char fileid[] = "$Id: SolarisDspSource.cpp 553 2013-07-15 05:50:56Z rafael@riseup.net $"; 112 | 113 | 114 | /* =============================================== local function prototypes */ 115 | 116 | 117 | /* ============================================================= module code */ 118 | 119 | /*------------------------------------------------------------------------------ 120 | * Initialize the object 121 | *----------------------------------------------------------------------------*/ 122 | void 123 | SolarisDspSource :: init ( const char * name ) throw ( Exception ) 124 | { 125 | fileName = Util::strDup( name); 126 | fileDescriptor = 0; 127 | } 128 | 129 | 130 | /*------------------------------------------------------------------------------ 131 | * De-initialize the object 132 | *----------------------------------------------------------------------------*/ 133 | void 134 | SolarisDspSource :: strip ( void ) throw ( Exception ) 135 | { 136 | if ( isOpen() ) { 137 | close(); 138 | } 139 | 140 | delete[] fileName; 141 | } 142 | 143 | #include 144 | 145 | /*------------------------------------------------------------------------------ 146 | * Open the audio source 147 | *----------------------------------------------------------------------------*/ 148 | bool 149 | SolarisDspSource :: open ( void ) throw ( Exception ) 150 | { 151 | audio_info_t audioInfo; 152 | 153 | if ( isOpen() ) { 154 | return false; 155 | } 156 | 157 | if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) { 158 | fileDescriptor = 0; 159 | return false; 160 | } 161 | 162 | AUDIO_INITINFO( &audioInfo); 163 | audioInfo.record.sample_rate = getSampleRate(); 164 | audioInfo.record.channels = getChannel(); 165 | audioInfo.record.precision = getBitsPerSample(); 166 | audioInfo.record.encoding = AUDIO_ENCODING_LINEAR; 167 | // for stupid OpenBSD we need to add the following, as it masks 168 | // read/write calls when using -pthread 169 | audioInfo.record.pause = 0; 170 | 171 | if ( ioctl( fileDescriptor, AUDIO_SETINFO, &audioInfo) == -1 ) { 172 | 173 | close(); 174 | throw Exception( __FILE__, __LINE__, "ioctl error"); 175 | } 176 | 177 | if ( audioInfo.record.channels != getChannel() ) { 178 | close(); 179 | throw Exception( __FILE__, __LINE__, 180 | "can't set channels", audioInfo.record.channels); 181 | } 182 | 183 | if ( audioInfo.record.precision != getBitsPerSample() ) { 184 | close(); 185 | throw Exception( __FILE__, __LINE__, 186 | "can't set bits per sample", 187 | audioInfo.record.precision); 188 | } 189 | 190 | if ( audioInfo.record.sample_rate != getSampleRate() ) { 191 | reportEvent( 2, "sound card recording sample rate set to ", 192 | audioInfo.record.sample_rate, 193 | " while trying to set it to ", getSampleRate()); 194 | reportEvent( 2, "this is probably not a problem, but a slight " 195 | "drift in the sound card driver"); 196 | } 197 | 198 | 199 | return true; 200 | } 201 | 202 | 203 | /*------------------------------------------------------------------------------ 204 | * Check wether read() would return anything 205 | *----------------------------------------------------------------------------*/ 206 | bool 207 | SolarisDspSource :: canRead ( unsigned int sec, 208 | unsigned int usec ) throw ( Exception ) 209 | { 210 | fd_set fdset; 211 | struct timespec timespec; 212 | sigset_t sigset; 213 | int ret; 214 | 215 | if ( !isOpen() ) { 216 | return false; 217 | } 218 | 219 | FD_ZERO( &fdset); 220 | FD_SET( fileDescriptor, &fdset); 221 | 222 | timespec.tv_sec = sec; 223 | timespec.tv_nsec = usec * 1000L; 224 | 225 | // mask out SIGUSR1, as we're expecting that signal for other reasons 226 | sigemptyset(&sigset); 227 | sigaddset(&sigset, SIGUSR1); 228 | 229 | ret = pselect( fileDescriptor + 1, &fdset, NULL, NULL, ×pec, &sigset); 230 | 231 | if ( ret == -1 ) { 232 | throw Exception( __FILE__, __LINE__, "select error"); 233 | } 234 | 235 | return ret > 0; 236 | } 237 | 238 | 239 | /*------------------------------------------------------------------------------ 240 | * Read from the audio source 241 | *----------------------------------------------------------------------------*/ 242 | unsigned int 243 | SolarisDspSource :: read ( void * buf, 244 | unsigned int len ) throw ( Exception ) 245 | { 246 | ssize_t ret; 247 | 248 | if ( !isOpen() ) { 249 | return 0; 250 | } 251 | 252 | ret = ::read( fileDescriptor, buf, len); 253 | 254 | if ( ret == -1 ) { 255 | throw Exception( __FILE__, __LINE__, "read error"); 256 | } 257 | 258 | return ret; 259 | } 260 | 261 | 262 | /*------------------------------------------------------------------------------ 263 | * Close the audio source 264 | *----------------------------------------------------------------------------*/ 265 | void 266 | SolarisDspSource :: close ( void ) throw ( Exception ) 267 | { 268 | if ( !isOpen() ) { 269 | return; 270 | } 271 | 272 | ::close( fileDescriptor); 273 | fileDescriptor = 0; 274 | } 275 | 276 | #endif // SUPPORT_SOLARIS_DSP 277 | 278 | -------------------------------------------------------------------------------- /src/OssDspSource.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : OssDspSource.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/OssDspSource.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef OSS_DSP_SOURCE_H 30 | #define OSS_DSP_SOURCE_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Reporter.h" 40 | #include "AudioSource.h" 41 | 42 | 43 | /* ================================================================ constants */ 44 | 45 | 46 | /* =================================================================== macros */ 47 | 48 | 49 | /* =============================================================== data types */ 50 | 51 | /** 52 | * An audio input based on /dev/dsp-like raw devices 53 | * 54 | * @author $Author: rafael@riseup.net $ 55 | * @version $Revision: 553 $ 56 | */ 57 | class OssDspSource : public AudioSource, public virtual Reporter 58 | { 59 | private: 60 | 61 | /** 62 | * The file name of the OSS DSP device (e.g. /dev/dsp or /dev/dsp0). 63 | */ 64 | char * fileName; 65 | 66 | /** 67 | * The low-level file descriptor of the OSS DSP device. 68 | */ 69 | int fileDescriptor; 70 | 71 | /** 72 | * Indicates wether the low-level OSS DSP device is in a recording 73 | * state. 74 | */ 75 | bool running; 76 | 77 | 78 | protected: 79 | 80 | /** 81 | * Default constructor. Always throws an Exception. 82 | * 83 | * @exception Exception 84 | */ 85 | inline 86 | OssDspSource ( void ) throw ( Exception ) 87 | { 88 | throw Exception( __FILE__, __LINE__); 89 | } 90 | 91 | /** 92 | * Initialize the object 93 | * 94 | * @param name the file name of the OSS DSP device. 95 | * @exception Exception 96 | */ 97 | void 98 | init ( const char * name ) throw ( Exception ); 99 | 100 | /** 101 | * De-iitialize the object 102 | * 103 | * @exception Exception 104 | */ 105 | void 106 | strip ( void ) throw ( Exception ); 107 | 108 | 109 | public: 110 | 111 | /** 112 | * Constructor. 113 | * 114 | * @param name the file name of the OSS DSP device 115 | * (e.g. /dev/dsp or /dev/dsp0). 116 | * @param sampleRate samples per second (e.g. 44100 for 44.1kHz). 117 | * @param bitsPerSample bits per sample (e.g. 16 bits). 118 | * @param channel number of channels of the audio source 119 | * (e.g. 1 for mono, 2 for stereo, etc.). 120 | * @exception Exception 121 | */ 122 | inline 123 | OssDspSource ( const char * name, 124 | int sampleRate = 44100, 125 | int bitsPerSample = 16, 126 | int channel = 2 ) 127 | throw ( Exception ) 128 | 129 | : AudioSource( sampleRate, bitsPerSample, channel) 130 | { 131 | init( name); 132 | } 133 | 134 | /** 135 | * Copy Constructor. 136 | * 137 | * @param ods the object to copy. 138 | * @exception Exception 139 | */ 140 | inline 141 | OssDspSource ( const OssDspSource & ods ) throw ( Exception ) 142 | : AudioSource( ods ) 143 | { 144 | init( ods.fileName); 145 | } 146 | 147 | /** 148 | * Destructor. 149 | * 150 | * @exception Exception 151 | */ 152 | inline virtual 153 | ~OssDspSource ( void ) throw ( Exception ) 154 | { 155 | strip(); 156 | } 157 | 158 | /** 159 | * Assignment operator. 160 | * 161 | * @param ds the object to assign to this one. 162 | * @return a reference to this object. 163 | * @exception Exception 164 | */ 165 | inline virtual OssDspSource & 166 | operator= ( const OssDspSource & ds ) throw ( Exception ) 167 | { 168 | if ( this != &ds ) { 169 | strip(); 170 | AudioSource::operator=( ds); 171 | init( ds.fileName); 172 | } 173 | return *this; 174 | } 175 | 176 | /** 177 | * Tell if the data from this source comes in big or little endian. 178 | * 179 | * @return true if the source is big endian, false otherwise 180 | */ 181 | virtual bool 182 | isBigEndian ( void ) const throw (); 183 | 184 | /** 185 | * Open the OssDspSource. 186 | * This does not put the OSS DSP device into recording mode. 187 | * To start getting samples, call either canRead() or read(). 188 | * 189 | * @return true if opening was successful, false otherwise 190 | * @exception Exception 191 | * 192 | * @see #canRead 193 | * @see #read 194 | */ 195 | virtual bool 196 | open ( void ) throw ( Exception ); 197 | 198 | /** 199 | * Check if the OssDspSource is open. 200 | * 201 | * @return true if the OssDspSource is open, false otherwise. 202 | */ 203 | inline virtual bool 204 | isOpen ( void ) const throw () 205 | { 206 | return fileDescriptor != 0; 207 | } 208 | 209 | /** 210 | * Check if the OssDspSource can be read from. 211 | * Blocks until the specified time for data to be available. 212 | * Puts the OSS DSP device into recording mode. 213 | * 214 | * @param sec the maximum seconds to block. 215 | * @param usec micro seconds to block after the full seconds. 216 | * @return true if the OssDspSource is ready to be read from, 217 | * false otherwise. 218 | * @exception Exception 219 | */ 220 | virtual bool 221 | canRead ( unsigned int sec, 222 | unsigned int usec ) throw ( Exception ); 223 | 224 | /** 225 | * Read from the OssDspSource. 226 | * Puts the OSS DSP device into recording mode. 227 | * 228 | * @param buf the buffer to read into. 229 | * @param len the number of bytes to read into buf 230 | * @return the number of bytes read (may be less than len). 231 | * @exception Exception 232 | */ 233 | virtual unsigned int 234 | read ( void * buf, 235 | unsigned int len ) throw ( Exception ); 236 | 237 | /** 238 | * Close the OssDspSource. 239 | * 240 | * @exception Exception 241 | */ 242 | virtual void 243 | close ( void ) throw ( Exception ); 244 | }; 245 | 246 | 247 | /* ================================================= external data structures */ 248 | 249 | 250 | /* ====================================================== function prototypes */ 251 | 252 | 253 | 254 | #endif /* OSS_DSP_SOURCE_H */ 255 | 256 | -------------------------------------------------------------------------------- /src/SerialUlaw.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | Copyright (c) 2007 Clyde Stubbs 5 | 6 | Tyrell DarkIce 7 | 8 | File : SerialUlaw.h 9 | Version : $Revision: 553 $ 10 | Author : $Author: rafael@riseup.net $ 11 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/SerialUlaw.h $ 12 | 13 | Copyright notice: 14 | 15 | This program is free software; you can redistribute it and/or 16 | modify it under the terms of the GNU General Public License 17 | as published by the Free Software Foundation; either version 3 18 | of the License, or (at your option) any later version. 19 | 20 | This program is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | GNU General Public License for more details. 24 | 25 | You should have received a copy of the GNU General Public License 26 | along with this program; if not, write to the Free Software 27 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 | 29 | ------------------------------------------------------------------------------*/ 30 | #ifndef SERIAL_ULAW_SOURCE_H 31 | #define SERIAL_ULAW_SOURCE_H 32 | 33 | #ifndef __cplusplus 34 | #error This is a C++ include file 35 | #endif 36 | 37 | 38 | /* ============================================================ include files */ 39 | 40 | #include "Reporter.h" 41 | #include "AudioSource.h" 42 | 43 | 44 | /* ================================================================ constants */ 45 | 46 | 47 | /* =================================================================== macros */ 48 | 49 | 50 | /* =============================================================== data types */ 51 | 52 | /** 53 | * An audio input based on /dev/dsp-like raw devices 54 | * 55 | * @author $Author: rafael@riseup.net $ 56 | * @version $Revision: 553 $ 57 | */ 58 | class SerialUlaw : public AudioSource, public virtual Reporter 59 | { 60 | private: 61 | 62 | /** 63 | * The file name of the OSS DSP device (e.g. /dev/dsp or /dev/dsp0). 64 | */ 65 | char * fileName; 66 | 67 | /** 68 | * The low-level file descriptor of the OSS DSP device. 69 | */ 70 | int fileDescriptor; 71 | 72 | /** 73 | * Indicates wether the low-level OSS DSP device is in a recording 74 | * state. 75 | */ 76 | bool running; 77 | 78 | 79 | protected: 80 | 81 | /** 82 | * Default constructor. Always throws an Exception. 83 | * 84 | * @exception Exception 85 | */ 86 | inline 87 | SerialUlaw ( void ) throw ( Exception ) 88 | { 89 | throw Exception( __FILE__, __LINE__); 90 | } 91 | 92 | /** 93 | * Initialize the object 94 | * 95 | * @param name the file name of the OSS DSP device. 96 | * @exception Exception 97 | */ 98 | void 99 | init ( const char * name ) throw ( Exception ); 100 | 101 | /** 102 | * De-iitialize the object 103 | * 104 | * @exception Exception 105 | */ 106 | void 107 | strip ( void ) throw ( Exception ); 108 | 109 | 110 | public: 111 | 112 | /** 113 | * Constructor. 114 | * 115 | * @param name the file name of the OSS DSP device 116 | * (e.g. /dev/dsp or /dev/dsp0). 117 | * @param sampleRate samples per second (e.g. 44100 for 44.1kHz). 118 | * @param bitsPerSample bits per sample (e.g. 16 bits). 119 | * @param channel number of channels of the audio source 120 | * (e.g. 1 for mono, 2 for stereo, etc.). 121 | * @exception Exception 122 | */ 123 | inline 124 | SerialUlaw ( const char * name, 125 | int sampleRate = 44100, 126 | int bitsPerSample = 16, 127 | int channel = 2 ) 128 | throw ( Exception ) 129 | 130 | : AudioSource( sampleRate, bitsPerSample, channel) 131 | { 132 | init( name); 133 | } 134 | 135 | /** 136 | * Copy Constructor. 137 | * 138 | * @param ods the object to copy. 139 | * @exception Exception 140 | */ 141 | inline 142 | SerialUlaw ( const SerialUlaw & ods ) throw ( Exception ) 143 | : AudioSource( ods ) 144 | { 145 | init( ods.fileName); 146 | } 147 | 148 | /** 149 | * Destructor. 150 | * 151 | * @exception Exception 152 | */ 153 | inline virtual 154 | ~SerialUlaw ( void ) throw ( Exception ) 155 | { 156 | strip(); 157 | } 158 | 159 | /** 160 | * Assignment operator. 161 | * 162 | * @param ds the object to assign to this one. 163 | * @return a reference to this object. 164 | * @exception Exception 165 | */ 166 | inline virtual SerialUlaw & 167 | operator= ( const SerialUlaw & ds ) throw ( Exception ) 168 | { 169 | if ( this != &ds ) { 170 | strip(); 171 | AudioSource::operator=( ds); 172 | init( ds.fileName); 173 | } 174 | return *this; 175 | } 176 | 177 | /** 178 | * Tell if the data from this source comes in big or little endian. 179 | * 180 | * @return true if the source is big endian, false otherwise 181 | */ 182 | virtual bool 183 | isBigEndian ( void ) const throw (); 184 | 185 | /** 186 | * Open the SerialUlaw. 187 | * This does not put the OSS DSP device into recording mode. 188 | * To start getting samples, call either canRead() or read(). 189 | * 190 | * @return true if opening was successful, false otherwise 191 | * @exception Exception 192 | * 193 | * @see #canRead 194 | * @see #read 195 | */ 196 | virtual bool 197 | open ( void ) throw ( Exception ); 198 | 199 | /** 200 | * Check if the SerialUlaw is open. 201 | * 202 | * @return true if the SerialUlaw is open, false otherwise. 203 | */ 204 | inline virtual bool 205 | isOpen ( void ) const throw () 206 | { 207 | return fileDescriptor != 0; 208 | } 209 | 210 | /** 211 | * Check if the SerialUlaw can be read from. 212 | * Blocks until the specified time for data to be available. 213 | * Puts the OSS DSP device into recording mode. 214 | * 215 | * @param sec the maximum seconds to block. 216 | * @param usec micro seconds to block after the full seconds. 217 | * @return true if the SerialUlaw is ready to be read from, 218 | * false otherwise. 219 | * @exception Exception 220 | */ 221 | virtual bool 222 | canRead ( unsigned int sec, 223 | unsigned int usec ) throw ( Exception ); 224 | 225 | /** 226 | * Read from the SerialUlaw. 227 | * Puts the OSS DSP device into recording mode. 228 | * 229 | * @param buf the buffer to read into. 230 | * @param len the number of bytes to read into buf 231 | * @return the number of bytes read (may be less than len). 232 | * @exception Exception 233 | */ 234 | virtual unsigned int 235 | read ( void * buf, 236 | unsigned int len ) throw ( Exception ); 237 | 238 | /** 239 | * Close the SerialUlaw. 240 | * 241 | * @exception Exception 242 | */ 243 | virtual void 244 | close ( void ) throw ( Exception ); 245 | }; 246 | 247 | 248 | /* ================================================= external data structures */ 249 | 250 | 251 | /* ====================================================== function prototypes */ 252 | 253 | 254 | 255 | #endif /* SERIAL_ULAW_SOURCE_H */ 256 | -------------------------------------------------------------------------------- /src/SolarisDspSource.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : SolarisDspSource.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/SolarisDspSource.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef SOLARIS_DSP_SOURCE_H 30 | #define SOLARIS_DSP_SOURCE_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Reporter.h" 40 | #include "AudioSource.h" 41 | 42 | 43 | /* ================================================================ constants */ 44 | 45 | 46 | /* =================================================================== macros */ 47 | 48 | 49 | /* =============================================================== data types */ 50 | 51 | /** 52 | * An audio input based on Solaris /dev/audio devices 53 | * 54 | * @author $Author: rafael@riseup.net $ 55 | * @version $Revision: 553 $ 56 | */ 57 | class SolarisDspSource : public AudioSource, public virtual Reporter 58 | { 59 | private: 60 | 61 | /** 62 | * The file name of the OSS DSP device (e.g. /dev/audio) 63 | */ 64 | char * fileName; 65 | 66 | /** 67 | * The low-level file descriptor of the Solaris DSP device. 68 | */ 69 | int fileDescriptor; 70 | 71 | 72 | protected: 73 | 74 | /** 75 | * Default constructor. Always throws an Exception. 76 | * 77 | * @exception Exception 78 | */ 79 | inline 80 | SolarisDspSource ( void ) throw ( Exception ) 81 | { 82 | throw Exception( __FILE__, __LINE__); 83 | } 84 | 85 | /** 86 | * Initialize the object 87 | * 88 | * @param name the file name of the Solaris DSP device. 89 | * @exception Exception 90 | */ 91 | void 92 | init ( const char * name ) throw ( Exception ); 93 | 94 | /** 95 | * De-iitialize the object 96 | * 97 | * @exception Exception 98 | */ 99 | void 100 | strip ( void ) throw ( Exception ); 101 | 102 | 103 | public: 104 | 105 | /** 106 | * Constructor. 107 | * 108 | * @param name the file name of the Solaris DSP device 109 | * (e.g. /dev/audio or /dev/sound/0) 110 | * @param sampleRate samples per second (e.g. 44100 for 44.1kHz). 111 | * @param bitsPerSample bits per sample (e.g. 16 bits). 112 | * @param channel number of channels of the audio source 113 | * (e.g. 1 for mono, 2 for stereo, etc.). 114 | * @exception Exception 115 | */ 116 | inline 117 | SolarisDspSource ( const char * name, 118 | int sampleRate = 44100, 119 | int bitsPerSample = 16, 120 | int channel = 2 ) 121 | throw ( Exception ) 122 | 123 | : AudioSource( sampleRate, bitsPerSample, channel) 124 | { 125 | init( name); 126 | } 127 | 128 | /** 129 | * Copy Constructor. 130 | * 131 | * @param sds the object to copy. 132 | * @exception Exception 133 | */ 134 | inline 135 | SolarisDspSource ( const SolarisDspSource & sds ) 136 | throw ( Exception ) 137 | : AudioSource( sds ) 138 | { 139 | init( sds.fileName); 140 | } 141 | 142 | /** 143 | * Destructor. 144 | * 145 | * @exception Exception 146 | */ 147 | inline virtual 148 | ~SolarisDspSource ( void ) throw ( Exception ) 149 | { 150 | strip(); 151 | } 152 | 153 | /** 154 | * Assignment operator. 155 | * 156 | * @param ds the object to assign to this one. 157 | * @return a reference to this object. 158 | * @exception Exception 159 | */ 160 | inline virtual SolarisDspSource & 161 | operator= ( const SolarisDspSource & ds ) throw ( Exception ) 162 | { 163 | if ( this != &ds ) { 164 | strip(); 165 | AudioSource::operator=( ds); 166 | init( ds.fileName); 167 | } 168 | return *this; 169 | } 170 | 171 | /** 172 | * Tell if the data from this source comes in big or little endian. 173 | * 174 | * @return true 175 | */ 176 | virtual inline bool 177 | isBigEndian ( void ) const throw () 178 | { 179 | #ifdef WORDS_BIGENDIAN 180 | return true; 181 | #else 182 | return false; 183 | #endif 184 | } 185 | 186 | /** 187 | * Open the SolarisDspSource. 188 | * This does not put the Solaris DSP device into recording mode. 189 | * To start getting samples, call either canRead() or read(). 190 | * 191 | * @return true if opening was successful, false otherwise 192 | * @exception Exception 193 | * 194 | * @see #canRead 195 | * @see #read 196 | */ 197 | virtual bool 198 | open ( void ) throw ( Exception ); 199 | 200 | /** 201 | * Check if the SolarisDspSource is open. 202 | * 203 | * @return true if the SolarisDspSource is open, false otherwise. 204 | */ 205 | inline virtual bool 206 | isOpen ( void ) const throw () 207 | { 208 | return fileDescriptor != 0; 209 | } 210 | 211 | /** 212 | * Check if the SolarisDspSource can be read from. 213 | * Blocks until the specified time for data to be available. 214 | * Puts the Solaris DSP device into recording mode. 215 | * 216 | * @param sec the maximum seconds to block. 217 | * @param usec micro seconds to block after the full seconds. 218 | * @return true if the SolarisDspSource is ready to be read from, 219 | * false otherwise. 220 | * @exception Exception 221 | */ 222 | virtual bool 223 | canRead ( unsigned int sec, 224 | unsigned int usec ) throw ( Exception ); 225 | 226 | /** 227 | * Read from the SolarisDspSource. 228 | * Puts the Solaris DSP device into recording mode. 229 | * 230 | * @param buf the buffer to read into. 231 | * @param len the number of bytes to read into buf 232 | * @return the number of bytes read (may be less than len). 233 | * @exception Exception 234 | */ 235 | virtual unsigned int 236 | read ( void * buf, 237 | unsigned int len ) throw ( Exception ); 238 | 239 | /** 240 | * Close the SolarisDspSource. 241 | * 242 | * @exception Exception 243 | */ 244 | virtual void 245 | close ( void ) throw ( Exception ); 246 | }; 247 | 248 | 249 | /* ================================================= external data structures */ 250 | 251 | 252 | /* ====================================================== function prototypes */ 253 | 254 | 255 | 256 | #endif /* SOLARIS_DSP_SOURCE_H */ 257 | 258 | -------------------------------------------------------------------------------- /src/IceCast2.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : IceCast2.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/IceCast2.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef ICE_CAST2_H 30 | #define ICE_CAST2_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Sink.h" 40 | #include "TcpSocket.h" 41 | #include "CastSink.h" 42 | #include "FileSink.h" /* modified */ 43 | 44 | 45 | 46 | /* ================================================================ constants */ 47 | 48 | 49 | /* =================================================================== macros */ 50 | 51 | 52 | /* =============================================================== data types */ 53 | 54 | /** 55 | * Class representing output to an IceCast2 server with 56 | * ice login 57 | * 58 | * @author $Author: rafael@riseup.net $ 59 | * @version $Revision: 553 $ 60 | */ 61 | class IceCast2 : public CastSink 62 | { 63 | public: 64 | 65 | /** 66 | * Type for specifying the format of the stream. 67 | */ 68 | enum StreamFormat { mp3, mp2, oggVorbis, oggOpus, aac, aacp }; 69 | 70 | 71 | private: 72 | 73 | /** 74 | * The format of the stream. 75 | */ 76 | StreamFormat format; 77 | 78 | /** 79 | * Mount point of the stream on the server. 80 | */ 81 | char * mountPoint; 82 | 83 | /** 84 | * Description of the stream. 85 | */ 86 | char * description; 87 | 88 | /** 89 | * Initalize the object. 90 | * 91 | * @param mountPoint mount point of the stream on the server. 92 | * @param remoteDumpFile remote dump file (may be NULL). 93 | * @param description description of the stream. 94 | * @exception Exception 95 | */ 96 | void 97 | init ( StreamFormat format, 98 | const char * mountPoint, 99 | const char * description ) 100 | throw ( Exception ); 101 | 102 | /** 103 | * De-initalize the object. 104 | * 105 | * @exception Exception 106 | */ 107 | void 108 | strip ( void ) throw ( Exception ); 109 | 110 | 111 | protected: 112 | 113 | /** 114 | * Default constructor. Always throws an Exception. 115 | * 116 | * @exception Exception 117 | */ 118 | inline 119 | IceCast2 ( void ) throw ( Exception ) 120 | { 121 | throw Exception( __FILE__, __LINE__); 122 | } 123 | 124 | /** 125 | * Log in to the server using the socket avialable. 126 | * 127 | * @return true if login was successful, false otherwise. 128 | * @exception Exception 129 | */ 130 | virtual bool 131 | sendLogin ( void ) throw ( Exception ); 132 | 133 | 134 | public: 135 | 136 | /** 137 | * Constructor. 138 | * 139 | * @param socket socket connection to the server. 140 | * @param password password to the server. 141 | * @param mountPoint mount point of the stream on the server. 142 | * @param format the format of the stream. 143 | * @param name name of the stream. 144 | * @param description description of the stream. 145 | * @param url URL associated with the stream. 146 | * @param genre genre of the stream. 147 | * @param bitRate bitrate of the stream (e.g. mp3 bitrate). 148 | * @param isPublic is the stream public? 149 | * @param streamDump an optional sink to dump the binary stream 150 | * data to. 151 | * @param bufferDuration duration of the BufferedSink buffer 152 | * in seconds. 153 | * @exception Exception 154 | */ 155 | inline 156 | IceCast2 ( TcpSocket * socket, 157 | const char * password, 158 | const char * mountPoint, 159 | StreamFormat format, 160 | unsigned int bitRate, 161 | const char * name = 0, 162 | const char * description = 0, 163 | const char * url = 0, 164 | const char * genre = 0, 165 | bool isPublic = false, 166 | Sink * streamDump = 0 ) 167 | throw ( Exception ) 168 | : CastSink( socket, 169 | password, 170 | bitRate, 171 | name, 172 | url, 173 | genre, 174 | isPublic, 175 | streamDump ) 176 | { 177 | init( format, mountPoint, description); 178 | } 179 | 180 | /** 181 | * Copy constructor. 182 | * 183 | * @param cs the IceCast2 to copy. 184 | */ 185 | inline 186 | IceCast2( const IceCast2 & cs ) throw ( Exception ) 187 | : CastSink( cs ) 188 | { 189 | init( cs.getFormat(), 190 | cs.getMountPoint(), 191 | cs.getDescription() ); 192 | } 193 | 194 | /** 195 | * Destructor. 196 | * 197 | * @exception Exception 198 | */ 199 | inline virtual 200 | ~IceCast2( void ) throw ( Exception ) 201 | { 202 | strip(); 203 | } 204 | 205 | /** 206 | * Assignment operator. 207 | * 208 | * @param cs the IceCast2 to assign this to. 209 | * @return a reference to this IceCast2. 210 | * @exception Exception 211 | */ 212 | inline virtual IceCast2 & 213 | operator= ( const IceCast2 & cs ) throw ( Exception ) 214 | { 215 | if ( this != &cs ) { 216 | strip(); 217 | CastSink::operator=( cs ); 218 | init( cs.getFormat(), 219 | cs.getMountPoint(), 220 | cs.getDescription() ); 221 | } 222 | return *this; 223 | } 224 | 225 | /** 226 | * Get the format of the stream. 227 | * 228 | * @return the format of the stream. 229 | */ 230 | inline StreamFormat 231 | getFormat ( void ) const throw () 232 | { 233 | return format; 234 | } 235 | 236 | /** 237 | * Get the mount point of the stream on the server. 238 | * 239 | * @return the mount point of the stream on the server. 240 | */ 241 | inline const char * 242 | getMountPoint ( void ) const throw () 243 | { 244 | return mountPoint; 245 | } 246 | 247 | /** 248 | * Get the description of the stream. 249 | * 250 | * @return the description of the stream. 251 | */ 252 | inline const char * 253 | getDescription ( void ) const throw () 254 | { 255 | return description; 256 | } 257 | 258 | }; 259 | 260 | 261 | /* ================================================= external data structures */ 262 | 263 | 264 | /* ====================================================== function prototypes */ 265 | 266 | 267 | 268 | #endif /* ICE_CAST2_H */ 269 | 270 | -------------------------------------------------------------------------------- /src/Connector.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : Connector.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Connector.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef CONNECTOR_H 30 | #define CONNECTOR_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Referable.h" 40 | #include "Ref.h" 41 | #include "Reporter.h" 42 | #include "Source.h" 43 | #include "Sink.h" 44 | 45 | 46 | /* ================================================================ constants */ 47 | 48 | 49 | /* =================================================================== macros */ 50 | 51 | 52 | /* =============================================================== data types */ 53 | 54 | /** 55 | * Connects a source to one or more sinks. 56 | * 57 | * @author $Author: rafael@riseup.net $ 58 | * @version $Revision: 553 $ 59 | */ 60 | class Connector : public virtual Referable, public virtual Reporter 61 | { 62 | private: 63 | 64 | /** 65 | * Initialize the object. 66 | * 67 | * @param source the source to read from. 68 | * @exception Exception 69 | */ 70 | void 71 | init ( Source * source ) throw ( Exception ); 72 | 73 | /** 74 | * De-initialize the object. 75 | * 76 | * @exception Exception 77 | */ 78 | void 79 | strip ( void ) throw ( Exception ); 80 | 81 | 82 | protected: 83 | 84 | /** 85 | * The source to read from. 86 | */ 87 | Ref source; 88 | 89 | /** 90 | * The sinks to connect the source to. 91 | */ 92 | Ref * sinks; 93 | 94 | /** 95 | * Total number of sinks. 96 | */ 97 | unsigned int numSinks; 98 | 99 | /** 100 | * Default constructor. Always throws an Exception. 101 | * 102 | * @exception Exception 103 | */ 104 | inline 105 | Connector ( void ) throw ( Exception ) 106 | { 107 | throw Exception( __FILE__, __LINE__); 108 | } 109 | 110 | /** 111 | * Detach an already attached Sink from the Source of this Connector. 112 | * 113 | * @param sink the Sink to detach. 114 | * @return true if the detachment was successful, false otherwise. 115 | * @exception Exception 116 | */ 117 | virtual bool 118 | detach ( Sink * sink ) throw ( Exception ); 119 | 120 | 121 | public: 122 | 123 | /** 124 | * Constructor based on a Source. 125 | * 126 | * @param source the source to connect to the sinks. 127 | * @exception Exception 128 | */ 129 | inline 130 | Connector ( Source * source ) throw ( Exception ) 131 | { 132 | init( source); 133 | } 134 | 135 | /** 136 | * Constructor based on a Source and a Sink. 137 | * 138 | * @param source the source to connect to the sinks. 139 | * @param sink a sink to connect to the source. 140 | * @exception Exception 141 | */ 142 | inline 143 | Connector ( Source * source, 144 | Sink * sink ) throw ( Exception ) 145 | { 146 | init( source); 147 | attach( sink); 148 | } 149 | 150 | /** 151 | * Copy constructor. 152 | * 153 | * @param connector the object to copy. 154 | * @exception Exception 155 | */ 156 | Connector ( const Connector & connector ) throw ( Exception ); 157 | 158 | /** 159 | * Destructor. 160 | * 161 | * @exception Exception 162 | */ 163 | inline virtual 164 | ~Connector( void ) throw ( Exception ) 165 | { 166 | strip(); 167 | } 168 | 169 | /** 170 | * Assignment operator. 171 | * 172 | * @param connector the object to assign to this one. 173 | * @return a reference to this object. 174 | * @exception Exception 175 | */ 176 | virtual Connector & 177 | operator= ( const Connector & connector ) throw ( Exception ); 178 | 179 | /** 180 | * Get the number of Sinks in the Connector. 181 | * 182 | * @return the number of Sinks in the Connector. 183 | * @exception Exception 184 | */ 185 | inline virtual unsigned int 186 | getNumSinks ( void ) const throw () 187 | { 188 | return numSinks; 189 | } 190 | 191 | /** 192 | * Attach a Sink to the Source of this Connector. 193 | * 194 | * @param sink the Sink to attach. 195 | * @exception Exception 196 | */ 197 | virtual void 198 | attach ( Sink * sink ) throw ( Exception ); 199 | 200 | /** 201 | * Open the connector. Opens the Source and the Sinks if necessary. 202 | * 203 | * @return true if opening was successful, false otherwise. 204 | * @exception Exception 205 | */ 206 | virtual bool 207 | open ( void ) throw ( Exception ); 208 | 209 | /** 210 | * Transfer a given amount of data from the Source to all the 211 | * Sinks attached. 212 | * If an attached Sink closes or encounteres an error during the 213 | * process, it is detached and the function carries on with the 214 | * rest of the Sinks. If no Sinks remain, or an error is encountered 215 | * with the Source, the function returns prematurely. 216 | * 217 | * @param bytes the amount of data to transfer, in bytes. 218 | * If 0, transfer forever. 219 | * @param bufSize the size of the buffer to use for transfering. 220 | * This amount of data is read from the Source and 221 | * written to each Sink on each turn. 222 | * @param sec the number of seconds to wait for the Source to have 223 | * data available in each turn, and the number of seconds 224 | * to wait for the Sinks to accept data. 225 | * @param usec the number of micro seconds to wait for the Source to 226 | * have data available in each turn, and the number of 227 | * micro seconds to wait for the Sinks to accept data. 228 | * @return the number of bytes read from the Source. 229 | * @exception Exception 230 | */ 231 | virtual unsigned int 232 | transfer ( unsigned long bytes, 233 | unsigned int bufSize, 234 | unsigned int sec, 235 | unsigned int usec ) throw ( Exception ); 236 | 237 | /** 238 | * Signal to each sink we have that they need to cut what they are 239 | * doing, and start again. For FileSinks, this usually means to 240 | * save the archive file recorded so far, and start a new archive 241 | * file. 242 | */ 243 | virtual void 244 | cut ( void ) throw (); 245 | 246 | /** 247 | * Close the Connector. The Source and all Sinks are closed. 248 | * 249 | * @exception Exception 250 | */ 251 | virtual void 252 | close ( void ) throw ( Exception ); 253 | }; 254 | 255 | 256 | /* ================================================= external data structures */ 257 | 258 | 259 | /* ====================================================== function prototypes */ 260 | 261 | 262 | 263 | #endif /* CONNECTOR_H */ 264 | 265 | -------------------------------------------------------------------------------- /src/Ref.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | 3 | Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved. 4 | 5 | Tyrell DarkIce 6 | 7 | File : Ref.h 8 | Version : $Revision: 553 $ 9 | Author : $Author: rafael@riseup.net $ 10 | Location : $HeadURL: https://darkice.googlecode.com/svn/darkice/tags/darkice-1_2/src/Ref.h $ 11 | 12 | Copyright notice: 13 | 14 | This program is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU General Public License 16 | as published by the Free Software Foundation; either version 3 17 | of the License, or (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 | 28 | ------------------------------------------------------------------------------*/ 29 | #ifndef REF_H 30 | #define REF_H 31 | 32 | #ifndef __cplusplus 33 | #error This is a C++ include file 34 | #endif 35 | 36 | 37 | /* ============================================================ include files */ 38 | 39 | #include "Exception.h" 40 | 41 | 42 | /* ================================================================ constants */ 43 | 44 | 45 | /* =================================================================== macros */ 46 | 47 | 48 | /* =============================================================== data types */ 49 | 50 | /** 51 | * Java-like object reference class. 52 | * Objects used with this reference class have to be descandents 53 | * of class Referable. 54 | * 55 | * sample usage: 56 | * 57 | *
 58 |  *  #include "Ref.h"
 59 |  *  #include "Referable.h"
 60 |  *
 61 |  *  class  A : public virtual Referable;
 62 |  *
 63 |  *  ...
 64 |  *   
 65 |  *  A        * a = new A();
 66 |  *  Ref     ref1 = a;       // 1 reference to a
 67 |  *  Ref     ref2 = ref1;    // 2 references to a
 68 |  *
 69 |  *  ref1 = 0;      // 1 reference to a
 70 |  *  ref2 = 0;      // at this point object a is destroyed
 71 |  *  
72 | * 73 | * Based on Tima Saarinen's work, 74 | * http://gamma.nic.fi/~timosa/comp/refcount.html 75 | * 76 | * @ref Referable 77 | * 78 | * @author $Author: rafael@riseup.net $ 79 | * @version $Revision: 553 $ 80 | */ 81 | template 82 | class Ref 83 | { 84 | private: 85 | 86 | /** 87 | * The object referenced by this Ref. 88 | * Must be a descandant of Referable. 89 | */ 90 | T* object; 91 | 92 | 93 | protected: 94 | 95 | 96 | public: 97 | 98 | /** 99 | * Default constructor. 100 | */ 101 | inline 102 | Ref ( void ) throw () 103 | { 104 | object = NULL; 105 | } 106 | 107 | /** 108 | * Copy constructor. 109 | * 110 | * @param other the Ref to copy. 111 | * @exception Exception 112 | */ 113 | inline 114 | Ref ( const Ref & other ) throw ( Exception ) 115 | { 116 | object = NULL; 117 | set( other.object); 118 | } 119 | 120 | /** 121 | * Constructor based on an object to reference. 122 | * 123 | * @param obj the object to reference. 124 | * @exception Exception 125 | */ 126 | inline 127 | Ref ( T * obj ) throw ( Exception ) 128 | { 129 | object = obj; 130 | obj->increaseReferenceCount(); 131 | } 132 | 133 | /** 134 | * Destructor. 135 | * 136 | * @exception Exception 137 | */ 138 | inline virtual 139 | ~Ref ( void ) throw ( Exception ) 140 | { 141 | set( 0 ); 142 | } 143 | 144 | /** 145 | * Operator overload to make the reference seem like a pointer. 146 | * 147 | * @return the pointer to the object referenced. 148 | */ 149 | inline T* 150 | operator->() const throw ( Exception ) 151 | { 152 | if ( !object ) { 153 | throw Exception( __FILE__, __LINE__, 154 | "reference to NULL object"); 155 | } 156 | return object; 157 | } 158 | 159 | /** 160 | * Assignment operator. 161 | * 162 | * @param other the Ref to assign to this one. 163 | * @return a reference to this Ref. 164 | * @exception Exception 165 | */ 166 | inline Ref & 167 | operator= ( Ref other ) throw ( Exception ) 168 | { 169 | set( other.object); 170 | return *this; 171 | } 172 | 173 | /** 174 | * Assignment operator. 175 | * 176 | * @param obj pointer to the object to assign to this Ref. 177 | * @return a reference to this Ref. 178 | * @exception Exception 179 | */ 180 | inline Ref & 181 | operator= ( T* obj ) throw ( Exception ) 182 | { 183 | set( obj); 184 | return *this; 185 | } 186 | 187 | /** 188 | * Set the object referenced. 189 | * Deletes the old referenced object is this was it's last reference. 190 | * 191 | * @param newobj pointer to the object to reference by this Ref. 192 | * @exception Exception 193 | */ 194 | inline void 195 | set ( T * newobj ) throw ( Exception ) 196 | { 197 | // If equal do nothing 198 | if ( newobj == object ) { 199 | return; 200 | } 201 | 202 | // Increase reference count 203 | if ( newobj ) { 204 | newobj->increaseReferenceCount(); 205 | } 206 | 207 | // Decrease the reference count of the old referable 208 | if ( object ) { 209 | if ( object->decreaseReferenceCount() == 0 ) { 210 | delete object; 211 | } 212 | } 213 | 214 | // Assign 215 | object = newobj; 216 | } 217 | 218 | /** 219 | * Return object pointer. This method should be used with 220 | * care because it breaks the encapsulation. 221 | * Typically this method is needed for the method calls 222 | * which require literal object pointer. 223 | * 224 | * It may not be bad idea to pass the Ref 225 | * objects as method arguments. 226 | * 227 | * @return Object pointer or NULL. 228 | */ 229 | inline T* 230 | get ( void ) const throw () 231 | { 232 | return object; 233 | } 234 | 235 | /** 236 | * Equality operator. 237 | * 238 | * @param other the pointer to compare this with. 239 | * @return true is this Ref refers to the same object as other, 240 | * false otherwise. 241 | */ 242 | inline bool 243 | operator== ( const T * other ) const throw () 244 | { 245 | return object == other; 246 | } 247 | 248 | /** 249 | * Equality operator. 250 | * 251 | * @param other the Ref to compare this with. 252 | * @return true is the two Refs refer to the same object, 253 | * false otherwise. 254 | */ 255 | inline bool 256 | operator== ( const Ref & other ) const throw () 257 | { 258 | return object == other.object; 259 | } 260 | 261 | /** 262 | * Unequality operator. 263 | * 264 | * @param other the pointer to compare this with. 265 | * @return false is this Ref refers to a different object then other, 266 | * true otherwise. 267 | */ 268 | inline bool 269 | operator!= ( const T * other ) const throw () 270 | { 271 | return object != other; 272 | } 273 | 274 | /** 275 | * Unequality operator. 276 | * 277 | * @param other the Ref to compare this with. 278 | * @return false is the two Refs refer to the same object, 279 | * true otherwise. 280 | */ 281 | inline bool 282 | operator!= ( const Ref & other ) const throw () 283 | { 284 | return object != other.object; 285 | } 286 | }; 287 | 288 | /* ================================================= external data structures */ 289 | 290 | 291 | /* ====================================================== function prototypes */ 292 | 293 | 294 | 295 | #endif /* REF_H */ 296 | 297 | -------------------------------------------------------------------------------- /src/.deps/Exception.Po: -------------------------------------------------------------------------------- 1 | Exception.o: Exception.cpp /usr/include/stdc-predef.h \ 2 | /usr/include/x86_64-linux-gnu/bits/predefs.h config.h \ 3 | /usr/include/string.h /usr/include/features.h \ 4 | /usr/include/x86_64-linux-gnu/sys/cdefs.h \ 5 | /usr/include/x86_64-linux-gnu/bits/wordsize.h \ 6 | /usr/include/x86_64-linux-gnu/gnu/stubs.h \ 7 | /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ 8 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h \ 9 | /usr/include/xlocale.h /usr/include/x86_64-linux-gnu/bits/string3.h \ 10 | Exception.h /usr/include/c++/4.8/iostream \ 11 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h \ 12 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h \ 13 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/cpu_defines.h \ 14 | /usr/include/c++/4.8/ostream /usr/include/c++/4.8/ios \ 15 | /usr/include/c++/4.8/iosfwd /usr/include/c++/4.8/bits/stringfwd.h \ 16 | /usr/include/c++/4.8/bits/memoryfwd.h \ 17 | /usr/include/c++/4.8/bits/postypes.h /usr/include/c++/4.8/cwchar \ 18 | /usr/include/wchar.h /usr/include/stdio.h \ 19 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h \ 20 | /usr/include/x86_64-linux-gnu/bits/wchar.h \ 21 | /usr/include/x86_64-linux-gnu/bits/wchar2.h \ 22 | /usr/include/c++/4.8/exception \ 23 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h \ 24 | /usr/include/c++/4.8/bits/char_traits.h \ 25 | /usr/include/c++/4.8/bits/stl_algobase.h \ 26 | /usr/include/c++/4.8/bits/functexcept.h \ 27 | /usr/include/c++/4.8/bits/exception_defines.h \ 28 | /usr/include/c++/4.8/bits/cpp_type_traits.h \ 29 | /usr/include/c++/4.8/ext/type_traits.h \ 30 | /usr/include/c++/4.8/ext/numeric_traits.h \ 31 | /usr/include/c++/4.8/bits/stl_pair.h /usr/include/c++/4.8/bits/move.h \ 32 | /usr/include/c++/4.8/bits/concept_check.h \ 33 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h \ 34 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h \ 35 | /usr/include/c++/4.8/debug/debug.h \ 36 | /usr/include/c++/4.8/bits/stl_iterator.h \ 37 | /usr/include/c++/4.8/bits/localefwd.h \ 38 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++locale.h \ 39 | /usr/include/c++/4.8/clocale /usr/include/locale.h \ 40 | /usr/include/x86_64-linux-gnu/bits/locale.h /usr/include/c++/4.8/cctype \ 41 | /usr/include/ctype.h /usr/include/x86_64-linux-gnu/bits/types.h \ 42 | /usr/include/x86_64-linux-gnu/bits/typesizes.h /usr/include/endian.h \ 43 | /usr/include/x86_64-linux-gnu/bits/endian.h \ 44 | /usr/include/x86_64-linux-gnu/bits/byteswap.h \ 45 | /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \ 46 | /usr/include/c++/4.8/bits/ios_base.h \ 47 | /usr/include/c++/4.8/ext/atomicity.h \ 48 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr.h \ 49 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr-default.h \ 50 | /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h \ 51 | /usr/include/x86_64-linux-gnu/bits/sched.h \ 52 | /usr/include/x86_64-linux-gnu/bits/time.h \ 53 | /usr/include/x86_64-linux-gnu/bits/timex.h \ 54 | /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \ 55 | /usr/include/x86_64-linux-gnu/bits/setjmp.h \ 56 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/atomic_word.h \ 57 | /usr/include/c++/4.8/bits/locale_classes.h /usr/include/c++/4.8/string \ 58 | /usr/include/c++/4.8/bits/allocator.h \ 59 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++allocator.h \ 60 | /usr/include/c++/4.8/ext/new_allocator.h /usr/include/c++/4.8/new \ 61 | /usr/include/c++/4.8/bits/ostream_insert.h \ 62 | /usr/include/c++/4.8/bits/cxxabi_forced.h \ 63 | /usr/include/c++/4.8/bits/stl_function.h \ 64 | /usr/include/c++/4.8/backward/binders.h \ 65 | /usr/include/c++/4.8/bits/range_access.h \ 66 | /usr/include/c++/4.8/bits/basic_string.h \ 67 | /usr/include/c++/4.8/bits/basic_string.tcc \ 68 | /usr/include/c++/4.8/bits/locale_classes.tcc \ 69 | /usr/include/c++/4.8/streambuf /usr/include/c++/4.8/bits/streambuf.tcc \ 70 | /usr/include/c++/4.8/bits/basic_ios.h \ 71 | /usr/include/c++/4.8/bits/locale_facets.h /usr/include/c++/4.8/cwctype \ 72 | /usr/include/wctype.h \ 73 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/ctype_base.h \ 74 | /usr/include/c++/4.8/bits/streambuf_iterator.h \ 75 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/ctype_inline.h \ 76 | /usr/include/c++/4.8/bits/locale_facets.tcc \ 77 | /usr/include/c++/4.8/bits/basic_ios.tcc \ 78 | /usr/include/c++/4.8/bits/ostream.tcc /usr/include/c++/4.8/istream \ 79 | /usr/include/c++/4.8/bits/istream.tcc 80 | 81 | /usr/include/stdc-predef.h: 82 | 83 | /usr/include/x86_64-linux-gnu/bits/predefs.h: 84 | 85 | config.h: 86 | 87 | /usr/include/string.h: 88 | 89 | /usr/include/features.h: 90 | 91 | /usr/include/x86_64-linux-gnu/sys/cdefs.h: 92 | 93 | /usr/include/x86_64-linux-gnu/bits/wordsize.h: 94 | 95 | /usr/include/x86_64-linux-gnu/gnu/stubs.h: 96 | 97 | /usr/include/x86_64-linux-gnu/gnu/stubs-64.h: 98 | 99 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h: 100 | 101 | /usr/include/xlocale.h: 102 | 103 | /usr/include/x86_64-linux-gnu/bits/string3.h: 104 | 105 | Exception.h: 106 | 107 | /usr/include/c++/4.8/iostream: 108 | 109 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h: 110 | 111 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h: 112 | 113 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/cpu_defines.h: 114 | 115 | /usr/include/c++/4.8/ostream: 116 | 117 | /usr/include/c++/4.8/ios: 118 | 119 | /usr/include/c++/4.8/iosfwd: 120 | 121 | /usr/include/c++/4.8/bits/stringfwd.h: 122 | 123 | /usr/include/c++/4.8/bits/memoryfwd.h: 124 | 125 | /usr/include/c++/4.8/bits/postypes.h: 126 | 127 | /usr/include/c++/4.8/cwchar: 128 | 129 | /usr/include/wchar.h: 130 | 131 | /usr/include/stdio.h: 132 | 133 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h: 134 | 135 | /usr/include/x86_64-linux-gnu/bits/wchar.h: 136 | 137 | /usr/include/x86_64-linux-gnu/bits/wchar2.h: 138 | 139 | /usr/include/c++/4.8/exception: 140 | 141 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h: 142 | 143 | /usr/include/c++/4.8/bits/char_traits.h: 144 | 145 | /usr/include/c++/4.8/bits/stl_algobase.h: 146 | 147 | /usr/include/c++/4.8/bits/functexcept.h: 148 | 149 | /usr/include/c++/4.8/bits/exception_defines.h: 150 | 151 | /usr/include/c++/4.8/bits/cpp_type_traits.h: 152 | 153 | /usr/include/c++/4.8/ext/type_traits.h: 154 | 155 | /usr/include/c++/4.8/ext/numeric_traits.h: 156 | 157 | /usr/include/c++/4.8/bits/stl_pair.h: 158 | 159 | /usr/include/c++/4.8/bits/move.h: 160 | 161 | /usr/include/c++/4.8/bits/concept_check.h: 162 | 163 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h: 164 | 165 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h: 166 | 167 | /usr/include/c++/4.8/debug/debug.h: 168 | 169 | /usr/include/c++/4.8/bits/stl_iterator.h: 170 | 171 | /usr/include/c++/4.8/bits/localefwd.h: 172 | 173 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++locale.h: 174 | 175 | /usr/include/c++/4.8/clocale: 176 | 177 | /usr/include/locale.h: 178 | 179 | /usr/include/x86_64-linux-gnu/bits/locale.h: 180 | 181 | /usr/include/c++/4.8/cctype: 182 | 183 | /usr/include/ctype.h: 184 | 185 | /usr/include/x86_64-linux-gnu/bits/types.h: 186 | 187 | /usr/include/x86_64-linux-gnu/bits/typesizes.h: 188 | 189 | /usr/include/endian.h: 190 | 191 | /usr/include/x86_64-linux-gnu/bits/endian.h: 192 | 193 | /usr/include/x86_64-linux-gnu/bits/byteswap.h: 194 | 195 | /usr/include/x86_64-linux-gnu/bits/byteswap-16.h: 196 | 197 | /usr/include/c++/4.8/bits/ios_base.h: 198 | 199 | /usr/include/c++/4.8/ext/atomicity.h: 200 | 201 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr.h: 202 | 203 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/gthr-default.h: 204 | 205 | /usr/include/pthread.h: 206 | 207 | /usr/include/sched.h: 208 | 209 | /usr/include/time.h: 210 | 211 | /usr/include/x86_64-linux-gnu/bits/sched.h: 212 | 213 | /usr/include/x86_64-linux-gnu/bits/time.h: 214 | 215 | /usr/include/x86_64-linux-gnu/bits/timex.h: 216 | 217 | /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h: 218 | 219 | /usr/include/x86_64-linux-gnu/bits/setjmp.h: 220 | 221 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/atomic_word.h: 222 | 223 | /usr/include/c++/4.8/bits/locale_classes.h: 224 | 225 | /usr/include/c++/4.8/string: 226 | 227 | /usr/include/c++/4.8/bits/allocator.h: 228 | 229 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++allocator.h: 230 | 231 | /usr/include/c++/4.8/ext/new_allocator.h: 232 | 233 | /usr/include/c++/4.8/new: 234 | 235 | /usr/include/c++/4.8/bits/ostream_insert.h: 236 | 237 | /usr/include/c++/4.8/bits/cxxabi_forced.h: 238 | 239 | /usr/include/c++/4.8/bits/stl_function.h: 240 | 241 | /usr/include/c++/4.8/backward/binders.h: 242 | 243 | /usr/include/c++/4.8/bits/range_access.h: 244 | 245 | /usr/include/c++/4.8/bits/basic_string.h: 246 | 247 | /usr/include/c++/4.8/bits/basic_string.tcc: 248 | 249 | /usr/include/c++/4.8/bits/locale_classes.tcc: 250 | 251 | /usr/include/c++/4.8/streambuf: 252 | 253 | /usr/include/c++/4.8/bits/streambuf.tcc: 254 | 255 | /usr/include/c++/4.8/bits/basic_ios.h: 256 | 257 | /usr/include/c++/4.8/bits/locale_facets.h: 258 | 259 | /usr/include/c++/4.8/cwctype: 260 | 261 | /usr/include/wctype.h: 262 | 263 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/ctype_base.h: 264 | 265 | /usr/include/c++/4.8/bits/streambuf_iterator.h: 266 | 267 | /usr/include/x86_64-linux-gnu/c++/4.8/bits/ctype_inline.h: 268 | 269 | /usr/include/c++/4.8/bits/locale_facets.tcc: 270 | 271 | /usr/include/c++/4.8/bits/basic_ios.tcc: 272 | 273 | /usr/include/c++/4.8/bits/ostream.tcc: 274 | 275 | /usr/include/c++/4.8/istream: 276 | 277 | /usr/include/c++/4.8/bits/istream.tcc: 278 | --------------------------------------------------------------------------------