Commit d04edd7d authored by Alexandre Bourget's avatar Alexandre Bourget
Browse files

Règle le problème de transmission audio quand c'est l'appel COURANT (currentCall)

Le tout est synchronisé avec le Manager, pour qu'on traite l'audio
et qu'on prenne le micro seulement quand c'est notre appel qui est en
cours.
parent 1a68b3ad
...@@ -166,13 +166,12 @@ IAXVoIPLink::terminateIAXCall() ...@@ -166,13 +166,12 @@ IAXVoIPLink::terminateIAXCall()
void void
IAXVoIPLink::getEvent() IAXVoIPLink::getEvent()
{ {
// mutex here IAXCall* call = NULL;
_mutexIAX.enterMutex();
// lock iax_ stuff..
_mutexIAX.enterMutex();
iax_event* event = NULL; iax_event* event = NULL;
IAXCall* call = NULL;
while ( (event = iax_get_event(IAX_NONBLOCKING)) != NULL ) { while ( (event = iax_get_event(IAX_NONBLOCKING)) != NULL ) {
// If we received an 'ACK', libiax2 tells apps to ignore them. // If we received an 'ACK', libiax2 tells apps to ignore them.
if (event->etype == IAX_EVENT_NULL) { if (event->etype == IAX_EVENT_NULL) {
continue; continue;
...@@ -183,31 +182,66 @@ IAXVoIPLink::getEvent() ...@@ -183,31 +182,66 @@ IAXVoIPLink::getEvent()
call = iaxFindCallBySession(event->session); call = iaxFindCallBySession(event->session);
if (call) { if (call) {
// We know that call, deal with it
//_debug(" - We've got an associated call, handle call event\n");
iaxHandleCallEvent(event, call); iaxHandleCallEvent(event, call);
}
} else if (event->session && event->session == _regSession) { else if (event->session && event->session == _regSession) {
// This is a registration session, deal with it
//_debug(" - We've got an associated REGISTRATION session, handle registration process\n");
// in iaxclient, there is many session handling, here, only one
iaxHandleRegReply(event); iaxHandleRegReply(event);
}
} else { else {
// We've got an event before it's associated with any call
//_debug (" - We've got some other event, deal with them alone.\n");
iaxHandlePrecallEvent(event); iaxHandlePrecallEvent(event);
} }
iax_event_free(event); iax_event_free(event);
} }
_mutexIAX.leaveMutex(); _mutexIAX.leaveMutex();
// Do the doodle-moodle to send audio from the microphone to the IAX channel.
sendAudioFromMic();
// Refresh registration.
if (_nextRefreshStamp && _nextRefreshStamp - 2 < time(NULL)) {
setRegister();
}
// thread wait 5 millisecond
_evThread->sleep(5);
}
void
IAXVoIPLink::sendAudioFromMic(void)
{
IAXCall* currentCall = dynamic_cast<IAXCall*>(getCall(Manager::instance().getCurrentCallId()));
AudioCodec* audiocodec = NULL;
if (!currentCall) {
// Let's mind our own business.
return;
}
// Just make sure the currentCall is in state to receive audio right now.
if (currentCall->getConnectionState() != Call::Connected) {
return;
}
audiocodec = currentCall->getAudioCodec();
if (!audiocodec) {
// Audio codec still not determined.
if (audiolayer) {
// To keep latency low..
audiolayer->flushMic();
}
return;
}
// Send sound here // Send sound here
if (_currentCall && audiolayer) { if (audiolayer) {
AudioCodec* audiocodec = _currentCall->getAudioCodec();
// 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
// rate/50 shall be lower than IAX__20S_48KHZ_MAX // rate/50 shall be lower than IAX__20S_48KHZ_MAX
...@@ -272,24 +306,21 @@ IAXVoIPLink::getEvent() ...@@ -272,24 +306,21 @@ IAXVoIPLink::getEvent()
// 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.
if (_currentCall->getSession()) { if (currentCall->getSession()) {
if ( iax_send_voice(_currentCall->getSession(), _currentCall->getFormat(), (unsigned char*)_sendDataEncoded, compSize, nbSample) == -1) { if ( iax_send_voice(currentCall->getSession(), currentCall->getFormat(), (unsigned char*)_sendDataEncoded, compSize, nbSample) == -1) {
_debug("IAX: Error sending voice data.\n"); _debug("IAX: Error sending voice data.\n");
} }
} }
_mutexIAX.leaveMutex(); _mutexIAX.leaveMutex();
} }
// Refresh registration.
if (_nextRefreshStamp && _nextRefreshStamp - 2 < time(NULL)) {
setRegister();
}
// thread wait 5 millisecond
_evThread->sleep(5);
} }
/*
void IAXVoIPLink::recvAudioForSpkr(void)
{
}
*/
...@@ -573,7 +604,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) ...@@ -573,7 +604,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
case IAX_EVENT_HANGUP: case IAX_EVENT_HANGUP:
Manager::instance().peerHungupCall(id); Manager::instance().peerHungupCall(id);
if (Manager::instance().isCurrentCall(id)) { if (Manager::instance().isCurrentCall(id)) {
_currentCall = NULL;
audiolayer->stopStream(); audiolayer->stopStream();
// stop audio // stop audio
} }
...@@ -584,7 +614,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) ...@@ -584,7 +614,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
Manager::instance().peerHungupCall(id); Manager::instance().peerHungupCall(id);
if (Manager::instance().isCurrentCall(id)) { if (Manager::instance().isCurrentCall(id)) {
// stop audio // stop audio
_currentCall = NULL;
audiolayer->stopStream(); audiolayer->stopStream();
} }
removeCall(id); removeCall(id);
...@@ -609,7 +638,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) ...@@ -609,7 +638,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
} }
Manager::instance().peerAnsweredCall(id); Manager::instance().peerAnsweredCall(id);
_currentCall = call;
audiolayer->startStream(); audiolayer->startStream();
// start audio here? // start audio here?
} else { } else {
......
...@@ -129,6 +129,11 @@ private: ...@@ -129,6 +129,11 @@ private:
*/ */
void iaxHandlePrecallEvent(iax_event* event); void iaxHandlePrecallEvent(iax_event* event);
/**
* Work out the audio data from Microphone to IAX2 channel
*/
void sendAudioFromMic(void);
/** /**
* Send an outgoing call invite to iax * Send an outgoing call invite to iax
* @param call An IAXCall pointer * @param call An IAXCall pointer
...@@ -199,7 +204,7 @@ private: ...@@ -199,7 +204,7 @@ private:
int _src_err; int _src_err;
/** Current IAX call pointer, used for sending, change when starting audio, switching */ /** Current IAX call pointer, used for sending, change when starting audio, switching */
IAXCall* _currentCall; //IAXCall* _currentCall;
}; };
#endif #endif
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