]> code.delx.au - pulseaudio/blobdiff - src/utils/pactl.c
bump API and protocol version. Return PA_ERR_NOTSUPPORTED if pa_context_move_sink_inp...
[pulseaudio] / src / utils / pactl.c
index fcc677d9cd0b56ac1320743130e790c19fe6a5f9..0fde33eb5f67c1257087ee5f35314647bccdd6a0 100644 (file)
@@ -1,20 +1,20 @@
 /* $Id$ */
 
 /***
-  This file is part of polypaudio.
+  This file is part of PulseAudio.
  
-  polypaudio is free software; you can redistribute it and/or modify
+  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.
 ***/
 
 #include <sndfile.h>
 
-#include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
+#include <pulse/pulseaudio.h>
 
-#if PA_API_VERSION != 8
-#error Invalid Polypaudio API version
+#if PA_API_VERSION < 10
+#error Invalid PulseAudio API version
 #endif
 
 #define BUFSIZE 1024
@@ -48,7 +46,8 @@
 static pa_context *context = NULL;
 static pa_mainloop_api *mainloop_api = NULL;
 
-static char *device = NULL, *sample_name = NULL;
+static char *device = NULL, *sample_name = NULL, *sink_name = NULL;
+static uint32_t sink_input_idx = PA_INVALID_INDEX;
 
 static SNDFILE *sndfile = NULL;
 static pa_stream *sample_stream = NULL;
@@ -66,7 +65,8 @@ static enum {
     UPLOAD_SAMPLE,
     PLAY_SAMPLE,
     REMOVE_SAMPLE,
-    LIST
+    LIST,
+    MOVE_SINK_INPUT
 } action = NONE;
 
 static void quit(int ret) {
@@ -176,7 +176,7 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
            "Volume: %s\n"
            "Monitor Source: %u\n"
            "Latency: %0.0f usec\n"
-           "Flags: %s%s\n",
+           "Flags: %s%s%s\n",
            i->index,
            i->name,
            i->driver,
@@ -188,7 +188,8 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
            i->monitor_source,
            (double) i->latency,
            i->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
-           i->flags & PA_SINK_LATENCY ? "LATENCY" : "");
+           i->flags & PA_SINK_LATENCY ? "LATENCY " : "",
+           i->flags & PA_SINK_HARDWARE ? "HARDWARE" : "");
 
 }
 
@@ -224,7 +225,7 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
            "Volume: %s\n"
            "Monitor of Sink: %s\n"
            "Latency: %0.0f usec\n"
-           "Flags: %s%s\n",
+           "Flags: %s%s%s\n",
            i->index,
            i->driver,
            i->name,
@@ -236,7 +237,8 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
            i->monitor_of_sink != PA_INVALID_INDEX ? t : "no",
            (double) i->latency,
            i->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
-           i->flags & PA_SOURCE_LATENCY ? "LATENCY" : "");
+           i->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
+           i->flags & PA_SOURCE_HARDWARE ? "HARDWARE" : "");
 
 }
 
@@ -511,19 +513,18 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
     float *d;
     assert(s && length && sndfile);
 
-    d = malloc(length);
-    assert(d);
+    d = pa_xmalloc(length);
 
     assert(sample_length >= length);
     l = length/pa_frame_size(&sample_spec);
 
     if ((sf_readf_float(sndfile, d, l)) != l) {
-        free(d);
+        pa_xfree(d);
         fprintf(stderr, "Premature end of file\n");
         quit(1);
     }
     
-    pa_stream_write(s, d, length, free, 0, PA_SEEK_RELATIVE);
+    pa_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE);
 
     sample_length -= length;
 
@@ -582,6 +583,10 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     pa_operation_unref(pa_context_get_autoload_info_list(c, get_autoload_info_callback, NULL));
                     break;
 
+                case MOVE_SINK_INPUT:
+                    pa_operation_unref(pa_context_move_sink_input_by_name(c, sink_input_idx, sink_name, simple_callback, NULL));
+                    break;
+
                 default:
                     assert(0);
             }
@@ -610,12 +615,13 @@ static void help(const char *argv0) {
            "%s [options] exit\n"
            "%s [options] upload-sample FILENAME [NAME]\n"
            "%s [options] play-sample NAME [SINK]\n"
+           "%s [options] move-sink-input NAME [SINK]\n"
            "%s [options] remove-sample NAME\n\n"
            "  -h, --help                            Show this help\n"
            "      --version                         Show version\n\n"
            "  -s, --server=SERVER                   The name of the server to connect to\n"
            "  -n, --client-name=NAME                How to call this client on the server\n",
-           argv0, argv0, argv0, argv0, argv0, argv0);
+           argv0, argv0, argv0, argv0, argv0, argv0, argv0);
 }
 
 enum { ARG_VERSION = 256 };
@@ -647,18 +653,18 @@ int main(int argc, char *argv[]) {
                 goto quit;
                 
             case ARG_VERSION:
-                printf("pactl "PACKAGE_VERSION"\nCompiled with libpolyp %s\nLinked with libpolyp %s\n", pa_get_headers_version(), pa_get_library_version());
+                printf("pactl "PACKAGE_VERSION"\nCompiled with libpulse %s\nLinked with libpulse %s\n", pa_get_headers_version(), pa_get_library_version());
                 ret = 0;
                 goto quit;
 
             case 's':
-                free(server);
-                server = strdup(optarg);
+                pa_xfree(server);
+                server = pa_xstrdup(optarg);
                 break;
 
             case 'n':
-                free(client_name);
-                client_name = strdup(optarg);
+                pa_xfree(client_name);
+                client_name = pa_xstrdup(optarg);
                 break;
 
             default:
@@ -667,7 +673,7 @@ int main(int argc, char *argv[]) {
     }
 
     if (!client_name)
-        client_name = strdup(bn);
+        client_name = pa_xstrdup(bn);
     
     if (optind < argc) {
         if (!strcmp(argv[optind], "stat"))
@@ -686,7 +692,7 @@ int main(int argc, char *argv[]) {
             }
 
             if (optind+2 < argc)
-                sample_name = strdup(argv[optind+2]);
+                sample_name = pa_xstrdup(argv[optind+2]);
             else {
                 char *f = strrchr(argv[optind+1], '/');
                 size_t n;
@@ -698,7 +704,7 @@ int main(int argc, char *argv[]) {
                 n = strcspn(f, ".");
                 strncpy(tmp, f, n);
                 tmp[n] = 0;
-                sample_name = strdup(tmp);
+                sample_name = pa_xstrdup(tmp);
             }
             
             memset(&sfinfo, 0, sizeof(sfinfo));
@@ -719,10 +725,10 @@ int main(int argc, char *argv[]) {
                 goto quit;
             }
 
-            sample_name = strdup(argv[optind+1]);
+            sample_name = pa_xstrdup(argv[optind+1]);
 
             if (optind+2 < argc)
-                device = strdup(argv[optind+2]);
+                device = pa_xstrdup(argv[optind+2]);
             
         } else if (!strcmp(argv[optind], "remove-sample")) {
             action = REMOVE_SAMPLE;
@@ -731,7 +737,16 @@ int main(int argc, char *argv[]) {
                 goto quit;
             }
 
-            sample_name = strdup(argv[optind+1]);
+            sample_name = pa_xstrdup(argv[optind+1]);
+        } else if (!strcmp(argv[optind], "move-sink-input")) {
+            action = MOVE_SINK_INPUT;
+            if (optind+2 >= argc) {
+                fprintf(stderr, "You have to specify a sink input index and a sink\n");
+                goto quit;
+            }
+
+            sink_input_idx = atoi(argv[optind+1]);
+            sink_name = pa_xstrdup(argv[optind+2]);
         }
     }
 
@@ -782,9 +797,10 @@ quit:
     if (sndfile)
         sf_close(sndfile);
 
-    free(server);
-    free(device);
-    free(sample_name);
+    pa_xfree(server);
+    pa_xfree(device);
+    pa_xfree(sample_name);
+    pa_xfree(sink_name);
 
     return ret;
 }