Commit bad3c752 authored by Adrien Béraud's avatar Adrien Béraud Committed by Andreas Traczyk

sipcall: call manager, request key frames on main thread

Change-Id: I047f0f1a87466e440cafdb0984b311b8bcb5e5ed
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 623bfc3d
......@@ -715,24 +715,38 @@ void
SIPCall::onFailure(signed cause)
{
setState(CallState::MERROR, ConnectionState::DISCONNECTED, cause);
Manager::instance().callFailure(*this);
removeCall();
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] {
if (auto shared = w.lock()) {
auto& call = *shared;
Manager::instance().callFailure(call);
call.removeCall();
}
});
}
void
SIPCall::onBusyHere()
{
setState(CallState::BUSY, ConnectionState::DISCONNECTED);
Manager::instance().callBusy(*this);
removeCall();
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] {
if (auto shared = w.lock()) {
auto& call = *shared;
Manager::instance().callBusy(call);
call.removeCall();
}
});
}
void
SIPCall::onClosed()
{
Manager::instance().peerHungupCall(*this);
removeCall();
Manager::instance().checkAudio();
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] {
if (auto shared = w.lock()) {
auto& call = *shared;
Manager::instance().peerHungupCall(call);
call.removeCall();
}
});
}
void
......@@ -741,8 +755,13 @@ SIPCall::onAnswered()
RING_WARN("[call:%s] onAnswered()", getCallId().c_str());
if (getConnectionState() != ConnectionState::CONNECTED) {
setState(CallState::ACTIVE, ConnectionState::CONNECTED);
if (not isSubcall())
Manager::instance().peerAnsweredCall(*this);
if (not isSubcall()) {
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] {
if (auto shared = w.lock()) {
Manager::instance().peerAnsweredCall(*shared);
}
});
}
}
}
......
......@@ -691,14 +691,10 @@ SIPVoIPLink::guessAccount(const std::string& userName,
void
SIPVoIPLink::handleEvents()
{
const pj_time_val timeout = {10, 0};
const pj_time_val timeout = {1, 0};
if (auto ret = pjsip_endpt_handle_events(endpt_, &timeout))
RING_ERR("pjsip_endpt_handle_events failed with error %s",
sip_utils::sip_strerror(ret).c_str());
#ifdef RING_VIDEO
dequeKeyframeRequests();
#endif
}
void SIPVoIPLink::registerKeepAliveTimer(pj_timer_entry &timer, pj_time_val &delay)
......@@ -736,33 +732,17 @@ void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer)
void
SIPVoIPLink::enqueueKeyframeRequest(const std::string &id)
{
if (auto link = getSIPVoIPLink()) {
std::lock_guard<std::mutex> lock(link->keyframeRequestsMutex_);
link->keyframeRequests_.push(id);
} else
RING_ERR("no more VoIP link");
}
// Called from SIP event thread
void
SIPVoIPLink::dequeKeyframeRequests()
{
std::lock_guard<std::mutex> lock(keyframeRequestsMutex_);
int max_requests = 20;
while (not keyframeRequests_.empty() and max_requests--) {
const std::string &id(keyframeRequests_.front());
requestKeyframe(id);
keyframeRequests_.pop();
}
runOnMainThread([link = getSIPVoIPLink(), id] {
if (link)
link->requestKeyframe(id);
});
}
// Called from SIP event thread
void
SIPVoIPLink::requestKeyframe(const std::string &callID)
{
auto call = Manager::instance().callFactory.getCall<SIPCall>(callID);
if (!call)
if (!call || call->getState() != Call::CallState::ACTIVE)
return;
const char * const BODY =
......
......@@ -167,10 +167,7 @@ class SIPVoIPLink {
std::thread sipThread_;
#ifdef RING_VIDEO
void dequeKeyframeRequests();
void requestKeyframe(const std::string &callID);
std::mutex keyframeRequestsMutex_ {};
std::queue<std::string> keyframeRequests_ {};
#endif
friend class SIPTest;
......
Markdown is supported
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