Package: darkice
Version: 1.2-0.2
Severity: wishlist
Tags: patch

Hello.
The attached patches implement many suggestions for the darkice Debian
package.
Please consider applying them.
Thanks.
>From ef929769bd67ea3de4ab2850612e9dc1f1ef1631 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 22:20:49 +0200
Subject: [PATCH 01/12] Switch copyright file to 1.0 machine-readable format.

---
 debian/copyright | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/debian/copyright b/debian/copyright
index b4c3ced..a5d4639 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,35 +1,36 @@
-This package was debianized by Maitland Bottoms <bott...@debian.org> on
-Fri,  2 Aug 2002 16:43:20 -0400.
-
-It is now being maintained by Jochen Friedrich <joc...@scram.de> on
-Wed, 20 Aug 2003 22:55:52 +0200
-
-It was downloaded from http://darkice.sourceforge.net/
- DarkIce is being written by Tyrell Hungary, Ákos Maróy, Rafael Diniz
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: DarkIce
+Upstream-Contact: http://www.freelists.org/list/darkice
+Source: http://www.darkice.org/
 
+Files: *
 Copyright:
-
    Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
    Copyright (c) 2008, Ákos Maróy, a...@maroy.hu
    Copyright (c) 2009, Rafael Diniz, raf...@riseup.net
- 
-   Tyrell DarkIce
- 
-   Copyright notice:
- 
+License: GPL-2+
+
+Files: debian/*
+Copyright: 2001-2002 Maitland Bottoms <bott...@debian.org>
+           2003-2011 Jochen Friedrich <joc...@scram.de>
+License: GPL-2+
+
+License: GPL-2+
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
     as published by the Free Software Foundation; either version 2
     of the License, or (at your option) any later version.
-    
+    .
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
-                                                                                
+    .
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
     MA 02110-1301, USA.
-
-the GNU GPL may be viewed on Debian systems in /usr/share/common-licenses/GPL
+    .
+    On Debian systems, the full text of the GNU General Public
+    License version 2 can be found in the file
+    `/usr/share/common-licenses/GPL-2'.
-- 
2.8.1

>From 9921c08893e35f3a9df4b3d467107f893444429e Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 22:31:29 +0200
Subject: [PATCH 02/12] Simplify watch file with sourceforge redirector and
 version 4 format.

---
 debian/watch | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/debian/watch b/debian/watch
index dc71667..9e50381 100644
--- a/debian/watch
+++ b/debian/watch
@@ -1,4 +1,6 @@
-version=3
-opts=uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha|b|a)[\-\.]?\d*)$/$1~$2/,\
-downloadurlmangle=s%.*/([^/]*)/downloads/detail\?name=([^=&]*).*%http://$1.googlecode.com/files/$2%,filenamemangle=s/.*name=([^&]+).*/$1/ \
-http://code.google.com/p/darkice/downloads/list?can=1 .*=darkice-(\d.*)\.(?:tgz|tbz2|txz|tar\.(?:gz|bz2|xz)|zip).*
+version=4
+
+# qa.debian.org runs a redirector which allows a simpler form of URL
+# for SourceForge based projects. The format below will automatically
+# be rewritten to use the redirector.
+http://sf.net/darkice/darkice@ANY_VERSION@@ARCHIVE_EXT@
-- 
2.8.1

>From 4991c4f954ded86ed7bf6c1de5261825b09f90ce Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 22:34:00 +0200
Subject: [PATCH 03/12] Update README.Debian: mp3lame has been enabled for a
 while.

---
 debian/README.debian | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/debian/README.debian b/debian/README.debian
index 03d496f..576b26b 100644
--- a/debian/README.debian
+++ b/debian/README.debian
@@ -1,12 +1,9 @@
 DarkIce for Debian
 ----------------------
 
-This package was built with Ogg Vorbis support but without mp3 (lame)
-support for patent reasons.
-
 A sample configuration in installed into /usr/share/doc/darkice/examples.
 In order to use DarkIce, please copy this example to your preferred
 configuration directory, make any required changes for your site and reference
 it using darkice -c <config file>.
 
-Jochen Friedrich <joc...@scram.de>, Wed, 20 Aug 2003 21:02:26 +0200
+ -- Nicolas Boulenguez <nico...@debian.org>, Fri,  1 Jul 2016 23:59:37 +0200
-- 
2.8.1

>From 78c9f787a148f3afe13038ca3bf28cab0c951661 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 22:43:47 +0200
Subject: [PATCH 04/12] Remove debian/dirs, automake handles creation of /bin.

---
 debian/dirs | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 debian/dirs

diff --git a/debian/dirs b/debian/dirs
deleted file mode 100644
index e772481..0000000
--- a/debian/dirs
+++ /dev/null
@@ -1 +0,0 @@
-usr/bin
-- 
2.8.1

>From a2a05ac3f1aecfb5e11cc2d269bbfc44c72fccd9 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 22:49:16 +0200
Subject: [PATCH 05/12] Remove debian/clean, dh-auto-reconf replaces these
 files early in the dh sequence.

---
 debian/clean | 2 --
 1 file changed, 2 deletions(-)
 delete mode 100644 debian/clean

diff --git a/debian/clean b/debian/clean
deleted file mode 100644
index 3b93b74..0000000
--- a/debian/clean
+++ /dev/null
@@ -1,2 +0,0 @@
-config.guess
-config.sub
-- 
2.8.1

>From dab8daf32c04b1b4c7986a49c9669425ce97c00f Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 22:55:32 +0200
Subject: [PATCH 06/12] Switch existing patches to DEP-3 patch tagging
 guidelines.

---
 debian/patches/02_errno_range.diff     | 12 ++++++------
 debian/patches/03_gcc-43.diff          | 10 +++++-----
 debian/patches/04_gcc44.diff           | 15 +++++++--------
 debian/patches/05_fix_crlf.diff        | 12 ++++++------
 debian/patches/06_ftbfs_kfreebsd.patch | 17 ++++++-----------
 5 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/debian/patches/02_errno_range.diff b/debian/patches/02_errno_range.diff
index a800342..41afc22 100644
--- a/debian/patches/02_errno_range.diff
+++ b/debian/patches/02_errno_range.diff
@@ -1,9 +1,9 @@
----
- src/Util.cpp |    5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
+Description: floating constant exceeds range of 'double' (gcc-4.0)
+Bug-Debian: https://bugs.debian.org/285614
+Author: Andreas Jochens <a...@andaco.de>
 
---- darkice-1.2.orig/src/Util.cpp
-+++ darkice-1.2/src/Util.cpp
+--- a/src/Util.cpp
++++ b/src/Util.cpp
 @@ -87,6 +87,9 @@
  #error need signal.h
  #endif
@@ -14,7 +14,7 @@
  
  #include "Util.h"
  
-@@ -286,7 +289,7 @@ Util :: strToD( const char    * str )
+@@ -286,7 +289,7 @@
      }
  
      val = strtod( str, &s);
diff --git a/debian/patches/03_gcc-43.diff b/debian/patches/03_gcc-43.diff
index 97650f7..18a2e5d 100644
--- a/debian/patches/03_gcc-43.diff
+++ b/debian/patches/03_gcc-43.diff
@@ -1,9 +1,9 @@
----
- src/JackDspSource.cpp |    2 ++
- 1 file changed, 2 insertions(+)
+Description: allow build with gcc-4.3.
+Bug-Debian: https://bugs.debian.org/417146
+Author: Jochen Friedrich <joc...@scram.de>
 
---- darkice-1.2.orig/src/JackDspSource.cpp
-+++ darkice-1.2/src/JackDspSource.cpp
+--- a/src/JackDspSource.cpp
++++ b/src/JackDspSource.cpp
 @@ -82,6 +82,8 @@
  #error need limits.h
  #endif
diff --git a/debian/patches/04_gcc44.diff b/debian/patches/04_gcc44.diff
index ce4465b..3cff636 100644
--- a/debian/patches/04_gcc44.diff
+++ b/debian/patches/04_gcc44.diff
@@ -1,10 +1,9 @@
----
- src/JackDspSource.cpp |    4 ++++
- src/SerialUlaw.cpp    |    4 ++++
- 2 files changed, 8 insertions(+)
+Description: allow compilation with gcc 4.4.
+Bug-Debian: https://bugs.debian.org/560431
+Author: Cyril Brulebois <k...@debian.org>
 
---- darkice-1.2.orig/src/SerialUlaw.cpp
-+++ darkice-1.2/src/SerialUlaw.cpp
+--- a/src/SerialUlaw.cpp
++++ b/src/SerialUlaw.cpp
 @@ -94,6 +94,10 @@
  #error need termios.h
  #endif
@@ -16,8 +15,8 @@
  
  #include "Util.h"
  #include "Exception.h"
---- darkice-1.2.orig/src/JackDspSource.cpp
-+++ darkice-1.2/src/JackDspSource.cpp
+--- a/src/JackDspSource.cpp
++++ b/src/JackDspSource.cpp
 @@ -82,6 +82,10 @@
  #error need limits.h
  #endif
diff --git a/debian/patches/05_fix_crlf.diff b/debian/patches/05_fix_crlf.diff
index c08be83..64c6622 100644
--- a/debian/patches/05_fix_crlf.diff
+++ b/debian/patches/05_fix_crlf.diff
@@ -1,10 +1,10 @@
----
- src/IceCast2.cpp |    2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
+Description: wrong terminal CRLF for HTTP request.
+Bug-Debian: https://bugs.debian.org/441281
+Author: Romain Beauxis <to...@rastageeks.org>
 
---- darkice-1.2.orig/src/IceCast2.cpp
-+++ darkice-1.2/src/IceCast2.cpp
-@@ -233,7 +233,7 @@ IceCast2 :: sendLogin ( void )
+--- a/src/IceCast2.cpp
++++ b/src/IceCast2.cpp
+@@ -233,7 +233,7 @@
          sink->write( str, strlen( str));
      }
  
diff --git a/debian/patches/06_ftbfs_kfreebsd.patch b/debian/patches/06_ftbfs_kfreebsd.patch
index ed93b25..449890c 100644
--- a/debian/patches/06_ftbfs_kfreebsd.patch
+++ b/debian/patches/06_ftbfs_kfreebsd.patch
@@ -1,14 +1,9 @@
 Description: Fix FTBFS on kfreebsd.
 Author: Alessio Treglia <ales...@debian.org>
 Forwarded: no
----
- src/OpusLibEncoder.cpp      |    2 ++
- src/OpusLibEncoder.h        |    2 ++
- src/PulseAudioDspSource.cpp |    1 +
- 3 files changed, 5 insertions(+)
 
---- darkice-1.2.orig/src/OpusLibEncoder.cpp
-+++ darkice-1.2/src/OpusLibEncoder.cpp
+--- a/src/OpusLibEncoder.cpp
++++ b/src/OpusLibEncoder.cpp
 @@ -41,6 +41,8 @@
  #include "Util.h"
  #include "OpusLibEncoder.h"
@@ -18,8 +13,8 @@ Forwarded: no
  
  
  /* ===================================================  local data structures */
---- darkice-1.2.orig/src/OpusLibEncoder.h
-+++ darkice-1.2/src/OpusLibEncoder.h
+--- a/src/OpusLibEncoder.h
++++ b/src/OpusLibEncoder.h
 @@ -59,6 +59,8 @@
  #include "aflibConverter.h"
  #endif
@@ -29,8 +24,8 @@ Forwarded: no
  
  /* ================================================================ constants */
  
---- darkice-1.2.orig/src/PulseAudioDspSource.cpp
-+++ darkice-1.2/src/PulseAudioDspSource.cpp
+--- a/src/PulseAudioDspSource.cpp
++++ b/src/PulseAudioDspSource.cpp
 @@ -35,6 +35,7 @@
  /* ============================================================ include files */
  
-- 
2.8.1

>From 05165c76502da686f89da2dea152577a5141af89 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sat, 30 Jul 2016 23:05:58 +0200
Subject: [PATCH 07/12] Apply 4 patches picked from upstream version control
 system.

---
 ...a-until-next-ogg-packet-is-ready-in-vorbis.diff |  20 +
 debian/patches/fixed-issue-98.diff                 |  32 +
 ...opus-encoder-by-christian-franke-nobody-no.diff |  56 ++
 debian/patches/series                              |   4 +
 .../patches/server-connection-related-fixes.diff   | 683 +++++++++++++++++++++
 5 files changed, 795 insertions(+)
 create mode 100644 debian/patches/accept-data-until-next-ogg-packet-is-ready-in-vorbis.diff
 create mode 100644 debian/patches/fixed-issue-98.diff
 create mode 100644 debian/patches/fixes-for-opus-encoder-by-christian-franke-nobody-no.diff
 create mode 100644 debian/patches/server-connection-related-fixes.diff

diff --git a/debian/patches/accept-data-until-next-ogg-packet-is-ready-in-vorbis.diff b/debian/patches/accept-data-until-next-ogg-packet-is-ready-in-vorbis.diff
new file mode 100644
index 0000000..a45abd3
--- /dev/null
+++ b/debian/patches/accept-data-until-next-ogg-packet-is-ready-in-vorbis.diff
@@ -0,0 +1,20 @@
+Origin: upstream https://github.com/rafael2k/darkice/commit/e0cad73a683b868f05db28834afdd94401f5963d
+From: "alban.peign...@gmail.com" <alban.peign...@gmail.com@caa462fc-51d2-11de-8b28-e1b452efc53a>
+Date: Sun, 21 Jul 2013 18:42:47 +0000
+Subject: Accept data until next Ogg packet is ready in VorbisEncoder#canWrite
+
+--- a/src/VorbisLibEncoder.h
++++ b/src/VorbisLibEncoder.h
+@@ -402,7 +402,11 @@
+                 return false;
+             }
+ 
+-            return getSink()->canWrite(sec, usec);
++            if ( 1 == vorbis_analysis_blockout( &vorbisDspState, &vorbisBlock) ) {
++              return getSink()->canWrite(sec, usec);
++            } else {
++              return true;
++            }
+         }
+ 
+         /**
diff --git a/debian/patches/fixed-issue-98.diff b/debian/patches/fixed-issue-98.diff
new file mode 100644
index 0000000..e80815c
--- /dev/null
+++ b/debian/patches/fixed-issue-98.diff
@@ -0,0 +1,32 @@
+Origin: upstream https://github.com/rafael2k/darkice/commit/ab48aa307122ec5da5cca733c922f8c16d3b5673
+From: raf...@riseup.net <raf...@riseup.net@caa462fc-51d2-11de-8b28-e1b452efc53a>
+Date: Wed, 11 Dec 2013 01:08:05 +0000
+Subject: fixed issue 98 (check minimum vorbis output rate)
+
+--- a/src/VorbisLibEncoder.cpp
++++ b/src/VorbisLibEncoder.cpp
+@@ -40,7 +40,7 @@
+ #include "Exception.h"
+ #include "Util.h"
+ #include "VorbisLibEncoder.h"
+-
++#define VORBIS_MIN_BITRATE 45
+ 
+ /* ===================================================  local data structures */
+ 
+@@ -79,6 +79,15 @@
+                          getInChannel() );
+     }
+ 
++    if ( getOutBitrateMode() == abr || getOutBitrateMode() == cbr ) {
++        if ( getOutBitrate() < VORBIS_MIN_BITRATE ) {
++            throw Exception( __FILE__, __LINE__,
++                            "output bitrate is lower than libvorbis minimum",
++                            getOutBitrate() );
++        }
++        
++    }
++
+     if ( getOutSampleRate() == getInSampleRate() ) {
+         resampleRatio = 1;
+         converter     = 0;
diff --git a/debian/patches/fixes-for-opus-encoder-by-christian-franke-nobody-no.diff b/debian/patches/fixes-for-opus-encoder-by-christian-franke-nobody-no.diff
new file mode 100644
index 0000000..0a8ceed
--- /dev/null
+++ b/debian/patches/fixes-for-opus-encoder-by-christian-franke-nobody-no.diff
@@ -0,0 +1,56 @@
+Origin: upstream https://github.com/rafael2k/darkice/commit/40fd8cc0cfadce396ab8f8d3b15715bfc79c5c9a
+From: "raf...@riseup.net" <raf...@riseup.net@caa462fc-51d2-11de-8b28-e1b452efc53a>
+Date: Fri, 13 Dec 2013 20:40:37 +0000
+Subject: fixes for Opus encoder by Christian Franke <nob...@nowhere.ws>
+
+--- a/configure.in
++++ b/configure.in
+@@ -260,10 +260,11 @@
+ dnl-----------------------------------------------------------------------------
+ if test "x${LAME_LDFLAGS}" = "x" \
+      -a "x${VORBIS_LDFLAGS}" = "x" \
++     -a "x${OPUS_LDFLAGS}" = "x" \
+      -a "x${FAAC_LDFLAGS}" = "x" \
+      -a "x${AACPLUS_LDFLAGS}" = "x" \
+      -a "x${TWOLAME_LDFLAGS}" = "x"; then
+-    AC_MSG_ERROR([neither lame, Ogg Vorbis, faac, aac+ nor twolame configured])
++    AC_MSG_ERROR([neither lame, Ogg Vorbis, opus, faac, aac+ nor twolame configured])
+ fi
+ 
+ 
+--- a/src/OpusLibEncoder.cpp
++++ b/src/OpusLibEncoder.cpp
+@@ -36,6 +36,9 @@
+ // compile only if configured for Ogg / Opus
+ #ifdef HAVE_OPUS_LIB
+ 
++#include <stdio.h>
++#include <string.h>
++#include <unistd.h>
+ 
+ #include "Exception.h"
+ #include "Util.h"
+@@ -476,10 +479,10 @@
+ 
+     int opusBufferSize = (1275*3+7)*getOutChannel();
+     unsigned char * opusBuffer = new unsigned char[opusBufferSize];
+-    short int * shortBuffer = new short int[480];
++    short int * shortBuffer = new short int[480*getInChannel()];
+ 
+     // Send an empty audio packet along to flush out the stream.
+-    memset( shortBuffer, 0, 480);
++    memset( shortBuffer, 0, 480*getInChannel()*sizeof(*shortBuffer));
+     memset( opusBuffer, 0, opusBufferSize);
+     int encBytes = opus_encode( opusEncoder, shortBuffer, 480, opusBuffer, opusBufferSize);
+     if( encBytes == -1 ) {
+--- a/src/OpusLibEncoder.h
++++ b/src/OpusLibEncoder.h
+@@ -40,6 +40,8 @@
+ #include "config.h"
+ #endif
+ 
++#include <stdlib.h>
++
+ #ifdef HAVE_OPUS_LIB
+ #include <opus/opus.h>
+ #include <ogg/ogg.h>
diff --git a/debian/patches/series b/debian/patches/series
index 65d6c9c..7f98598 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,3 +3,7 @@
 04_gcc44.diff
 05_fix_crlf.diff
 06_ftbfs_kfreebsd.patch
+accept-data-until-next-ogg-packet-is-ready-in-vorbis.diff
+fixed-issue-98.diff
+fixes-for-opus-encoder-by-christian-franke-nobody-no.diff
+server-connection-related-fixes.diff
diff --git a/debian/patches/server-connection-related-fixes.diff b/debian/patches/server-connection-related-fixes.diff
new file mode 100644
index 0000000..0377c0a
--- /dev/null
+++ b/debian/patches/server-connection-related-fixes.diff
@@ -0,0 +1,683 @@
+Origin: upstream https://github.com/rafael2k/darkice/commit/710d2c26c4f9518d2f382673bf8b1829b9bdac3d
+From: "raf...@riseup.net" <raf...@riseup.net@caa462fc-51d2-11de-8b28-e1b452efc53a>
+Date: Wed, 26 Feb 2014 19:48:19 +0000
+Subject: Server connection related fixes.
+
+Description: Bugs related to streaming to remote servers fixed. Patch
+ by Kalle Kulonen <kulon...@gmail.com>
+ and Mark Turner <jmarktur...@gmail.com>.
+
+--- a/src/AlsaDspSource.cpp
++++ b/src/AlsaDspSource.cpp
+@@ -255,7 +255,7 @@
+ 
+         // Check for buffer overrun
+         if (ret == -EPIPE) {
+-            reportEvent(1, "Buffer overrun!");
++            reportEvent(1, "AlsaDspSource :: Buffer overrun!");
+             snd_pcm_prepare(captureHandle);
+             ret = -EAGAIN;
+         }
+--- a/src/BufferedSink.cpp
++++ b/src/BufferedSink.cpp
+@@ -99,6 +99,8 @@
+     this->bufferEnd    = buffer + bufferSize;
+     this->inp          = buffer;
+     this->outp         = buffer;
++    this->bOpen        = true;
++    this->openAttempts = 0; 
+ }
+ 
+ 
+@@ -112,6 +114,8 @@
+ 
+     this->peak         = buffer.peak;
+     this->misalignment = buffer.misalignment;
++    this->bOpen        = buffer.bOpen;
++    this->openAttempts = buffer.openAttempts; 
+     memcpy( this->buffer, buffer.buffer, this->bufferSize);
+ }
+ 
+@@ -145,6 +149,8 @@
+         
+         this->peak         = buffer.peak;
+         this->misalignment = buffer.misalignment;
++        this->bOpen        = buffer.bOpen;
++        this->openAttempts = buffer.openAttempts;
+         memcpy( this->buffer, buffer.buffer, this->bufferSize);
+     }
+ 
+@@ -177,6 +183,16 @@
+         return 0;
+     }
+ 
++    unsigned int remaining = this->bufferSize - ( outp <= inp ? inp - outp : 
++                             (bufferEnd - outp) + (inp - this->buffer) );
++
++    // react only to the first overrun whenever there is a series of overruns
++    if ( remaining + chunkSize <= bufferSize && remaining > chunkSize  ) {
++        reportEvent(3,"BufferedSink :: store, buffer overrun");
++        throw Exception( __FILE__, __LINE__,
++                         "buffer overrun");
++    }
++
+     oldInp = inp;
+     buf    = (const unsigned char *) buffer;
+     
+@@ -257,8 +273,8 @@
+ BufferedSink :: write (    const void    * buf,
+                            unsigned int    len )       throw ( Exception )
+ {
+-    unsigned int    length;
+-    unsigned int    soFar;
++    unsigned int    length = 0;
++    unsigned int    soFar = 0;
+     unsigned char * b = (unsigned char *) buf;
+ 
+     if ( !buf ) {
+@@ -272,6 +288,28 @@
+     if ( !align() ) {
+         return 0;
+     }
++    
++    if ( !sink->isOpen() && openAttempts < 10 ) {
++        // try to reopen underlying sink, because it has closed on its own
++        openAttempts++;
++        try {
++            if( sink->open() ) {
++                // if reopening succeeds, reset open attempts
++                openAttempts = 0;
++            }
++        } catch ( Exception &e ) {
++            reportEvent( 4,"BufferedSink :: write,",
++                         "couldn't reopen underlying sink, attempt",
++                         openAttempts, "/ 10" );
++        }
++        
++        if( openAttempts == 10 ) {
++            // all the attempts have been used, give up
++            close();
++            throw Exception( __FILE__, __LINE__,
++                             "reopen failed");
++        }
++    }
+ 
+     // make it a multiple of chunkSize
+     len -= len % chunkSize;
+@@ -286,12 +324,24 @@
+             // try to write the outp -> bufferEnd
+             // the rest will be written in the next if
+ 
+-            size    = bufferEnd - outp - 1;
++            size    = bufferEnd - outp;
+             size   -= size % chunkSize;
++            if( size > len * 2 ) {
++                // do not try to send the content of the entire buffer at once,
++                // but limit sending to a multiple of len
++                // this prevents a surge of data to underlying buffer
++                // which is important especially during a lot of packet loss
++                size = len * 2;
++            }
+             soFar   = 0;
+ 
+             while ( outp > inp && soFar < size && sink->canWrite( 0, 0) ) {
+-                length  = sink->write( outp + soFar, size - soFar);
++                try {
++                    length  = sink->write( outp + soFar, size - soFar);
++                } catch (Exception &e) {
++                    length = 0;
++                    reportEvent(3,"Exception caught in BufferedSink :: write1");
++                }
+                 outp    = slidePointer( outp, length);
+                 soFar  += length;
+             }
+@@ -305,10 +355,19 @@
+             // this part will write the rest
+ 
+             size    = inp - outp;
++            if( size > len * 2 ) {
++                // prevent a surge of data to underlying buffer
++                size = len * 2;
++            }
+             soFar   = 0;
+ 
+             while ( soFar < size && sink->canWrite( 0, 0) ) {
+-                length  = sink->write( outp + soFar, size - soFar);
++                try {
++                    length  = sink->write( outp + soFar, size - soFar);
++                } catch (Exception &e) {
++                    length = 0;
++                    reportEvent(3,"Exception caught in BufferedSink :: write2" );
++                }
+                 outp    = slidePointer( outp, length);
+                 soFar  += length;
+             }
+@@ -332,13 +391,12 @@
+     soFar = 0;
+     if ( inp == outp ) { 
+         while ( soFar < len && sink->canWrite( 0, 0) ) {
+-	    try {
+-	        soFar += sink->write( b + soFar, len - soFar);
+-	    } catch (Exception &e) {
+-	        reportEvent(3,"Exception caught in BufferedSink :: write3\n");
+-		throw; /* up a level */
+-	    }
+-	}
++            try {
++                soFar += sink->write( b + soFar, len - soFar);
++            } catch (Exception &e) {
++                reportEvent(3,"Exception caught in BufferedSink :: write3");
++            }
++        }
+     }
+     length = soFar;
+ 
+@@ -351,6 +409,8 @@
+         store( b + length, len - length);
+     }
+ 
++    updatePeak();
++
+     // tell them we ate everything up to chunkSize alignment
+     return len;
+ }
+@@ -369,5 +429,6 @@
+     flush();
+     sink->close();
+     inp = outp = buffer;
++    bOpen = false;
+ }
+ 
+--- a/src/BufferedSink.h
++++ b/src/BufferedSink.h
+@@ -109,6 +109,17 @@
+          *  The underlying Sink.
+          */
+         Ref<Sink>           sink;
++        
++        /**
++         *  Is BufferedSink open.
++         */
++        bool               bOpen;
++         
++         /**
++          * Number of attempts so far to open underlying sink after it has
++          * closed on its own.
++          */
++        unsigned int       openAttempts;  
+ 
+         /**
+          *  Initialize the object.
+@@ -163,10 +174,17 @@
+             unsigned int    u;
+ 
+             u = outp <= inp ? inp - outp : (bufferEnd - outp) + (inp - buffer);
+-            if ( peak < u ) {
++            
++            // report new peaks if it is either significantly more severe than
++            // the previously reported peak
++            if ( peak * 2 < u ) {
+                 peak = u;
+-                reportEvent( 4, "BufferedSink, new peak:", peak);
+-                reportEvent( 4, "BufferedSink, remaining:", bufferSize - peak);
++                reportEvent( 4, "BufferedSink, new peak:", peak, " / ", bufferSize);
++            }
++            
++            if ( peak > 0 && u == 0 ) {
++                peak = 0;
++                reportEvent( 4, "BufferedSink, healed:", peak, " / ", bufferSize);
+             }
+         }
+ 
+@@ -306,7 +324,9 @@
+         inline virtual bool
+         open ( void )                                   throw ( Exception )
+         {
+-            return sink->open();
++            bOpen = sink->open();
++            openAttempts = 0;
++            return bOpen;
+         }
+ 
+         /**
+@@ -317,7 +337,7 @@
+         inline virtual bool
+         isOpen ( void ) const                           throw ()
+         {
+-            return sink->isOpen();
++            return bOpen;
+         }
+ 
+         /**
+--- a/src/DarkIce.cpp
++++ b/src/DarkIce.cpp
+@@ -262,7 +262,7 @@
+         FileSink                  * localDumpFile   = 0;
+         bool                        fileAddDate     = false;
+         const char                * fileDateFormat  = 0;
+-        AudioEncoder              * encoder         = 0;
++        BufferedSink              * audioOut        = 0;
+         int                         bufferSize      = 0;
+ 
+         str         = cs->get( "sampleRate");
+@@ -384,10 +384,14 @@
+                              "unsupported stream format: ", str);
+ 
+         }
++        
++        // augment audio outs with a buffer when used from encoder
++        audioOut = new BufferedSink( audioOuts[u].server.get(), 
++                                                  bufferSize, 1);
+ 
+ #ifdef HAVE_LAME_LIB
+         if ( Util::strEq( str, "mp3") ) {
+-            encoder = new LameLibEncoder( audioOuts[u].server.get(),
++            audioOuts[u].encoder = new LameLibEncoder( audioOut,
+                                           dsp.get(),
+                                           bitrateMode,
+                                           bitrate,
+@@ -400,8 +404,8 @@
+ #endif
+ #ifdef HAVE_TWOLAME_LIB
+         if ( Util::strEq( str, "mp2") ) {
+-            encoder = new TwoLameLibEncoder(
+-                                            audioOuts[u].server.get(),
++            audioOuts[u].encoder = new TwoLameLibEncoder(
++                                            audioOut,
+                                             dsp.get(),
+                                             bitrateMode,
+                                             bitrate,
+@@ -410,7 +414,6 @@
+         }
+ #endif
+ 
+-        audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+         encConnector->attach( audioOuts[u].encoder.get());
+ #endif // HAVE_LAME_LIB || HAVE_TWOLAME_LIB
+     }
+@@ -467,7 +470,7 @@
+         FileSink                  * localDumpFile   = 0;
+         bool                        fileAddDate     = false;
+         const char                * fileDateFormat  = 0;
+-        AudioEncoder              * encoder         = 0;
++        BufferedSink              * audioOut        = 0;
+         int                         bufferSize      = 0;
+ 
+         str         = cs->getForSure( "format", " missing in section ", stream);
+@@ -597,6 +600,9 @@
+                                             isPublic,
+                                             localDumpFile);
+ 
++        audioOut = new BufferedSink( audioOuts[u].server.get(), 
++                                     bufferSize, 1);
++        
+         switch ( format ) {
+             case IceCast2::mp3:
+ #ifndef HAVE_LAME_LIB
+@@ -605,8 +611,8 @@
+                                  "thus can't create mp3 stream: ",
+                                  stream);
+ #else
+-                encoder = new LameLibEncoder(
+-                                             audioOuts[u].server.get(),
++                audioOuts[u].encoder = new LameLibEncoder(
++                                             audioOut,
+                                              dsp.get(),
+                                              bitrateMode,
+                                              bitrate,
+@@ -616,8 +622,6 @@
+                                              lowpass,
+                                              highpass );
+ 
+-                audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+-
+ #endif // HAVE_LAME_LIB
+                 break;
+ 
+@@ -630,8 +634,8 @@
+                                 stream);
+ #else
+ 
+-                encoder = new VorbisLibEncoder(
+-                                               audioOuts[u].server.get(),
++                audioOuts[u].encoder = new VorbisLibEncoder(
++                                               audioOut,
+                                                dsp.get(),
+                                                bitrateMode,
+                                                bitrate,
+@@ -640,7 +644,6 @@
+                                                dsp->getChannel(),
+                                                maxBitrate);
+ 
+-                audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+ #endif // HAVE_VORBIS_LIB
+                 break;
+ 
+@@ -652,8 +655,8 @@
+                                 stream);
+ #else
+ 
+-                encoder = new OpusLibEncoder(
+-                                               audioOuts[u].server.get(),
++                audioOuts[u].encoder = new OpusLibEncoder(
++                                               audioOut,
+                                                dsp.get(),
+                                                bitrateMode,
+                                                bitrate,
+@@ -662,7 +665,6 @@
+                                                dsp->getChannel(),
+                                                maxBitrate);
+ 
+-                audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getBitsPerSample() / 8);
+ #endif // HAVE_OPUS_LIB
+                 break;
+ 
+@@ -673,15 +675,14 @@
+                                  "thus can't create mp2 stream: ",
+                                  stream);
+ #else
+-                encoder = new TwoLameLibEncoder(
+-                                                audioOuts[u].server.get(),
++                audioOuts[u].encoder = new TwoLameLibEncoder(
++                                                audioOut,
+                                                 dsp.get(),
+                                                 bitrateMode,
+                                                 bitrate,
+                                                 sampleRate,
+                                                 channel );
+ 
+-                audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+ #endif // HAVE_TWOLAME_LIB
+                 break;
+ 
+@@ -693,8 +694,8 @@
+                                 "thus can't aac stream: ",
+                                 stream);
+ #else
+-                encoder = new FaacEncoder(
+-                                          audioOuts[u].server.get(),
++                audioOuts[u].encoder = new FaacEncoder(
++                                          audioOut,
+                                           dsp.get(),
+                                           bitrateMode,
+                                           bitrate,
+@@ -702,7 +703,6 @@
+                                           sampleRate,
+                                           dsp->getChannel());
+ 
+-                audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+ #endif // HAVE_FAAC_LIB
+                 break;
+ 
+@@ -713,8 +713,8 @@
+                                 "thus can't aacp stream: ",
+                                 stream);
+ #else
+-                encoder = new aacPlusEncoder(
+-                                             audioOuts[u].server.get(),
++                audioOuts[u].encoder = new aacPlusEncoder(
++                                             audioOut,
+                                              dsp.get(),
+                                              bitrateMode,
+                                              bitrate,
+@@ -722,7 +722,6 @@
+                                              sampleRate,
+                                              channel );
+ 
+-                audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+ #endif // HAVE_AACPLUS_LIB
+                 break;
+ 
+@@ -793,7 +792,7 @@
+         FileSink                  * localDumpFile   = 0;
+         bool                        fileAddDate     = false;
+         const char                * fileDateFormat  = 0;
+-        AudioEncoder              * encoder         = 0;
++        BufferedSink              * audioOut        = 0;
+         int                         bufferSize      = 0;
+ 
+         str         = cs->get( "sampleRate");
+@@ -908,7 +907,9 @@
+                                              localDumpFile);
+ 
+ 
+-        encoder = new LameLibEncoder( audioOuts[u].server.get(),
++        audioOut = new BufferedSink(audioOuts[u].socket.get(), bufferSize, 1);
++        audioOuts[u].encoder = new LameLibEncoder( 
++                                      audioOut,
+                                       dsp.get(),
+                                       bitrateMode,
+                                       bitrate,
+@@ -917,7 +918,6 @@
+                                       channel,
+                                       lowpass,
+                                       highpass );
+-        audioOuts[u].encoder = new BufferedSink(encoder, bufferSize, dsp->getSampleSize());
+ 
+         encConnector->attach( audioOuts[u].encoder.get());
+ #endif // HAVE_LAME_LIB
+--- a/src/OpusLibEncoder.h
++++ b/src/OpusLibEncoder.h
+@@ -54,7 +54,7 @@
+ #include "Exception.h"
+ #include "Reporter.h"
+ #include "AudioEncoder.h"
+-#include "CastSink.h"
++#include "Sink.h"
+ #ifdef HAVE_SRC_LIB
+ #include <samplerate.h>
+ #else
+@@ -315,7 +315,7 @@
+          *  @exception Exception
+          */
+         inline
+-        OpusLibEncoder (  CastSink      * sink,
++        OpusLibEncoder (  Sink      * sink,
+                             unsigned int    inSampleRate,
+                             unsigned int    inBitsPerSample,
+                             unsigned int    inChannel,
+@@ -360,7 +360,7 @@
+          *  @exception Exception
+          */
+         inline
+-        OpusLibEncoder (  CastSink              * sink,
++        OpusLibEncoder (    Sink                  * sink,
+                             const AudioSource     * as,
+                             BitrateMode             outBitrateMode,
+                             unsigned int            outBitrate,
+--- a/src/TcpSocket.cpp
++++ b/src/TcpSocket.cpp
+@@ -318,9 +318,9 @@
+                 break;
+ 
+             default:
+-		::close( sockfd);
+-		sockfd = 0;
+-		throw Exception( __FILE__, __LINE__, "recv error", errno);
++                ::close( sockfd);
++                sockfd = 0;
++                throw Exception( __FILE__, __LINE__, "recv error", errno);
+         }
+     }
+ 
+@@ -329,7 +329,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check wether write() would send anything
+  *----------------------------------------------------------------------------*/
+ bool
+ TcpSocket :: canWrite (    unsigned int    sec,
+@@ -357,11 +357,11 @@
+     ret = pselect( sockfd + 1, NULL, &fdset, NULL, &timespec, &sigset);
+     
+     if ( ret == -1 ) {
+-	::close( sockfd);
+-	sockfd = 0;
+-        throw Exception( __FILE__, __LINE__, "select error");
++        ::close( sockfd);
++        sockfd = 0;
++        reportEvent(4,"TcpSocket :: canWrite, connection lost", errno);
+     }
+-
++  
+     return ret > 0;
+ }
+ 
+@@ -389,8 +389,9 @@
+         if ( errno == EAGAIN ) {
+             ret = 0;
+         } else {
+-	    ::close( sockfd);
+-	    sockfd = 0;
++            ::close( sockfd);
++            sockfd = 0;
++            reportEvent(4,"TcpSocket :: write, send error", errno);
+             throw Exception( __FILE__, __LINE__, "send error", errno);
+         }
+     }
+--- a/src/VorbisLibEncoder.cpp
++++ b/src/VorbisLibEncoder.cpp
+@@ -300,13 +300,13 @@
+             if ( bitsPerSample == 8 ) {
+                 char          * buf8 = (char *) buf;
+                 unsigned int    ix   = sampleSize * i;
+-		unsigned int    iix  = ix;
++                unsigned int    iix  = ix;
+                 buf8[i] = (buf8[ix] + buf8[++iix]) / 2;
+             }
+             if ( bitsPerSample == 16 ) {
+                 short         * buf16 = (short *) buf;
+                 unsigned int    ix    = (bitsPerSample >> 3) * i;
+-		unsigned int    iix   = ix;
++                unsigned int    iix   = ix;
+                 buf16[i] = (buf16[ix] + buf16[++iix]) / 2;
+             }
+         }
+@@ -370,6 +370,7 @@
+     }
+ 
+     delete[] shortBuffer;
++    
+     vorbisBlocksOut();
+ 
+     return processed;
+@@ -411,7 +412,7 @@
+             ogg_stream_packetin( &oggStreamState, &oggPacket);
+ 
+             while ( ogg_stream_pageout( &oggStreamState, &oggPage) ) {
+-                int    written;
++                int    written = 0;
+                 
+                 written  = getSink()->write(oggPage.header, oggPage.header_len);
+                 written += getSink()->write( oggPage.body, oggPage.body_len);
+--- a/src/VorbisLibEncoder.h
++++ b/src/VorbisLibEncoder.h
+@@ -51,7 +51,7 @@
+ #include "Exception.h"
+ #include "Reporter.h"
+ #include "AudioEncoder.h"
+-#include "CastSink.h"
++#include "Sink.h"
+ #ifdef HAVE_SRC_LIB
+ #include <samplerate.h>
+ #else
+@@ -199,7 +199,7 @@
+          *  @exception Exception
+          */
+         inline
+-        VorbisLibEncoder (  CastSink      * sink,
++        VorbisLibEncoder (  Sink          * sink,
+                             unsigned int    inSampleRate,
+                             unsigned int    inBitsPerSample,
+                             unsigned int    inChannel,
+@@ -244,7 +244,7 @@
+          *  @exception Exception
+          */
+         inline
+-        VorbisLibEncoder (  CastSink              * sink,
++        VorbisLibEncoder (  Sink                  * sink,
+                             const AudioSource     * as,
+                             BitrateMode             outBitrateMode,
+                             unsigned int            outBitrate,
+--- a/src/aacPlusEncoder.cpp
++++ b/src/aacPlusEncoder.cpp
+@@ -114,7 +114,7 @@
+ #else
+         converter->initialize( resampleRatio, getInChannel());
+         //needed 2x(converted input samples) to handle offsets
+-	int outCount                 = 2 * getInChannel() * (inputSamples + 1);
++    int outCount                 = 2 * getInChannel() * (inputSamples + 1);
+         if (resampleRatio > 1)
+         outCount = (int) (outCount * resampleRatio);
+         resampledOffset = new short int[outCount];
+@@ -152,7 +152,6 @@
+     int             processedSamples = 0;
+ 
+ 
+-
+     if ( converter ) {
+         unsigned int         converted;
+ #ifdef HAVE_SRC_LIB
+@@ -178,25 +177,29 @@
+ 
+         // encode samples (if enough)
+         while(resampledOffsetSize - processedSamples >= inputSamples/channels) {
+-            int outputBytes;
+ #ifdef HAVE_SRC_LIB
+             short *shortData = new short[inputSamples];
+             src_float_to_short_array(resampledOffset + (processedSamples * channels),
+                                      shortData, inputSamples) ;
+-            outputBytes = aacplusEncEncode(encoderHandle,
++            int outputBytes = aacplusEncEncode(encoderHandle,
+                                        (int32_t*) shortData,
+                                         inputSamples,
+                                         aacplusBuf,
+                                         maxOutputBytes);
+             delete [] shortData;
+ #else
+-            outputBytes = aacplusEncEncode(encoderHandle,
++            int outputBytes = aacplusEncEncode(encoderHandle,
+                                        (int32_t*) &resampledOffset[processedSamples*channels],
+                                         inputSamples,
+                                         aacplusBuf,
+                                         maxOutputBytes);
+ #endif
+-            getSink()->write(aacplusBuf, outputBytes);
++            unsigned int wrote = getSink()->write(aacplusBuf, outputBytes);
++            
++            if (wrote < outputBytes) {
++                reportEvent(3, "aacPlusEncoder :: write, couldn't write full data to underlying sink");
++            }
++
+             processedSamples+=inputSamples/channels;
+         }
+ 
+@@ -214,18 +217,22 @@
+         }
+     } else {
+         while (processedSamples < samples) {
+-            int     outputBytes;
+             int     inSamples = samples - processedSamples < (int) inputSamples
+                               ? samples - processedSamples
+                               : inputSamples;
+ 
+-            outputBytes = aacplusEncEncode(encoderHandle,
++            int outputBytes = aacplusEncEncode(encoderHandle,
+                                        (int32_t*) (b + processedSamples/sampleSize),
+                                         inSamples,
+                                         aacplusBuf,
+                                         maxOutputBytes);
+-            getSink()->write(aacplusBuf, outputBytes);
+-
++            
++            unsigned int wrote = getSink()->write(aacplusBuf, outputBytes);
++            
++            if (wrote < outputBytes) {
++                reportEvent(3, "aacPlusEncoder :: write, couldn't write full data to underlying sink");
++            }
++            
+             processedSamples += inSamples;
+         }
+     }
-- 
2.8.1

>From 003c1d8d0f91885474c872db38b750a091007ab5 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sun, 31 Jul 2016 00:25:12 +0200
Subject: [PATCH 08/12] Various style improvements: * Standards-Version: 3.9.8 
  Explain status of init script in extended description. * Update homepage. *
 Rely on dpkg-dev to set DEB_HOST_MULTIARCH efficiently. * Link with
 --as-needed to reduce actual dependencies on some architectures. * Declare
 phony targets in debian/rules. * Explicitly disable aacplus to ensure
 reproducible builds   even if the library is available on the build system.

---
 debian/control | 11 +++++++++--
 debian/rules   | 22 ++++++++++++++++++++--
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/debian/control b/debian/control
index 6b9aaa9..e20c003 100644
--- a/debian/control
+++ b/debian/control
@@ -2,9 +2,11 @@ Source: darkice
 Section: sound
 Priority: optional
 Maintainer: Jochen Friedrich <joc...@scram.de>
-Standards-Version: 3.9.2
+Standards-Version: 3.9.8
 Build-Depends: debhelper (>= 9~), libvorbis-dev, libasound2-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], libjack-dev, libtwolame-dev, dh-autoreconf, libpulse-dev, libsamplerate0-dev, libopus-dev, libmp3lame-dev
-Homepage: http://code.google.com/p/darkice/
+# dpgk-dev provides /usr/share/dpkg/architecture.mk.
+ ,dpkg-dev (>= 1.16.1),
+Homepage: http://www.darkice.org/
 
 Package: darkice
 Architecture: any
@@ -17,3 +19,8 @@ Description: Live audio streamer
  ShoutCast servers, the Ogg Vorbis stream to one or more IceCast2
  servers. DarkIce uses lame as a shared object as its mp3 encoder, and
  the Ogg Vorbis as its Ogg Vorbis encoder.
+ .
+ A legacy SYSV init script is provided for existing
+ configurations. You have to set RUN=yes in /etc/default/darkice to
+ run darkice as a daemon. With modern systems, this is not needed as
+ realtime scheduling is available to normal users.
diff --git a/debian/rules b/debian/rules
index ec53039..9c57cbf 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,10 +1,27 @@
 #!/usr/bin/make -f
 
-DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+include /usr/share/dpkg/architecture.mk
 
-%:
+# Dependency on NSL is not really required on some architectures.
+export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed -Wl,-z,defs
+export DEB_BUILD_MAINT_OPTIONS := hardening=+all
+
+POLICY_TARGETS := binary binary-arch binary-indep build build-arch	\
+build-indep clean
+.PHONY: $(POLICY_TARGETS)
+$(POLICY_TARGETS):
 	dh $@ --with autoreconf
 
+# lame lacks pkg-config support and requires an explicit option.
+
+# vorbis, opus, twolame, alsa, pulseaudio, jack, samplerate are listed
+# in Build-Depends and selected automatically if present.
+
+# faac, aacplus are not in Debian main. Explicitly disable them so
+# that the build does not change if they are installed or removed.
+
+# Trick sysconfdir to install the examples in the right place.
+.PHONY: override_dh_auto_configure
 override_dh_auto_configure:
 	dh_auto_configure -- \
 		--with-lame-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
@@ -16,4 +33,5 @@ override_dh_auto_configure:
 		--with-jack-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
 		--prefix=/usr \
 		--sysconfdir=/usr/share/doc/darkice/examples \
+		--without-aacplus \
 		--without-faac
-- 
2.8.1

>From 96cbbdb110e3eb8f8a68e26846325d12e75b09ae Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sun, 31 Jul 2016 00:29:52 +0200
Subject: [PATCH 09/12] Remove --prefix configure option, already set by
 dh_auto_configure.

---
 debian/rules | 1 -
 1 file changed, 1 deletion(-)

diff --git a/debian/rules b/debian/rules
index 9c57cbf..5de5d8b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -31,7 +31,6 @@ override_dh_auto_configure:
 		--with-pulseaudio-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
 		--with-samplerate-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
 		--with-jack-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--prefix=/usr \
 		--sysconfdir=/usr/share/doc/darkice/examples \
 		--without-aacplus \
 		--without-faac
-- 
2.8.1

>From ad1e3a7d268daf14bbafc8b6cc42791d2f314fdf Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sun, 31 Jul 2016 00:41:19 +0200
Subject: [PATCH 10/12] Let ./configure rely on pkg-config to find path to
 external libraries. Current settings ignore CFLAGS like -DREENTRANT for
 pulseaudio.

---
 debian/control                              |   2 +
 debian/patches/pkg-config-if-available.diff | 427 ++++++++++++++++++++++++++++
 debian/patches/series                       |   1 +
 debian/rules                                |   6 -
 4 files changed, 430 insertions(+), 6 deletions(-)
 create mode 100644 debian/patches/pkg-config-if-available.diff

diff --git a/debian/control b/debian/control
index e20c003..3229eb3 100644
--- a/debian/control
+++ b/debian/control
@@ -6,6 +6,8 @@ Standards-Version: 3.9.8
 Build-Depends: debhelper (>= 9~), libvorbis-dev, libasound2-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], libjack-dev, libtwolame-dev, dh-autoreconf, libpulse-dev, libsamplerate0-dev, libopus-dev, libmp3lame-dev
 # dpgk-dev provides /usr/share/dpkg/architecture.mk.
  ,dpkg-dev (>= 1.16.1),
+# Configure tests rely on pkg-config.
+ ,pkg-config
 Homepage: http://www.darkice.org/
 
 Package: darkice
diff --git a/debian/patches/pkg-config-if-available.diff b/debian/patches/pkg-config-if-available.diff
new file mode 100644
index 0000000..e5362ea
--- /dev/null
+++ b/debian/patches/pkg-config-if-available.diff
@@ -0,0 +1,427 @@
+Description: use pkg-config to set CFLAGS and LIBS when available.
+ Pkg-config handles cross compilations for example.
+ Use CFLAGS LIBS LDADD current autoconf nomenclature.
+Author: Nicolas Boulenguez <nico...@debian.org>
+Author: Monsieur Noit <benoit.delc...@gmail.com>
+
+--- a/configure.in
++++ b/configure.in
+@@ -41,8 +41,8 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link the lame library if requested
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(LAME_INCFLAGS)
+-AC_SUBST(LAME_LDFLAGS)
++AC_SUBST(LAME_CFLAGS)
++AC_SUBST(LAME_LIBS)
+ 
+ AC_ARG_WITH(lame,
+ [  --with-lame             use lame for encoding mp3 streams [yes] ],
+@@ -60,9 +60,9 @@
+     if test "x${LAME_LIB_LOC}" != "x" ; then
+         AC_DEFINE( HAVE_LAME_LIB, 1, [build with lame library] )
+         if test "x${LAME_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            LAME_INCFLAGS="-I${LAME_INC_LOC}"
++            LAME_CFLAGS="-I${LAME_INC_LOC}"
+         fi
+-        LAME_LDFLAGS="-L${LAME_LIB_LOC} -lmp3lame"
++        LAME_LIBS="-L${LAME_LIB_LOC} -lmp3lame"
+         AC_MSG_RESULT( [found at ${CONFIG_LAME_PREFIX}] )
+     else
+         AC_MSG_WARN( [not found, building without lame])
+@@ -72,44 +72,22 @@
+ fi
+ 
+ 
++PKG_PROG_PKG_CONFIG()
++
++
+ dnl-----------------------------------------------------------------------------
+ dnl link the ogg vorbis libraries if requested
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(VORBIS_INCFLAGS)
+-AC_SUBST(VORBIS_LDFLAGS)
++AC_SUBST(VORBIS_CFLAGS)
++AC_SUBST(VORBIS_LIBS)
+ 
+ AC_ARG_WITH(vorbis,
+ [  --with-vorbis           use Ogg Vorbis for encoding vorbis streams [yes] ],
+     USE_VORBIS=${withval}, USE_VORBIS="yes" )
+-AC_ARG_WITH(vorbis-prefix,
+-[  --with-vorbis-prefix=DIR    alternate location for vorbis [/usr]
+-                              look for libraries in VORBIS-PREFIX/lib,
+-                              for headers in VORBIS-PREFIX/include],
+-    CONFIG_VORBIS_PREFIX="${withval}", CONFIG_VORBIS_PREFIX="/usr")
+-
+ if test "x${USE_VORBIS}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for vorbis libraries at ${CONFIG_VORBIS_PREFIX}] )
+-    LA_SEARCH_LIB( OGG_LIB_LOC, OGG_INC_LOC, libogg.a libogg.so, ogg/ogg.h,
+-                   ${CONFIG_VORBIS_PREFIX})
+-    LA_SEARCH_LIB( VORBIS_LIB_LOC, VORBIS_INC_LOC, libvorbis.a libvorbis.so, vorbis/codec.h,
+-                   ${CONFIG_VORBIS_PREFIX})
+-    LA_SEARCH_LIB( VORBISENC_LIB_LOC, VORBISENC_INC_LOC,
+-                   libvorbisenc.a libvorbisenc.so, vorbis/vorbisenc.h,
+-                   ${CONFIG_VORBIS_PREFIX})
+-
+-    if test "x${OGG_LIB_LOC}" != "x" -a \
+-            "x${VORBIS_LIB_LOC}" != "x" -a \
+-            "x${VORBISENC_LIB_LOC}" != "x" ; then
+-
+-        AC_DEFINE( HAVE_VORBIS_LIB, 1, [build with Ogg Vorbis library] )
+-        if test "x${OGG_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            VORBIS_INCFLAGS="-I${OGG_INC_LOC}"
+-        fi
+-        VORBIS_LDFLAGS="-L${OGG_LIB_LOC} -logg -lvorbis -lvorbisenc"
+-        AC_MSG_RESULT( [found at ${CONFIG_VORBIS_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without Ogg Vorbis])
+-    fi
++    AC_MSG_CHECKING( [for vorbis libraries] )
++    PKG_CHECK_MODULES( [VORBIS], [ogg vorbis vorbisenc],
++    [AC_DEFINE( HAVE_VORBIS_LIB, 1, [build with Ogg Vorbis library] )])
+ else
+     AC_MSG_RESULT( [building without Ogg Vorbis] )
+ fi
+@@ -118,37 +96,16 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link the ogg / opus libraries if requested
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(OPUS_INCFLAGS)
+-AC_SUBST(OPUS_LDFLAGS)
++AC_SUBST(OPUS_CFLAGS)
++AC_SUBST(OPUS_LIBS)
+ 
+ AC_ARG_WITH(opus,
+ [  --with-opus           use Ogg Opus for encoding opus streams [yes] ],
+     USE_OPUS=${withval}, USE_OPUS="yes" )
+-AC_ARG_WITH(opus-prefix,
+-[  --with-opus-prefix=DIR    alternate location for opus [/usr]
+-                              look for libraries in OPUS-PREFIX/lib,
+-                              for headers in OPUS-PREFIX/include],
+-    CONFIG_OPUS_PREFIX="${withval}", CONFIG_OPUS_PREFIX="/usr")
+-
+ if test "x${USE_OPUS}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for opus libraries at ${CONFIG_OPUS_PREFIX}] )
+-    LA_SEARCH_LIB( OGG_LIB_LOC, OGG_INC_LOC, libogg.a libogg.so, ogg/ogg.h,
+-                   ${CONFIG_OPUS_PREFIX})
+-    LA_SEARCH_LIB( OPUS_LIB_LOC, OPUS_INC_LOC, libopus.a libopus.so, opus/opus.h,
+-                   ${CONFIG_OPUS_PREFIX})
+-
+-    if test "x${OGG_LIB_LOC}" != "x" -a \
+-            "x${OPUS_LIB_LOC}" != "x" ; then
+-
+-        AC_DEFINE( HAVE_OPUS_LIB, 1, [build with Ogg Opus library] )
+-        if test "x${OGG_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            OPUS_INCFLAGS="-I${OGG_INC_LOC}"
+-        fi
+-        OPUS_LDFLAGS="-L${OGG_LIB_LOC} -logg -lopus"
+-        AC_MSG_RESULT( [found at ${CONFIG_OPUS_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without Ogg Opus])
+-    fi
++    AC_MSG_CHECKING( [for opus libraries] )
++    PKG_CHECK_MODULES( [OPUS], [ogg opus],
++    [AC_DEFINE( HAVE_OPUS_LIB, 1, [build with Ogg Opus library] )])
+ else
+     AC_MSG_RESULT( [building without Ogg Opus] )
+ fi
+@@ -156,8 +113,8 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link the faac library if requested
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(FAAC_INCFLAGS)
+-AC_SUBST(FAAC_LDFLAGS)
++AC_SUBST(FAAC_CFLAGS)
++AC_SUBST(FAAC_LIBS)
+ 
+ AC_ARG_WITH(faac,
+ [  --with-faac             use faac for encoding AAC streams [yes] ],
+@@ -175,9 +132,9 @@
+     if test "x${FAAC_LIB_LOC}" != "x" ; then
+         AC_DEFINE( HAVE_FAAC_LIB, 1, [build with faac library] )
+         if test "x${FAAC_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            FAAC_INCFLAGS="-I${FAAC_INC_LOC}"
++            FAAC_CFLAGS="-I${FAAC_INC_LOC}"
+         fi
+-        FAAC_LDFLAGS="-L${FAAC_LIB_LOC} -lfaac"
++        FAAC_LIBS="-L${FAAC_LIB_LOC} -lfaac"
+         AC_MSG_RESULT( [found at ${CONFIG_FAAC_PREFIX}] )
+     else
+         AC_MSG_WARN( [not found, building without faac])
+@@ -190,32 +147,17 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link the aacplus library if requested
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(AACPLUS_INCFLAGS)
+-AC_SUBST(AACPLUS_LDFLAGS)
++AC_SUBST(AACPLUS_CFLAGS)
++AC_SUBST(AACPLUS_LIBS)
+ 
+ AC_ARG_WITH(aacplus,
+ [  --with-aacplus             use aacplus for encoding AAC HEv2 streams [yes] ],
+     USE_AACPLUS=${withval}, USE_AACPLUS="yes" )
+-AC_ARG_WITH(aacplus-prefix,
+-[  --with-aacplus-prefix=DIR  alternate location for aacplus [/usr]
+-                              look for libraries in AACPLUS-PREFIX/lib,
+-                              for headers in AACPLUS-PREFIX/include],
+-    CONFIG_AACPLUS_PREFIX="${withval}", CONFIG_AACPLUS_PREFIX="/usr")
+ 
+ if test "x${USE_AACPLUS}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for aacplus library at ${CONFIG_AACPLUS_PREFIX}] )
+-    LA_SEARCH_LIB( AACPLUS_LIB_LOC, AACPLUS_INC_LOC, libaacplus.a libaacplus.so, aacplus.h,
+-                   ${CONFIG_AACPLUS_PREFIX})
+-    if test "x${AACPLUS_LIB_LOC}" != "x" ; then
+-        AC_DEFINE( HAVE_AACPLUS_LIB, 1, [build with aacplus library] )
+-        if test "x${AACPLUS_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            AACPLUS_INCFLAGS="-I${AACPLUS_INC_LOC}"
+-        fi
+-        AACPLUS_LDFLAGS="-L${AACPLUS_LIB_LOC} -laacplus"
+-        AC_MSG_RESULT( [found at ${CONFIG_AACPLUS_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without aacplus])
+-    fi
++    AC_MSG_CHECKING( [for aacplus library] )
++    PKG_CHECK_MODULES( [AACPLUS], [aacplus],
++    [AC_DEFINE( HAVE_AACPLUS_LIB, 1, [build with aacplus library] )])
+ else
+     AC_MSG_RESULT( [building without aacplus] )
+ fi
+@@ -224,32 +166,17 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link the twolame library if requested
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(TWOLAME_INCFLAGS)
+-AC_SUBST(TWOLAME_LDFLAGS)
++AC_SUBST(TWOLAME_CFLAGS)
++AC_SUBST(TWOLAME_LIBS)
+ 
+ AC_ARG_WITH(twolame,
+ [  --with-twolame             use twolame for encoding MP2 streams [yes] ],
+     USE_TWOLAME=${withval}, USE_TWOLAME="yes" )
+-AC_ARG_WITH(twolame-prefix,
+-[  --with-twolame-prefix=DIR  alternate location for twolame [/usr]
+-                              look for libraries in TWOLAME-PREFIX/lib,
+-                              for headers in TWOLAME-PREFIX/include],
+-    CONFIG_TWOLAME_PREFIX="${withval}", CONFIG_TWOLAME_PREFIX="/usr")
+ 
+ if test "x${USE_TWOLAME}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for twolame library at ${CONFIG_TWOLAME_PREFIX}] )
+-    LA_SEARCH_LIB( TWOLAME_LIB_LOC, TWOLAME_INC_LOC, libtwolame.a libtwolame.so, twolame.h,
+-                   ${CONFIG_TWOLAME_PREFIX})
+-    if test "x${TWOLAME_LIB_LOC}" != "x" ; then
+-        AC_DEFINE( HAVE_TWOLAME_LIB, 1, [build with twolame library] )
+-        if test "x${TWOLAME_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            TWOLAME_INCFLAGS="-I${TWOLAME_INC_LOC}"
+-        fi
+-        TWOLAME_LDFLAGS="-L${TWOLAME_LIB_LOC} -ltwolame"
+-        AC_MSG_RESULT( [found at ${CONFIG_TWOLAME_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without twolame])
+-    fi
++    AC_MSG_CHECKING( [for twolame library] )
++    PKG_CHECK_MODULES( [TWOLAME], [twolame],
++    [AC_DEFINE( HAVE_TWOLAME_LIB, 1, [build with twolame library] )])
+ else
+     AC_MSG_RESULT( [building without twolame] )
+ fi
+@@ -258,12 +185,12 @@
+ dnl-----------------------------------------------------------------------------
+ dnl make sure at least one of lame and vorbis present
+ dnl-----------------------------------------------------------------------------
+-if test "x${LAME_LDFLAGS}" = "x" \
+-     -a "x${VORBIS_LDFLAGS}" = "x" \
+-     -a "x${OPUS_LDFLAGS}" = "x" \
+-     -a "x${FAAC_LDFLAGS}" = "x" \
+-     -a "x${AACPLUS_LDFLAGS}" = "x" \
+-     -a "x${TWOLAME_LDFLAGS}" = "x"; then
++if test "x${LAME_LIBS}" = "x" \
++     -a "x${VORBIS_LIBS}" = "x" \
++     -a "x${OPUS_LIBS}" = "x" \
++     -a "x${FAAC_LIBS}" = "x" \
++     -a "x${AACPLUS_LIBS}" = "x" \
++     -a "x${TWOLAME_LIBS}" = "x"; then
+     AC_MSG_ERROR([neither lame, Ogg Vorbis, opus, faac, aac+ nor twolame configured])
+ fi
+ 
+@@ -271,34 +198,16 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link ALSA sound system if requested 
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(ALSA_INCFLAGS)
+-AC_SUBST(ALSA_LDFLAGS)
++AC_SUBST(ALSA_CFLAGS)
++AC_SUBST(ALSA_LIBS)
+ 
+ AC_ARG_WITH(alsa,
+ [  --with-alsa             use ALSA sound system [yes] ],
+     USE_ALSA=${withval}, USE_ALSA="yes" )
+-AC_ARG_WITH(alsa-prefix,
+-[  --with-alsa-prefix=DIR      alternate location for ALSA [/usr]
+-                              look for libraries in ALSA-PREFIX/lib,
+-                              for headers in ALSA-PREFIX/include],
+-    CONFIG_ALSA_PREFIX="${withval}", CONFIG_ALSA_PREFIX="/usr")
+-
+ if test "x${USE_ALSA}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for alsa libraries at ${CONFIG_ALSA_PREFIX}] )
+-    LA_SEARCH_LIB( ALSA_LIB_LOC, ALSA_INC_LOC, libasound.so, alsa/asoundlib.h,
+-                   ${CONFIG_ALSA_PREFIX})
+-
+-    if test "x${ALSA_LIB_LOC}" != "x" ; then
+-
+-        AC_DEFINE( HAVE_ALSA_LIB, 1, [build with ALSA sound system] )
+-        if test "x${ALSA_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            ALSA_INCFLAGS="-I${ALSA_INC_LOC}"
+-        fi
+-        ALSA_LDFLAGS="-L${ALSA_LIB_LOC} -lasound"
+-        AC_MSG_RESULT( [found at ${CONFIG_ALSA_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without ALSA support])
+-    fi
++    AC_MSG_CHECKING( [for alsa libraries] )
++    PKG_CHECK_MODULES( [ALSA], [alsa],
++    [AC_DEFINE( HAVE_ALSA_LIB, 1, [build with ALSA sound system] )])
+ else
+     AC_MSG_RESULT( [building without ALSA support] )
+ fi
+@@ -307,34 +216,16 @@
+ dnl-----------------------------------------------------------------------------
+ dnl link PULSEAUDIO sound system if requested 
+ dnl-----------------------------------------------------------------------------
+-AC_SUBST(PULSEAUDIO_INCFLAGS)
+-AC_SUBST(PULSEAUDIO_LDFLAGS)
++AC_SUBST(PULSEAUDIO_CFLAGS)
++AC_SUBST(PULSEAUDIO_LIBS)
+ 
+ AC_ARG_WITH(pulseaudio,
+ [  --with-pulseaudio             use PULSEAUDIO sound system [yes] ],
+     USE_PULSEAUDIO=${withval}, USE_PULSEAUDIO="yes" )
+-AC_ARG_WITH(pulseaudio-prefix,
+-[  --with-pulseaudio-prefix=DIR      alternate location for PULSEAUDIO [/usr]
+-                              look for libraries in PULSEAUDIO-PREFIX/lib,
+-                              for headers in PULSEAUDIO-PREFIX/include],
+-    CONFIG_PULSEAUDIO_PREFIX="${withval}", CONFIG_PULSEAUDIO_PREFIX="/usr")
+-
+ if test "x${USE_PULSEAUDIO}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for pulseaudio libraries at ${CONFIG_PULSEAUDIO_PREFIX}] )
+-    LA_SEARCH_LIB( PULSEAUDIO_LIB_LOC, PULSEAUDIO_INC_LOC, libpulse.so, pulse/pulseaudio.h,
+-                   ${CONFIG_PULSEAUDIO_PREFIX})
+-
+-    if test "x${PULSEAUDIO_LIB_LOC}" != "x" ; then
+-
+-        AC_DEFINE( HAVE_PULSEAUDIO_LIB, 1, [build with PULSEAUDIO sound system] )
+-        if test "x${PULSEAUDIO_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            PULSEAUDIO_INCFLAGS="-I${PULSEAUDIO_INC_LOC}"
+-        fi
+-        PULSEAUDIO_LDFLAGS="-L${PULSEAUDIO_LIB_LOC} -lpulse-simple -L${PULSEAUDIO_LIB_LOC} -lpulse"
+-        AC_MSG_RESULT( [found at ${CONFIG_PULSEAUDIO_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without PULSEAUDIO support])
+-    fi
++    AC_MSG_CHECKING( [for pulseaudio libraries] )
++    PKG_CHECK_MODULES( [PULSEAUDIO], [libpulse-simple libpulse],
++    [AC_DEFINE( HAVE_PULSEAUDIO_LIB, 1, [build with PULSEAUDIO sound system] )])
+ else
+     AC_MSG_RESULT( [building without PULSEAUDIO support] )
+ fi
+@@ -344,34 +235,15 @@
+ dnl link JACK sound server if requested 
+ dnl-----------------------------------------------------------------------------
+ AC_SUBST(JACK_CFLAGS)
+-AC_SUBST(JACK_LDFLAGS)
+-AC_SUBST(JACK_INCFLAGS)
++AC_SUBST(JACK_LIBS)
+ 
+ AC_ARG_WITH(jack,
+ [  --with-jack             use JACK sound system [yes] ],
+     USE_JACK=${withval}, USE_JACK="yes" )
+-AC_ARG_WITH(jack-prefix,
+-[  --with-jack-prefix=DIR      alternate location for JACK [/usr]
+-                              look for libraries in JACK-PREFIX/lib,
+-                              for headers in JACK-PREFIX/include],
+-    CONFIG_JACK_PREFIX="${withval}", CONFIG_JACK_PREFIX="/usr")
+-
+ if test "x${USE_JACK}" = "xyes" ; then
+     AC_MSG_CHECKING( [for jack libraries at ${CONFIG_JACK_PREFIX}] )
+-    LA_SEARCH_LIB( JACK_LIB_LOC, JACK_INC_LOC, libjack.la libjack.so libjack.dylib, jack/jack.h,
+-                   ${CONFIG_JACK_PREFIX})
+-
+-    if test "x${JACK_LIB_LOC}" != "x" ; then
+-
+-        AC_DEFINE( HAVE_JACK_LIB, 1, [build with JACK audio server support] )
+-        if test "x${JACK_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            JACK_INCFLAGS="-I${JACK_INC_LOC}"
+-        fi
+-        JACK_LDFLAGS="-L${JACK_LIB_LOC} -ljack"
+-        AC_MSG_RESULT( [found at ${CONFIG_JACK_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building without JACK support])
+-    fi
++    PKG_CHECK_MODULES( [JACK], [jack],
++    [AC_DEFINE( HAVE_JACK_LIB, 1, [build with JACK audio server support] )])
+ else
+     AC_MSG_RESULT( [building without JACK support] )
+ fi
+@@ -381,39 +253,20 @@
+ dnl link Secret Rabbit Code (aka libsamplerate) if requested 
+ dnl-----------------------------------------------------------------------------
+ AC_SUBST(SRC_CFLAGS)
+-AC_SUBST(SRC_LDFLAGS)
+-AC_SUBST(SRC_INCFLAGS)
++AC_SUBST(SRC_LIBS)
+ 
+ AC_ARG_WITH(samplerate,
+ [  --with-samplerate             use Secret Rabbit Code (aka libsamplerate) for samplerate conversion [yes] ],
+     USE_SRC=${withval}, USE_SRC="yes" )
+-AC_ARG_WITH(samplerate-prefix,
+-[  --with-samplerate-prefix=DIR      alternate location for samplerate [/usr]
+-                              look for libraries in SRC-PREFIX/lib,
+-                              for headers in SRC-PREFIX/include],
+-    CONFIG_SRC_PREFIX="${withval}", CONFIG_SRC_PREFIX="/usr")
+-
+ if test "x${USE_SRC}" = "xyes" ; then
+-    AC_MSG_CHECKING( [for samplerate libraries at ${CONFIG_SRC_PREFIX}] )
+-    LA_SEARCH_LIB( SRC_LIB_LOC, SRC_INC_LOC, libsamplerate.la libsamplerate.so libsamplerate.dylib, samplerate.h,
+-                   ${CONFIG_SRC_PREFIX})
+-
+-    if test "x${SRC_LIB_LOC}" != "x" ; then
+-
+-        AC_DEFINE( HAVE_SRC_LIB, 1, [build with samplerate conversion through libsamplerate] )
+-        if test "x${SRC_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then
+-            SRC_INCFLAGS="-I${SRC_INC_LOC}"
+-        fi
+-        SRC_LDFLAGS="-L${SRC_LIB_LOC} -lsamplerate"
+-        AC_MSG_RESULT( [found at ${CONFIG_SRC_PREFIX}] )
+-    else
+-        AC_MSG_WARN( [not found, building libsamplerate support])
+-    fi
++    AC_MSG_CHECKING( [for samplerate libraries] )
++    PKG_CHECK_MODULES( [SRC], [samplerate],
++    [AC_DEFINE( HAVE_SRC_LIB, 1, [build with samplerate conversion through libsamplerate] )])
+ else
+     AC_MSG_RESULT( [building without libsamplerate support] )
+ fi
+ 
+-AM_CONDITIONAL(HAVE_SRC_LIB, test "x${SRC_LIB_LOC}" != "x")
++AM_CONDITIONAL(HAVE_SRC_LIB, test "x${SRC_LIBS}" != "x")
+ dnl-----------------------------------------------------------------------------
+ dnl check for MSG_NOSIGNAL for the send() function in libsocket
+ dnl-----------------------------------------------------------------------------
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -1,10 +1,10 @@
+ bin_PROGRAMS = darkice
+-AM_CXXFLAGS = -O2 -pedantic -Wall @DEBUG_CXXFLAGS@ @PTHREAD_CFLAGS@
+-			  @JACK_CFLAGS@ 
+-INCLUDES = @LAME_INCFLAGS@ @VORBIS_INCFLAGS@ @OPUS_INCFLAGS@ @FAAC_INCFLAGS@ @AACPLUS_INCFLAGS@ @TWOLAME_INCFLAGS@ \
+-		@ALSA_INCFLAGS@ @PULSEAUDIO_INCFLAGS@ @JACK_INCFLAGS@ @SRC_INCFLAGS@
+-LDADD = @PTHREAD_LIBS@ @LAME_LDFLAGS@ @VORBIS_LDFLAGS@ @OPUS_LDFLAGS@ @FAAC_LDFLAGS@ @AACPLUS_LDFLAGS@ @TWOLAME_LDFLAGS@ \
+-		@ALSA_LDFLAGS@ @PULSEAUDIO_LDFLAGS@ @JACK_LDFLAGS@ @SRC_LDFLAGS@
++
++darkice_CXXFLAGS = \
++ -O2 -pedantic -Wall @DEBUG_CXXFLAGS@ \
++  $(PTHREAD_CFLAGS) $(LAME_CFLAGS) $(VORBIS_CFLAGS) $(OPUS_CFLAGS) $(FAAC_CFLAGS) $(AACPLUS_CFLAGS) $(TWOLAME_CFLAGS) $(ALSA_CFLAGS) $(PULSEAUDIO_CFLAGS) $(JACK_CFLAGS) $(SRC_CFLAGS)
++darkice_LDADD = \
++ $(PTHREAD_LIBS) $(LAME_LIBS) $(VORBIS_LIBS) $(OPUS_LIBS) $(FAAC_LIBS) $(AACPLUS_LIBS) $(TWOLAME_LIBS) $(ALSA_LIBS) $(PULSEAUDIO_LIBS) $(JACK_LIBS) $(SRC_LIBS)
+ 
+ if HAVE_SRC_LIB
+ AFLIB_SOURCE = 
diff --git a/debian/patches/series b/debian/patches/series
index 7f98598..0cebedd 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -7,3 +7,4 @@ accept-data-until-next-ogg-packet-is-ready-in-vorbis.diff
 fixed-issue-98.diff
 fixes-for-opus-encoder-by-christian-franke-nobody-no.diff
 server-connection-related-fixes.diff
+pkg-config-if-available.diff
diff --git a/debian/rules b/debian/rules
index 5de5d8b..5131efc 100755
--- a/debian/rules
+++ b/debian/rules
@@ -25,12 +25,6 @@ $(POLICY_TARGETS):
 override_dh_auto_configure:
 	dh_auto_configure -- \
 		--with-lame-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--with-vorbis-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--with-opus-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--with-alsa-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--with-pulseaudio-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--with-samplerate-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
-		--with-jack-prefix=/usr/lib/$(DEB_HOST_MULTIARCH) \
 		--sysconfdir=/usr/share/doc/darkice/examples \
 		--without-aacplus \
 		--without-faac
-- 
2.8.1

>From 2adad212ceaf4c31b7b34ede2308260701c41593 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sun, 31 Jul 2016 00:51:47 +0200
Subject: [PATCH 11/12] Prepare changelog for NMU.

---
 debian/changelog | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index e3d366c..359f96d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,26 @@
+darkice (1.2-0.3) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Apply some upstream VCS commits.
+    - Accept data until next Ogg packet is ready in VorbisEncoder#canWrite
+    - fixed issue 98 (check minimum vorbis output rate)
+    - fixes for Opus encoder by Christian Franke <nob...@nowhere.ws>
+    - Server connection related fixes.
+  * Let ./configure rely on pkg-config to find path to external libraries.
+    Current settings ignore CFLAGS like -DREENTRANT for pulseaudio.
+  * Enable all hardening flags.  Link with --as-needed -z defs.
+  * Explicitly disable aacplus to ensure reproducible builds
+    even if the library is available on the build system.
+  * Update homepage and watch file.
+  * Standards-Versions: 3.9.8. Explain status of init script in description.
+  * Let architecture.mk from dpkg-dev>=1.16.1 set DEB_HOST_MULTIARCH.
+  * Document patches according to DEP-3 patch tagging guidelines.
+  * Switch copyright file to 1.0 machine-readable format.
+  * Update README.debian, mp3lame has been enabled since 1.2-0.1.
+  * Remove redundant files (clean dirs) and configure options (prefix).
+
+ -- Nicolas Boulenguez <nico...@debian.org>  Sun, 31 Jul 2016 00:43:03 +0200
+
 darkice (1.2-0.2) unstable; urgency=medium
 
   * Non-maintainer upload.
-- 
2.8.1

>From 0266042757d6b3dbaab7331af2abdbf00b002bf7 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.bouleng...@free.fr>
Date: Sun, 31 Jul 2016 01:09:34 +0200
Subject: [PATCH 12/12] Various typos detected by lintian.

---
 debian/patches/series     |   1 +
 debian/patches/typos.diff | 308 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 309 insertions(+)
 create mode 100644 debian/patches/typos.diff

diff --git a/debian/patches/series b/debian/patches/series
index 0cebedd..8da36dd 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -8,3 +8,4 @@ fixed-issue-98.diff
 fixes-for-opus-encoder-by-christian-franke-nobody-no.diff
 server-connection-related-fixes.diff
 pkg-config-if-available.diff
+typos.diff
diff --git a/debian/patches/typos.diff b/debian/patches/typos.diff
new file mode 100644
index 0000000..574d253
--- /dev/null
+++ b/debian/patches/typos.diff
@@ -0,0 +1,308 @@
+Description: typos.
+Author: Nicolas Boulenguez <nico...@debian.org>
+
+--- a/src/DarkIce.cpp
++++ b/src/DarkIce.cpp
+@@ -1277,7 +1277,7 @@
+ 
+     len = encConnector->transfer( bytes, 4096, 1, 0 );
+ 
+-    reportEvent( 1, len, "bytes transfered to the encoders");
++    reportEvent( 1, len, "bytes transferred to the encoders");
+ 
+     encConnector->close();
+ 
+--- a/src/MultiThreadedConnector.cpp
++++ b/src/MultiThreadedConnector.cpp
+@@ -229,7 +229,7 @@
+     dataBuffer   = new unsigned char[bufSize];
+     dataSize     = 0;
+ 
+-    reportEvent( 6, "MultiThreadedConnector :: tranfer, bytes", bytes);
++    reportEvent( 6, "MultiThreadedConnector :: transfer, bytes", bytes);
+ 
+     for ( b = 0; !bytes || b < bytes; ) {
+         if ( source->canRead( sec, usec) ) {
+--- a/man/darkice.cfg.5
++++ b/man/darkice.cfg.5
+@@ -175,7 +175,7 @@
+ Genre of the stream
+ .TP
+ .I public
+-"yes" or "no", wether the stream is public
++"yes" or "no", whether the stream is public
+ .TP
+ .I remoteDumpFile 
+ The file the
+@@ -189,7 +189,7 @@
+ server to this local file.
+ .TP
+ .I fileAddDate
+-"yes" or "no" if you want to automaticaly insert a date string in 
++"yes" or "no" if you want to automatically insert a date string in 
+ the localDumpFile name before its extension or at the end of file name if
+ no extension present
+ .TP
+@@ -302,7 +302,7 @@
+ Genre of the stream
+ .TP
+ .I public
+-"yes" or "no", wether the stream is public
++"yes" or "no", whether the stream is public
+ .TP
+ .I localDumpFile
+ Dump the same Ogg Vorbis data sent to the
+@@ -310,7 +310,7 @@
+ server to this local file.
+ .TP
+ .I fileAddDate
+-"yes" or "no" if you want to automaticaly insert a date string in 
++"yes" or "no" if you want to automatically insert a date string in 
+ the localDumpFile name before its extension or at the end of file name if
+ no extension present
+ .TP
+@@ -403,7 +403,7 @@
+ Genre of the stream
+ .TP
+ .I public
+-"yes" or "no", wether the stream is public
++"yes" or "no", whether the stream is public
+ .TP
+ .I irc
+ IRC information related to the stream
+@@ -432,7 +432,7 @@
+ server to this local file.
+ .TP
+ .I fileAddDate
+-"yes" or "no" if you want to automaticaly insert a date string in 
++"yes" or "no" if you want to automatically insert a date string in 
+ the localDumpFile name before its extension or at the end of file name if
+ no extension present
+ .TP
+--- a/src/AlsaDspSource.cpp
++++ b/src/AlsaDspSource.cpp
+@@ -210,7 +210,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check whether read() would return anything
+  *----------------------------------------------------------------------------*/
+ bool
+ AlsaDspSource :: canRead ( unsigned int    sec,
+--- a/src/AudioEncoder.h
++++ b/src/AudioEncoder.h
+@@ -441,7 +441,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
+--- a/src/CastSink.h
++++ b/src/CastSink.h
+@@ -431,7 +431,7 @@
+         }
+ 
+         /**
+-         *  Get wether this stream is public.
++         *  Get whether this stream is public.
+          *
+          *  @return true if the stream is public, false otherwise.
+          */
+--- a/src/FaacEncoder.h
++++ b/src/FaacEncoder.h
+@@ -399,7 +399,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
+--- a/src/FileSink.cpp
++++ b/src/FileSink.cpp
+@@ -191,7 +191,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether a file exists and is regular file
++ *  Check whether a file exists and is regular file
+  *----------------------------------------------------------------------------*/
+ bool
+ FileSink :: exists ( void ) const               throw ()
+@@ -250,7 +250,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether the file can be written to
++ *  Check whether the file can be written to
+  *----------------------------------------------------------------------------*/
+ bool
+ FileSink :: canWrite (     unsigned int    sec,
+--- a/src/JackDspSource.cpp
++++ b/src/JackDspSource.cpp
+@@ -302,7 +302,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check whether read() would return anything
+  *----------------------------------------------------------------------------*/
+ bool
+ JackDspSource :: canRead ( unsigned int   sec,
+--- a/src/LameLibEncoder.h
++++ b/src/LameLibEncoder.h
+@@ -320,7 +320,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
+--- a/src/OpusLibEncoder.h
++++ b/src/OpusLibEncoder.h
+@@ -447,7 +447,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
+--- a/src/OssDspSource.cpp
++++ b/src/OssDspSource.cpp
+@@ -229,7 +229,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check whether read() would return anything
+  *----------------------------------------------------------------------------*/
+ bool
+ OssDspSource :: canRead ( unsigned int    sec,
+--- a/src/OssDspSource.h
++++ b/src/OssDspSource.h
+@@ -69,7 +69,7 @@
+         int         fileDescriptor;
+ 
+         /**
+-         *  Indicates wether the low-level OSS DSP device is in a recording
++         *  Indicates whether the low-level OSS DSP device is in a recording
+          *  state.
+          */
+         bool        running;
+--- a/src/PulseAudioDspSource.cpp
++++ b/src/PulseAudioDspSource.cpp
+@@ -173,7 +173,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check whether read() would return anything
+  *----------------------------------------------------------------------------*/
+ bool
+ PulseAudioDspSource :: canRead ( unsigned int    sec,
+--- a/src/SerialUlaw.h
++++ b/src/SerialUlaw.h
+@@ -70,7 +70,7 @@
+         int         fileDescriptor;
+ 
+         /**
+-         *  Indicates wether the low-level OSS DSP device is in a recording
++         *  Indicates whether the low-level OSS DSP device is in a recording
+          *  state.
+          */
+         bool        running;
+--- a/src/SolarisDspSource.cpp
++++ b/src/SolarisDspSource.cpp
+@@ -201,7 +201,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check whether read() would return anything
+  *----------------------------------------------------------------------------*/
+ bool
+ SolarisDspSource :: canRead ( unsigned int    sec,
+--- a/src/TcpSocket.cpp
++++ b/src/TcpSocket.cpp
+@@ -256,7 +256,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether read() would return anything
++ *  Check whether read() would return anything
+  *----------------------------------------------------------------------------*/
+ bool
+ TcpSocket :: canRead (      unsigned int    sec,
+@@ -329,7 +329,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether write() would send anything
++ *  Check whether write() would send anything
+  *----------------------------------------------------------------------------*/
+ bool
+ TcpSocket :: canWrite (    unsigned int    sec,
+--- a/src/TwoLameLibEncoder.h
++++ b/src/TwoLameLibEncoder.h
+@@ -249,7 +249,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
+--- a/src/Util.cpp
++++ b/src/Util.cpp
+@@ -235,7 +235,7 @@
+ 
+ 
+ /*------------------------------------------------------------------------------
+- *  Check wether two strings are equal
++ *  Check whether two strings are equal
+  *----------------------------------------------------------------------------*/
+ bool
+ Util :: strEq( const char    * str1,
+--- a/src/Util.h
++++ b/src/Util.h
+@@ -169,7 +169,7 @@
+         strDup (        const char    * str )       throw ( Exception );
+ 
+         /**
+-         *  Determine wether two string are equal.
++         *  Determine whether two string are equal.
+          *
+          *  @param str1 one of the strings.
+          *  @param str2 the other string.
+--- a/src/VorbisLibEncoder.h
++++ b/src/VorbisLibEncoder.h
+@@ -331,7 +331,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
+--- a/src/aacPlusEncoder.h
++++ b/src/aacPlusEncoder.h
+@@ -401,7 +401,7 @@
+         }
+ 
+         /**
+-         *  Check wether encoding is in progress.
++         *  Check whether encoding is in progress.
+          *
+          *  @return true if encoding is in progress, false otherwise.
+          */
-- 
2.8.1

Reply via email to