reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
GstMediaStackAdapter.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"
22#include "GstConversation.hxx"
23#include "Participant.hxx"
24#include "GstBridgeMixer.hxx"
25#include "DtmfEvent.hxx"
27#include "Conversation.hxx"
30
31#include "cajun/json/elements.h"
32
33#include <glibmm/main.h>
34#include <gstreamermm.h>
35
36#if defined(WIN32) && !defined(__GNUC__)
37#pragma warning( disable : 4355 )
38#endif
39
40using namespace recon;
41using namespace resip;
42using namespace std;
43
44using namespace Gst;
45using Glib::RefPtr;
46
47#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
48
50: MediaStackAdapter(conversationManager),
51 mGstTOSValue(0) // FIXME - make this value configurable
52{
53 init();
54}
55
56GstMediaStackAdapter::GstMediaStackAdapter(ConversationManager& conversationManager, int defaultSampleRate, int maxSampleRate)
57: MediaStackAdapter(conversationManager),
58 mGstTOSValue(0) // FIXME - make this value configurable
59{
60 init(defaultSampleRate, maxSampleRate);
61}
62
63void
64GstMediaStackAdapter::init(int defaultSampleRate, int maxSampleRate)
65{
66 DebugLog(<<"Gstreamer media stack initialization");
67
68 const char* _argv[] = { "reConServer", "--gst-debug", "5", NULL }; // FIXME
69 int _argc = 3;
70 char** __argv = (char**)_argv;
71 // FIXME: are there C++ equivalents of these functions?
72 gst_debug_remove_log_function (gst_debug_log_default);
73 gst_debug_add_log_function(gst2resip_log_function, nullptr, nullptr);
74 Gst::init(_argc, __argv);
75
76 main_loop = Glib::MainLoop::create();
77
78 //run();
79}
80
81void
83{
84 run(); // FIXME: run one Gst::main_loop thread per process or per Conversation?
85}
86
87void
88GstMediaStackAdapter::thread()
89{
90 DebugLog(<<"running the Gstreamer main loop");
91 main_loop->run();
92 DebugLog(<<"main_loop::run() completed");
93}
94
95void
97{
98 InfoLog(<<"GstMediaStackAdapter shutdown");
100 main_loop->quit();
101 // FIXME - join / wait for any threads to stop
102}
103
105{
106 // FIXME - move to ::shutdown() ?
107 getBridgeMixer().reset(); // Make sure the mixer is destroyed before the media interface
108 shutdown();
109 join();
110}
111
112void
116
117void
119{
120 // FIXME for Gst
121// if (mMediaInterface)
122// {
123// // Enable/Disable DTMF digit logging according to UserAgentMasterProfile setting
124// mMediaInterface->allowLoggingDTMFDigits(userAgent->getUserAgentMasterProfile()->dtmfDigitLoggingEnabled());
125// }
126
127}
128
131{
132 if (isShuttingDown()) return 0; // Don't allow new things to be created when we are shutting down
133
135
136 CreateConversationCmd* cmd = new CreateConversationCmd(&getConversationManager(), convHandle, autoHoldMode, sharedMediaInterfaceConvHandle);
137 post(cmd);
138 return convHandle;
139}
140
141void
142GstMediaStackAdapter::outputBridgeMatrixImpl(ConversationHandle convHandle)
143{
144 // Note: convHandle of 0 only makes sense if sipXGlobalMediaInterfaceMode is enabled
145 if (convHandle == 0)
146 {
147 if (getBridgeMixer() != 0)
148 {
149 getBridgeMixer()->outputBridgeMixWeights();
150 }
151 else
152 {
153 WarningLog(<< "ConversationManager::outputBridgeMatrix request with no conversation handle is not appropriate for current MediaInterfaceMode");
154 }
155 }
156 else
157 {
158 Conversation* conversation = getConversation(convHandle);
159 if (conversation)
160 {
161 if (conversation->getBridgeMixer() != 0)
162 {
163 conversation->getBridgeMixer()->outputBridgeMixWeights();
164 }
165 else
166 {
167 WarningLog(<< "ConversationManager::outputBridgeMatrix requested conversation wihtout a mixer/media interface, conversationHandle=" << convHandle);
168 }
169 }
170 else
171 {
172 WarningLog(<< "ConversationManager::outputBridgeMatrix requested for non-existing conversationHandle=" << convHandle);
173 }
174 }
175}
176
177void
179 const std::vector<unsigned int>& codecIds, resip::SdpContents& sessionCaps)
180{
181 // FIXME VP8
182 // FIXME OPUS
183 // FIXME Gst:
184 // - check who calls this (called from testUA, reConServer, ...
185 // - adapt for Gstreamer
186
187 // as a hack, we populate it with a static copy of the SDP from Gstreamer
188
189 // FIXME: ipaddress is assumed to be IP4
190 Data caps("v=0\r\n"
191 "o=- 3843572881 3843572881 IN IP4 " + ipaddress + "\r\n"
192 "s=Gstreamer Media Server\r\n"
193 "c=IN IP4 " + ipaddress + "\r\n"
194 "t=0 0\r\n"
195 "m=audio 34712 RTP/AVP 0\r\n"
196 "a=sendrecv\r\n"
197 "a=rtcp:34713\r\n"
198 "a=rtpmap:0 PCMU/8000\r\n"
199 "a=ssrc:866007149 cname:user2141419334@host-99aef493\r\n"
200 "m=video 2962 RTP/AVP 97 126\r\n"
201 "a=sendrecv\r\n"
202 "a=rtcp:2963\r\n"
203 "a=rtpmap:97 H264/90000\r\n"
204 "a=rtpmap:126 H264/90000\r\n"
205 "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"
206 "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"
207 "a=ssrc:1014502683 cname:user2141419334@host-99aef493\r\n");
208
209 HeaderFieldValue hfv(caps.data(), caps.size());
210 Mime type("application", "sdp");
211 SdpContents sdp(hfv, type);
212 sessionCaps = sdp;
213}
214
215bool
220
221bool
223{
224 return false;
225}
226
229 RelatedConversationSet* relatedConversationSet, // Pass NULL to create new RelatedConversationSet
230 ConversationHandle sharedMediaInterfaceConvHandle,
232{
233 return new GstConversation(handle, getConversationManager(), *this, relatedConversationSet, sharedMediaInterfaceConvHandle, autoHoldMode);
234}
235
241
243GstMediaStackAdapter::createMediaResourceParticipantInstance(ParticipantHandle partHandle, const resip::Uri& mediaUrl, const std::shared_ptr<resip::Data>& audioBuffer, void* recordingCircularBuffer)
244{
245 return 0; // FIXME Gst - implement MediaResourceParticipant in Gst
246}
247
248void
253
261
269
273 std::shared_ptr<ConversationProfile> conversationProfile)
274{
275 return new GstRemoteParticipantDialogSet(getConversationManager(), *this, forkSelectMode, conversationProfile);
276}
277
278void
279GstMediaStackAdapter::process()
280{
281 // Gstreamer has its own thread so we don't need to do anything here
282}
283
284void
285GstMediaStackAdapter::initializeDtlsFactory(const resip::Data& defaultAoR)
286{
287 // FIXME Gst
288}
289
290
291/* ====================================================================
292
293 Copyright (c) 2022, Software Freedom Institute https://softwarefreedom.institute
294 Copyright (c) 2022, Daniel Pocock https://danielpocock.com
295 Copyright (c) 2021-2022, SIP Spectrum, Inc. www.sipspectrum.com
296 Copyright (c) 2007-2008, Plantronics, Inc.
297 All rights reserved.
298
299 Redistribution and use in source and binary forms, with or without
300 modification, are permitted provided that the following conditions are
301 met:
302
303 1. Redistributions of source code must retain the above copyright
304 notice, this list of conditions and the following disclaimer.
305
306 2. Redistributions in binary form must reproduce the above copyright
307 notice, this list of conditions and the following disclaimer in the
308 documentation and/or other materials provided with the distribution.
309
310 3. Neither the name of Plantronics nor the names of its contributors
311 may be used to endorse or promote products derived from this
312 software without specific prior written permission.
313
314 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
315 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
317 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
318 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
319 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
320 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
321 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
322 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
323 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
324 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325
326 ==================================================================== */
#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 RemoteParticipant * createRemoteParticipantInstance(resip::DialogUsageManager &dum, RemoteParticipantDialogSet &rpds) override
virtual void conversationManagerReady(ConversationManager *conversationManager) override
virtual ConversationHandle createSharedMediaInterfaceConversation(ConversationHandle sharedMediaInterfaceConvHandle, ConversationManager::AutoHoldMode autoHoldMode=ConversationManager::AutoHoldEnabled)
Only applicable if GstConversationMediaInterfaceMode is used.
virtual RemoteParticipantDialogSet * createRemoteParticipantDialogSetInstance(ConversationManager::ParticipantForkSelectMode forkSelectMode=ConversationManager::ForkSelectAutomatic, std::shared_ptr< ConversationProfile > conversationProfile=nullptr) override
virtual bool supportsMultipleMediaInterfaces() override
virtual MediaResourceParticipant * createMediaResourceParticipantInstance(ParticipantHandle partHandle, const resip::Uri &mediaUrl, const std::shared_ptr< resip::Data > &audioBuffer, void *recordingCircularBuffer) override
virtual bool canConversationsShareParticipants(Conversation *conversation1, Conversation *conversation2) override
GstMediaStackAdapter(ConversationManager &conversationManager)
Note: Gsttapi Media Interfaces have a finite number of supported endpoints that are allowed in each b...
virtual void configureRemoteParticipantInstance(GstRemoteParticipant *krp)
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 Conversation * createConversationInstance(ConversationHandle handle, RelatedConversationSet *relatedConversationSet, ConversationHandle sharedMediaInterfaceConvHandle, ConversationManager::AutoHoldMode autoHoldMode) override
virtual void shutdown() override
virtual LocalParticipant * createLocalParticipantInstance(ParticipantHandle partHandle) 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)
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).
virtual void shutdown()
Definition ThreadIf.cxx:190
virtual void run()
Definition ThreadIf.cxx:75
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;