-
Notifications
You must be signed in to change notification settings - Fork 1
/
GstPGMSink.c
699 lines (598 loc) · 19.4 KB
/
GstPGMSink.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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/* vim:ts=8:sts=4:sw=4:noai:noexpandtab
*
* PGM GStreamer-sink GObject interface (GstPgmSink)
*
* Copyright (c) 2008 Miru Limited.
* Copyright (c) 2014 Tim Aerts.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include <netinet/ip.h>
#include <pgm/packet.h>
#include "GstPGMSink.h"
#include "GstPGMConfig.h"
enum
{
PROP_0,
PROP_NETWORK = 1,
PROP_PORT,
PROP_URI,
PROP_UDP_ENCAP_PORT,
PROP_MAX_TPDU,
PROP_HOPS,
PROP_TXW_SQNS,
PROP_SPM_AMBIENT,
PROP_IHB_MIN,
PROP_IHB_MAX,
PROP_LAST
};
/* supported media types of this pad */
static GstStaticPadTemplate gst_pgm_sink_sink_template =
GST_STATIC_PAD_TEMPLATE ( "sink"
, GST_PAD_SINK
, GST_PAD_ALWAYS
, GST_STATIC_CAPS_ANY
);
static gboolean gst_pgm_sink_set_uri (GstPgmSink*, const gchar*);
static void gst_pgm_sink_uri_handler_init (gpointer, gpointer);
static GstFlowReturn gst_pgm_sink_render (GstBaseSink*, GstBuffer*);
static gboolean gst_pgm_client_sink_stop (GstBaseSink*);
static gboolean gst_pgm_client_sink_start (GstBaseSink*);
static void gst_pgm_sink_finalize (GObject*);
static void gst_pgm_sink_set_property (GObject*, guint, const GValue*, GParamSpec*);
static void gst_pgm_sink_get_property (GObject*, guint, GValue*, GParamSpec*);
G_DEFINE_TYPE (GstPgmSink, gst_pgm_sink, GST_TYPE_BASE_SINK)
static GstURIType gst_pgm_sink_uri_get_type (GType dummy)
{
return GST_URI_SRC;
}
static const gchar* const* gst_pgm_sink_uri_get_protocols (GType dummy)
{
static const gchar* protocols[] = { "pgm", NULL };
return protocols;
}
static gchar* gst_pgm_sink_uri_get_uri (GstURIHandler* i_handler)
{
GstPgmSink* sink = GST_PGM_SINK(i_handler);
return sink->uri;
}
static gboolean gst_pgm_sink_uri_set_uri (GstURIHandler* i_handler, const gchar* i_uri, GError** o_err)
{
GstPgmSink* sink = GST_PGM_SINK(i_handler);
return gst_pgm_sink_set_uri (sink, i_uri);
}
static void gst_pgm_sink_uri_handler_init (gpointer o_iface, gpointer dummy)
{
GstURIHandlerInterface* iface = (GstURIHandlerInterface*)o_iface;
iface->get_type = GST_DEBUG_FUNCPTR(gst_pgm_sink_uri_get_type);
iface->get_protocols = GST_DEBUG_FUNCPTR(gst_pgm_sink_uri_get_protocols);
iface->get_uri = GST_DEBUG_FUNCPTR(gst_pgm_sink_uri_get_uri);
iface->set_uri = GST_DEBUG_FUNCPTR(gst_pgm_sink_uri_set_uri);
}
static void gst_pgm_sink_update_uri (GstPgmSink* io_sink)
{
g_free (io_sink->uri);
io_sink->uri = g_strdup_printf ("pgm://%s:%i:%i", io_sink->network, io_sink->port, io_sink->udp_encap_port);
}
static gboolean gst_pgm_sink_set_uri (GstPgmSink* io_sink, const gchar* i_uri)
{
gchar* protocol = gst_uri_get_protocol (i_uri);
if (strncmp (protocol, "pgm", strlen("pgm")) != 0) goto wrong_protocol;
{
g_free (protocol);
gchar* location = gst_uri_get_location (i_uri);
if (location == NULL) return FALSE;
gchar* port = strstr (location, ":");
g_free (io_sink->network);
if (port == NULL)
{
io_sink->network = g_strdup (location);
io_sink->port = PGM_DEFAULT_PORT;
io_sink->udp_encap_port = PGM_DEFAULT_UDP_ENCAP_PORT;
}
else
{
io_sink->network = g_strndup (location, port - location);
io_sink->port = atoi (port + 1);
gchar* udp_encap_port = strstr (port + 1, ":");
if (udp_encap_port == NULL)
{
io_sink->udp_encap_port = PGM_DEFAULT_UDP_ENCAP_PORT;
}
else
{
io_sink->udp_encap_port = atoi (udp_encap_port + 1);
}
}
g_free (location);
gst_pgm_sink_update_uri (io_sink);
return TRUE;
}
wrong_protocol:
g_free (protocol);
GST_ELEMENT_ERROR ( io_sink
, RESOURCE
, READ
, (NULL)
, ("error parsing uri %s: wrong protocol (%s != udp)", i_uri, protocol)
);
return FALSE;
}
static gpointer gst_pgm_sink_nak_thread (gpointer io_sink)
{
GstPgmSink* sink = (GstPgmSink*) io_sink;
struct pgm_msgv_t msgv;
int result;
do
{
result = pgm_recvmsg (sink->sock, &msgv, 0, NULL, NULL);
}
while (!sink->nak_quit);
return NULL;
}
static void gst_pgm_sink_base_init (gpointer klass)
{
}
static void gst_pgm_sink_class_init (GstPgmSinkClass* klass)
{
GstBaseSinkClass* gstbasesink_class = (GstBaseSinkClass*)klass;
gstbasesink_class->start = GST_DEBUG_FUNCPTR(gst_pgm_client_sink_start);
gstbasesink_class->stop = GST_DEBUG_FUNCPTR(gst_pgm_client_sink_stop);
gstbasesink_class->render = GST_DEBUG_FUNCPTR(gst_pgm_sink_render);
GObjectClass* gobjectClass = (GObjectClass*)klass;
gobjectClass->finalize = GST_DEBUG_FUNCPTR(gst_pgm_sink_finalize);
gobjectClass->set_property = GST_DEBUG_FUNCPTR(gst_pgm_sink_set_property);
gobjectClass->get_property = GST_DEBUG_FUNCPTR(gst_pgm_sink_get_property);
GstElementClass* elementClass = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template
( elementClass
, gst_static_pad_template_get (&gst_pgm_sink_sink_template)
);
gst_element_class_set_static_metadata
( elementClass
, "PGM Sink"
, "Source/Network"
, "Sends data from a GStreamer pipeline over PGM."
, "Tim Aerts <[email protected]>"
);
g_object_class_install_property
( gobjectClass
, PROP_NETWORK
, g_param_spec_string
( "network"
, "Network"
, "Rendezvous style multicast network definition."
, PGM_DEFAULT_NETWORK
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_PORT
, g_param_spec_uint
( "dport"
, "DPORT"
, "Data-destination port."
, 0 // minimum
, UINT16_MAX
, PGM_DEFAULT_PORT
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_URI
, g_param_spec_string
( "uri"
, "URI"
, "URI in the form of pgm://adapter;receive-multicast-groups;send-multicast-group:destination-port:udp-encapsulation-port"
, PGM_DEFAULT_URI
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_UDP_ENCAP_PORT
, g_param_spec_uint
( "udp-encap-port"
, "UDP encapsulation port"
, "UDP port for encapsulation of PGM protocol."
, 0 // minimum
, UINT16_MAX
, PGM_DEFAULT_UDP_ENCAP_PORT
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_MAX_TPDU
, g_param_spec_uint
( "max-tpdu"
, "Maximum TPDU"
, "Largest supported Transport Protocol Data Unit."
, (sizeof(struct iphdr) + sizeof(struct pgm_header))
, UINT16_MAX
, PGM_DEFAULT_MAX_TPDU
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_HOPS
, g_param_spec_uint
( "hops"
, "Hops"
, "Multicast packet hop limit."
, 1 // minimum
, UINT8_MAX
, PGM_DEFAULT_HOPS
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_TXW_SQNS
, g_param_spec_uint
( "txw-sqns"
, "TXW_SQNS"
, "Size of the transmit window in sequence numbers."
, 1 // minimum
, UINT16_MAX
, PGM_DEFAULT_TXW_SQNS
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_SPM_AMBIENT
, g_param_spec_uint
( "spm-ambient"
, "SPM ambient"
, "Ambient SPM broadcast interval."
, 1 // minimum
, UINT_MAX
, PGM_DEFAULT_SPM_AMBIENT
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_IHB_MIN
, g_param_spec_uint
( "ihb-min"
, "IHB_MIN"
, "Minimum SPM inter-heartbeat timer interval."
, 1 // minimum
, UINT_MAX
, PGM_DEFAULT_IHB_MIN
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
g_object_class_install_property
( gobjectClass
, PROP_IHB_MAX
, g_param_spec_uint
( "ihb-max"
, "IHB_MAX"
, "Maximum SPM inter-heartbeat timer interval."
, 1 // minimum
, UINT_MAX
, PGM_DEFAULT_IHB_MAX
, (GParamFlags) G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/
)
);
}
static void gst_pgm_sink_init ( GstPgmSink* io_sink)
{
io_sink->sock = NULL;
io_sink->network = g_strdup (PGM_DEFAULT_NETWORK);
io_sink->port = PGM_DEFAULT_PORT;
io_sink->uri = g_strdup (PGM_DEFAULT_URI);
io_sink->udp_encap_port = PGM_DEFAULT_UDP_ENCAP_PORT;
io_sink->max_tpdu = PGM_DEFAULT_MAX_TPDU;
io_sink->hops = PGM_DEFAULT_HOPS;
io_sink->txw_sqns = PGM_DEFAULT_TXW_SQNS;
io_sink->spm_ambient = PGM_DEFAULT_SPM_AMBIENT;
io_sink->ihb_min = PGM_DEFAULT_IHB_MIN;
io_sink->ihb_max = PGM_DEFAULT_IHB_MAX;
}
static void gst_pgm_sink_finalize ( GObject* io_obj)
{
GstPgmSink* sink = GST_PGM_SINK (io_obj);
g_free (sink->network);
g_free (sink->uri);
G_OBJECT_CLASS(gst_pgm_sink_parent_class)->finalize(io_obj);
}
static void gst_pgm_sink_set_property (GObject* io_obj, guint i_propId, const GValue* i_value, GParamSpec* pspec)
{
GstPgmSink* sink = GST_PGM_SINK (io_obj);
switch (i_propId)
{
case PROP_NETWORK:
g_free (sink->network);
if (g_value_get_string (i_value) == NULL)
{
sink->network = g_strdup (PGM_DEFAULT_NETWORK);
}
else
{
sink->network = g_value_dup_string (i_value);
}
gst_pgm_sink_update_uri (sink);
break;
case PROP_PORT:
sink->port = g_value_get_uint (i_value);
gst_pgm_sink_update_uri (sink);
break;
case PROP_UDP_ENCAP_PORT:
sink->udp_encap_port = g_value_get_uint (i_value);
gst_pgm_sink_update_uri (sink);
break;
case PROP_URI:
gst_pgm_sink_set_uri (sink, g_value_get_string (i_value));
break;
case PROP_MAX_TPDU:
sink->max_tpdu = g_value_get_uint (i_value);
break;
case PROP_HOPS:
sink->hops = g_value_get_uint (i_value);
break;
case PROP_TXW_SQNS:
sink->txw_sqns = g_value_get_uint (i_value);
break;
case PROP_SPM_AMBIENT:
sink->spm_ambient = g_value_get_uint (i_value);
break;
case PROP_IHB_MIN:
sink->ihb_min = g_value_get_uint (i_value);
break;
case PROP_IHB_MAX:
sink->ihb_max = g_value_get_uint (i_value);
break;
}
}
static void gst_pgm_sink_get_property (GObject* io_obj, guint i_propId, GValue* o_value, GParamSpec* pspec)
{
GstPgmSink* sink = GST_PGM_SINK (io_obj);
switch (i_propId)
{
case PROP_NETWORK:
g_value_set_string (o_value, sink->network);
break;
case PROP_PORT:
g_value_set_uint (o_value, sink->port);
break;
case PROP_UDP_ENCAP_PORT:
g_value_set_uint (o_value, sink->udp_encap_port);
break;
case PROP_URI:
g_value_set_string (o_value, sink->uri);
break;
case PROP_MAX_TPDU:
g_value_set_uint (o_value, sink->max_tpdu);
break;
case PROP_HOPS:
g_value_set_uint (o_value, sink->hops);
break;
case PROP_TXW_SQNS:
g_value_set_uint (o_value, sink->txw_sqns);
break;
case PROP_SPM_AMBIENT:
g_value_set_uint (o_value, sink->spm_ambient);
break;
case PROP_IHB_MIN:
g_value_set_uint (o_value, sink->ihb_min);
break;
case PROP_IHB_MAX:
g_value_set_uint (o_value, sink->ihb_max);
break;
}
}
/* GstBaseSinkClass::render
*
* As a GStreamer source, create data, so recv on PGM transport.
*/
static GstFlowReturn gst_pgm_sink_render (GstBaseSink* io_basesink, GstBuffer* i_buffer)
{
GstPgmSink* sink = GST_PGM_SINK (io_basesink);
GstMapInfo map;
gst_buffer_map (i_buffer, &map, (GstMapFlags)GST_MAP_READ);
size_t written = 0u;
const int status = pgm_send ( sink->sock
, map.data
, map.size
, &written
);
gst_buffer_unmap (i_buffer, &map);
if (PGM_IO_STATUS_NORMAL != status) return GST_FLOW_ERROR;
return GST_FLOW_OK;
}
/* create PGM transport
*/
static gboolean gst_pgm_client_sink_start (GstBaseSink* basesink)
{
GstPgmSink* sink = GST_PGM_SINK (basesink);
const int valTrue = 1;
const int valFalse = 0;
sa_family_t sa_family = AF_UNSPEC;
struct pgm_addrinfo_t* res = NULL;
pgm_error_t* pErr = NULL;
GError* gErr = NULL;
if (!pgm_init (&pErr)) {
g_error ("Unable to start PGM engine: %s", pErr->message);
pgm_error_free (pErr);
goto destroy_transport;
}
if (!pgm_getaddrinfo (sink->network, NULL, &res, &pErr))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Parsing network parameter: %s", pErr->message));
pgm_error_free (pErr);
return FALSE;
}
sa_family = res->ai_send_addrs[0].gsr_group.ss_family;
if (!pgm_socket (&sink->sock, sa_family, SOCK_SEQPACKET, IPPROTO_UDP, &pErr))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Creating transport: %s", pErr->message));
pgm_freeaddrinfo (res);
return FALSE;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_IP_ROUTER_ALERT, &valFalse, sizeof(valFalse)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot unset the router assist"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_SEND_ONLY, &valTrue, sizeof(valTrue)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set send-only mode"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_MTU, &sink->max_tpdu, sizeof(sink->max_tpdu)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set maximum TPDU size"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_MULTICAST_LOOP, &valTrue, sizeof(valTrue)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set multicast loop"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_MULTICAST_HOPS, &sink->hops, sizeof(sink->hops)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set IP hop limit"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_TXW_SQNS, &sink->txw_sqns, sizeof(sink->txw_sqns)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set TXW_SQNS"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_AMBIENT_SPM, &sink->spm_ambient, sizeof(sink->spm_ambient)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set SPM ambient interval"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_UDP_ENCAP_UCAST_PORT, &sink->udp_encap_port, sizeof(sink->udp_encap_port)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set UDP encap ucast port"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_UDP_ENCAP_MCAST_PORT, &sink->udp_encap_port, sizeof(sink->udp_encap_port)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set UDP encap mcast port"));
goto destroy_transport;
}
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_NOBLOCK, &valFalse, sizeof(valFalse)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot unset no-block"));
goto destroy_transport;
}
{
const int heartbeat_spm[] = { pgm_msecs (100)
, pgm_msecs (100)
, pgm_msecs (100)
, pgm_msecs (100)
, pgm_msecs (1300)
, pgm_secs (7)
, pgm_secs (16)
, pgm_secs (25)
, pgm_secs (30)
};
if (!pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_HEARTBEAT_SPM, &heartbeat_spm, sizeof(heartbeat_spm)))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("cannot set SPM heartbeat intervals"));
goto destroy_transport;
}
}
struct pgm_sockaddr_t addr;
memset (&addr, '\0', sizeof(addr));
addr.sa_port = sink->port;
addr.sa_addr.sport = DEFAULT_DATA_SOURCE_PORT;
if (!pgm_gsi_create_from_hostname (&addr.sa_addr.gsi, &pErr))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Creating GSI: %s", pErr->message));
pgm_error_free (pErr);
pgm_freeaddrinfo (res);
return FALSE;
}
struct pgm_interface_req_t ifReq;
memset (&ifReq, '\0', sizeof(ifReq));
ifReq.ir_interface = res->ai_recv_addrs[0].gsr_interface;
ifReq.ir_scope_id = 0;
if (AF_INET6 == sa_family)
{
struct sockaddr_in6 sa6;
memcpy (&sa6, &res->ai_recv_addrs[0].gsr_group, sizeof(sa6));
ifReq.ir_scope_id = sa6.sin6_scope_id;
}
if (!pgm_bind3 ( sink->sock
, &addr, sizeof(addr)
, &ifReq, sizeof(ifReq) // tx interface
, &ifReq, sizeof(ifReq) // rx interface
, &pErr
)
)
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Binding transport: %s", pErr->message));
pgm_error_free (pErr);
goto destroy_transport;
}
for (unsigned i = 0; i < res->ai_recv_addrs_len; ++i)
{
pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_JOIN_GROUP, &res->ai_recv_addrs[i], sizeof(struct group_req));
}
pgm_setsockopt (sink->sock, IPPROTO_PGM, PGM_SEND_GROUP, &res->ai_send_addrs[0], sizeof(struct group_req));
pgm_freeaddrinfo (res);
if (!pgm_connect (sink->sock, &pErr))
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Connecting socket: %s", pErr->message));
pgm_error_free (pErr);
goto destroy_transport;
}
/* create NAK thread */
sink->nak_thread = g_thread_new
( "nak_thread"
, gst_pgm_sink_nak_thread
, sink
);
if (sink->nak_thread == NULL)
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Creating NAK processing thread:/%s", gErr->message));
g_error_free (gErr);
goto destroy_transport;
}
return TRUE;
destroy_transport:
pgm_close (sink->sock, TRUE);
sink->sock = NULL;
return FALSE;
}
static gboolean gst_pgm_client_sink_stop (GstBaseSink* io_basesink)
{
GstPgmSink* sink = GST_PGM_SINK (io_basesink);
/* stop nak thread */
if (sink->nak_thread)
{
sink->nak_quit = TRUE;
g_thread_join (sink->nak_thread);
}
GST_DEBUG_OBJECT (sink, "destroying transport");
if (sink->sock)
{
pgm_close (sink->sock, TRUE);
sink->sock = NULL;
}
return TRUE;
}