33 * AUTHORS: David Cassany <david.cassany@i2cat.net>
44 * Gerard Castillo <gerard.castillo@i2cat.net>
55 *
6- * Copyright (c) 2005-2010 Fundació i2CAT, Internet I Innovació Digital a Catalunya
7- * Copyright (c) 2014-2023 CESNET, z. s. p. o.
6+ * Copyright (c) 2013-2014 Fundació i2CAT, Internet I Innovació Digital a Catalunya
7+ * Copyright (c) 2014-2026 CESNET, zájmové sdružení právnických osob
88 *
99 * Redistribution and use in source and binary forms, with or without
1010 * modification, is permitted provided that the following conditions
@@ -64,6 +64,7 @@ BasicRTSPOnlySubsession*
6464BasicRTSPOnlySubsession::createNew (UsageEnvironment& env,
6565 Boolean reuseFirstSource, rtsp_types_t avType, int rtpPort,
6666 struct rtsp_server_parameters params) {
67+ assert (avType == rtsp_type_audio || avType == rtsp_type_video);
6768 return new BasicRTSPOnlySubsession (env, reuseFirstSource, avType,
6869 rtpPort, params);
6970}
@@ -75,8 +76,7 @@ BasicRTSPOnlySubsession::BasicRTSPOnlySubsession(UsageEnvironment& env,
7576 fLastStreamToken(nullptr ), rtsp_params(params)
7677{
7778 assert (avType == rtsp_type_audio || avType == rtsp_type_video);
78- Vdestination = NULL ;
79- Adestination = NULL ;
79+ destination = NULL ;
8080 gethostname (fCNAME , sizeof fCNAME );
8181 this ->avType = avType;
8282 this ->rtpPort = rtpPort;
@@ -90,8 +90,7 @@ BasicRTSPOnlySubsession::BasicRTSPOnlySubsession(UsageEnvironment& env,
9090
9191BasicRTSPOnlySubsession::~BasicRTSPOnlySubsession () {
9292 delete[] fSDPLines ;
93- delete Adestination;
94- delete Vdestination;
93+ delete destination;
9594}
9695
9796const static struct media_spec {
@@ -181,26 +180,12 @@ void BasicRTSPOnlySubsession::getStreamParameters(unsigned /* clientSessionId */
181180 struct sockaddr_storage & /* destinationAddress*/ , uint8_t & /* destinationTTL*/ ,
182181 Boolean& /* isMulticast */ , Port& serverRTPPort, Port& serverRTCPPort,
183182 void *& /* streamToken */ ) {
184- if (avType == rtsp_type_video) {
185- Port rtp (rtsp_params.rtp_port_video );
186- serverRTPPort = rtp;
187- Port rtcp (rtsp_params.rtp_port_video + 1 );
188- serverRTCPPort = rtcp;
189-
190- delete Vdestination;
191- Vdestination = new Destinations (clientAddress, clientRTPPort,
192- clientRTCPPort);
193- }
194- if (avType == rtsp_type_audio) {
195- Port rtp (rtsp_params.rtp_port_audio );
196- serverRTPPort = rtp;
197- Port rtcp (rtsp_params.rtp_port_audio + 1 );
198- serverRTCPPort = rtcp;
199-
200- delete Adestination;
201- Adestination = new Destinations (clientAddress, clientRTPPort,
202- clientRTCPPort);
203- }
183+ delete destination;
184+ serverRTPPort = avType == rtsp_type_video ? rtsp_params.rtp_port_video
185+ : rtsp_params.rtp_port_audio ;
186+ serverRTCPPort = serverRTPPort.num () + 1 ;
187+ destination =
188+ new Destinations (clientAddress, clientRTPPort, clientRTCPPort);
204189}
205190
206191void BasicRTSPOnlySubsession::startStream (unsigned /* clientSessionId */ ,
@@ -211,139 +196,136 @@ void BasicRTSPOnlySubsession::startStream(unsigned /* clientSessionId */,
211196 void * /* serverRequestAlternativeByteHandlerClientData */ ) {
212197 struct response *resp = NULL ;
213198
214- if (Vdestination != NULL ) {
215- if (avType == rtsp_type_video) {
216- char pathV[1024 ];
217-
218- memset (pathV, 0 , sizeof (pathV));
219- enum module_class path_sender[] = { MODULE_CLASS_SENDER,
220- MODULE_CLASS_NONE };
221- append_message_path (pathV, sizeof (pathV), path_sender);
222-
223- // CHANGE DST PORT
224- struct msg_sender *msgV1 = (struct msg_sender *) new_message (
225- sizeof (struct msg_sender ));
226- msgV1->tx_port = ntohs (Vdestination->rtpPort .num ());
227- msgV1->type = SENDER_MSG_CHANGE_PORT;
228- resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV1);
229- free_response (resp);
230-
231- // CHANGE DST ADDRESS
232- struct msg_sender *msgV2 = (struct msg_sender *) new_message (
233- sizeof (struct msg_sender ));
234- char host[IN6_MAX_ASCII_LEN + 1 ];
235- const int ret =
236- getnameinfo ((struct sockaddr *) &Vdestination->addr ,
237- sizeof Vdestination->addr , host,
238- sizeof host, nullptr , 0 , NI_NUMERICHOST);
239- assert (ret == 0 );
240- strncpy (msgV2->receiver , host,
241- sizeof (msgV2->receiver ) - 1 );
242- msgV2->type = SENDER_MSG_CHANGE_RECEIVER;
243-
244- resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV2);
245- free_response (resp);
246- }
199+ // / @todo shouldn't here be rather assert?
200+ if (destination == nullptr ) {
201+ return ;
202+ }
203+
204+ if (avType == rtsp_type_video) {
205+ char pathV[1024 ];
206+
207+ memset (pathV, 0 , sizeof (pathV));
208+ enum module_class path_sender[] = { MODULE_CLASS_SENDER,
209+ MODULE_CLASS_NONE };
210+ append_message_path (pathV, sizeof (pathV), path_sender);
211+
212+ // CHANGE DST PORT
213+ struct msg_sender *msgV1 = (struct msg_sender *) new_message (
214+ sizeof (struct msg_sender ));
215+ msgV1->tx_port = ntohs (destination->rtpPort .num ());
216+ msgV1->type = SENDER_MSG_CHANGE_PORT;
217+ resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV1);
218+ free_response (resp);
219+
220+ // CHANGE DST ADDRESS
221+ struct msg_sender *msgV2 = (struct msg_sender *) new_message (
222+ sizeof (struct msg_sender ));
223+ char host[IN6_MAX_ASCII_LEN + 1 ];
224+ const int ret =
225+ getnameinfo ((struct sockaddr *) &destination->addr ,
226+ sizeof destination->addr , host,
227+ sizeof host, nullptr , 0 , NI_NUMERICHOST);
228+ assert (ret == 0 );
229+ strncpy (msgV2->receiver , host,
230+ sizeof (msgV2->receiver ) - 1 );
231+ msgV2->type = SENDER_MSG_CHANGE_RECEIVER;
232+
233+ resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV2);
234+ free_response (resp);
247235 }
248236
249- if (Adestination != NULL ) {
250- if (avType == rtsp_type_audio) {
251- char pathA[1024 ];
252-
253- memset (pathA, 0 , sizeof (pathA));
254- enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
255- MODULE_CLASS_SENDER, MODULE_CLASS_NONE };
256- append_message_path (pathA, sizeof (pathA), path_sender);
257-
258- // CHANGE DST PORT
259- struct msg_sender *msgA1 = (struct msg_sender *) new_message (
260- sizeof (struct msg_sender ));
261- msgA1->tx_port = ntohs (Adestination->rtpPort .num ());
262- msgA1->type = SENDER_MSG_CHANGE_PORT;
263- resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA1);
264- free_response (resp);
265- resp = NULL ;
266-
267- // CHANGE DST ADDRESS
268- struct msg_sender *msgA2 = (struct msg_sender *) new_message (
269- sizeof (struct msg_sender ));
270- char host[IN6_MAX_ASCII_LEN + 1 ];
271- const int ret =
272- getnameinfo ((struct sockaddr *) &Adestination->addr ,
273- sizeof Adestination->addr , host,
274- sizeof host, nullptr , 0 , NI_NUMERICHOST);
275- assert (ret == 0 );
276- strncpy (msgA2->receiver , host,
277- sizeof (msgA2->receiver ) - 1 );
278- msgA2->type = SENDER_MSG_CHANGE_RECEIVER;
279-
280- resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA2);
281- free_response (resp);
282- resp = NULL ;
283- }
237+ if (avType == rtsp_type_audio) {
238+ char pathA[1024 ];
239+
240+ memset (pathA, 0 , sizeof (pathA));
241+ enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
242+ MODULE_CLASS_SENDER, MODULE_CLASS_NONE };
243+ append_message_path (pathA, sizeof (pathA), path_sender);
244+
245+ // CHANGE DST PORT
246+ struct msg_sender *msgA1 = (struct msg_sender *) new_message (
247+ sizeof (struct msg_sender ));
248+ msgA1->tx_port = ntohs (destination->rtpPort .num ());
249+ msgA1->type = SENDER_MSG_CHANGE_PORT;
250+ resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA1);
251+ free_response (resp);
252+ resp = NULL ;
253+
254+ // CHANGE DST ADDRESS
255+ struct msg_sender *msgA2 = (struct msg_sender *) new_message (
256+ sizeof (struct msg_sender ));
257+ char host[IN6_MAX_ASCII_LEN + 1 ];
258+ const int ret =
259+ getnameinfo ((struct sockaddr *) &destination->addr ,
260+ sizeof destination->addr , host,
261+ sizeof host, nullptr , 0 , NI_NUMERICHOST);
262+ assert (ret == 0 );
263+ strncpy (msgA2->receiver , host,
264+ sizeof (msgA2->receiver ) - 1 );
265+ msgA2->type = SENDER_MSG_CHANGE_RECEIVER;
266+
267+ resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA2);
268+ free_response (resp);
269+ resp = NULL ;
284270 }
285271}
286272
287273void BasicRTSPOnlySubsession::deleteStream (unsigned /* clientSessionId */ ,
288274 void *& /* streamToken */ ) {
289- if (Vdestination != NULL ) {
290- if (avType == rtsp_type_video) {
291- char pathV[1024 ];
292- delete Vdestination;
293- Vdestination = NULL ;
294- memset (pathV, 0 , sizeof (pathV));
295- enum module_class path_sender[] = { MODULE_CLASS_SENDER,
296- MODULE_CLASS_NONE };
297- append_message_path (pathV, sizeof (pathV), path_sender);
298-
299- // CHANGE DST PORT
300- struct msg_sender *msgV1 = (struct msg_sender *) new_message (
301- sizeof (struct msg_sender ));
302- msgV1->tx_port = rtsp_params.rtp_port_video ;
303- msgV1->type = SENDER_MSG_CHANGE_PORT;
304- struct response *resp;
305- resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV1);
306- free_response (resp);
307-
308- // CHANGE DST ADDRESS
309- struct msg_sender *msgV2 = (struct msg_sender *) new_message (
310- sizeof (struct msg_sender ));
311- strncpy (msgV2->receiver , " 127.0.0.1" , sizeof (msgV2->receiver ) - 1 );
312- msgV2->type = SENDER_MSG_CHANGE_RECEIVER;
313- resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV2);
314- free_response (resp);
315- }
275+ if (avType == rtsp_type_video) {
276+ char pathV[1024 ];
277+ delete destination;
278+ destination = NULL ;
279+ memset (pathV, 0 , sizeof (pathV));
280+ enum module_class path_sender[] = { MODULE_CLASS_SENDER,
281+ MODULE_CLASS_NONE };
282+ append_message_path (pathV, sizeof (pathV), path_sender);
283+
284+ // CHANGE DST PORT
285+ struct msg_sender *msgV1 = (struct msg_sender *) new_message (
286+ sizeof (struct msg_sender ));
287+ msgV1->tx_port = rtsp_params.rtp_port_video ;
288+ msgV1->type = SENDER_MSG_CHANGE_PORT;
289+ struct response *resp;
290+ resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV1);
291+ free_response (resp);
292+
293+ // CHANGE DST ADDRESS
294+ struct msg_sender *msgV2 = (struct msg_sender *) new_message (
295+ sizeof (struct msg_sender ));
296+ strncpy (msgV2->receiver , " 127.0.0.1" , sizeof (msgV2->receiver ) - 1 );
297+ msgV2->type = SENDER_MSG_CHANGE_RECEIVER;
298+ resp = send_message (rtsp_params.parent , pathV, (struct message *) msgV2);
299+ free_response (resp);
316300 }
317301
318- if (Adestination != NULL ) {
319- if (avType == rtsp_type_audio) {
320- char pathA[1024 ];
321- delete Adestination;
322- Adestination = NULL ;
323- memset (pathA, 0 , sizeof (pathA));
324- enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
325- MODULE_CLASS_SENDER, MODULE_CLASS_NONE };
326- append_message_path (pathA, sizeof (pathA), path_sender);
327-
328- // CHANGE DST PORT
329- struct msg_sender *msgA1 = (struct msg_sender *) new_message (
330- sizeof (struct msg_sender ));
331-
332- // TODO: GET AUDIO PORT SET (NOT A COMMON CASE WHEN RTSP IS ENABLED: DEFAULT -> vport + 2)
333- msgA1->tx_port = rtsp_params.rtp_port_audio ;
334- msgA1->type = SENDER_MSG_CHANGE_PORT;
335- struct response *resp;
336- resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA1);
337- free_response (resp);
338-
339- // CHANGE DST ADDRESS
340- struct msg_sender *msgA2 = (struct msg_sender *) new_message (
341- sizeof (struct msg_sender ));
342- strncpy (msgA2->receiver , " 127.0.0.1" , sizeof (msgA2->receiver ) - 1 );
343- msgA2->type = SENDER_MSG_CHANGE_RECEIVER;
344- resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA2);
345- free_response (resp);
346- }
302+ if (avType == rtsp_type_audio) {
303+ char pathA[1024 ];
304+ delete destination;
305+ destination = NULL ;
306+ memset (pathA, 0 , sizeof (pathA));
307+ enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
308+ MODULE_CLASS_SENDER, MODULE_CLASS_NONE };
309+ append_message_path (pathA, sizeof (pathA), path_sender);
310+
311+ // CHANGE DST PORT
312+ struct msg_sender *msgA1 = (struct msg_sender *) new_message (
313+ sizeof (struct msg_sender ));
314+
315+ // TODO: GET AUDIO PORT SET (NOT A COMMON CASE WHEN RTSP IS ENABLED: DEFAULT -> vport + 2)
316+ msgA1->tx_port = rtsp_params.rtp_port_audio ;
317+ msgA1->type = SENDER_MSG_CHANGE_PORT;
318+ struct response *resp;
319+ resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA1);
320+ free_response (resp);
321+
322+ // CHANGE DST ADDRESS
323+ struct msg_sender *msgA2 = (struct msg_sender *) new_message (
324+ sizeof (struct msg_sender ));
325+ strncpy (msgA2->receiver , " 127.0.0.1" , sizeof (msgA2->receiver ) - 1 );
326+ msgA2->type = SENDER_MSG_CHANGE_RECEIVER;
327+ resp = send_message (rtsp_params.parent , pathA, (struct message *) msgA2);
328+ free_response (resp);
347329 }
348330}
349331/* vi: set noexpandtab: */
0 commit comments