reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Participant.cxx
Go to the documentation of this file.
2#include "ReconSubsystem.hxx"
3#include "Participant.hxx"
4#include "Conversation.hxx"
5#include "UserAgent.hxx"
7
8#include <rutil/Log.hxx>
9#include <rutil/Logger.hxx>
10
11using namespace recon;
12using namespace resip;
13using namespace std;
14
15#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
16
19 ConversationManager& conversationManager)
20: mHandle(partHandle),
21 mType(participantType),
22 mRecordChannelNum(1),
23 mConversationManager(conversationManager)
24{
25 mConversationManager.registerParticipant(this);
26 //InfoLog(<< "Participant created, handle=" << mHandle);
27}
28
30 ConversationManager& conversationManager)
31: mHandle(0),
32 mType(participantType),
33 mRecordChannelNum(1),
34 mConversationManager(conversationManager)
35{
37 //InfoLog(<< "Participant created, handle=" << mHandle);
38}
39
41{
42 // Note: We cannot call Conversation::unregisterParticipant here, since dynamic_cast in the fn will not work -
43 // thus unregister must be implemented in sub-classes destructors (see ~LocalParticipant and ~RemoteParticipant)
44 //InfoLog(<< "Participant destroyed, handle=" << mHandle);
46 setHandle(0); // unregister from Conversation Manager
47}
48
49void
51{
52 if(mHandle == partHandle) return; // already set
53
54 // unregister old handle if set
55 if(mHandle)
56 {
57 mConversationManager.unregisterParticipant(this);
58 }
59 mHandle = partHandle;
60 if(mHandle)
61 {
62 mConversationManager.registerParticipant(this);
63 }
64}
65
66void
67Participant::addToConversation(Conversation* conversation, unsigned int inputGain, unsigned int outputGain)
68{
69 resip_assert(conversation);
70 if(mConversations.find(conversation->getHandle()) != mConversations.end()) return; // already present
71
72 InfoLog(<< "Participant handle=" << mHandle << " added to conversation=" << conversation->getHandle() << ", inputGain=" << inputGain << ", outputGain=" << outputGain);
73
74 mConversations[conversation->getHandle()] = conversation;
75 conversation->registerParticipant(this, inputGain, outputGain);
76}
77
78void
80{
81 resip_assert(conversation);
82 InfoLog(<< "Participant handle=" << mHandle << " removed from conversation=" << conversation->getHandle());
83 mConversations.erase(conversation->getHandle()); // Note: this must come before next line - since unregisterParticipant may end up destroying conversation
84 conversation->unregisterParticipant(this);
85}
86
87void
89{
90 // unregister from Conversations
91 ConversationMap::iterator it;
92 for (it = mConversations.begin(); it != mConversations.end(); it++)
93 {
94 it->second->unregisterParticipant(this);
95 }
96 mConversations.clear();
97}
98
99void
101{
102 ConversationMap::iterator it;
103 for(it = mConversations.begin(); it != mConversations.end(); it++)
104 {
105 destParticipant->addToConversation(it->second); // Will over-write our entry in the conversations participant map
106 }
107}
108
109void
111{
112 replacingParticipant->setHandle(mHandle); // Set handle on replacing participant
113 copyConversationsToParticipant(replacingParticipant); // Will over-write our entry in the conversations participant map
114 Conversation* firstAssociatedConversation=0;
115 if(mConversations.size() > 0)
116 {
117 // If we are running in sipXConversationMediaInterfaceMode, then the call to applyBridgeMixWeights below must be
118 // passed a conversation pointer, since this participant will not be able to find the appropriate
119 // BridgeMixer after it's conversation list is cleared.
120 firstAssociatedConversation = mConversations.begin()->second;
121 }
122 mConversations.clear(); // Clear so that we won't remove replaced reference from Conversation
123 mHandle = 0; // Set to 0 so that we won't remove replaced reference from ConversationManager
124 resip_assert((!mConversationManager.getMediaStackAdapter().supportsMultipleMediaInterfaces()) || // We are either running in sipXGlobalMediaInterfaceMode
125 firstAssociatedConversation != 0); // or we are running in sipXConversationMediaInterfaceMode and must have belonged to a conversation
126 applyBridgeMixWeights(firstAssociatedConversation); // Ensure we remove ourselves from the bridge mix matrix
127}
128
129void
131{
132 // Only need to do work on the bridge mixer if we are using it (ie: portOnBridge != -1)
133 if (getConnectionPortOnBridge() != -1)
134 {
135 BridgeMixer* mixer = 0;
137 {
139 mixer = mConversationManager.getBridgeMixer().get();
140 }
141 else
142 {
143 // Note: For this mode, the recon code ensures that all conversations a participant
144 // is added to will share the same media interface, so using the first
145 // conversation is sufficient.
146 resip_assert(mConversations.begin()->second->getBridgeMixer() != 0);
147 mixer = mConversations.begin()->second->getBridgeMixer();
148 }
149 resip_assert(mixer);
150 if (mixer)
151 {
153 }
154 }
155}
156
157// Special version of this call used only when a participant
158// is removed from a conversation. Required when sipXConversationMediaInterfaceMode
159// is used, in order to get a pointer to the bridge mixer
160// for a participant (ie. LocalParticipant) that has no currently
161// assigned conversations.
162void
164{
165 BridgeMixer* mixer=0;
167 {
169 mixer = mConversationManager.getBridgeMixer().get();
170 }
171 else
172 {
173 resip_assert(removedConversation->getBridgeMixer() != 0);
174 mixer = removedConversation->getBridgeMixer();
175 }
176 resip_assert(mixer);
177 if(mixer)
178 {
180 }
181}
182
183/* ====================================================================
184
185 Copyright (c) 2021-2023, SIP Spectrum, Inc. http://www.sipspectrum.com
186 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
187 Copyright (c) 2007-2008, Plantronics, Inc.
188 All rights reserved.
189
190 Redistribution and use in source and binary forms, with or without
191 modification, are permitted provided that the following conditions are
192 met:
193
194 1. Redistributions of source code must retain the above copyright
195 notice, this list of conditions and the following disclaimer.
196
197 2. Redistributions in binary form must reproduce the above copyright
198 notice, this list of conditions and the following disclaimer in the
199 documentation and/or other materials provided with the distribution.
200
201 3. Neither the name of Plantronics nor the names of its contributors
202 may be used to endorse or promote products derived from this
203 software without specific prior written permission.
204
205 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
206 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
207 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
208 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
210 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
211 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
212 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
213 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
214 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
215 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
216
217 ==================================================================== */
#define InfoLog(args_)
Definition Logger.hxx:131
#define resip_assert(x)
This file needs to work for both C and C++ code.
This class is used to control the sipX Bridge Mixer mix matrix.
virtual void calculateMixWeightsForParticipant(Participant *participant)=0
Calculates all of the current mixer settings required for the passed in participant and applies them.
This class is one of two main classes of concern to an application using the UserAgent library.
ParticipantHandle getNewParticipantHandle()
MediaStackAdapter & getMediaStackAdapter()
std::shared_ptr< BridgeMixer > & getBridgeMixer()
virtual void onParticipantDestroyed(ParticipantHandle partHandle)=0
Notifies an application when a Participant has been destroyed.
This class is used to manage membership of participants.
BridgeMixer * getBridgeMixer() noexcept
ConversationHandle getHandle()
void registerParticipant(Participant *, unsigned int inputGain=100, unsigned int outputGain=100)
void unregisterParticipant(Participant *)
virtual bool supportsMultipleMediaInterfaces()=0
This is the base class for a RemoteParticipant, LocalParticipant and a MediaResourceParticipant.
virtual void removeFromConversation(Conversation *conversation)
virtual void applyBridgeMixWeights()
ConversationMap mConversations
ConversationManager::ParticipantType mType
virtual void setHandle(ParticipantHandle partHandle)
Participant(ParticipantHandle partHandle, ConversationManager::ParticipantType participantType, ConversationManager &conversationManager)
virtual void addToConversation(Conversation *conversation, unsigned int inputGain=100, unsigned int outputGain=100)
virtual void unregisterFromAllConversations()
ParticipantHandle mHandle
virtual void replaceWithParticipant(Participant *replacingParticipant)
virtual void copyConversationsToParticipant(Participant *destParticipant)
virtual int getConnectionPortOnBridge()=0
ConversationManager & mConversationManager
unsigned int ParticipantHandle
dcm! – add UnusedChecking(_enum) below;