Skip to content

Commit

Permalink
aplay/mixer: print participant add/rm
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Nov 13, 2024
1 parent 110e656 commit 225fbc8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
21 changes: 20 additions & 1 deletion src/audio/playback/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/utils/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 225fbc8

Please sign in to comment.