-
Notifications
You must be signed in to change notification settings - Fork 323
/
kvsWebrtcClientMasterGstSample.c
507 lines (444 loc) · 24.6 KB
/
kvsWebrtcClientMasterGstSample.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#include "Samples.h"
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
extern PSampleConfiguration gSampleConfiguration;
// #define VERBOSE
GstElement* senderPipeline = NULL;
GstFlowReturn on_new_sample(GstElement* sink, gpointer data, UINT64 trackid)
{
GstBuffer* buffer;
STATUS retStatus = STATUS_SUCCESS;
BOOL isDroppable, delta;
GstFlowReturn ret = GST_FLOW_OK;
GstSample* sample = NULL;
GstMapInfo info;
GstSegment* segment;
GstClockTime buf_pts;
Frame frame;
STATUS status;
PSampleConfiguration pSampleConfiguration = (PSampleConfiguration) data;
PSampleStreamingSession pSampleStreamingSession = NULL;
PRtcRtpTransceiver pRtcRtpTransceiver = NULL;
UINT32 i;
guint bitrate;
CHK_ERR(pSampleConfiguration != NULL, STATUS_NULL_ARG, "NULL sample configuration");
info.data = NULL;
sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
buffer = gst_sample_get_buffer(sample);
isDroppable = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_CORRUPTED) || GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DECODE_ONLY) ||
(GST_BUFFER_FLAGS(buffer) == GST_BUFFER_FLAG_DISCONT) ||
(GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DISCONT) && GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) ||
// drop if buffer contains header only and has invalid timestamp
!GST_BUFFER_PTS_IS_VALID(buffer);
if (!isDroppable) {
delta = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
frame.flags = delta ? FRAME_FLAG_NONE : FRAME_FLAG_KEY_FRAME;
// convert from segment timestamp to running time in live mode.
segment = gst_sample_get_segment(sample);
buf_pts = gst_segment_to_running_time(segment, GST_FORMAT_TIME, buffer->pts);
if (!GST_CLOCK_TIME_IS_VALID(buf_pts)) {
DLOGE("[KVS GStreamer Master] Frame contains invalid PTS dropping the frame");
}
if (!(gst_buffer_map(buffer, &info, GST_MAP_READ))) {
DLOGE("[KVS GStreamer Master] on_new_sample(): Gst buffer mapping failed");
goto CleanUp;
}
frame.trackId = trackid;
frame.duration = 0;
frame.version = FRAME_CURRENT_VERSION;
frame.size = (UINT32) info.size;
frame.frameData = (PBYTE) info.data;
MUTEX_LOCK(pSampleConfiguration->streamingSessionListReadLock);
for (i = 0; i < pSampleConfiguration->streamingSessionCount; ++i) {
pSampleStreamingSession = pSampleConfiguration->sampleStreamingSessionList[i];
frame.index = (UINT32) ATOMIC_INCREMENT(&pSampleStreamingSession->frameIndex);
if (trackid == DEFAULT_AUDIO_TRACK_ID) {
if (pSampleStreamingSession->pSampleConfiguration->enableTwcc && senderPipeline != NULL) {
GstElement* encoder = gst_bin_get_by_name(GST_BIN(senderPipeline), "sampleAudioEncoder");
if (encoder != NULL) {
g_object_get(G_OBJECT(encoder), "bitrate", &bitrate, NULL);
MUTEX_LOCK(pSampleStreamingSession->twccMetadata.updateLock);
pSampleStreamingSession->twccMetadata.currentAudioBitrate = (UINT64) bitrate;
if (pSampleStreamingSession->twccMetadata.newAudioBitrate != 0) {
bitrate = (guint) (pSampleStreamingSession->twccMetadata.newAudioBitrate);
pSampleStreamingSession->twccMetadata.newAudioBitrate = 0;
g_object_set(G_OBJECT(encoder), "bitrate", bitrate, NULL);
}
MUTEX_UNLOCK(pSampleStreamingSession->twccMetadata.updateLock);
}
}
pRtcRtpTransceiver = pSampleStreamingSession->pAudioRtcRtpTransceiver;
frame.presentationTs = pSampleStreamingSession->audioTimestamp;
frame.decodingTs = frame.presentationTs;
pSampleStreamingSession->audioTimestamp +=
SAMPLE_AUDIO_FRAME_DURATION; // assume audio frame size is 20ms, which is default in opusenc
} else {
if (pSampleStreamingSession->pSampleConfiguration->enableTwcc && senderPipeline != NULL) {
GstElement* encoder = gst_bin_get_by_name(GST_BIN(senderPipeline), "sampleVideoEncoder");
if (encoder != NULL) {
g_object_get(G_OBJECT(encoder), "bitrate", &bitrate, NULL);
MUTEX_LOCK(pSampleStreamingSession->twccMetadata.updateLock);
pSampleStreamingSession->twccMetadata.currentVideoBitrate = (UINT64) bitrate;
if (pSampleStreamingSession->twccMetadata.newVideoBitrate != 0) {
bitrate = (guint) (pSampleStreamingSession->twccMetadata.newVideoBitrate);
pSampleStreamingSession->twccMetadata.newVideoBitrate = 0;
g_object_set(G_OBJECT(encoder), "bitrate", bitrate, NULL);
}
MUTEX_UNLOCK(pSampleStreamingSession->twccMetadata.updateLock);
}
}
pRtcRtpTransceiver = pSampleStreamingSession->pVideoRtcRtpTransceiver;
frame.presentationTs = pSampleStreamingSession->videoTimestamp;
frame.decodingTs = frame.presentationTs;
pSampleStreamingSession->videoTimestamp += SAMPLE_VIDEO_FRAME_DURATION; // assume video fps is 25
}
status = writeFrame(pRtcRtpTransceiver, &frame);
if (status != STATUS_SRTP_NOT_READY_YET && status != STATUS_SUCCESS) {
#ifdef VERBOSE
DLOGE("[KVS GStreamer Master] writeFrame() failed with 0x%08x", status);
#endif
} else if (status == STATUS_SUCCESS && pSampleStreamingSession->firstFrame) {
PROFILE_WITH_START_TIME(pSampleStreamingSession->offerReceiveTime, "Time to first frame");
pSampleStreamingSession->firstFrame = FALSE;
} else if (status == STATUS_SRTP_NOT_READY_YET) {
DLOGI("[KVS GStreamer Master] SRTP not ready yet, dropping frame");
}
}
MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock);
}
CleanUp:
if (info.data != NULL) {
gst_buffer_unmap(buffer, &info);
}
if (sample != NULL) {
gst_sample_unref(sample);
}
if (ATOMIC_LOAD_BOOL(&pSampleConfiguration->appTerminateFlag)) {
ret = GST_FLOW_EOS;
}
return ret;
}
GstFlowReturn on_new_sample_video(GstElement* sink, gpointer data)
{
return on_new_sample(sink, data, DEFAULT_VIDEO_TRACK_ID);
}
GstFlowReturn on_new_sample_audio(GstElement* sink, gpointer data)
{
return on_new_sample(sink, data, DEFAULT_AUDIO_TRACK_ID);
}
PVOID sendGstreamerAudioVideo(PVOID args)
{
STATUS retStatus = STATUS_SUCCESS;
GstElement *appsinkVideo = NULL, *appsinkAudio = NULL;
GstBus* bus;
GstMessage* msg;
GError* error = NULL;
PSampleConfiguration pSampleConfiguration = (PSampleConfiguration) args;
CHK_ERR(pSampleConfiguration != NULL, STATUS_NULL_ARG, "[KVS Gstreamer Master] Streaming session is NULL");
/**
* Use x264enc as its available on mac, pi, ubuntu and windows
* mac pipeline fails if resolution is not 720p
*
* For alaw
* audiotestsrc is-live=TRUE ! queue leaky=2 max-size-buffers=400 ! audioconvert ! audioresample !
* audio/x-raw, rate=8000, channels=1, format=S16LE, layout=interleaved ! alawenc ! appsink sync=TRUE emit-signals=TRUE name=appsink-audio
*
* For VP8
* videotestsrc is-live=TRUE ! video/x-raw,width=1280,height=720,framerate=30/1 !
* vp8enc error-resilient=partitions keyframe-max-dist=10 auto-alt-ref=true cpu-used=5 deadline=1 !
* appsink sync=TRUE emit-signals=TRUE name=appsink-video
*
*
* Raspberry Pi Hardware Encode Example
* "v4l2src device=\"/dev/video0\" ! queue ! v4l2convert ! "
* "video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! "
* "v4l2h264enc ! "
* "h264parse ! "
* "video/x-h264,stream-format=byte-stream,alignment=au,width=640,height=480,framerate=30/1,profile=baseline,level=(string)4 ! "
* "appsink sync=TRUE emit-signals=TRUE name=appsink-video"
*/
CHAR rtspPipeLineBuffer[RTSP_PIPELINE_MAX_CHAR_COUNT];
switch (pSampleConfiguration->mediaType) {
case SAMPLE_STREAMING_VIDEO_ONLY:
switch (pSampleConfiguration->srcType) {
case TEST_SOURCE: {
if (pSampleConfiguration->videoCodec == RTC_CODEC_H265) {
senderPipeline = gst_parse_launch("videotestsrc pattern=ball is-live=TRUE ! timeoverlay ! queue ! videoconvert ! "
"video/x-raw,width=1280,height=720,framerate=25/1 ! queue ! "
"x265enc speed-preset=veryfast bitrate=512 tune=zerolatency ! "
"video/x-h265,stream-format=byte-stream,alignment=au,profile=main ! appsink sync=TRUE "
"emit-signals=TRUE name=appsink-video",
&error);
} else {
senderPipeline = gst_parse_launch(
"videotestsrc pattern=ball is-live=TRUE ! "
"queue ! videoconvert ! videoscale ! video/x-raw,width=1280,height=720 ! "
"clockoverlay halignment=right valignment=top time-format=\"%Y-%m-%d %H:%M:%S\" ! "
"videorate ! video/x-raw,framerate=25/1 ! "
"x264enc name=sampleVideoEncoder bframes=0 speed-preset=veryfast bitrate=512 byte-stream=TRUE tune=zerolatency ! "
"video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! "
"appsink sync=TRUE emit-signals=TRUE name=appsink-video",
&error);
}
break;
}
case DEVICE_SOURCE: {
senderPipeline = gst_parse_launch(
"autovideosrc ! queue ! videoconvert ! video/x-raw,width=1280,height=720,framerate=25/1 ! "
"x264enc name=sampleVideoEncoder bframes=0 speed-preset=veryfast bitrate=512 byte-stream=TRUE tune=zerolatency ! "
"video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! "
" appsink sync=TRUE "
"emit-signals=TRUE name=appsink-video",
&error);
break;
}
case RTSP_SOURCE: {
UINT16 stringOutcome =
SNPRINTF(rtspPipeLineBuffer, RTSP_PIPELINE_MAX_CHAR_COUNT,
"uridecodebin uri=%s ! "
"videoconvert ! "
"x264enc name=sampleVideoEncoder bframes=0 speed-preset=veryfast bitrate=512 byte-stream=TRUE tune=zerolatency ! "
"video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! queue ! "
"appsink sync=TRUE emit-signals=TRUE name=appsink-video ",
pSampleConfiguration->rtspUri);
if (stringOutcome > RTSP_PIPELINE_MAX_CHAR_COUNT) {
DLOGE("[KVS GStreamer Master] ERROR: rtsp uri entered exceeds maximum allowed length set by RTSP_PIPELINE_MAX_CHAR_COUNT");
goto CleanUp;
}
senderPipeline = gst_parse_launch(rtspPipeLineBuffer, &error);
break;
}
}
break;
case SAMPLE_STREAMING_AUDIO_VIDEO:
switch (pSampleConfiguration->srcType) {
case TEST_SOURCE: {
if (pSampleConfiguration->videoCodec == RTC_CODEC_H264_PROFILE_42E01F_LEVEL_ASYMMETRY_ALLOWED_PACKETIZATION_MODE &&
pSampleConfiguration->audioCodec == RTC_CODEC_OPUS) {
senderPipeline = gst_parse_launch(
"videotestsrc pattern=ball is-live=TRUE ! "
"queue ! videorate ! videoscale ! videoconvert ! video/x-raw,width=1280,height=720,framerate=25/1 ! "
"clockoverlay halignment=right valignment=top time-format=\"%Y-%m-%d %H:%M:%S\" ! "
"x264enc name=sampleVideoEncoder bframes=0 speed-preset=veryfast bitrate=512 byte-stream=TRUE tune=zerolatency ! "
"video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! "
"appsink sync=TRUE emit-signals=TRUE name=appsink-video audiotestsrc wave=ticks is-live=TRUE ! "
"queue leaky=2 max-size-buffers=400 ! audioconvert ! audioresample ! opusenc name=sampleAudioEncoder ! "
"audio/x-opus,rate=48000,channels=2 ! appsink sync=TRUE emit-signals=TRUE name=appsink-audio",
&error);
} else if (pSampleConfiguration->videoCodec == RTC_CODEC_H265 && pSampleConfiguration->audioCodec == RTC_CODEC_OPUS) {
senderPipeline =
gst_parse_launch("videotestsrc pattern=ball is-live=TRUE ! timeoverlay ! queue ! videoconvert ! "
"video/x-raw,width=1280,height=720,framerate=25/1 ! queue ! "
"x265enc speed-preset=veryfast bitrate=512 tune=zerolatency ! "
"video/x-h265,stream-format=byte-stream,alignment=au,profile=main ! appsink sync=TRUE "
"emit-signals=TRUE name=appsink-video audiotestsrc is-live=TRUE ! "
"queue leaky=2 max-size-buffers=400 ! audioconvert ! audioresample ! opusenc ! "
"audio/x-opus,rate=48000,channels=2 ! appsink sync=TRUE emit-signals=TRUE name=appsink-audio",
&error);
}
// TODO: test and add more such combinations
break;
}
case DEVICE_SOURCE: {
senderPipeline = gst_parse_launch(
"autovideosrc ! queue ! videoconvert ! video/x-raw,width=1280,height=720,framerate=25/1 ! "
"x264enc name=sampleVideoEncoder bframes=0 speed-preset=veryfast bitrate=512 byte-stream=TRUE tune=zerolatency ! "
"video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! appsink sync=TRUE emit-signals=TRUE "
"name=appsink-video autoaudiosrc ! "
"queue leaky=2 max-size-buffers=400 ! audioconvert ! audioresample ! opusenc name=sampleAudioEncoder ! "
"audio/x-opus,rate=48000,channels=2 ! appsink sync=TRUE emit-signals=TRUE name=appsink-audio",
&error);
break;
}
case RTSP_SOURCE: {
UINT16 stringOutcome =
SNPRINTF(rtspPipeLineBuffer, RTSP_PIPELINE_MAX_CHAR_COUNT,
"uridecodebin uri=%s name=src ! videoconvert ! "
"x264enc name=sampleVideoEncoder bframes=0 speed-preset=veryfast bitrate=512 byte-stream=TRUE tune=zerolatency ! "
"video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! queue ! "
"appsink sync=TRUE emit-signals=TRUE name=appsink-video "
"src. ! audioconvert ! "
"audioresample ! opusenc name=sampleAudioEncoder ! audio/x-opus,rate=48000,channels=2 ! queue ! "
"appsink sync=TRUE emit-signals=TRUE name=appsink-audio",
pSampleConfiguration->rtspUri);
if (stringOutcome > RTSP_PIPELINE_MAX_CHAR_COUNT) {
DLOGE("[KVS GStreamer Master] ERROR: rtsp uri entered exceeds maximum allowed length set by RTSP_PIPELINE_MAX_CHAR_COUNT");
goto CleanUp;
}
senderPipeline = gst_parse_launch(rtspPipeLineBuffer, &error);
break;
}
}
break;
}
CHK_ERR(senderPipeline != NULL, STATUS_NULL_ARG, "[KVS Gstreamer Master] Pipeline is NULL");
appsinkVideo = gst_bin_get_by_name(GST_BIN(senderPipeline), "appsink-video");
appsinkAudio = gst_bin_get_by_name(GST_BIN(senderPipeline), "appsink-audio");
if (!(appsinkVideo != NULL || appsinkAudio != NULL)) {
DLOGE("[KVS GStreamer Master] sendGstreamerAudioVideo(): cant find appsink, operation returned status code: 0x%08x", STATUS_INTERNAL_ERROR);
goto CleanUp;
}
if (appsinkVideo != NULL) {
g_signal_connect(appsinkVideo, "new-sample", G_CALLBACK(on_new_sample_video), (gpointer) pSampleConfiguration);
}
if (appsinkAudio != NULL) {
g_signal_connect(appsinkAudio, "new-sample", G_CALLBACK(on_new_sample_audio), (gpointer) pSampleConfiguration);
}
gst_element_set_state(senderPipeline, GST_STATE_PLAYING);
/* block until error or EOS */
bus = gst_element_get_bus(senderPipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Free resources */
if (msg != NULL) {
gst_message_unref(msg);
}
if (bus != NULL) {
gst_object_unref(bus);
}
if (senderPipeline != NULL) {
gst_element_set_state(senderPipeline, GST_STATE_NULL);
gst_object_unref(senderPipeline);
}
if (appsinkAudio != NULL) {
gst_object_unref(appsinkAudio);
}
if (appsinkVideo != NULL) {
gst_object_unref(appsinkVideo);
}
CleanUp:
if (error != NULL) {
DLOGE("[KVS GStreamer Master] %s", error->message);
g_clear_error(&error);
}
return (PVOID) (ULONG_PTR) retStatus;
}
INT32 main(INT32 argc, CHAR* argv[])
{
STATUS retStatus = STATUS_SUCCESS;
PSampleConfiguration pSampleConfiguration = NULL;
PCHAR pChannelName;
RTC_CODEC audioCodec = RTC_CODEC_OPUS;
RTC_CODEC videoCodec = RTC_CODEC_H264_PROFILE_42E01F_LEVEL_ASYMMETRY_ALLOWED_PACKETIZATION_MODE;
SET_INSTRUMENTED_ALLOCATORS();
UINT32 logLevel = setLogLevel();
signal(SIGINT, sigintHandler);
#ifdef IOT_CORE_ENABLE_CREDENTIALS
CHK_ERR((pChannelName = argc > 1 ? argv[1] : GETENV(IOT_CORE_THING_NAME)) != NULL, STATUS_INVALID_OPERATION,
"AWS_IOT_CORE_THING_NAME must be set");
#else
pChannelName = argc > 1 ? argv[1] : SAMPLE_CHANNEL_NAME;
#endif
CHK_STATUS(createSampleConfiguration(pChannelName, SIGNALING_CHANNEL_ROLE_TYPE_MASTER, TRUE, TRUE, logLevel, &pSampleConfiguration));
if (argc > 3 && STRCMP(argv[3], "testsrc") == 0) {
if (argc > 4) {
if (!STRCMP(argv[4], AUDIO_CODEC_NAME_OPUS)) {
audioCodec = RTC_CODEC_OPUS;
}
}
if (argc > 5) {
if (!STRCMP(argv[5], VIDEO_CODEC_NAME_H265)) {
videoCodec = RTC_CODEC_H265;
}
}
}
pSampleConfiguration->videoSource = sendGstreamerAudioVideo;
pSampleConfiguration->mediaType = SAMPLE_STREAMING_VIDEO_ONLY;
pSampleConfiguration->audioCodec = audioCodec;
pSampleConfiguration->videoCodec = videoCodec;
#ifdef ENABLE_DATA_CHANNEL
pSampleConfiguration->onDataChannel = onDataChannel;
#endif
pSampleConfiguration->customData = (UINT64) pSampleConfiguration;
pSampleConfiguration->srcType = DEVICE_SOURCE; // Default to device source (autovideosrc and autoaudiosrc)
/* Initialize GStreamer */
gst_init(&argc, &argv);
DLOGI("[KVS Gstreamer Master] Finished initializing GStreamer and handlers");
if (argc > 2) {
if (STRCMP(argv[2], "video-only") == 0) {
pSampleConfiguration->mediaType = SAMPLE_STREAMING_VIDEO_ONLY;
DLOGI("[KVS Gstreamer Master] Streaming video only");
} else if (STRCMP(argv[2], "audio-video-storage") == 0) {
pSampleConfiguration->mediaType = SAMPLE_STREAMING_AUDIO_VIDEO;
pSampleConfiguration->channelInfo.useMediaStorage = TRUE;
DLOGI("[KVS Gstreamer Master] Streaming audio and video");
} else if (STRCMP(argv[2], "audio-video") == 0) {
pSampleConfiguration->mediaType = SAMPLE_STREAMING_AUDIO_VIDEO;
DLOGI("[KVS Gstreamer Master] Streaming audio and video");
} else {
DLOGI("[KVS Gstreamer Master] Unrecognized streaming type. Default to video-only");
}
} else {
DLOGI("[KVS Gstreamer Master] Streaming video only");
}
if (argc > 3) {
if (STRCMP(argv[3], "testsrc") == 0) {
DLOGI("[KVS GStreamer Master] Using test source in GStreamer");
pSampleConfiguration->srcType = TEST_SOURCE;
} else if (STRCMP(argv[3], "devicesrc") == 0) {
DLOGI("[KVS GStreamer Master] Using device source in GStreamer");
pSampleConfiguration->srcType = DEVICE_SOURCE;
} else if (STRCMP(argv[3], "rtspsrc") == 0) {
DLOGI("[KVS GStreamer Master] Using RTSP source in GStreamer");
if (argc < 5) {
DLOGI("[KVS GStreamer Master] No RTSP source URI included. Defaulting to device source");
DLOGI("[KVS GStreamer Master] Usage: ./kvsWebrtcClientMasterGstSample <channel name> audio-video rtspsrc rtsp://<rtsp uri>"
"or ./kvsWebrtcClientMasterGstSample <channel name> video-only rtspsrc <rtsp://<rtsp uri>");
pSampleConfiguration->srcType = DEVICE_SOURCE;
} else {
pSampleConfiguration->srcType = RTSP_SOURCE;
pSampleConfiguration->rtspUri = argv[4];
}
} else {
DLOGI("[KVS Gstreamer Master] Unrecognized source type. Defaulting to device source in GStreamer");
}
} else {
DLOGI("[KVS GStreamer Master] Using device source in GStreamer");
}
switch (pSampleConfiguration->mediaType) {
case SAMPLE_STREAMING_VIDEO_ONLY:
DLOGI("[KVS GStreamer Master] streaming type video-only");
break;
case SAMPLE_STREAMING_AUDIO_VIDEO:
DLOGI("[KVS GStreamer Master] streaming type audio-video");
break;
}
// Initalize KVS WebRTC. This must be done before anything else, and must only be done once.
CHK_STATUS(initKvsWebRtc());
DLOGI("[KVS GStreamer Master] KVS WebRTC initialization completed successfully");
CHK_STATUS(initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID));
DLOGI("[KVS GStreamer Master] Channel %s set up done ", pChannelName);
// Checking for termination
CHK_STATUS(sessionCleanupWait(pSampleConfiguration));
DLOGI("[KVS GStreamer Master] Streaming session terminated");
CleanUp:
if (retStatus != STATUS_SUCCESS) {
DLOGE("[KVS GStreamer Master] Terminated with status code 0x%08x", retStatus);
}
DLOGI("[KVS GStreamer Master] Cleaning up....");
if (pSampleConfiguration != NULL) {
// Kick of the termination sequence
ATOMIC_STORE_BOOL(&pSampleConfiguration->appTerminateFlag, TRUE);
if (pSampleConfiguration->mediaSenderTid != INVALID_TID_VALUE) {
THREAD_JOIN(pSampleConfiguration->mediaSenderTid, NULL);
}
if (pSampleConfiguration->enableFileLogging) {
freeFileLogger();
}
retStatus = freeSignalingClient(&pSampleConfiguration->signalingClientHandle);
if (retStatus != STATUS_SUCCESS) {
DLOGE("[KVS GStreamer Master] freeSignalingClient(): operation returned status code: 0x%08x", retStatus);
}
retStatus = freeSampleConfiguration(&pSampleConfiguration);
if (retStatus != STATUS_SUCCESS) {
DLOGE("[KVS GStreamer Master] freeSampleConfiguration(): operation returned status code: 0x%08x", retStatus);
}
}
DLOGI("[KVS Gstreamer Master] Cleanup done");
RESET_INSTRUMENTED_ALLOCATORS();
// https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
// We can only return with 0 - 127. Some platforms treat exit code >= 128
// to be a success code, which might give an unintended behaviour.
// Some platforms also treat 1 or 0 differently, so it's better to use
// EXIT_FAILURE and EXIT_SUCCESS macros for portability.
return STATUS_FAILED(retStatus) ? EXIT_FAILURE : EXIT_SUCCESS;
}