--- wengophone-2.1.2.dfsg0.orig/debian/rules
+++ wengophone-2.1.2.dfsg0/debian/rules
@@ -0,0 +1,57 @@
+#!/usr/bin/make -f
+
+include debian/cmake.mk
+include /usr/share/cdbs/1/rules/debhelper.mk
+include /usr/share/cdbs/1/rules/patchsys-quilt.mk
+
+DEB_DESTDIR=$(CURDIR)/debian/wengophone
+DEB_DH_STRIP_ARGS := --dbg-package=wengophone
+
+DEB_INSTALL_MANPAGES_wengophone := $(CURDIR)/debian/qtwengophone.1
+DEB_INSTALL_DOCS_wengophone := $(CURDIR)/wengophone/src/presentation/qt/AUTHORS
+
+DEB_CMAKE_EXTRA_FLAGS := -DQT_UIC_EXECUTABLE=/usr/bin/uic-qt4 \
+	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
+	-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
+	-DOWSOUND_PORTAUDIO_SUPPORT=OFF \
+	-DFFMPEG_INTERNAL=OFF \
+	-DSPEEX_INTERNAL=OFF \
+	-DSAMPLERATE_INTERNAL=OFF \
+	-DCURL_INTERNAL=OFF \
+	-DPHAPI_VIDEO_SUPPORT=ON \
+	-DHAVE_SWSCALE=1
+
+
+ifeq ($(DEB_HOST_ARCH), i386)
+        DEB_CMAKE_EXTRA_FLAGS += -DENABLE_CRASHREPORT=ON
+else
+        ifeq ($(DEB_HOST_ARCH), amd64)
+                DEB_CMAKE_EXTRA_FLAGS += -DENABLE_CRASHREPORT=ON
+        else
+                DEB_CMAKE_EXTRA_FLAGS += -DENABLE_CRASHREPORT=OFF
+        endif
+endif
+
+
+# Avoid postinst-has-useless-call-to-ldconfig
+DEB_DH_MAKESHLIBS_ARGS_wengophone := -n
+
+DEBVERSION:=$(shell head -n 1 debian/changelog | sed -e 's/^[^(]*(\([^)]*\)).*/\1/')
+SRCVERSION:=$(shell echo $(DEBVERSION) | sed -e 's/^.*://' -e 's/-[.0-9]*$$//')
+UPVERSION:=$(shell echo $(SRCVERSION) | sed -e 's/-svn.*$$//' -e 's/\.dfsg.*$$//')
+SVNVERSION:=$(shell echo $(DEBVERSION) | grep svn | sed -e 's/^.*svn//' -e 's/-[0-9]*$$//')
+
+SVNREP:=https://dev.openwengo.com/svn/openwengo/wengophone-ng/tags/release/2.1/2007-08-22-wengophone-2.1.2
+
+print-version:
+	@@echo "Debian version:          $(DEBVERSION)"
+	@@echo "Source version:          $(SRCVERSION)"
+	@@echo "Upstream version:        $(UPVERSION)"
+	@@echo "Svn version:             $(SVNVERSION)"
+
+get-orig-source:
+	@@dh_testdir
+	@@[ -d ../tarballs/. ]||mkdir -p ../tarballs
+	@@echo Downloading version $(UPVERSION) from $(SVNREP) ...
+	@@chmod +x debian/get-orig-source.sh
+	debian/get-orig-source.sh $(SRCVERSION) $(SVNREP) $(SVNVERSION)
--- wengophone-2.1.2.dfsg0.orig/debian/wengophone.menu
+++ wengophone-2.1.2.dfsg0/debian/wengophone.menu
@@ -0,0 +1,4 @@
+?package(wengophone):needs="X11" section="Applications/Network/Communication"\
+  command="/usr/bin/qtwengophone"\
+  title="WengoPhone" icon="/usr/share/pixmaps/wengophone.xpm"\
+  longtitle="SIP-based software telephone with video and chat features"
--- wengophone-2.1.2.dfsg0.orig/debian/copyright
+++ wengophone-2.1.2.dfsg0/debian/copyright
@@ -0,0 +1,80 @@
+This package was debianized by Marco Nenciarini <mnencia@debian.org> on
+Mon,  6 Feb 2006 10:54:04 +0100.
+
+It was downloaded from 
+http://dev.openwengo.com/svn/openwengo/softphone-classic
+
+Copyright Holder: Wengo Development Team <wengophone-devel@lists.openwengo.com>
+
+License:
+
+   This package 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 package 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 package; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+   As a special exception, Wengo gives permission to link
+   this program with the Qt Library (commercial or non-commercial edition),
+   and distribute the resulting executable, without including the source
+   code for the Qt library in the source distribution.
+
+   As a special exception, Wengo gives permission to link
+   this program with the OpenSSL Library.
+
+On Debian systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL'.
+
+This software contains some files from the following other softwares:
+
+- phApi
+Copyright (C) Vadim Lebedev
+published under GNU GPL
+
+- eXosip
+Copyright (C) Aymeric Moizard
+published under GNU GPL
+
+- oSIP
+Copyright (C) Aymeric Moizard
+published under GNU LGPL
+
+- oRTP
+Copyright (C) Simon Morlat
+published under GNU LGPL
+
+- trayicon
+Copyright (C) Justin Karneges
+published under GNU LGPL
+
+- cURL
+Copyright (C) Daniel Stenberg
+published under MIT/X-style license
+
+- TinyXML
+Copyright (C) Lee Thomason
+published under zlib license
+
+- sipX
+Copyright (C) Pingtel Corp
+published under GNU LGPL
+
+- Gaim
+published under GNU GPL
+
+- OWbuild
+Copyright (C) 2006-2007  Wengo
+published under BSD-style license
+
+- Coredumper
+Copyright (c) 2005, Google Inc.
+published under BSD-style license
+
--- wengophone-2.1.2.dfsg0.orig/debian/compat
+++ wengophone-2.1.2.dfsg0/debian/compat
@@ -0,0 +1 @@
+4
--- wengophone-2.1.2.dfsg0.orig/debian/changelog
+++ wengophone-2.1.2.dfsg0/debian/changelog
@@ -0,0 +1,468 @@
+wengophone (2.1.2.dfsg0-6) unstable; urgency=low
+
+  * Removed debian/cmake-no-soname-shlibs.patch. Closes: #486948
+  * Added Build-Conflicts with qt3-dev-tools (can be removed after cmake bug
+    #487528 gets closed) 
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Sun, 22 Jun 2008 14:50:36 +0200
+
+wengophone (2.1.2.dfsg0-5) unstable; urgency=low
+
+  * Add build dependency on libx11-dev and python-dev. Closes: #479920
+  * Add ffmpeg-swscale-api.patch and img_resample.patch from 2.2 branch in
+    order to use swscale instead of img_resample (removed from ffmpeg)
+  * Remove build dependency on libavformat-dev
+  * Add cmake-swscale.patch to link against libswscale and not agains
+    libavformat
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Wed, 18 Jun 2008 19:16:37 +0200
+
+wengophone (2.1.2.dfsg0-4) unstable; urgency=low
+
+  * Update patch generic/gcc-4_3.patch to resolve FTBFS with GCC 4.3.
+    Closes: #475994
+  * Update wengophone.xpm for consistency with hicolor icons.
+  * Update patch generic/desktop-file-update.patch for more meaningful
+    comments inside wengophone.desktop file
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Tue, 22 Apr 2008 17:14:36 -0700
+
+wengophone (2.1.2.dfsg0-3) unstable; urgency=low
+
+  * Add patch generic/gcc-4_3.patch to make it compileable with GCC 4.3
+    (thanks to Cyril Brulebois). Closes: #455654
+  * Update package description. Closes: #463812
+  * Update Standards-Version to 3.7.3
+  * Fix build depends according to build-depends-on-1-revision lintian warning
+  * Compiling with swscale support
+  * Import the code for managing ALSA devices from the 2.2 branch.
+    Closes: #471385
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Sun, 23 Mar 2008 23:37:04 +0100
+
+wengophone (2.1.2.dfsg0-2) unstable; urgency=low
+
+  * Documented video support status in README.Debian. Closes: #448307
+  * Added patch qt-fix-bad-window-size.patch to fix bad window size under
+    some configurations
+  * Removed Build-Conflicts on qt3-dev-tools: no longer necessary since
+    cmake 2.4.3-3
+  * Added patches to comply with the new dpkg-shlibdeps (1.14.7):
+    - debian/cmake-rpath-shlibs.patch: add RPATH to private shared libraries
+      depending on other private shared libraries
+    - debian/patches/debian/cmake-no-soname-shlibs.patch: remove SONAMEs from
+      private shared libraries
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Wed, 28 Nov 2007 23:56:26 +0100
+
+wengophone (2.1.2.dfsg0-1) unstable; urgency=low
+
+  * New upstream release
+  * Removed patches (merged upstream):
+    - head/phapi-disable-iLBC-codec.patch
+    - generic/exosip-fix-empty-notify.patch
+    - generic/portaudio-avoid-unnecessary-inclusion.patch
+    - generic/phapi-fix-empty-ctype-dos.patch
+  * Refreshed patches:
+    - generic/qobjectthreadsafe-fix-qt42.patch (partially merged upstream)
+    - generic/cmake-fix-ENABLE_CRASHREPORT.patch
+    - generic/curl-openssl-mt-fix.patch
+    - generic/qobjectthreadsafe-fix-qt42.patch
+  * Improved patches:
+    - generic/memory-dump-fix-double-dump.patch (make sure all thread die
+      after core dump)
+    - generic/memory-dump-tmp-path.patch (create core dumps in
+      WENGOPHONE_COREDUMP_DIR, TMPDIR, or /tmp)
+    - head/alsa-plughw-default.patch (use dmix plugin to get non-exclusive
+      access to hardware)
+  * Re-enable video support
+  * Added patch generic/phapi-fix-crash-missing-codec.patch to avoid crash if
+    video codec is not available in ffmpeg
+  * Added "Homepage:" tag in description (Developer's Reference, 6.2.4)
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Sat, 22 Sep 2007 23:58:10 +0200
+
+wengophone (2.1.1.dfsg0-4) unstable; urgency=low
+
+  * Modified changelog of prvious upload to mention CVE-2007-4366 to make
+    more easy to track security issues.
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 29 Aug 2007 12:11:55 +0200
+
+wengophone (2.1.1.dfsg0-3) unstable; urgency=low
+
+  [ Marco Nenciarini ]
+  * debian/control: Priority of wengophone-dbg changed to extra
+    to match the overrides file
+  * debian/control: Changed maintainer to Debian VoIP Team.
+  * debian/control: Added myself as uploader.
+
+  [ Kilian Krause ]
+  * Add dpkg-dev (>= 1.13.19) to Build-Depends for binary:Version
+
+  [ Ludovico Cavedon ]
+  * Added patch head/alsa-plughw-default.patch to enable selection of additional
+    sound cards. Closes: #435747
+  * Added patch generic/phapi-fix-empty-ctype-dos.patch to prevent crash on
+    messages with no Content-Type (CVE-2007-4366). Closes: #438419
+  * Moved menu item to Applications/Network/Communication to conform to new
+    Debian Policy (lintian warning menu-item-uses-apps-section)
+  * Added patch def-enable-video-fix.patch to make PHAPI_VIDEO_SUPPORT=OFF work
+  * Disabled video support for sid, as mpeg-based video codecs have been removed
+    from ffmpeg. Closes: #434389
+  * Added desktop-file-update.patch to remove deprecated "Encoding" line
+    (lintian info desktop-entry-contains-encoding-key)
+  * Modified qobjectthreadsafe-fix-qt42.patch to initialize _blockEvents
+    before calling moveToThread()
+  * Added patch curl-openssl-mt-fix.patch to fix some crashes inside cURL lib:
+    - initialize cURL before stating threads
+    - set CURLOPT_NOSIGNAL to 1, as specified in cURL doc
+    - initialize openssl with locking callbacks for multi-thread applications
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 29 Aug 2007 09:53:50 +0200
+
+wengophone (2.1.1.dfsg0-2) unstable; urgency=low
+
+  [ Marco Nenciarini ]
+  * Added Ludovico Cavedon as uploader.
+  * Added patch head/phapi-disable-iLBC-codec (stolen from upstream
+    svn commit 11646) to make iLBC codec really disabled.
+    Closes: #434389, #434402
+
+  [ Ludovico Cavedon ]
+  * Added patches:
+    + generic/memory-dump-tmp-path.patch to create core dumps in
+      WENGOPHONE_COREDUMP_DIR or /tmp
+    + generic/memory-dump-fix-double-dump.patch to avoid creation of two
+      core dumps
+  * Created wengophone-dbg package with debug symbols.
+  * Included AUTHORS file in documentation.
+  * Added patch generic/exosip-fix-empty-notify.patch from Mikael Magnusson.
+    Closes: #427930
+  * Added README.Debian to document WENGOPHONE_COREDUMP_DIR environment
+    variable
+  * Removed IAXClient copyright notice (library not included in source
+    archieve)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 25 Jul 2007 17:48:31 +0200
+
+wengophone (2.1.1.dfsg0-1) unstable; urgency=low
+
+  [ Ludovico Cavedon ]
+  * New upstream release. (Closes: #432022)
+  * Updated copyright file
+  * Updated build dependencies
+  * Removed dirs file (not needed)
+  * Using patched .desktop file from upstream
+  * Updated man page
+  * Added patch for Qt >= 4.2
+  * Disabling portaudio support
+  * Added patch for correct portaudio exclusion
+  * Removed cmake-fix-disable-crashreport.patch
+  * Added patch for fixing the behavior of ENABLE_CRASHREPORT=OFF
+  * Enabling crashreport and coredumper only on i386 and amd64
+  * Added patch for compiling coredumper statically
+  * Removing from orig tarball:
+    + libs/3rdparty/ffmpeg-bin-win32
+    + libs/3rdparty/pthread
+    + libs/3rdparty/glib
+    + libs/3rdparty/openssl
+  * No longer removing from orig tarball:
+    + scons code (already removed by upstream)
+    + libs/3rdparty/curl (needed for etch and feisty)
+  * Added backport script for etch and feisty:
+    + using internal libcurl
+    + changed dependence on Boost 1.33 instead of 1.34
+    + compiling with gcc/g++ 3.4
+  * get-orig-source.sh: added hack to install SVN server certificate
+
+  [ Marco Nenciarini ]
+  * debian/rules: made get-oprig-source working for NMUs
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 18 Jul 2007 15:35:03 +0200
+
+wengophone (2.1.0.dfsg-3) unstable; urgency=low
+
+  * Added patch cmake-fix-disable-crashreport to really disable
+    crashreport feature. (Closes: #425604)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Tue,  5 Jun 2007 14:24:40 +0200
+
+wengophone (2.1.0.dfsg-2) unstable; urgency=low
+
+  * Disabled crashreport (Closes: #425604)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Mon, 04 Jun 2007 10:58:04 +0200
+
+wengophone (2.1.0.dfsg-1) unstable; urgency=low
+
+  * New upstream stable release.
+    Closes: #396943, #396967, #397390
+  * Disabled cmake-svnrelease-from-debian-changelog patch.
+    Closes: #423517
+  * debian/get-orig-source.sh: strip uneeded library sources shipped
+    upstream
+  * debian/control: Build-depends on libboost 1.34.0 so we don't need
+    g++-3.4 anymore. Closes: #417662    
+  * debian/control: Build-depends on libiaxclient-dev
+  * Removed disable-ilbc patch (merged upstream).
+  * Refreshed patches
+    + cmake-no-rpath_to_link_path
+    + remove-extra-copying-file
+  * Added cmake-find-boost-1.34.0 patch
+
+ -- Marco Nenciarini <mnencia@debian.org>  Fri, 18 May 2007 16:53:40 +0200
+
+wengophone (2.1.0~rc2-svn10386-2) UNRELEASED; urgency=low
+
+  * Modified cmake-svnrelease-from-debian-changelog patch to use
+    perl instead of sed. Closes: #423517
+
+ -- Marco Nenciarini <mnencia@debian.org>  Fri, 18 May 2007 11:03:45 +0200
+
+wengophone (2.1.0~rc2-svn10386-1) unstable; urgency=low
+
+  * New upstream release candidate.
+    Closes: #405439, #384973, #397298, #397387, #402656, #404968,
+    #404970, #412595
+  * Forced to compile with g++-3.4 to avoid random crashes.
+    http://dev.openwengo.com/pipermail/wengophone-devel/2006-December/004731.html
+  * Added patches
+    + cmake-no-rpath_to_link_path
+    + remove-extra-copying-file
+    + cmake-force-fpic
+  * debian/control: Build-depends on g++-3.4
+  * Modified get-orig-source.sh to better handle the new source
+    structure.
+
+ -- Marco Nenciarini <mnencia@debian.org>  Tue, 03 Apr 2007 21:42:13 +0200
+
+wengophone (2.1.0~beta1-svn9983-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot. Switched to branches/wengophone-2.1
+  * Removed patches
+    + disable-crashreport
+    + cmake-fix-static-sfp-plugin
+  * debian/control: Build-depends on libcurl3-openssl-dev,
+    libsamplerate0-dev and libsndfile1-dev
+  * Modified get-orig-source.sh to match the new source tree
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 28 Feb 2007 18:35:34 +0100
+
+wengophone (2.0.0~rc5-svn8768-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot.
+  * Removed patches
+     + cmake-findxml2 (fixed upstream)
+     + cmake-fix-gaim4 (fixed upstream)
+     + cmake-fix-qtutil (fixed upstream)
+  * Merged changes from unstable package.
+
+ -- Marco Nenciarini <mnencia@debian.org>  Thu, 28 Dec 2006 18:10:08 +0100
+
+wengophone (2.0.0~rc5-svn8281-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot. Switched to branches/wengophone-2.0
+  * debian/get-orig-source.sh: Stripped wifo/phapi/speex from the
+    source tarball.
+  * debian/control
+     + added XS-Vcs-Svn field to source package
+     + Build-depends on libxml2-dev
+  * Added patches
+     + cmake-fix-gaim4
+     + cmake-findxml2 (from upstream trunk)
+     + cmake-fix-qtutil
+  * Removed patches
+     + cmake-external-speex (fixed upstream)
+     + fix-varargs-alpha (fixed upstream)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Mon,  6 Nov 2006 12:03:32 +0100
+
+wengophone (2.0.0~rc5-svn8108-3) unstable; urgency=high
+
+  * Urgency high due RC bug fix.
+  * Added cmake-fix-find-alsa-FTBFS.patch (Closes: #403056)
+  * Added Build-Conflicts against qt3-dev-tools (Closes: #398184)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Thu, 28 Dec 2006 18:11:38 +0100
+
+wengophone (2.0.0~rc5-svn8108-2) unstable; urgency=low
+
+  * Added cmake-external-speex.patch to fix compilation on alpha,
+    amd64, hppa and ia64 (Closes: #394137)
+  * debian/wengophone.desktop: Merged french translation from Ubuntu,
+    added italian translation.
+
+ -- Marco Nenciarini <mnencia@debian.org>  Fri, 20 Oct 2006 10:35:43 +0200
+
+wengophone (2.0.0~rc5-svn8108-1) unstable; urgency=low
+
+  * New upstream snapshot.
+  * debian/copyright: Added references to licenses of sorce files
+    included from other projects.
+  * Modified fix-varargs-alpha patch to make wengophone compiling on
+    alpha.
+  * Removed patches:
+     + fix-implicit-pointer-functions (merged upstream)
+     + stun-fix-non-i386 (merged upstream)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 18 Oct 2006 16:36:01 +0200
+
+wengophone (2.0.0~rc4-svn8088-1) unstable; urgency=medium
+
+  * New upstream snapshot.
+  * Removed iLBC codec from source. (Closes: #361327)
+  * This version includes many new translations:
+     + German
+     + Spanish
+     + Italian
+     + Japanese
+     + Polish
+     + Swedish (Closes: #391349)
+     + Turkish
+     + Chinese
+  * Added patches
+     + disable-ilbc
+     + fix-varargs-alpha (Closes: #393218)
+  * Removed patches (merged upstream)
+     + cmake-fix-static-phapi
+     + cmake-amrplugin-pic-code
+     + cmake-static-owcurl
+
+ -- Marco Nenciarini <mnencia@debian.org>  Tue, 17 Oct 2006 13:04:15 +0200
+
+wengophone (2.0.0~rc4-svn7960-3) unstable; urgency=low
+
+  * Updated patch stun-fix-non-i386 to fix even similar code in netlib
+    (Closes: #365557)
+  * New patch fix-implicit-pointer-functions (Closes: #392008)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Tue, 10 Oct 2006 13:14:43 +0200
+
+wengophone (2.0.0~rc4-svn7960-2) unstable; urgency=low
+
+  * New patch stun-fix-non-i386 (Closes: 391907)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Mon,  9 Oct 2006 15:44:41 +0200
+
+wengophone (2.0.0~rc4-svn7960-1) unstable; urgency=low
+
+  * New upstream snapshot.
+  * Upload wengophone-ng to unstable. (Closes: #360505, #387649)
+  * Changed description to make clear the specificity of the
+    package to the Wengo provider. (Closes: #358204)
+  * Switch to CMake build system. (Closes: #376370, #390531)
+  * Added debian/cmake.mk stolen from strigi package.
+  * Cleaned debian/rules from scons, now all work is done
+    by debian/cmake.mk
+  * Removed all scons-related patches.
+  * New patches:
+      + cmake-static-owcurl
+      + cmake-fix-static-phapi
+      + cmake-fix-static-sfp-plugin
+      + cmake-amrplugin-pic-code
+      + no-crashreport
+      + cmake-svnrelease-from-debian-changelog
+  * Modified debian/get-orig-source.sh:
+      + checkout the cmake build system instead
+        of the scons one.
+      + increased verbosity of source clean process.
+  * Checked Build-Depends:
+      +cmake
+      +libavformat-dev
+      -libdc1394-dev
+      -libglade2-dev
+      -libglib2.0-dev
+      -libraw1394-dev
+      -libxv-dev
+      -pkg-config
+      +portaudio19-dev
+      -scons
+
+ -- Marco Nenciarini <mnencia@debian.org>  Sun,  8 Oct 2006 12:17:15 +0200
+
+wengophone (2.0.0~rc3-svn7552-2) experimental; urgency=low
+
+  * Added patch to install missing libsfp-plugin.so
+
+ -- Marco Nenciarini <mnencia@debian.org>  Sun, 17 Sep 2006 21:05:15 +0200
+
+wengophone (2.0.0~rc3-svn7552-1) experimental; urgency=low
+
+  * New upstream snapshot.
+  * Refreshed almost all patch.
+  * Added missing patch 010_wengophone-phapi.patch from Andreas Schneider
+    http://dev.openwengo.com/trac/openwengo/trac.cgi/ticket/806
+
+ -- Marco Nenciarini <mnencia@debian.org>  Sun, 17 Sep 2006 17:50:49 +0200
+
+wengophone (2.0.0~rc2-svn7135-1) experimental; urgency=low
+
+  * New upstream snapshot, switched to ng branch.
+  * Uploaded to experimental. (Closes: #387649)
+  * Removed workarround to ffmpeg bug #361269. Build-depends to
+    libavcodec-dev instead of libavformat-dev.
+  * Build-depends on libraw1394-dev and libdc1934-dev as workarround to
+    ffmpeg bug #386458
+
+ -- Marco Nenciarini <mnencia@debian.org>  Sat, 16 Sep 2006 18:00:39 +0200
+
+wengophone (0.99+svn5830-1) unstable; urgency=low
+
+  * New upstream snapshot.
+  * Added 107_wengoscons-pkg-config.patch to make wengoscons able to
+    undestand the output of pkg-config.
+  * Modified patch 202_external_ffmpeg.patch to use pkg-config to
+    detect correct ffmpeg settings.
+  * Build-depends on pkg-config.
+
+ -- Marco Nenciarini <mnencia@debian.org>  Wed, 31 May 2006 22:01:03 +0200
+
+wengophone (0.99+svn5670-1) unstable; urgency=low
+
+  * New upstream snapshot.
+  * Bumped Standards Version to 3.7.2
+  * Added patch to make wengopone buildable on linux
+    106_FTBFS-GeneralConfigWidget.patch
+  * Renamed patch 105_FTBFS-random-seed.patch
+
+ -- Marco Nenciarini <mnencia@debian.org>  Thu, 25 May 2006 15:29:48 +0200
+
+wengophone (0.99+svn4511-4) unstable; urgency=low
+
+  * Really fix #358491
+
+ -- Marco Nenciarini <mnencia@debian.org>  Fri,  7 Apr 2006 19:04:23 +0200
+
+wengophone (0.99+svn4511-3) unstable; urgency=low
+
+  * Added 105_FBTS_random_seed.patch. This patch solves FTBFS on many
+    architectures. (Closes: #358491)
+  * Build-depends to libavformat-dev instead of libavcodec-dev as
+    workarround to ffmpeg bug #361269
+
+ -- Marco Nenciarini <mnencia@debian.org>  Fri,  7 Apr 2006 17:15:36 +0200
+
+wengophone (0.99+svn4511-2) unstable; urgency=low
+
+  * Added implicit-pointer-conversion patch. This patch fixes problem that
+    will cause wengophone to segfault on architectures where the size of a
+    pointer is greater than the size of an integer, such as ia64. Thanks to
+    Dann Frazier <dannf@hp.com> for the patch.  (Closes: #357519)
+  * Added gcc41 patch. This patch allow wengophone to be built with gcc-4.1
+    suite. Thanks to Martin Michlmayr <tbm@cyrius.com> for the patch.
+    (Closes: #357866)
+
+ -- Marco Nenciarini <mnencia@debian.org>  Mon, 20 Mar 2006 10:48:01 +0100
+
+wengophone (0.99+svn4511-1) unstable; urgency=low
+
+  * New upstream snapshot.
+
+ -- Marco Nenciarini <mnencia@debian.org>  Tue, 14 Mar 2006 17:51:55 +0100
+
+wengophone (0.99+svn4227-1) unstable; urgency=low
+
+  * Initial release. Closes: #351951
+
+ -- Marco Nenciarini <mnencia@debian.org>  Tue, 14 Feb 2006 07:34:58 +0100
--- wengophone-2.1.2.dfsg0.orig/debian/get-orig-source.sh
+++ wengophone-2.1.2.dfsg0/debian/get-orig-source.sh
@@ -0,0 +1,132 @@
+#!/bin/sh
+#
+
+set -e
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+    echo "Missing parameter"
+    echo "Usage: $0 version repository [revision]"
+    echo
+    exit 1;
+fi
+
+version=$1
+svn_url=$2
+
+# ugly hack to install dev.openwengo.com certificate 
+if ! svn --password guest --username guest --non-interactive info https://dev.openwengo.com/svn/openwengo > /dev/null; then
+   echo "p" | svn --password guest --username guest info https://dev.openwengo.com/svn/openwengo > /dev/null
+fi
+
+if [ -n "$3" ]; then
+    svn_rev="$3"
+else
+    # Retrive latest svn verion numbers
+    svn_rev=$(LANG=C svn --password guest --username guest --non-interactive info $svn_url | \
+              awk '/Last Changed Rev:/ {print $4}')
+fi
+
+curdir="$PWD"
+destdir=wengophone-$version
+desttar=wengophone_$version.orig.tar
+
+if [ -d "$curdir/../tarballs" ]; then
+    finaldir=$curdir/../tarballs
+else
+    finaldir=$(dirname $curdir)
+fi
+
+if [ -e "$finaldir/$desttar.gz" ]; then
+    echo "Uptodate archive found ($finaldir/$desttar.gz), nothing to do."
+    exit 0
+fi
+
+workdir="$(mktemp -d)"
+trap "rm -fr $workdir; echo Aborted." EXIT
+
+cd $workdir
+
+# Download sources from svn
+if [ -d $destdir ]; then
+    echo "Uptodate source found ($destdir), skipping download."
+else
+    echo -n "Downloading sources... "
+    svn export -q -r $svn_rev --password guest --username guest --non-interactive $svn_url $destdir
+    echo "done."
+fi
+
+# Cleaning tree
+purge_3rdparty() {
+    purgedir="$1"
+    if [ -z "$purgedir" ] || [ ! -d "$purgedir" ]; then
+        return 1
+    fi
+    find $purgedir -depth -type f -not -iname cmake\* -print0 | xargs -0 rm -vf
+    find $purgedir -depth -type d -not -iname cmake\* -print0 | xargs -0 rmdir --ignore-fail-on-non-empty
+}
+
+echo "Cleaning tree to remove anything not needed for non-Windows builds..."
+
+# Remove windows binary stuff
+rm -vrf $destdir/wengophone/together
+rm -vrf $destdir/wengophone/nsis
+rm -vrf $destdir/libs/3rdparty/*/binary-lib
+find $destdir -iname \*.dll -print0 | xargs -0 rm -vf
+find $destdir -iname \*.lib -print0 | xargs -0 rm -vf
+
+# Remove deprecated scons code
+# already removed since upstream release 2.1.1
+#rm -vrf $destdir/wengoscons
+#find $destdir -depth \( -iname scons\* -o -iname soptions \) -print0 | xargs -0 rm -vrf
+
+# Remove outdated autotools files
+find $destdir \( -iname config.guess -o -iname config.sub \) -print0 | xargs -0 rm -vf
+
+# Remove iLBC codec
+rm -rfv $destdir/wifo/phapi/ilbc
+
+# Remove portaudio code
+purge_3rdparty $destdir/libs/3rdparty/portaudio 
+
+# Remove ffmpeg code
+purge_3rdparty $destdir/libs/3rdparty/ffmpeg 
+rm -r $destdir/libs/3rdparty/ffmpeg-bin-win32
+
+# Remove speex code
+purge_3rdparty $destdir/wifo/phapi/speex
+
+# Remove samplerate code
+purge_3rdparty $destdir/libs/3rdparty/samplerate
+
+# Remove curl code
+# libray needed for Debian etch and Ubuntu feisty
+#purge_3rdparty $destdir/libs/3rdparty/curl
+
+# Remove iaxclient code
+purge_3rdparty $destdir/libs/3rdparty/iaxclient
+
+# Remove pthread code
+purge_3rdparty $destdir/libs/3rdparty/pthread
+
+# Remove glib code
+purge_3rdparty $destdir/libs/3rdparty/glib
+
+# Remove openssl code
+purge_3rdparty $destdir/libs/3rdparty/openssl
+
+echo "Cleaning done"
+
+# Make the sources archive
+echo -n "Writing archive... "
+tar cf $desttar $destdir
+gzip --best $desttar
+echo "done"
+
+mv -f $desttar.gz "$finaldir"
+echo "Archive is in $finaldir/$desttar.gz"
+
+rm -fr "$workdir"
+
+trap "" EXIT
+
+exit 0
--- wengophone-2.1.2.dfsg0.orig/debian/README.Debian
+++ wengophone-2.1.2.dfsg0/debian/README.Debian
@@ -0,0 +1,65 @@
+WengoPhone for Debian
+=====================
+
+Core dumps
+----------
+
+If WengoPhone crashes a core dump is created. Differently from upstream version,
+the position where the core dump is created can be controlled with the
+WENGOPHONE_COREDUMP_DIR environment variable. If such variable is not set, the
+dump is created in /tmp.
+
+Video support
+-------------
+
+According to ffmpeg-free changelog [1], MPEG-based video encoders have been
+removed since version 0.cvs20070307-6, because of patent problems:
+>   * Rename the source package. We are (again) no longer shipping the
+>     'real' upstream source of ffmpeg.
+>   * Add debian/strip.sh to strip ffmpeg upstream source disabling mpeg
+>     based encoders as discussed with ftp-master at debconf7
+
+Wengophone video support depends on those codecs, therefore it is no longer
+working with this new ffmpeg package.
+
+Video support can be enabled without recompiling wengophone, by just installing a
+non-stripped version of ffmpeg.
+
+Waiting for proper documentation from ffmpeg maintaners [2], here is a quick
+howto in order to self-recompile ffmpeg enabling MPEG-based encoders.
+
+WARNING: Those encoders are covered by patents which are actively enforced in
+some countries. USE AT YOUR OWN RISK.
+
+1. Create the orig tarball:
+	$ svn export --ignore-externals -r {20070307} svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg-0.svn20070307
+	$ svn export --ignore-externals -r {20070307} svn://svn.mplayerhq.hu/mplayer/trunk/libswscale ffmpeg-0.svn20070307/libswscale
+	$ tar cvzf ffmpeg_0.svn20070307.orig.tar.gz ffmpeg-0.svn20070307
+
+2. Apply the debian patch [3], in order to add the debian
+   control files:
+	$ wget http://ftp.debian.org/debian/pool/main/f/ffmpeg-free/ffmpeg-free_0.cvs20070307-6.diff.gz
+	$ cd ffmpeg-0.svn20070307
+	$ zcat ../ffmpeg-free_0.cvs20070307-6.diff.gz | patch -p1
+
+3. Replace "ffmpeg-free" with "ffmpeg" in debian/control an debian/changelog
+   files (the right way would be adding a new custom changelog entry in the
+   change):
+	$ sed -i -e "s/ffmpeg-free/ffmpeg/g" debian/control debian/changelog
+
+4. Build it:
+	$ sudo apt-get build-dep ffmpeg-free
+	$ chmod +x debian/rules
+	$ dpkg-buildpackage -rfakeroot
+
+5. Install the packages:
+	$ cd ..
+	$ sudo dpkg -i lib*d_0.cvs20070307-*.deb	# Just runtime libs
+   or
+	$ sudo dpkg -i lib_0.cvs20070307-*.deb		# everything
+
+[1] http://packages.debian.org/changelogs/pool/main/f/ffmpeg-free/current/changelog
+[2] http://bugs.debian.org/440702
+[3] http://ftp.debian.org/debian/pool/main/f/ffmpeg-free/ffmpeg-free_0.cvs20070307-6.diff.gz
+
+ -- Ludovico Cavedon <cavedon@sssup.it>  Thu, 01 Nov 2007 17:23:09 +0100
--- wengophone-2.1.2.dfsg0.orig/debian/cmake.mk
+++ wengophone-2.1.2.dfsg0/debian/cmake.mk
@@ -0,0 +1,76 @@
+# -*- mode: makefile; coding: utf-8 -*-
+# Copyright (C) 2006 Peter Rockai <me@mornfall.net>
+# Copyright (C) 2006 Fathi Boudra <fboudra@free.fr>
+# Description: A class for cmake packages
+#
+# 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, 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., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+ifndef _cdbs_bootstrap
+_cdbs_scripts_path ?= /usr/lib/cdbs
+_cdbs_rules_path ?= /usr/share/cdbs/1/rules
+_cdbs_class_path ?= /usr/share/cdbs/1/class
+endif
+
+ifndef _cdbs_class_cmake
+_cdbs_class_cmake := 1
+
+include $(_cdbs_rules_path)/buildcore.mk$(_cdbs_makefile_suffix)
+
+ifdef _cdbs_tarball_dir
+DEB_BUILDDIR = $(_cdbs_tarball_dir)/obj-$(DEB_BUILD_GNU_TYPE)
+else
+DEB_BUILDDIR = obj-$(DEB_BUILD_GNU_TYPE)
+endif
+
+DEB_MAKE_INSTALL_TARGET = install DESTDIR=$(DEB_DESTDIR)
+DEB_CMAKE_PREFIX =/usr
+
+# Overriden from makefile-vars.mk
+# We pass CFLAGS and friends to ./configure, so no need to pass them to make
+DEB_MAKE_INVOKE = $(DEB_MAKE_ENVVARS) $(MAKE) -C $(DEB_BUILDDIR)
+
+include $(_cdbs_class_path)/makefile.mk$(_cdbs_makefile_suffix)
+
+ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+# well, -O0
+endif
+
+ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+# semi-debug
+else
+# final
+endif
+
+ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
+# debug
+endif
+
+#DEB_COMPRESS_EXCLUDE = .dcl .docbook -license .tag .sty .el
+
+common-configure-arch common-configure-indep:: common-configure-impl
+common-configure-impl:: $(DEB_BUILDDIR)/CMakeCache.txt
+$(DEB_BUILDDIR)/CMakeCache.txt:
+	cd $(DEB_BUILDDIR) && cmake $(CURDIR)/$(DEB_SRCDIR) \
+	-DCMAKE_INSTALL_PREFIX="$(DEB_CMAKE_PREFIX)" \
+	$(DEB_CMAKE_EXTRA_FLAGS) -DCMAKE_CXX_FLAGS="$(CXXFLAGS)" \
+	-DCMAKE_C_FLAGS="$(CFLAGS)" -DCMAKE_VERBOSE_MAKEFILE=ON
+	mkdir -p $(DEB_DESTDIR)
+
+cleanbuilddir::
+	-if test "$(DEB_BUILDDIR)" != "$(DEB_SRCDIR)"; then rm -rf $(DEB_BUILDDIR); fi
+
+endif
+
--- wengophone-2.1.2.dfsg0.orig/debian/qtwengophone.1
+++ wengophone-2.1.2.dfsg0/debian/qtwengophone.1
@@ -0,0 +1,45 @@
+.TH "qtwengophone" "1" "16 July 2007" "Wengophone" "User Commands"
+.SH "NAME"
+wengophone \- SIP-based software telephone with video and chat features
+internet phone.
+.SH "SYNOPSIS"
+.B qtwengophone
+.RI [ options ]
+.SH "DESCRIPTION"
+WengoPhone is a Voice over IP application based on standard protocols like
+SIP and RTP. It enables voice, video and text chat between two clients.
+Features include a contact list with presence and status, call history and
+NAT traversal capability.
+
+In conjunction with other services, WengoPhone can be used to call regular
+PSTN lines and/or send SMS messages to cell phones.
+.SH "OPTIONS"
+.TP
+.B -h, --help
+Print usage message.
+.TP
+.B -b, --background
+Run in background mode.
+.TP
+.B -s, --several
+Allow several WengoPhone at the same time.
+.TP
+.B -q, --configpath \fIarg\fP
+Pass a path to load configuration directory.
+.TP
+.B -c, --command \fIarg\fP
+Pass a command to the wengophone.
+.SH "FILES"
+.TP
+.I ~/.wengophone/
+This is where wengophone reads its config information. You do not have to
+modify or edit this file.
+.SH "SEE ALSO"
+http://www.openwengo.org/
+.SH "AUTHORS"
+Wengo Development Team <wengophone-devel@lists.openwengo.com>
+.PP
+This manual page was written by Marco Nenciarini <mnencia@debian.org> for
+the Debian project (but may be used by others).  
+.PP
+This manual page was updated by Ludovico Cavedon <cavedon@sssup.it>.
--- wengophone-2.1.2.dfsg0.orig/debian/wengophone.xpm
+++ wengophone-2.1.2.dfsg0/debian/wengophone.xpm
@@ -0,0 +1,489 @@
+/* XPM */
+static char * wengophone_xpm[] = {
+"32 32 454 2",
+"  	c None",
+". 	c #7797B0",
+"+ 	c #83A1B8",
+"@ 	c #7294AD",
+"# 	c #84A2B8",
+"$ 	c #7D9CB4",
+"% 	c #809FB6",
+"& 	c #82A0B7",
+"* 	c #86A4BA",
+"= 	c #7C9CB3",
+"- 	c #88A5BB",
+"; 	c #85A4B9",
+"> 	c #7798B1",
+", 	c #83A2B8",
+"' 	c #809FB5",
+") 	c #89A6BB",
+"! 	c #8DAABE",
+"~ 	c #7A9AB2",
+"{ 	c #8CA9BE",
+"] 	c #7496AE",
+"^ 	c #93AEC2",
+"/ 	c #96B1C4",
+"( 	c #8EAABF",
+"_ 	c #88A6BB",
+": 	c #87A5BB",
+"< 	c #9CB5C8",
+"[ 	c #9BB4C7",
+"} 	c #9AB4C6",
+"| 	c #9AB3C6",
+"1 	c #99B2C5",
+"2 	c #8FABC0",
+"3 	c #84A3B9",
+"4 	c #7E9DB5",
+"5 	c #8EAABE",
+"6 	c #95AFC3",
+"7 	c #96B0C4",
+"8 	c #99B3C6",
+"9 	c #9AB4C7",
+"0 	c #97B2C6",
+"a 	c #93AFC3",
+"b 	c #91ADC1",
+"c 	c #90AABF",
+"d 	c #7D9CB3",
+"e 	c #7F9EB5",
+"f 	c #87A4BA",
+"g 	c #88A6BA",
+"h 	c #90ADC1",
+"i 	c #9FB9CB",
+"j 	c #ABC3D3",
+"k 	c #B0C6D6",
+"l 	c #AEC4D5",
+"m 	c #A4BDD1",
+"n 	c #93B2C7",
+"o 	c #84A3BC",
+"p 	c #7D9DB5",
+"q 	c #7F9FB5",
+"r 	c #799AB2",
+"s 	c #6C8FA9",
+"t 	c #7797AF",
+"u 	c #7B9BB3",
+"v 	c #83A1B9",
+"w 	c #ACC2D2",
+"x 	c #D4E1EA",
+"y 	c #E9F0F5",
+"z 	c #F1F6F8",
+"A 	c #F4F7FA",
+"B 	c #F1F5F8",
+"C 	c #E9F0F4",
+"D 	c #D1DFE9",
+"E 	c #A5BED0",
+"F 	c #789CB5",
+"G 	c #7092AC",
+"H 	c #7293AC",
+"I 	c #6387A3",
+"J 	c #6D90A9",
+"K 	c #7092AB",
+"L 	c #84A2B9",
+"M 	c #CBD9E4",
+"N 	c #F0F5F8",
+"O 	c #EBF2F6",
+"P 	c #E8EFF4",
+"Q 	c #E6EDF2",
+"R 	c #E5ECF2",
+"S 	c #E6EDF3",
+"T 	c #E9EFF4",
+"U 	c #EBF0F5",
+"V 	c #CDDBE6",
+"W 	c #81A2BB",
+"X 	c #6489A5",
+"Y 	c #678BA5",
+"Z 	c #59809D",
+"` 	c #6085A1",
+" .	c #668BA5",
+"..	c #7698B0",
+"+.	c #CDDCE6",
+"@.	c #ECF2F6",
+"#.	c #E0E9F0",
+"$.	c #DAE4EC",
+"%.	c #D7E2EB",
+"&.	c #D2DFE9",
+"*.	c #D1DEE8",
+"=.	c #D0DEE8",
+"-.	c #D8E3EB",
+";.	c #CDDCE7",
+">.	c #7599B4",
+",.	c #5C829F",
+"'.	c #5C839E",
+").	c #5E84A0",
+"!.	c #6187A2",
+"~.	c #ADC4D4",
+"{.	c #E0EAF0",
+"].	c #CBDAE6",
+"^.	c #C5D6E2",
+"/.	c #C0D2DF",
+"(.	c #BED1DF",
+"_.	c #BFD1DF",
+":.	c #BDD0DE",
+"<.	c #BCCFDD",
+"[.	c #B8CDDB",
+"}.	c #B6CBDB",
+"|.	c #BACFDC",
+"1.	c #BACEDC",
+"2.	c #A7C0D3",
+"3.	c #557F9F",
+"4.	c #587E9C",
+"5.	c #4F7896",
+"6.	c #527A98",
+"7.	c #577E9B",
+"8.	c #7598B1",
+"9.	c #C5D7E4",
+"0.	c #C7D8E3",
+"a.	c #BDD0DD",
+"b.	c #B0C7D8",
+"c.	c #B9CDDC",
+"d.	c #B4CADA",
+"e.	c #AAC3D5",
+"f.	c #ABC2D4",
+"g.	c #ADC4D5",
+"h.	c #B1C7D7",
+"i.	c #A2BCD0",
+"j.	c #A3BDD0",
+"k.	c #A1BCCF",
+"l.	c #A3BED0",
+"m.	c #5E88A7",
+"n.	c #4A7594",
+"o.	c #4E7796",
+"p.	c #497392",
+"q.	c #4F7897",
+"r.	c #547C9A",
+"s.	c #84A5BF",
+"t.	c #B7CCDC",
+"u.	c #AFC6D6",
+"v.	c #A6C0D4",
+"w.	c #9CB9CE",
+"x.	c #BBCFDE",
+"y.	c #FFFEFF",
+"z.	c #A0BCD0",
+"A.	c #92B1C8",
+"B.	c #9DB9CD",
+"C.	c #EFF3F7",
+"D.	c #FFFFFF",
+"E.	c #B1C8D7",
+"F.	c #86A9C2",
+"G.	c #89ABC3",
+"H.	c #8AABC2",
+"I.	c #5B85A3",
+"J.	c #37668A",
+"K.	c #4C7594",
+"L.	c #436E8F",
+"M.	c #3E6B8C",
+"N.	c #467090",
+"O.	c #497393",
+"P.	c #567F9E",
+"Q.	c #7DA3BF",
+"R.	c #9EBBCF",
+"S.	c #98B6CC",
+"T.	c #90B1C9",
+"U.	c #86A9C3",
+"V.	c #B5CCDB",
+"W.	c #F8FAFB",
+"X.	c #92B1C9",
+"Y.	c #7BA1BD",
+"Z.	c #8EAEC6",
+"`.	c #F6F9FB",
+" +	c #ABC3D5",
+".+	c #6D97B5",
+"++	c #719AB7",
+"@+	c #7298B4",
+"#+	c #497495",
+"$+	c #28587D",
+"%+	c #477191",
+"&+	c #406B8C",
+"*+	c #3B6788",
+"=+	c #305F83",
+"-+	c #396688",
+";+	c #3B6789",
+">+	c #416C8D",
+",+	c #446E8E",
+"'+	c #5781A0",
+")+	c #6E99B7",
+"!+	c #81A6C0",
+"~+	c #83A7C1",
+"{+	c #7CA2BE",
+"]+	c #7AA1BC",
+"^+	c #7BA1BE",
+"/+	c #A6C0D2",
+"(+	c #97B5CC",
+"_+	c #7099B7",
+":+	c #6A95B4",
+"<+	c #8DADC6",
+"[+	c #9CB8CD",
+"}+	c #6692B1",
+"|+	c #5E8CAD",
+"1+	c #5C89AB",
+"2+	c #5884A5",
+"3+	c #2E5F83",
+"4+	c #1F4E72",
+"5+	c #406B8B",
+"6+	c #3C6889",
+"7+	c #366485",
+"8+	c #326083",
+"9+	c #326183",
+"0+	c #376486",
+"a+	c #3D6889",
+"b+	c #3F6A8B",
+"c+	c #517E9F",
+"d+	c #6390B1",
+"e+	c #6691B2",
+"f+	c #6E98B7",
+"g+	c #6995B5",
+"h+	c #6994B4",
+"i+	c #6793B3",
+"j+	c #5F8EAF",
+"k+	c #5E8DAF",
+"l+	c #628FB0",
+"m+	c #5F8DAF",
+"n+	c #5B8AAD",
+"o+	c #5183A7",
+"p+	c #4B7EA4",
+"q+	c #4F81A6",
+"r+	c #4D80A5",
+"s+	c #4A7DA2",
+"t+	c #3B6E93",
+"u+	c #1F5077",
+"v+	c #1B486B",
+"w+	c #386586",
+"x+	c #386587",
+"y+	c #326084",
+"z+	c #2D5D80",
+"A+	c #305E82",
+"B+	c #376587",
+"C+	c #487799",
+"D+	c #5688AC",
+"E+	c #5687AA",
+"F+	c #5787AB",
+"G+	c #5989AC",
+"H+	c #5889AC",
+"I+	c #5486AA",
+"J+	c #5284A8",
+"K+	c #4E81A7",
+"L+	c #4B7FA5",
+"M+	c #487DA3",
+"N+	c #4479A1",
+"O+	c #40769F",
+"P+	c #3C739C",
+"Q+	c #306993",
+"R+	c #265C84",
+"S+	c #1C4B70",
+"T+	c #194365",
+"U+	c #356183",
+"V+	c #346385",
+"W+	c #2E5D80",
+"X+	c #336284",
+"Y+	c #366385",
+"Z+	c #3D6D91",
+"`+	c #487DA4",
+" @	c #4C81A6",
+".@	c #4C80A6",
+"+@	c #4C7FA5",
+"@@	c #4A7FA5",
+"#@	c #497DA4",
+"$@	c #467CA2",
+"%@	c #4379A1",
+"&@	c #3F779E",
+"*@	c #3D749D",
+"=@	c #39729B",
+"-@	c #316C97",
+";@	c #286592",
+">@	c #4D7DA0",
+",@	c #255980",
+"'@	c #184467",
+")@	c #194161",
+"!@	c #2F5E82",
+"~@	c #366487",
+"{@	c #3E7298",
+"]@	c #43779D",
+"^@	c #467BA1",
+"/@	c #477DA4",
+"(@	c #477CA3",
+"_@	c #457AA2",
+":@	c #4379A0",
+"<@	c #40779F",
+"[@	c #3D759D",
+"}@	c #39719B",
+"|@	c #2B6794",
+"1@	c #2C6994",
+"2@	c #9BB8CC",
+"3@	c #14476F",
+"4@	c #133A5B",
+"5@	c #1D4464",
+"6@	c #305F84",
+"7@	c #2A5A7E",
+"8@	c #2D5C80",
+"9@	c #356589",
+"0@	c #3A6B91",
+"a@	c #3F7298",
+"b@	c #3A729B",
+"c@	c #3E769E",
+"d@	c #3F769E",
+"e@	c #3C749C",
+"f@	c #356F99",
+"g@	c #2C6895",
+"h@	c #2B6894",
+"i@	c #5C8AAC",
+"j@	c #CADAE5",
+"k@	c #F9FBFC",
+"l@	c #416E90",
+"m@	c #103E62",
+"n@	c #113250",
+"o@	c #244F71",
+"p@	c #2B5C81",
+"q@	c #26577C",
+"r@	c #29597D",
+"s@	c #2C5B7F",
+"t@	c #34658A",
+"u@	c #386C92",
+"v@	c #80A3BD",
+"w@	c #6E98B6",
+"x@	c #42789F",
+"y@	c #3B749C",
+"z@	c #4B7FA4",
+"A@	c #739CB9",
+"B@	c #BBCEDD",
+"C@	c #FAFBFC",
+"D@	c #8CA7BC",
+"E@	c #0D3E65",
+"F@	c #123553",
+"G@	c #143755",
+"H@	c #29597E",
+"I@	c #25577C",
+"J@	c #28587C",
+"K@	c #285579",
+"L@	c #295577",
+"M@	c #27587E",
+"N@	c #547E9E",
+"O@	c #DBE4EB",
+"P@	c #F0F5F9",
+"Q@	c #D9E5ED",
+"R@	c #DCE6EE",
+"S@	c #ADBFCD",
+"T@	c #19476B",
+"U@	c #103554",
+"V@	c #0E2D4A",
+"W@	c #214D70",
+"X@	c #26587D",
+"Y@	c #25577E",
+"Z@	c #225179",
+"`@	c #25587D",
+" #	c #26567B",
+".#	c #224C6D",
+"+#	c #224A6B",
+"@#	c #1C4A6F",
+"##	c #AFC1CF",
+"$#	c #F8F9FB",
+"%#	c #E8EDF1",
+"&#	c #869EB2",
+"*#	c #164164",
+"=#	c #0D314F",
+"-#	c #0D2B46",
+";#	c #1B4465",
+">#	c #25577D",
+",#	c #23567E",
+"'#	c #215378",
+")#	c #24567D",
+"!#	c #235479",
+"~#	c #1D4667",
+"{#	c #1A3E5C",
+"]#	c #163E5F",
+"^#	c #154064",
+"/#	c #375D7C",
+"(#	c #5D7C95",
+"_#	c #658299",
+":#	c #55748D",
+"<#	c #274D6B",
+"[#	c #072D4F",
+"}#	c #0B2B48",
+"|#	c #0F2E4A",
+"1#	c #1B4567",
+"2#	c #23557C",
+"3#	c #22557D",
+"4#	c #1E4E72",
+"5#	c #22567E",
+"6#	c #22547A",
+"7#	c #1D496B",
+"8#	c #163A58",
+"9#	c #133350",
+"0#	c #0D2E4B",
+"a#	c #062949",
+"b#	c #042647",
+"c#	c #042544",
+"d#	c #0A2944",
+"e#	c #0E2E48",
+"f#	c #143958",
+"g#	c #1E4D71",
+"h#	c #22567D",
+"i#	c #21557D",
+"j#	c #163F5E",
+"k#	c #071621",
+"l#	c #173D59",
+"m#	c #20547C",
+"n#	c #21567E",
+"o#	c #1F5178",
+"p#	c #1C496D",
+"q#	c #184061",
+"r#	c #163B5A",
+"s#	c #153958",
+"t#	c #153C5C",
+"u#	c #1E4D72",
+"v#	c #21557C",
+"w#	c #21577F",
+"x#	c #112F46",
+"y#	c #000405",
+"z#	c #010406",
+"A#	c #0C2130",
+"B#	c #194160",
+"C#	c #1F5177",
+"D#	c #20547D",
+"E#	c #20557C",
+"F#	c #20547B",
+"G#	c #1D4C6F",
+"H#	c #14354E",
+"I#	c #07151E",
+"J#	c #000406",
+"K#	c #02070B",
+"L#	c #0A1D2B",
+"M#	c #153852",
+"N#	c #1B4769",
+"O#	c #1C496C",
+"P#	c #1C496B",
+"Q#	c #1C4A6C",
+"R#	c #194261",
+"S#	c #102D43",
+"T#	c #06131C",
+"U#	c #01070B",
+"                          . + +                                 ",
+"                        @ # $ % &                               ",
+"                        * = -   ; >                             ",
+"                        , ' )   ! ~                             ",
+"                        { ] ^ / (                               ",
+"                        - _                                     ",
+"                        : < [ } | 1 2 3                         ",
+"                    4 5 6 7 8 9 0 a b c ) d                     ",
+"                  e f g h i j k l m n o p q r s                 ",
+"                t u v w x y z A A B C D E F G H I               ",
+"              J K L M N N O P Q R R S T U V W X Y Z             ",
+"            `  ...+.@.#.$.%.x &.*.=.=.=.*.-.;.>.,.'.            ",
+"            ).!.~.{.D ].^./.(._.:.<.[.}.|.1./.2.3.4.5.          ",
+"          6.7.8.9.0.a.}.b.c.d.e.f.2.g.h.i.j.k.l.m.n.o.          ",
+"        p.q.r.s.t.u.v.w.x.y.B z.A.B.C.D.E.F.G.H.I.J.K.L.        ",
+"      M.N.O.P.Q.R.S.T.U.V.D.W.X.Y.Z.`.D. +.+++@+#+$+%+&+*+=+    ",
+"    -+;+>+,+'+)+!+~+{+]+^+/+(+++_+:+<+[+}+|+1+2+3+4+5+6+7+8+    ",
+"    9+0+a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+    ",
+"      A+B+*+C+D+E+F+G+G+H+F+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+      ",
+"        X+Y+Z+`+ @.@+@.@.@@@#@$@%@&@*@=@-@;@>@,@'@)@y+!@        ",
+"          8+~@{@]@^@$@/@M+(@_@:@<@[@}@|@1@2@/ 3@4@5@6@7@        ",
+"          8@!@9@0@a@]@*@b@c@d@e@f@g@h@i@j@k@l@m@n@o@p@q@        ",
+"          r@s@8@A+t@u@v@w@x@y@e@z@A@B@C@D.D@E@F@G@H@I@          ",
+"            J@H@K@L@M@N@O@P@Q@R@B D.D.D.S@T@U@V@W@X@Y@          ",
+"            Z@`@ #.#+#@#;+##$#D.D.D.%#&#*#=#-#;#>#,#            ",
+"              '#)#!#~#{#]#^#/#(#_#:#<#[#}#|#1#2#3#              ",
+"                4#5#6#7#8#9#0#a#b#c#d#e#f#g#h#i#j#              ",
+"                k#l#m#n#o#p#q#r#s#t#T+u#v#w#4#x#                ",
+"                y#z#A#B#C#m#D#E#v#v#i#F#G#H#I#                  ",
+"                    J#K#L#M#N#O#P#Q#R#S#T#U#                    ",
+"                                                                ",
+"                                                                "};
--- wengophone-2.1.2.dfsg0.orig/debian/wengophone.install
+++ wengophone-2.1.2.dfsg0/debian/wengophone.install
@@ -0,0 +1 @@
+debian/wengophone.xpm usr/share/pixmaps
--- wengophone-2.1.2.dfsg0.orig/debian/wengophone.manpages
+++ wengophone-2.1.2.dfsg0/debian/wengophone.manpages
@@ -0,0 +1 @@
+debian/qtwengophone.1
--- wengophone-2.1.2.dfsg0.orig/debian/control
+++ wengophone-2.1.2.dfsg0/debian/control
@@ -0,0 +1,50 @@
+Source: wengophone
+Section: net
+Priority: optional
+Maintainer: Debian VoIP Team <pkg-voip-maintainers@lists.alioth.debian.org>
+Uploaders: Marco Nenciarini <mnencia@debian.org>, Ludovico Cavedon <cavedon@sssup.it>
+Build-Depends: cdbs (>= 0.4.27), bzip2, debhelper (>= 4.1.0), quilt,
+ patchutils (>= 0.2.25), cmake (>= 2.4.4), libqt4-dev (>= 4.1.4),
+ libglib2.0-dev (>= 2.10.3), libavcodec-dev (>= 0.cvs20060823-3.1),
+ libswscale-dev (>= 0.cvs20060823-3.1), libgnutls-dev (>= 1.2.9),
+ libboost-serialization-dev (>= 1.34.0), libboost-thread-dev (>= 1.34.0),
+ libboost-regex-dev (>= 1.34.0), libboost-signals-dev (>= 1.34.0),
+ libboost-program-options-dev (>= 1.34.0), uuid-dev,
+ libasound2-dev (>= 1.0.11), libspeex-dev (>= 1.1.12), libssl-dev (>= 0.9.8a),
+ libxml2-dev (>= 2.6.24), libsamplerate0-dev (>= 0.1.2),
+ libsndfile1-dev (>= 1.0.12), libcurl4-openssl-dev (>= 7.16.1),
+ dpkg-dev (>= 1.13.19), libx11-dev, python-dev
+Build-Conflicts: qt3-dev-tools
+Standards-Version: 3.7.3
+Homepage: http://www.openwengo.org/
+Vcs-Svn: svn://svn.debian.org/pkg-voip/wengophone/trunk/
+Vcs-Browser: http://svn.debian.org/wsvn/pkg-voip/wengophone/?op=log
+
+Package: wengophone
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: SIP-based software telephone with video and chat features
+ WengoPhone is a Voice-over-IP application based on standard protocols like SIP
+ and RTP. It enables voice, video and text chat between two clients. Features
+ include a contact list with multi-protocol presence and status, call history
+ and NAT traversal capability.
+ .
+ In conjunction with commercial services provided from Wengo
+ (http://www.wengo.fr), WengoPhone can be used to call regular PSTN lines
+ and/or send SMS messages to cell phones.
+
+Package: wengophone-dbg
+Architecture: any
+Priority: extra
+Depends: wengophone (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
+Description: SIP-based software telephone with video and chat features
+ WengoPhone is a Voice-over-IP application based on standard protocols like SIP
+ and RTP. It enables voice, video and text chat between two clients. Features
+ include a contact list with multi-protocol presence and status, call history
+ and NAT traversal capability.
+ .
+ In conjunction with commercial services provided from Wengo
+ (http://www.wengo.fr), WengoPhone can be used to call regular PSTN lines
+ and/or send SMS messages to cell phones.
+ .
+ This package contains debug symbols, useful to debug wengophone.
--- wengophone-2.1.2.dfsg0.orig/debian/backports/feisty
+++ wengophone-2.1.2.dfsg0/debian/backports/feisty
@@ -0,0 +1,12 @@
+#!/bin/bash
+#
+# Hook for automatic backports at buildserver.net
+#
+# Target dist: Ubuntu Feisty
+
+sed -i -e 's#\(libboost-[-a-z]*-dev *( *>= *\)1.34[^)]*)#\11.33)#g' debian/control
+sed -i -e 's#libcurl4-openssl-dev[^)]*)#g++-3.4#g' debian/control
+sed -i -e 's#-DCURL_INTERNAL=OFF#-DCURL_INTERNAL=ON#' debian/rules
+sed -i -e 's#-DPHAPI_VIDEO_SUPPORT=ON#-DPHAPI_VIDEO_SUPPORT=ON \\\n\t-DCMAKE_C_COMPILER=$(shell which gcc-3.4) \\\n\t-DCMAKE_CXX_COMPILER=$(shell which g++-3.4)#' debian/rules
+
+exit 0
--- wengophone-2.1.2.dfsg0.orig/debian/backports/etch
+++ wengophone-2.1.2.dfsg0/debian/backports/etch
@@ -0,0 +1,12 @@
+#!/bin/bash
+#
+# Hook for automatic backports at buildserver.net
+#
+# Target dist: Debian Etch
+
+sed -i -e 's#\(libboost-[-a-z]*-dev *( *>= *\)1.34[^)]*)#\11.33)#g' debian/control
+sed -i -e 's#libcurl4-openssl-dev[^)]*)#g++-3.4#g' debian/control
+sed -i -e 's#-DCURL_INTERNAL=OFF#-DCURL_INTERNAL=ON#' debian/rules
+sed -i -e 's#-DPHAPI_VIDEO_SUPPORT=ON#-DPHAPI_VIDEO_SUPPORT=ON \\\n\t-DCMAKE_C_COMPILER=$(shell which gcc-3.4) \\\n\t-DCMAKE_CXX_COMPILER=$(shell which g++-3.4)#' debian/rules
+
+exit 0
--- wengophone-2.1.2.dfsg0.orig/debian/patches/series
+++ wengophone-2.1.2.dfsg0/debian/patches/series
@@ -0,0 +1,21 @@
+head/alsa-plughw-default.patch
+head/qt-fix-bad-window-size.patch
+head/phapi-alsa-code-from-2.2.patch
+head/img_resample.patch
+head/ffmpeg-swscale-api.patch
+head/cmake-swscale.patch -p0
+generic/qobjectthreadsafe-fix-qt42.patch
+generic/cmake-fix-ENABLE_CRASHREPORT.patch
+generic/cmake-static-coredumper.patch
+generic/memory-dump-fix-double-dump.patch
+generic/memory-dump-tmp-path.patch
+generic/desktop-file-update.patch
+generic/def-enable-video-fix.patch
+generic/phapi-fix-crash-missing-codec.patch
+generic/curl-openssl-mt-fix.patch
+generic/gcc-4_3.patch
+debian/remove-extra-copying-file.patch
+debian/cmake-no-rpath_to_link_path.patch
+debian/cmake-rpath-shlibs.patch
+debian/cmake-force-fpic.patch
+debian/cmake-find-boost-1.34.0.patch
--- wengophone-2.1.2.dfsg0.orig/debian/patches/README
+++ wengophone-2.1.2.dfsg0/debian/patches/README
@@ -0,0 +1,3 @@
+generic: Possibly relevant for upstream adoption.
+head: Grabbed from upstream development.
+debian: Only relevant for official Debian release.
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/qobjectthreadsafe-fix-qt42.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/qobjectthreadsafe-fix-qt42.patch
@@ -0,0 +1,21 @@
+Index: wengophone-2.1.2.dfsg0/libs/qtutil/src/QObjectThreadSafe.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/qtutil/src/QObjectThreadSafe.cpp	2007-07-04 07:52:16.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/qtutil/src/QObjectThreadSafe.cpp	2007-09-07 21:32:18.000000000 +0000
+@@ -23,7 +23,7 @@
+ #include <QtCore/QThread>
+ 
+ QObjectThreadSafe::QObjectThreadSafe(QObject * parent)
+-	: QObject(parent) {
++	: QObject(parent), _blockEvents(false) {
+ #if QT_VERSION >= 0x040200
+ 	// This is needed with Qt 4.2 and later. See Trac ticket #1322.
+ 	//
+@@ -34,7 +34,6 @@
+ 		moveToThread(QCoreApplication::instance()->thread());
+ 	}
+ #endif
+-	_blockEvents = false;
+ }
+ 
+ QObjectThreadSafe::~QObjectThreadSafe() {
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/phapi-fix-crash-missing-codec.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/phapi-fix-crash-missing-codec.patch
@@ -0,0 +1,181 @@
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h263.c	2007-09-07 21:58:54.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263.c	2007-09-07 21:59:00.000000000 +0000
+@@ -68,7 +68,12 @@
+  	h263t->max_frame_len = MAX_ENC_BUFFER_SIZE;
+ 	h263t->data_enc = (uint8_t *) av_malloc (h263t->max_frame_len);
+ 
+-	phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s);
++	if(phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s) < 0)
++	{
++		av_free(h263t->data_enc);
++		free(h263t);
++		return 0;
++	}
+ 
+ 	h263t->encoder_ctx.context->flags |= CODEC_FLAG_QP_RD;
+ 	h263t->encoder_ctx.context->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
+@@ -103,7 +108,11 @@
+ 
+ 	h263t = (ph_h263_decoder_ctx_t *) calloc(sizeof(ph_h263_decoder_ctx_t), 1);
+   	_h263_meta_init(&h263t->meta, s);
+-	phcodec_avcodec_decoder_init(&h263t->decoder_ctx, &h263t->meta);
++ 	if(phcodec_avcodec_decoder_init(&h263t->decoder_ctx, &h263t->meta) < 0)
++ 	{
++ 		free(h263t);
++ 		return 0;
++ 	}
+ 	h263t->max_frame_len = MAX_DEC_BUFFER_SIZE;
+ 	h263t->data_dec = (uint8_t *) av_malloc (h263t->max_frame_len+FF_INPUT_BUFFER_PADDING_SIZE);
+ 	memset(h263t->data_dec + h263t->max_frame_len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263flv1.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h263flv1.c	2007-09-07 21:58:54.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263flv1.c	2007-09-07 21:59:00.000000000 +0000
+@@ -68,7 +68,12 @@
+  	h263t->max_frame_len = MAX_ENC_BUFFER_SIZE;
+ 	h263t->data_enc = (uint8_t *) av_malloc (h263t->max_frame_len);
+ 
+-	phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s);
++	if(phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s) < 0)
++	{
++		av_free(h263t->data_enc);
++		free(h263t);
++		return 0;
++	}
+ 
+ 	h263t->encoder_ctx.context->flags |= CODEC_FLAG_QP_RD;
+ 	h263t->encoder_ctx.context->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
+@@ -103,7 +108,11 @@
+ 
+ 	h263t = (ph_h263_decoder_ctx_t *) calloc(sizeof(ph_h263_decoder_ctx_t), 1);
+   	_h263flv1_meta_init(&h263t->meta, s);
+-	phcodec_avcodec_decoder_init(&h263t->decoder_ctx, &h263t->meta);
++  	if(phcodec_avcodec_decoder_init(&h263t->decoder_ctx, &h263t->meta) < 0)
++  	{
++  		free(h263t);
++  		return 0;
++  	}
+ 	h263t->max_frame_len = MAX_DEC_BUFFER_SIZE;
+ 	h263t->data_dec = (uint8_t *) av_malloc (h263t->max_frame_len+FF_INPUT_BUFFER_PADDING_SIZE);
+ 	memset(h263t->data_dec + h263t->max_frame_len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263plus.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h263plus.c	2007-09-07 21:58:54.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263plus.c	2007-09-07 21:59:00.000000000 +0000
+@@ -61,7 +61,12 @@
+  	h263t->max_frame_len = MAX_ENC_BUFFER_SIZE;
+ 	h263t->data_enc = (uint8_t *) av_malloc (h263t->max_frame_len);
+ 
+-	phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s);
++	if(phcodec_avcodec_encoder_init(&h263t->encoder_ctx, &h263t->meta, s) < 0)
++	{
++		av_free(h263t->data_enc);
++		free(h263t);
++		return 0;
++	}
+ 
+ 	h263t->encoder_ctx.context->flags |= CODEC_FLAG_QP_RD;
+ 	h263t->encoder_ctx.context->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
+@@ -96,7 +101,11 @@
+ 
+ 	h263t = (ph_h263_decoder_ctx_t *) calloc(sizeof(ph_h263_decoder_ctx_t), 1);
+   	_h263p_meta_init(&h263t->meta, s);
+-	phcodec_avcodec_decoder_init(&h263t->decoder_ctx, &h263t->meta);
++	if(phcodec_avcodec_decoder_init(&h263t->decoder_ctx, &h263t->meta) < 0)
++	{
++		free(h263t);
++		return 0;
++	}
+ 	h263t->max_frame_len = MAX_DEC_BUFFER_SIZE;
+ 	h263t->data_dec = (uint8_t *) av_malloc (h263t->max_frame_len+FF_INPUT_BUFFER_PADDING_SIZE);
+ 	memset(h263t->data_dec + h263t->max_frame_len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h264.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h264.c	2007-09-07 21:58:54.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h264.c	2007-09-07 21:59:00.000000000 +0000
+@@ -70,7 +70,12 @@
+  	h264t->max_frame_len = 8096;
+ 	h264t->data_enc = (uint8_t *) av_malloc (h264t->max_frame_len);
+ 
+-	phcodec_avcodec_encoder_init(&h264t->encoder_ctx, &h264t->meta, s);
++	if(phcodec_avcodec_encoder_init(&h264t->encoder_ctx, &h264t->meta, s) < 0)
++	{
++		av_free(h264t->data_enc);
++		free(h264t);
++		return 0;
++	}
+ 
+ 	if (avcodec_open(h264t->encoder_ctx.context,
+ 			h264t->encoder_ctx.encoder) < 0)
+@@ -90,7 +95,11 @@
+ 	h264t->data_dec = (uint8_t *) av_malloc (100000);
+ 	h264t->buf_index = 0;
+ 	h264t->max_frame_len = 8096;
+-	phcodec_avcodec_decoder_init(&h264t->decoder_ctx, &h264t->meta);
++ 	if(phcodec_avcodec_decoder_init(&h264t->decoder_ctx, &h264t->meta) < 0)
++ 	{
++ 		free(h264t);
++ 		return 0;
++ 	}
+ 
+ 	return h264t;
+ }
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-mpeg4.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-mpeg4.c	2007-09-07 21:58:54.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-mpeg4.c	2007-09-07 21:59:00.000000000 +0000
+@@ -73,7 +73,12 @@
+ 	mpeg4t->max_frame_len = 8096;
+ 	mpeg4t->data_enc = (uint8_t *) av_malloc (mpeg4t->max_frame_len);
+ 
+-	phcodec_avcodec_encoder_init(&mpeg4t->encoder_ctx, &mpeg4t->meta, s);
++	if(phcodec_avcodec_encoder_init(&mpeg4t->encoder_ctx, &mpeg4t->meta, s) < 0)
++	{
++		av_free(mpeg4t->data_enc);
++		free(mpeg4t);
++		return 0;
++	}
+ 
+ 	mpeg4t->encoder_ctx.context->flags |= CODEC_FLAG_QP_RD;
+ 	//mpeg4t->encoder_ctx.context->flags |= CODEC_FLAG_H263P_UMV;
+@@ -106,7 +111,11 @@
+ 
+ 	mpeg4t = (ph_mpeg4_decoder_ctx_t *) calloc(sizeof(ph_mpeg4_decoder_ctx_t), 1);
+   	_mpeg4_meta_init(&mpeg4t->meta, s);
+-	phcodec_avcodec_decoder_init(&mpeg4t->decoder_ctx, &mpeg4t->meta);
++ 	if(phcodec_avcodec_decoder_init(&mpeg4t->decoder_ctx, &mpeg4t->meta) < 0)
++ 	{
++ 		free(mpeg4t);
++ 		return 0;
++ 	}
+ 	mpeg4t->data_dec = (uint8_t *) av_malloc (100000);
+ 	mpeg4t->buf_index = 0;
+ 	mpeg4t->max_frame_len = 8096;
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phmedia-video.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phmedia-video.c	2007-09-07 21:58:54.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phmedia-video.c	2007-09-07 21:59:00.000000000 +0000
+@@ -489,11 +489,21 @@
+ 	if (codec->encoder_init)
+ 	{
+ 		video_stream->ms.encoder_ctx = codec->encoder_init(video_stream);
++		if (!video_stream->ms.encoder_ctx) {
++			DBG_MEDIA_ENGINE_VIDEO("unable to initialize video encoder\n");
++			osip_free(video_stream);
++			return -1;
++		}
+ 	}
+ 
+ 	if (codec->decoder_init)
+ 	{
+ 		video_stream->ms.decoder_ctx = codec->decoder_init(video_stream);
++		if (!video_stream->ms.decoder_ctx) {
++			DBG_MEDIA_ENGINE_VIDEO("unable to initialize video decoder\n");
++			osip_free(video_stream);
++			return -1;
++		}
+ 	}
+ 
+ #ifdef PHAPI_VIDEO_LOCAL_HACK
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/gcc-4_3.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/gcc-4_3.patch
@@ -0,0 +1,46 @@
+Index: wengophone-2.1.2.dfsg0/libs/owutil/system/src/unix/Processes.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/system/src/unix/Processes.cpp	2007-02-25 05:15:25.000000000 -0800
++++ wengophone-2.1.2.dfsg0/libs/owutil/system/src/unix/Processes.cpp	2008-04-22 15:27:32.000000000 -0700
+@@ -22,6 +22,8 @@
+ #include <dirent.h>
+ #include <fcntl.h>
+ 
++#include <cstdlib>
++
+ #define BUFFERSIZE 1024
+ #define FILENAMESIZE 128
+ #define PROCESSNAMESIZE 512
+Index: wengophone-2.1.2.dfsg0/owbuild/owbuild/getcurrentdatetime.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/owbuild/owbuild/getcurrentdatetime.cpp	2007-03-26 05:13:43.000000000 -0700
++++ wengophone-2.1.2.dfsg0/owbuild/owbuild/getcurrentdatetime.cpp	2008-04-22 15:27:32.000000000 -0700
+@@ -7,6 +7,7 @@
+ 
+ #include <string>
+ #include <ctime>
++#include <cstdlib>
+ #include <iostream>
+ #include <sstream>
+ 
+Index: wengophone-2.1.2.dfsg0/wengophone/src/presentation/qt/chat/QtChatAvatarWidget.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wengophone/src/presentation/qt/chat/QtChatAvatarWidget.cpp	2008-04-22 15:28:30.000000000 -0700
++++ wengophone-2.1.2.dfsg0/wengophone/src/presentation/qt/chat/QtChatAvatarWidget.cpp	2008-04-22 15:28:35.000000000 -0700
+@@ -17,14 +17,14 @@
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  */
+ 
+-#include "QtChatAvatarWidget.h"
+-
+ #include <QtGui/QtGui>
+ 
+ #include <model/profile/AvatarList.h>
+ 
+ #include <util/Logger.h>
+ 
++#include "QtChatAvatarWidget.h"
++
+ QtChatAvatarWidget::QtChatAvatarWidget(QWidget * parent, const QString & id,
+ 	QPixmap picture, const QString & nickname, const QString & contactId, PictureMode pmode, NicknameMode nmode)
+ 	: QWidget(parent), _pictureMode(pmode), _nicknameMode(nmode), _contactId(id) {
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/curl-openssl-mt-fix.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/curl-openssl-mt-fix.patch
@@ -0,0 +1,156 @@
+Index: wengophone-2.1.2.dfsg0/libs/owutil/http/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/http/CMakeLists.txt	2007-03-01 14:37:00.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/http/CMakeLists.txt	2007-09-07 21:37:11.000000000 +0000
+@@ -7,6 +7,7 @@
+ 
+ ow_use_private_libraries(
+ 	curl
++	httptunnel
+ )
+ 
+ if (WIN32)
+@@ -18,6 +19,7 @@
+ 
+ ow_add_sources(
+ 	src/HttpRequest.cpp
++	src/HttpRequestFactory.cpp
+ 	src/curl/CurlHttpRequest.cpp
+ 	#src/null/NullHttpRequest.cpp
+ 	#src/qt/QtHttpRequest.cpp
+Index: wengophone-2.1.2.dfsg0/libs/owutil/http/HttpRequest.h
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/http/HttpRequest.h	2007-01-31 17:57:31.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/http/HttpRequest.h	2007-09-07 21:37:11.000000000 +0000
+@@ -156,6 +156,8 @@
+ 
+ 	OWHTTP_API void abort();
+ 
++	OWHTTP_API static void init();
++
+ private:
+ 
+ 	//Inherited from Thread
+Index: wengophone-2.1.2.dfsg0/libs/owutil/http/src/HttpRequest.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/http/src/HttpRequest.cpp	2007-01-31 17:57:31.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/http/src/HttpRequest.cpp	2007-09-07 21:37:11.000000000 +0000
+@@ -156,6 +156,10 @@
+ void HttpRequest::run() {
+ }
+ 
++void HttpRequest::init() {
++	HttpRequestFactory::init();
++}
++
+ void HttpRequest::answerReceivedEventHandler(IHttpRequest * sender, int requestId, const std::string & answer, Error error) {
+ 	//sender = _httpRequestPrivate
+ 	//sender now is HttpRequest that will delete _httpRequestPrivate
+Index: wengophone-2.1.2.dfsg0/libs/owutil/http/src/HttpRequestFactory.cpp
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/http/src/HttpRequestFactory.cpp	2007-09-07 21:37:11.000000000 +0000
+@@ -0,0 +1,15 @@
++#include "HttpRequestFactory.h"
++
++#include <httptunnel.h>
++
++#include <util/Logger.h>
++
++#include <curl/curl.h>
++
++void HttpRequestFactory::init() {
++	CURLcode ret = curl_global_init(CURL_GLOBAL_ALL);
++	if(ret)
++		LOG_ERROR("initialization of curl failed");
++	http_tunnel_init_ssl();
++}
++
+Index: wengophone-2.1.2.dfsg0/libs/owutil/http/src/HttpRequestFactory.h
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/http/src/HttpRequestFactory.h	2007-03-01 12:17:48.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/http/src/HttpRequestFactory.h	2007-09-07 21:37:11.000000000 +0000
+@@ -36,6 +36,8 @@
+ class HttpRequestFactory : NonCopyable {
+ public:
+ 
++	static void init();
++	
+ 	static IHttpRequest * create() {
+ 		//new QtHttpRequest();
+ 		//new NullHttpRequest();
+Index: wengophone-2.1.2.dfsg0/libs/owutil/http/src/curl/CurlHttpRequest.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/http/src/curl/CurlHttpRequest.cpp	2007-03-19 17:31:18.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/http/src/curl/CurlHttpRequest.cpp	2007-09-07 21:37:11.000000000 +0000
+@@ -205,7 +205,7 @@
+ 	//curl_easy_setopt(_curl, CURLOPT_WRITEHEADER, this);
+ 	curl_easy_setopt(_curl, CURLOPT_WRITEDATA, this);
+ 	curl_easy_setopt(_curl, CURLOPT_PROGRESSDATA, this);
+-	curl_easy_setopt(_curl, CURLOPT_NOSIGNAL, 0);
++	curl_easy_setopt(_curl, CURLOPT_NOSIGNAL, 1);
+ 	curl_easy_setopt(_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ 
+ 	//Maximum time in seconds that you allow the libcurl transfer operation to take
+Index: wengophone-2.1.2.dfsg0/wengophone/src/model/WengoPhone.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wengophone/src/model/WengoPhone.cpp	2007-06-20 08:44:26.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wengophone/src/model/WengoPhone.cpp	2007-09-07 21:37:11.000000000 +0000
+@@ -50,6 +50,7 @@
+ 	_enableSerialization = true;
+ 	_startupSettingListener = new StartupSettingListener();
+ 
++	HttpRequest::init();
+ 	//set HttpRequest User Agent
+ 	std::stringstream ss;
+ 	ss << WengoPhoneBuildId::getSoftphoneName();
+Index: wengophone-2.1.2.dfsg0/wifo/httptunnel/httptunnel.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/httptunnel/httptunnel.c	2007-04-20 14:29:17.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/httptunnel/httptunnel.c	2007-09-07 21:37:11.000000000 +0000
+@@ -93,7 +93,7 @@
+ 
+ int	UseProxy = 0;
+ 
+-int UseSSL = 0;
++int UseSSL = 1;
+ int sslIsInit = 0;
+ 
+ #ifdef HT_USE_SSL
+Index: wengophone-2.1.2.dfsg0/wifo/httptunnel/httptunnel.h
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/httptunnel/httptunnel.h	2007-01-26 13:40:41.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/httptunnel/httptunnel.h	2007-09-07 21:37:11.000000000 +0000
+@@ -88,6 +88,7 @@
+ int http_tunnel_close(void *h_tunnel);
+ void http_tunnel_init_host(const char *hostname, int port, int ssl);
+ void http_tunnel_init_proxy(const char *hostname, int port, const char *username, const char *password);
++void http_tunnel_init_ssl();
+ void http_tunnel_clean_up();
+ #ifdef __cplusplus
+ }
+Index: wengophone-2.1.2.dfsg0/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/CMakeLists.txt	2007-08-22 11:44:50.000000000 +0000
++++ wengophone-2.1.2.dfsg0/CMakeLists.txt	2007-09-07 21:38:13.000000000 +0000
+@@ -40,6 +40,7 @@
+ endif(LINUX AND OWSOUND_PORTAUDIO_SUPPORT)
+ 
+ subdirs(
++ 	wifo/httptunnel	# Needed by owhttp
+ 	libs/owutil
+ 	libs/wenbox
+ 	libs/qtutil
+Index: wengophone-2.1.2.dfsg0/wifo/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/CMakeLists.txt	2007-04-24 10:01:04.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/CMakeLists.txt	2007-09-07 21:37:11.000000000 +0000
+@@ -35,7 +35,7 @@
+ endif (PHAPI_CODEC_ILBC_SUPPORT)
+ 
+ subdirs(
+-	httptunnel
++#	httptunnel # Moved in ../CMakeLists.txt
+ 	netlib
+ 	ortp
+ 	srtp
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/memory-dump-fix-double-dump.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/memory-dump-fix-double-dump.patch
@@ -0,0 +1,21 @@
+Index: wengophone-2.1.2.dfsg0/libs/owutil/memorydump/src/unix/UNIXMemoryDump.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/memorydump/src/unix/UNIXMemoryDump.cpp	2007-04-02 16:01:08.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/memorydump/src/unix/UNIXMemoryDump.cpp	2007-09-08 14:51:43.000000000 +0000
+@@ -25,11 +25,16 @@
+ #include <util/Path.h>
+ 
+ #include <unistd.h>
++#include <sys/resource.h>
+ 
+ UNIXMemoryDump::UNIXMemoryDump(const std::string & applicationName, const std::string & revision)
+ 	: MemoryDump(applicationName, revision) {
+ 
+ 	doJob();
++
++	// avoid an additional core dump
++	struct rlimit rlim = {0, 0};
++	setrlimit(RLIMIT_CORE, &rlim);
+ 	abort();
+ }
+ 
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/cmake-fix-ENABLE_CRASHREPORT.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/cmake-fix-ENABLE_CRASHREPORT.patch
@@ -0,0 +1,59 @@
+Index: wengophone-2.1.2.dfsg0/libs/3rdparty/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/3rdparty/CMakeLists.txt	2007-07-19 15:05:30.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/3rdparty/CMakeLists.txt	2007-09-07 21:36:28.000000000 +0000
+@@ -57,8 +57,8 @@
+ 	#iaxclient
+ )
+ 
+-if (LINUX)
++if (LINUX AND ENABLE_CRASHREPORT)
+ 	subdirs(
+ 		coredumper
+ 	)
+-endif (LINUX)
++endif (LINUX AND ENABLE_CRASHREPORT)
+Index: wengophone-2.1.2.dfsg0/libs/owutil/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/CMakeLists.txt	2007-04-02 16:41:31.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/CMakeLists.txt	2007-09-07 21:34:49.000000000 +0000
+@@ -32,9 +32,11 @@
+ 	http
+ )
+ 
+-if (WIN32 OR LINUX)
+-       subdirs(
+-               memorydump
+-       )
+-endif (WIN32 OR LINUX)
++if (ENABLE_CRASHREPORT)
++	if (WIN32 OR LINUX)
++	       subdirs(
++		       memorydump
++	       )
++	endif (WIN32 OR LINUX)
++endif (ENABLE_CRASHREPORT)
+ 
+Index: wengophone-2.1.2.dfsg0/wengophone/src/presentation/qt/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wengophone/src/presentation/qt/CMakeLists.txt	2007-07-20 13:37:37.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wengophone/src/presentation/qt/CMakeLists.txt	2007-09-07 21:34:49.000000000 +0000
+@@ -23,11 +23,13 @@
+ 	owsoftupdater
+ )
+ 
+-if (MSVC OR LINUX)
+-	ow_use_private_libraries(
+-		owmemorydump
+-		)
+-endif (MSVC OR LINUX)
++if (ENABLE_CRASHREPORT)
++	if (MSVC OR LINUX)
++		ow_use_private_libraries(
++			owmemorydump
++			)
++	endif (MSVC OR LINUX)
++endif (ENABLE_CRASHREPORT)
+ 
+ if (SIPWRAPPER_BACKEND_SIPX)
+ 	ow_add_private_definitions(
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/def-enable-video-fix.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/def-enable-video-fix.patch
@@ -0,0 +1,24 @@
+Index: wengophone-2.1.1.dfsg0/libs/sipwrapper/src/phapi/PhApiWrapper.cpp
+===================================================================
+--- wengophone-2.1.1.dfsg0.orig/libs/sipwrapper/src/phapi/PhApiWrapper.cpp	2007-08-23 11:38:15.000000000 +0000
++++ wengophone-2.1.1.dfsg0/libs/sipwrapper/src/phapi/PhApiWrapper.cpp	2007-08-23 11:38:56.000000000 +0000
+@@ -655,7 +655,9 @@
+ }
+ 
+ void PhApiWrapper::setVideoQuality(EnumVideoQuality::VideoQuality videoQuality) {
++#ifdef ENABLE_VIDEO
+ 	phVideoControlSetWebcamCaptureResolution(320, 240);
++#endif
+ 
+ 	switch(videoQuality) {
+ 	case EnumVideoQuality::VideoQualityNormal:
+@@ -887,7 +889,9 @@
+ }
+ 
+ void PhApiWrapper::flipVideoImage(bool flip) {
++#ifdef ENABLE_VIDEO
+ 	phVideoControlSetCameraFlip((int)flip);
++#endif
+ }
+ 
+ std::string PhApiWrapper::makeSipAddress(const std::string & contactId) {
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/desktop-file-update.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/desktop-file-update.patch
@@ -0,0 +1,19 @@
+Index: wengophone-2.1.2.dfsg0/wengophone/res/wengophone.desktop
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wengophone/res/wengophone.desktop	2007-03-20 08:51:32.000000000 -0700
++++ wengophone-2.1.2.dfsg0/wengophone/res/wengophone.desktop	2008-04-22 17:14:20.000000000 -0700
+@@ -1,8 +1,11 @@
+ [Desktop Entry]
+-Encoding=UTF-8
+ Name=WengoPhone
+-Comment=VOIP softphone
+-Comment[fr]=Téléphone VOIP
++Comment=Talk to people over the Internet and send instant messages over multiple protocols
++Comment[fr]=Discuter avec des personnes sur Internet e envoie des messages instantanés en utilisant divers protocoles
++Comment[it]=Comunicare con le persone via Internet e inviare messaggi istantanei multiprotocollo
++GenericName=VoIP softphone and IM client
++GenericName[fr]=Téléphone VoIP e client IM
++GenericName[it]=Programma VoIP e client IM
+ Exec=qtwengophone
+ Icon=wengophone
+ StartupNotify=true
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/memory-dump-tmp-path.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/memory-dump-tmp-path.patch
@@ -0,0 +1,30 @@
+Index: wengophone-2.1.2.dfsg0/libs/owutil/memorydump/src/unix/UNIXMemoryDump.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owutil/memorydump/src/unix/UNIXMemoryDump.cpp	2007-09-08 14:51:43.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owutil/memorydump/src/unix/UNIXMemoryDump.cpp	2007-09-08 14:52:55.000000000 +0000
+@@ -25,6 +25,7 @@
+ #include <util/Path.h>
+ 
+ #include <unistd.h>
++#include <stdlib.h>
+ #include <sys/resource.h>
+ 
+ UNIXMemoryDump::UNIXMemoryDump(const std::string & applicationName, const std::string & revision)
+@@ -51,8 +52,15 @@
+ 	memoryDumpName += getCurrentDateTime();
+ 	memoryDumpName += ".core";
+ 
+-	std::string memoryDumpFile(Path::getApplicationDirPath());
+-	memoryDumpFile += memoryDumpName;
++	const char * coreDir = getenv("WENGOPHONE_COREDUMP_DIR");
++	if(!coreDir) {
++		coreDir = getenv("TMPDIR");
++	}
++	if(!coreDir) {
++		coreDir = "/tmp";
++	}
++	std::string memoryDumpFile(coreDir);
++	memoryDumpFile += '/' + memoryDumpName;
+ 
+ 	WriteCoreDump(memoryDumpFile.c_str());
+ 
--- wengophone-2.1.2.dfsg0.orig/debian/patches/generic/cmake-static-coredumper.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/generic/cmake-static-coredumper.patch
@@ -0,0 +1,33 @@
+Index: wengophone-2.1.1.dfsg/libs/3rdparty/coredumper/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.1.dfsg.orig/libs/3rdparty/coredumper/CMakeLists.txt	2007-07-16 16:10:04.000000000 +0200
++++ wengophone-2.1.1.dfsg/libs/3rdparty/coredumper/CMakeLists.txt	2007-07-16 16:10:32.000000000 +0200
+@@ -1,4 +1,4 @@
+-ow_create_shared_library(coredumper)
++ow_create_static_library(coredumper)
+ 
+ ow_add_sources(
+ 	src/coredumper.c
+Index: wengophone-2.1.1.dfsg/wengophone/src/presentation/qt/CMakeLists-install-linux.txt
+===================================================================
+--- wengophone-2.1.1.dfsg.orig/wengophone/src/presentation/qt/CMakeLists-install-linux.txt	2007-07-16 16:10:17.000000000 +0200
++++ wengophone-2.1.1.dfsg/wengophone/src/presentation/qt/CMakeLists-install-linux.txt	2007-07-16 16:11:08.000000000 +0200
+@@ -21,12 +21,12 @@
+ 	${TMP_BUILD_DIR}/libsfp-plugin.so
+ 	DESTINATION lib${LIB_SUFFIX}/wengophone)
+ 
+-if (ENABLE_CRASHREPORT)
+-	install(PROGRAMS
+-		${TMP_BUILD_DIR}/libcoredumper.so
+-		DESTINATION lib${LIB_SUFFIX}/wengophone
+-	)
+-endif (ENABLE_CRASHREPORT)
++#if (ENABLE_CRASHREPORT)
++#	install(PROGRAMS
++#		${TMP_BUILD_DIR}/libcoredumper.so
++#		DESTINATION lib${LIB_SUFFIX}/wengophone
++#	)
++#endif (ENABLE_CRASHREPORT)
+ 
+ if (CURL_INTERNAL)
+ 	install(PROGRAMS
--- wengophone-2.1.2.dfsg0.orig/debian/patches/head/ffmpeg-swscale-api.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/head/ffmpeg-swscale-api.patch
@@ -0,0 +1,282 @@
+Index: wengophone-2.1.2.dfsg0/libs/owpixertool/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owpixertool/CMakeLists.txt	2008-05-25 22:50:14.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owpixertool/CMakeLists.txt	2008-05-25 22:50:19.000000000 +0000
+@@ -17,6 +17,7 @@
+ 
+ ow_add_public_include_dirs(
+ 	${CMAKE_CURRENT_SOURCE_DIR}/include
++	${CMAKE_CURRENT_BINARY_DIR}
+ )
+ 
+ ow_add_sources(
+@@ -49,3 +50,5 @@
+ endif (UNIX AND NOT WIN32)
+ 
+ ow_create_binary()
++configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
++
+Index: wengophone-2.1.2.dfsg0/libs/owpixertool/config.h.cmake
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owpixertool/config.h.cmake	2008-05-25 22:50:19.000000000 +0000
+@@ -0,0 +1,6 @@
++#ifndef PIXERTOOL_CONFIG_H
++#define PIXERTOOL_CONFIG_H
++
++#cmakedefine HAVE_SWSCALE
++
++#endif
+Index: wengophone-2.1.2.dfsg0/libs/owpixertool/include/pixertool/ffmpeg-pixertool.h
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owpixertool/include/pixertool/ffmpeg-pixertool.h	2008-05-25 22:50:14.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owpixertool/include/pixertool/ffmpeg-pixertool.h	2008-05-25 22:50:19.000000000 +0000
+@@ -22,7 +22,18 @@
+ 
+ #include <pixertool/pixertool.h>
+ 
++#include "config.h"
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++#ifdef HAVE_SWSCALE
++#include <swscale.h>
++#endif
+ #include <avcodec.h>
++#ifdef __cplusplus
++}
++#endif
+ 
+ #ifdef __cplusplus
+ extern "C" {
+Index: wengophone-2.1.2.dfsg0/libs/owpixertool/src/ffmpeg/ffmpeg-pixertool.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owpixertool/src/ffmpeg/ffmpeg-pixertool.c	2008-05-25 22:50:14.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owpixertool/src/ffmpeg/ffmpeg-pixertool.c	2008-05-25 22:50:19.000000000 +0000
+@@ -17,15 +17,23 @@
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  */
+ 
++#include "config.h"
++
+ #include <pixertool/ffmpeg-pixertool.h>
+ 
++#include <stdlib.h>
++
+ #include <avcodec.h>
++#ifdef HAVE_SWSCALE
++#include <swscale.h>
++#endif
+ 
+-#include <stdlib.h>
+ 
+ /** Used by pix_convert_avpicture */
+ static AVPicture * pictureBuffer = NULL;
+ 
++
++
+ /** Called at program exit */
+ static void pix_ffmpeg_cleanup(void);
+ 
+@@ -123,8 +131,12 @@
+ }
+ 
+ pixerrorcode pix_convert_avpicture(int flags, piximage * img_dst, AVPicture * img_src, pixosi src_fmt) {
++#ifdef HAVE_SWSCALE
++	struct SwsContext *convert_context;
++#endif
+ 	pixosi desiredPalette = pix_ffmpeg_from_pix_osi(img_dst->palette);
+ 
++
+ 	if (!pictureBuffer) {
+ 		pictureBuffer = (AVPicture *) malloc(sizeof(AVPicture));
+ 		atexit(pix_ffmpeg_cleanup);
+@@ -132,9 +144,22 @@
+ 
+ 	avpicture_fill(pictureBuffer, img_dst->data, desiredPalette, img_dst->width, img_dst->height);
+ 
+-	img_convert(pictureBuffer, desiredPalette,
+-		img_src, pix_ffmpeg_from_pix_osi(src_fmt),
+-		img_dst->width, img_dst->height);
++#ifndef HAVE_SWSCALE
++       img_convert(pictureBuffer, desiredPalette,
++               img_src, pix_ffmpeg_from_pix_osi(src_fmt),
++               img_dst->width, img_dst->height);
++#else
++	convert_context = sws_getContext(img_dst->width, img_dst->height, pix_ffmpeg_from_pix_osi(src_fmt),
++		    img_dst->width, img_dst->height, desiredPalette,
++		    SWS_BICUBIC, NULL, NULL, NULL);
++	if(!convert_context) {
++		return PIX_NOK;
++	}
++	sws_scale(convert_context, img_src->data, img_src->linesize,
++		      0, img_dst->height,
++		      pictureBuffer->data, pictureBuffer->linesize);
++	sws_freeContext(convert_context);
++#endif
+ 
+ 	//pictureBuffer->data[0] should contain only valid data
+ 
+Index: wengophone-2.1.2.dfsg0/libs/owpixertool/src/pixertool.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/owpixertool/src/pixertool.cpp	2008-05-25 22:50:14.000000000 +0000
++++ wengophone-2.1.2.dfsg0/libs/owpixertool/src/pixertool.cpp	2008-05-25 22:50:19.000000000 +0000
+@@ -17,10 +17,23 @@
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  */
+ 
++#include "config.h"
++
+ #include <pixertool/pixertool.h>
+ 
+ #include <pixertool/ffmpeg-pixertool.h>
+ 
++#ifdef __cplusplus
++extern "C" {
++#endif
++#include <avcodec.h>
++#ifdef HAVE_SWSCALE
++#include <swscale.h>
++#endif
++#ifdef __cplusplus
++}
++#endif
++
+ #include <stdlib.h>
+ #include <string.h>
+ 
+@@ -73,6 +86,9 @@
+ 
+ 	uint8_t * buf_source = img_src->data;
+ 	int need_avfree = 0;
++#ifdef HAVE_SWSCALE
++	struct SwsContext *convert_context;
++#endif
+ 
+ 	//If the format is NV12, transforming it
+ 	if (img_src->palette == PIX_OSI_NV12) {
+@@ -90,7 +106,7 @@
+ 	}
+ 	////
+ 
+-	int len_target = pix_size(img_dst->palette, img_src->width, img_src->height);
++	//int len_target = pix_size(img_dst->palette, img_src->width, img_src->height);
+ 
+ 	int pix_fmt_source = pix_ffmpeg_from_pix_osi(img_src->palette);
+ 	int pix_fmt_target = pix_ffmpeg_from_pix_osi(img_dst->palette);
+@@ -121,43 +137,73 @@
+ 			return PIX_NOK;
+ 		}
+ 
+-		//TODO optimize this part but will need the preparation of contexts
+-		ImgReSampleContext * resample_context = img_resample_init(img_dst->width, img_dst->height,
+-			img_src->width, img_src->height);
++#ifndef HAVE_SWSCALE
++	      //TODO optimize this part but will need the preparation of contexts
++               ImgReSampleContext * resample_context = img_resample_init(img_dst->width, img_dst->height,
++                       img_src->width, img_src->height);
++
++               if (!resample_context) {
++                       return PIX_NOK;
++               }
++
++               AVPicture avp_tmp_target;
++
++               //we need to prepare a tmp buffer
++               uint8_t * buf_tmp_target = (uint8_t *)av_malloc(avpicture_get_size(pix_fmt_source, img_dst->width, img_dst->height)  * sizeof(uint8_t));
++               avpicture_fill(&avp_tmp_target, buf_tmp_target, pix_fmt_source, img_dst->width, img_dst->height);
++               //
++
++               //do the resampling
++               img_resample(resample_context, &avp_tmp_target, &avp_source);
++               img_resample_close(resample_context);
++               //
+ 
+-		if (!resample_context) {
++                //do the conversion
++		if (img_convert(&avp_target, pix_fmt_target,
++		        &avp_tmp_target, pix_fmt_source,
++	  	        img_dst->width, img_dst->height) == -1) {
++			av_free(buf_tmp_target);
++                        return PIX_NOK;
++	        }
++	        av_free(buf_tmp_target);
++#else
++		//do the conversion
++		convert_context = sws_getContext(img_src->width, img_src->height, pix_fmt_source, img_dst->width, img_dst->height, pix_fmt_target, SWS_BICUBIC, NULL, NULL, NULL);
++		if(!convert_context) {
+ 			return PIX_NOK;
+ 		}
++		if (sws_scale(convert_context, avp_source.data, avp_source.linesize,
++		    0, img_src->height, 
++		    avp_target.data, avp_target.linesize) == -1) {
++			sws_freeContext(convert_context);
+ 
+-		AVPicture avp_tmp_target;
+-
+-		//we need to prepare a tmp buffer
+-		uint8_t * buf_tmp_target = (uint8_t *)av_malloc(avpicture_get_size(pix_fmt_source, img_dst->width, img_dst->height)  * sizeof(uint8_t));
+-		avpicture_fill(&avp_tmp_target, buf_tmp_target, pix_fmt_source, img_dst->width, img_dst->height);
+-		//
+-
+-		//do the resampling
+-		img_resample(resample_context, &avp_tmp_target, &avp_source);
+-		img_resample_close(resample_context);
+-		//
+-
+-		//do the conversion
+-		if (img_convert(&avp_target, pix_fmt_target,
+-			&avp_tmp_target, pix_fmt_source,
+-			img_dst->width, img_dst->height) == -1) {
+-
+-			av_free(buf_tmp_target);
+ 			return PIX_NOK;
+ 		}
+-		av_free(buf_tmp_target);
++		sws_freeContext(convert_context);
+ 		//
++#endif
++
+ 
+ 	} else {
+-		if (img_convert(&avp_target, pix_fmt_target,
+-			&avp_source, pix_fmt_source,
+-			img_src->width, img_src->height) == -1) {
++#ifndef HAVE_SWSCALE
++               if (img_convert(&avp_target, pix_fmt_target,
++                       &avp_source, pix_fmt_source,
++                       img_src->width, img_src->height) == -1) {
++			return PIX_NOK;
++		}
++#else
++		convert_context = sws_getContext(img_src->width, img_src->height, pix_fmt_source, img_dst->width, img_dst->height, pix_fmt_target, SWS_BICUBIC, NULL, NULL, NULL);
++		if(!convert_context) {
++			return PIX_NOK;
++		}
++		if (sws_scale(convert_context, avp_source.data, avp_source.linesize,
++		    0, img_src->height, 
++		    avp_target.data, avp_target.linesize) == -1) {
++			sws_freeContext(convert_context);
+ 			return PIX_NOK;
+ 		}
++		sws_freeContext(convert_context);
++#endif
+ 	}
+ 	////
+ 
+Index: wengophone-2.1.2.dfsg0/wengophone/src/WengoPhoneBuildId.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wengophone/src/WengoPhoneBuildId.cpp	2008-05-25 22:50:38.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wengophone/src/WengoPhoneBuildId.cpp	2008-05-25 22:50:48.000000000 +0000
+@@ -27,9 +27,9 @@
+ 	#include <portaudio.h>
+ #endif
+ #include <boost/version.hpp>
+-#include <avcodec.h>
+ #include <tinyxml.h>
+ extern "C" {
++#include <avcodec.h>
+ #include <glib.h>
+ #include <gaim/core.h>
+ }
--- wengophone-2.1.2.dfsg0.orig/debian/patches/head/alsa-plughw-default.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/head/alsa-plughw-default.patch
@@ -0,0 +1,67 @@
+Index: wengophone-2.1.2.dfsg0/libs/sound/src/linux/AudioDeviceManager.cpp
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/libs/sound/src/linux/AudioDeviceManager.cpp	2007-04-20 16:06:36.000000000 +0200
++++ wengophone-2.1.2.dfsg0/libs/sound/src/linux/AudioDeviceManager.cpp	2007-09-22 23:57:08.000000000 +0200
+@@ -28,39 +28,19 @@
+ std::list<AudioDevice> AudioDeviceManager::getInputDeviceList() {
+ 	RecursiveMutex::ScopedLock scopedLock(_mutex);
+ 
+-	//HACK: always return the default one + plughw
+-	std::list<AudioDevice> deviceList;
+-	deviceList.push_back(getDefaultInputDevice());
+-
+-	StringList data;
+-	data += String("ALSA: plughw");
+-	data += String("plughw");
+-	data += EnumDeviceType::toString(EnumDeviceType::DeviceTypeWaveIn);
+-	deviceList.push_back(AudioDevice(data));
++	std::list<AudioDevice> deviceList = find_alsa_devices(1);
++	deviceList.push_front(getDefaultInputDevice());
+ 
+ 	return deviceList;
+-	////
+-
+-	//return find_alsa_devices(1);
+ }
+ 
+ std::list<AudioDevice> AudioDeviceManager::getOutputDeviceList() {
+ 	RecursiveMutex::ScopedLock scopedLock(_mutex);
+ 
+-	//HACK: always return the default one + plughw
+-	std::list<AudioDevice> deviceList;
+-	deviceList.push_back(getDefaultOutputDevice());
+-
+-	StringList data;
+-	data += String("ALSA: plughw");
+-	data += String("plughw");
+-	data += EnumDeviceType::toString(EnumDeviceType::DeviceTypeWaveOut);
+-	deviceList.push_back(AudioDevice(data));
++	std::list<AudioDevice> deviceList = find_alsa_devices(0);
++	deviceList.push_front(getDefaultOutputDevice());
+ 
+ 	return deviceList;
+-	////
+-
+-	//return find_alsa_devices(0);
+ }
+ 
+ AudioDevice AudioDeviceManager::getDefaultOutputDevice() {
+@@ -165,8 +145,16 @@
+ 			int has_playback = 0;
+ 
+ 			// compute internal device name
+-			snprintf(alsa_device_name, sizeof(alsa_device_name), "%s:%d,%d", "hw",
+-			card_index, device_index);
++			if (input)
++			{
++				snprintf(alsa_device_name, sizeof(alsa_device_name), "%s:%d,%d",
++					"plughw", card_index, device_index);
++			}
++			else
++			{
++				snprintf(alsa_device_name, sizeof(alsa_device_name), "%s:%d",
++					"plug:dmix", card_index);
++			}
+ 			LOG_DEBUG("alsa_device_name: " + String(alsa_device_name));
+ 			////
+ 
--- wengophone-2.1.2.dfsg0.orig/debian/patches/head/qt-fix-bad-window-size.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/head/qt-fix-bad-window-size.patch
@@ -0,0 +1,23 @@
+Index: wengophone-2.2/wengophone/src/presentation/qt/QtWengoStyle.h
+===================================================================
+--- wengophone-2.2/wengophone/src/presentation/qt/QtWengoStyle.h (revision 12904)
++++ wengophone-2.2/wengophone/src/presentation/qt/QtWengoStyle.h (revision 13153)
+@@ -25,8 +25,8 @@
+ #ifdef OS_MACOSX
+ 	#include <QtGui/QMacStyle>
+-	class SystemStyle : public QMacStyle { };
++	typedef QMacStyle BaseStyle;
+ #else
+-	#include <QtGui/QStyle>
+-	class SystemStyle : public QStyle { };
++	#include <QtGui/QCommonStyle>
++	typedef QCommonStyle BaseStyle;
+ #endif
+ 
+@@ -40,5 +40,5 @@
+  * @author Tanguy Krotoff
+  */
+-class QtWengoStyle : public SystemStyle {
++class QtWengoStyle : public BaseStyle {
+ public:
+ 
--- wengophone-2.1.2.dfsg0.orig/debian/patches/head/phapi-alsa-code-from-2.2.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/head/phapi-alsa-code-from-2.2.patch
@@ -0,0 +1,1722 @@
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phmedia-alsa.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phmedia-alsa.c	2008-03-23 23:32:51.000000000 +0100
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phmedia-alsa.c	2008-03-23 23:34:52.000000000 +0100
+@@ -1,5 +1,4 @@
+-/*
+- * The phmedia-alsa  module implements interface to ALSA audio devices for phapi
++/* -*- Mode: C; tab-width:8; c-basic-offset:8; -*-
+  *
+  * Copyright (C) 2004  Vadim Lebedev  <vadim@mbdsys.com>
+  * Copyright (C) 2006-2007 WENGO SAS
+@@ -15,586 +14,1200 @@
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public
+- * License along with dpkg; if not, write to the Free Software
++ * License along with wengophone; if not, write to the Free Software
+  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++ *
++ *  2008-03-23 Ludovico Cavedon <cavedon@sssup.it>
++ *     - removed owpl logging code backporting it to branch 2.1
++ *
++ *  2007-09-27 Alec Leamas  <nospam>
++ *     - Documentation added
++ *     - Hardware buffer limited to 3 periods
++ *     - Support for silence_threshold and silence_size added (not used).
++ *     - Now uses implicit (start_threshold) start instead of explicit.
++ *     - Changed threading model, now uses internal threads.
++ *     - Added handling of stereo devices which can't be opened in mono.
++ *     - Added rebuffering support in playback_thread().
++ *     - Fixed bug in snd_pcm_open, which was done in blocking mode
++ *       (potential hang if device can't be opened).
++ *     - Refactored alsa_dev_open fixed memory leaks.
++ *     - Added function prototypes to avoid compiler warnings.
++ *     - Removed DBG_DYNA_DRV references, uses std owplDebug calls instead.
++ *     - Added statistics support.
++ *     - Made lot's of literals to symbolic constants.
++ *
++ *  BUGS
++ *     - Since the device is held open by this driver, playing sounds
++ *       through alsa_sndfile.cpp does not work on physical alsa devices.
++ *     - Marked as FIXME  here and there...
+  */
+ 
+-/** @see http://www.linuxjournal.com/article/6735 for an introduction to ALSA */
++/**
++ *
++ * @file phmedia-alsa.c
++ *
++ * The phmedia-alsa  module implements interface to ALSA devices for phapi
++ *
++ * @see http://www.linuxjournal.com/article/6735 for an introduction to ALSA
++ * @see http://dev.openwengo.com/trac/openwengo/trac.fcgi/wiki/PhApiAudio [PHAPI]
++ * @see http://www.alsa-project.org/  [ALSA]
++ *
++ * The data transferred to/from the ALSA driver is organized in three levels:
++ *
++ * - The first level is the samplesize, the size of each sample. [PHAPI]
++ *   defines each sample as a 16-bit, signed and little endian entity.
++ *
++ * - [ALSA] defines the frame, which is defined as a sample from each channel.
++ *   Thus, in mono mode framesize == samplesize, in stereo
++ *   framesize == 2 * samplesize.
++ *
++ * - Data is transferred to/from the driver in chunks, typically a 100-2000
++ *   bytes.  These chunks are described as 'frames' in [PHAPI] and as
++ *   'periods' in [ALSA].  For now, these  chunks are  mono streams of
++ *   samples.
++ *
++ *  [ALSA] defines the basic setup parameters:
++ *  - The size of the hardware ring buffer. This is tradeoff between not
++ *    not losing packets, and packets becoming to old to be
++ *    usable in an oversized buffer.
++ *  - The 'period' size, effectively the same as a 'chunk'.
++ *  - The relations between audio format, channels and framesize.
++ *  - The start threshold - a stream starts if the amount of buffered
++ *    (output) or requested(input) data is equal to or exceeds this value.
++ *    This drivers setup starts streams in this way.
++ *  - The silence threshold and silence length: See ::SILENCE_THRESHOLD
++ *
++ *  The fundamental requirement for the flow comes from the codecs, which emits
++ *  and requires data at a specific rate. Wengophone's codecs has a sampling
++ *  rate of 16 000 frames per second. This requirement is embodied in the
++ *  parameters chunk_size and sample_rate to the open() function.
++ *
++ *  Basic dependencies, with some real example data (see [ALSA], API
++ *  reference, PCM section)
++ *  - Sample rate = 16000 samples/sec.
++ *  - Time for 1 sample = 1/rate s = 1000/rate ms:  1000/16000 ms.
++ *  - Chunk(bytes, mono) = 640 bytes
++ *  - Chunk(bytes, stereo) = 1280 bytes
++ *  - Chunk(frames) = chunk(bytes)/sample_size/channels: 1280/2/2 = 320
++ *  - Period size(frames) = 1 chunk = 320 frames.
++ *  - Period time = chunk(frames)/sample rate: 320/16000 = 20 ms
++ *  - Buffer size = periods per buffer * period size: 3 * 320  = 960 frames
++ *  - Buffer time = buffer size(frames)/sample rate: 960/16000 = 60 ms
++ *
++ *  Debugging tip: <i>cat /proc/asound/card0/pcm0p/sub0/hw_params</i>,
++ *  <i>cat /proc/asound/card0/pcm0c/sub0/sw_params</i>. I bet your
++ *  filenames are different.
++ *
++ */
++
++//FIXME: split in header  + implementation file.
+ 
+ #ifdef ENABLE_ALSA
+ 
+ #define ALSA_PCM_NEW_HW_PARAMS_API
++#include <sys/time.h>
+ #include <alsa/asoundlib.h>
++#include <fcntl.h>
++#include <libgen.h>
++#include <pthread.h>
+ 
+ #include "phapi.h"
+ #include "phastream.h"
+ #include "phaudiodriver.h"
+ #include "phlog.h"
+ 
+-struct alsa_dev {
+-  snd_pcm_t *ain, *aout;
+-};
++/** Preferred # channels (1-2). Wengophone always uses mono internally. */
++const int DEFAULT_CHANNELS   = 1;
++
++/** Size of hw buffer (periods). */
++const unsigned  BUFFER_PERIODS  = 3;
++
++/**
++ *
++ * Iff I've understood this right: When the number of outgoing,
++ * buffered frames drops below this value, SILENZE_SIZE number
++ * of silence frames is added to the output - all this to make the
++ * expected underrun less noisy.
++ *
++ * SILENZE_SIZE should be <= SILENCE_THRESHOLD,
++ * or >= boundary (INT_MAX works fine). The latter case fills the
++ * buffer with silence.
++ *
++ * Beware: The [ALSA] docs for this are horrible, and I might have got
++ * all this wrong.
++ *
++ * Using internal threads and rebuffering support, this is not used.
++ *
++ * @see [ALSA], set_silence_threshold().
++ *
++ */
++const snd_pcm_uframes_t   SILENCE_THRESHOLD = 0;
++
++/** Time (ms) we wait for a device in snd_pcm_wait(). */
++const unsigned            SND_PCM_WAIT_MS   = 500;
++
++/** @see SILENCE_THRESHOLD. */
++const snd_pcm_uframes_t   SILENCE_SIZE      = 0;
++
++/** Used format. */
++const snd_pcm_format_t    PCM_FORMAT        = SND_PCM_FORMAT_S16_LE;
++
++/** Suppress ALSA diagnostics on stdout/stderr (0/1). */
++const int                 ALSA_SILENT       = 1;
++
++#define   OUTPUT_LATENCY         100  /**< Buffering before stream start
++					   as percent of a period.   */
++#define   INPUT_LATENCY          50   /**< Min size of requested data
++					   which starts stream.    */
++
++#define   MONO_AVERAGE           1    /**< stereo2mono takes the average
++					 of the two stereo channels. */
++
++#define   PH_TRUE                1
++#define   PH_FALSE               0
++typedef   short                  ph_bool;
++
++/** Returns the alsa_drv_info* ptr stored as drvinfo in phastream_t. */
++#define   DRV_INFO(x) ((alsa_drv_info *)((x)->drvinfo))
+ 
+-#define ADEV(x) ((struct alsa_dev *)((x)->drvinfo))
++/** Kludge to fix incompatibility between gcc 4.2 and alsa. */
++#define GCC_VERSION (__GNUC__ * 10    + __GNUC_MINOR__  )
+ 
+-void alsa_stream_start(phastream_t *as);
+-int  alsa_stream_open(phastream_t *as, char *name, int rate, int framesize, ph_audio_cbk cbk);
+-int  alsa_stream_write(phastream_t *as, void *buf,  int len);
+-int  alsa_stream_read(phastream_t *as, void *buf,  int len);
+-int  alsa_stream_get_out_space(phastream_t *as, int *used);
+-int  alsa_stream_get_avail_data(phastream_t *as);
+-void alsa_stream_close(phastream_t *as);
+-int  alsa_stream_get_fds(phastream_t *as, int fds[2]);
++#if GCC_VERSION > 41
+ 
++#undef snd_pcm_sw_params_alloca
++#define snd_pcm_sw_params_alloca(ptr) \
++do { \
++    *ptr = (snd_pcm_sw_params_t*) alloca(snd_pcm_sw_params_sizeof()); \
++    memset(*ptr, 0, snd_pcm_sw_params_sizeof()); \
++} while (0)
++
++#undef snd_pcm_hw_params_alloca
++#define snd_pcm_hw_params_alloca(ptr) \
++do { \
++    *ptr = (snd_pcm_hw_params_t*) alloca(snd_pcm_hw_params_sizeof()); \
++    memset(*ptr, 0, snd_pcm_hw_params_sizeof()); \
++} while (0)
++
++#undef snd_pcm_status_alloca
++#define snd_pcm_status_alloca(ptr) \
++do  { \
++    *ptr = (snd_pcm_status_t *) alloca(snd_pcm_status_sizeof()); \
++    memset(*ptr, 0, snd_pcm_status_sizeof()); \
++} while (0)
++
++#endif  //GCC_VERSION
++
++
++/**
++ * @name Driver entry points
++ *
++ * @{
++ *
++ */
++
++/**
++ *
++ * Implements ::ph_audio_open.
++ *
++ * @BUG  No check if ain/aout has same channel count
++ *
++ */
++static int alsa_stream_open(phastream_t* as,
++			    const char* name,
++			    int wished_rate,
++			    int chunk_size,
++			    ph_audio_cbk cbk);
++
++/**
++ * Implements ::ph_audio_close
++ */
++static void alsa_stream_close(phastream_t *as);
++
++/**
++ * Implements ::ph_audio_start
++ */
++static void alsa_stream_start(phastream_t *as);
++
++/**
++ * Implements ::ph_audio_write
++ *
++ *  Timing: On a AMD X2 4200+ each invocation is about 150 us.
++ *
++*/
++static int alsa_stream_write(phastream_t *as, void *buf,  int len);
++
++/**
++ * Implements ::ph_audio_read
++ */
++static int alsa_stream_read(phastream_t *as, void *buf,  int len);
++
++/**
++ * Implements ::ph_audio_get_avail_data
++ */
++static int alsa_stream_get_avail_data(phastream_t *as);
++
++/**
++ * Implements ::ph_audio_get_out_space.
++ */
++static int alsa_stream_get_out_space(phastream_t *as, int *used);
++
++/**
++ * Implements ::ph_audio_get_fds
++ */
++static int alsa_stream_get_fds(phastream_t *as, int fds[2]);
++/** Register the driver. */
+ void ph_alsa_driver_init(void);
+-snd_pcm_t *alsa_dev_open(char *name, int type, int wished_rate, int framesize, int latencymsecs, int *chosen_rate);
+-int alsa_dev_get_fd(snd_pcm_t *s);
+-int suspend(snd_pcm_t *handle);
+ 
++/*@}*/
++
++
++/** Description of one device (input or output). */
++struct _alsa_dev {
++		snd_pcm_t*     pcm;
++		char*          id;           /**< id string e g "input".  */
++		unsigned long  bytes;        /**< # bytes read/written.   */
++		unsigned long  rebuffered;   /**< Resent (no input) bytes.*/
++		unsigned       soft_errors;  /**< recoverable errors.     */
++		unsigned       again_errors; /**< EAGAIN soft error.      */
++		unsigned       hard_errors;  /**< Non-recoverable errors. */
++		pthread_t      thread;       /**< Thread in async mode.   */
++		unsigned       stop_thread;  /**< Initially 0, set to 1   */
++		                             /**  of main thread to stop  */
++		                             /**  child, set to 2 by      */
++		                             /**  child when child exits. */
++};
++
++typedef struct _alsa_dev alsa_dev;
++
++/** The driver info kept in the phastream->drv_info. */
++struct _alsa_drv_info {
++		alsa_dev  input;
++		alsa_dev  output;
++		unsigned  channels;         /**< Mono/stereo (1, 2).      */
++		unsigned  sample_size;      /**< In bytes, 1.\ .\ 8.      */
++		size_t    chunk_size;       /**< As to alsa_stream_open().*/
++		ph_audio_cbk  callback;     /**< Invoked by threads.      */
++};
++
++typedef struct _alsa_drv_info alsa_drv_info;
++
++/** Argument when opening device. */
++struct _pcm_data {
++		snd_pcm_t* device;
++		unsigned channels;
++                unsigned rate;
++                ssize_t  chunk_size;  /**< # bytes (sic!) in each transfer. */
++		unsigned  threshold;
++                                      /**< Delay before stream starts(frames)*/
++                unsigned buffer_periods; /**< Size of hw buffer, in periods. */
++		unsigned silence_threshold;
++	        unsigned silence_size;
++};
++
++typedef struct _pcm_data pcm_data;
++
++/**
++ * The driver info registered by init()
++ */
+ struct ph_audio_driver ph_alsa_driver = {
+-  "alsa",
+-  PH_SNDDRVR_FDS,
+-  0,
+-  alsa_stream_start,
+-  alsa_stream_open,
+-  alsa_stream_write,
+-  alsa_stream_read,
+-  alsa_stream_get_out_space,
+-  alsa_stream_get_avail_data,
+-  alsa_stream_close,
+-  alsa_stream_get_fds,
+-  NULL
++	"alsa",
++	PH_SNDDRVR_PLAY_CALLBACK | PH_SNDDRVR_REC_CALLBACK,
++	0,
++	alsa_stream_start,
++	alsa_stream_open,
++	alsa_stream_write,
++	alsa_stream_read,
++	alsa_stream_get_out_space,
++	alsa_stream_get_avail_data,
++	alsa_stream_close,
++	alsa_stream_get_fds,
++	NULL
+ };
+ 
+-void ph_alsa_driver_init(void)
+-{
+-  ph_register_audio_driver(&ph_alsa_driver);
++/**
++ * nanosleep(2) arg to relinquish CPU while waiting for IO, 5 ms.
++ */
++const struct timespec io_wait = { 0, 5 * 1000000 };
++
++/** Dump lot's of information about a pcm device. */
++static void dump_pcm_data( snd_pcm_t* handle, snd_pcm_hw_params_t *params);
++
++/**
++ * Open an ALSA device for input or output
++ *
++ * @param handle On exit, handle to device in state SND_PCM_STATE_OPEN.
++ *
++ * @param name Name of device. Might be the plain device name, or environment
++ *        setting on the form "alsa:IN=inputdev OUT=outputdev".
++ * @param type indicates a playback or a recorder device.
++ *
++ * @return 0 on success, else ALSA error code.
++ *
++ */
++static int open_device( snd_pcm_t**      handle,
++			const char*      name,
++			snd_pcm_format_t type);
++
++/**
++ *
++ * Open and setup an ALSA device for input or output.
++ *
++ * @param name Plain ALSA device name e g "hw:0,0" or a string as present
++ * in environment e g "alsa:IN=hw:0,0 OUT=hw:1,0".
++ * @param pcm Device and device data. On successful exit, pcm->pcm is
++ * in state SND_PCM_STATE_PREPARE.
++ *
++ * @return 0 on success, else negative alsa error code.
++ *
++ */
++static int alsa_dev_open( const char*      name,
++			  snd_pcm_stream_t type,
++			  pcm_data*        pcm);
++
++/** Return size of hw buffer, in frames.  */
++static snd_pcm_uframes_t
++pcm_data_get_buffer_size( snd_pcm_hw_params_t* params, pcm_data* pcm);
++
++/** Return size of one period, in frames. */
++
++static snd_pcm_sframes_t
++pcm_data_get_period_size( snd_pcm_hw_params_t* params, pcm_data* pcm);
++
++/** Return size of input/output threshold, in frames. */
++static snd_pcm_uframes_t pcm_data_get_threshold( pcm_data* pcm );
++
++static snd_pcm_uframes_t pcm_data_get_silence_threshold( pcm_data* pcm);
++
++static snd_pcm_uframes_t pcm_data_get_silence_size( pcm_data* pcm);
++
++/** printf-style sibling to LOG_ERROR. */
++#define ALSA_ERROR DBG_DYNA_AUDIO_DRV
++
++#define ALSA_DEBUG DBG_DYNA_AUDIO_DRV
++
++/** Non-blocking handling of ALSA error code, reset dev as required. */
++static void ph_handle_pcm_error( alsa_dev* device, int err );
++
++static snd_pcm_uframes_t
++wp_bytes_to_frames( snd_pcm_hw_params_t* params, size_t bytes);
++
++/** Set hw parameters for an alsa device. */
++static int set_hw_params( snd_pcm_stream_t     type,
++			  pcm_data*            pcm,
++			  snd_pcm_hw_params_t* hw_params);
++
++/** Set sw parameters for an alsa device. */
++static int set_sw_params( snd_pcm_stream_t     type,
++			  pcm_data*            pcm,
++			  snd_pcm_hw_params_t* hw_params );
++
++/**
++ * Initiate a new pcm_data instance.
++ *
++ * @see snd_pcm_sw_params_set_start_threshold.
++ * @param pcm Filled with data on exit.
++ * @param rate Sample rate (frames/sec).
++ * @param chunk_size Size of blocks read or written (bytes).
++ * @param latency Start threshold value as percent of a period.
++ */
++static void pcm_data_new( pcm_data* pcm,
++			  unsigned  rate,
++			  unsigned  chunk_size,
++			  unsigned  latency);
++
++/**
++ * Create a stereo buffer from a mono source.
++ *
++ * @param dest   The destination stereo buffer, 2 * size big.
++ * @param src    The source mono buffer
++ * @param size   Size of source mono buffer (bytes).
++ * @param sample_size Size in bytes of each sample 1.\ .\ 8
++ *
++ */
++static  void mono2stereo( char*    dest,
++			  char*    src,
++			  size_t   size,
++			  size_t   sample_size);
++
++/**
++ *
++ * Read data from ALSA, support for alsa_stream_read.
++ *
++ * @param stream Data source (mic).
++ * @param buf    Buffer for data, stereo or mono as required.
++ * @param len    Buffer length = requested read size (bytes).
++ * @return       # bytes read, <= len.
++ *
++ */
++static int stream_read( alsa_dev* input, void* buff, int len);
++
++/**
++ *
++ * Write data to ALSA, support for alsa_stream_write.
++ *
++ * @param output Where to send data.
++ * @param buff Stereo or mono data.
++ * @len   length of buff (bytes).
++ * @return #  bytes written.
++ *
++ */
++static int stream_write( alsa_dev* output, void *buf, int len);
++
++/**
++ *
++ * Create a mono buffer from a stereo source.
++ *
++ * @param src    The stereo input buffer with signed 16-bit samples.
++ * @param dest   The mono destination buffer.
++ * @param size   Size of source stereo buffer (bytes).
++ * @param sample_size Size in bytes of each sample 1.\ .\ 8.
++ * @return       Size of returned mono buffer (i e, size / 2 ).
++ *
++ */
++static size_t  stereo2mono( char*       dest,
++			    char*       src,
++			    size_t      size,
++			    size_t      sample_size);
++
++/** Shuffles data from ALSA to phapi. */
++static void* recorder_thread( void* arg) ;
++
++/** Shuffles data from phapi to ALSA. */
++static void* playback_thread( void* arg);
++
++static void dump_pcm_data( snd_pcm_t*          handle,
++			   snd_pcm_hw_params_t *params) {
++
++	int dir;
++	unsigned int val2;
++	unsigned int val;
++	snd_pcm_access_t access;
++	snd_pcm_subformat_t format;
++	snd_pcm_uframes_t uframe;
++	snd_pcm_uframes_t frames;
++
++	/* Display information about the PCM interface */
++	ALSA_DEBUG("PCM handle name = '%s'", snd_pcm_name(handle));
++	ALSA_DEBUG("PCM state = %s",
++			   snd_pcm_state_name(snd_pcm_state(handle)));
++	snd_pcm_hw_params_get_access(params, &access);
++	ALSA_DEBUG("access type = %s", snd_pcm_access_name(access));
++	snd_pcm_hw_params_get_format(params, &dir);
++	ALSA_DEBUG("format = '%s' (%s)",
++			   snd_pcm_format_name((snd_pcm_format_t)dir),
++			   snd_pcm_format_description((snd_pcm_format_t)dir));
++	snd_pcm_hw_params_get_subformat(params, &format);
++	ALSA_DEBUG("subformat = '%s' (%s)",
++			   snd_pcm_subformat_name(format),
++			   snd_pcm_subformat_description(format));
++	snd_pcm_hw_params_get_channels(params, &val);
++	ALSA_DEBUG("channels = %d", val);
++	snd_pcm_hw_params_get_rate(params, &val, &dir);
++	ALSA_DEBUG("rate = %d bps", val);
++	snd_pcm_hw_params_get_period_time(params, &val, &dir);
++	ALSA_DEBUG("period time = %d us", val);
++	snd_pcm_hw_params_get_period_size(params, &frames, &dir);
++	ALSA_DEBUG("period size = %d frames", (int)frames);
++	snd_pcm_hw_params_get_buffer_time(params, &val, &dir);
++	ALSA_DEBUG("buffer time = %d us", val);
++	snd_pcm_hw_params_get_buffer_size(params, &uframe);
++	ALSA_DEBUG("buffer size = %d frames", (int)uframe);
++	snd_pcm_hw_params_get_periods(params, &val, &dir);
++	ALSA_DEBUG("periods per buffer = %d frames", val);
++	snd_pcm_hw_params_get_rate_numden(params, &val, &val2);
++	ALSA_DEBUG("exact rate = %d/%d bps", val, val2);
++	val = snd_pcm_hw_params_get_sbits(params);
++	ALSA_DEBUG("significant bits = %d", val);
++	snd_pcm_hw_params_get_tick_time(params, &val, &dir);
++	ALSA_DEBUG("tick time = %d us", val);
++	val = snd_pcm_hw_params_is_batch(params);
++	ALSA_DEBUG("is batch = %d", val);
++	val = snd_pcm_hw_params_is_block_transfer(params);
++	ALSA_DEBUG("is block transfer = %d", val);
++	val = snd_pcm_hw_params_is_double(params);
++	ALSA_DEBUG("is double = %d", val);
++	val = snd_pcm_hw_params_is_half_duplex(params);
++	ALSA_DEBUG("is half duplex = %d", val);
++	val = snd_pcm_hw_params_is_joint_duplex(params);
++	ALSA_DEBUG("is joint duplex = %d", val);
++	val = snd_pcm_hw_params_can_overrange(params);
++	ALSA_DEBUG("can overrange = %d", val);
++	val = snd_pcm_hw_params_can_mmap_sample_resolution(params);
++	ALSA_DEBUG("can mmap = %d", val);
++	val = snd_pcm_hw_params_can_pause(params);
++	ALSA_DEBUG("can pause = %d", val);
++	val = snd_pcm_hw_params_can_resume(params);
++	ALSA_DEBUG("can resume = %d", val);
++	val = snd_pcm_hw_params_can_sync_start(params);
++	ALSA_DEBUG("can sync start = %d", val);
+ }
+ 
+-snd_pcm_t *alsa_dev_open(char *name, int type, int wished_rate, int framesize, int latencymsecs, int *chosen_rate)
+-{
+-  snd_pcm_t *handle;
+-  snd_pcm_hw_params_t *params;
+-  snd_pcm_sw_params_t *sparams;
+-  unsigned int val;
+-  snd_pcm_uframes_t frames;
+-  int rc;
+-  char *nmend = 0;
+-  char *s = 0;
+-  *chosen_rate = 0;
+-
+-#if ACTIVATE_DYNA_AUDIO_DRV_DBG
+-  int dir;
+-  unsigned int val2;
+-  snd_pcm_access_t access;
+-  snd_pcm_subformat_t format;
+-  snd_pcm_uframes_t uframe;
+-#endif
++/** Register this driver. */
++void ph_alsa_driver_init( void) {
++	ph_register_audio_driver( &ph_alsa_driver);
++}
+ 
+-  if (name == NULL)
+-  {
+-    DBG_DYNA_AUDIO_DRV("alsa_dev_open: name == NULL!\n");
+-    return 0;
+-  }
+-
+-  if (!strncasecmp(name, "alsa:", 5))
+-  {
+-    name += 5;
+-  }
+-
+-  if (type == SND_PCM_STREAM_CAPTURE)
+-  {
+-    if ((s = strstr(name, "IN=")) != NULL)
+-    {
+-      nmend = strchr(name + 3, ' ');
+-      if (nmend)
+-      {
+-        *nmend = 0;
+-      }
+-      name = s + 3;
+-    }
+-  }
+-  else if (type == SND_PCM_STREAM_PLAYBACK)
+-  {
+-    if ((s = strstr(name, "OUT=")) != NULL)
+-    {
+-        nmend = strchr(name + 4, ' ');
+-        if (nmend)
+-        {
+-          *nmend = 0;
+-        }
+-        name = s + 4;
+-    }
+-  }
+-
+-  if (type == SND_PCM_STREAM_PLAYBACK)
+-  {
+-    DBG_DYNA_AUDIO_DRV("alsa_dev_open: SND_PCM_STREAM_PLAYBACK (name: %s, rate: %d, framesize: %d)\n", name, wished_rate, framesize);
+-  }
+-  else if (type == SND_PCM_STREAM_CAPTURE)
+-  {
+-    DBG_DYNA_AUDIO_DRV("alsa_dev_open: SND_PCM_STREAM_CAPTURE (name: %s, rate: %d, framesize: %d)\n", name, wished_rate, framesize);
+-  }
+-
+-  /* Open PCM device */
+-  rc = snd_pcm_open(&handle, name, type, 0);
+-
+-  /* restore the overwritten space */
+-  if (nmend)
+-  {
+-    *nmend = ' ';
+-  }
+-
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("failed to open pcm device: %s\n", snd_strerror(rc));
+-    return 0;
+-  }
+-  else
+-  {
+-    DBG_DYNA_AUDIO_DRV("open pcm device: succes\n");
+-  }
+-
+-  /* Allocate a hardware parameters object. */
+-  rc = snd_pcm_hw_params_malloc(&params);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("cannot allocate hardware parameter structure: %s\n", snd_strerror(rc));
+-    return 0;
+-  }
+-
+-  /* Fill it in with default values. */
+-  snd_pcm_hw_params_any(handle, params);
+-
+-  /* Set the desired hardware parameters. */
+-  /* One channel (mono) */
+-  rc = snd_pcm_hw_params_set_channels(handle, params, 1);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set hw parameters(channels=1): %s\n", snd_strerror(rc));
+-    /* two channel (stereo) */
+-#if 0
+-    rc = snd_pcm_hw_params_set_channels(handle, params, 2);
+-    if (rc < 0)
+-    {
+-      DBG_DYNA_AUDIO_DRV("unable to set hw parameters(channels=2): %s\n", snd_strerror(rc));
+-      goto err;
+-    }
+-#else
+-    goto err;
+-#endif
+-  }
++static void pcm_data_new( pcm_data* pcm,
++			  unsigned rate,
++			  unsigned chunk_size,
++			  unsigned latency) {
++
++	memset( pcm, 0, sizeof( pcm_data));
++	pcm->channels = DEFAULT_CHANNELS;
++	pcm->rate = rate;
++	pcm->threshold = latency;
++        pcm->chunk_size = chunk_size;
++	pcm->buffer_periods = BUFFER_PERIODS;
++	pcm->silence_threshold = SILENCE_THRESHOLD;
++	pcm->silence_size = SILENCE_SIZE;
++}
+ 
+-  /* Interleaved mode */
+-  rc = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set hw parameters(SND_PCM_ACCESS_RW_INTERLEAVED): %s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  /* Signed 16-bit little-endian format */
+-  rc = snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set hw parameters(SND_PCM_FORMAT_S16_LE): %s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  /* Set sampling rate */
+-  val = wished_rate;
+-  rc = snd_pcm_hw_params_set_rate_near(handle, params, &val, 0);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set hw parameters(rate=%d dir=%d): %s\n", val, dir, snd_strerror(rc));
+-    goto err;
+-  }
+-  *chosen_rate = val;
+-
+-  /* Set period size */
+-  frames = framesize;
+-  rc = snd_pcm_hw_params_set_period_size_near(handle, params, &frames, 0);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set hw parameters(period_size=%d): %s\n", (int) frames, snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  /* Write the parameters to the driver */
+-  rc = snd_pcm_hw_params(handle, params);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set hw parameters: %s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  /* Set the non-blocking mode */
+-  rc = snd_pcm_nonblock(handle, 1);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set noblocking mode:%s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-#if ACTIVATE_DYNA_AUDIO_DRV_DBG
+-  /* Display information about the PCM interface */
+-  DBG_DYNA_AUDIO_DRV("PCM handle name = '%s'\n", snd_pcm_name(handle));
+-  DBG_DYNA_AUDIO_DRV("PCM state = %s\n", snd_pcm_state_name(snd_pcm_state(handle)));
+-  snd_pcm_hw_params_get_access(params, &access);
+-  DBG_DYNA_AUDIO_DRV("access type = %s\n", snd_pcm_access_name(access));
+-  snd_pcm_hw_params_get_format(params, &dir);
+-  DBG_DYNA_AUDIO_DRV("format = '%s' (%s)\n", snd_pcm_format_name((snd_pcm_format_t)dir), snd_pcm_format_description((snd_pcm_format_t)dir));
+-  snd_pcm_hw_params_get_subformat(params, &format);
+-  DBG_DYNA_AUDIO_DRV("subformat = '%s' (%s)\n",
+-    snd_pcm_subformat_name(format),
+-    snd_pcm_subformat_description(format));
+-  snd_pcm_hw_params_get_channels(params, &val);
+-  DBG_DYNA_AUDIO_DRV("channels = %d\n", val);
+-  snd_pcm_hw_params_get_rate(params, &val, &dir);
+-  DBG_DYNA_AUDIO_DRV("rate = %d bps\n", val);
+-  snd_pcm_hw_params_get_period_time(params, &val, &dir);
+-  DBG_DYNA_AUDIO_DRV("period time = %d us\n", val);
+-  snd_pcm_hw_params_get_period_size(params, &frames, &dir);
+-  DBG_DYNA_AUDIO_DRV("period size = %d frames\n", (int)frames);
+-  snd_pcm_hw_params_get_buffer_time(params, &val, &dir);
+-  DBG_DYNA_AUDIO_DRV("buffer time = %d us\n", val);
+-  snd_pcm_hw_params_get_buffer_size(params, &uframe);
+-  DBG_DYNA_AUDIO_DRV("buffer size = %d frames\n", (int)uframe);
+-  snd_pcm_hw_params_get_periods(params, &val, &dir);
+-  DBG_DYNA_AUDIO_DRV("periods per buffer = %d frames\n", val);
+-  snd_pcm_hw_params_get_rate_numden(params, &val, &val2);
+-  DBG_DYNA_AUDIO_DRV("exact rate = %d/%d bps\n", val, val2);
+-  val = snd_pcm_hw_params_get_sbits(params);
+-  DBG_DYNA_AUDIO_DRV("significant bits = %d\n", val);
+-  snd_pcm_hw_params_get_tick_time(params, &val, &dir);
+-  DBG_DYNA_AUDIO_DRV("tick time = %d us\n", val);
+-  val = snd_pcm_hw_params_is_batch(params);
+-  DBG_DYNA_AUDIO_DRV("is batch = %d\n", val);
+-  val = snd_pcm_hw_params_is_block_transfer(params);
+-  DBG_DYNA_AUDIO_DRV("is block transfer = %d\n", val);
+-  val = snd_pcm_hw_params_is_double(params);
+-  DBG_DYNA_AUDIO_DRV("is double = %d\n", val);
+-  val = snd_pcm_hw_params_is_half_duplex(params);
+-  DBG_DYNA_AUDIO_DRV("is half duplex = %d\n", val);
+-  val = snd_pcm_hw_params_is_joint_duplex(params);
+-  DBG_DYNA_AUDIO_DRV("is joint duplex = %d\n", val);
+-  val = snd_pcm_hw_params_can_overrange(params);
+-  DBG_DYNA_AUDIO_DRV("can overrange = %d\n", val);
+-  val = snd_pcm_hw_params_can_mmap_sample_resolution(params);
+-  DBG_DYNA_AUDIO_DRV("can mmap = %d\n", val);
+-  val = snd_pcm_hw_params_can_pause(params);
+-  DBG_DYNA_AUDIO_DRV("can pause = %d\n", val);
+-  val = snd_pcm_hw_params_can_resume(params);
+-  DBG_DYNA_AUDIO_DRV("can resume = %d\n", val);
+-  val = snd_pcm_hw_params_can_sync_start(params);
+-  DBG_DYNA_AUDIO_DRV("can sync start = %d\n", val);
+-#endif
++static snd_pcm_sframes_t
++pcm_data_get_period_size( snd_pcm_hw_params_t* params, pcm_data* pcm) {
+ 
+-  if (!latencymsecs)
+-  {
+-    snd_pcm_hw_params_free(params);
+-    return handle;
+-  }
+-
+-  snd_pcm_sw_params_alloca(&sparams);
+-
+-  /* retrieve the parameters from the driver */
+-  rc = snd_pcm_sw_params_current(handle, sparams);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to get sw parameters: %s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  frames = (*chosen_rate) / 1000 * latencymsecs;
+-  rc = snd_pcm_sw_params_set_start_threshold(handle, sparams, frames);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set start threshold: %s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  /* Write the parameters to the driver */
+-  rc = snd_pcm_sw_params(handle, sparams);
+-  if (rc < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV("unable to set sw parameters: %s\n", snd_strerror(rc));
+-    goto err;
+-  }
+-
+-  snd_pcm_hw_params_free(params);
+-  //snd_pcm_sw_params_free(sparams);
+-  return handle;
+-
+-err:
+-  snd_pcm_hw_params_free(params);
+-  //snd_pcm_sw_params_free(sparams);
+-  snd_pcm_close(handle);
+-  return 0;
++	return wp_bytes_to_frames( params, pcm->chunk_size);
+ }
+ 
+-int alsa_dev_get_fd(snd_pcm_t *s)
+-{
+-  int err;
+-  struct pollfd ufd;
++static snd_pcm_uframes_t
++pcm_data_get_buffer_size( snd_pcm_hw_params_t* params, pcm_data* pcm) {
+ 
+-  if ((err = snd_pcm_poll_descriptors(s, &ufd, 1)) < 0)
+-  {
+-    DBG_DYNA_AUDIO_DRV( "Unable to obtain poll descriptors for device: %s\n", snd_strerror(err));
+-    return -1;
+-  }
++	return  pcm_data_get_period_size( params, pcm) * pcm->buffer_periods;
++}
+ 
+-  return ufd.fd;
++static snd_pcm_uframes_t pcm_data_get_threshold( pcm_data* pcm){
++
++        snd_pcm_uframes_t period =
++		snd_pcm_bytes_to_frames( pcm->device, pcm->chunk_size);
++	return ( pcm->threshold * period) / 100;
+ }
+ 
+-int alsa_stream_open(phastream_t *as, char *name, int wished_rate, int framesize, ph_audio_cbk cbk)
+-{
+-  struct alsa_dev *ad = 0;
+-  int mic_chosen_rate = 0;
+-  int spk_chosen_rate = 0;
+-
+-  DBG_DYNA_AUDIO_DRV("alsa_stream_open: (name: %s, rate: %d, framesize: %d)\n", name, wished_rate, framesize);
+-  ad = calloc(sizeof(*ad), 1);
+-  if (!ad)
+-  {
+-    return -PH_NORESOURCES;
+-  }
+-
+-  // 200ms may satisfied every sound card
+-  ad->aout = alsa_dev_open(name, SND_PCM_STREAM_PLAYBACK, wished_rate, framesize / 2, 200, &spk_chosen_rate);
+-  if (!ad->aout)
+-  {
+-    free(ad);
+-    return -PH_NORESOURCES;
+-  }
+-
+-  ad->ain = alsa_dev_open(name, SND_PCM_STREAM_CAPTURE, wished_rate, framesize / 2, 0, &mic_chosen_rate);
+-  if (!ad->ain)
+-  {
+-    // close the playback device if we fail to open capture device
+-    snd_pcm_close(ad->aout);
+-    free(ad);
+-    return -PH_NORESOURCES;
+-  }
+-
+-  // TODO: refactor the actual_rate across all phaudio_driver backends
+-  //       it should be an OUT parameter in the dev_open prototype
+-  // here, hopefully, both MIC and SPK devices have been opened with the same rate
+-  // we use only the MIC rate
+-  as->actual_rate = mic_chosen_rate;
+-  DBG_DYNA_AUDIO_DRV("alsa_stream_open: chosen rate (freq)=(%d)\n",
+-    as->actual_rate);
++static snd_pcm_uframes_t pcm_data_get_silence_size( pcm_data* pcm){
+ 
+-  as->drvinfo = ad;
+-  PH_SNDDRVR_USE();
++	return ( pcm->silence_size );
++}
++
++static snd_pcm_uframes_t pcm_data_get_silence_threshold( pcm_data* pcm){
+ 
+-  return 0;
++	return ( pcm->silence_threshold );
+ }
+ 
+-void alsa_stream_close(phastream_t *as)
+-{
+-  DBG_DYNA_AUDIO_DRV("alsa_stream_close\n");
+ 
+-  if (!as->drvinfo)
+-  {
+-    DBG_DYNA_AUDIO_DRV("alsa stream already closed\n");
+-    return;
+-  }
++static int open_device( snd_pcm_t** handle,
++			const char* name,
++			snd_pcm_format_t type) {
++
++        const ph_bool   input   = ( type == SND_PCM_STREAM_CAPTURE);
++        const char*     keyword = ( input ? "in" : "out");
++
++	char       string[128];
++	char*      strtok_ptr;
++	char*      device = NULL;
++	int        rc;
++
++	if ( name == NULL) {
++		ALSA_ERROR( "alsa_dev_open: name == NULL!");
++		return -1;
++	}
++	strncpy( string, name, sizeof( string));
++        device = strtok_r( string, ":", &strtok_ptr);
++        if( strcasecmp( device, "alsa") == 0) {
++		while( strcasecmp( device, keyword) != 0 && device != NULL) {
++			device = strtok_r( NULL, " =", &strtok_ptr);
++		}
++		if( device != NULL) {
++			device = strtok_r( NULL, " =", &strtok_ptr);
++		}
++		if( device == NULL) {
++			ALSA_ERROR( "Illegal device string: %s", name);
++			return -1;
++		}
++	}
++
++	rc = snd_pcm_open( handle, device, type, SND_PCM_NONBLOCK);
++	if (rc < 0){
++		ALSA_ERROR( "Cannot open pcm device %s: %s",
++			    name, snd_strerror( rc));
++		return rc;
++	}
++	ALSA_DEBUG( "open pcm device %s for %s: OK",
++		    name, input ? "input" : "output");
++	return 0;
++}
+ 
+-  snd_pcm_drop(ADEV(as)->ain);
+-  snd_pcm_drop(ADEV(as)->aout);
+-  snd_pcm_close(ADEV(as)->ain);
+-  snd_pcm_close(ADEV(as)->aout);
++static int set_hw_params( snd_pcm_stream_t     type,
++			  pcm_data*            pcm,
++			  snd_pcm_hw_params_t* params) {
++
++        snd_pcm_uframes_t   frames;
++	int                 rc;
++
++	/* Fill it in with default values. */
++	snd_pcm_hw_params_any( pcm->device, params);
++
++	/* Set the desired hardware parameters. */
++	rc = snd_pcm_hw_params_set_channels_near( pcm->device,
++						  params,
++						  &pcm->channels);
++	if ( rc < 0) {
++		ALSA_ERROR("Unable to set hw parameters(channel): %s",
++			   snd_strerror( rc));
++		return( rc );
++	}
++
++        if( pcm->channels == 2) {
++		// We will expand the mono chunk to a stereo chunk.
++		pcm->chunk_size *= 2;
++	}
++
++	rc = snd_pcm_hw_params_set_access( pcm->device,
++					   params,
++					   SND_PCM_ACCESS_RW_INTERLEAVED);
++	if( rc < 0) {
++		ALSA_ERROR(
++			"Set access SND_PCM_ACCESS_RW_INTERLEAVED: %s",
++			snd_strerror(rc));
++		return( rc );
++	}
++
++	/* Signed 16-bit little-endian format. */
++	rc = snd_pcm_hw_params_set_format( pcm->device,
++					   params,
++					   PCM_FORMAT);
++	if ( rc < 0) {
++		ALSA_ERROR( "Unable to set format %s: %s",
++			    "SND_PCM_FORMAT_S16_LE",
++			    snd_strerror( rc));
++		return( rc );
++	}
++	rc = snd_pcm_hw_params_set_rate_near( pcm->device,
++					      params,
++					      &pcm->rate,
++					      0);
++	if ( rc < 0) {
++		ALSA_ERROR( "Unable to set hw parameters: %s",
++			    snd_strerror( rc));
++		return( rc );
++	}
++
++	frames = pcm_data_get_period_size( params, pcm);
++	rc = snd_pcm_hw_params_set_period_size_near( pcm->device,
++						     params,
++						     &frames,
++						     0);
++	if ( rc < 0) {
++		ALSA_ERROR(
++			"Unable to set hw params (period_size=%d): %s",
++			(int) frames, snd_strerror( rc));
++		return( rc );
++	}
++
++	frames = pcm_data_get_buffer_size( params, pcm);
++        rc = snd_pcm_hw_params_set_buffer_size_near( pcm->device,
++						     params,
++						     &frames);
++        if( rc < 0) {
++		ALSA_ERROR( "Unable to set hw buffer size: %s",
++			    snd_strerror( rc));
++		return( rc );
++	}
++	/* Write the parameters to the driver */
++	rc = snd_pcm_hw_params( pcm->device, params);
++	if ( rc < 0) {
++		ALSA_ERROR( "Unable to set hw params: %s",
++			    snd_strerror( rc));
++		return( rc );
++	}
+ 
+-  free(as->drvinfo);
+-  as->drvinfo = 0;
++	return( 0 );
+ 
+-  PH_SNDDRVR_UNUSE();
+ }
+ 
+-void alsa_stream_start(phastream_t *as)
++static int set_sw_params( snd_pcm_stream_t     type,
++			  pcm_data*            pcm,
++			  snd_pcm_hw_params_t* hw_params )
+ {
+-  snd_pcm_start(ADEV(as)->ain);
+-  snd_pcm_start(ADEV(as)->aout);
++	int                 rc;
++	snd_pcm_sw_params_t *sparams = 0;
++        snd_pcm_uframes_t   frames;
++
++	snd_pcm_sw_params_alloca( &sparams);
++
++	/* retrieve the parameters from the driver */
++	rc = snd_pcm_sw_params_current( pcm->device, sparams);
++	assert( rc == 0 );
++
++        frames = pcm_data_get_threshold( pcm);
++	rc = snd_pcm_sw_params_set_start_threshold( pcm->device,
++						    sparams,
++						    frames);
++	assert( rc == 0);
++
++	frames = pcm_data_get_period_size( hw_params, pcm);
++	rc = snd_pcm_sw_params_set_avail_min( pcm->device,
++					      sparams,
++					      frames);
++	assert( rc == 0);
++
++	if( type == SND_PCM_STREAM_PLAYBACK) {
++		frames = pcm_data_get_silence_threshold( pcm);
++		rc = snd_pcm_sw_params_set_silence_threshold( pcm->device,
++							      sparams,
++							      frames);
++		assert( rc == 0);
++
++		frames = pcm_data_get_silence_size( pcm);
++		rc = snd_pcm_sw_params_set_silence_size( pcm->device,
++							 sparams,
++							 frames);
++		assert( rc == 0);
++	}
++
++	/* Write the parameters to the driver */
++	rc = snd_pcm_sw_params( pcm->device, sparams);
++	if( rc < 0) {
++		ALSA_ERROR( "Unable to set sw parameters: %s",
++			    snd_strerror( rc));
++		return( rc);
++	}
++	return( 0);
++
+ }
+ 
+-int suspend(snd_pcm_t *handle)
+-{
+-  int res = 0;
++static snd_pcm_uframes_t
++wp_bytes_to_frames( snd_pcm_hw_params_t* params, size_t bytes) {
+ 
+-  // wait until suspend flag is released
+-  while ((res = snd_pcm_resume(handle)) == -EAGAIN)
+-  {
+-    sleep(1);
+-  }
+-  if (res < 0)
+-  {
+-    // failed to restart stream, let's try to repair
+-    DBG_DYNA_AUDIO_DRV("failed restarting stream: %s\n", snd_strerror(res));
+-    if ((res = snd_pcm_prepare(handle)) < 0)
+-    {
+-      DBG_DYNA_AUDIO_DRV("suspend error: %s\n", snd_strerror(res));
+-      return 1;
+-    }
+-  }
+-  return 0;
++	unsigned             channels;
++	int                  res;
++	snd_pcm_format_t     format;
++        int                  samplesize;
++
++        res = snd_pcm_hw_params_get_channels( params, &channels);
++	assert( res >= 0  && channels >= 1);
++	res = snd_pcm_hw_params_get_format( params, &format);
++	assert( res >= 0);
++	samplesize = snd_pcm_format_size( format, 1);
++	assert( samplesize > 0);
++	return bytes / (samplesize * channels);
+ }
+ 
+-int alsa_stream_write(phastream_t *as, void *buf,  int len)
+-{
+-  int res = 0;
+-  int total = 0;
++static int alsa_dev_open( const char*       name,
++			  snd_pcm_stream_t  type,
++			  pcm_data*         pcm) {
++
++	int                  rc;
++	snd_pcm_hw_params_t* hw_params;
++
++	snd_pcm_hw_params_alloca( &hw_params);
++
++	ALSA_DEBUG( "open_device:  %s (name: %s, rate: %d, chunk: %d)",
++		    type == SND_PCM_STREAM_CAPTURE ? "input" : "output",
++		    name, pcm->rate, pcm->chunk_size);
++
++	rc  = open_device( &pcm->device, name, type);
++        if( rc < 0 ) {
++		return ( rc);
++        };
++	rc = set_hw_params( type, pcm, hw_params );
++	snd_pcm_nonblock( pcm->device, 1);
++	dump_pcm_data( pcm->device, hw_params);
++	if( rc == 0) {
++		rc = set_sw_params( type, pcm, hw_params);
++	}
++
++	if( rc < 0 && pcm->device != 0) {
++		snd_pcm_close( pcm->device );
++	}
++	return rc;
++}
+ 
+-  while(total < len / 2)
+-  {
+-    res = snd_pcm_writei(ADEV(as)->aout, buf, len / 2);
+-    if (res < 0)
+-    {
+-      if (res == -EAGAIN)
+-      {
+-        DBG_DYNA_AUDIO_DRV("must wait: %s\n", snd_strerror(res));
+-        if (snd_pcm_wait(ADEV(as)->aout, 1000) < 0)
+-        {
+-          DBG_DYNA_AUDIO_DRV("snd_pcm_wait failed: %s\n", snd_strerror(res));
+-          return 0;
+-        }
+-        continue;
+-      }
+-      else if (res == -EPIPE)
+-      {
+-        DBG_DYNA_AUDIO_DRV("overrun: %s\n", snd_strerror(res));
+-        // PCM device reached overrun, let's recover and try again
+-        if (snd_pcm_prepare(ADEV(as)->aout) < 0)
+-        {
+-          DBG_DYNA_AUDIO_DRV("snd_pcm_prepare failed: %s\n", snd_strerror(res));
+-          return 0;
+-        }
+-        continue;
+-      }
+-      else if (res == -ESTRPIPE)
+-      {
+-        // the system has suspended drivers, let's suspend and try again
+-        DBG_DYNA_AUDIO_DRV("driver has been suspended: %s\n", snd_strerror(res));
+-        if (suspend(ADEV(as)->aout))
+-        {
+-          DBG_DYNA_AUDIO_DRV("suspend failed\n");
+-          return 0;
+-        }
+-        continue;
+-      }
+-    }
+-    else
+-    {
+-#if ACTIVATE_DYNA_AUDIO_DRV_DBG
+-      if (res != len / 2)
+-      {
+-        // failed to write all data
+-        DBG_DYNA_AUDIO_DRV("%d samples has been written instead of %d\n", res, len / 2);
+-      }
+-#endif
+-      total += res;
+-    }
+-  }
+ 
+-  return total * 2;
++static int alsa_stream_open( phastream_t* as,
++			     const char*  name,
++			     int          wished_rate,
++			     int          chunk_size,
++			     ph_audio_cbk cbk) {
++
++	alsa_drv_info*  ad = 0;
++        pcm_data        input_dev;
++	pcm_data        output_dev;
++
++	ALSA_DEBUG(
++		"alsa_stream_open: (name: %s, rate: %d, chunk: %d)",
++		name, wished_rate, chunk_size);
++	ad = calloc( sizeof( alsa_drv_info), 1);
++	if ( !ad) {
++		return -PH_NORESOURCES;
++	}
++
++        pcm_data_new( &output_dev, wished_rate, chunk_size, OUTPUT_LATENCY);
++	alsa_dev_open(name,  SND_PCM_STREAM_PLAYBACK,  &output_dev);
++        ad->output.pcm = output_dev.device;
++	if ( !ad->output.pcm) {
++		free( ad);
++		return -PH_NOAUDIODEVICE;
++	}
++        ad->output.id = "output";
++
++        pcm_data_new( &input_dev, wished_rate, chunk_size, INPUT_LATENCY);
++	alsa_dev_open( name, SND_PCM_STREAM_CAPTURE, &input_dev);
++	ad->input.pcm = input_dev.device;
++	if ( !ad->input.pcm) {
++		// close the playback device if we fail to open capture device
++		snd_pcm_close( ad->output.pcm);
++		free( ad);
++		return -PH_NOAUDIODEVICE;
++	}
++	ad->input.id = "input";
++
++	if( input_dev.rate != output_dev.rate)
++  	{
++  		ALSA_ERROR( "Mic speed %d differs from speaker rate %d",
++  			    input_dev.rate, output_dev.rate);
++  		ALSA_ERROR( "Lets try anyway, but this is scary...");
++  	}
++
++        // TODO: refactor the actual_rate across all phaudio_driver backends
++	//       it should be an OUT parameter in the dev_open prototype
++	// here, hopefully, both MIC and SPK devices have been opened with
++        // the same rate. We use only the MIC rate.
++
++	as->actual_rate = input_dev.rate;
++        ad->channels = input_dev.channels;
++	ad->sample_size = snd_pcm_format_size( PCM_FORMAT, 1);
++	ad->chunk_size = chunk_size;
++	ad->callback = cbk;
++	ALSA_DEBUG( "alsa_stream_open: chosen rate (freq)=(%d)",
++			   as->actual_rate);
++	as->drvinfo = ad;
++	PH_SNDDRVR_USE();
++
++	return 0;
++ }
++
++static void alsa_stream_close( phastream_t *as) {
++
++	alsa_dev* input = &( DRV_INFO(as)->input);
++	alsa_dev* output = &( DRV_INFO(as)->output);
++
++	ALSA_DEBUG( "alsa_stream_close");
++	if ( !as->drvinfo){
++		ALSA_DEBUG( "ALSA streams already closed");
++		return;
++	}
++
++	ALSA_DEBUG( "Stop playback thread");
++	output->stop_thread = 1;
++	pthread_join( output->thread, NULL);
++	snd_pcm_drop( output->pcm);
++	snd_pcm_close( output->pcm);
++	ALSA_DEBUG(
++		"Output: (sent,rebuffered,again,soft,hard): %ld %ld %d, %d, %d",
++		output->bytes,
++		output->rebuffered,
++		output->again_errors,
++		output->soft_errors,
++		output->hard_errors);
++
++	ALSA_DEBUG( "Stop recorder thread");
++	input->stop_thread = 1;
++	pthread_join( input->thread, NULL);
++	snd_pcm_drop( input->pcm );
++	snd_pcm_close( input->pcm);
++	ALSA_DEBUG(
++		"Input: received %ld, errors(again, soft,hard) : %d, %d, %d",
++		input->bytes,
++		input->again_errors,
++		input->soft_errors,
++		input->hard_errors);
++
++	free( as->drvinfo);
++	as->drvinfo = 0;
++
++	PH_SNDDRVR_UNUSE();
++}
++
++static void alsa_stream_start( phastream_t *as) {
++
++	alsa_dev*       output = &( DRV_INFO( as)->output);
++	alsa_dev*       input = &( DRV_INFO( as)->input);
++        int             rc;
++
++	// Output start automagically when the buffer exceeds threshold.
++	ALSA_DEBUG( "Streams ready to start");
++
++	output->stop_thread = 0;
++	rc = pthread_create( &output->thread,
++			     NULL,
++			     playback_thread,
++			     (void*) as);
++	assert( rc == 0);
++	ALSA_DEBUG( "Playback thread started" );
++
++	input->stop_thread = 0;
++	rc = pthread_create( &input->thread,
++			     NULL,
++			     recorder_thread,
++			     (void*) as);
++	assert( rc == 0);
++	ALSA_DEBUG( "Recorder thread started");
+ }
+ 
+-int alsa_stream_read(phastream_t *as, void *buf,  int len)
++static void mono2stereo( char*       dest,
++			 char*       src,
++			 size_t      size,
++			 size_t      sample_size) {
++
++	char*  last_in_buffer = src + size - sample_size;
++	char*  stereo         = dest + 2 * size - sample_size;
++	char*  mono;
++
++	for( mono = last_in_buffer; mono >= src; mono -= sample_size) {
++		memcpy( stereo, mono, sample_size) ;
++		stereo -= sample_size;
++		memcpy( stereo, mono, sample_size) ;
++		stereo -= sample_size;
++	}
++
++}
++
++static void ph_handle_pcm_error( alsa_dev* device, int err )
+ {
+-  int res = 0;
+-  int total = 0;
+ 
+-  while(total < len / 2)
+-  {
+-    res = snd_pcm_readi(ADEV(as)->ain, buf, len / 2);
+-    if (res < 0)
+-    {
+-      if (res == -EAGAIN)
+-      {
+-        DBG_DYNA_AUDIO_DRV("must wait: %s\n", snd_strerror(res));
+-        if (snd_pcm_wait(ADEV(as)->ain, 1000) < 0)
+-        {
+-          DBG_DYNA_AUDIO_DRV("snd_pcm_wait failed: %s\n", snd_strerror(res));
+-          return 0;
+-        }
+-        continue;
+-      }
+-      else if (res == -EPIPE)
+-      {
+-        // PCM device reached underrun, let's recover and try again
+-        DBG_DYNA_AUDIO_DRV("underrun: %s\n", snd_strerror(res));
+-        if (snd_pcm_prepare(ADEV(as)->ain) < 0)
+-        {
+-          DBG_DYNA_AUDIO_DRV("snd_pcm_prepare failed: %s\n", snd_strerror(res));
+-          return 0;
+-        }
+-        continue;
+-      }
+-      else if (res == -ESTRPIPE)
+-      {
+-        // the system has suspended drivers, let's suspend and try again
+-        DBG_DYNA_AUDIO_DRV("driver has been suspended: %s\n", snd_strerror(res));
+-        if (suspend(ADEV(as)->ain))
+-        {
+-          DBG_DYNA_AUDIO_DRV("suspend failed\n");
+-          return 0;
++	assert( err < 0 );
++	if( err == -EAGAIN){
++		device->again_errors += 1;
++	}
++	else {
++		device->soft_errors += 1;
++		err = snd_pcm_recover( device->pcm, err, ALSA_SILENT);
++		if( err < 0) {
++			ALSA_ERROR( "Can't restore ALSA %s: %s",
++				    device->id, snd_strerror( err));
++			device->hard_errors += 1;
++			snd_pcm_prepare( device->pcm);
++		}
++	}
++}
++
++static int stream_write( alsa_dev* output, void *buf,  int len){
++
++	snd_pcm_uframes_t frames;
++	int               res = 0;
++	ssize_t           bytes;
++
++
++	frames = snd_pcm_bytes_to_frames( output->pcm, len);
++	res = snd_pcm_writei( output->pcm, buf, frames);
++        if( res < 0 ){
++		ph_handle_pcm_error( output, res );
++		bytes = 0;
++	}
++	else{
++		bytes = snd_pcm_frames_to_bytes( output->pcm, res);
++	}
++	return bytes;
++}
++
++static int alsa_stream_write( phastream_t *as, void *buf,  int len) {
++
++	char*      ph_buf;
++	ssize_t    bytes;
++	alsa_dev*  output = &( DRV_INFO( as)->output);
++
++	assert( len >=0 && len <= (int) DRV_INFO( as)->chunk_size);
++
++        if( DRV_INFO( as)->channels == 1) {
++		bytes = stream_write( output, buf, len);
++	}
++	else {
++		ph_buf = alloca( len * 2);
++		mono2stereo( ph_buf, buf, len, DRV_INFO(as)->sample_size);
++		bytes = stream_write( output, ph_buf, len * 2) / 2;
++	}
++	output->bytes += bytes;
++
++	assert( bytes >= 0 &&
++		bytes <= (ssize_t) DRV_INFO( as)->chunk_size);
++	return bytes;
++}
++
++static size_t stereo2mono( char*    dest_arg,
++			   char*    src_arg,
++			   size_t   size,
++			   size_t   sample_size)
++{
++	long     val;
++	short*   src = (short*) src_arg;
++	short*   dest= (short*) dest_arg;
++
++	assert( sample_size == 2);  // This only works for 16bit signed data.
++	assert( sizeof( short ) == 2);
++
++#ifdef  MONO_AVERAGE
++	while( (char*) src < src_arg + size) {
++		val = *src++;
++		val += *src++;
++
++		*dest = (short)(val / 2);
++		dest++;
++	}
++#else
++        while( (char*) src < buf + size) {
++		*dest = *(src + (src % 4) / 2);
++  	        src += 2;
++                dest += 1;
+         }
+-        continue;
+-      }
+-    }
+-    else
+-    {
+-#if ACTIVATE_DYNA_AUDIO_DRV_DBG
+-      if (res != len / 2)
+-      {
+-        // failed to write all data
+-        DBG_DYNA_AUDIO_DRV("%d samples has been written instead of %d\n", res, len / 2);
+-      }
+ #endif
+-      total += res;
+-      break;
+-    }
+-  }
++	return size / 2;
++}
++
++static int stream_read(alsa_dev* input, void *buf,  int len) {
+ 
+-  return res * 2;
++	snd_pcm_uframes_t frames;
++	int               res = 0;
++	unsigned          bytes;
++
++	frames = snd_pcm_bytes_to_frames( input->pcm, len);
++	res = snd_pcm_readi( input->pcm, buf, frames);
++	if ( res == 0) {
++		ALSA_DEBUG( "Empty read!");
++		bytes = 0;
++	}
++	else if ( res < 0) {
++		ph_handle_pcm_error( input, res );
++		bytes = 0;
++	}
++	else{
++		bytes = snd_pcm_frames_to_bytes( input->pcm, res);
++	}
++        return bytes;
+ }
+ 
+-int alsa_stream_get_out_space(phastream_t *as, int *used)
+-{
+-  snd_pcm_status_t *st;
+-  snd_pcm_status_alloca(&st);
++static int alsa_stream_read( phastream_t *as, void *buf, int len) {
++
++	char*      bigger_buf;
++	size_t     bytes = len;
++	alsa_dev*  input = &( DRV_INFO( as)->input);
++
++	assert( len <= (int) DRV_INFO( as)->chunk_size);
++
++        if( DRV_INFO( as)->channels == 1) {
++		bytes = stream_read( input, buf, len);
++	}
++	else {
++		assert( DRV_INFO( as)->channels == 2);
++		bigger_buf = alloca( len * 2);
++		bytes = stream_read( input, bigger_buf, len * 2);
++		bytes = stereo2mono( buf, bigger_buf, bytes, 2);
++	}
++	input->bytes  += bytes;
++	assert( (int) bytes <= len);
++	return( bytes);
++}
+ 
+-  if (snd_pcm_status(ADEV(as)->aout, st) < 0)
+-  {
+-    *used = 0;
+-    return 320;
+-  }
++static int alsa_stream_get_out_space( phastream_t *as, int *used) {
++	snd_pcm_status_t  *st;
++	snd_pcm_uframes_t available;
++        snd_pcm_t* output = DRV_INFO( as)->output.pcm;
++
++        snd_pcm_status_alloca( &st);
++
++        if ( snd_pcm_status( output, st) < 0) {
++                *used = 0;
++                return 320;  //FIXME! Whats this?!
++        }
++
++        *used = snd_pcm_frames_to_bytes( output,
++                                         snd_pcm_status_get_delay( st));
+ 
+-  *used = 2 * (int) snd_pcm_status_get_delay(st);
+-  return 2 * (int) snd_pcm_status_get_avail(st);
++        available = snd_pcm_status_get_avail( st);
++        ALSA_DEBUG( "Get_out_space, used: %d, available:%d",
++                    *used, available);
++        return snd_pcm_frames_to_bytes( output, available);
+ }
+ 
+-int alsa_stream_get_avail_data(phastream_t *as)
+-{
+-  snd_pcm_status_t *st;
+-  snd_pcm_status_alloca(&st);
+ 
+-  if (snd_pcm_status(ADEV(as)->ain, st) < 0)
+-  {
+-    return 0;
+-  }
++static int alsa_stream_get_avail_data( phastream_t *as) {
+ 
+-  return 2 * (int) snd_pcm_status_get_avail(st);
++	ALSA_ERROR( "alsa_stream_get_avail_data(): not implemented" );
++	return -1;
+ }
+ 
+-int alsa_stream_get_fds(phastream_t *as, int fds[2])
+-{
+-  fds[0] = fds[1] = -1;
++static int alsa_stream_get_fds( phastream_t *as, int fds[2]) {
++
++	ALSA_ERROR( "alsa_stream_get_fds(): not implemented" );
++	return -1;
++}
++
++//
++// Timing: on a lightly loaded AMD x2 4200 I've measured
++// invocation of routines within +-3ms, without looking for
++// exceptions which sure are there.
++static void* playback_thread( void* arg) {
++
++	phastream_t*   ps         = (phastream_t*) arg;
++	alsa_dev*      output     = &( DRV_INFO( ps)->output);
++	const unsigned chunk_size = DRV_INFO( ps)->chunk_size;
++	int            size;
++	unsigned       sent;
++	char*          buffer;
++	char*          nxt_buff   = buffer;
++	unsigned short prev_size  = chunk_size;
++	int            odd        = 0;
++
++        buffer = alloca( 2 * chunk_size);
++	snd_pcm_format_set_silence( PCM_FORMAT, buffer, chunk_size);
++
++	while( !output->stop_thread) {
++		size = chunk_size;
++		odd = ( odd + 1) % 2;
++		nxt_buff =  buffer + odd * chunk_size;
++		DRV_INFO( ps)->callback( ps, NULL, 0, nxt_buff, &size);
++		if( size == 0) {
++			size = prev_size;
++			odd = ( odd + 1) % 2;
++			nxt_buff =  buffer + odd * chunk_size;
++			output->rebuffered += size;
++		}
++		else {
++			prev_size = size;
++		}
++		for( sent = 0; sent < (unsigned) size; ) {
++			sent += alsa_stream_write( ps,
++						   nxt_buff + sent,
++						   size - sent);
++			snd_pcm_wait( output->pcm, SND_PCM_WAIT_MS);
++		}
++	}
++	output->stop_thread++;
++	return( NULL);
++}
+ 
+-  fds[0] = alsa_dev_get_fd(ADEV(as)->ain);
+-  fds[1] = alsa_dev_get_fd(ADEV(as)->aout);
++static void* recorder_thread( void* arg) {
+ 
+-  return 0;
++	phastream_t*     ps = (phastream_t*) arg;
++	alsa_dev*        input = &( DRV_INFO(ps)->input);
++	int              res;
++	char*            buffer;
++
++	buffer = alloca( DRV_INFO(ps)->chunk_size);
++
++	while( !input->stop_thread) {
++		snd_pcm_wait( input->pcm, SND_PCM_WAIT_MS);
++
++		res = alsa_stream_read( ps,
++					buffer,
++					DRV_INFO(ps)->chunk_size);
++		if( res <= 0) {
++			// Don't monopolize CPU if continous errors.
++			nanosleep( &io_wait, NULL);
++			continue;
++		}
++		DRV_INFO( ps)->callback(ps, buffer, res, NULL, 0);
++	}
++	input->stop_thread++;
++	return( NULL);
+ }
+ 
+ #endif //ENABLE_ALSA
--- wengophone-2.1.2.dfsg0.orig/debian/patches/head/img_resample.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/head/img_resample.patch
@@ -0,0 +1,97 @@
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-avcodec-wrapper.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-avcodec-wrapper.c	2006-10-09 22:44:22.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-avcodec-wrapper.c	2008-05-25 22:20:45.000000000 +0000
+@@ -128,13 +128,8 @@
+ 	encoder_t->context->rtp_payload_size = 1000;
+ 	encoder_t->context->rtp_callback = phcodec_avcodec_video_rtp_callback;
+ 
+-	encoder_t->res_ctx = img_resample_init(
+-			dest_width, dest_height,
+-			meta_t->frame_width, meta_t->frame_height
+-	);
+-
+-    encoder_t->resized_pic = avcodec_alloc_frame();
+-    encoder_t->sampled_frame = avcodec_alloc_frame();
++	encoder_t->resized_pic = avcodec_alloc_frame();
++	encoder_t->sampled_frame = avcodec_alloc_frame();
+ 
+ 	return 0;
+ }
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-avcodec-wrapper.h
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-avcodec-wrapper.h	2006-05-12 01:16:29.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-avcodec-wrapper.h	2008-05-25 22:20:05.000000000 +0000
+@@ -49,7 +49,6 @@
+ 	AVPicture pictureOut;
+ 	AVFrame *resized_pic, *sampled_frame;
+ 	AVCodecContext *context;
+-	ImgReSampleContext *res_ctx;
+ 	AVCodec* encoder;
+ 	int maxencodesize;
+ };
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h263.c	2007-01-25 14:49:02.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263.c	2008-05-25 22:20:05.000000000 +0000
+@@ -113,7 +113,7 @@
+ 
+ void h263_encoder_cleanup(void *ctx) {
+ 	ph_h263_encoder_ctx_t * encoder = (ph_h263_encoder_ctx_t *) ctx;
+-	img_resample_close(encoder->encoder_ctx.res_ctx);
++
+ 	//avcodec_flush_buffers(encoder->encoder_ctx.context);
+ 	avcodec_close(encoder->encoder_ctx.context);
+ 	av_free(encoder->encoder_ctx.resized_pic);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263flv1.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h263flv1.c	2007-02-22 19:17:04.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263flv1.c	2008-05-25 22:20:05.000000000 +0000
+@@ -113,7 +113,7 @@
+ 
+ void h263flv1_encoder_cleanup(void *ctx) {
+ 	ph_h263_encoder_ctx_t * encoder = (ph_h263_encoder_ctx_t *) ctx;
+-	img_resample_close(encoder->encoder_ctx.res_ctx);
++
+ 	//avcodec_flush_buffers(encoder->encoder_ctx.context);
+ 	avcodec_close(encoder->encoder_ctx.context);
+ 	av_free(encoder->encoder_ctx.resized_pic);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263plus.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h263plus.c	2007-02-22 19:17:04.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h263plus.c	2008-05-25 22:20:05.000000000 +0000
+@@ -106,7 +106,7 @@
+ 
+ void h263p_encoder_cleanup(void *ctx) {
+ 	ph_h263_encoder_ctx_t * encoder = (ph_h263_encoder_ctx_t *) ctx;
+-	img_resample_close(encoder->encoder_ctx.res_ctx);
++
+ 	//avcodec_flush_buffers(encoder->encoder_ctx.context);
+ 	avcodec_close(encoder->encoder_ctx.context);
+ 	av_free(encoder->encoder_ctx.resized_pic);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h264.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-h264.c	2006-10-09 22:44:22.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-h264.c	2008-05-25 22:20:05.000000000 +0000
+@@ -98,7 +98,7 @@
+ 
+ void h264_encoder_cleanup(void *ctx) {
+ 	ph_h264_encoder_ctx_t * encoder = (ph_h264_encoder_ctx_t *) ctx;
+-	img_resample_close(encoder->encoder_ctx.res_ctx);
++
+ 	av_free(encoder->encoder_ctx.resized_pic);
+ 	av_free(encoder->encoder_ctx.sampled_frame);
+ 	av_free(encoder->data_enc);
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-mpeg4.c
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/phcodec-mpeg4.c	2007-04-11 11:08:44.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/phcodec-mpeg4.c	2008-05-25 22:20:05.000000000 +0000
+@@ -116,7 +116,7 @@
+ 
+ void mpeg4_encoder_cleanup(void *ctx) {
+ 	ph_mpeg4_encoder_ctx_t * encoder = (ph_mpeg4_encoder_ctx_t *) ctx;
+-	img_resample_close(encoder->encoder_ctx.res_ctx);
++
+ 	av_free(encoder->encoder_ctx.resized_pic);
+ 	av_free(encoder->encoder_ctx.sampled_frame);
+ 	av_free(encoder->data_enc);
--- wengophone-2.1.2.dfsg0.orig/debian/patches/head/cmake-swscale.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/head/cmake-swscale.patch
@@ -0,0 +1,65 @@
+Index: owbuild/FindFFMPEG.cmake
+===================================================================
+--- owbuild/FindFFMPEG.cmake.orig	2007-01-16 18:13:55.000000000 +0100
++++ owbuild/FindFFMPEG.cmake	2008-05-27 00:51:25.000000000 +0200
+@@ -21,6 +21,7 @@
+   # use pkg-config to get the directories and then use these values
+   # in the FIND_PATH() and FIND_LIBRARY() calls
+   include(UsePkgConfig)
++  include(CheckFunctionExists)
+ 
+   pkgconfig(libavcodec _FFMPEGIncDir _FFMPEGLinkDir _FFMPEGLinkFlags _FFMPEGCflags)
+ 
+@@ -61,9 +62,20 @@
+       /sw/lib
+   )
+ 
+-  find_library(AVFORMAT_LIBRARY
++#  find_library(AVFORMAT_LIBRARY
++#    NAMES
++#      avformat
++#    PATHS
++#      ${_FFMPEGLinkDir}
++#      /usr/lib
++#      /usr/local/lib
++#      /opt/local/lib
++#      /sw/lib
++#  )
++
++  find_library(SWSCALE_LIBRARY
+     NAMES
+-      avformat
++      swscale
+     PATHS
+       ${_FFMPEGLinkDir}
+       /usr/lib
+@@ -92,12 +104,26 @@
+     )
+   endif (AVCODEC_LIBRARY)
+ 
+-  if (AVFORMAT_LIBRARY)
++#  if (AVFORMAT_LIBRARY)
++#    set(FFMPEG_LIBRARIES
++#      ${FFMPEG_LIBRARIES}
++#      ${AVFORMAT_LIBRARY}
++#    )
++#  endif (AVFORMAT_LIBRARY)
++
++  if (SWSCALE_LIBRARY)
+     set(FFMPEG_LIBRARIES
+       ${FFMPEG_LIBRARIES}
+-      ${AVFORMAT_LIBRARY}
++      ${SWSCALE_LIBRARY}
+     )
+-  endif (AVFORMAT_LIBRARY)
++  endif (SWSCALE_LIBRARY)
++
++  set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_INCLUDE_DIR})
++  set(CMAKE_REQUIRED_LIBRARIES ${FFMPEG_LIBRARIES})
++  check_function_exists(
++    sws_scale HAVE_SWSCALE
++  )
++
+ 
+   if (FFMPEG_INCLUDE_DIRS AND FFMPEG_LIBRARIES)
+      set(FFMPEG_FOUND TRUE)
--- wengophone-2.1.2.dfsg0.orig/debian/patches/debian/cmake-svnrelease-from-debian-changelog.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/debian/cmake-svnrelease-from-debian-changelog.patch
@@ -0,0 +1,38 @@
+Index: wengophone-2.1.0~rc2-svn10386/owbuild/owbuild/OWGetSvnRevision.cmake
+===================================================================
+--- wengophone-2.1.0~rc2-svn10386.orig/owbuild/owbuild/OWGetSvnRevision.cmake	2007-05-13 11:23:24.000000000 +0200
++++ wengophone-2.1.0~rc2-svn10386/owbuild/owbuild/OWGetSvnRevision.cmake	2007-05-14 17:19:00.000000000 +0200
+@@ -53,7 +53,32 @@
+ 			set(${revision} 0)
+ 		endif (SVN_REVISION_RESULT_VARIABLE EQUAL 0)
+ 	else (SVNVERSION_EXECUTABLE AND SVN_DOT_DIR)
+-		message("Subversion svn command line not found, it is recommended to install it")
++		find_file(DEBIAN_CHANGELOG
++			NAMES
++				changelog
++			PATHS
++				${CMAKE_SOURCE_DIR}/debian
++		)
++
++		if (DEBIAN_CHANGELOG)
++			message("-- Generating subversion revison using debian/changelog")
++				execute_process(
++					COMMAND
++						/usr/bin/perl -e "\$_=<>;\$_=~/^.*svn\(.*?\)-.*\$/;print \$1" ${DEBIAN_CHANGELOG}
++					RESULT_VARIABLE
++						SVN_REVISION_RESULT_VARIABLE
++					OUTPUT_VARIABLE
++						SVN_REVISION_OUTPUT_VARIABLE
++				)
++
++				if (SVN_REVISION_RESULT_VARIABLE EQUAL 0 AND SVN_REVISION_OUTPUT_VARIABLE)
++					set(${revision} ${SVN_REVISION_OUTPUT_VARIABLE})
++				else (SVN_REVISION_RESULT_VARIABLE EQUAL 0 AND SVN_REVISION_OUTPUT_VARIABLE)
++					message(FATAL_ERROR "FATAL: cannot generate svn revision number from debian/changelog")
++				endif (SVN_REVISION_RESULT_VARIABLE EQUAL 0 AND SVN_REVISION_OUTPUT_VARIABLE)
++
++		endif (DEBIAN_CHANGELOG)
++
+ 	endif (SVNVERSION_EXECUTABLE AND SVN_DOT_DIR)
+ 
+ endmacro (ow_get_svn_revision revision)
--- wengophone-2.1.2.dfsg0.orig/debian/patches/debian/remove-extra-copying-file.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/debian/remove-extra-copying-file.patch
@@ -0,0 +1,12 @@
+Index: wengophone-2.1.0.dfsg/wengophone/src/presentation/qt/CMakeLists-install-linux.txt
+===================================================================
+--- wengophone-2.1.0.dfsg.orig/wengophone/src/presentation/qt/CMakeLists-install-linux.txt	2007-05-18 12:39:05.000000000 +0200
++++ wengophone-2.1.0.dfsg/wengophone/src/presentation/qt/CMakeLists-install-linux.txt	2007-05-18 12:39:15.000000000 +0200
+@@ -63,7 +63,3 @@
+ 		DESTINATION share/icons/hicolor/${size}x${size}/apps/
+ 		RENAME wengophone.png)
+ endforeach(size)
+-
+-install(FILES
+-	${CMAKE_SOURCE_DIR}/wengophone/COPYING
+-	DESTINATION ${DATA_INSTALL_DIR})
--- wengophone-2.1.2.dfsg0.orig/debian/patches/debian/cmake-no-rpath_to_link_path.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/debian/cmake-no-rpath_to_link_path.patch
@@ -0,0 +1,13 @@
+Index: wengophone-2.1.0.dfsg/wengophone/src/presentation/qt/CMakeLists-install-linux.txt
+===================================================================
+--- wengophone-2.1.0.dfsg.orig/wengophone/src/presentation/qt/CMakeLists-install-linux.txt	2007-05-18 12:43:07.000000000 +0200
++++ wengophone-2.1.0.dfsg/wengophone/src/presentation/qt/CMakeLists-install-linux.txt	2007-05-18 12:43:15.000000000 +0200
+@@ -4,8 +4,6 @@
+ 	PROPERTIES
+ 		INSTALL_RPATH
+ 			${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/wengophone
+-		INSTALL_RPATH_USE_LINK_PATH
+-			ON
+ )
+ 
+ install(TARGETS
--- wengophone-2.1.2.dfsg0.orig/debian/patches/debian/cmake-find-boost-1.34.0.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/debian/cmake-find-boost-1.34.0.patch
@@ -0,0 +1,13 @@
+Index: wengophone-2.1.0.dfsg/owbuild/FindBoost.cmake
+===================================================================
+--- wengophone-2.1.0.dfsg.orig/owbuild/FindBoost.cmake	2007-05-10 11:48:10.000000000 +0000
++++ wengophone-2.1.0.dfsg/owbuild/FindBoost.cmake	2007-05-18 13:41:46.000000000 +0000
+@@ -91,7 +91,7 @@
+     endif (CYGWIN)
+ 
+   else (WIN32)
+-    set(BOOST_LIB_SUFFIXES -gcc-mt)
++    set(BOOST_LIB_SUFFIXES -gcc41-mt-1_34 -gcc-mt)
+   endif (WIN32)
+ 
+   find_path(BOOST_INCLUDE_DIR
--- wengophone-2.1.2.dfsg0.orig/debian/patches/debian/cmake-force-fpic.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/debian/cmake-force-fpic.patch
@@ -0,0 +1,21 @@
+Index: wengophone-2.1.0~rc2-svn10386/owbuild/owbuild/OWDefaultCompilerFlags.cmake
+===================================================================
+--- wengophone-2.1.0~rc2-svn10386.orig/owbuild/owbuild/OWDefaultCompilerFlags.cmake	2007-04-03 14:54:16.000000000 +0000
++++ wengophone-2.1.0~rc2-svn10386/owbuild/owbuild/OWDefaultCompilerFlags.cmake	2007-04-03 14:54:34.000000000 +0000
+@@ -15,12 +15,10 @@
+ 
+ # With -fPIC
+ if (UNIX AND NOT WIN32)
+-	if (CMAKE_SIZEOF_VOID_P MATCHES "8")
+-		ow_check_cxx_compiler_flag("-fPIC" WITH_FPIC)
+-		if (WITH_FPIC)
+-			add_definitions(-fPIC)
+-		endif (WITH_FPIC)
+-	endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
++	ow_check_cxx_compiler_flag("-fPIC" WITH_FPIC)
++	if (WITH_FPIC)
++		add_definitions(-fPIC)
++	endif (WITH_FPIC)
+ 
+ 	if (GCC4)
+ 		# See http://www.cynapses.org/tmp/gcc/fortify_source
--- wengophone-2.1.2.dfsg0.orig/debian/patches/debian/cmake-rpath-shlibs.patch
+++ wengophone-2.1.2.dfsg0/debian/patches/debian/cmake-rpath-shlibs.patch
@@ -0,0 +1,30 @@
+Index: wengophone-2.1.2.dfsg0/wifo/phapi/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/phapi/CMakeLists.txt	2007-11-28 18:46:32.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/phapi/CMakeLists.txt	2007-11-28 18:46:44.000000000 +0000
+@@ -324,3 +324,10 @@
+ ow_set_library_version(0.2.0 0)
+ 
+ ow_create_binary()
++
++set_target_properties(
++    phapi
++    PROPERTIES
++        INSTALL_RPATH
++            ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/wengophone
++)
+Index: wengophone-2.1.2.dfsg0/wifo/wifo-plugins/sfp-plugin/CMakeLists.txt
+===================================================================
+--- wengophone-2.1.2.dfsg0.orig/wifo/wifo-plugins/sfp-plugin/CMakeLists.txt	2007-11-28 18:46:33.000000000 +0000
++++ wengophone-2.1.2.dfsg0/wifo/wifo-plugins/sfp-plugin/CMakeLists.txt	2007-11-28 18:47:00.000000000 +0000
+@@ -37,3 +37,10 @@
+ )
+ 
+ ow_create_binary()
++
++set_target_properties(
++    sfp-plugin
++    PROPERTIES
++        INSTALL_RPATH
++            ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/wengophone
++)
