Skip to content
Snippets Groups Projects
Commit 7bce87d6 authored by Alexandre Bourget's avatar Alexandre Bourget
Browse files

DEBUG: Add debugging facilities, TO BE REMOVED.

parent 04e796ac
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
#include <math.h> #include <math.h>
/** @todo Remove the fstream and iostream stuff */
#include <fstream> // fstream + iostream pour fstream debugging..
#include <iostream> // removeable...
#define IAX_BLOCKING 1 #define IAX_BLOCKING 1
#define IAX_NONBLOCKING 0 #define IAX_NONBLOCKING 0
...@@ -50,6 +55,7 @@ ...@@ -50,6 +55,7 @@
IAXVoIPLink::IAXVoIPLink(const AccountID& accountID) IAXVoIPLink::IAXVoIPLink(const AccountID& accountID)
: VoIPLink(accountID) : VoIPLink(accountID)
, _fstream("/tmp/audio.dat", std::ofstream::binary) /** @todo Remove this */
{ {
_evThread = new EventThread(this); _evThread = new EventThread(this);
_regSession = NULL; _regSession = NULL;
...@@ -216,7 +222,7 @@ IAXVoIPLink::getEvent() ...@@ -216,7 +222,7 @@ IAXVoIPLink::getEvent()
void void
IAXVoIPLink::sendAudioFromMic(void) IAXVoIPLink::sendAudioFromMic(void)
{ {
IAXCall* currentCall = dynamic_cast<IAXCall*>(getCall(Manager::instance().getCurrentCallId())); IAXCall* currentCall = getIAXCall(Manager::instance().getCurrentCallId());
AudioCodec* audiocodec = NULL; AudioCodec* audiocodec = NULL;
if (!currentCall) { if (!currentCall) {
...@@ -225,7 +231,12 @@ IAXVoIPLink::sendAudioFromMic(void) ...@@ -225,7 +231,12 @@ IAXVoIPLink::sendAudioFromMic(void)
} }
// Just make sure the currentCall is in state to receive audio right now. // Just make sure the currentCall is in state to receive audio right now.
if (currentCall->getConnectionState() != Call::Connected) { //_debug("Here we get: connectionState: %d state: %d \n",
// currentCall->getConnectionState(),
// currentCall->getState());
if (currentCall->getConnectionState() != Call::Connected ||
currentCall->getState() != Call::Active) {
return; return;
} }
...@@ -247,15 +258,21 @@ IAXVoIPLink::sendAudioFromMic(void) ...@@ -247,15 +258,21 @@ IAXVoIPLink::sendAudioFromMic(void)
// rate/50 shall be lower than IAX__20S_48KHZ_MAX // rate/50 shall be lower than IAX__20S_48KHZ_MAX
int maxBytesToGet = audiolayer->getSampleRate()/50*sizeof(SFLDataFormat); int maxBytesToGet = audiolayer->getSampleRate()/50*sizeof(SFLDataFormat);
// We want at least 70% of a packet, because we want 20ms chunks
//int minBytesToGet = maxBytesToGet * 70 / 100;
// available bytes inside ringbuffer // available bytes inside ringbuffer
int availBytesFromMic = audiolayer->canGetMic(); int availBytesFromMic = audiolayer->canGetMic();
// take the lowest // take the lowest
int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet; int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet;
//_debug("available = %d, maxBytesToGet = %d\n", availBytesFromMic, maxBytesToGet); _debug("available = %d, maxBytesToGet = %d\n", availBytesFromMic, maxBytesToGet);
// Get bytes from micRingBuffer to data_from_mic // Get bytes from micRingBuffer to data_from_mic
int nbSample = audiolayer->getMic(_dataAudioLayer, bytesAvail) / sizeof(SFLDataFormat); int nbSample = audiolayer->getMic(_dataAudioLayer, bytesAvail) / sizeof(SFLDataFormat);
// Audio ici est PARFAIT
int16* toIAX = NULL; int16* toIAX = NULL;
if (audiolayer->getSampleRate() != audiocodec->getClockRate() && nbSample) { if (audiolayer->getSampleRate() != audiocodec->getClockRate() && nbSample) {
SRC_DATA src_data; SRC_DATA src_data;
...@@ -266,6 +283,8 @@ IAXVoIPLink::sendAudioFromMic(void) ...@@ -266,6 +283,8 @@ IAXVoIPLink::sendAudioFromMic(void)
src_data.data_in = _floatBuffer48000; src_data.data_in = _floatBuffer48000;
#endif #endif
// Audio parfait à ce point.
double factord = (double) audiocodec->getClockRate() / audiolayer->getSampleRate(); double factord = (double) audiocodec->getClockRate() / audiolayer->getSampleRate();
src_data.src_ratio = factord; src_data.src_ratio = factord;
...@@ -278,8 +297,13 @@ IAXVoIPLink::sendAudioFromMic(void) ...@@ -278,8 +297,13 @@ IAXVoIPLink::sendAudioFromMic(void)
nbSample = src_data.output_frames_gen; nbSample = src_data.output_frames_gen;
// Bon, l'audio en float 8000 est laid mais yé consistant.
src_float_to_short_array (_floatBuffer8000, _intBuffer8000, nbSample); src_float_to_short_array (_floatBuffer8000, _intBuffer8000, nbSample);
toIAX = _intBuffer8000; toIAX = _intBuffer8000;
// Audio bon ici aussi..
} else { } else {
#ifdef DATAFORMAT_IS_FLOAT #ifdef DATAFORMAT_IS_FLOAT
// convert _receiveDataDecoded to float inside _receiveData // convert _receiveDataDecoded to float inside _receiveData
...@@ -291,18 +315,32 @@ IAXVoIPLink::sendAudioFromMic(void) ...@@ -291,18 +315,32 @@ IAXVoIPLink::sendAudioFromMic(void)
#endif #endif
} }
// DEBUG
_fstream.write((char *) toIAX, nbSample*sizeof(int16));
_fstream.flush();
// NOTE: L'audio ici est bon.
// LE PROBLÈME est dans cette snippet de fonction:
if ( nbSample < (IAX__20S_8KHZ_MAX - 10) ) { // if only 10 is missing, it's ok if ( nbSample < (IAX__20S_8KHZ_MAX - 10) ) { // if only 10 is missing, it's ok
// fill end with 0... // fill end with 0...
//_debug("begin: %p, nbSample: %d\n", toIAX, nbSample); _debug("begin: %p, nbSample: %d\n", toIAX, nbSample);
//_debug("has to fill: %d chars at %p\n", (IAX__20S_8KHZ_MAX-nbSample)*sizeof(int16), toIAX + nbSample); _debug("has to fill: %d chars at %p\n", (IAX__20S_8KHZ_MAX-nbSample)*sizeof(int16), toIAX + nbSample);
memset(toIAX + nbSample, 0, (IAX__20S_8KHZ_MAX-nbSample)*sizeof(int16)); memset(toIAX + nbSample, 0, (IAX__20S_8KHZ_MAX-nbSample)*sizeof(int16));
nbSample = IAX__20S_8KHZ_MAX; nbSample = IAX__20S_8KHZ_MAX;
} }
//_debug("AR: Nb sample: %d int, [0]=%d [1]=%d [2]=%d\n", nbSample, toIAX[0], toIAX[1], toIAX[2]); //_debug("AR: Nb sample: %d int, [0]=%d [1]=%d [2]=%d\n", nbSample, toIAX[0], toIAX[1], toIAX[2]);
// NOTE: Le son dans toIAX (nbSamle*sizeof(int16)) est mauvais.
// for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16) // for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16)
int compSize = audiocodec->codecEncode(_sendDataEncoded, toIAX, nbSample*sizeof(int16)); int compSize = audiocodec->codecEncode(_sendDataEncoded, toIAX, nbSample*sizeof(int16));
// Send it out! // Send it out!
_mutexIAX.enterMutex(); _mutexIAX.enterMutex();
// Make sure the session and the call still exists. // Make sure the session and the call still exists.
...@@ -331,7 +369,7 @@ IAXVoIPLink::getIAXCall(const CallID& id) ...@@ -331,7 +369,7 @@ IAXVoIPLink::getIAXCall(const CallID& id)
if (call) { if (call) {
return dynamic_cast<IAXCall*>(call); return dynamic_cast<IAXCall*>(call);
} }
return 0; return NULL;
} }
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include "global.h" #include "global.h"
#include <samplerate.h> #include <samplerate.h>
/** @todo Remove this fstream/iostream stuff */
#include <fstream> // fstream + iostream for _fstream debugging...
#include <iostream>
class EventThread; class EventThread;
class IAXCall; class IAXCall;
...@@ -203,8 +207,10 @@ private: ...@@ -203,8 +207,10 @@ private:
/** libsamplerate error */ /** libsamplerate error */
int _src_err; int _src_err;
/** Current IAX call pointer, used for sending, change when starting audio, switching */ /** Debugging output file
//IAXCall* _currentCall; * @todo Remove this */
std::ofstream _fstream;
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment