]> 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 7d903eb8feb3b6351d4046b74d13f56cf3093ba4..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/polyplib.h>
-#include <polyp/error.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
-#include <polyp/sample.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
@@ -50,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;
@@ -68,7 +65,8 @@ static enum {
     UPLOAD_SAMPLE,
     PLAY_SAMPLE,
     REMOVE_SAMPLE,
-    LIST
+    LIST,
+    MOVE_SINK_INPUT
 } action = NONE;
 
 static void quit(int ret) {
@@ -177,7 +175,8 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
            "Owner Module: %u\n"
            "Volume: %s\n"
            "Monitor Source: %u\n"
-           "Latency: %0.0f usec\n",
+           "Latency: %0.0f usec\n"
+           "Flags: %s%s%s\n",
            i->index,
            i->name,
            i->driver,
@@ -185,14 +184,17 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
            pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
            pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
            i->owner_module,
-           pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
+           i->mute ? "muted" : pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
            i->monitor_source,
-           (double) i->latency);
+           (double) i->latency,
+           i->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
+           i->flags & PA_SINK_LATENCY ? "LATENCY " : "",
+           i->flags & PA_SINK_HARDWARE ? "HARDWARE" : "");
 
 }
 
 static void get_source_info_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
-    char s[PA_SAMPLE_SPEC_SNPRINT_MAX], t[32], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+    char s[PA_SAMPLE_SPEC_SNPRINT_MAX], t[32], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
 
     if (is_last < 0) {
         fprintf(stderr, "Failed to get source information: %s\n", pa_strerror(pa_context_errno(c)));
@@ -220,8 +222,10 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
            "Sample Specification: %s\n"
            "Channel Map: %s\n"
            "Owner Module: %u\n"
+           "Volume: %s\n"
            "Monitor of Sink: %s\n"
-           "Latency: %0.0f usec\n",
+           "Latency: %0.0f usec\n"
+           "Flags: %s%s%s\n",
            i->index,
            i->driver,
            i->name,
@@ -229,9 +233,13 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
            pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
            pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
            i->owner_module,
+           i->mute ? "muted" : pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
            i->monitor_of_sink != PA_INVALID_INDEX ? t : "no",
-           (double) i->latency);
-    
+           (double) i->latency,
+           i->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
+           i->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
+           i->flags & PA_SOURCE_HARDWARE ? "HARDWARE" : "");
+
 }
 
 static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
@@ -505,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_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE);
 
     sample_length -= length;
 
@@ -561,7 +568,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     break;
                     
                 case EXIT:
-                    pa_context_exit_daemon(c);
+                    pa_operation_unref(pa_context_exit_daemon(c, NULL, NULL));
                     drain();
 
                 case LIST:
@@ -576,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);
             }
@@ -604,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 };
@@ -641,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:
@@ -661,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"))
@@ -680,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;
@@ -692,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));
@@ -713,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;
@@ -725,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]);
         }
     }
 
@@ -754,7 +775,7 @@ int main(int argc, char *argv[]) {
     }
 
     pa_context_set_state_callback(context, context_state_callback, NULL);
-    pa_context_connect(context, server, 1, NULL);
+    pa_context_connect(context, server, 0, NULL);
 
     if (pa_mainloop_run(m, &ret) < 0) {
         fprintf(stderr, "pa_mainloop_run() failed.\n");
@@ -776,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;
 }