]> code.delx.au - pulseaudio/blobdiff - src/tests/sync-playback.c
use (uint32_t) -1 to signify default buffer_attr values instead of 0, to allow prebuf=0
[pulseaudio] / src / tests / sync-playback.c
index 5df790c9acfe95796b0319b770fb4f920007e5a8..7e364685825173269f5a96542964f35ebef7549c 100644 (file)
@@ -1,20 +1,18 @@
-/* $Id$ */
-
 /***
-  This file is part of polypaudio.
-  polypaudio is free software; you can redistribute it and/or modify
+  This file is part of PulseAudio.
+
+  PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
-  polypaudio is distributed in the hope that it will be useful, but
+
+  PulseAudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
+
   You should have received a copy of the GNU Lesser General Public License
-  along with polypaudio; if not, write to the Free Software
+  along with PulseAudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
@@ -33,8 +31,8 @@
 #include <getopt.h>
 #include <math.h>
 
-#include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
+#include <pulse/pulseaudio.h>
+#include <pulse/mainloop.h>
 
 #define NSTREAMS 4
 #define SINE_HZ 440
@@ -56,18 +54,19 @@ static const pa_sample_spec sample_spec = {
 
 static const pa_buffer_attr buffer_attr = {
     .maxlength = SAMPLE_HZ*sizeof(float)*NSTREAMS, /* exactly space for the entire play time */
-    .tlength = 0,
+    .tlength = (uint32_t) -1,
     .prebuf = 0, /* Setting prebuf to 0 guarantees us the the streams will run synchronously, no matter what */
-    .minreq = 0
+    .minreq = (uint32_t) -1,
+    .fragsize = 0
 };
 
 static void nop_free_cb(void *p) {}
 
 static void underflow_cb(struct pa_stream *s, void *userdata) {
-    int i = (int) userdata;
+    int i = (int) (long) userdata;
 
     fprintf(stderr, "Stream %i finished\n", i);
-    
+
     if (++n_streams_ready >= 2*NSTREAMS) {
         fprintf(stderr, "We're done\n");
         mainloop_api->quit(mainloop_api, 0);
@@ -86,22 +85,22 @@ static void stream_state_callback(pa_stream *s, void *userdata) {
 
         case PA_STREAM_READY: {
 
-            int r, i = (int) userdata;
+            int r, i = (int) (long) userdata;
 
             fprintf(stderr, "Writing data to stream %i.\n", i);
-            
+
             r = pa_stream_write(s, data, sizeof(data), nop_free_cb, sizeof(data) * i, PA_SEEK_ABSOLUTE);
             assert(r == 0);
 
             /* Be notified when this stream is drained */
             pa_stream_set_underflow_callback(s, underflow_cb, userdata);
-            
+
             /* All streams have been set up, let's go! */
             if (++n_streams_ready >= NSTREAMS) {
                 fprintf(stderr, "Uncorking\n");
                 pa_operation_unref(pa_stream_cork(s, 0, NULL, NULL));
             }
-           
+
             break;
         }
 
@@ -121,7 +120,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
         case PA_CONTEXT_AUTHORIZING:
         case PA_CONTEXT_SETTING_NAME:
             break;
-        
+
         case PA_CONTEXT_READY: {
 
             int i;
@@ -131,18 +130,18 @@ static void context_state_callback(pa_context *c, void *userdata) {
                 char name[64];
 
                 fprintf(stderr, "Creating stream %i\n", i);
-                
+
                 snprintf(name, sizeof(name), "stream #%i", i);
-            
+
                 streams[i] = pa_stream_new(c, name, &sample_spec, NULL);
                 assert(streams[i]);
-                pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) i);
+                pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) (long) i);
                 pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]);
             }
-                
+
             break;
         }
-            
+
         case PA_CONTEXT_TERMINATED:
             mainloop_api->quit(mainloop_api, 0);
             break;
@@ -163,7 +162,7 @@ int main(int argc, char *argv[]) {
 
     for (i = 0; i < NSTREAMS; i++)
         streams[i] = NULL;
-    
+
     /* Set up a new main loop */
     m = pa_mainloop_new();
     assert(m);
@@ -175,7 +174,7 @@ int main(int argc, char *argv[]) {
 
     pa_context_set_state_callback(context, context_state_callback, NULL);
 
-    pa_context_connect(context, NULL, 1, NULL);
+    pa_context_connect(context, NULL, 0, NULL);
 
     if (pa_mainloop_run(m, &ret) < 0)
         fprintf(stderr, "pa_mainloop_run() failed.\n");
@@ -187,6 +186,6 @@ int main(int argc, char *argv[]) {
             pa_stream_unref(streams[i]);
 
     pa_mainloop_free(m);
-    
+
     return ret;
 }