reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
LibWebRTCMediaStackAdapter.cxx
Go to the documentation of this file.
1
2#if (_MSC_VER >= 1600)
3#include <stdint.h> // Use Visual Studio's stdint.h
4#define _MSC_STDINT_H_ // This define will ensure that stdint.h in sipXport tree is not used
5#endif
6
7// resip includes
8#include <rutil/Log.hxx>
9#include <rutil/Logger.hxx>
10#include <rutil/Lock.hxx>
11#include <rutil/Random.hxx>
17
18#include "ReconSubsystem.hxx"
19#include "UserAgent.hxx"
23#include "Participant.hxx"
25#include "DtmfEvent.hxx"
27#include "Conversation.hxx"
29
30#include "cajun/json/elements.h"
31
32#if defined(WIN32) && !defined(__GNUC__)
33#pragma warning( disable : 4355 )
34#endif
35
36using namespace recon;
37using namespace resip;
38using namespace std;
39
40#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
41
43: MediaStackAdapter(conversationManager),
44 mLibWebRTCTOSValue(0) // FIXME - make this value configurable
45{
46 init();
47}
48
49LibWebRTCMediaStackAdapter::LibWebRTCMediaStackAdapter(ConversationManager& conversationManager, int defaultSampleRate, int maxSampleRate)
50: MediaStackAdapter(conversationManager),
51 mLibWebRTCTOSValue(0) // FIXME - make this value configurable
52{
53 init(defaultSampleRate, maxSampleRate);
54}
55
56void
57LibWebRTCMediaStackAdapter::init(int defaultSampleRate, int maxSampleRate)
58{
59 // Connect to the LibWebRTC server
60 DebugLog(<<"trying to connect to LibWebRTC host " << mLibWebRTCUri);
61 mLibWebRTCConnection = mLibWebRTCManager.getLibWebRTCConnection(mLibWebRTCUri.c_str(), *this); // FIXME wait for connection
62
63}
64
65void
67{
68 // FIXME
69 // - if LibWebRTC connection was dropped but the same LibWebRTC instance is still
70 // running then mPipeline remains valid and we don't need to replace it
71 // - if it was a LibWebRTC restart then mPipeline does need to be replaced and all
72 // calls need to be dropped at the SIP level so the clients reconnect
73
74 mPipeline = make_shared<libwebrtc::MediaPipeline>(mLibWebRTCConnection);
75 mPipeline->create([this]{
76 DebugLog(<<"pipeline created with ID " << mPipeline->getId());
77 }); // FIXME - wait for creation
78}
79
80void
82{
83 InfoLog(<<"LibWebRTCMediaStackAdapter shutdown");
84 if(mPipeline)
85 {
86 mPipeline->release([this](){
87 InfoLog(<<"mPipeline has been released");
88 mLibWebRTCConnection.reset();
89 });
90 }
91 else
92 {
93 mLibWebRTCConnection.reset();
94 }
95 // FIXME - join / wait for any threads to stop
96}
97
99{
100 // FIXME - move to ::shutdown() ?
101 getBridgeMixer().reset(); // Make sure the mixer is destroyed before the media interface
102}
103
104void
108
109void
111{
112 // FIXME for LibWebRTC
113// if (mMediaInterface)
114// {
115// // Enable/Disable DTMF digit logging according to UserAgentMasterProfile setting
116// mMediaInterface->allowLoggingDTMFDigits(userAgent->getUserAgentMasterProfile()->dtmfDigitLoggingEnabled());
117// }
118
119}
120
123{
124 if (isShuttingDown()) return 0; // Don't allow new things to be created when we are shutting down
125
127
128 CreateConversationCmd* cmd = new CreateConversationCmd(&getConversationManager(), convHandle, autoHoldMode, sharedMediaInterfaceConvHandle);
129 post(cmd);
130 return convHandle;
131}
132
133void
134LibWebRTCMediaStackAdapter::outputBridgeMatrixImpl(ConversationHandle convHandle)
135{
136 // Note: convHandle of 0 only makes sense if sipXGlobalMediaInterfaceMode is enabled
137 if (convHandle == 0)
138 {
139 if (getBridgeMixer() != 0)
140 {
141 getBridgeMixer()->outputBridgeMixWeights();
142 }
143 else
144 {
145 WarningLog(<< "ConversationManager::outputBridgeMatrix request with no conversation handle is not appropriate for current MediaInterfaceMode");
146 }
147 }
148 else
149 {
150 Conversation* conversation = getConversation(convHandle);
151 if (conversation)
152 {
153 if (conversation->getBridgeMixer() != 0)
154 {
155 conversation->getBridgeMixer()->outputBridgeMixWeights();
156 }
157 else
158 {
159 WarningLog(<< "ConversationManager::outputBridgeMatrix requested conversation wihtout a mixer/media interface, conversationHandle=" << convHandle);
160 }
161 }
162 else
163 {
164 WarningLog(<< "ConversationManager::outputBridgeMatrix requested for non-existing conversationHandle=" << convHandle);
165 }
166 }
167}
168
169void
171 const std::vector<unsigned int>& codecIds, resip::SdpContents& sessionCaps)
172{
173 // FIXME LibWebRTC:
174 // - check who calls this (called from testUA, reConServer, ...
175 // - adapt for LibWebRTC
176
177 // as a hack, we populate it with a static copy of the SDP from LibWebRTC
178
179 // FIXME: ipaddress is assumed to be IP4
180 Data caps("v=0\r\n"
181 "o=- 3843572881 3843572881 IN IP4 " + ipaddress + "\r\n"
182 "s=LibWebRTC Media Server\r\n"
183 "c=IN IP4 " + ipaddress + "\r\n"
184 "t=0 0\r\n"
185 "m=audio 34712 RTP/AVP 0\r\n"
186 "a=sendrecv\r\n"
187 "a=rtcp:34713\r\n"
188 "a=rtpmap:0 PCMU/8000\r\n"
189 "a=ssrc:866007149 cname:user2141419334@host-99aef493\r\n"
190 "m=video 2962 RTP/AVP 97 126\r\n"
191 "a=sendrecv\r\n"
192 "a=rtcp:2963\r\n"
193 "a=rtpmap:97 H264/90000\r\n"
194 "a=rtpmap:126 H264/90000\r\n"
195 "a=fmtp:97 packetization-mode=0;profile-level-id=420016;max-br=5000;max-mbps=245000;max-fs=9000;max-smbps=245000;max-fps=6000;max-rcmd-nalu-size=3456000;sar-supported=16\r\n"
196 "a=fmtp:126 packetization-mode=1;profile-level-id=428016;max-br=5000;max-mbps=245000;max-fs=9000;max-smbps=245000;max-fps=6000;max-rcmd-nalu-size=3456000;sar-supported=16\r\n"
197 "a=ssrc:1014502683 cname:user2141419334@host-99aef493\r\n");
198
199 HeaderFieldValue hfv(caps.data(), caps.size());
200 Mime type("application", "sdp");
201 SdpContents sdp(hfv, type);
202 sessionCaps = sdp;
203}
204
205bool
210
211bool
213{
214 return false;
215}
216
219 RelatedConversationSet* relatedConversationSet, // Pass NULL to create new RelatedConversationSet
220 ConversationHandle sharedMediaInterfaceConvHandle,
222{
223 return new LibWebRTCConversation(handle, getConversationManager(), *this, relatedConversationSet, sharedMediaInterfaceConvHandle, autoHoldMode);
224}
225
231
233LibWebRTCMediaStackAdapter::createMediaResourceParticipantInstance(ParticipantHandle partHandle, const resip::Uri& mediaUrl, const std::shared_ptr<resip::Data>& audioBuffer, void* recordingCircularBuffer)
234{
235 return 0; // FIXME LibWebRTC - implement MediaResourceParticipant in LibWebRTC
236}
237
238void
240{
241 std::shared_ptr<ConfigParse> cfg = getConfig();
242 if(cfg)
243 {
244 krp->mRemoveExtraMediaDescriptors = cfg->getConfigBool("LibWebRTCRemoveExtraMediaDescriptors", false);
245 krp->mSipRtpEndpoint = cfg->getConfigBool("LibWebRTCSipRtpEndpoint", true);
246 krp->mReuseSdpAnswer = cfg->getConfigBool("LibWebRTCReuseSdpAnswer", false);
247 krp->mWSAcceptsKeyframeRequests = cfg->getConfigBool("LibWebRTCWebSocketAcceptsKeyframeRequests", true);
248 }
249}
250
258
266
270 std::shared_ptr<ConversationProfile> conversationProfile)
271{
272 return new LibWebRTCRemoteParticipantDialogSet(getConversationManager(), *this, forkSelectMode, conversationProfile);
273}
274
275void
276LibWebRTCMediaStackAdapter::process()
277{
278 mLibWebRTCManager.process();
279}
280
281void
282LibWebRTCMediaStackAdapter::initializeDtlsFactory(const resip::Data& defaultAoR)
283{
284 // FIXME LibWebRTC
285}
286
287
288/* ====================================================================
289
290 Copyright (c) 2022, Software Freedom Institute https://softwarefreedom.institute
291 Copyright (c) 2022, Daniel Pocock https://danielpocock.com
292 Copyright (c) 2021-2022, SIP Spectrum, Inc. www.sipspectrum.com
293 Copyright (c) 2007-2008, Plantronics, Inc.
294 All rights reserved.
295
296 Redistribution and use in source and binary forms, with or without
297 modification, are permitted provided that the following conditions are
298 met:
299
300 1. Redistributions of source code must retain the above copyright
301 notice, this list of conditions and the following disclaimer.
302
303 2. Redistributions in binary form must reproduce the above copyright
304 notice, this list of conditions and the following disclaimer in the
305 documentation and/or other materials provided with the distribution.
306
307 3. Neither the name of Plantronics nor the names of its contributors
308 may be used to endorse or promote products derived from this
309 software without specific prior written permission.
310
311 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
312 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
313 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
314 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
315 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
316 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
317 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
318 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
319 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
320 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
321 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322
323 ==================================================================== */
#define DebugLog(args_)
Definition Logger.hxx:128
#define InfoLog(args_)
Definition Logger.hxx:131
#define WarningLog(args_)
Definition Logger.hxx:134
virtual void outputBridgeMixWeights()=0
Logs a multiline representation of the current state of the mixing matrix.
This class is one of two main classes of concern to an application using the UserAgent library.
This class is used to manage membership of participants.
BridgeMixer * getBridgeMixer() noexcept
The classes defined here are used to pass commands from the application thread to the UserAgent threa...
virtual bool canConversationsShareParticipants(Conversation *conversation1, Conversation *conversation2) override
virtual MediaResourceParticipant * createMediaResourceParticipantInstance(ParticipantHandle partHandle, const resip::Uri &mediaUrl, const std::shared_ptr< resip::Data > &audioBuffer, void *recordingCircularBuffer) override
LibWebRTCMediaStackAdapter(ConversationManager &conversationManager)
Note: LibWebRTCtapi Media Interfaces have a finite number of supported endpoints that are allowed in ...
virtual Conversation * createConversationInstance(ConversationHandle handle, RelatedConversationSet *relatedConversationSet, ConversationHandle sharedMediaInterfaceConvHandle, ConversationManager::AutoHoldMode autoHoldMode) override
virtual RemoteParticipant * createRemoteParticipantInstance(resip::DialogUsageManager &dum, RemoteParticipantDialogSet &rpds) override
virtual ConversationHandle createSharedMediaInterfaceConversation(ConversationHandle sharedMediaInterfaceConvHandle, ConversationManager::AutoHoldMode autoHoldMode=ConversationManager::AutoHoldEnabled)
Only applicable if LibWebRTCConversationMediaInterfaceMode is used.
virtual void configureRemoteParticipantInstance(LibWebRTCRemoteParticipant *krp)
virtual RemoteParticipantDialogSet * createRemoteParticipantDialogSetInstance(ConversationManager::ParticipantForkSelectMode forkSelectMode=ConversationManager::ForkSelectAutomatic, std::shared_ptr< ConversationProfile > conversationProfile=nullptr) override
virtual void setUserAgent(UserAgent *userAgent) override
virtual void buildSessionCapabilities(const resip::Data &ipaddress, const std::vector< unsigned int > &codecIds, resip::SdpContents &sessionCaps) override
Builds a session capabilties SDPContents based on the passed in ipaddress and codec ordering.
virtual LocalParticipant * createLocalParticipantInstance(ParticipantHandle partHandle) override
virtual void conversationManagerReady(ConversationManager *conversationManager) override
This class represent a remote participant.
This class represents a local participant.
This class represents a media resource participant.
This class is one of two main classes of concern to an application.
ConversationManager & getConversationManager()
Conversation * getConversation(ConversationHandle convHandle)
std::shared_ptr< resip::ConfigParse > getConfig()
ConversationHandle getNewConversationHandle()
std::shared_ptr< BridgeMixer > & getBridgeMixer()
void post(resip::Message *message)
This is used to keep a mapping between all related conversations.
This class is used by Invite DialogSets.
This class represent a remote participant.
This class is one of two main classes of concern to an application using the UserAgent library.
Definition UserAgent.hxx:56
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
size_type size() const noexcept
Returns the number of bytes in this Data.
Definition Data.hxx:599
const char * data() const noexcept
Returns a pointer to the contents of this Data.
Definition Data.hxx:608
Represents the "media-type" element in the RFC 3261 grammar.
Definition Mime.hxx:20
Provides an interface to process and generate SDP bodies (MIME content-type application/sdp).
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
unsigned int ConversationHandle
unsigned int ParticipantHandle
dcm! – add UnusedChecking(_enum) below;