/* $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
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;
UPLOAD_SAMPLE,
PLAY_SAMPLE,
REMOVE_SAMPLE,
- LIST
+ LIST,
+ MOVE_SINK_INPUT
} action = NONE;
static void quit(int ret) {
"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,
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)));
"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,
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) {
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;
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);
}
"%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 };
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:
}
if (!client_name)
- client_name = strdup(bn);
+ client_name = pa_xstrdup(bn);
if (optind < argc) {
if (!strcmp(argv[optind], "stat"))
}
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;
n = strcspn(f, ".");
strncpy(tmp, f, n);
tmp[n] = 0;
- sample_name = strdup(tmp);
+ sample_name = pa_xstrdup(tmp);
}
memset(&sfinfo, 0, sizeof(sfinfo));
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;
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]);
}
}
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;
}