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

[#4847] Apply RTP modification to ZRTP session

parent a5504ae1
Branches
No related tags found
No related merge requests found
...@@ -255,9 +255,7 @@ void AudioRtpSession::sendDtmfEvent (sfl::DtmfEvent *dtmf) ...@@ -255,9 +255,7 @@ void AudioRtpSession::sendDtmfEvent (sfl::DtmfEvent *dtmf)
bool AudioRtpSession::onRTPPacketRecv (ost::IncomingRTPPkt&) bool AudioRtpSession::onRTPPacketRecv (ost::IncomingRTPPkt&)
{ {
// audioCodecMutex.enter();
receiveSpeakerData (); receiveSpeakerData ();
// audioCodecMutex.leave();
return true; return true;
} }
...@@ -355,9 +353,6 @@ void AudioRtpSession::run () ...@@ -355,9 +353,6 @@ void AudioRtpSession::run ()
// Set recording sampling rate // Set recording sampling rate
_ca->setRecordingSmplRate (getCodecSampleRate()); _ca->setRecordingSmplRate (getCodecSampleRate());
// Start audio stream (if not started) AND flush all buffers (main and urgent)
// _manager->getAudioDriver()->startStream();
_debug ("AudioRtpSession: Entering mainloop for call %s",_ca->getCallId().c_str()); _debug ("AudioRtpSession: Entering mainloop for call %s",_ca->getCallId().c_str());
uint32 timeout = 0; uint32 timeout = 0;
...@@ -394,7 +389,6 @@ void AudioRtpSession::run () ...@@ -394,7 +389,6 @@ void AudioRtpSession::run ()
setCancel (cancelImmediate); setCancel (cancelImmediate);
timerTick(); timerTick();
} else { } else {
if (isPendingData (timeout/1000)) { if (isPendingData (timeout/1000)) {
setCancel (cancelDeferred); setCancel (cancelDeferred);
......
/* /*
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com> * Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -89,7 +90,7 @@ AudioZrtpSession::~AudioZrtpSession() ...@@ -89,7 +90,7 @@ AudioZrtpSession::~AudioZrtpSession()
throw; throw;
} }
_manager->getAudioDriver()->getMainBuffer()->unBindAll (_ca->getCallId()); Manager::instance().getMainBuffer()->unBindAll (_ca->getCallId());
if (_time) if (_time)
delete _time; delete _time;
...@@ -177,14 +178,11 @@ void AudioZrtpSession::setSessionMedia (AudioCodec* audioCodec) ...@@ -177,14 +178,11 @@ void AudioZrtpSession::setSessionMedia (AudioCodec* audioCodec)
_debug ("AudioZrtpSession: RTP timestamp increment: %d", _timestampIncrement); _debug ("AudioZrtpSession: RTP timestamp increment: %d", _timestampIncrement);
// Even if specified as a 16 kHz codec, G722 requires rtp sending rate to be 8 kHz // Even if specified as a 16 kHz codec, G722 requires rtp sending rate to be 8 kHz
if (payloadType == g722PayloadType) { if (dynamic) {
_debug ("AudioZrtpSession: Setting G722 payload format"); _debug ("AudioRtpSession: Setting dynamic payload format");
setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) payloadType, g722RtpClockRate));
} else if (dynamic) {
_debug ("AudioZrtpSession: Setting dynamic payload format");
setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) payloadType, smplRate)); setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) payloadType, smplRate));
} else if (dynamic && payloadType != g722PayloadType) { } else {
_debug ("AudioZrtpSession: Setting static payload format"); _debug ("AudioRtpSession: Setting static payload format");
setPayloadFormat (ost::StaticPayloadFormat ( (ost::StaticPayloadType) payloadType)); setPayloadFormat (ost::StaticPayloadFormat ( (ost::StaticPayloadType) payloadType));
} }
...@@ -214,13 +212,10 @@ void AudioZrtpSession::updateSessionMedia (AudioCodec *audioCodec) ...@@ -214,13 +212,10 @@ void AudioZrtpSession::updateSessionMedia (AudioCodec *audioCodec)
_debug ("AudioRtpSession: RTP timestamp increment: %d", _timestampIncrement); _debug ("AudioRtpSession: RTP timestamp increment: %d", _timestampIncrement);
// Even if specified as a 16 kHz codec, G722 requires rtp sending rate to be 8 kHz // Even if specified as a 16 kHz codec, G722 requires rtp sending rate to be 8 kHz
if (payloadType == g722PayloadType) { if (dynamic) {
_debug ("AudioRtpSession: Setting G722 payload format");
setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) payloadType, g722RtpClockRate));
} else if (dynamic) {
_debug ("AudioRtpSession: Setting dynamic payload format"); _debug ("AudioRtpSession: Setting dynamic payload format");
setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) payloadType, smplRate)); setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) payloadType, smplRate));
} else if (dynamic && payloadType != g722PayloadType) { } else {
_debug ("AudioRtpSession: Setting static payload format"); _debug ("AudioRtpSession: Setting static payload format");
setPayloadFormat (ost::StaticPayloadFormat ( (ost::StaticPayloadType) payloadType)); setPayloadFormat (ost::StaticPayloadFormat ( (ost::StaticPayloadType) payloadType));
} }
...@@ -288,7 +283,8 @@ void AudioZrtpSession::sendDtmfEvent (sfl::DtmfEvent *dtmf) ...@@ -288,7 +283,8 @@ void AudioZrtpSession::sendDtmfEvent (sfl::DtmfEvent *dtmf)
if (dtmf->newevent) if (dtmf->newevent)
setMark (true); setMark (true);
putData (_timestamp, (const unsigned char*) (& (dtmf->payload)), sizeof (ost::RTPPacket::RFC2833Payload)); // putData (_timestamp, (const unsigned char*) (& (dtmf->payload)), sizeof (ost::RTPPacket::RFC2833Payload));
sendImmediate (_timestamp, (const unsigned char*) (& (dtmf->payload)), sizeof (ost::RTPPacket::RFC2833Payload));
// This is no more a new event // This is no more a new event
if (dtmf->newevent) { if (dtmf->newevent) {
...@@ -330,17 +326,12 @@ void AudioZrtpSession::sendMicData() ...@@ -330,17 +326,12 @@ void AudioZrtpSession::sendMicData()
if (!compSize) if (!compSize)
return; return;
// Reset timestamp to make sure the timing information are up to date
if (_timestampCount > RTP_TIMESTAMP_RESET_FREQ) {
_timestamp = getCurrentTimestamp();
_timestampCount = 0;
}
// Increment timestamp for outgoing packet // Increment timestamp for outgoing packet
_timestamp += _timestampIncrement; _timestamp += _timestampIncrement;
// putData put the data on RTP queue, sendImmediate bypass this queue // putData put the data on RTP queue, sendImmediate bypass this queue
putData (_timestamp, getMicDataEncoded(), compSize); putData (_timestamp, getMicDataEncoded(), compSize);
sendImmediate (_timestamp, getMicDataEncoded(), compSize);
} }
...@@ -388,43 +379,33 @@ void AudioZrtpSession::notifyIncomingCall() ...@@ -388,43 +379,33 @@ void AudioZrtpSession::notifyIncomingCall()
int AudioZrtpSession::startRtpThread (AudioCodec* audiocodec) int AudioZrtpSession::startRtpThread (AudioCodec* audiocodec)
{ {
if (_isStarted)
return 0;
_debug ("AudioZrtpSession: Starting main thread"); _debug ("AudioZrtpSession: Starting main thread");
_isStarted = true;
setSessionTimeouts(); setSessionTimeouts();
setSessionMedia (audiocodec); setSessionMedia (audiocodec);
initBuffers(); initBuffers();
initNoiseSuppress(); initNoiseSuppress();
enableStack(); enableStack();
int ret = start (_mainloopSemaphore); int ret = start (_mainloopSemaphore);
return ret; return ret;
} }
void AudioZrtpSession::run () void AudioZrtpSession::stopRtpThread ()
{ {
_debug ("AudioZrtpSession: Stoping main thread");
// Timestamp must be initialized randomly disableStack();
_timestamp = getCurrentTimestamp();
/*
int threadSleep = 0;
if (getCodecSampleRate() != 0) {
threadSleep = (getCodecFrameSize() * 1000) / getCodecSampleRate();
} else {
// TODO should not be dependent of audio layer frame size
threadSleep = getAudioLayerFrameSize();
} }
TimerPort::setTimer (threadSleep); void AudioZrtpSession::run ()
*/ {
// Set recording sampling rate // Set recording sampling rate
_ca->setRecordingSmplRate (getCodecSampleRate()); _ca->setRecordingSmplRate (getCodecSampleRate());
// Start audio stream (if not started) AND flush all buffers (main and urgent)
_manager->getAudioDriver()->startStream();
_debug ("AudioZrtpSession: Entering mainloop for call %s",_ca->getCallId().c_str()); _debug ("AudioZrtpSession: Entering mainloop for call %s",_ca->getCallId().c_str());
uint32 timeout = 0; uint32 timeout = 0;
...@@ -435,8 +416,6 @@ void AudioZrtpSession::run () ...@@ -435,8 +416,6 @@ void AudioZrtpSession::run ()
timeout = getSchedulingTimeout(); timeout = getSchedulingTimeout();
} }
// _manager->getAudioLayerMutex()->enter();
// Send session // Send session
if (getEventQueueSize() > 0) { if (getEventQueueSize() > 0) {
sendDtmfEvent (getEventQueue()->front()); sendDtmfEvent (getEventQueue()->front());
...@@ -447,8 +426,6 @@ void AudioZrtpSession::run () ...@@ -447,8 +426,6 @@ void AudioZrtpSession::run ()
// This also should be moved // This also should be moved
notifyIncomingCall(); notifyIncomingCall();
// _manager->getAudioLayerMutex()->leave();
setCancel (cancelDeferred); setCancel (cancelDeferred);
controlReceptionService(); controlReceptionService();
controlTransmissionService(); controlTransmissionService();
...@@ -461,7 +438,7 @@ void AudioZrtpSession::run () ...@@ -461,7 +438,7 @@ void AudioZrtpSession::run ()
if (timeout < 1000) { // !(timeout/1000) if (timeout < 1000) { // !(timeout/1000)
setCancel (cancelDeferred); setCancel (cancelDeferred);
dispatchDataPacket(); // dispatchDataPacket();
setCancel (cancelImmediate); setCancel (cancelImmediate);
timerTick(); timerTick();
} else { } else {
......
/* /*
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com> * Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -67,6 +68,8 @@ class AudioZrtpSession : protected ost::Thread, public AudioRtpRecordHandler, pu ...@@ -67,6 +68,8 @@ class AudioZrtpSession : protected ost::Thread, public AudioRtpRecordHandler, pu
int startRtpThread (AudioCodec *); int startRtpThread (AudioCodec *);
void stopRtpThread (void);
/** /**
* Used mostly when receiving a reinvite * Used mostly when receiving a reinvite
*/ */
...@@ -168,6 +171,8 @@ class AudioZrtpSession : protected ost::Thread, public AudioRtpRecordHandler, pu ...@@ -168,6 +171,8 @@ class AudioZrtpSession : protected ost::Thread, public AudioRtpRecordHandler, pu
int _countNotificationTime; int _countNotificationTime;
SIPCall * _ca; SIPCall * _ca;
bool _isStarted;
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment