[polypaudio-commits] r687 - /trunk/src/utils/pacat.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Apr 12 10:18:24 PDT 2006


Author: lennart
Date: Wed Apr 12 19:18:24 2006
New Revision: 687

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=687&root=polypaudio&view=rev
Log:
beefup pacat a little: 
* when -v is passed, show current playback time and latency
* modify SIGUSR1 behaviour to show only playback time and latency

Modified:
    trunk/src/utils/pacat.c

Modified: trunk/src/utils/pacat.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/pacat.c?rev=687&root=polypaudio&r1=686&r2=687&view=diff
==============================================================================
--- trunk/src/utils/pacat.c (original)
+++ trunk/src/utils/pacat.c Wed Apr 12 19:18:24 2006
@@ -36,6 +36,9 @@
 #include <polyp/polypaudio.h>
 #include <polyp/mainloop.h>
 #include <polyp/mainloop-signal.h>
+#include <polypcore/util.h>
+
+#define TIME_EVENT_USEC 50000
 
 #if PA_API_VERSION != 8
 #error Invalid Polypaudio API version
@@ -153,7 +156,7 @@
 
         case PA_STREAM_READY:
             if (verbose)
-                fprintf(stderr, "Stream successfully created\n");
+                fprintf(stderr, "Stream successfully created.\n");
             break;
             
         case PA_STREAM_FAILED:
@@ -341,34 +344,46 @@
 
 /* Show the current latency */
 static void stream_update_timing_callback(pa_stream *s, int success, void *userdata) {
-    pa_usec_t total;
+    pa_usec_t latency, usec;
     int negative = 0;
-    const pa_timing_info *i;
     
     assert(s);
 
     if (!success ||
-        !(i = pa_stream_get_timing_info(s)) ||
-        pa_stream_get_latency(s, &total, &negative) < 0) {
+        pa_stream_get_time(s, &usec) < 0 ||
+        pa_stream_get_latency(s, &latency, &negative) < 0) {
         fprintf(stderr, "Failed to get latency: %s\n", pa_strerror(pa_context_errno(context)));
         quit(1);
         return;
     }
 
-    fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
-            (float) i->buffer_usec,
-            (float) i->sink_usec,
-            (float) i->source_usec,
-            (float) i->transport_usec,
-            (float) total * (negative?-1:1),
-            i->synchronized_clocks ? "yes" : "no");
+    fprintf(stderr, "Time: %0.3f sec; Latency: %0.0f usec.  \r",
+            (float) usec / 1000000,
+            (float) latency * (negative?-1:1));
 }
 
 /* Someone requested that the latency is shown */
 static void sigusr1_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
+
+    if (!stream)
+        return;
+    
     pa_operation_unref(pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL));
 }
 
+static void time_event_callback(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
+    struct timeval next;
+    
+    if (!stream)
+        return;
+    
+    pa_operation_unref(pa_stream_update_timing_info(stream, stream_update_timing_callback, NULL));
+
+    pa_gettimeofday(&next);
+    pa_timeval_add(&next, TIME_EVENT_USEC);
+
+    m->time_restart(e, &next);
+}
 
 static void help(const char *argv0) {
 
@@ -404,6 +419,7 @@
     pa_mainloop* m = NULL;
     int ret = 1, r, c;
     char *bn, *server = NULL;
+    pa_time_event *time_event = NULL;
 
     static const struct option long_options[] = {
         {"record",      0, NULL, 'r'},
@@ -561,7 +577,7 @@
                                              mode == PLAYBACK ? STDIN_FILENO : STDOUT_FILENO,
                                              mode == PLAYBACK ? PA_IO_EVENT_INPUT : PA_IO_EVENT_OUTPUT,
                                              mode == PLAYBACK ? stdin_callback : stdout_callback, NULL))) {
-        fprintf(stderr, "source_io() failed.\n");
+        fprintf(stderr, "io_new() failed.\n");
         goto quit;
     }
 
@@ -576,6 +592,18 @@
     /* Connect the context */
     pa_context_connect(context, server, 0, NULL);
 
+    if (verbose) {
+        struct timeval tv;
+
+        pa_gettimeofday(&tv);
+        pa_timeval_add(&tv, TIME_EVENT_USEC);
+        
+        if (!(time_event = mainloop_api->time_new(mainloop_api, &tv, time_event_callback, NULL))) {
+            fprintf(stderr, "time_new() failed.\n");
+            goto quit;
+        }
+    }
+
     /* Run the main loop */
     if (pa_mainloop_run(m, &ret) < 0) {
         fprintf(stderr, "pa_mainloop_run() failed.\n");
@@ -593,6 +621,11 @@
         assert(mainloop_api);
         mainloop_api->io_free(stdio_event);
     }
+
+    if (time_event) {
+        assert(mainloop_api);
+        mainloop_api->time_free(time_event);
+    }
     
     if (m) {
         pa_signal_done();




More information about the pulseaudio-commits mailing list