From 87864f772bd033fa5e405b9ced6f8ca46d4fb388 Mon Sep 17 00:00:00 2001 Message-Id: <87864f772bd033fa5e405b9ced6f8ca46d4fb388.1715314575.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 12 Feb 2011 17:35:43 +0000 Subject: [PATCH] Add (undocumented) rtp_verbose option, to generate once-a-minute metadata logging from the RTP transmission subsystem. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/configuration.c | 1 + lib/configuration.h | 3 +++ lib/uaudio-rtp.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/lib/configuration.c b/lib/configuration.c index 53fddd5..932c54b 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -1106,6 +1106,7 @@ static const struct conf conf[] = { { C(replay_min), &type_integer, validate_non_negative }, { C2(restrict, restrictions), &type_restrict, validate_any }, { C(rtp_delay_threshold), &type_integer, validate_positive }, + { C(rtp_verbose), &type_boolean, validate_any }, { C(sample_format), &type_sample_format, validate_sample_format }, { C(scratch), &type_string_accum, validate_isreg }, { C(sendmail), &type_string, validate_isabspath }, diff --git a/lib/configuration.h b/lib/configuration.h index 8255db2..6e3a9a9 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -251,6 +251,9 @@ struct config { /** @brief RTP delay threshold */ long rtp_delay_threshold; + + /** @brief Verbose RTP transmission logging */ + int rtp_verbose; /** @brief TTL for multicast packets */ long multicast_ttl; diff --git a/lib/uaudio-rtp.c b/lib/uaudio-rtp.c index c8e2ef2..3ce1cbe 100644 --- a/lib/uaudio-rtp.c +++ b/lib/uaudio-rtp.c @@ -164,6 +164,20 @@ static size_t rtp_play(void *buffer, size_t nsamples, unsigned flags) { vec[1].iov_len = nsamples * uaudio_sample_size; const uint32_t timestamp = uaudio_schedule_sync(); header.timestamp = htonl(rtp_base + (uint32_t)timestamp); + + /* We send ~120 packets a second with current arrangements. So if we log + * once every 8192 packets we log about once a minute. */ + + if(!(ntohs(header.seq) & 8191) + && config->rtp_verbose) + disorder_info("RTP: seq %04"PRIx16" %08"PRIx32"+%08"PRIx32"=%08"PRIx32" ns %zu%s", + ntohs(header.seq), + rtp_base, + timestamp, + header.timestamp, + nsamples, + flags & UAUDIO_PAUSED ? " [paused]" : ""); + /* If we're paused don't actually end a packet, we just pretend */ if(flags & UAUDIO_PAUSED) { uaudio_schedule_sent(nsamples); @@ -293,6 +307,8 @@ static void rtp_open(void) { if(connect(rtp_fd, res->ai_addr, res->ai_addrlen) < 0) disorder_fatal(errno, "error connecting broadcast socket to %s", format_sockaddr(res->ai_addr)); + if(config->rtp_verbose) + disorder_info("RTP: prepared socket"); } static void rtp_start(uaudio_callback *callback, @@ -309,14 +325,22 @@ static void rtp_start(uaudio_callback *callback, else disorder_fatal(0, "asked for %d/%d/%d 16/44100/1 and 16/44100/2", uaudio_bits, uaudio_rate, uaudio_channels); + if(config->rtp_verbose) + disorder_info("RTP: %d channels %d bits %d Hz payload type %d", + uaudio_channels, uaudio_bits, uaudio_rate, rtp_payload); /* Various fields are required to have random initial values by RFC3550. The * packet contents are highly public so there's no point asking for very * strong randomness. */ gcry_create_nonce(&rtp_id, sizeof rtp_id); gcry_create_nonce(&rtp_base, sizeof rtp_base); gcry_create_nonce(&rtp_sequence, sizeof rtp_sequence); + if(config->rtp_verbose) + disorder_info("RTP: id %08"PRIx32" base %08"PRIx32" initial seq %08"PRIx16, + rtp_id, rtp_base, rtp_sequence); rtp_open(); uaudio_schedule_init(); + if(config->rtp_verbose) + disorder_info("RTP: initialized schedule"); uaudio_thread_start(callback, userdata, rtp_play, @@ -324,6 +348,8 @@ static void rtp_start(uaudio_callback *callback, (NETWORK_BYTES - sizeof(struct rtp_header)) / uaudio_sample_size, 0); + if(config->rtp_verbose) + disorder_info("RTP: created thread"); } static void rtp_stop(void) { @@ -344,6 +370,8 @@ static void rtp_configure(void) { snprintf(buffer, sizeof buffer, "%ld", config->multicast_ttl); uaudio_set("multicast-ttl", buffer); uaudio_set("multicast-loop", config->multicast_loop ? "yes" : "no"); + if(config->rtp_verbose) + disorder_info("RTP: configured"); } const struct uaudio uaudio_rtp = { -- [mdw]