Commit f9b4bdd7 authored by Guillaume Carmel-Archambault's avatar Guillaume Carmel-Archambault
Browse files
parents 3b679fbf 22c7a6a2
sflcodecdir = ($libdir)/sflphone/codecs
bin_PROGRAMS = sflphoned
#bin_SCRIPTS = sflphone
if USE_ZEROCONF
ZEROCONFDIR = zeroconf
......@@ -40,7 +41,8 @@ sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone
#sflphoned_LDFLAGS = -static
sflphoned_LDADD = ./libsflphone.la $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) $(IAX_LIBS) $(EXOSIP_LIBS)
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(IAX_CFLAGS) $(USER_INCLUDES) $(libdbuscpp_CFLAGS)
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(IAX_CFLAGS) $(USER_INCLUDES) $(libdbuscpp_CFLAGS) \
-DCODECS_DIR=\""$(sflcodecdir)"\"
# libsflphone_la_LDFLAGS= -version-info 0:1:0
......
#SUBDIRS = gsm
sflcodecdir = $(libdir)/sflphone/codecs/
noinst_LTLIBRARIES = libaudio.la
noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_gsm.so
libcodec_ulaw_so_SOURCES = ulaw.cpp
libcodec_ulaw_so_CFLAGS = -fPIC -g -Wall
libcodec_ulaw_so_LDFLAGS = -shared
libcodec_alaw_so_SOURCES = alaw.cpp
libcodec_alaw_so_CFLAGS = -fPIC -g -Wall
libcodec_alaw_so_LDFLAGS = -shared
libcodec_gsm_so_SOURCES = gsmcodec.cpp
libcodec_gsm_so_CFLAGS = -fPIC -g -Wall
libcodec_gsm_so_LDFLAGS = -shared -lgsm
if USE_SPEEX
SPEEX_SOURCES_CPP=CodecSpeex.cpp
......@@ -17,13 +30,31 @@ audiortp.cpp dtmf.cpp tone.cpp audiolayer.cpp audiodevice.cpp dtmfge
tonegenerator.cpp codecDescriptor.cpp \
audioloop.cpp ringbuffer.cpp $(SPEEX_SOURCES_CPP)
AM_CXXFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libdbuscpp_CFLAGS) $(libccrtp1_CFLAGS) $(USER_INCLUDES)
#libaudio_la_LIBADD = gsm/libgsm.la $(SPEEX_LIB)
AM_CXXFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libdbuscpp_CFLAGS) $(libccrtp1_CFLAGS) $(USER_INCLUDES) \
-DCODECS_DIR=\""$(sflcodecdir)"\"
libaudio_la_CPPFLAGS = $(SPEEX_FLAG)
noinst_HEADERS = audioloop.h common.h ringbuffer.h audiofile.h \
tonelist.h audiortp.h audiocodec.h audiolayer.h audiodevice.h \
dtmfgenerator.h tonegenerator.h \
codecDescriptor.h dtmf.h tone.h \
CodecSpeex.h
install-exec-local: install-libcodec_ulaw_so install-libcodec_alaw_so install-libcodec_gsm_so
uninstall-local: uninstall-libcodec_ulaw_so uninstall-libcodec_alaw_so uninstall-libcodec_gsm_so
install-libcodec_ulaw_so: libcodec_ulaw.so
mkdir -p $(sflcodecdir)
$(INSTALL_PROGRAM) libcodec_ulaw.so $(sflcodecdir)
install-libcodec_alaw_so: libcodec_alaw.so
$(INSTALL_PROGRAM) libcodec_alaw.so $(sflcodecdir)
install-libcodec_gsm_so: libcodec_gsm.so
$(INSTALL_PROGRAM) libcodec_gsm.so $(sflcodecdir)
uninstall-libcodec_ulaw_so:
rm -f $(sflcodecdir)/libcodec_ulaw.so
uninstall-libcodec_alaw_so:
rm -f $(sflcodecdir)/libcodec_alaw.so
uninstall-libcodec_gsm_so:
rm -f $(sflcodecdir)/libcodec_gsm.so
rm -rf $(sflcodecdir)
How to build the codec shared libraries
---------------------------------------
CODEC_ALAW:
gcc -fPIC -g -c -Wall ulaw.cpp
-------> gives you the object file ulaw.o.
-------> option -g to include debug information
-------> option -Wall to generate warnings
-------> option -fPIC to enable position independant code generation
gcc -shared -o libcodec_ulaw.so ulaw.o -lc
-------> creates the shared library
CODEC ALAW:
idem
CODEC_GSM:
gcc -fPIC -g -c -Wall gsmcodec.cpp
gcc -shared -o -libcodec_gsm.so gsmcodec.o -lc -lgsm
-------> You need the standard library libgsm1 installed (with dev package).
REFERENCES: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
The shared library should be installed in $(libdir)/sflphone/codecs where libdir=$(PREFIX)/lib.
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
*
* This 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,
* or (at your option) any later version.
*
* This 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 dpkg; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <iostream>
#include <string>
#include "audiocodec.h"
AudioCodec::AudioCodec (int payload, const std::string &codecName)
: _codecName(codecName)
{
_payload = payload;
_clockRate = 8000; // default
_channel = 1; // default
_active = false;
_hasDynamicPayload = (_payload >= 96 && _payload <= 127) ? true : false;
}
AudioCodec::~AudioCodec (void)
{
}
......@@ -31,12 +31,11 @@ AudioFile::AudioFile()
: AudioLoop()
{
// could vary later...
//_ulaw = new Ulaw(PAYLOAD_CODEC_ULAW);
_start = false;
using std::cout;
using std::cerr;
void* codec = dlopen("codec_ulaw.so", RTLD_LAZY);
void* codec = dlopen( CODECS_DIR "/libcodec_ulaw.so", RTLD_LAZY);
if(!codec){
cerr<<"cannot load library: "<< dlerror() <<'\n';
}
......
......@@ -259,16 +259,16 @@ AudioRtpRTX::loadCodec(int payload)
switch(payload){
case 0:
handle_codec = dlopen("codec_ulaw.so", RTLD_LAZY);
handle_codec = dlopen( CODECS_DIR "/libcodec_ulaw.so", RTLD_LAZY);
break;
case 3:
handle_codec = dlopen("codec_gsm.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_gsm.so", RTLD_LAZY);
break;
case 8:
handle_codec = dlopen("codec_alaw.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_alaw.so", RTLD_LAZY);
break;
case 97:
handle_codec = dlopen("codec_ilbc.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_ilbc.so", RTLD_LAZY);
break;
}
......
/**
* Copyright (C) 2005 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
Implementation of ITU-T (formerly CCITT) Recomendation G711
Copyright (C) 2004 J.D.Medhurst (a.k.a. Tixy)
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library 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 Library General Public
* License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
#include "common.h"
#include "g711.h"
/*
Members of class G711
*/
uint8 G711::ALawEncode(int16 pcm16)
{
int p = pcm16;
uint a; // A-law value we are forming
if(p<0)
{
// -ve value
// Note, ones compliment is here used here as this keeps encoding symetrical
// and equal spaced around zero cross-over, (it also matches the standard).
p = ~p;
a = 0x00; // sign = 0
}
else
{
// +ve value
a = 0x80; // sign = 1
}
// Calculate segment and interval numbers
p >>= 4;
if(p>=0x20)
{
if(p>=0x100)
{
p >>= 4;
a += 0x40;
}
if(p>=0x40)
{
p >>= 2;
a += 0x20;
}
if(p>=0x20)
{
p >>= 1;
a += 0x10;
}
}
// a&0x70 now holds segment value and 'p' the interval number
a += p; // a now equal to encoded A-law value
return a^0x55; // A-law has alternate bits inverted for transmission
}
int G711::ALawDecode(uint8 alaw)
{
alaw ^= 0x55; // A-law has alternate bits inverted for transmission
uint sign = alaw&0x80;
int linear = alaw&0x1f;
linear <<= 4;
linear += 8; // Add a 'half' bit (0x08) to place PCM value in middle of range
alaw &= 0x7f;
if(alaw>=0x20)
{
linear |= 0x100; // Put in MSB
uint shift = (alaw>>4)-1;
linear <<= shift;
}
if(!sign)
return -linear;
else
return linear;
}
uint8 G711::ULawEncode(int16 pcm16)
{
int p = pcm16;
uint u; // u-law value we are forming
if(p<0)
{
// -ve value
// Note, ones compliment is here used here as this keeps encoding symetrical
// and equal spaced around zero cross-over, (it also matches the standard).
p = ~p;
u = 0x80^0x10^0xff; // Sign bit = 1 (^0x10 because this will get inverted later) ^0xff ^0xff to invert final u-Law code
}
else
{
// +ve value
u = 0x00^0x10^0xff; // Sign bit = 0 (-0x10 because this amount extra will get added later) ^0xff to invert final u-Law code
}
p += 0x84; // Add uLaw bias
if(p>0x7f00)
p = 0x7f00; // Clip to 15 bits
// Calculate segment and interval numbers
p >>= 3; // Shift down to 13bit
if(p>=0x100)
{
p >>= 4;
u ^= 0x40;
}
if(p>=0x40)
{
p >>= 2;
u ^= 0x20;
}
if(p>=0x20)
{
p >>= 1;
u ^= 0x10;
}
// (u^0x10)&0x70 now equal to the segment value and 'p' the interval number (^0x10)
u ^= p; // u now equal to encoded u-law value (with all bits inverted)
return u;
}
int G711::ULawDecode(uint8 ulaw)
{
ulaw ^= 0xff; // u-law has all bits inverted for transmission
int linear = ulaw&0x0f;
linear <<= 3;
linear |= 0x84; // Set MSB (0x80) and a 'half' bit (0x04) to place PCM value in middle of range
uint shift = ulaw>>4;
shift &= 7;
linear <<= shift;
linear -= 0x84; // Subract uLaw bias
if(ulaw&0x80)
return -linear;
else
return linear;
}
uint8 G711::ALawToULaw(uint8 alaw)
{
uint8 sign=alaw&0x80;
alaw ^= sign;
alaw ^= 0x55;
uint ulaw;
if(alaw<45)
{
if(alaw<24)
ulaw = (alaw<8) ? (alaw<<1)+1 : alaw+8;
else
ulaw = (alaw<32) ? (alaw>>1)+20 : alaw+4;
}
else
{
if(alaw<63)
ulaw = (alaw<47) ? alaw+3 : alaw+2;
else
ulaw = (alaw<79) ? alaw+1 : alaw;
}
ulaw ^= sign;
return ulaw^0x7f;
}
uint8 G711::ULawToALaw(uint8 ulaw)
{
uint8 sign=ulaw&0x80;
ulaw ^= sign;
ulaw ^= 0x7f;
uint alaw;
if(ulaw<48)
{
if(ulaw<=32)
alaw = (ulaw<=15) ? ulaw>>1 : ulaw-8;
else
alaw = (ulaw<=35) ? (ulaw<<1)-40 : ulaw-4;
}
else
{
if(ulaw<=63)
alaw = (ulaw==48) ? ulaw-3 : ulaw-2;
else
alaw = (ulaw<=79) ? ulaw-1 : ulaw;
}
alaw ^= sign;
return alaw^0x55;
}
uint G711::ALawEncode(uint8* dst, int16* src, uint srcSize)
{
srcSize >>= 1;
uint8* end = dst+srcSize;
while(dst<end)
*dst++ = ALawEncode(*src++);
return srcSize;
}
uint G711::ALawDecode(int16* dst, uint8* src, uint srcSize)
{
int16* end = dst+srcSize;
while(dst<end)
*dst++ = ALawDecode(*src++);
return srcSize<<1;
}
uint G711::ULawEncode(uint8* dst, int16* src, uint srcSize)
{
srcSize >>= 1;
uint8* end = dst+srcSize;
while(dst<end)
*dst++ = ULawEncode(*src++);
return srcSize;
}
uint G711::ULawDecode(int16* dst, uint8* src, uint srcSize)
{
int16* end = dst+srcSize;
while(dst<end)
*dst++ = ULawDecode(*src++);
return srcSize<<1;
}
uint G711::ALawToULaw(uint8* dst, uint8* src, uint srcSize)
{
uint8* end = dst+srcSize;
while(dst<end)
*dst++ = ALawToULaw(*src++);
return srcSize;
}
uint G711::ULawToALaw(uint8* dst, uint8* src, uint srcSize)
{
uint8* end = dst+srcSize;
while(dst<end)
*dst++ = ULawToALaw(*src++);
return srcSize;
}
/**
* Copyright (C) 2005 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
Implementation of ITU-T (formerly CCITT) Recomendation G711
Copyright (C) 2004 J.D.Medhurst (a.k.a. Tixy)
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library 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 Library General Public
* License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
#ifndef __G711_H__
#define __G711_H__
#include "common.h"
/**
A class which implements ITU-T (formerly CCITT) Recomendation G711
"Pulse Code Modulation (PCM) of Voice Frequencies"
This encodes and decodes uniform PCM values to/from 8 bit A-law and u-Law values.
Note, the methods in this class use uniform PCM values which are of 16 bits precision,
these are 'left justified' values corresponding to the 13 and 14 bit values described
in G711.
*/
class G711
{
public:
/**
Encode a 16 bit uniform PCM value into an A-Law value
@param pcm16 A 16 bit uniform PCM value (sign extented into an int).
If the value doesn't lie in the range -32768 to 32767 then the
result is undefined.
@return The A-Law encoded value corresponding to pcm16
*/
static uint8 ALawEncode(int16 pcm16);
/**
Encode an A-Law value into a 16 bit uniform PCM value
@param alaw An A-Law encoded value
@return The 16 bit uniform PCM value corresponding to alaw
*/
static int ALawDecode(uint8 alaw);
/**
Encode a 16 bit uniform PCM value into an u-Law value
@param pcm16 A 16 bit uniform PCM value (sign extented into an int)
If the value doesn't lie in the range -32768 to 32767 then the
result is undefined.
@return The u-Law encoded value corresponding to pcm16
*/
static uint8 ULawEncode(int16 pcm16);
/**
Encode an u-Law value into a 16 bit uniform PCM value
@param ulaw An u-Law encoded value
@return The 16 bit uniform PCM value corresponding to ulaw
*/
static int ULawDecode(uint8 ulaw);
/**
Convert an A-Law value into a u-law value.
@param alaw An A-Law encoded value
@return The u-law value.
*/
static uint8 ALawToULaw(uint8 alaw);
/**
Convert a u-Law value into an A-law value.
@param ulaw An u-Law encoded value
@return The A-Law value
*/
static uint8 ULawToALaw(uint8 ulaw);
/**
Encode a buffer of 16 bit uniform PCM values into A-Law values
@param dst Pointer to location to store A-Law encoded values
@param src Pointer to the buffer of 16 bit uniform PCM values to be encoded
@param srcSize The size in bytes of the src buffer
@return The number of bytes which were stored at dst (equal to srcSize>>1)
*/
static uint ALawEncode(uint8* dst, int16* src, uint srcSize);
/**
Decode a buffer of A-Law values into 16 bit uniform PCM values
@param dst Pointer to location to store decoded 16 bit uniform PCM values
@param src Pointer to the buffer of A-Law values to be decoded
@param srcSize The size in bytes of the src buffer
@return The number of bytes which were stored at dst (equal to srcSize<<1)
*/
static uint ALawDecode(int16* dst, uint8* src, uint srcSize);
/**
Encode a buffer of 16 bit uniform PCM values into u-Law values
@param dst Pointer to location to store u-Law encoded values
@param src Pointer to the buffer of 16 bit uniform PCM values to be encoded
@param srcSize The size in bytes of the src buffer
@return The number of bytes which were stored at dst (equal to srcSize>>1)
*/
static uint ULawEncode(uint8* dst, int16* src, uint srcSize);
/**
Decode a buffer of u-Law values into 16 bit uniform PCM values
@param dst Pointer to location to store decoded 16 bit uniform PCM values
@param src Pointer to the buffer of u-Law values to be decoded
@param srcSize The size in bytes of the src buffer
@return The number of bytes which were stored at dst (equal to srcSize<<1)
*/
static uint ULawDecode(int16* dst, uint8* src, uint srcSize);
/**
Convert a buffer of A-Law value into u-law values.
@param dst Pointer to location to store u-law values
@param src Pointer to the buffer of A-Law values to be converted
@param srcSize The size in bytes of the src buffer
@return The number of bytes which were stored at dst (equal to srcSize)
*/
static uint ALawToULaw(uint8* dst, uint8* src, uint srcSize);
/**
Convert a buffer of u-Law value into A-law values.
@param dst Pointer to location to store A-law values
@param src Pointer to the buffer of u-Law values to be converted
@param srcSize The size in bytes of the src buffer
@return The number of bytes which were stored at dst (equal to srcSize)
*/
static uint ULawToALaw(uint8* dst, uint8* src, uint srcSize);
};
#endif
......@@ -236,16 +236,16 @@ IAXVoIPLink::loadCodec(int payload)
switch(payload)
{
case 0:
handle_codec = dlopen("codec_ulaw.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_ulaw.so", RTLD_LAZY);
break;
case 3:
handle_codec = dlopen("codec_gsm.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_gsm.so", RTLD_LAZY);
break;
case 8:
handle_codec = dlopen("codec_alaw.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_alaw.so", RTLD_LAZY);
break;
case 97:
handle_codec = dlopen("codec_ilbc.so", RTLD_LAZY);
handle_codec = dlopen(CODECS_DIR "/libcodec_ilbc.so", RTLD_LAZY);
break;
}
if(!handle_codec){
......