chiark / gitweb /
debug dump (mac only) for playrtp
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 8 Dec 2007 15:55:01 +0000 (15:55 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 8 Dec 2007 15:55:01 +0000 (15:55 +0000)
clients/Makefile.am
clients/dump2wav [new file with mode: 0755]
clients/playrtp-coreaudio.c
clients/playrtp.c
clients/playrtp.h

index 72a77396891e15671e5307bac4657f7e58dc0388..f767025da9e7118c5c3c77c2b9aa34e9f3ae39cc 100644 (file)
@@ -20,6 +20,7 @@
 
 bin_PROGRAMS=disorder disorderfm disorder-playrtp
 noinst_PROGRAMS=test-eclient filename-bytes
+noinst_SCRIPTS=dump2wav
 
 AM_CPPFLAGS=-I${top_srcdir}/lib -I../lib
 
diff --git a/clients/dump2wav b/clients/dump2wav
new file mode 100755 (executable)
index 0000000..aec1056
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/bash
+#
+# Usage: dump2wav DUMPFILE [sox format options] OUTPUT
+#
+exec sox -r 44100 -s -w -c 2 "$@"
index a22c8af8c24c0ccaabd53bd242fc3e8ff1473290..689cdbd1a60cc456e9a6ff21569a7ec5b0b7a24f 100644 (file)
@@ -67,6 +67,14 @@ static OSStatus adioproc
           samples_available = samplesOutLeft;
         next_timestamp += samples_available;
         samplesOutLeft -= samples_available;
+        if(dump_buffer) {
+          size_t n;
+
+          for(n = 0; n < samples_available; ++n) {
+            dump_buffer[dump_index++] = (int16_t)ntohs(ptr[n]);
+            dump_index %= dump_size;
+          }
+        }
         while(samples_available-- > 0)
           *samplesOut++ = (int16_t)ntohs(*ptr++) * (0.5 / 32767);
         /* We don't bother junking the packet - that'll be dealt with next time
index 9757be6566d6835da080646181a0799e6a72a369..1263d7a012cc000085cb359a63a9d8ad20fae205 100644 (file)
@@ -69,6 +69,8 @@
 #include <sys/time.h>
 #include <sys/un.h>
 #include <unistd.h>
+#include <sys/mman.h>
+#include <fcntl.h>
 
 #include "log.h"
 #include "mem.h"
@@ -190,6 +192,10 @@ HEAP_DEFINE(pheap, struct packet *, lt_packet);
 /** @brief Control socket or NULL */
 const char *control_socket;
 
+int16_t *dump_buffer;
+size_t dump_index;
+size_t dump_size = 44100 * 2 * 20; /* 20s */
+
 static const struct option options[] = {
   { "help", no_argument, 0, 'h' },
   { "version", no_argument, 0, 'V' },
@@ -208,6 +214,7 @@ static const struct option options[] = {
 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
   { "core-audio", no_argument, 0, 'c' },
 #endif
+  { "dump", required_argument, 0, 'r' },
   { "socket", required_argument, 0, 's' },
   { "config", required_argument, 0, 'C' },
   { 0, 0, 0, 0 }
@@ -532,6 +539,7 @@ int main(int argc, char **argv) {
     struct sockaddr_in6 in6;
   };
   union any_sockaddr mgroup;
+  const char *dumpfile = 0;
 
   static const struct addrinfo prefs = {
     AI_PASSIVE,
@@ -546,7 +554,7 @@ int main(int argc, char **argv) {
 
   mem_init();
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVdD:m:b:x:L:R:M:aocC:", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVdD:m:b:x:L:R:M:aocC:r", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
@@ -568,6 +576,7 @@ int main(int argc, char **argv) {
 #endif
     case 'C': configfile = optarg; break;
     case 's': control_socket = optarg; break;
+    case 'r': dumpfile = optarg; break;
     default: fatal(0, "invalid option");
     }
   }
@@ -676,6 +685,27 @@ int main(int argc, char **argv) {
     if((err = pthread_create(&tid, 0, control_thread, 0)))
       fatal(err, "pthread_create control_thread");
   }
+  if(dumpfile) {
+    int fd;
+    unsigned char buffer[65536];
+    size_t written;
+
+    if((fd = open(dumpfile, O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0)
+      fatal(errno, "opening %s", dumpfile);
+    /* Fill with 0s to a suitable size */
+    memset(buffer, 0, sizeof buffer);
+    for(written = 0; written < dump_size * sizeof(int16_t);
+        written += sizeof buffer) {
+      if(write(fd, buffer, sizeof buffer) < 0)
+        fatal(errno, "clearing %s", dumpfile);
+    }
+    /* Map the buffer into memory for convenience */
+    dump_buffer = mmap(0, dump_size * sizeof(int16_t), PROT_READ|PROT_WRITE,
+                       MAP_SHARED, fd, 0);
+    if(dump_buffer == (void *)-1)
+      fatal(errno, "mapping %s", dumpfile);
+    info("dumping to %s", dumpfile);
+  }
   play_rtp();
   return 0;
 }
index dd9fa5de4222705c5649c950ccd7a41e9135275a..565ca0b7d87bb5360c65a00c1cffc4ccc9dc983a 100644 (file)
@@ -144,6 +144,10 @@ extern pthread_mutex_t lock;
 extern pthread_cond_t cond;
 extern unsigned minbuffer;
 
+extern int16_t *dump_buffer;
+extern size_t dump_index;
+extern size_t dump_size;
+
 void playrtp_oss(void), playrtp_alsa(void), playrtp_coreaudio(void);
 
 #endif /* PLAYRTP_H */