From: Richard Kettlewell Date: Sun, 9 Dec 2007 14:32:08 +0000 (+0000) Subject: playrtp: --dump support for ALSA and OSS backends X-Git-Tag: 1.5.99+dev10~9 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/b28bddbb2d2b2f07364153df3b980605d9caa9d9 playrtp: --dump support for ALSA and OSS backends --- diff --git a/clients/playrtp-alsa.c b/clients/playrtp-alsa.c index 263ab40..142f1ee 100644 --- a/clients/playrtp-alsa.c +++ b/clients/playrtp-alsa.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "mem.h" #include "log.h" @@ -141,6 +142,15 @@ static int playrtp_alsa_writei(const void *s, size_t n) { } else { /* Success */ next_timestamp += frames_written * 2; + if(dump_buffer) { + snd_pcm_sframes_t count; + const int16_t *sp = s; + + for(count = 0; count < frames_written * 2; ++count) { + dump_buffer[dump_index++] = (int16_t)ntohs(*sp++); + dump_index %= dump_size; + } + } return 0; } } diff --git a/clients/playrtp-oss.c b/clients/playrtp-oss.c index 7281e15..b40947d 100644 --- a/clients/playrtp-oss.c +++ b/clients/playrtp-oss.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "mem.h" #include "log.h" @@ -138,6 +139,15 @@ static int playrtp_oss_flush(void) { if(nbyteswritten < playrtp_oss_bufsize) error(0, "%s: short write (%d/%d)", device, nbyteswritten, playrtp_oss_bufsize); + if(dump_buffer) { + int count; + const int16_t *sp = (const int16_t *)playrtp_oss_buffer; + + for(count = 0; count < playrtp_oss_bufsize; count += sizeof(int16_t)) { + dump_buffer[dump_index++] = (int16_t)ntohs(*sp++); + dump_index %= dump_size; + } + } playrtp_oss_bufused = 0; return 0; } diff --git a/clients/playrtp.c b/clients/playrtp.c index 1263d7a..54107da 100644 --- a/clients/playrtp.c +++ b/clients/playrtp.c @@ -192,9 +192,26 @@ HEAP_DEFINE(pheap, struct packet *, lt_packet); /** @brief Control socket or NULL */ const char *control_socket; +/** @brief Buffer for debugging dump + * + * The debug dump is enabled by the @c --dump option. It records the last 20s + * of audio to the specified file (which will be about 3.5Mbytes). The file is + * written as as ring buffer, so the start point will progress through it. + * + * Use clients/dump2wav to convert this to a WAV file, which can then be loaded + * into (e.g.) Audacity for further inspection. + * + * All three backends (ALSA, OSS, Core Audio) now support this option. + * + * The idea is to allow the user a few seconds to react to an audible artefact. + */ int16_t *dump_buffer; + +/** @brief Current index within debugging dump */ size_t dump_index; -size_t dump_size = 44100 * 2 * 20; /* 20s */ + +/** @brief Size of debugging dump in samples */ +size_t dump_size = 44100/*Hz*/ * 2/*channels*/ * 20/*seconds*/; static const struct option options[] = { { "help", no_argument, 0, 'h' },