From 983471e8d0aec48f00d8c038109d363b6aec1a81 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 12 Feb 2018 17:48:55 +0100 Subject: [PATCH] For fixes for real time text. --- coreapi/call_log.c | 6 +- coreapi/chat.c | 10 +-- coreapi/private_structs.h | 5 -- coreapi/private_types.h | 2 - include/linphone/call_log.h | 9 ++- src/c-wrapper/api/c-call.cpp | 15 ++-- src/c-wrapper/api/c-chat-room.cpp | 18 +++-- src/call/call-p.h | 5 ++ src/call/call.cpp | 29 +++++-- src/call/call.h | 3 +- src/chat/chat-message/chat-message.cpp | 76 ++++++++++--------- .../chat-room/real-time-text-chat-room-p.h | 12 ++- .../chat-room/real-time-text-chat-room.cpp | 53 ++++++------- src/chat/chat-room/real-time-text-chat-room.h | 6 +- .../session/call-session-listener.h | 4 + src/conference/session/call-session.cpp | 10 ++- src/conference/session/call-session.h | 10 +-- src/conference/session/media-session.cpp | 9 +-- tester/message_tester.c | 1 + 19 files changed, 156 insertions(+), 127 deletions(-) diff --git a/coreapi/call_log.c b/coreapi/call_log.c index 176ad4960..abdcf98b5 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -198,7 +198,11 @@ const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){ return cl->refkey; } -LinphoneAddress *linphone_call_log_get_remote_address(const LinphoneCallLog *cl){ +const LinphoneAddress *linphone_call_log_get_local_address(const LinphoneCallLog *cl) { + return (cl->dir == LinphoneCallIncoming) ? cl->to : cl->from; +} + +const LinphoneAddress *linphone_call_log_get_remote_address(const LinphoneCallLog *cl){ return (cl->dir == LinphoneCallIncoming) ? cl->from : cl->to; } diff --git a/coreapi/chat.c b/coreapi/chat.c index 19a3d040a..ac9c8dcf0 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -36,6 +36,7 @@ #include "linphone/wrapper_utils.h" #include "c-wrapper/c-wrapper.h" +#include "call/call.h" #include "chat/chat-room/basic-chat-room.h" #include "chat/chat-room/client-group-chat-room.h" #include "chat/chat-room/client-group-to-basic-chat-room.h" @@ -149,12 +150,9 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, } void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call) { - if (linphone_core_realtime_text_enabled(lc)) { - shared_ptr rttcr = - static_pointer_cast(L_GET_CPP_PTR_FROM_C_OBJECT(cr)); - L_GET_PRIVATE(rttcr)->realtimeTextReceived(character, call); - //L_GET_PRIVATE(static_pointer_cast(L_GET_CPP_PTR_FROM_C_OBJECT(cr)))->realtimeTextReceived(character, call); - } + if (!(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::RealTimeText)) + return; + L_GET_PRIVATE_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->realtimeTextReceived(character, L_GET_CPP_PTR_FROM_C_OBJECT(call)); } unsigned int linphone_chat_message_store(LinphoneChatMessage *msg) { diff --git a/coreapi/private_structs.h b/coreapi/private_structs.h index 073598723..993e5f983 100644 --- a/coreapi/private_structs.h +++ b/coreapi/private_structs.h @@ -151,11 +151,6 @@ struct _LinphoneAuthInfo char *algorithm; }; -struct _LinphoneChatMessageCharacter { - uint32_t value; - bool_t has_been_read; -}; - struct _LinphoneFriendPresence { char *uri_or_tel; LinphonePresenceModel *presence; diff --git a/coreapi/private_types.h b/coreapi/private_types.h index f646ce3ce..5e7ca8029 100644 --- a/coreapi/private_types.h +++ b/coreapi/private_types.h @@ -27,8 +27,6 @@ typedef struct StunCandidate StunCandidate; typedef struct _PortConfig PortConfig; -typedef struct _LinphoneChatMessageCharacter LinphoneChatMessageCharacter; - typedef struct _LinphoneFriendPresence LinphoneFriendPresence; typedef struct _LinphoneFriendPhoneNumberSipUri LinphoneFriendPhoneNumberSipUri; diff --git a/include/linphone/call_log.h b/include/linphone/call_log.h index 205865fad..004377e55 100644 --- a/include/linphone/call_log.h +++ b/include/linphone/call_log.h @@ -90,12 +90,19 @@ LINPHONE_PUBLIC float linphone_call_log_get_quality(const LinphoneCallLog *cl); **/ LINPHONE_PUBLIC const char * linphone_call_log_get_ref_key(const LinphoneCallLog *cl); +/** + * Get the local address (that is from or to depending on call direction) + * @param[in] cl LinphoneCallLog object + * @return The local address of the call + */ +LINPHONE_PUBLIC const LinphoneAddress *linphone_call_log_get_local_address(const LinphoneCallLog *cl); + /** * Get the remote address (that is from or to depending on call direction). * @param[in] cl LinphoneCallLog object * @return The remote address of the call. **/ -LINPHONE_PUBLIC LinphoneAddress * linphone_call_log_get_remote_address(const LinphoneCallLog *cl); +LINPHONE_PUBLIC const LinphoneAddress * linphone_call_log_get_remote_address(const LinphoneCallLog *cl); /** * Get the RTP statistics computed by the remote end and sent back via RTCP. diff --git a/src/c-wrapper/api/c-call.cpp b/src/c-wrapper/api/c-call.cpp index 3f0b4f376..07159bfc4 100644 --- a/src/c-wrapper/api/c-call.cpp +++ b/src/c-wrapper/api/c-call.cpp @@ -27,6 +27,7 @@ #include "call/call.h" #include "call/local-conference-call.h" #include "call/remote-conference-call.h" +#include "chat/chat-room/real-time-text-chat-room.h" #include "conference/params/media-session-params-p.h" #include "core/core-p.h" @@ -246,7 +247,7 @@ const char *linphone_call_get_to_header (const LinphoneCall *call, const char *n } char *linphone_call_get_remote_address_as_string (const LinphoneCall *call) { - return ms_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(call)->getRemoteAddressAsString().c_str()); + return ms_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(call)->getRemoteAddress().asString().c_str()); } const LinphoneAddress *linphone_call_get_diversion_address (const LinphoneCall *call) { @@ -538,16 +539,10 @@ bool_t linphone_call_echo_limiter_enabled (const LinphoneCall *call) { } LinphoneChatRoom *linphone_call_get_chat_room (LinphoneCall *call) { -#if 0 - if (!call->chat_room){ - if (call->state != LinphoneCallReleased && call->state != LinphoneCallEnd){ - call->chat_room = _linphone_core_create_chat_room_from_call(call); - } - } - return call->chat_room; -#else + shared_ptr acr = L_GET_PRIVATE_FROM_C_OBJECT(call)->getChatRoom(); + if (acr) + return L_GET_C_BACK_PTR(acr); return nullptr; -#endif } float linphone_call_get_play_volume (const LinphoneCall *call) { diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 3288f1073..72fad5d60 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -27,6 +27,7 @@ #include "address/identity-address.h" #include "c-wrapper/c-wrapper.h" +#include "call/call.h" #include "chat/chat-message/chat-message-p.h" #include "chat/chat-room/basic-chat-room.h" #include "chat/chat-room/client-group-chat-room-p.h" @@ -156,9 +157,9 @@ void linphone_chat_room_receive_chat_message (LinphoneChatRoom *cr, LinphoneChat } uint32_t linphone_chat_room_get_char (const LinphoneChatRoom *cr) { - if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr))) - return L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getChar(); - return 0; + if (!(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::RealTimeText)) + return 0; + return L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getChar(); } void linphone_chat_room_compose (LinphoneChatRoom *cr) { @@ -166,14 +167,15 @@ void linphone_chat_room_compose (LinphoneChatRoom *cr) { } LinphoneCall *linphone_chat_room_get_call (const LinphoneChatRoom *cr) { - if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr))) - return L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getCall(); - return nullptr; + if (!(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::RealTimeText)) + return nullptr; + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getCall()); } void linphone_chat_room_set_call (LinphoneChatRoom *cr, LinphoneCall *call) { - if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr))) - L_GET_PRIVATE_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->call = call; + if (!(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::RealTimeText)) + return; + L_GET_PRIVATE_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->call = L_GET_CPP_PTR_FROM_C_OBJECT(call); } void linphone_chat_room_mark_as_read (LinphoneChatRoom *cr) { diff --git a/src/call/call-p.h b/src/call/call-p.h index 71eb8fa41..09f796d4c 100644 --- a/src/call/call-p.h +++ b/src/call/call-p.h @@ -34,6 +34,7 @@ LINPHONE_BEGIN_NAMESPACE class CallSession; +class RealTimeTextChatRoom; class CallPrivate : public ObjectPrivate, public CallSessionListener { public: @@ -50,6 +51,7 @@ public: virtual std::shared_ptr getActiveSession () const { return nullptr; } bool getAudioMuted () const; + std::shared_ptr getChatRoom (); LinphoneProxyConfig *getDestProxy () const; IceSession *getIceSession () const; @@ -109,6 +111,7 @@ private: void onStopRingingIfNeeded (const std::shared_ptr &session) override; bool areSoundResourcesAvailable (const std::shared_ptr &session) override; bool isPlayingRingbackTone (const std::shared_ptr &session) override; + void onRealTimeTextCharacterReceived (const std::shared_ptr &session, RealtimeTextReceivedCharacter *character) override; mutable LinphonePlayer *player = nullptr; @@ -119,6 +122,8 @@ private: BackgroundTask bgTask; + mutable std::shared_ptr chatRoom; + L_DECLARE_PUBLIC(Call); }; diff --git a/src/call/call.cpp b/src/call/call.cpp index 973e352e3..6153c3848 100644 --- a/src/call/call.cpp +++ b/src/call/call.cpp @@ -19,6 +19,7 @@ #include "c-wrapper/c-wrapper.h" #include "call-p.h" +#include "chat/chat-room/real-time-text-chat-room-p.h" #include "conference/params/media-session-params-p.h" #include "conference/session/call-session-p.h" #include "conference/session/media-session-p.h" @@ -37,6 +38,17 @@ bool CallPrivate::getAudioMuted () const { return static_pointer_cast(getActiveSession())->getPrivate()->getAudioMuted(); } +shared_ptr CallPrivate::getChatRoom () { + L_Q(); + if (!chatRoom && (q->getState() != CallSession::State::End) && (q->getState() != CallSession::State::Released)) { + ChatRoomId chatRoomId(q->getRemoteAddress(), q->getLocalAddress()); + RealTimeTextChatRoom *rttcr = new RealTimeTextChatRoom(q->getCore(), chatRoomId); + chatRoom.reset(rttcr); + rttcr->getPrivate()->setCall(q->getSharedFromThis()); + } + return chatRoom; +} + LinphoneProxyConfig *CallPrivate::getDestProxy () const { return getActiveSession()->getPrivate()->getDestProxy(); } @@ -167,7 +179,7 @@ void CallPrivate::startRemoteRing () { void CallPrivate::terminateBecauseOfLostMedia () { L_Q(); - lInfo() << "Call [" << q << "]: Media connectivity with " << q->getRemoteAddressAsString() + lInfo() << "Call [" << q << "]: Media connectivity with " << q->getRemoteAddress().asString() << " is lost, call is going to be terminated"; static_pointer_cast(getActiveSession())->terminateBecauseOfLostMedia(); linphone_core_play_named_tone(q->getCore()->getCCore(), LinphoneToneCallLost); @@ -459,6 +471,11 @@ bool CallPrivate::isPlayingRingbackTone (const shared_ptr &se return playingRingbackTone; } +void CallPrivate::onRealTimeTextCharacterReceived (const shared_ptr &session, RealtimeTextReceivedCharacter *data) { + L_Q(); + getChatRoom()->getPrivate()->realtimeTextReceived(data->character, q->getSharedFromThis()); +} + // ============================================================================= Call::Call (CallPrivate &p, shared_ptr core) : Object(p), CoreAccessor(core) { @@ -682,6 +699,11 @@ const LinphoneErrorInfo *Call::getErrorInfo () const { return d->getActiveSession()->getErrorInfo(); } +const Address &Call::getLocalAddress () const { + L_D(); + return d->getActiveSession()->getLocalAddress(); +} + LinphoneCallLog *Call::getLog () const { L_D(); return d->getActiveSession()->getLog(); @@ -756,11 +778,6 @@ const Address &Call::getRemoteAddress () const { return d->getActiveSession()->getRemoteAddress(); } -string Call::getRemoteAddressAsString () const { - L_D(); - return d->getActiveSession()->getRemoteAddressAsString(); -} - string Call::getRemoteContact () const { L_D(); return d->getActiveSession()->getRemoteContact(); diff --git a/src/call/call.h b/src/call/call.h index 6d1059127..15204a797 100644 --- a/src/call/call.h +++ b/src/call/call.h @@ -36,6 +36,7 @@ class MediaSessionPrivate; class Call : public Object, public CoreAccessor { friend class CallSessionPrivate; + friend class ChatMessage; friend class CorePrivate; friend class MediaSessionPrivate; @@ -85,6 +86,7 @@ public: const Address &getDiversionAddress () const; int getDuration () const; const LinphoneErrorInfo *getErrorInfo () const; + const Address &getLocalAddress () const; LinphoneCallLog *getLog () const; RtpTransport *getMetaRtcpTransport (int streamIndex) const; RtpTransport *getMetaRtpTransport (int streamIndex) const; @@ -98,7 +100,6 @@ public: std::shared_ptr getReferer () const; std::string getReferTo () const; const Address &getRemoteAddress () const; - std::string getRemoteAddressAsString () const; std::string getRemoteContact () const; const MediaSessionParams *getRemoteParams () const; std::string getRemoteUserAgent () const; diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index d6f7d3f95..13045da1f 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -25,7 +25,7 @@ #include "address/address.h" #include "c-wrapper/c-wrapper.h" -#include "call/call.h" +#include "call/call-p.h" #include "chat/chat-message/chat-message-p.h" #include "chat/chat-room/chat-room-p.h" #include "chat/chat-room/client-group-to-basic-chat-room.h" @@ -981,48 +981,50 @@ void ChatMessage::cancelFileTransfer () { int ChatMessage::putCharacter (uint32_t character) { L_D(); - shared_ptr core = getCore(); - if (linphone_core_realtime_text_enabled(core->getCCore())) { - static const uint32_t new_line = 0x2028; - static const uint32_t crlf = 0x0D0A; - static const uint32_t lf = 0x0A; + static const uint32_t new_line = 0x2028; + static const uint32_t crlf = 0x0D0A; + static const uint32_t lf = 0x0A; - shared_ptr chatRoom = getChatRoom(); + shared_ptr chatRoom = getChatRoom(); + if (!(chatRoom->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::RealTimeText)) + return -1; - shared_ptr rttcr = - static_pointer_cast(chatRoom); - LinphoneCall *call = rttcr->getCall(); + shared_ptr rttcr = + static_pointer_cast(chatRoom); + if (!rttcr) + return -1; - if (!call || !linphone_call_get_stream(call, LinphoneStreamTypeText)) - return -1; + shared_ptr call = rttcr->getCall(); + if (!call || !call->getPrivate()->getMediaStream(LinphoneStreamTypeText)) + return -1; - if (character == new_line || character == crlf || character == lf) { - if (lp_config_get_int(core->getCCore()->config, "misc", "store_rtt_messages", 1) == 1) { - // TODO: History. - lDebug() << "New line sent, forge a message with content " << d->rttMessage.c_str(); - d->setTime(ms_time(0)); - d->state = State::Displayed; - // d->direction = Direction::Outgoing; - // setFromAddress(Address( - // linphone_address_as_string(linphone_address_new(linphone_core_get_identity(core->getCCore()))) - // )); - // linphone_chat_message_store(L_GET_C_BACK_PTR(this)); - d->rttMessage = ""; - } - } else { - char *value = LinphonePrivate::Utils::utf8ToChar(character); - d->rttMessage = d->rttMessage + string(value); - lDebug() << "Sent RTT character: " << value << "(" << (unsigned long)character << - "), pending text is " << d->rttMessage.c_str(); - delete value; + if (character == new_line || character == crlf || character == lf) { + shared_ptr core = getCore(); + if (lp_config_get_int(core->getCCore()->config, "misc", "store_rtt_messages", 1) == 1) { + // TODO: History. + lDebug() << "New line sent, forge a message with content " << d->rttMessage.c_str(); + d->setTime(ms_time(0)); + d->state = State::Displayed; + // d->direction = Direction::Outgoing; + // setFromAddress(Address( + // linphone_address_as_string(linphone_address_new(linphone_core_get_identity(core->getCCore()))) + // )); + // linphone_chat_message_store(L_GET_C_BACK_PTR(this)); + d->rttMessage = ""; } - - text_stream_putchar32(reinterpret_cast( - linphone_call_get_stream(call, LinphoneStreamTypeText)), character - ); - return 0; + } else { + char *value = LinphonePrivate::Utils::utf8ToChar(character); + d->rttMessage = d->rttMessage + string(value); + lDebug() << "Sent RTT character: " << value << "(" << (unsigned long)character << + "), pending text is " << d->rttMessage.c_str(); + delete[] value; } - return -1; + + text_stream_putchar32( + reinterpret_cast(call->getPrivate()->getMediaStream(LinphoneStreamTypeText)), + character + ); + return 0; } LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-room/real-time-text-chat-room-p.h b/src/chat/chat-room/real-time-text-chat-room-p.h index c8e5e2b62..ae9af9de3 100644 --- a/src/chat/chat-room/real-time-text-chat-room-p.h +++ b/src/chat/chat-room/real-time-text-chat-room-p.h @@ -29,13 +29,19 @@ LINPHONE_BEGIN_NAMESPACE class RealTimeTextChatRoomPrivate : public BasicChatRoomPrivate { public: + struct Character { + uint32_t value; + bool hasBeenRead; + }; + RealTimeTextChatRoomPrivate () = default; - void realtimeTextReceived (uint32_t character, LinphoneCall *call); + void realtimeTextReceived (uint32_t character, const std::shared_ptr &call); void sendChatMessage (const std::shared_ptr &chatMessage) override; + void setCall (const std::shared_ptr &value) { call = value; } - LinphoneCall *call = nullptr; - std::list receivedRttCharacters; + std::weak_ptr call; + std::list receivedRttCharacters; std::shared_ptr pendingMessage = nullptr; private: diff --git a/src/chat/chat-room/real-time-text-chat-room.cpp b/src/chat/chat-room/real-time-text-chat-room.cpp index f12e120b3..ec6eb3df5 100644 --- a/src/chat/chat-room/real-time-text-chat-room.cpp +++ b/src/chat/chat-room/real-time-text-chat-room.cpp @@ -18,6 +18,7 @@ */ #include "c-wrapper/c-wrapper.h" +#include "call/call.h" #include "chat/chat-message/chat-message-p.h" #include "conference/participant.h" #include "core/core.h" @@ -32,7 +33,7 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- -void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, LinphoneCall *call) { +void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, const shared_ptr &call) { L_Q(); const uint32_t new_line = 0x2028; const uint32_t crlf = 0x0D0A; @@ -41,14 +42,13 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp shared_ptr core = q->getCore(); LinphoneCore *cCore = core->getCCore(); - if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) { - LinphoneChatMessageCharacter *cmc = bctbx_new0(LinphoneChatMessageCharacter, 1); - + if (call && call->getCurrentParams()->realtimeTextEnabled()) { if (!pendingMessage) pendingMessage = q->createChatMessage(""); - cmc->value = character; - cmc->has_been_read = FALSE; + Character cmc; + cmc.value = character; + cmc.hasBeenRead = false; receivedRttCharacters.push_back(cmc); remoteIsComposing.push_back(q->getPeerAddress()); @@ -74,23 +74,24 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp onChatMessageReceived(pendingMessage); pendingMessage = nullptr; - for (auto &rttChars : receivedRttCharacters) - ms_free(rttChars); receivedRttCharacters.clear(); } else { char *value = Utils::utf8ToChar(character); - char *text = (char *)pendingMessage->getPrivate()->getText().c_str(); - pendingMessage->getPrivate()->setText(ms_strcat_printf(text, value)); - lDebug() << "Received RTT character: " << value << " (" << character << "), pending text is " << pendingMessage->getPrivate()->getText(); - delete value; + string text(pendingMessage->getPrivate()->getText()); + text += string(value); + pendingMessage->getPrivate()->setText(text); + lInfo() << "Received RTT character: " << value << " (" << character << "), pending text is " << pendingMessage->getPrivate()->getText(); + delete[] value; } } } void RealTimeTextChatRoomPrivate::sendChatMessage (const shared_ptr &chatMessage) { - if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) { - uint32_t new_line = 0x2028; - chatMessage->putCharacter(new_line); + L_Q(); + shared_ptr call = q->getCall(); + if (call && call->getCurrentParams()->realtimeTextEnabled()) { + uint32_t newLine = 0x2028; + chatMessage->putCharacter(newLine); } } @@ -99,26 +100,16 @@ void RealTimeTextChatRoomPrivate::sendChatMessage (const shared_ptr RealTimeTextChatRoom::RealTimeTextChatRoom (const shared_ptr &core, const ChatRoomId &chatRoomId) : BasicChatRoom(*new RealTimeTextChatRoomPrivate, core, chatRoomId) {} -RealTimeTextChatRoom::~RealTimeTextChatRoom () { - L_D(); - - if (!d->receivedRttCharacters.empty()) - for (auto &rttChars : d->receivedRttCharacters) - bctbx_free(rttChars); -} - RealTimeTextChatRoom::CapabilitiesMask RealTimeTextChatRoom::getCapabilities () const { return BasicChatRoom::getCapabilities() | Capabilities::RealTimeText; } uint32_t RealTimeTextChatRoom::getChar () const { L_D(); - if (!d->receivedRttCharacters.empty()) { - for (auto &cmc : d->receivedRttCharacters) { - if (!cmc->has_been_read) { - cmc->has_been_read = TRUE; - return cmc->value; - } + for (const auto &cmc : d->receivedRttCharacters) { + if (!cmc.hasBeenRead) { + const_cast(&cmc)->hasBeenRead = true; + return cmc.value; } } return 0; @@ -126,9 +117,9 @@ uint32_t RealTimeTextChatRoom::getChar () const { // ----------------------------------------------------------------------------- -LinphoneCall *RealTimeTextChatRoom::getCall () const { +shared_ptr RealTimeTextChatRoom::getCall () const { L_D(); - return d->call; + return d->call.lock(); } LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-room/real-time-text-chat-room.h b/src/chat/chat-room/real-time-text-chat-room.h index 7206bf3bc..4f0d8cb7f 100644 --- a/src/chat/chat-room/real-time-text-chat-room.h +++ b/src/chat/chat-room/real-time-text-chat-room.h @@ -26,18 +26,20 @@ LINPHONE_BEGIN_NAMESPACE +class Call; class RealTimeTextChatRoomPrivate; class LINPHONE_PUBLIC RealTimeTextChatRoom : public BasicChatRoom { + friend class CallPrivate; friend class CorePrivate; public: - ~RealTimeTextChatRoom (); + ~RealTimeTextChatRoom () = default; CapabilitiesMask getCapabilities () const override; uint32_t getChar () const; - LinphoneCall *getCall () const; + std::shared_ptr getCall () const; private: RealTimeTextChatRoom (const std::shared_ptr &core, const ChatRoomId &chatRoomId); diff --git a/src/conference/session/call-session-listener.h b/src/conference/session/call-session-listener.h index f14d9249c..65f76eeb6 100644 --- a/src/conference/session/call-session-listener.h +++ b/src/conference/session/call-session-listener.h @@ -22,6 +22,8 @@ #include "conference/session/call-session.h" +#include + // ============================================================================= LINPHONE_BEGIN_NAMESPACE @@ -75,6 +77,8 @@ public: virtual bool areSoundResourcesAvailable (const std::shared_ptr &session) { return true; } virtual bool isPlayingRingbackTone (const std::shared_ptr &session) { return false; } + + virtual void onRealTimeTextCharacterReceived (const std::shared_ptr &session, RealtimeTextReceivedCharacter *data) {} }; LINPHONE_END_NAMESPACE diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp index 97aa06f6f..944fb8b91 100644 --- a/src/conference/session/call-session.cpp +++ b/src/conference/session/call-session.cpp @@ -1226,6 +1226,12 @@ const LinphoneErrorInfo * CallSession::getErrorInfo () const { return d->ei; } +const Address& CallSession::getLocalAddress () const { + L_D(); + return *L_GET_CPP_PTR_FROM_C_OBJECT((d->direction == LinphoneCallIncoming) + ? linphone_call_log_get_to(d->log) : linphone_call_log_get_from(d->log)); +} + LinphoneCallLog * CallSession::getLog () const { L_D(); return d->log; @@ -1251,10 +1257,6 @@ const Address& CallSession::getRemoteAddress () const { ? linphone_call_log_get_from(d->log) : linphone_call_log_get_to(d->log)); } -string CallSession::getRemoteAddressAsString () const { - return getRemoteAddress().asString(); -} - string CallSession::getRemoteContact () const { L_D(); if (d->op) { diff --git a/src/conference/session/call-session.h b/src/conference/session/call-session.h index cddbfbaa4..4fc531734 100644 --- a/src/conference/session/call-session.h +++ b/src/conference/session/call-session.h @@ -78,23 +78,23 @@ public: CallSessionParams *getCurrentParams () const; LinphoneCallDir getDirection () const; - const Address& getDiversionAddress () const; + const Address &getDiversionAddress () const; int getDuration () const; const LinphoneErrorInfo * getErrorInfo () const; - LinphoneCallLog * getLog () const; + const Address &getLocalAddress () const; + LinphoneCallLog *getLog () const; virtual const CallSessionParams *getParams () const; LinphoneReason getReason () const; std::shared_ptr getReferer () const; std::string getReferTo () const; - const Address& getRemoteAddress () const; - std::string getRemoteAddressAsString () const; + const Address &getRemoteAddress () const; std::string getRemoteContact () const; const Address *getRemoteContactAddress () const; const CallSessionParams *getRemoteParams (); std::string getRemoteUserAgent () const; std::shared_ptr getReplacedCallSession () const; CallSession::State getState () const; - const Address& getToAddress () const; + const Address &getToAddress () const; CallSession::State getTransferState () const; std::shared_ptr getTransferTarget () const; std::string getToHeader (const std::string &name) const; diff --git a/src/conference/session/media-session.cpp b/src/conference/session/media-session.cpp index b3b6f04cd..89ab3d443 100644 --- a/src/conference/session/media-session.cpp +++ b/src/conference/session/media-session.cpp @@ -2830,7 +2830,7 @@ void MediaSessionPrivate::startTextStream () { rtp_session_set_multicast_ttl(textStream->ms.sessions.rtp_session, tstream->ttl); text_stream_start(textStream, textProfile, rtpAddr, tstream->rtp_port, rtcpAddr, (linphone_core_rtcp_enabled(q->getCore()->getCCore()) && !isMulticast) ? (tstream->rtcp_port ? tstream->rtcp_port : tstream->rtp_port + 1) : 0, usedPt); - ms_filter_add_notify_callback(textStream->rttsink, realTimeTextCharacterReceived, q, false); + ms_filter_add_notify_callback(textStream->rttsink, realTimeTextCharacterReceived, this, false); ms_media_stream_sessions_set_encryption_mandatory(&textStream->ms.sessions, isEncryptionMandatory()); } } else @@ -3806,12 +3806,11 @@ void MediaSessionPrivate::videoStreamEventCb (const MSFilter *f, const unsigned #endif void MediaSessionPrivate::realTimeTextCharacterReceived (MSFilter *f, unsigned int id, void *arg) { + L_Q(); if (id == MS_RTT_4103_RECEIVED_CHAR) { -#if 0 RealtimeTextReceivedCharacter *data = reinterpret_cast(arg); - LinphoneChatRoom * chat_room = linphone_call_get_chat_room(call); - linphone_core_real_time_text_received(call->core, chat_room, data->character, call); -#endif + if (listener) + listener->onRealTimeTextCharacterReceived(q->getSharedFromThis(), data); } } diff --git a/tester/message_tester.c b/tester/message_tester.c index cc62e98c3..3d7f16e0e 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -1709,6 +1709,7 @@ static void real_time_text(bool_t audio_stream_enabled, bool_t srtp_enabled, boo } linphone_chat_room_send_chat_message(pauline_chat_room, rtt_message); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); + linphone_chat_message_unref(rtt_message); if (sql_storage) { bctbx_list_t *marie_messages = linphone_chat_room_get_history(marie_chat_room, 0);