Commit aadb2a64 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Merge branch 'plugins' into debug_threads

Conflicts:

	configure.ac
	src/Makefile.am
parents 25aa4a38 5cec7153
......@@ -4,6 +4,6 @@
aclocal -I m4
libtoolize --force
autoheader
autoconf -f
autoconf -v -f
automake -a
./configure $@
......@@ -2,16 +2,48 @@
#
# @author: Yun Liu <yun.liu@savoirfairelinux.com>
#
# Build sflphone debian packages for Ubuntu 8.04
# Build sflphone rpm packages for Fedora 10 and openSUSE 11
# 1 - The SFLphone package must be build with a specific GnuPG key. Please contact us to have more information about that (<sflphoneteam@savoirfairelinux.com>)
# 2. The source code can be teched through anonymous http access. So no need of special access.
# 3. After having all the prerequisites, you can run "build-package.sh" to build debian packages for sflphone.
# All the source packages and binary packages will be generated in the current directory.
# 3. After having all the prerequisites, you can run "build-rpm-package.sh" to build rpm packages for sflphone.
#
# Refer to http://www.sflphone.org for futher information
# Analyze parameters
if [ "$1" == "--help" ] || [ "$1" == "" ];then
echo -e '\E[34mThis script is used to build sflphone rpm packages on ubuntu series(8.04,8,10,9), Fedora 10 and SUSE 11 platform.'
echo -e '\E[34mYou can add --fedora, --suse or --ubuntu to start packaging.'
echo
echo "The SFLphone package must be build with a specific GnuPG key. Please contact us to have more information about that (<sflphoneteam@savoirfairelinux.com>)"
echo
echo "For fedora and SUSE, you also need to add the following lines to $HOME/.rpmmacros:"
echo -e '\E[32m%_gpg_path /home/yun/.gnupg'
echo -e '\E[32m%_gpg_name Savoir-Faire Linux Inc. (Génération des paquets pour SFLphone) <sflphoneteam@savoirfairelinux.com>'
echo -e '\E[32m%_gpgbin /usr/bin/gpg'
echo
echo -e '\E[34mAfter all these preparations done, you can run ./build-package.sh --platform-name'
echo
echo -e '\E[36mHave fun!'
tput sgr0 # Reset colors to "normal."
echo
exit 1
elif [ $1 == "--fedora" ];then
BUILDDIR=$HOME/rpmbuild
platform="fedora"
elif [ $1 == "--suse" ];then
BUILDDIR=/usr/src/packages
platform="suse"
elif [ $1 == "--ubuntu" ];then
platform="ubuntu"
else
echo "This script can only be used for Ubuntu series, Fedora 10 and SUSE 11 platform. Use --help to get more information."
exit 1
fi
if [ -d "sflphone" ]; then
echo "Directory sflphone already exists. Please remove it first."
exit 1
exit 1
fi
# Anonymous git http access
......@@ -22,33 +54,54 @@ git checkout origin/release -b release
# Get system parameters
arch_flag=`getconf -a|grep LONG_BIT | sed -e 's/LONG_BIT\s*//'`
os_version=`lsb_release -d -s -c | sed -e '1d'`
ver=0.9.2
if [ $platform == "ubuntu" ];then
# Generate the changelog, according to the distribution and the git commit messages
cp debian/changelog.$os_version debian/changelog
git-dch --debian-branch=release --release
fi
# Generate the changelog, according to the distribution and the git commit messages
cp debian/changelog.$os_version debian/changelog
git-dch --debian-branch=release --release
cd ..
# Remove useless git directory
rm sflphone/.git/ -rf
# Copy the appropriate control file based on different archtecture
cp sflphone/debian/control.$os_version sflphone/debian/control
# Get the public gpg key to sign the packages
wget -q http://www.sflphone.org/downloads/gpg/sflphone.gpg.asc -O- | gpg --import -
echo "Building sflphone package on Ubuntu $os_version $arch_flag bit architecture...."
if [ $platform == "ubuntu" ];then
# Copy the appropriate control file based on different archtecture
cp sflphone/debian/control.$os_version sflphone/debian/control
# Provide prerequisite directories used by debuild
cp sflphone sflphone-0.9.2 -r
cp sflphone sflphone-0.9.2.orig -r
echo "Building sflphone package on Ubuntu $os_version $arch_flag bit architecture...."
# Provide prerequisite directories used by debuild
cp sflphone sflphone-$ver -r
cp sflphone sflphone-$ver.orig -r
# Build packages
cd sflphone-$ver/debian; debuild -k'Savoir-Faire Linux Inc.'
# Get the public gpg key to sign the packages
wget -q http://www.sflphone.org/downloads/gpg/sflphone.gpg.asc -O- | gpg --import -
# Post clean
cd ..
rm sflphone-$ver sflphone -rf
echo "Done! All the source packages and binary packages are generated in the current directory"
# Build packages
cd sflphone-0.9.2/debian; debuild -k'Savoir-Faire Linux Inc.'
else
# Prepare for packaging
mv sflphone sflphone-$ver
# Clean
cd ../..
rm sflphone-0.9.2/ -rf
rm sflphone/ -rf
cp sflphone-$ver/platform/$platform.spec $BUILDDIR/SPECS/
cp sflphone-$ver/libs/pjproject-1.0/libpj-sfl.pc $BUILDDIR/SOURCES
tar zcvf sflphone-$ver.tar.gz sflphone-$ver
echo "Building package finished successullly!"
rm sflphone-$ver -rf
mv sflphone-$ver.tar.gz $BUILDDIR/SOURCES
echo "Building sflphone package on $platform $arch_flag bit architecture...."
# Build packages
cd $BUILDDIR/SPECS/
rpmbuild -ba --sign sflphone.spec
echo "Done! All source rpms and binary rpms are stored in $BUILDDIR/SRPMS and $BUILDDIR/RPMS"
fi
......@@ -36,7 +36,10 @@ AC_CONFIG_FILES([src/Makefile \
src/audio/codecs/Makefile
src/audio/codecs/ilbc/Makefile \
src/config/Makefile \
src/dbus/Makefile ])
src/dbus/Makefile \
src/plug-in/audiorecorder/Makefile \
src/plug-in/Makefile \
src/plug-in/test/Makefile])
dnl Unitary test section
AC_CONFIG_FILES([test/Makefile])
......
# Global variables
src=$(top_srcdir)
sflcodecdir=$(libdir)/sflphone/codecs
sflplugindir=$(libdir)/sflphone/plugins
PJSIP_LIBS = -lpjnath-sfl -lpjsua-sfl -lpjsip-sfl -lpjmedia-sfl -lpjsip-simple-sfl -lpjsip-ua-sfl -lpjmedia-codec-sfl -lpjlib-util-sfl -lpj-sfl
......@@ -16,5 +17,6 @@ AM_CPPFLAGS = \
@SIP_CFLAGS@ \
@DBUSCPP_CFLAGS@ \
-DCODECS_DIR=\""$(sflcodecdir)"\" \
-DPLUGINS_DIR=\""$(sflplugindir)"\" \
-DENABLE_TRACE
......@@ -13,7 +13,7 @@ IAXSOURCES =
IAXHEADERS =
endif
SUBDIRS = audio config dbus
SUBDIRS = audio config dbus plug-in
# Add here the cpp files to be build with sflphone
sflphoned_SOURCES = \
......@@ -75,6 +75,8 @@ libsflphone_la_LIBADD = \
./audio/libaudio.la \
./dbus/libdbus.la \
./config/libconfig.la \
./plug-in/libplugin.la \
./plug-in/audiorecorder/libaudiorecorder.la \
$(IAX_LIBS)
libsflphone_la_SOURCES =
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "audiorecord.h"
AudioRecord::AudioRecord(){
sndSmplRate_ = 44100;
channels_ = 1;
byteCounter_ = 0;
}
void AudioRecord::setSndSamplingRate(int smplRate){
sndSmplRate_ = smplRate;
}
void AudioRecord::openFile(std::string fileName, FILE_TYPE type, SOUND_FORMAT format) {
channels_ =1;
fileType_ = type;
byteCounter_ = 0;
sndFormat_ = format;
bool result = false;
if(fileType_ == FILE_RAW){
result = setRawFile( fileName.c_str() );
}
else if (fileType_ == FILE_WAV){
result = setWavFile( fileName.c_str() );
}
}
void AudioRecord::closeFile() {
if (fp == 0) return;
if (fileType_ == FILE_RAW)
fclose(fp);
else if (fileType_ == FILE_WAV)
this->closeWavFile();
}
bool AudioRecord::isOpenFile() {
if(fp)
return true;
else
return false;
}
bool AudioRecord::setRawFile(const char *fileName) {
char name[8192];
strncpy(name, fileName, 8192);
if ( strstr(name, ".raw") == NULL) strcat(name, ".raw");
fp = fopen(name, "wb");
if ( !fp ) {
cout << "AudioRecord: could not create RAW file: " << name << '.';
return false;
}
if ( sndFormat_ != INT16 ) { // TODO need to change INT16 to SINT16
sndFormat_ = INT16;
cout << "AudioRecord: using 16-bit signed integer data format for file " << name << '.';
}
cout << "AudioRecord: creating RAW file: " << name;
return true;
}
bool AudioRecord::setWavFile(const char *fileName) {
char name[8192];
strncpy(name, fileName, 8192);
if ( strstr(name, ".wav") == NULL) strcat(name, ".wav");
fp = fopen(name, "wb");
if ( !fp ) {
cout << "AudioRecord: could not create WAV file: " << name;
return false;
}
struct wavhdr hdr = {"RIF", 44, "WAV", "fmt", 16, 1, 1,
44100, 0, 2, 16, "dat", 0};
hdr.riff[3] = 'F';
hdr.wave[3] = 'E';
hdr.fmt[3] = ' ';
hdr.data[3] = 'a';
hdr.num_chans = channels_;
if ( sndFormat_ == INT16 ) { // TODO need to write INT16 to SINT16
hdr.bits_per_samp = 16;
}
hdr.bytes_per_samp = (SINT16) (channels_ * hdr.bits_per_samp / 8);
hdr.bytes_per_sec = (SINT32) (hdr.sample_rate * hdr.bytes_per_samp);
if ( fwrite(&hdr, 4, 11, fp) != 11 ) {
cout << "AudioRecord: could not write WAV header for file " << name << '.';
return false;
}
cout << "AudioRecord: creating WAV file: " << name;
return true;
}
void AudioRecord::closeWavFile()
{
int bytes_per_sample = 1;
if ( sndFormat_ == INT16 )
bytes_per_sample = 2;
SINT32 bytes = byteCounter_ * channels_ * bytes_per_sample;
fseek(fp, 40, SEEK_SET); // jump to data length
fwrite(&bytes, 4, 1, fp);
bytes = byteCounter_ * channels_ * bytes_per_sample + 44; // + 44 for the wave header
fseek(fp, 4, SEEK_SET); // jump to file size
fwrite(&bytes, 4, 1, fp);
fclose( fp );
}
void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) {
if (fp == 0){
cout << "AudioRecord: Can't record data, a file has not yet been opened!";
return;
}
if ( sndFormat_ == INT16 ) { // TODO change INT16 to SINT16
if (nSamples <= 1){
if ( fwrite(buffer, 2, 1, fp) != 1)
cout << "AudioRecord: Could not record data!";
}
else {
for ( int k=0; k<nSamples; k++ ) {
cout << "Buffer[" << k << "] : " << buffer[k] << "\n";
if ( fwrite(&buffer[k], 2, 1, fp) != 1 )
cout << "AudioRecord: Could not record data!";
}
}
}
byteCounter_ += (unsigned long)(sizeof(buffer) / sizeof(SINT16));
return;
}
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <iostream>
#include <string.h>
#include "global.h"
using namespace std;
// structure for the wave header
struct wavhdr {
char riff[4]; // "RIFF"
SINT32 file_size; // in bytes
char wave[4]; // "WAVE"
char fmt[4]; // "fmt "
SINT32 chunk_size; // in bytes (16 for PCM)
SINT16 format_tag; // 1=PCM, 2=ADPCM, 3=IEEE float, 6=A-Law, 7=Mu-Law
SINT16 num_chans; // 1=mono, 2=stereo
SINT32 sample_rate;
SINT32 bytes_per_sec;
SINT16 bytes_per_samp; // 2=16-bit mono, 4=16-bit stereo
SINT16 bits_per_samp;
char data[4]; // "data"
SINT32 data_length; // in bytes
};
class AudioRecord
{
public:
AudioRecord();
void setSndSamplingRate(int smplRate);
/**
* Check if no otehr file is opened, then create a new one
* @param fileName A string containing teh file (with/without extension)
* @param type The sound file format (FILE_RAW, FILE_WAVE)
* @param format Internal sound format (INT16 / INT32)
*/
void openFile(std::string fileName, FILE_TYPE type, SOUND_FORMAT format);
/**
* Close the opend recording file. If wave: cout the number of byte
*/
void closeFile();
/**
* Check if a file is already opened
*/
bool isOpenFile();
/**
* Record a chunk of data in an openend file
* @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded
*/
void recData(SFLDataFormat* buffer, int nSamples); // TODO ad the data to rec
protected:
/**
* Set the header for raw files
*/
bool setRawFile(const char* fileName);
/**
* Set the header for wave files
*/
bool setWavFile(const char* fileName);
/**
* Compute the number of byte recorded and close the file
*/
void closeWavFile();
/**
* Pointer to the recorded file
*/
FILE *fp; //file pointer
/**
* File format (RAW / WAVE)
*/
FILE_TYPE fileType_;
/**
* Sound format (SINT16/SINT32)
*/
SOUND_FORMAT sndFormat_;
/**
* Number of channels
*/
int channels_;
/**
* Number f byte recorded
*/
unsigned long byteCounter_;
/**
* Sampling rate
*/
int sndSmplRate_;
};
......@@ -22,6 +22,7 @@
#include "audiolayer.h"
#include "audiostream.h"
#include "plug-in/audiorecorder/audiorecord.h"
#include <pulse/pulseaudio.h>
......
......@@ -37,6 +37,19 @@
typedef float float32;
typedef short int16;
//useful typedefs.
typedef signed short SINT16;
typedef signed int SINT32;
typedef unsigned long FILE_TYPE;
typedef unsigned long SOUND_FORMAT;
const FILE_TYPE FILE_RAW = 1;
const FILE_TYPE FILE_WAV = 2;
static const SOUND_FORMAT INT16 = 0x2; // TODO shold change these symbols
static const SOUND_FORMAT INT32 = 0x8;
#define SUCCESS 0
#define ASSERT( expected , value) if( value == expected ) return SUCCESS; \
......
include ../../globals.mak
SUBDIRS=audiorecorder
noinst_LTLIBRARIES = libplugin.la
SUBDIRS=test
libplugin_la_SOURCES = \
pluginmanager.cpp \
librarymanager.cpp
include $(top_srcdir)/globals.mak
noinst_LTLIBRARIES = libaudiorecorder.la
libaudiorecorder_la_SOURCES = \
audiorecord.cpp
/*
* Copyright (C) 2008 Savoir-Faire Linux inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "audiorecord.h"
AudioRecord::AudioRecord(){
sndSmplRate_ = 44100;
channels_ = 1;
byteCounter_ = 0;
}
void AudioRecord::setSndSamplingRate(int smplRate){
sndSmplRate_ = smplRate;
}
void AudioRecord::openFile(std::string fileName, FILE_TYPE type, SOUND_FORMAT format) {
channels_ =1;
fileType_ = type;
byteCounter_ = 0;
sndFormat_ = format;
bool result = false;
if(fileType_ == FILE_RAW){
result = setRawFile( fileName.c_str() );
}
else if (fileType_ == FILE_WAV){
result = setWavFile( fileName.c_str() );
}
}
void AudioRecord::closeFile() {
if (fp == 0) return;
if (fileType_ == FILE_RAW)
fclose(fp);
else if (fileType_ == FILE_WAV)
this->closeWavFile();
}
bool AudioRecord::isOpenFile() {
if(fp)
return true;
else
return false;
}
bool AudioRecord::setRawFile(const char *fileName) {
char name[8192];
strncpy(name, fileName, 8192);
if ( strstr(name, ".raw") == NULL) strcat(name, ".raw");
fp = fopen(name, "wb");
if ( !fp ) {
cout << "AudioRecord: could not create RAW file: " << name << '.';
return false;
}
if ( sndFormat_ != INT16 ) { // TODO need to change INT16 to SINT16
sndFormat_ = INT16;
cout << "AudioRecord: using 16-bit signed integer data format for file " << name << '.';
}
cout << "AudioRecord: creating RAW file: " << name;