Skip to content

Commit 225fbc8

Browse files
committed
aplay/mixer: print participant add/rm
1 parent 110e656 commit 225fbc8

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/audio/playback/mixer.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@
6565
#include "transmit.h"
6666
#include "types.h" // for tx_media_type
6767
#include "utils/audio_buffer.h"
68+
#include "utils/macros.h" // for STR_LEN
69+
#include "utils/net.h" // for get_sockaddr_addr_str
6870
#include "utils/thread.h"
6971

72+
#define MOD_NAME "[audio mixer] "
73+
7074
#define SAMPLE_RATE 48000
7175
#define BPS 2 /// @todo 4?
7276
#define CHANNELS 1
@@ -122,7 +126,10 @@ static void mixer_dummy_rtp_callback(struct rtp *session [[gnu::unused]], rtp_ev
122126
}
123127

124128
struct am_participant {
125-
am_participant(struct socket_udp_local *l, struct sockaddr_storage *ss, string const & audio_codec) {
129+
am_participant(struct socket_udp_local *l, struct sockaddr_storage *ss,
130+
string const &audio_codec)
131+
: remote_addr(*ss)
132+
{
126133
assert(l != nullptr && ss != nullptr);
127134
m_buffer = audio_buffer_init(SAMPLE_RATE, BPS, CHANNELS, get_commandline_param("low-latency-audio") ? 50 : 5);
128135
assert(m_buffer != NULL);
@@ -140,6 +147,12 @@ struct am_participant {
140147
LOG(LOG_LEVEL_ERROR) << "Audio coder init failed!\n";
141148
throw 1;
142149
}
150+
151+
char buf[STR_LEN];
152+
MSG(NOTICE, "added participant: %s:%u\n",
153+
get_sockaddr_addr_str((struct sockaddr *) &ss, buf,
154+
sizeof buf),
155+
get_sockaddr_addr_port((struct sockaddr *) &ss));
143156
}
144157
~am_participant() {
145158
if (m_tx_session) {
@@ -154,6 +167,11 @@ struct am_participant {
154167
if (m_audio_coder) {
155168
audio_codec_done(m_audio_coder);
156169
}
170+
char buf[STR_LEN];
171+
MSG(NOTICE, "removed participant: %s:%u\n",
172+
get_sockaddr_addr_str((struct sockaddr *) &remote_addr, buf,
173+
sizeof buf),
174+
get_sockaddr_addr_port((struct sockaddr *) &remote_addr));
157175
}
158176
am_participant& operator=(am_participant&& other) {
159177
m_audio_coder = std::move(other.m_audio_coder);
@@ -170,6 +188,7 @@ struct am_participant {
170188
am_participant(am_participant && other) {
171189
*this = std::move(other);
172190
}
191+
struct sockaddr_storage remote_addr;
173192
struct audio_codec_state *m_audio_coder;
174193
struct audio_buffer *m_buffer;
175194
struct rtp *m_network_device;

src/utils/net.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,12 @@ unsigned get_sockaddr_addr_port(struct sockaddr *sa){
424424
return port;
425425
}
426426

427-
void get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n){
427+
/**
428+
* @returns the input buffer (buf)
429+
*/
430+
char *
431+
get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n)
432+
{
428433
assert(n >= IN6_MAX_ASCII_LEN + 3 /* []: */ + 1 /* \0 */);
429434
const void *src = NULL;
430435
if (sa->sa_family == AF_INET6) {
@@ -434,17 +439,18 @@ void get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n){
434439
src = &((struct sockaddr_in *)(void *) sa)->sin_addr;
435440
} else {
436441
snprintf(buf, n, "(unknown)");
437-
return;
442+
return buf;
438443
}
439444
if (inet_ntop(sa->sa_family, src, buf + strlen(buf), n - strlen(buf)) == NULL) {
440445
perror("get_sockaddr_str");
441446
snprintf(buf, n, "(error)");
442-
return;
447+
return buf;
443448
}
444449

445450
if (sa->sa_family == AF_INET6) {
446451
snprintf(buf + strlen(buf), n - strlen(buf), "]");
447452
}
453+
return buf;
448454
}
449455

450456
const char *get_sockaddr_str(struct sockaddr *sa)

src/utils/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool is_host_private(const char *hostname);
6666
uint16_t socket_get_recv_port(int fd);
6767
bool get_local_addresses(struct sockaddr_storage *addrs, size_t *len, int ip_version);
6868
bool is_ipv6_supported(void);
69-
void get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n);
69+
char *get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n);
7070
unsigned get_sockaddr_addr_port(struct sockaddr *sa);
7171
const char *get_sockaddr_str(struct sockaddr *sa);
7272
const char *ug_gai_strerror(int errcode);

0 commit comments

Comments
 (0)