Commit 34318366 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

CallSession objects need to be handle by shared_ptr.

parent fda31ecc
......@@ -58,6 +58,11 @@ ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me,
this->subject = subject;
}
ClientGroupChatRoom::~ClientGroupChatRoom () {
shared_ptr<CallSession> 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<const CallSession> session) {
if (session == focus->getPrivate()->getSession())
focus->getPrivate()->removeSession();
}
void ClientGroupChatRoom::onCallSessionStateChanged (const std::shared_ptr<const CallSession> 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);
}
}
......
......@@ -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<const CallSession> session) override;
void onCallSessionStateChanged (const std::shared_ptr<const CallSession> session, LinphoneCallState state, const std::string &message) override;
private:
L_DECLARE_PRIVATE(ClientGroupChatRoom);
......
......@@ -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<const CallSession> session, LinphoneHeaders *headers) {
if (callListener)
callListener->onAckBeingSent(headers);
}
void Conference::onAckReceived (const CallSession &session, LinphoneHeaders *headers) {
void Conference::onAckReceived (const std::shared_ptr<const CallSession> session, LinphoneHeaders *headers) {
if (callListener)
callListener->onAckReceived(headers);
}
void Conference::onCallSessionAccepted (const CallSession &session) {
void Conference::onCallSessionAccepted (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onIncomingCallToBeAdded();
}
void Conference::onCallSessionSetReleased (const CallSession &session) {
void Conference::onCallSessionSetReleased (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onCallSetReleased();
}
void Conference::onCallSessionSetTerminated (const CallSession &session) {
void Conference::onCallSessionSetTerminated (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onCallSetTerminated();
}
void Conference::onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const string &message) {
void Conference::onCallSessionStateChanged (const std::shared_ptr<const CallSession> 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<const CallSession> session) {
if (callListener)
callListener->onCheckForAcceptation();
}
void Conference::onIncomingCallSessionStarted (const CallSession &session) {
void Conference::onIncomingCallSessionStarted (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onIncomingCallStarted();
}
void Conference::onEncryptionChanged (const CallSession &session, bool activated, const string &authToken) {
void Conference::onEncryptionChanged (const std::shared_ptr<const CallSession> 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<const CallSession> session) {
if (callListener)
callListener->onResetCurrentCall();
}
void Conference::onSetCurrentSession (const CallSession &session) {
void Conference::onSetCurrentSession (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onSetCurrentCall();
}
void Conference::onFirstVideoFrameDecoded (const CallSession &session) {
void Conference::onFirstVideoFrameDecoded (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onFirstVideoFrameDecoded();
}
void Conference::onResetFirstVideoFrameDecoded (const CallSession &session) {
void Conference::onResetFirstVideoFrameDecoded (const std::shared_ptr<const CallSession> session) {
if (callListener)
callListener->onResetFirstVideoFrameDecoded();
}
......
......@@ -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<const CallSession> session, LinphoneHeaders *headers) override;
void onAckReceived (const std::shared_ptr<const CallSession> session, LinphoneHeaders *headers) override;
void onCallSessionAccepted (const std::shared_ptr<const CallSession> session) override;
void onCallSessionSetReleased (const std::shared_ptr<const CallSession> session) override;
void onCallSessionSetTerminated (const std::shared_ptr<const CallSession> session) override;
void onCallSessionStateChanged (const std::shared_ptr<const CallSession> session, LinphoneCallState state, const std::string &message) override;
void onCheckForAcceptation (const std::shared_ptr<const CallSession> session) override;
void onIncomingCallSessionStarted (const std::shared_ptr<const CallSession> session) override;
void onEncryptionChanged (const std::shared_ptr<const CallSession> 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<const CallSession> session) override;
void onSetCurrentSession (const std::shared_ptr<const CallSession> session) override;
void onFirstVideoFrameDecoded (const std::shared_ptr<const CallSession> session) override;
void onResetFirstVideoFrameDecoded (const std::shared_ptr<const CallSession> session) override;
protected:
explicit Conference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr);
......
......@@ -40,6 +40,7 @@ public:
std::shared_ptr<CallSession> createSession (const Conference &conference, const CallSessionParams *params, bool hasMedia, CallSessionListener *listener);
std::shared_ptr<CallSession> getSession () const { return session; }
void removeSession () { session = nullptr; }
void setAddress (const Address &newAddr) { addr = newAddr; }
private:
......
......@@ -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<const CallSession> session, LinphoneHeaders *headers) = 0;
virtual void onAckReceived (const std::shared_ptr<const CallSession> session, LinphoneHeaders *headers) = 0;
virtual void onCallSessionAccepted (const std::shared_ptr<const CallSession> session) = 0;
virtual void onCallSessionSetReleased (const std::shared_ptr<const CallSession> session) = 0;
virtual void onCallSessionSetTerminated (const std::shared_ptr<const CallSession> session) = 0;
virtual void onCallSessionStateChanged (const std::shared_ptr<const CallSession> session, LinphoneCallState state, const std::string &message) = 0;
virtual void onCheckForAcceptation (const std::shared_ptr<const CallSession> session) = 0;
virtual void onIncomingCallSessionStarted (const std::shared_ptr<const CallSession> session) = 0;
virtual void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) = 0;
virtual void onEncryptionChanged (const std::shared_ptr<const CallSession> 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<const CallSession> session) = 0;
virtual void onSetCurrentSession (const std::shared_ptr<const CallSession> session) = 0;
virtual void onFirstVideoFrameDecoded (const CallSession &session) = 0;
virtual void onResetFirstVideoFrameDecoded (const CallSession &session) = 0;
virtual void onFirstVideoFrameDecoded (const std::shared_ptr<const CallSession> session) = 0;
virtual void onResetFirstVideoFrameDecoded (const std::shared_ptr<const CallSession> session) = 0;
};
LINPHONE_END_NAMESPACE
......
......@@ -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<CallSession> 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");
......
......@@ -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. */
......
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