Skip to content

Commit 9114181

Browse files
committed
control_socket: drop reset-ssrc
supposing that the only user was CoUniverse + introduced asprintf compat for Windows (asprintf is used)
1 parent 24522b3 commit 9114181

6 files changed

Lines changed: 60 additions & 53 deletions

File tree

src/audio/audio.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -931,25 +931,6 @@ static struct response *audio_sender_process_message(struct state_audio *s, stru
931931
break;
932932
case SENDER_MSG_QUERY_VIDEO_MODE:
933933
return new_response(RESPONSE_BAD_REQUEST, nullptr);
934-
case SENDER_MSG_RESET_SSRC: {
935-
assert(s->audio_tx_mode == MODE_SENDER);
936-
const uint32_t old_ssrc = rtp_my_ssrc(s->audio_network_device);
937-
auto *old_devices = s->audio_network_device;
938-
s->audio_network_device =
939-
initialize_audio_network(&s->audio_network_parameters);
940-
if (s->audio_network_device == nullptr) {
941-
s->audio_network_device = old_devices;
942-
log_msg(LOG_LEVEL_ERROR,
943-
"[control] Audio: Unable to change SSRC!\n");
944-
return new_response(RESPONSE_INT_SERV_ERR, nullptr);
945-
}
946-
947-
rtp_done(old_devices);
948-
log_msg(LOG_LEVEL_NOTICE,
949-
"[control] Audio: changed SSRC from 0x%08" PRIx32 " to "
950-
"0x%08" PRIx32 ".\n",
951-
old_ssrc, rtp_my_ssrc(s->audio_network_device));
952-
} break;
953934
}
954935
return new_response(RESPONSE_OK, nullptr);
955936
}

src/compat/strings.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* compatibility header for strcasecmp. strdup, strerror_s
66
*/
77
/*
8-
* Copyright (c) 2024-2025 CESNET
8+
* Copyright (c) 2024-2026 CESNET, zájmové sdružení právnických osob
99
* All rights reserved.
1010
*
1111
* Redistribution and use in source and binary forms, with or without
@@ -72,14 +72,23 @@ COMPAT_MISC_EXT_C int __xpg_strerror_r(int errcode, char *buffer, size_t length)
7272
#endif // ! defined _WIN32
7373

7474
// strdupa is defined as a macro
75-
#include <string.h>
7675
#ifndef strdupa
7776
#define strdupa(s) (char *) memcpy(alloca(strlen(s) + 1), s, strlen(s) + 1)
7877
#endif // defined strdupa
7978

8079
COMPAT_MISC_EXT_C const char *ug_strcasestr(const char *haystack,
8180
const char *needle);
8281

82+
#ifdef _WIN32
83+
COMPAT_MISC_EXT_C int asprintf(char **strp, const char *fmt, ...);
84+
#else
85+
#ifdef __cplusplus
86+
#include <cstdio> // for asprintf
87+
#else
88+
#include <stdio.h> // for asprintf
89+
#endif
90+
#endif
91+
8392
#undef COMPAT_MISC_EXT_C
8493

8594
#endif // ! defined COMPAT_STRINGS_H_D54CAFC8_A1A0_4FF5_80A0_91F34FB11E12

src/control_socket.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#include "debug.h"
6363
#include "compat/net.h" // for net related
6464
#include "compat/platform_pipe.h"
65-
#include "compat/strings.h" // for strncasecmp, strcasecmp
65+
#include "compat/strings.h" // for asprintf, strncasecmp, strcasecmp
6666
#include "compat/time.h" // for timeval, gettimeofday
6767
#include "host.h"
6868
#include "messaging.h"
@@ -385,6 +385,28 @@ process_audio_message(struct module *root_module, const char *cmd)
385385
return new_response(RESPONSE_BAD_REQUEST, "unexpected audio msg");
386386
}
387387

388+
static struct response *
389+
handle_removed_feature(char *message)
390+
{
391+
char *space = strchr(message, ' ');
392+
if (space != nullptr) {
393+
*space = '\0';
394+
}
395+
char *msg = nullptr;
396+
int rc = asprintf(
397+
&msg, "%s has been removed. Let us know if you use this feature. ",
398+
message);
399+
if (rc != -1) {
400+
bug_msg(LOG_LEVEL_ERROR, "%s", msg);
401+
} else {
402+
perror("");
403+
msg = nullptr;
404+
}
405+
auto *resp = new_response(RESPONSE_BAD_REQUEST, msg);
406+
free(msg);
407+
return resp;
408+
}
409+
388410
/**
389411
* @retval -1 exit thread
390412
* @retval -2 close handle
@@ -532,15 +554,13 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s
532554
send_message(s->root_module, path_audio, (struct message *) msg_audio);
533555
free_response(resp_audio);
534556
} else if(prefix_matches(message, "receiver ") || prefix_matches(message, "play") ||
535-
prefix_matches(message, "pause") || prefix_matches(message, "reset-ssrc")) {
557+
prefix_matches(message, "pause")) {
536558
struct msg_sender *msg =
537559
(struct msg_sender *)
538560
new_message(sizeof(struct msg_sender));
539561
if(prefix_matches(message, "receiver ")) {
540562
strncpy(msg->receiver, suffix(message, "receiver "), sizeof(msg->receiver) - 1);
541563
msg->type = SENDER_MSG_CHANGE_RECEIVER;
542-
} else if(prefix_matches(message, "reset-ssrc")) {
543-
msg->type = SENDER_MSG_RESET_SSRC;
544564
} else {
545565
abort();
546566
}
@@ -561,11 +581,9 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s
561581
struct response *resp_audio =
562582
send_message(s->root_module, path_audio, (struct message *) msg_audio);
563583
free_response(resp_audio);
564-
} else if (prefix_matches(message, "receiver-port ")) {
565-
const char msg[] = "receiver-port has been removed. Let us "
566-
"know if you use this feature. ";
567-
bug_msg(LOG_LEVEL_ERROR, msg);
568-
resp = new_response(RESPONSE_BAD_REQUEST, msg);
584+
} else if (prefix_matches(message, "receiver-port ") ||
585+
prefix_matches(message, "reset-ssrc")) {
586+
resp = handle_removed_feature(message);
569587
} else if(prefix_matches(message, "fec ")) {
570588
auto *msg = reinterpret_cast<struct msg_universal *>(new_message(sizeof(struct msg_universal)));
571589
char *fec = suffix(message, "fec ");
@@ -1050,8 +1068,7 @@ static void print_control_help() {
10501068
TBOLD("\tpause") "\n"
10511069
TBOLD("\tplay") "\n"
10521070
TBOLD("\treciever {pause|play}") "\n"
1053-
TBOLD("\treset-ssrc") "\n"
1054-
TBOLD("\t{receiver|sender}-port <XY>") "\n"
1071+
TBOLD("\tsender-port <XY>") "\n"
10551072
TBOLD("\tfec {audio|video} <fec-string>") "\n"
10561073
TBOLD("\tcompress <new-compress>") "\n"
10571074
TBOLD("\tcompress param <new-compress-param>") "\n"

src/messaging.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ enum msg_sender_type {
9191
SENDER_MSG_MUTE_TOGGLE,
9292
SENDER_MSG_CHANGE_FEC,
9393
SENDER_MSG_QUERY_VIDEO_MODE,
94-
SENDER_MSG_RESET_SSRC,
9594
};
9695

9796
struct msg_sender {

src/utils/string.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
typedef SSIZE_T ssize_t;
5656
#endif
5757

58+
#include "compat/c23.h"
5859
#include "compat/strings.h"
5960
#include "utils/macros.h" // for MIN
6061
#include "utils/string.h"
@@ -296,3 +297,23 @@ sprintf_append(char *str, const char *format, ...)
296297

297298
return str;
298299
}
300+
301+
#ifdef _WIN32
302+
int
303+
asprintf(char **strp, const char *fmt, ...)
304+
{
305+
va_list ap;
306+
307+
va_start(ap, fmt);
308+
// get number of required bytes
309+
int size = vsnprintf(nullptr, 0, fmt, ap);
310+
va_end(ap);
311+
312+
*strp = malloc(size + 1);
313+
va_start(ap, fmt);
314+
(void) vsnprintf(*strp, size + 1, fmt, ap);
315+
va_end(ap);
316+
317+
return size;
318+
}
319+
#endif

src/video_rxtx/rtp.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,6 @@ rtp_process_sender_message(struct rtp_rxtx_common *s, struct msg_sender *msg)
178178
delete old_fec_state;
179179
MSG(NOTICE, "Fec changed successfully\n");
180180
} break;
181-
case SENDER_MSG_RESET_SSRC: {
182-
ultragrid::pthread_mutex_guard lock(s->network_devices_lock);
183-
const uint32_t old_ssrc = rtp_my_ssrc(s->network_device);
184-
auto *old_device = s->network_device;
185-
s->network_device = initialize_network(
186-
s->priv->requested_receiver, s->priv->rx_port,
187-
s->priv->tx_port, s->participants,
188-
s->priv->force_ip_version,
189-
s->priv->mcast_if, s->priv->ttl);
190-
if (s->network_device == nullptr) {
191-
s->network_device = old_device;
192-
MSG(ERROR, "Unable to change SSRC!\n");
193-
return new_response(RESPONSE_INT_SERV_ERR, nullptr);
194-
}
195-
destroy_rtp_device(old_device);
196-
MSG(NOTICE,
197-
"Changed SSRC from 0x%08" PRIx32 " to "
198-
"0x%08" PRIx32 ".\n",
199-
old_ssrc, rtp_my_ssrc(s->network_device));
200-
} break;
201181
case SENDER_MSG_GET_STATUS:
202182
case SENDER_MSG_MUTE:
203183
case SENDER_MSG_UNMUTE:

0 commit comments

Comments
 (0)