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

[#5229] Use inner class for rtp thread instead of inheritance

parent f8bc445a
No related branches found
No related tags found
No related merge requests found
...@@ -42,13 +42,8 @@ namespace sfl ...@@ -42,13 +42,8 @@ namespace sfl
{ {
AudioRtpSession::AudioRtpSession (ManagerImpl * manager, SIPCall * sipcall) : AudioRtpSession::AudioRtpSession (ManagerImpl * manager, SIPCall * sipcall) :
// ost::SymmetricRTPSession (ost::InetHostAddress (sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()), AudioRtpRecordHandler (sipcall)
AudioRtpRecordHandler (sipcall), , ost::SymmetricRTPSession (ost::InetHostAddress (sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort())
ost::TRTPSessionBase<ost::SymmetricRTPChannel,ost::SymmetricRTPChannel,ost::AVPQueue> (ost::InetHostAddress (sipcall->getLocalIp().c_str()),
sipcall->getLocalAudioPort(),
0,
ost::MembershipBookkeeping::defaultMembersHashSize,
ost::defaultApplication())
, _mainloopSemaphore (0) , _mainloopSemaphore (0)
, _manager (manager) , _manager (manager)
, _timestamp (0) , _timestamp (0)
...@@ -56,31 +51,20 @@ AudioRtpSession::AudioRtpSession (ManagerImpl * manager, SIPCall * sipcall) : ...@@ -56,31 +51,20 @@ AudioRtpSession::AudioRtpSession (ManagerImpl * manager, SIPCall * sipcall) :
, _timestampCount (0) , _timestampCount (0)
, _ca (sipcall) , _ca (sipcall)
, _isStarted (false) , _isStarted (false)
, _rtpThread (new AudioRtpThread (this))
{ {
ost::Thread::setCancel (cancelDefault);
assert (_ca); assert (_ca);
_info ("AudioRtpSession: Setting new RTP session with destination %s:%d", _ca->getLocalIp().c_str(), _ca->getLocalAudioPort()); _info ("AudioRtpSession: Setting new RTP session with destination %s:%d", _ca->getLocalIp().c_str(), _ca->getLocalAudioPort());
_audioRtpRecord._callId = _ca->getCallId(); _audioRtpRecord._callId = _ca->getCallId();
// static_cast<ost::DualRTPUDPIPv4Channel>(dso)->sendSocket->setTypeOfService(ost::Socket::tosLowDelay);
// static_cast<ost::DualRTPChannel<ost::DualRTPUDPIPv4Channel> >(dso)->sendSocket->setTypeOfService(ost::Socket::tosLowDelay);
setTypeOfService (tosEnhanced); setTypeOfService (tosEnhanced);
} }
AudioRtpSession::~AudioRtpSession() AudioRtpSession::~AudioRtpSession()
{ {
_info ("AudioRtpSession: Delete AudioRtpSession instance"); _info ("AudioRtpSession: Delete AudioRtpSession instance");
try {
ost::Thread::terminate();
} catch (...) {
_debugException ("AudioRtpSession: Thread destructor didn't terminate correctly");
throw;
}
} }
void AudioRtpSession::final() void AudioRtpSession::final()
...@@ -89,6 +73,8 @@ void AudioRtpSession::final() ...@@ -89,6 +73,8 @@ void AudioRtpSession::final()
Manager::instance().getMainBuffer()->unBindAll (_audioRtpRecord._callId); Manager::instance().getMainBuffer()->unBindAll (_audioRtpRecord._callId);
delete _rtpThread;
delete static_cast<AudioRtpSession *> (this); delete static_cast<AudioRtpSession *> (this);
} }
...@@ -334,77 +320,61 @@ int AudioRtpSession::startRtpThread (AudioCodec* audiocodec) ...@@ -334,77 +320,61 @@ int AudioRtpSession::startRtpThread (AudioCodec* audiocodec)
return 0; return 0;
_debug ("AudioRtpSession: Starting main thread"); _debug ("AudioRtpSession: Starting main thread");
_isStarted = true; _isStarted = true;
setSessionTimeouts(); setSessionTimeouts();
setSessionMedia (audiocodec); setSessionMedia (audiocodec);
initBuffers(); initBuffers();
initNoiseSuppress(); initNoiseSuppress();
enableStack();
int ret = ost::Thread::start (_mainloopSemaphore); startRunning();
return ret; _rtpThread->start();
return 0;
} }
void AudioRtpSession::stopRtpThread () void AudioRtpSession::stopRtpThread ()
{ {
_debug ("AudioRtpSession: Stoping main thread"); _debug ("AudioRtpSession: Stoping main thread");
_rtpThread->stopRtpThread();
disableStack(); disableStack();
} }
void AudioRtpSession::run () AudioRtpSession::AudioRtpThread::AudioRtpThread (AudioRtpSession *session) : rtpSession (session), running (true)
{ {
_debug ("AudioRtpSession: Entering mainloop for call %s", _audioRtpRecord._callId.c_str()); _debug ("AudioRtpSession: Create new rtp thread");
}
uint32 timeout = 0;
_timestamp = getCurrentTimestamp();
while (isActive()) {
if (timeout < 1000) { // !(timeout/1000) AudioRtpSession::AudioRtpThread::~AudioRtpThread()
timeout = getSchedulingTimeout(); {
_debug ("AudioRtpSession: Delete rtp thread");
} }
setCancel (cancelDeferred); void AudioRtpSession::AudioRtpThread::run()
{
int threadSleep = 20;
// Send session TimerPort::setTimer (threadSleep);
if (getEventQueueSize() > 0) {
sendDtmfEvent (getEventQueue()->front());
} else {
sendMicData ();
}
setCancel (cancelImmediate); _debug ("AudioRtpThread: Entering Audio rtp thread main loop");
setCancel (cancelDeferred); while (running) {
controlReceptionService();
controlTransmissionService();
setCancel (cancelImmediate);
uint32 maxWait = timeval2microtimeout (getRTCPCheckInterval());
// make sure the scheduling timeout is
// <= the check interval for RTCP
// packets
timeout = (timeout > maxWait) ? maxWait : timeout;
if (timeout < 1000) { // !(timeout/1000) // Send session
timerTick(); if (rtpSession->getEventQueueSize() > 0) {
rtpSession->sendDtmfEvent (rtpSession->getEventQueue()->front());
} else { } else {
if (isPendingData (timeout/1000)) { rtpSession->sendMicData ();
setCancel (cancelDeferred);
if (isActive()) { // take in only if active
takeInDataPacket();
} }
setCancel (cancelImmediate); Thread::sleep (TimerPort::getTimer());
}
timeout = 0; TimerPort::incTimer (threadSleep);
}
} }
_debug ("AudioRtpSession: Left main loop for call %s", _audioRtpRecord._callId.c_str()); _debug ("AudioRtpThread: Leaving audio rtp thread loop");
} }
} }
...@@ -53,12 +53,11 @@ ...@@ -53,12 +53,11 @@
#include <cc++/numbers.h> // ost::Time #include <cc++/numbers.h> // ost::Time
#include <fstream> #include <fstream>
namespace sfl namespace sfl
{ {
// class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public AudioRtpRecordHandler, public ost::TRTPSessionBase<ost::DualRTPUDPIPv4Channel,ost::DualRTPUDPIPv4Channel,ost::AVPQueue> // class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public AudioRtpRecordHandler, public ost::TRTPSessionBase<ost::DualRTPUDPIPv4Channel,ost::DualRTPUDPIPv4Channel,ost::AVPQueue>
class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public AudioRtpRecordHandler, public ost::TRTPSessionBase<ost::SymmetricRTPChannel, ost::SymmetricRTPChannel, ost::AVPQueue> class AudioRtpSession : public ost::TimerPort, public AudioRtpRecordHandler, public ost::SymmetricRTPSession
{ {
public: public:
/** /**
...@@ -74,7 +73,7 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud ...@@ -74,7 +73,7 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud
void terminateRtpSession(); void terminateRtpSession();
// Thread associated method // Thread associated method
virtual void run (); // virtual void run ();
virtual bool onRTPPacketRecv (ost::IncomingRTPPkt&); virtual bool onRTPPacketRecv (ost::IncomingRTPPkt&);
...@@ -104,8 +103,31 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud ...@@ -104,8 +103,31 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud
*/ */
void updateSessionMedia (AudioCodec *); void updateSessionMedia (AudioCodec *);
/**
* Send encoded data to peer
*/
void sendMicData();
private: private:
class AudioRtpThread : public ost::Thread, public ost::TimerPort
{
public:
AudioRtpThread (AudioRtpSession *session);
~AudioRtpThread();
void stopRtpThread (void) {
running = false;
}
virtual void run();
private:
AudioRtpSession *rtpSession;
bool running;
};
/** /**
* Set RTP Sockets send/receive timeouts * Set RTP Sockets send/receive timeouts
*/ */
...@@ -122,11 +144,6 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud ...@@ -122,11 +144,6 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud
*/ */
void setDestinationIpAddress (void); void setDestinationIpAddress (void);
/**
* Send encoded data to peer
*/
void sendMicData();
/** /**
* Receive data from peer * Receive data from peer
*/ */
...@@ -183,6 +200,12 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud ...@@ -183,6 +200,12 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud
SIPCall * _ca; SIPCall * _ca;
bool _isStarted; bool _isStarted;
AudioRtpThread *_rtpThread;
public:
friend class AudioRtpThread;
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment