Commit 03cc5544 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

nothing

parent b68cbde6
...@@ -29,9 +29,9 @@ SPEEX_FLAG= ...@@ -29,9 +29,9 @@ SPEEX_FLAG=
SPEEX_LIB= SPEEX_LIB=
endif endif
#SUBDIRS = ilbc #SUBDIRS = gsm
libaudio_la_SOURCES = audiofile.cpp tonelist.cpp \ libaudio_la_SOURCES = audiofile.cpp tonelist.cpp \
audiortp.cpp dtmf.cpp tone.cpp audiolayer.cpp audiodevice.cpp dtmfgenerator.cpp \ audiortp.cpp dtmf.cpp tone.cpp audiolayer.cpp audiodevice.cpp dtmfgenerator.cpp \
tonegenerator.cpp codecDescriptor.cpp \ tonegenerator.cpp codecDescriptor.cpp \
audioloop.cpp ringbuffer.cpp $(SPEEX_SOURCES_CPP) audioloop.cpp ringbuffer.cpp $(SPEEX_SOURCES_CPP)
...@@ -40,7 +40,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $ ...@@ -40,7 +40,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $
-DCODECS_DIR=\""$(sflcodecdir)"\" -DCODECS_DIR=\""$(sflcodecdir)"\"
libaudio_la_CPPFLAGS = $(SPEEX_FLAG) libaudio_la_CPPFLAGS = $(SPEEX_FLAG)
noinst_HEADERS = audioloop.h common.h ringbuffer.h audiofile.h \ noinst_HEADERS = audioloop.h common.h ringbuffer.h audiofile.h \
tonelist.h audiortp.h audiocodec.h audiolayer.h audiodevice.h \ tonelist.h audiortp.h audiocodec.h audiolayer.h audiodevice.h \
dtmfgenerator.h tonegenerator.h \ dtmfgenerator.h tonegenerator.h \
codecDescriptor.h dtmf.h tone.h \ codecDescriptor.h dtmf.h tone.h \
...@@ -63,8 +63,8 @@ uninstall-libcodec_ulaw_so: ...@@ -63,8 +63,8 @@ uninstall-libcodec_ulaw_so:
rm -f $(sflcodecdir)/libcodec_ulaw.so rm -f $(sflcodecdir)/libcodec_ulaw.so
uninstall-libcodec_alaw_so: uninstall-libcodec_alaw_so:
rm -f $(sflcodecdir)/libcodec_alaw.so rm -f $(sflcodecdir)/libcodec_alaw.so
uninstall-libcodec_gsm_so: #uninstall-libcodec_gsm_so:
rm -f $(sflcodecdir)/libcodec_gsm.so # rm -f $(sflcodecdir)/libcodec_gsm.so
uninstall-libcodec_speex_so: uninstall-libcodec_speex_so:
rm -f $(sflcodecdir)/libcodec_speex.so rm -f $(sflcodecdir)/libcodec_speex.so
rm -rf $(sflcodecdir) rm -rf $(sflcodecdir)
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
_channel = 1; _channel = 1;
} }
virtual ~Alaw(){}
virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) virtual int codecDecode (short *dst, unsigned char *src, unsigned int size)
{ {
int16* end = dst+size; int16* end = dst+size;
......
...@@ -97,13 +97,12 @@ AudioRtp::closeRtpSession () { ...@@ -97,13 +97,12 @@ AudioRtp::closeRtpSession () {
// AudioRtpRTX Class // // AudioRtpRTX Class //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AudioRtpRTX::AudioRtpRTX (SIPCall *sipcall, bool sym) AudioRtpRTX::AudioRtpRTX (SIPCall *sipcall, bool sym)
: _fstream("/tmp/audio.dat", std::ofstream::binary|std::ios::out|std::ios::app) : _fstream("/tmp/audio.gsm", std::ofstream::binary|std::ios::out|std::ios::app)
{ {
setCancel(cancelDeferred); setCancel(cancelDeferred);
time = new ost::Time(); time = new ost::Time();
_ca = sipcall; _ca = sipcall;
_sym = sym; _sym = sym;
//std::string s = "snd.dat";
// AudioRtpRTX should be close if we change sample rate // AudioRtpRTX should be close if we change sample rate
//_codecSampleRate = _ca->getAudioCodec()->getClockRate(); //_codecSampleRate = _ca->getAudioCodec()->getClockRate();
...@@ -141,7 +140,6 @@ AudioRtpRTX::~AudioRtpRTX () { ...@@ -141,7 +140,6 @@ AudioRtpRTX::~AudioRtpRTX () {
} }
//_debug("terminate audiortprtx ended...\n"); //_debug("terminate audiortprtx ended...\n");
_ca = 0; _ca = 0;
//fd = fopen("snd_data", "wa");
if (!_sym) { if (!_sym) {
delete _sessionRecv; _sessionRecv = NULL; delete _sessionRecv; _sessionRecv = NULL;
delete _sessionSend; _sessionSend = NULL; delete _sessionSend; _sessionSend = NULL;
...@@ -321,7 +319,6 @@ try { ...@@ -321,7 +319,6 @@ try {
// we have to get 20ms of data from the mic *20/1000 = /50 // we have to get 20ms of data from the mic *20/1000 = /50
int maxBytesToGet = _layerSampleRate * _layerFrameSize * sizeof(SFLDataFormat) / 1000; int maxBytesToGet = _layerSampleRate * _layerFrameSize * sizeof(SFLDataFormat) / 1000;
// available bytes inside ringbuffer // available bytes inside ringbuffer
int availBytesFromMic = audiolayer->canGetMic(); int availBytesFromMic = audiolayer->canGetMic();
...@@ -332,7 +329,6 @@ try { ...@@ -332,7 +329,6 @@ try {
int nbSample = audiolayer->getMic(_dataAudioLayer, bytesAvail) / sizeof(SFLDataFormat); int nbSample = audiolayer->getMic(_dataAudioLayer, bytesAvail) / sizeof(SFLDataFormat);
int nb_sample_up = nbSample; int nb_sample_up = nbSample;
int nbSamplesMax = _layerFrameSize * audiocodec->getClockRate() / 1000; int nbSamplesMax = _layerFrameSize * audiocodec->getClockRate() / 1000;
//_fstream.write((char*) _dataAudioLayer, nbSample);
nbSample = reSampleData(audiocodec->getClockRate(), nb_sample_up, DOWN_SAMPLING); nbSample = reSampleData(audiocodec->getClockRate(), nb_sample_up, DOWN_SAMPLING);
...@@ -348,6 +344,7 @@ try { ...@@ -348,6 +344,7 @@ try {
//_debug("AR: Nb sample: %d int, [0]=%d [1]=%d [2]=%d\n", nbSample, toSIP[0], toSIP[1], toSIP[2]); //_debug("AR: Nb sample: %d int, [0]=%d [1]=%d [2]=%d\n", nbSample, toSIP[0], toSIP[1], toSIP[2]);
// for the mono: range = 0 to RTP_FRAME2SEND * sizeof(int16) // for the mono: range = 0 to RTP_FRAME2SEND * sizeof(int16)
// codecEncode(char *dest, int16* src, size in bytes of the src) // codecEncode(char *dest, int16* src, size in bytes of the src)
//int compSize = audiocodec->codecEncode(_sendDataEncoded, toSIP, nbSample*sizeof(int16));
int compSize = audiocodec->codecEncode(_sendDataEncoded, toSIP, nbSample*sizeof(int16)); int compSize = audiocodec->codecEncode(_sendDataEncoded, toSIP, nbSample*sizeof(int16));
//printf("jusqu'ici tout vas bien\n"); //printf("jusqu'ici tout vas bien\n");
...@@ -401,7 +398,7 @@ try { ...@@ -401,7 +398,7 @@ try {
audiocodec = loadCodec(payload); audiocodec = loadCodec(payload);
// Decode data with relevant codec // Decode data with relevant codec
_codecSampleRate = audiocodec->getClockRate(); _codecSampleRate = audiocodec->getClockRate();
int max = (int)(_codecSampleRate * _layerFrameSize); int max = (int)(_codecSampleRate * _layerFrameSize / 1000);
if ( size > max ) { if ( size > max ) {
_debug("We have received from RTP a packet larger than expected: %s VS %s\n", size, max); _debug("We have received from RTP a packet larger than expected: %s VS %s\n", size, max);
...@@ -413,6 +410,7 @@ try { ...@@ -413,6 +410,7 @@ try {
if (audiocodec != NULL) { if (audiocodec != NULL) {
int expandedSize = audiocodec->codecDecode(_receiveDataDecoded, data, size); int expandedSize = audiocodec->codecDecode(_receiveDataDecoded, data, size);
_fstream.write((char*) _receiveDataDecoded, 160);
//buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes //buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes
int nbInt16 = expandedSize / sizeof(int16); int nbInt16 = expandedSize / sizeof(int16);
//nbInt16 represents the number of samples we just decoded //nbInt16 represents the number of samples we just decoded
...@@ -569,7 +567,7 @@ try { ...@@ -569,7 +567,7 @@ try {
Thread::sleep(TimerPort::getTimer()); Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms
} }
//_fstream.close(); _fstream.close();
//_debug("stop stream for audiortp loop\n"); //_debug("stop stream for audiortp loop\n");
audiolayer->stopStream(); audiolayer->stopStream();
} catch(std::exception &e) { } catch(std::exception &e) {
......
...@@ -19,54 +19,94 @@ ...@@ -19,54 +19,94 @@
*/ */
#include <iostream> #include <iostream>
extern "C" {
#include <gsm/gsm.h> #include <gsm/gsm.h>
}
#include "audiocodec.h" #include "audiocodec.h"
#include "../global.h" #include "../global.h"
#define GSM_PACKED_FRAME_SIZE_IN_BYTES 33
#define GSM_UNPACKED_FRAME_SIZE_IN_BYTES 320
#define GSM_UNPACKED_FRAME_SIZE_IN_SHORTS 160
/*
void * GSMCodecHandle = 0;
void* (*gsm_session_create)() = 0;
void (*gsm_session_destroy)(void *) = 0;
void (*gsm_session_encode)(void*, unsigned char*, short*) = 0 ;
int (*gsm_session_decode)(void*, short* , unsigned char*) = 0 ;
*/
class Gsm : public AudioCodec { class Gsm : public AudioCodec {
public: public:
// 3 GSM A 8000 1 [RFC3551] // 3 GSM A 8000 1 [RFC3551]
Gsm(int payload = 0) Gsm(int payload = 0)
: AudioCodec(payload, "GSM") : AudioCodec(payload, "GSM")
{ {
//_description = "GSM";
_clockRate = 8000; _clockRate = 8000;
_channel = 1; _channel = 1;
//initGSMStruct();
if (!(_decode_gsmhandle = gsm_create() )) if (!(_decode_gsmhandle = gsm_create() ))
_debug("ERROR: decode_gsm_create\n"); _debug("ERROR: decode_gsm_create\n");
if (!(_encode_gsmhandle = gsm_create() )) if (!(_encode_gsmhandle = gsm_create() ))
_debug("AudioCodec: ERROR: encode_gsm_create\n"); _debug("AudioCodec: ERROR: encode_gsm_create\n");
//_encode_state = gsm_session_create();
//_decode_state = gsm_session_create();
} }
~Gsm (void) ~Gsm (void)
{ {
//gsm_session_destroy(_decode_state);
//gsm_session_destroy(_encode_state);
gsm_destroy(_decode_gsmhandle); gsm_destroy(_decode_gsmhandle);
gsm_destroy(_encode_gsmhandle); gsm_destroy(_encode_gsmhandle);
} }
/*
bool initGSMStruct()
{
if(GSMCodecHandle) return true;
GSMCodecHandle = dlopen("libgsm.so", RTLD_NOW | RTLD_GLOBAL);
if(!GSMCodecHandle) return false;
gsm_session_create = (void * (*)()) dlsym(GSMCodecHandle, "gsm_create");
gsm_session_destroy = (void (*) (void *)) dlsym(GSMCodecHandle, "gsm_destroy");
gsm_session_encode = ( void (*) (void*, unsigned char*, short*)) dlsym(GSMCodecHandle, "gsm_encode");
gsm_session_decode = (int (*) (void*, short*, unsigned char*)) dlsym(GSMCodecHandle, "gsm_decode");
if(!(gsm_session_create && gsm_session_destroy && gsm_session_encode && gsm_session_decode)){
dlclose(GSMCodecHandle);
GSMCodecHandle = 0 ;
return false;}
return true;
}*/
virtual int codecDecode (short *dst, unsigned char *src, unsigned int size) virtual int codecDecode (short *dst, unsigned char *src, unsigned int size)
{ {
(void)size; if(gsm_decode(_decode_gsmhandle, (gsm_byte *)src, (gsm_signal*)dst) < 0)
if (gsm_decode(_decode_gsmhandle, (gsm_byte*)src, (gsm_signal*)dst) < 0) { return 0;
_debug("ERROR: gsm_decode\n");
} return GSM_UNPACKED_FRAME_SIZE_IN_BYTES;
return 320;
} }
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) virtual int codecEncode (unsigned char *dst, short *src, unsigned int size)
{ {
(void)size; if(size < GSM_UNPACKED_FRAME_SIZE_IN_BYTES) return 0;
gsm_encode(_encode_gsmhandle, (gsm_signal*)src, (gsm_byte*)dst); //if (gsm_session_encode( gsm_signal*)src, (gsm_byte*)dst);
return 33; gsm_encode( _encode_gsmhandle, (gsm_signal*)src, (gsm_byte*) dst);
return GSM_PACKED_FRAME_SIZE_IN_BYTES;
} }
private: private:
gsm _decode_gsmhandle; gsm _decode_gsmhandle;
gsm _encode_gsmhandle; gsm _encode_gsmhandle;
//void * _encode_state;
//void * _decode_state;
}; };
...@@ -78,3 +118,4 @@ extern "C" AudioCodec* create() { ...@@ -78,3 +118,4 @@ extern "C" AudioCodec* create() {
extern "C" void destroy(AudioCodec* a) { extern "C" void destroy(AudioCodec* a) {
delete a; delete a;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment