diff --git a/daemon/src/audio/audiortp/audio_rtp_session.cpp b/daemon/src/audio/audiortp/audio_rtp_session.cpp index 7d7aeced682745611ff4f8ec5bdffd9693aeb0d3..bb4ce4a415c1e3ce3d70307c2f4026c2f371511a 100644 --- a/daemon/src/audio/audiortp/audio_rtp_session.cpp +++ b/daemon/src/audio/audiortp/audio_rtp_session.cpp @@ -51,6 +51,7 @@ AudioRtpSession::AudioRtpSession(SIPCall &call, ost::RTPDataQueue &queue) : , remote_ip_() , remote_port_(0) , timestampCount_(0) + , rtpSendThread_(*this) { queue_.setTypeOfService(ost::RTPDataQueue::tosEnhanced); } @@ -268,4 +269,52 @@ void AudioRtpSession::startRtpThreads(const std::vector<AudioCodec*> &audioCodec startSendThread(); } +AudioRtpSession::AudioRtpSendThread::AudioRtpSendThread(AudioRtpSession &session) : + running_(false), rtpSession_(session), thread_(0), timer_() +{} + +AudioRtpSession::AudioRtpSendThread::~AudioRtpSendThread() +{ + running_ = false; + if (thread_) + pthread_join(thread_, NULL); +} + +void AudioRtpSession::AudioRtpSendThread::start() +{ + running_ = true; + pthread_create(&thread_, NULL, &runCallback, this); +} + +void * +AudioRtpSession::AudioRtpSendThread::runCallback(void *data) +{ + AudioRtpSession::AudioRtpSendThread *context = static_cast<AudioRtpSession::AudioRtpSendThread*>(data); + context->run(); + return NULL; +} + +void AudioRtpSession::AudioRtpSendThread::run() +{ + timer_.setTimer(rtpSession_.transportRate_); + const int MS_TO_USEC = 1000; + + while (running_) { + // Send session + if (rtpSession_.hasDTMFPending()) + rtpSession_.sendDtmfEvent(); + else + rtpSession_.sendMicData(); + + usleep(timer_.getTimer() * MS_TO_USEC); + + timer_.incTimer(rtpSession_.transportRate_); + } +} + + +void AudioRtpSession::startSendThread() +{ + rtpSendThread_.start(); +} } diff --git a/daemon/src/audio/audiortp/audio_rtp_session.h b/daemon/src/audio/audiortp/audio_rtp_session.h index ec8fa90c9b6d3d12ea2c4feb1a224819fbdcc702..4d647a318f4c4a5ccbfee133c950b88efbf4ce78 100644 --- a/daemon/src/audio/audiortp/audio_rtp_session.h +++ b/daemon/src/audio/audiortp/audio_rtp_session.h @@ -86,19 +86,6 @@ class AudioRtpSession : public AudioRtpRecordHandler { bool onRTPPacketRecv(ost::IncomingRTPPkt&); - /** - * Send DTMF over RTP (RFC2833). The timestamp and sequence number must be - * incremented as if it was microphone audio. This function change the payload type of the rtp session, - * send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get - * back the codec payload for further audio processing. - */ - void sendDtmfEvent(); - - /** - * Send encoded data to peer - */ - virtual void sendMicData(); - SIPCall &call_; /** @@ -121,7 +108,37 @@ class AudioRtpSession : public AudioRtpRecordHandler { private: NON_COPYABLE(AudioRtpSession); virtual void startReceiveThread() = 0; - virtual void startSendThread() = 0; + void startSendThread(); + + /** + * Send DTMF over RTP (RFC2833). The timestamp and sequence number must be + * incremented as if it was microphone audio. This function change the payload type of the rtp session, + * send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get + * back the codec payload for further audio processing. + */ + void sendDtmfEvent(); + + /** + * Send encoded data to peer + */ + virtual void sendMicData(); + + + class AudioRtpSendThread { + public: + AudioRtpSendThread(AudioRtpSession &session); + ~AudioRtpSendThread(); + void start(); + bool running_; + + private: + static void *runCallback(void *data); + void run(); + NON_COPYABLE(AudioRtpSendThread); + AudioRtpSession &rtpSession_; + pthread_t thread_; + ost::TimerPort timer_; + }; /** * Set RTP Sockets send/receive timeouts @@ -152,6 +169,8 @@ class AudioRtpSession : public AudioRtpRecordHandler { * Timestamp reset frequency specified in number of packet sent */ short timestampCount_; + + AudioRtpSendThread rtpSendThread_; }; } diff --git a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp index c91c1c4455529a86ce7a8e79eb8bb678b7dc11ab..de1ed5490d380474e1680ad92e5663b80c29e163 100644 --- a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp +++ b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp @@ -41,63 +41,14 @@ namespace sfl { AudioSymmetricRtpSession::AudioSymmetricRtpSession(SIPCall &call) : ost::SymmetricRTPSession(ost::InetHostAddress(call.getLocalIp().c_str()), call.getLocalAudioPort()) , AudioRtpSession(call, *this) - , rtpSendThread_(*this) { DEBUG("Setting new RTP session with destination %s:%d", call_.getLocalIp().c_str(), call_.getLocalAudioPort()); audioRtpRecord_.callId_ = call_.getCallId(); } -AudioSymmetricRtpSession::AudioRtpSendThread::AudioRtpSendThread(AudioSymmetricRtpSession &session) : - running_(false), rtpSession_(session), thread_(0) -{} - -AudioSymmetricRtpSession::AudioRtpSendThread::~AudioRtpSendThread() -{ - running_ = false; - if (thread_) - pthread_join(thread_, NULL); -} - -void AudioSymmetricRtpSession::AudioRtpSendThread::start() -{ - running_ = true; - pthread_create(&thread_, NULL, &runCallback, this); -} - -void * -AudioSymmetricRtpSession::AudioRtpSendThread::runCallback(void *data) -{ - AudioSymmetricRtpSession::AudioRtpSendThread *context = static_cast<AudioSymmetricRtpSession::AudioRtpSendThread*>(data); - context->run(); - return NULL; -} - -void AudioSymmetricRtpSession::AudioRtpSendThread::run() -{ - ost::TimerPort::setTimer(rtpSession_.transportRate_); - const int MS_TO_USEC = 1000; - - while (running_) { - // Send session - if (rtpSession_.hasDTMFPending()) - rtpSession_.sendDtmfEvent(); - else - rtpSession_.sendMicData(); - - usleep(ost::TimerPort::getTimer() * MS_TO_USEC); - - ost::TimerPort::incTimer(rtpSession_.transportRate_); - } -} - void AudioSymmetricRtpSession::startReceiveThread() { ost::SymmetricRTPSession::start(); } - -void AudioSymmetricRtpSession::startSendThread() -{ - rtpSendThread_.start(); -} } diff --git a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h index 4b3b7e1228efd8df5d44b73f11909f66b98d2a38..2b85124856a23ff14bb16f0afda365f188f0406a 100644 --- a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h +++ b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h @@ -78,25 +78,7 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP private: NON_COPYABLE(AudioSymmetricRtpSession); - class AudioRtpSendThread : public ost::TimerPort { - public: - AudioRtpSendThread(AudioSymmetricRtpSession &session); - ~AudioRtpSendThread(); - void start(); - bool running_; - - private: - NON_COPYABLE(AudioRtpSendThread); - static void *runCallback(void *data); - void run(); - pthread_t thread_; - AudioSymmetricRtpSession &rtpSession_; - }; - void startReceiveThread(); - void startSendThread(); - - AudioRtpSendThread rtpSendThread_ ; }; } diff --git a/daemon/src/audio/audiortp/audio_zrtp_session.cpp b/daemon/src/audio/audiortp/audio_zrtp_session.cpp index 5452dbdaff252f895b64d510f673fae35b572c34..9f9035b60d3115e0cf47fe7f6267e96bb1a819a7 100644 --- a/daemon/src/audio/audiortp/audio_zrtp_session.cpp +++ b/daemon/src/audio/audiortp/audio_zrtp_session.cpp @@ -50,7 +50,6 @@ AudioZrtpSession::AudioZrtpSession(SIPCall &call, const std::string &zidFilename ost::SymmetricZRTPSession(ost::InetHostAddress(call.getLocalIp().c_str()), call.getLocalAudioPort()) , AudioRtpSession(call, *this) , zidFilename_(zidFilename) - , rtpSendThread_(*this) { initializeZid(); DEBUG("Setting new RTP session with destination %s:%d", @@ -112,52 +111,6 @@ void AudioZrtpSession::sendMicData() queue_.sendImmediate(timestamp_, getMicDataEncoded(), compSize); } -AudioZrtpSession::AudioZrtpSendThread::AudioZrtpSendThread(AudioZrtpSession &session) : - running_(true), zrtpSession_(session), thread_(0) -{} - -AudioZrtpSession::AudioZrtpSendThread::~AudioZrtpSendThread() -{ - running_ = false; - if (thread_) - pthread_join(thread_, NULL); -} - -void -AudioZrtpSession::AudioZrtpSendThread::start() -{ - pthread_create(&thread_, NULL, &runCallback, this); -} - -void * -AudioZrtpSession::AudioZrtpSendThread::runCallback(void *data) -{ - AudioZrtpSession::AudioZrtpSendThread *context = static_cast<AudioZrtpSession::AudioZrtpSendThread*>(data); - context->run(); - return NULL; -} - -void AudioZrtpSession::AudioZrtpSendThread::run() -{ - DEBUG("Entering Audio zrtp thread main loop %s", running_ ? "running" : "not running"); - - TimerPort::setTimer(zrtpSession_.transportRate_); - - while (running_) { - // Send session - if (zrtpSession_.hasDTMFPending()) - zrtpSession_.sendDtmfEvent(); - else - zrtpSession_.sendMicData(); - - Thread::sleep(TimerPort::getTimer()); - - TimerPort::incTimer(zrtpSession_.transportRate_); - } - - DEBUG("Leaving audio rtp thread loop"); -} - int AudioZrtpSession::getIncrementForDTMF() const { return 160; @@ -168,9 +121,4 @@ void AudioZrtpSession::startReceiveThread() ost::SymmetricZRTPSession::start(); } -void AudioZrtpSession::startSendThread() -{ - rtpSendThread_.start(); -} - } diff --git a/daemon/src/audio/audiortp/audio_zrtp_session.h b/daemon/src/audio/audiortp/audio_zrtp_session.h index dce361ac1b60465292ef54369a81938a5992f0af..2a9bf5d1c202ad7deb61fd71a3ea99d11ee9d772 100644 --- a/daemon/src/audio/audiortp/audio_zrtp_session.h +++ b/daemon/src/audio/audiortp/audio_zrtp_session.h @@ -42,7 +42,6 @@ using std::ptrdiff_t; #include "global.h" #include "audio_rtp_session.h" -// #include <commoncpp/numbers.h> // OST::Time class SIPCall; class AudioCodec; @@ -76,28 +75,11 @@ class AudioZrtpSession : private: NON_COPYABLE(AudioZrtpSession); - class AudioZrtpSendThread : public ost::TimerPort { - public: - AudioZrtpSendThread(AudioZrtpSession &session); - ~AudioZrtpSendThread(); - void start(); - bool running_; - - private: - static void *runCallback(void *data); - void run(); - NON_COPYABLE(AudioZrtpSendThread); - AudioZrtpSession &zrtpSession_; - pthread_t thread_; - }; void sendMicData(); void initializeZid(); std::string zidFilename_; void startReceiveThread(); - void startSendThread(); virtual int getIncrementForDTMF() const; - - AudioZrtpSendThread rtpSendThread_; }; }