From 225fbc8ea1c1f21fc60e487e2d41623fb7b59017 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 13 Nov 2024 14:39:38 +0100 Subject: [PATCH] aplay/mixer: print participant add/rm --- src/audio/playback/mixer.cpp | 21 ++++++++++++++++++++- src/utils/net.c | 12 +++++++++--- src/utils/net.h | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/audio/playback/mixer.cpp b/src/audio/playback/mixer.cpp index 2d7addf8d..3c38f1838 100644 --- a/src/audio/playback/mixer.cpp +++ b/src/audio/playback/mixer.cpp @@ -65,8 +65,12 @@ #include "transmit.h" #include "types.h" // for tx_media_type #include "utils/audio_buffer.h" +#include "utils/macros.h" // for STR_LEN +#include "utils/net.h" // for get_sockaddr_addr_str #include "utils/thread.h" +#define MOD_NAME "[audio mixer] " + #define SAMPLE_RATE 48000 #define BPS 2 /// @todo 4? #define CHANNELS 1 @@ -122,7 +126,10 @@ static void mixer_dummy_rtp_callback(struct rtp *session [[gnu::unused]], rtp_ev } struct am_participant { - am_participant(struct socket_udp_local *l, struct sockaddr_storage *ss, string const & audio_codec) { + am_participant(struct socket_udp_local *l, struct sockaddr_storage *ss, + string const &audio_codec) + : remote_addr(*ss) + { assert(l != nullptr && ss != nullptr); m_buffer = audio_buffer_init(SAMPLE_RATE, BPS, CHANNELS, get_commandline_param("low-latency-audio") ? 50 : 5); assert(m_buffer != NULL); @@ -140,6 +147,12 @@ struct am_participant { LOG(LOG_LEVEL_ERROR) << "Audio coder init failed!\n"; throw 1; } + + char buf[STR_LEN]; + MSG(NOTICE, "added participant: %s:%u\n", + get_sockaddr_addr_str((struct sockaddr *) &ss, buf, + sizeof buf), + get_sockaddr_addr_port((struct sockaddr *) &ss)); } ~am_participant() { if (m_tx_session) { @@ -154,6 +167,11 @@ struct am_participant { if (m_audio_coder) { audio_codec_done(m_audio_coder); } + char buf[STR_LEN]; + MSG(NOTICE, "removed participant: %s:%u\n", + get_sockaddr_addr_str((struct sockaddr *) &remote_addr, buf, + sizeof buf), + get_sockaddr_addr_port((struct sockaddr *) &remote_addr)); } am_participant& operator=(am_participant&& other) { m_audio_coder = std::move(other.m_audio_coder); @@ -170,6 +188,7 @@ struct am_participant { am_participant(am_participant && other) { *this = std::move(other); } + struct sockaddr_storage remote_addr; struct audio_codec_state *m_audio_coder; struct audio_buffer *m_buffer; struct rtp *m_network_device; diff --git a/src/utils/net.c b/src/utils/net.c index f5d3117df..e9e23497d 100644 --- a/src/utils/net.c +++ b/src/utils/net.c @@ -424,7 +424,12 @@ unsigned get_sockaddr_addr_port(struct sockaddr *sa){ return port; } -void get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n){ +/** + * @returns the input buffer (buf) + */ +char * +get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n) +{ assert(n >= IN6_MAX_ASCII_LEN + 3 /* []: */ + 1 /* \0 */); const void *src = NULL; if (sa->sa_family == AF_INET6) { @@ -434,17 +439,18 @@ void get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n){ src = &((struct sockaddr_in *)(void *) sa)->sin_addr; } else { snprintf(buf, n, "(unknown)"); - return; + return buf; } if (inet_ntop(sa->sa_family, src, buf + strlen(buf), n - strlen(buf)) == NULL) { perror("get_sockaddr_str"); snprintf(buf, n, "(error)"); - return; + return buf; } if (sa->sa_family == AF_INET6) { snprintf(buf + strlen(buf), n - strlen(buf), "]"); } + return buf; } const char *get_sockaddr_str(struct sockaddr *sa) diff --git a/src/utils/net.h b/src/utils/net.h index dffe59822..0a951d9b6 100644 --- a/src/utils/net.h +++ b/src/utils/net.h @@ -66,7 +66,7 @@ bool is_host_private(const char *hostname); uint16_t socket_get_recv_port(int fd); bool get_local_addresses(struct sockaddr_storage *addrs, size_t *len, int ip_version); bool is_ipv6_supported(void); -void get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n); +char *get_sockaddr_addr_str(struct sockaddr *sa, char *buf, size_t n); unsigned get_sockaddr_addr_port(struct sockaddr *sa); const char *get_sockaddr_str(struct sockaddr *sa); const char *ug_gai_strerror(int errcode);