Commit dfda5df8 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

#13678: Fix Zrtp thread may hang when hanging up a call

parent eac7e9a3
......@@ -47,25 +47,27 @@
namespace sfl {
AudioZrtpSession::AudioZrtpSession(SIPCall &call, const std::string &zidFilename) :
AudioRtpSession(call, *this, *this),
ost::TRTPSessionBase<ost::SymmetricRTPChannel, ost::SymmetricRTPChannel, ost::ZrtpQueue>(ost::InetHostAddress(call_.getLocalIp().c_str()),
call_.getLocalAudioPort(),
0,
ost::MembershipBookkeeping::defaultMembersHashSize,
ost::defaultApplication()),
zidFilename_(zidFilename)
ost::TimerPort()
, ost::SymmetricZRTPSession(ost::InetHostAddress(call.getLocalIp().c_str()), call.getLocalAudioPort())
, AudioRtpSession(call, *this, *this)
, zidFilename_(zidFilename)
, rtpThread_(*this)
{
initializeZid();
DEBUG("Setting new RTP session with destination %s:%d",
call_.getLocalIp().c_str(), call_.getLocalAudioPort());
audioRtpRecord_.callId_ = call_.getCallId();
}
AudioZrtpSession::~AudioZrtpSession()
{
ost::Thread::terminate();
Manager::instance().getMainBuffer()->unBindAll(call_.getCallId());
if (rtpThread_.running_) {
rtpThread_.running_ = false;
rtpThread_.join();
}
}
void AudioZrtpSession::initializeZid()
{
if (zidFilename_.empty())
......@@ -120,46 +122,31 @@ void AudioZrtpSession::sendMicData()
queue_.sendImmediate(timestamp_, getMicDataEncoded(), compSize);
}
void AudioZrtpSession::run()
AudioZrtpSession::AudioZrtpThread::AudioZrtpThread(AudioZrtpSession &session) : running_(true), zrtpSession_(session)
{}
void AudioZrtpSession::AudioZrtpThread::run()
{
// Set recording sampling rate
call_.setRecordingSmplRate(getCodecSampleRate());
DEBUG("Entering mainloop for call %s", call_.getCallId().c_str());
int threadSleep = 20;
uint32 timeout = 0;
DEBUG("Entering Audio zrtp thread main loop %s", running_ ? "running" : "not running");
while (isActive()) {
if (timeout < 1000)
timeout = getSchedulingTimeout();
TimerPort::setTimer(threadSleep);
while (running_) {
// Send session
if (hasDTMFPending())
sendDtmfEvent();
if (zrtpSession_.hasDTMFPending())
zrtpSession_.sendDtmfEvent();
else
sendMicData();
controlReceptionService();
controlTransmissionService();
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)
// dispatchDataPacket();
timerTick();
} else {
if (isPendingData(timeout / 1000)) {
if (isActive())
takeInDataPacket();
}
timeout = 0;
}
zrtpSession_.sendMicData();
Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(threadSleep);
}
DEBUG("Left main loop for call %s", call_.getCallId().c_str());
DEBUG("Leaving audio rtp thread loop");
}
int AudioZrtpSession::getIncrementForDTMF() const
......@@ -172,4 +159,13 @@ void AudioZrtpSession::setSessionMedia(AudioCodec &audioCodec)
AudioRtpSession::setSessionMedia(audioCodec);
}
int AudioZrtpSession::startRtpThread(AudioCodec &audiocodec)
{
if(isStarted_)
return 0;
AudioRtpSession::startRtpThread(audiocodec);
return startZrtpThread();
}
}
......@@ -54,25 +54,46 @@ class ZrtpZidException : public std::runtime_error {
};
class AudioZrtpSession :
public AudioRtpSession, protected ost::Thread,
public ost::TRTPSessionBase<ost::SymmetricRTPChannel, ost::SymmetricRTPChannel, ost::ZrtpQueue> {
public ost::TimerPort,
// public ost::TRTPSessionBase<ost::SymmetricRTPChannel, ost::SymmetricRTPChannel, ost::ZrtpQueue> {
public ost::SymmetricZRTPSession,
public AudioRtpSession {
public:
AudioZrtpSession(SIPCall &call, const std::string& zidFilename);
~AudioZrtpSession();
// Thread associated method
virtual void run();
int startZrtpThread() {
rtpThread_.start();
return 0;
}
virtual bool onRTPPacketRecv(ost::IncomingRTPPkt &pkt) {
return AudioRtpSession::onRTPPacketRecv(pkt);
}
private:
NON_COPYABLE(AudioZrtpSession);
class AudioZrtpThread : public ost::Thread, public ost::TimerPort {
public:
AudioZrtpThread(AudioZrtpSession &session);
virtual void run();
bool running_;
private:
NON_COPYABLE(AudioZrtpThread);
AudioZrtpSession &zrtpSession_;
};
void sendMicData();
void initializeZid();
std::string zidFilename_;
void setSessionMedia(AudioCodec &codec);
int startRtpThread(AudioCodec &audiocodec);
virtual int getIncrementForDTMF() const;
AudioZrtpThread rtpThread_;
};
}
......
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