Commit d623c210 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

sipcall: check ice for null, cleanup

Change-Id: Ia6a43fe3650762b0b8cf1185aaac6cf582b55b8b
parent 2251dbd2
...@@ -740,14 +740,15 @@ SIPCall::removeCall() ...@@ -740,14 +740,15 @@ SIPCall::removeCall()
void void
SIPCall::onFailure(signed cause) SIPCall::onFailure(signed cause)
{ {
setState(CallState::MERROR, ConnectionState::DISCONNECTED, cause); if (setState(CallState::MERROR, ConnectionState::DISCONNECTED, cause)) {
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] { runOnMainThread([w = weak()] {
if (auto shared = w.lock()) { if (auto shared = w.lock()) {
auto& call = *shared; auto& call = *shared;
Manager::instance().callFailure(call); Manager::instance().callFailure(call);
call.removeCall(); call.removeCall();
} }
}); });
}
} }
void void
...@@ -758,7 +759,7 @@ SIPCall::onBusyHere() ...@@ -758,7 +759,7 @@ SIPCall::onBusyHere()
else else
setState(CallState::BUSY, ConnectionState::DISCONNECTED); setState(CallState::BUSY, ConnectionState::DISCONNECTED);
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] { runOnMainThread([w = weak()] {
if (auto shared = w.lock()) { if (auto shared = w.lock()) {
auto& call = *shared; auto& call = *shared;
Manager::instance().callBusy(call); Manager::instance().callBusy(call);
...@@ -770,7 +771,7 @@ SIPCall::onBusyHere() ...@@ -770,7 +771,7 @@ SIPCall::onBusyHere()
void void
SIPCall::onClosed() SIPCall::onClosed()
{ {
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] { runOnMainThread([w = weak()] {
if (auto shared = w.lock()) { if (auto shared = w.lock()) {
auto& call = *shared; auto& call = *shared;
Manager::instance().peerHungupCall(call); Manager::instance().peerHungupCall(call);
...@@ -787,7 +788,7 @@ SIPCall::onAnswered() ...@@ -787,7 +788,7 @@ SIPCall::onAnswered()
if (getConnectionState() != ConnectionState::CONNECTED) { if (getConnectionState() != ConnectionState::CONNECTED) {
setState(CallState::ACTIVE, ConnectionState::CONNECTED); setState(CallState::ACTIVE, ConnectionState::CONNECTED);
if (not isSubcall()) { if (not isSubcall()) {
runOnMainThread([w = std::weak_ptr<Call>(shared_from_this())] { runOnMainThread([w = weak()] {
if (auto shared = w.lock()) { if (auto shared = w.lock()) {
Manager::instance().peerAnsweredCall(*shared); Manager::instance().peerAnsweredCall(*shared);
} }
...@@ -1093,13 +1094,12 @@ void ...@@ -1093,13 +1094,12 @@ void
SIPCall::waitForIceAndStartMedia() SIPCall::waitForIceAndStartMedia()
{ {
// Initialization waiting task // Initialization waiting task
auto weak_call = std::weak_ptr<SIPCall>(std::static_pointer_cast<SIPCall>(shared_from_this())); Manager::instance().addTask([weak_call = weak()] {
Manager::instance().addTask([weak_call] {
// TODO: polling algo, to it by event // TODO: polling algo, to it by event
if (auto call = weak_call.lock()) { if (auto call = weak_call.lock()) {
auto ice = call->getIceMediaTransport(); auto ice = call->getIceMediaTransport();
if (ice->isFailed()) { if (not ice or ice->isFailed()) {
JAMI_ERR("[call:%s] Media ICE init failed", call->getCallId().c_str()); JAMI_ERR("[call:%s] Media ICE init failed", call->getCallId().c_str());
call->onFailure(EIO); call->onFailure(EIO);
return false; return false;
...@@ -1126,7 +1126,7 @@ SIPCall::waitForIceAndStartMedia() ...@@ -1126,7 +1126,7 @@ SIPCall::waitForIceAndStartMedia()
if (auto call = weak_call.lock()) { if (auto call = weak_call.lock()) {
auto ice = call->getIceMediaTransport(); auto ice = call->getIceMediaTransport();
if (ice->isFailed()) { if (not ice or ice->isFailed()) {
JAMI_ERR("[call:%s] Media ICE negotiation failed", call->getCallId().c_str()); JAMI_ERR("[call:%s] Media ICE negotiation failed", call->getCallId().c_str());
call->onFailure(EIO); call->onFailure(EIO);
return false; return false;
......
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