reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Object.cxx
Go to the documentation of this file.
1
2#include "rutil/Logger.hxx"
3#include "rutil/Subsystem.hxx"
4#include "rutil/ResipAssert.h"
5
8#include "Object.hxx"
9
10#define RESIPROCATE_SUBSYSTEM kurento::KurentoSubsystem::KURENTOCLIENT
11
12using namespace kurento;
13
14using std::placeholders::_1;
15using std::placeholders::_2;
16
17const char *MediaProfileSpecType::JPEG_VIDEO_ONLY = "JPEG_VIDEO_ONLY";
18const char *MediaProfileSpecType::KURENTO_SPLIT_RECORDER = "KURENTO_SPLIT_RECORDER";
19const char *MediaProfileSpecType::MP4 = "MP4";
20const char *MediaProfileSpecType::MP4_AUDIO_ONLY = "MP4_AUDIO_ONLY";
21const char *MediaProfileSpecType::MP4_VIDEO_ONLY = "MP4_VIDEO_ONLY";
22const char *MediaProfileSpecType::WEBM = "WEBM";
23const char *MediaProfileSpecType::WEBM_AUDIO_ONLY = "WEBM_AUDIO_ONLY";
24const char *MediaProfileSpecType::WEBM_VIDEO_ONLY = "WEBM_VIDEO_ONLY";
25
26Object::Object(const std::string& name, std::shared_ptr<KurentoConnection> connection)
27 : mName(name),
28 mConnection(connection)
29{
30}
31
33{
34
35}
36
37std::string
38Object::makeRpcCallStatic(const std::string& methodName, const json::Object& params, ContinuationInternal c)
39{
40 std::string reqId = mConnection->sendRequest(
41 KurentoResponseHandler::shared_from_this(),
42 methodName, params);
43 mContinuations[reqId] = c;
44 return reqId;
45}
46
47std::string
48Object::makeRpcCall(const std::string& methodName, json::Object& params, ContinuationInternal c)
49{
50 resip_assert(!mId.empty()); // FIXME Kurento logging, throw
51 params[JSON_RPC_OBJECT] = json::String(mId);
52 return makeRpcCallStatic(methodName, params, c);
53}
54
55void
57{
58 json::Object params;
59 params[JSON_RPC_TYPE] = json::String(mName);
60 params["constructorParams"] = constructorParams;
61 params["properties"] = json::Object();
62 ContinuationInternal ci = std::bind(&Object::onConstructorSuccess, this, c, _1);
63 std::string reqId = makeRpcCallStatic("create", params, ci);
64}
65
66void
67Object::subscribe(const std::string& eventName, ContinuationVoid c)
68{
69 json::Object params;
70 params[JSON_RPC_TYPE] = json::String(eventName);
71 ContinuationInternal ci = std::bind(&Object::onSubscribeSuccess, this, c, _1);
72 std::string reqId = makeRpcCall("subscribe", params, ci);
73}
74
75void
77{
78 json::Object params;
79 ContinuationInternal ci = std::bind(&Object::onVoidSuccess, this, c, _1);
80 std::string reqId = makeRpcCall("release", params, ci);
81 mId.clear();
82}
83
84void
85Object::onEvent(const std::string& eventType, const json::Object& message)
86{
87 if(mEventListeners.find(eventType) == mEventListeners.end())
88 {
89 WarningLog(<<"notification for event that we didn't subscribe to " << eventType);
90 return;
91 }
92
94}
95
96void
97Object::sendNotifications(const std::string& eventType, const json::Object& message)
98{
99 std::shared_ptr<Event> event = Event::make_event(eventType, message);
100
101 if(!event) {
102 ErrLog(<<"failed to construct event for type: " << eventType);
103 return;
104 }
105
106 EventListenerList listeners = mEventListeners[eventType];
107 EventListenerList::const_iterator it;
108 for(it = listeners.begin(); it != listeners.end(); it++)
109 {
110 //std::shared_ptr<EventListener<T> > l = std::dynamic_pointer_cast<EventListener<T> >(*it);
111 std::shared_ptr<EventListener> l = *it;
112 l->onEvent(event);
113 }
114}
115
116void
117Object::addListener(const std::string& eventName, std::shared_ptr<EventListener> l, ContinuationVoid c)
118{
119 //resip_assert(std::is_base_of<Event,T>::value); // FIXME uncomment
120
121 //const std::string& eventName = T::EVENT_NAME;
122 //std::shared_ptr<EventListener<Event> > _l = std::static_pointer_cast<EventListener<Event> >(l);
123 mEventListeners[eventName].push_back(l);
124
125 subscribe(eventName, c);
126}
127
128void
129Object::invokeVoidMethod(const std::string& methodName, ContinuationVoid c, const json::Object& methodParams)
130{
131 json::Object params;
132 params["operation"] = json::String(methodName);
133 params["operationParams"] = methodParams;
134 params["properties"] = json::Object();
135
136 ContinuationInternal ci = std::bind(&Object::onVoidSuccess, this, c, _1);
137
138 std::string reqId = makeRpcCall("invoke", params, ci);
139}
140
141void
143{
144 json::Object params;
145 params["operation"] = json::String(methodName);
146 params["operationParams"] = methodParams;
147 params["properties"] = json::Object();
148
149 ContinuationInternal ci = std::bind(&Object::onStringSuccess, this, c, _1);
150
151 std::string reqId = makeRpcCall("invoke", params, ci);
152}
153
154void
155Object::processResponse(const std::string& id, std::shared_ptr<KurentoResponseHandler> krh, const json::Object& message)
156{
157 const ContinuationMap::const_iterator it = mContinuations.find(id);
158 if(it == mContinuations.end())
159 {
160 ErrLog(<<"received response for unknown request");
161 return; // FIXME
162 }
163 const ContinuationInternal& c = it->second;
164 c(message);
165 mContinuations.erase(id);
166}
167
168void
169Object::onConstructorSuccess(ContinuationVoid c, const json::Object& message)
170{
171 json::String idValue = message[JSON_RPC_RESULT][JSON_RPC_VALUE];
172 mId = idValue.Value();
173 DebugLog(<<"Object: " << mName << " got Kurento Object ID: " << mId);
174 mConnection->registerObject(shared_from_this());
175 c();
176}
177
178void
179Object::onSubscribeSuccess(ContinuationVoid c, const json::Object& message)
180{
181 // FIXME - do we need anything from the message?
182 c();
183}
184
185void
186Object::onVoidSuccess(ContinuationVoid c, const json::Object& message)
187{
188 if(message.Find(JSON_RPC_ERROR) != message.End())
189 {
190 json::String errorMessage = message[JSON_RPC_ERROR][JSON_RPC_ERROR_MESSAGE];
191 ErrLog(<<"Error from Kurento: " << errorMessage.Value());
192 throw KurentoException(errorMessage.Value().c_str()); // FIXME - pass up to the application
193 }
194 DebugLog(<<"successfully executed RPC method without a return value");
195 c();
196}
197
198void
199Object::onStringSuccess(ContinuationString c, const json::Object& message)
200{
201 if(message.Find(JSON_RPC_ERROR) != message.End())
202 {
203 json::String errorMessage = message[JSON_RPC_ERROR][JSON_RPC_ERROR_MESSAGE];
204 ErrLog(<<"Error from Kurento: " << errorMessage.Value());
205 resip_assert(0); // FIXME - pass up to the application
206 }
207 DebugLog(<<"successfully executed RPC method returning string");
208 json::String value = message[JSON_RPC_RESULT][JSON_RPC_VALUE];
209 std::string& _value = value.Value();
210 DebugLog(<<"return value: " << _value);
211 c(_value);
212}
213
214MediaPipeline::MediaPipeline(std::shared_ptr<KurentoConnection> connection)
215 : Object("MediaPipeline", connection)
216{
217 //create();
218}
219
223
224MediaElement::MediaElement(const std::string& name, std::shared_ptr<MediaPipeline> mediaPipeline)
225 : Object(name, mediaPipeline->getConnection()),
226 mMediaPipeline(mediaPipeline)
227{
228}
229
233
234void
236{
237 json::Object params;
238 params[JSON_RPC_MEDIAPIPELINE] = json::String(mMediaPipeline->getId());
239 createObject(c, params);
240}
241
242void
244{
245 json::Object params(extraParams);
246 params[JSON_RPC_MEDIAPIPELINE] = json::String(mMediaPipeline->getId());
247 createObject(c, params);
248}
249
250void
252{
253 const std::string& peerId = element.getId();
254
255 json::Object params;
256 params[JSON_RPC_SINK] = json::String(peerId);
257 invokeVoidMethod("connect", c, params);
258}
259
260void
262{
263 json::Object params;
264 params[JSON_RPC_SINK] = json::String(element.getId());
265 invokeVoidMethod("disconnect", c, params);
266}
267
268void
273
274void
279
280void
285
286void
291
292void
297
298void
303
304void
309
311 : MediaElement("PassThrough", mediaPipeline)
312{
313}
314
318
319GStreamerFilter::GStreamerFilter(std::shared_ptr<MediaPipeline> mediaPipeline, const std::string& command)
320 : MediaElement("GStreamerFilter", mediaPipeline),
321 mCommand(command)
322{
323}
324
328
330{
331 json::Object params;
332 params["command"] = json::String(mCommand);
333 MediaElement::create(c, params);
334}
335
336Endpoint::Endpoint(const std::string& name, std::shared_ptr<MediaPipeline> mediaPipeline)
338{
339}
340
344
345UriEndpoint::UriEndpoint(const std::string& name, std::shared_ptr<MediaPipeline> mediaPipeline, const std::string& uri)
346 : Endpoint(name, mediaPipeline),
347 mUri(uri)
348{
349}
350
354
355void
357{
358 json::Object params;
359 params["uri"] = json::String(mUri);
360 MediaElement::create(c, params);
361}
362
363void
365{
366 json::Object params(extraParams);
367 params["uri"] = json::String(mUri);
368 MediaElement::create(c, params);
369}
370
371void
376
377void
382
383PlayerEndpoint::PlayerEndpoint(std::shared_ptr<MediaPipeline> mediaPipeline, const std::string& uri)
384 : UriEndpoint("PlayerEndpoint", mediaPipeline, uri)
385{
386}
387
391
392void
397
398RecorderEndpoint::RecorderEndpoint(std::shared_ptr<MediaPipeline> mediaPipeline, const std::string& uri, const char *mediaProfile)
399 : UriEndpoint("RecorderEndpoint", mediaPipeline, uri),
400 mMediaProfile(mediaProfile)
401{
402}
403
407
408void
410{
411 json::Object params;
412 params["mediaProfile"] = json::String(mMediaProfile);
413 UriEndpoint::create(c, params);
414}
415
416void
421
422void
427
428BaseRtpEndpoint::BaseRtpEndpoint(const std::string& name, std::shared_ptr<MediaPipeline> mediaPipeline)
429 : Endpoint(name, mediaPipeline)
430{
431}
432
436
437void
439{
440 json::Object params;
441 params["externalIPv4"] = json::String(addr);
442 invokeVoidMethod("setExternalIPv4", c, params);
443}
444
445void
447{
448 json::Object params;
449 params["externalIPv6"] = json::String(addr);
450 invokeVoidMethod("setExternalIPv6", c, params);
451}
452
453void
458
459void
461{
462 json::Object params;
463 params["answer"] = json::String(sdp);
464 invokeStringMethod("processAnswer", c, params);
465}
466
467void
469{
470 json::Object params;
471 params["offer"] = json::String(sdp);
472 invokeStringMethod("processOffer", c, params);
473}
474
475void
480
481void
486
487void
492
493RtpEndpoint::RtpEndpoint(std::shared_ptr<MediaPipeline> mediaPipeline)
494 : BaseRtpEndpoint("RtpEndpoint", mediaPipeline)
495{
496}
497
501
503 : BaseRtpEndpoint("SipRtpEndpoint", mediaPipeline),
504 mCryptoAgnostic(cryptoAgnostic)
505{
506}
507
511
512void
514{
515 json::Object params;
516 params["cryptoAgnostic"] = json::Boolean(mCryptoAgnostic);
517 BaseRtpEndpoint::create(c, params);
518}
519
520WebRtcEndpoint::WebRtcEndpoint(std::shared_ptr<MediaPipeline> mediaPipeline)
521 : BaseRtpEndpoint("WebRtcEndpoint", mediaPipeline)
522{
523 //create();
524}
525
529
530void
535
536void
537WebRtcEndpoint::addIceCandidate(ContinuationVoid c, const std::string& candidate, const std::string& mid, unsigned int lineIndex)
538{
539 json::Object params;
540 params["candidate"] = json::Object();
541 params["candidate"]["candidate"] = json::String(candidate);
542 params["candidate"]["sdpMid"] = json::String(mid);
543 params["candidate"]["sdpMLineIndex"] = json::Number(lineIndex);
544 invokeVoidMethod("addIceCandidate", c, params);
545}
546
547void
552
553void
558
559/* ====================================================================
560
561 Copyright (c) 2021, Software Freedom Institute https://softwarefreedom.institute
562 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
563 All rights reserved.
564
565 Redistribution and use in source and binary forms, with or without
566 modification, are permitted provided that the following conditions are
567 met:
568
569 1. Redistributions of source code must retain the above copyright
570 notice, this list of conditions and the following disclaimer.
571
572 2. Redistributions in binary form must reproduce the above copyright
573 notice, this list of conditions and the following disclaimer in the
574 documentation and/or other materials provided with the distribution.
575
576 3. Neither the name of Plantronics nor the names of its contributors
577 may be used to endorse or promote products derived from this
578 software without specific prior written permission.
579
580 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
581 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
582 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
583 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
584 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
585 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
586 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
587 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
588 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
589 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
590 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
591
592 ==================================================================== */
#define JSON_RPC_ERROR_MESSAGE
#define JSON_RPC_SINK
#define JSON_RPC_ERROR
#define JSON_RPC_RESULT
#define JSON_RPC_MEDIAPIPELINE
#define JSON_RPC_VALUE
#define JSON_RPC_TYPE
#define JSON_RPC_OBJECT
#define DebugLog(args_)
Definition Logger.hxx:128
#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.
void setExternalIPv4(ContinuationVoid c, const std::string &addr)
Definition Object.cxx:438
void getLocalSessionDescriptor(ContinuationString s)
Definition Object.cxx:476
void sendPictureFastUpdate(ContinuationVoid c)
Definition Object.cxx:482
void generateOffer(ContinuationString s)
Definition Object.cxx:454
void processAnswer(ContinuationString s, const std::string &sdp)
Definition Object.cxx:460
void setExternalIPv6(ContinuationVoid c, const std::string &addr)
Definition Object.cxx:446
void addKeyframeRequiredListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:488
void processOffer(ContinuationString s, const std::string &sdp)
Definition Object.cxx:468
BaseRtpEndpoint(const std::string &name, std::shared_ptr< MediaPipeline > mediaPipeline)
Definition Object.cxx:428
virtual ~Endpoint()
Definition Object.cxx:341
Endpoint(const std::string &name, std::shared_ptr< MediaPipeline > mediaPipeline)
Definition Object.cxx:336
static std::shared_ptr< Event > make_event(const std::string &eventType, const json::Object &message)
Definition Event.cxx:29
GStreamerFilter(std::shared_ptr< MediaPipeline > mediaPipeline, const std::string &command)
Definition Object.cxx:319
virtual void create(ContinuationVoid c) override
Definition Object.cxx:329
void disconnect(ContinuationVoid c, MediaElement &element)
Definition Object.cxx:261
virtual ~MediaElement()
Definition Object.cxx:230
void addErrorListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:269
void addMediaFlowOutStateChangeListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:299
void addMediaStateChangedListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:281
void connect(ContinuationVoid c, MediaElement &element)
Definition Object.cxx:251
void addMediaFlowInStateChangeListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:293
virtual void create(ContinuationVoid c) override
Definition Object.cxx:235
MediaElement(const std::string &name, std::shared_ptr< MediaPipeline > mediaPipeline)
Definition Object.cxx:224
void addConnectionStateChangedListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:275
void addMediaTranscodingStateChangeListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:287
virtual ~MediaPipeline()
Definition Object.cxx:220
MediaPipeline(std::shared_ptr< KurentoConnection > connection)
Definition Object.cxx:214
std::function< void(const json::Object &message) > ContinuationInternal
Definition Object.hxx:49
void sendNotifications(const std::string &eventType, const json::Object &message)
Definition Object.cxx:97
void addListener(const std::string &eventName, std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:117
Object(const std::string &name, std::shared_ptr< KurentoConnection > connection)
Definition Object.cxx:26
void processResponse(const std::string &id, std::shared_ptr< KurentoResponseHandler > krh, const json::Object &message) override
Definition Object.cxx:155
virtual void release(ContinuationVoid c)
Definition Object.cxx:76
void invokeStringMethod(const std::string &methodName, ContinuationString c, const json::Object &methodParams=json::Object())
Definition Object.cxx:142
void invokeVoidMethod(const std::string &methodName, ContinuationVoid c, const json::Object &methodParams=json::Object())
Definition Object.cxx:129
virtual void onEvent(const std::string &eventType, const json::Object &message)
Definition Object.cxx:85
virtual ~Object()
Definition Object.cxx:32
virtual void create(ContinuationVoid c)
Definition Object.hxx:38
void createObject(ContinuationVoid c, const json::Object &constructorParams=json::Object())
Definition Object.cxx:56
static const std::string EVENT_NAME
Definition Event.hxx:66
static const std::string EVENT_NAME
Definition Event.hxx:129
static const std::string EVENT_NAME
Definition Event.hxx:120
static const std::string EVENT_NAME
Definition Event.hxx:39
static const std::string EVENT_NAME
Definition Event.hxx:57
static const std::string EVENT_NAME
Definition Event.hxx:111
static const std::string EVENT_NAME
Definition Event.hxx:93
static const std::string EVENT_NAME
Definition Event.hxx:102
static const std::string EVENT_NAME
Definition Event.hxx:75
static const std::string EVENT_NAME
Definition Event.hxx:84
PassThroughElement(std::shared_ptr< MediaPipeline > mediaPipeline)
Definition Object.cxx:310
void play(ContinuationVoid c)
Definition Object.cxx:393
PlayerEndpoint(std::shared_ptr< MediaPipeline > mediaPipeline, const std::string &uri)
Definition Object.cxx:383
virtual ~PlayerEndpoint()
Definition Object.cxx:388
void record(ContinuationVoid c)
Definition Object.cxx:417
RecorderEndpoint(std::shared_ptr< MediaPipeline > mediaPipeline, const std::string &uri, const char *mediaProfile)
Definition Object.cxx:398
void stopAndWait(ContinuationVoid c)
Definition Object.cxx:423
virtual void create(ContinuationVoid c) override
Definition Object.cxx:409
virtual ~RtpEndpoint()
Definition Object.cxx:498
RtpEndpoint(std::shared_ptr< MediaPipeline > mediaPipeline)
Definition Object.cxx:493
SipRtpEndpoint(std::shared_ptr< MediaPipeline > mediaPipeline, bool cryptoAgnostic=true)
Definition Object.cxx:502
virtual void create(ContinuationVoid c) override
Definition Object.cxx:513
virtual ~SipRtpEndpoint()
Definition Object.cxx:508
void stop(ContinuationVoid c)
Definition Object.cxx:378
void pause(ContinuationVoid c)
Definition Object.cxx:372
virtual void create(ContinuationVoid c) override
Definition Object.cxx:356
UriEndpoint(const std::string &name, std::shared_ptr< MediaPipeline > mediaPipeline, const std::string &uri)
Definition Object.cxx:345
virtual ~UriEndpoint()
Definition Object.cxx:351
void addOnIceCandidateFoundListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:548
WebRtcEndpoint(std::shared_ptr< MediaPipeline > mediaPipeline)
Definition Object.cxx:520
void addDataChannelOpenedListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:305
void addOnIceGatheringDoneListener(std::shared_ptr< EventListener > l, ContinuationVoid c)
Definition Object.cxx:554
void gatherCandidates(ContinuationVoid c)
Definition Object.cxx:531
void addIceCandidate(ContinuationVoid c, const std::string &candidate, const std::string &mid, unsigned int lineIndex)
Definition Object.cxx:537
virtual ~WebRtcEndpoint()
Definition Object.cxx:526
This class is used in the logging subsystem to identify logging messages generated from the Kurento c...
std::function< void(void) > ContinuationVoid
std::function< void(const std::string &s) > ContinuationString
void list()
Definition userAdmin.cxx:66