reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
LibWebRTCConversation.cxx
Go to the documentation of this file.
1
2#include <rutil/Log.hxx>
3
5#include "Participant.hxx"
9#include "UserAgent.hxx"
11#include "ReconSubsystem.hxx"
13
14
15#include <rutil/Logger.hxx>
17
18using namespace recon;
19using namespace resip;
20
21#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
22
23// The LibWebRTC integration is currently only designed to
24// bridge two participants. LibWebRTC itself can support
25// rooms with more than two participants.
26// FIXME: adapt to support rooms with more than two participants
27#define MAX_PARTICIPANTS 2
28
30 ConversationManager& conversationManager,
31 LibWebRTCMediaStackAdapter& libwebrtcMediaStackAdapter,
32 RelatedConversationSet* relatedConversationSet,
33 ConversationHandle sharedMediaInterfaceConvHandle,
35: Conversation(handle, conversationManager, relatedConversationSet, sharedMediaInterfaceConvHandle, autoHoldMode, MAX_PARTICIPANTS),
36 mLibWebRTCMediaStackAdapter(libwebrtcMediaStackAdapter),
37 mLibWebRTCReInviteOnParticipantsPresent(true)
38{
39 if(mLibWebRTCMediaStackAdapter.supportsMultipleMediaInterfaces())
40 {
41
42 // FIXME LibWebRTC
44 {
45 //LibWebRTCConversation* sharedFlowConversation = dynamic_cast<LibWebRTCConversation*>(mLibWebRTCMediaStackAdapter.getConversation(sharedMediaInterfaceConvHandle));
46 //mMediaInterface = sharedFlowConversation->getMediaInterface();
47 }
48 else
49 {
50 //std::shared_ptr<BridgeMixer> mixer;
51 //mLibWebRTCMediaStackAdapter.createMediaInterfaceAndMixer(false /* giveFocus?*/, // Focus will be given when local participant is added
52 // mMediaInterface,
53 // mixer);
54 //setBridgeMixer(mixer);
55 }
56 }
57 //InfoLog(<< "mBridgeMixer " << getBridgeMixerShared().use_count() << " " << getBridgeMixer());
58
59 std::shared_ptr<ConfigParse> cfg = getConfig();
60 if(cfg)
61 {
62 mLibWebRTCReInviteOnParticipantsPresent = cfg->getConfigBool("LibWebRTCReInviteOnParticipantsPresent",
63 mLibWebRTCReInviteOnParticipantsPresent);
64 }
65}
66
68{
69 getBridgeMixerShared().reset(); // Make sure the mixer is destroyed before the media interface
70 //mMediaInterface.reset();
71}
72
73void
77
78void
80{
81 DebugLog(<<"confirmParticipant handle: " << getHandle()
82 << " numRemote: " << getNumRemoteParticipants()
83 << " participant: " << participant->getParticipantHandle());
84 LibWebRTCRemoteParticipant *_p = dynamic_cast<LibWebRTCRemoteParticipant*>(participant);
85 std::shared_ptr<libwebrtc::BaseRtpEndpoint> answeredEndpoint = _p->getEndpoint();
87 {
88 DebugLog(<<"we are first in the conversation");
89 //_p->waitingMode(); // FIXME - loopback is setup in buildSdpOffer/buildSdpAnswer logic
90 return;
91 }
93 {
94 WarningLog(<<"participants already here, can't join, numRemoteParticipants = " << getNumRemoteParticipants());
95 return;
96 }
97 DebugLog(<<"joining a Conversation with an existing Participant");
98
99 if(!answeredEndpoint)
100 {
101 ErrLog(<<"our endpoint is not initialized"); // FIXME
102 return;
103 }
104 if(!_p->getWaitingModeElement()->valid())
105 {
106 DebugLog(<<"the local endpoint is not yet in a valid state");
107 return;
108 }
109 DebugLog(<<"attempting to join two RemoteParticipants");
110 _p->getWaitingModeElement()->disconnect([this, _p, answeredEndpoint]{
111 answeredEndpoint->disconnect([this, _p, answeredEndpoint]{
112 // Find the other Participant / endpoint
113
115 LibWebRTCRemoteParticipant* krp = 0; // FIXME - better to use shared_ptr
116 Conversation::ParticipantMap::iterator _it = m.begin();
117 for(;_it != m.end() && krp == 0; _it++)
118 {
119 krp = dynamic_cast<LibWebRTCRemoteParticipant*>(_it->second.getParticipant());
120 if(krp == _p)
121 {
122 krp = 0;
123 }
124 }
125 resip_assert(krp);
126 std::shared_ptr<libwebrtc::BaseRtpEndpoint> otherEndpoint = krp->getEndpoint();
127
128 krp->getWaitingModeElement()->disconnect([this, _p, answeredEndpoint, otherEndpoint, krp]{
129 otherEndpoint->disconnect([this, _p, answeredEndpoint, otherEndpoint, krp]{
130 otherEndpoint->connect([this, _p, answeredEndpoint, otherEndpoint, krp]{
131 answeredEndpoint->connect([this, _p, answeredEndpoint, otherEndpoint, krp]{
132 InfoLog(<<"peers connected");
133 if(mLibWebRTCReInviteOnParticipantsPresent)
134 {
135 krp->reInvite();
136 }
137
138 ParticipantHandle partHandle1 = _p->getParticipantHandle();
139 ParticipantHandle partHandle2 = krp->getParticipantHandle();
140 for(int i = 1000; i <= 5000; i+=1000)
141 {
142 std::chrono::milliseconds _i = std::chrono::milliseconds(i);
143 std::chrono::milliseconds __i = std::chrono::milliseconds(i + 500);
144 getConversationManager().requestKeyframe(partHandle1, _i);
145 getConversationManager().requestKeyframe(partHandle2, _i);
148 }
149
150 }, *otherEndpoint);
151 }, *answeredEndpoint);
152 }, *krp->getWaitingModeElement());
153 }, *otherEndpoint); // otherEndpoint->disconnect()
154 }, *_p->getWaitingModeElement());
155 }, *answeredEndpoint); // answeredEndpoint->disconnect()
156}
157
158void
160{
161 DebugLog(<<"onParticipantRemoved, checking for remaining participants");
162 LibWebRTCRemoteParticipant *_p = dynamic_cast<LibWebRTCRemoteParticipant*>(participant);
163 std::shared_ptr<libwebrtc::BaseRtpEndpoint> myEndpoint = _p->getEndpoint();
165 LibWebRTCRemoteParticipant* krp = 0; // FIXME - better to use shared_ptr
166 Conversation::ParticipantMap::iterator _it = m.begin();
167 for(;_it != m.end() && krp == 0; _it++)
168 {
169 krp = dynamic_cast<LibWebRTCRemoteParticipant*>(_it->second.getParticipant());
170 if(krp == _p)
171 {
172 krp = 0;
173 }
174 }
175 if(krp)
176 {
177 DebugLog(<<"remaining participant found");
178 std::shared_ptr<libwebrtc::BaseRtpEndpoint> otherEndpoint = krp->getEndpoint();
179 otherEndpoint->disconnect([this, krp, myEndpoint, otherEndpoint](){
180 myEndpoint->disconnect([this, krp](){
181 krp->waitingMode();
182 }, *otherEndpoint);
183 }, *myEndpoint);
184 }
185
186 return;
187}
188
189/* ====================================================================
190
191 Copyright (c) 2022, Software Freedom Institute https://softwarefreedom.institute
192 Copyright (c) 2022, Daniel Pocock https://danielpocock.com
193 Copyright (c) 2021, SIP Spectrum, Inc. www.sipspectrum.com
194 Copyright (c) 2007-2008, Plantronics, Inc.
195 All rights reserved.
196
197 Redistribution and use in source and binary forms, with or without
198 modification, are permitted provided that the following conditions are
199 met:
200
201 1. Redistributions of source code must retain the above copyright
202 notice, this list of conditions and the following disclaimer.
203
204 2. Redistributions in binary form must reproduce the above copyright
205 notice, this list of conditions and the following disclaimer in the
206 documentation and/or other materials provided with the distribution.
207
208 3. Neither the name of Plantronics nor the names of its contributors
209 may be used to endorse or promote products derived from this
210 software without specific prior written permission.
211
212 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
213 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
214 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
218 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
219 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
220 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
221 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
222 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223
224 ==================================================================== */
#define MAX_PARTICIPANTS
#define DebugLog(args_)
Definition Logger.hxx:128
#define InfoLog(args_)
Definition Logger.hxx:131
#define WarningLog(args_)
Definition Logger.hxx:134
#define ErrLog(args_)
Definition Logger.hxx:137
#define resip_assert(x)
This file needs to work for both C and C++ code.
This class is one of two main classes of concern to an application using the UserAgent library.
virtual void requestKeyframeFromPeer(ParticipantHandle partHandle, std::chrono::duration< double > durationMs)
virtual void requestKeyframe(ParticipantHandle partHandle, std::chrono::duration< double > durationMs)
This class is used to manage membership of participants.
ParticipantMap & getParticipants()
unsigned int getNumRemoteParticipants()
std::shared_ptr< resip::ConfigParse > getConfig()
virtual ConversationManager & getConversationManager()
std::shared_ptr< BridgeMixer > getBridgeMixerShared()
ConversationHandle getHandle()
virtual bool isSharingMediaInterfaceWithAnotherConversation()
std::map< ParticipantHandle, ConversationParticipantAssignment > ParticipantMap
virtual void onParticipantRemoved(Participant *participant)
virtual void confirmParticipant(Participant *participant)
LibWebRTCConversation(ConversationHandle handle, ConversationManager &conversationManager, LibWebRTCMediaStackAdapter &libwebrtcMediaStackAdapter, RelatedConversationSet *relatedConversationSet, ConversationHandle sharedMediaInterfaceConvHandle, ConversationManager::AutoHoldMode autoHoldMode)
virtual void onParticipantAdded(Participant *participant)
This class is one of two main classes of concern to an application using the UserAgent library.
This class represent a remote participant.
virtual std::shared_ptr< libwebrtc::MediaElement > getWaitingModeElement()
virtual std::shared_ptr< libwebrtc::BaseRtpEndpoint > getEndpoint()
This is the base class for a RemoteParticipant, LocalParticipant and a MediaResourceParticipant.
virtual ParticipantHandle getParticipantHandle()
This is used to keep a mapping between all related conversations.
unsigned int ConversationHandle
unsigned int ParticipantHandle
dcm! – add UnusedChecking(_enum) below;