From 34318366b6d86767bc7b8dce06ee6304975bb3bf Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 4 Oct 2017 14:59:45 +0200 Subject: [PATCH] CallSession objects need to be handle by shared_ptr. --- src/chat/client-group-chat-room.cpp | 16 +++++++++--- src/chat/client-group-chat-room.h | 5 ++-- src/conference/conference.cpp | 26 +++++++++---------- src/conference/conference.h | 26 +++++++++---------- src/conference/participant-p.h | 1 + .../session/call-session-listener.h | 26 +++++++++---------- src/conference/session/call-session.cpp | 18 ++++++------- src/conference/session/media-session.cpp | 14 +++++----- 8 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/chat/client-group-chat-room.cpp b/src/chat/client-group-chat-room.cpp index 7afe7c70e..6cb6e9b0a 100644 --- a/src/chat/client-group-chat-room.cpp +++ b/src/chat/client-group-chat-room.cpp @@ -58,6 +58,11 @@ ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me, this->subject = subject; } +ClientGroupChatRoom::~ClientGroupChatRoom () { + shared_ptr session = focus->getPrivate()->getSession(); + session->terminate(); +} + // ----------------------------------------------------------------------------- void ClientGroupChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) { @@ -213,12 +218,17 @@ void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { // ----------------------------------------------------------------------------- -void ClientGroupChatRoom::onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const string &message) { +void ClientGroupChatRoom::onCallSessionSetTerminated (const std::shared_ptr session) { + if (session == focus->getPrivate()->getSession()) + focus->getPrivate()->removeSession(); +} + +void ClientGroupChatRoom::onCallSessionStateChanged (const std::shared_ptr session, LinphoneCallState state, const string &message) { if (state == LinphoneCallConnected) { - Address addr(session.getRemoteContact()); + Address addr(session->getRemoteContact()); addr.clean(); onConferenceCreated(addr); - if (session.getRemoteContactAddress()->hasParam("isfocus")) + if (session->getRemoteContactAddress()->hasParam("isfocus")) eventHandler->subscribe(conferenceAddress); } } diff --git a/src/chat/client-group-chat-room.h b/src/chat/client-group-chat-room.h index ff060bf0f..7a12fd0f3 100644 --- a/src/chat/client-group-chat-room.h +++ b/src/chat/client-group-chat-room.h @@ -37,7 +37,7 @@ class ClientGroupChatRoomPrivate; class LINPHONE_PUBLIC ClientGroupChatRoom : public ChatRoom, public RemoteConference { public: ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &subject); - virtual ~ClientGroupChatRoom () = default; + virtual ~ClientGroupChatRoom (); public: /* ConferenceInterface */ @@ -63,7 +63,8 @@ private: private: /* CallSessionListener */ - void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) override; + void onCallSessionSetTerminated (const std::shared_ptr session) override; + void onCallSessionStateChanged (const std::shared_ptr session, LinphoneCallState state, const std::string &message) override; private: L_DECLARE_PRIVATE(ClientGroupChatRoom); diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 1496fa327..95ff53e24 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -84,47 +84,47 @@ void Conference::setSubject (const string &subject) { // ----------------------------------------------------------------------------- -void Conference::onAckBeingSent (const CallSession &session, LinphoneHeaders *headers) { +void Conference::onAckBeingSent (const std::shared_ptr session, LinphoneHeaders *headers) { if (callListener) callListener->onAckBeingSent(headers); } -void Conference::onAckReceived (const CallSession &session, LinphoneHeaders *headers) { +void Conference::onAckReceived (const std::shared_ptr session, LinphoneHeaders *headers) { if (callListener) callListener->onAckReceived(headers); } -void Conference::onCallSessionAccepted (const CallSession &session) { +void Conference::onCallSessionAccepted (const std::shared_ptr session) { if (callListener) callListener->onIncomingCallToBeAdded(); } -void Conference::onCallSessionSetReleased (const CallSession &session) { +void Conference::onCallSessionSetReleased (const std::shared_ptr session) { if (callListener) callListener->onCallSetReleased(); } -void Conference::onCallSessionSetTerminated (const CallSession &session) { +void Conference::onCallSessionSetTerminated (const std::shared_ptr session) { if (callListener) callListener->onCallSetTerminated(); } -void Conference::onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const string &message) { +void Conference::onCallSessionStateChanged (const std::shared_ptr session, LinphoneCallState state, const string &message) { if (callListener) callListener->onCallStateChanged(state, message); } -void Conference::onCheckForAcceptation (const CallSession &session) { +void Conference::onCheckForAcceptation (const std::shared_ptr session) { if (callListener) callListener->onCheckForAcceptation(); } -void Conference::onIncomingCallSessionStarted (const CallSession &session) { +void Conference::onIncomingCallSessionStarted (const std::shared_ptr session) { if (callListener) callListener->onIncomingCallStarted(); } -void Conference::onEncryptionChanged (const CallSession &session, bool activated, const string &authToken) { +void Conference::onEncryptionChanged (const std::shared_ptr session, bool activated, const string &authToken) { if (callListener) callListener->onEncryptionChanged(activated, authToken); } @@ -134,22 +134,22 @@ void Conference::onStatsUpdated (const LinphoneCallStats *stats) { callListener->onStatsUpdated(stats); } -void Conference::onResetCurrentSession (const CallSession &session) { +void Conference::onResetCurrentSession (const std::shared_ptr session) { if (callListener) callListener->onResetCurrentCall(); } -void Conference::onSetCurrentSession (const CallSession &session) { +void Conference::onSetCurrentSession (const std::shared_ptr session) { if (callListener) callListener->onSetCurrentCall(); } -void Conference::onFirstVideoFrameDecoded (const CallSession &session) { +void Conference::onFirstVideoFrameDecoded (const std::shared_ptr session) { if (callListener) callListener->onFirstVideoFrameDecoded(); } -void Conference::onResetFirstVideoFrameDecoded (const CallSession &session) { +void Conference::onResetFirstVideoFrameDecoded (const std::shared_ptr session) { if (callListener) callListener->onResetFirstVideoFrameDecoded(); } diff --git a/src/conference/conference.h b/src/conference/conference.h index fe4b2f80d..213b4ef3d 100644 --- a/src/conference/conference.h +++ b/src/conference/conference.h @@ -60,20 +60,20 @@ public: private: /* CallSessionListener */ - void onAckBeingSent (const CallSession &session, LinphoneHeaders *headers) override; - void onAckReceived (const CallSession &session, LinphoneHeaders *headers) override; - void onCallSessionAccepted (const CallSession &session) override; - void onCallSessionSetReleased (const CallSession &session) override; - void onCallSessionSetTerminated (const CallSession &session) override; - void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) override; - void onCheckForAcceptation (const CallSession &session) override; - void onIncomingCallSessionStarted (const CallSession &session) override; - void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) override; + void onAckBeingSent (const std::shared_ptr session, LinphoneHeaders *headers) override; + void onAckReceived (const std::shared_ptr session, LinphoneHeaders *headers) override; + void onCallSessionAccepted (const std::shared_ptr session) override; + void onCallSessionSetReleased (const std::shared_ptr session) override; + void onCallSessionSetTerminated (const std::shared_ptr session) override; + void onCallSessionStateChanged (const std::shared_ptr session, LinphoneCallState state, const std::string &message) override; + void onCheckForAcceptation (const std::shared_ptr session) override; + void onIncomingCallSessionStarted (const std::shared_ptr session) override; + void onEncryptionChanged (const std::shared_ptr session, bool activated, const std::string &authToken) override; void onStatsUpdated (const LinphoneCallStats *stats) override; - void onResetCurrentSession (const CallSession &session) override; - void onSetCurrentSession (const CallSession &session) override; - void onFirstVideoFrameDecoded (const CallSession &session) override; - void onResetFirstVideoFrameDecoded (const CallSession &session) override; + void onResetCurrentSession (const std::shared_ptr session) override; + void onSetCurrentSession (const std::shared_ptr session) override; + void onFirstVideoFrameDecoded (const std::shared_ptr session) override; + void onResetFirstVideoFrameDecoded (const std::shared_ptr session) override; protected: explicit Conference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr); diff --git a/src/conference/participant-p.h b/src/conference/participant-p.h index 58d522a34..6c7cb5ea7 100644 --- a/src/conference/participant-p.h +++ b/src/conference/participant-p.h @@ -40,6 +40,7 @@ public: std::shared_ptr createSession (const Conference &conference, const CallSessionParams *params, bool hasMedia, CallSessionListener *listener); std::shared_ptr getSession () const { return session; } + void removeSession () { session = nullptr; } void setAddress (const Address &newAddr) { addr = newAddr; } private: diff --git a/src/conference/session/call-session-listener.h b/src/conference/session/call-session-listener.h index cae85a71e..60aa2c2ab 100644 --- a/src/conference/session/call-session-listener.h +++ b/src/conference/session/call-session-listener.h @@ -27,24 +27,24 @@ class LINPHONE_PUBLIC CallSessionListener { public: virtual ~CallSessionListener() = default; - virtual void onAckBeingSent (const CallSession &session, LinphoneHeaders *headers) = 0; - virtual void onAckReceived (const CallSession &session, LinphoneHeaders *headers) = 0; - virtual void onCallSessionAccepted (const CallSession &session) = 0; - virtual void onCallSessionSetReleased (const CallSession &session) = 0; - virtual void onCallSessionSetTerminated (const CallSession &session) = 0; - virtual void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) = 0; - virtual void onCheckForAcceptation (const CallSession &session) = 0; - virtual void onIncomingCallSessionStarted (const CallSession &session) = 0; + virtual void onAckBeingSent (const std::shared_ptr session, LinphoneHeaders *headers) = 0; + virtual void onAckReceived (const std::shared_ptr session, LinphoneHeaders *headers) = 0; + virtual void onCallSessionAccepted (const std::shared_ptr session) = 0; + virtual void onCallSessionSetReleased (const std::shared_ptr session) = 0; + virtual void onCallSessionSetTerminated (const std::shared_ptr session) = 0; + virtual void onCallSessionStateChanged (const std::shared_ptr session, LinphoneCallState state, const std::string &message) = 0; + virtual void onCheckForAcceptation (const std::shared_ptr session) = 0; + virtual void onIncomingCallSessionStarted (const std::shared_ptr session) = 0; - virtual void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) = 0; + virtual void onEncryptionChanged (const std::shared_ptr session, bool activated, const std::string &authToken) = 0; virtual void onStatsUpdated (const LinphoneCallStats *stats) = 0; - virtual void onResetCurrentSession (const CallSession &session) = 0; - virtual void onSetCurrentSession (const CallSession &session) = 0; + virtual void onResetCurrentSession (const std::shared_ptr session) = 0; + virtual void onSetCurrentSession (const std::shared_ptr session) = 0; - virtual void onFirstVideoFrameDecoded (const CallSession &session) = 0; - virtual void onResetFirstVideoFrameDecoded (const CallSession &session) = 0; + virtual void onFirstVideoFrameDecoded (const std::shared_ptr session) = 0; + virtual void onResetFirstVideoFrameDecoded (const std::shared_ptr session) = 0; }; LINPHONE_END_NAMESPACE diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp index 0a3db26cc..562cb9420 100644 --- a/src/conference/session/call-session.cpp +++ b/src/conference/session/call-session.cpp @@ -174,7 +174,7 @@ void CallSessionPrivate::setState(LinphoneCallState newState, const string &mess linphone_call_state_to_string(prevState) << " to " << linphone_call_state_to_string(state) << ")"; } if (listener) - listener->onCallSessionStateChanged(*q, state, message); + listener->onCallSessionStateChanged(q->getSharedFromThis(), state, message); if (newState == LinphoneCallReleased) setReleased(); /* Shall be performed after app notification */ } @@ -231,13 +231,13 @@ void CallSessionPrivate::accepted () { void CallSessionPrivate::ackBeingSent (LinphoneHeaders *headers) { L_Q(); if (listener) - listener->onAckBeingSent(*q, headers); + listener->onAckBeingSent(q->getSharedFromThis(), headers); } void CallSessionPrivate::ackReceived (LinphoneHeaders *headers) { L_Q(); if (listener) - listener->onAckReceived(*q, headers); + listener->onAckReceived(q->getSharedFromThis(), headers); } bool CallSessionPrivate::failure () { @@ -431,7 +431,7 @@ void CallSessionPrivate::accept (const CallSessionParams *params) { op->accept(); if (listener) - listener->onSetCurrentSession(*q); + listener->onSetCurrentSession(q->getSharedFromThis()); setState(LinphoneCallConnected, "Connected"); } @@ -450,7 +450,7 @@ LinphoneStatus CallSessionPrivate::checkForAcceptation () const { return -1; } if (listener) - listener->onCheckForAcceptation(*q); + listener->onCheckForAcceptation(q->getSharedFromThis()); /* Check if this call is supposed to replace an already running one */ SalOp *replaced = op->get_replaces(); @@ -547,7 +547,7 @@ void CallSessionPrivate::setReleased () { } #endif if (listener) - listener->onCallSessionSetReleased(*q); + listener->onCallSessionSetReleased(q->getSharedFromThis()); } /* This method is called internally to get rid of a call that was notified to the application, @@ -559,7 +559,7 @@ void CallSessionPrivate::setTerminated() { L_Q(); completeLog(); if (listener) - listener->onCallSessionSetTerminated(*q); + listener->onCallSessionSetTerminated(q->getSharedFromThis()); } LinphoneStatus CallSessionPrivate::startAcceptUpdate (LinphoneCallState nextState, const std::string &stateInfo) { @@ -837,7 +837,7 @@ LinphoneStatus CallSession::redirect (const Address &redirectAddr) { void CallSession::startIncomingNotification () { L_D(); if (d->listener) - d->listener->onCallSessionAccepted(*this); + d->listener->onCallSessionAccepted(getSharedFromThis()); /* Prevent the CallSession from being destroyed while we are notifying, if the user declines within the state callback */ shared_ptr ref = getSharedFromThis(); #if 0 @@ -849,7 +849,7 @@ void CallSession::startIncomingNotification () { } if (d->listener) - d->listener->onIncomingCallSessionStarted(*this); + d->listener->onIncomingCallSessionStarted(getSharedFromThis()); d->setState(LinphoneCallIncomingReceived, "Incoming CallSession"); diff --git a/src/conference/session/media-session.cpp b/src/conference/session/media-session.cpp index c56921792..09c4b89cf 100644 --- a/src/conference/session/media-session.cpp +++ b/src/conference/session/media-session.cpp @@ -164,7 +164,7 @@ void MediaSessionPrivate::accepted () { nextStateMsg = "Call paused by remote"; } else { if (!params->getPrivate()->getInConference() && listener) - listener->onSetCurrentSession(*q); + listener->onSetCurrentSession(q->getSharedFromThis()); nextState = LinphoneCallStreamsRunning; nextStateMsg = "Streams running"; } @@ -2921,7 +2921,7 @@ void MediaSessionPrivate::startVideoStream (LinphoneCallState targetState) { } ms_media_stream_sessions_set_encryption_mandatory(&videoStream->ms.sessions, isEncryptionMandatory()); if (listener) - listener->onResetFirstVideoFrameDecoded(*q); + listener->onResetFirstVideoFrameDecoded(q->getSharedFromThis()); /* Start ZRTP engine if needed : set here or remote have a zrtp-hash attribute */ SalMediaDescription *remote = op->get_remote_media_description(); const SalStreamDescription *remoteStream = sal_media_description_find_best_stream(remote, SalVideo); @@ -3344,7 +3344,7 @@ void MediaSessionPrivate::propagateEncryptionChanged () { lInfo() << "Some streams are not encrypted"; q->getCurrentParams()->setMediaEncryption(LinphoneMediaEncryptionNone); if (listener) - listener->onEncryptionChanged(*q, false, authToken); + listener->onEncryptionChanged(q->getSharedFromThis(), false, authToken); } else { if (!authToken.empty()) { /* ZRTP only is using auth_token */ @@ -3357,7 +3357,7 @@ void MediaSessionPrivate::propagateEncryptionChanged () { << ((q->getCurrentParams()->getMediaEncryption() == LinphoneMediaEncryptionZRTP) ? "ZRTP" : (q->getCurrentParams()->getMediaEncryption() == LinphoneMediaEncryptionDTLS) ? "DTLS" : "Unknown mechanism"); if (listener) - listener->onEncryptionChanged(*q, true, authToken); + listener->onEncryptionChanged(q->getSharedFromThis(), true, authToken); #ifdef VIDEO_ENABLED if (isEncryptionMandatory() && videoStream && media_stream_started(&videoStream->ms)) { /* Nothing could have been sent yet so generating key frame */ @@ -3671,7 +3671,7 @@ LinphoneStatus MediaSessionPrivate::pause () { op->set_local_media_description(localDesc); op->update(subject.c_str(), false); if (listener) - listener->onResetCurrentSession(*q); + listener->onResetCurrentSession(q->getSharedFromThis()); if (audioStream || videoStream || textStream) stopStreams(); pausedByApp = false; @@ -3932,7 +3932,7 @@ void MediaSessionPrivate::videoStreamEventCb (const MSFilter *f, const unsigned case MS_VIDEO_DECODER_FIRST_IMAGE_DECODED: lInfo() << "First video frame decoded successfully"; if (listener) - listener->onFirstVideoFrameDecoded(*q); + listener->onFirstVideoFrameDecoded(q->getSharedFromThis()); break; case MS_VIDEO_DECODER_SEND_PLI: case MS_VIDEO_DECODER_SEND_SLI: @@ -4200,7 +4200,7 @@ LinphoneStatus MediaSession::resume () { return -1; d->setState(LinphoneCallResuming,"Resuming"); if (!d->params->getPrivate()->getInConference() && d->listener) - d->listener->onSetCurrentSession(*this); + d->listener->onSetCurrentSession(getSharedFromThis()); if (d->core->sip_conf.sdp_200_ack) { /* We are NOT offering, set local media description after sending the call so that we are ready to * process the remote offer when it will arrive. */