]> code.delx.au - pulseaudio/blob - src/utils/pactl.c
e3305f0f5954dab0520e8b889b84986a8a5d185b
[pulseaudio] / src / utils / pactl.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <signal.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <unistd.h>
30 #include <assert.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <limits.h>
34 #include <getopt.h>
35
36 #include <sndfile.h>
37
38 #include <polyp/polypaudio.h>
39 #include <polyp/mainloop.h>
40 #include <polyp/mainloop-signal.h>
41
42 #if PA_API_VERSION != 8
43 #error Invalid Polypaudio API version
44 #endif
45
46 #define BUFSIZE 1024
47
48 static pa_context *context = NULL;
49 static pa_mainloop_api *mainloop_api = NULL;
50
51 static char *device = NULL, *sample_name = NULL;
52
53 static SNDFILE *sndfile = NULL;
54 static pa_stream *sample_stream = NULL;
55 static pa_sample_spec sample_spec;
56 static size_t sample_length = 0;
57
58 static int actions = 1;
59
60 static int nl = 0;
61
62 static enum {
63 NONE,
64 EXIT,
65 STAT,
66 UPLOAD_SAMPLE,
67 PLAY_SAMPLE,
68 REMOVE_SAMPLE,
69 LIST
70 } action = NONE;
71
72 static void quit(int ret) {
73 assert(mainloop_api);
74 mainloop_api->quit(mainloop_api, ret);
75 }
76
77
78 static void context_drain_complete(pa_context *c, void *userdata) {
79 pa_context_disconnect(c);
80 }
81
82 static void drain(void) {
83 pa_operation *o;
84 if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
85 pa_context_disconnect(context);
86 else
87 pa_operation_unref(o);
88 }
89
90
91 static void complete_action(void) {
92 assert(actions > 0);
93
94 if (!(--actions))
95 drain();
96 }
97
98 static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata) {
99 char s[128];
100 if (!i) {
101 fprintf(stderr, "Failed to get statistics: %s\n", pa_strerror(pa_context_errno(c)));
102 quit(1);
103 return;
104 }
105
106 pa_bytes_snprint(s, sizeof(s), i->memblock_total_size);
107 printf("Currently in use: %u blocks containing %s bytes total.\n", i->memblock_total, s);
108
109 pa_bytes_snprint(s, sizeof(s), i->memblock_allocated_size);
110 printf("Allocated during whole lifetime: %u blocks containing %s bytes total.\n", i->memblock_allocated, s);
111
112 pa_bytes_snprint(s, sizeof(s), i->scache_size);
113 printf("Sample cache size: %s\n", s);
114
115 complete_action();
116 }
117
118 static void get_server_info_callback(pa_context *c, const pa_server_info *i, void *useerdata) {
119 char s[PA_SAMPLE_SPEC_SNPRINT_MAX];
120
121 if (!i) {
122 fprintf(stderr, "Failed to get server information: %s\n", pa_strerror(pa_context_errno(c)));
123 quit(1);
124 return;
125 }
126
127 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec);
128
129 printf("User name: %s\n"
130 "Host Name: %s\n"
131 "Server Name: %s\n"
132 "Server Version: %s\n"
133 "Default Sample Specification: %s\n"
134 "Default Sink: %s\n"
135 "Default Source: %s\n"
136 "Cookie: %08x\n",
137 i->user_name,
138 i->host_name,
139 i->server_name,
140 i->server_version,
141 s,
142 i->default_sink_name,
143 i->default_source_name,
144 i->cookie);
145
146 complete_action();
147 }
148
149 static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) {
150 char s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
151
152 if (is_last < 0) {
153 fprintf(stderr, "Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c)));
154 quit(1);
155 return;
156 }
157
158 if (is_last) {
159 complete_action();
160 return;
161 }
162
163 assert(i);
164
165 if (nl)
166 printf("\n");
167 nl = 1;
168
169 printf("*** Sink #%u ***\n"
170 "Name: %s\n"
171 "Driver: %s\n"
172 "Description: %s\n"
173 "Sample Specification: %s\n"
174 "Channel Map: %s\n"
175 "Owner Module: %u\n"
176 "Volume: %s\n"
177 "Monitor Source: %u\n"
178 "Latency: %0.0f usec\n",
179 i->index,
180 i->name,
181 i->driver,
182 i->description,
183 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
184 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
185 i->owner_module,
186 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
187 i->monitor_source,
188 (double) i->latency);
189
190 }
191
192 static void get_source_info_callback(pa_context *c, const pa_source_info *i, int is_last, void *userdata) {
193 char s[PA_SAMPLE_SPEC_SNPRINT_MAX], t[32], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
194
195 if (is_last < 0) {
196 fprintf(stderr, "Failed to get source information: %s\n", pa_strerror(pa_context_errno(c)));
197 quit(1);
198 return;
199 }
200
201 if (is_last) {
202 complete_action();
203 return;
204 }
205
206 assert(i);
207
208 if (nl)
209 printf("\n");
210 nl = 1;
211
212 snprintf(t, sizeof(t), "%u", i->monitor_of_sink);
213
214 printf("*** Source #%u ***\n"
215 "Name: %s\n"
216 "Driver: %s\n"
217 "Description: %s\n"
218 "Sample Specification: %s\n"
219 "Channel Map: %s\n"
220 "Owner Module: %u\n"
221 "Monitor of Sink: %s\n"
222 "Latency: %0.0f usec\n",
223 i->index,
224 i->driver,
225 i->name,
226 i->description,
227 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
228 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
229 i->owner_module,
230 i->monitor_of_sink != PA_INVALID_INDEX ? t : "no",
231 (double) i->latency);
232
233 }
234
235 static void get_module_info_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
236 char t[32];
237
238 if (is_last < 0) {
239 fprintf(stderr, "Failed to get module information: %s\n", pa_strerror(pa_context_errno(c)));
240 quit(1);
241 return;
242 }
243
244 if (is_last) {
245 complete_action();
246 return;
247 }
248
249 assert(i);
250
251 if (nl)
252 printf("\n");
253 nl = 1;
254
255 snprintf(t, sizeof(t), "%u", i->n_used);
256
257 printf("*** Module #%u ***\n"
258 "Name: %s\n"
259 "Argument: %s\n"
260 "Usage counter: %s\n"
261 "Auto unload: %s\n",
262 i->index,
263 i->name,
264 i->argument,
265 i->n_used != PA_INVALID_INDEX ? t : "n/a",
266 i->auto_unload ? "yes" : "no");
267 }
268
269 static void get_client_info_callback(pa_context *c, const pa_client_info *i, int is_last, void *userdata) {
270 char t[32];
271
272 if (is_last < 0) {
273 fprintf(stderr, "Failed to get client information: %s\n", pa_strerror(pa_context_errno(c)));
274 quit(1);
275 return;
276 }
277
278 if (is_last) {
279 complete_action();
280 return;
281 }
282
283 assert(i);
284
285 if (nl)
286 printf("\n");
287 nl = 1;
288
289 snprintf(t, sizeof(t), "%u", i->owner_module);
290
291 printf("*** Client #%u ***\n"
292 "Name: %s\n"
293 "Driver: %s\n"
294 "Owner Module: %s\n",
295 i->index,
296 i->name,
297 i->driver,
298 i->owner_module != PA_INVALID_INDEX ? t : "n/a");
299 }
300
301 static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
302 char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
303
304 if (is_last < 0) {
305 fprintf(stderr, "Failed to get sink input information: %s\n", pa_strerror(pa_context_errno(c)));
306 quit(1);
307 return;
308 }
309
310 if (is_last) {
311 complete_action();
312 return;
313 }
314
315 assert(i);
316
317 if (nl)
318 printf("\n");
319 nl = 1;
320
321 snprintf(t, sizeof(t), "%u", i->owner_module);
322 snprintf(k, sizeof(k), "%u", i->client);
323
324 printf("*** Sink Input #%u ***\n"
325 "Name: %s\n"
326 "Driver: %s\n"
327 "Owner Module: %s\n"
328 "Client: %s\n"
329 "Sink: %u\n"
330 "Sample Specification: %s\n"
331 "Channel Map: %s\n"
332 "Volume: %s\n"
333 "Buffer Latency: %0.0f usec\n"
334 "Sink Latency: %0.0f usec\n"
335 "Resample method: %s\n",
336 i->index,
337 i->name,
338 i->driver,
339 i->owner_module != PA_INVALID_INDEX ? t : "n/a",
340 i->client != PA_INVALID_INDEX ? k : "n/a",
341 i->sink,
342 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
343 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
344 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
345 (double) i->buffer_usec,
346 (double) i->sink_usec,
347 i->resample_method ? i->resample_method : "n/a");
348 }
349
350
351 static void get_source_output_info_callback(pa_context *c, const pa_source_output_info *i, int is_last, void *userdata) {
352 char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
353
354 if (is_last < 0) {
355 fprintf(stderr, "Failed to get source output information: %s\n", pa_strerror(pa_context_errno(c)));
356 quit(1);
357 return;
358 }
359
360 if (is_last) {
361 complete_action();
362 return;
363 }
364
365 assert(i);
366
367 if (nl)
368 printf("\n");
369 nl = 1;
370
371
372 snprintf(t, sizeof(t), "%u", i->owner_module);
373 snprintf(k, sizeof(k), "%u", i->client);
374
375 printf("*** Source Output #%u ***\n"
376 "Name: %s\n"
377 "Driver: %s\n"
378 "Owner Module: %s\n"
379 "Client: %s\n"
380 "Source: %u\n"
381 "Sample Specification: %s\n"
382 "Channel Map: %s\n"
383 "Buffer Latency: %0.0f usec\n"
384 "Source Latency: %0.0f usec\n"
385 "Resample method: %s\n",
386 i->index,
387 i->name,
388 i->driver,
389 i->owner_module != PA_INVALID_INDEX ? t : "n/a",
390 i->client != PA_INVALID_INDEX ? k : "n/a",
391 i->source,
392 pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec),
393 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
394 (double) i->buffer_usec,
395 (double) i->source_usec,
396 i->resample_method ? i->resample_method : "n/a");
397 }
398
399 static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int is_last, void *userdata) {
400 char t[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
401
402 if (is_last < 0) {
403 fprintf(stderr, "Failed to get sample information: %s\n", pa_strerror(pa_context_errno(c)));
404 quit(1);
405 return;
406 }
407
408 if (is_last) {
409 complete_action();
410 return;
411 }
412
413 assert(i);
414
415 if (nl)
416 printf("\n");
417 nl = 1;
418
419
420 pa_bytes_snprint(t, sizeof(t), i->bytes);
421
422 printf("*** Sample #%u ***\n"
423 "Name: %s\n"
424 "Volume: %s\n"
425 "Sample Specification: %s\n"
426 "Channel Map: %s\n"
427 "Duration: %0.1fs\n"
428 "Size: %s\n"
429 "Lazy: %s\n"
430 "Filename: %s\n",
431 i->index,
432 i->name,
433 pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
434 pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : "n/a",
435 pa_sample_spec_valid(&i->sample_spec) ? pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map) : "n/a",
436 (double) i->duration/1000000,
437 t,
438 i->lazy ? "yes" : "no",
439 i->filename ? i->filename : "n/a");
440 }
441
442 static void get_autoload_info_callback(pa_context *c, const pa_autoload_info *i, int is_last, void *userdata) {
443 if (is_last < 0) {
444 fprintf(stderr, "Failed to get autoload information: %s\n", pa_strerror(pa_context_errno(c)));
445 quit(1);
446 return;
447 }
448
449 if (is_last) {
450 complete_action();
451 return;
452 }
453
454 assert(i);
455
456 if (nl)
457 printf("\n");
458 nl = 1;
459
460 printf("*** Autoload Entry #%u ***\n"
461 "Name: %s\n"
462 "Type: %s\n"
463 "Module: %s\n"
464 "Argument: %s\n",
465 i->index,
466 i->name,
467 i->type == PA_AUTOLOAD_SINK ? "sink" : "source",
468 i->module,
469 i->argument);
470 }
471
472 static void simple_callback(pa_context *c, int success, void *userdata) {
473 if (!success) {
474 fprintf(stderr, "Failure: %s\n", pa_strerror(pa_context_errno(c)));
475 quit(1);
476 return;
477 }
478
479 complete_action();
480 }
481
482 static void stream_state_callback(pa_stream *s, void *userdata) {
483 assert(s);
484
485 switch (pa_stream_get_state(s)) {
486 case PA_STREAM_CREATING:
487 case PA_STREAM_READY:
488 break;
489
490 case PA_STREAM_TERMINATED:
491 drain();
492 break;
493
494 case PA_STREAM_FAILED:
495 default:
496 fprintf(stderr, "Failed to upload sample: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
497 quit(1);
498 }
499 }
500
501 static void stream_write_callback(pa_stream *s, size_t length, void *userdata) {
502 sf_count_t l;
503 float *d;
504 assert(s && length && sndfile);
505
506 d = malloc(length);
507 assert(d);
508
509 assert(sample_length >= length);
510 l = length/pa_frame_size(&sample_spec);
511
512 if ((sf_readf_float(sndfile, d, l)) != l) {
513 free(d);
514 fprintf(stderr, "Premature end of file\n");
515 quit(1);
516 }
517
518 pa_stream_write(s, d, length, free, 0, PA_SEEK_RELATIVE);
519
520 sample_length -= length;
521
522 if (sample_length <= 0) {
523 pa_stream_set_write_callback(sample_stream, NULL, NULL);
524 pa_stream_finish_upload(sample_stream);
525 }
526 }
527
528 static void context_state_callback(pa_context *c, void *userdata) {
529 assert(c);
530 switch (pa_context_get_state(c)) {
531 case PA_CONTEXT_CONNECTING:
532 case PA_CONTEXT_AUTHORIZING:
533 case PA_CONTEXT_SETTING_NAME:
534 break;
535
536 case PA_CONTEXT_READY:
537 switch (action) {
538 case STAT:
539 actions = 2;
540 pa_operation_unref(pa_context_stat(c, stat_callback, NULL));
541 pa_operation_unref(pa_context_get_server_info(c, get_server_info_callback, NULL));
542 break;
543
544 case PLAY_SAMPLE:
545 pa_operation_unref(pa_context_play_sample(c, sample_name, device, PA_VOLUME_NORM, simple_callback, NULL));
546 break;
547
548 case REMOVE_SAMPLE:
549 pa_operation_unref(pa_context_remove_sample(c, sample_name, simple_callback, NULL));
550 break;
551
552 case UPLOAD_SAMPLE:
553 sample_stream = pa_stream_new(c, sample_name, &sample_spec, NULL);
554 assert(sample_stream);
555
556 pa_stream_set_state_callback(sample_stream, stream_state_callback, NULL);
557 pa_stream_set_write_callback(sample_stream, stream_write_callback, NULL);
558 pa_stream_connect_upload(sample_stream, sample_length);
559 break;
560
561 case EXIT:
562 pa_context_exit_daemon(c);
563 drain();
564
565 case LIST:
566 actions = 8;
567 pa_operation_unref(pa_context_get_module_info_list(c, get_module_info_callback, NULL));
568 pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL));
569 pa_operation_unref(pa_context_get_source_info_list(c, get_source_info_callback, NULL));
570 pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
571 pa_operation_unref(pa_context_get_source_output_info_list(c, get_source_output_info_callback, NULL));
572 pa_operation_unref(pa_context_get_client_info_list(c, get_client_info_callback, NULL));
573 pa_operation_unref(pa_context_get_sample_info_list(c, get_sample_info_callback, NULL));
574 pa_operation_unref(pa_context_get_autoload_info_list(c, get_autoload_info_callback, NULL));
575 break;
576
577 default:
578 assert(0);
579 }
580 break;
581
582 case PA_CONTEXT_TERMINATED:
583 quit(0);
584 break;
585
586 case PA_CONTEXT_FAILED:
587 default:
588 fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
589 quit(1);
590 }
591 }
592
593 static void exit_signal_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
594 fprintf(stderr, "Got SIGINT, exiting.\n");
595 quit(0);
596 }
597
598 static void help(const char *argv0) {
599
600 printf("%s [options] stat\n"
601 "%s [options] list\n"
602 "%s [options] exit\n"
603 "%s [options] upload-sample FILENAME [NAME]\n"
604 "%s [options] play-sample NAME [SINK]\n"
605 "%s [options] remove-sample NAME\n\n"
606 " -h, --help Show this help\n"
607 " --version Show version\n\n"
608 " -s, --server=SERVER The name of the server to connect to\n"
609 " -n, --client-name=NAME How to call this client on the server\n",
610 argv0, argv0, argv0, argv0, argv0, argv0);
611 }
612
613 enum { ARG_VERSION = 256 };
614
615 int main(int argc, char *argv[]) {
616 pa_mainloop* m = NULL;
617 char tmp[PATH_MAX];
618 int ret = 1, r, c;
619 char *server = NULL, *client_name = NULL, *bn;
620
621 static const struct option long_options[] = {
622 {"server", 1, NULL, 's'},
623 {"client-name", 1, NULL, 'n'},
624 {"version", 0, NULL, ARG_VERSION},
625 {"help", 0, NULL, 'h'},
626 {NULL, 0, NULL, 0}
627 };
628
629 if (!(bn = strrchr(argv[0], '/')))
630 bn = argv[0];
631 else
632 bn++;
633
634 while ((c = getopt_long(argc, argv, "s:n:h", long_options, NULL)) != -1) {
635 switch (c) {
636 case 'h' :
637 help(bn);
638 ret = 0;
639 goto quit;
640
641 case ARG_VERSION:
642 printf("pactl "PACKAGE_VERSION"\nCompiled with libpolyp %s\nLinked with libpolyp %s\n", pa_get_headers_version(), pa_get_library_version());
643 ret = 0;
644 goto quit;
645
646 case 's':
647 free(server);
648 server = strdup(optarg);
649 break;
650
651 case 'n':
652 free(client_name);
653 client_name = strdup(optarg);
654 break;
655
656 default:
657 goto quit;
658 }
659 }
660
661 if (!client_name)
662 client_name = strdup(bn);
663
664 if (optind < argc) {
665 if (!strcmp(argv[optind], "stat"))
666 action = STAT;
667 else if (!strcmp(argv[optind], "exit"))
668 action = EXIT;
669 else if (!strcmp(argv[optind], "list"))
670 action = LIST;
671 else if (!strcmp(argv[optind], "upload-sample")) {
672 struct SF_INFO sfinfo;
673 action = UPLOAD_SAMPLE;
674
675 if (optind+1 >= argc) {
676 fprintf(stderr, "Please specify a sample file to load\n");
677 goto quit;
678 }
679
680 if (optind+2 < argc)
681 sample_name = strdup(argv[optind+2]);
682 else {
683 char *f = strrchr(argv[optind+1], '/');
684 size_t n;
685 if (f)
686 f++;
687 else
688 f = argv[optind];
689
690 n = strcspn(f, ".");
691 strncpy(tmp, f, n);
692 tmp[n] = 0;
693 sample_name = strdup(tmp);
694 }
695
696 memset(&sfinfo, 0, sizeof(sfinfo));
697 if (!(sndfile = sf_open(argv[optind+1], SFM_READ, &sfinfo))) {
698 fprintf(stderr, "Failed to open sound file.\n");
699 goto quit;
700 }
701
702 sample_spec.format = PA_SAMPLE_FLOAT32;
703 sample_spec.rate = sfinfo.samplerate;
704 sample_spec.channels = sfinfo.channels;
705
706 sample_length = sfinfo.frames*pa_frame_size(&sample_spec);
707 } else if (!strcmp(argv[optind], "play-sample")) {
708 action = PLAY_SAMPLE;
709 if (optind+1 >= argc) {
710 fprintf(stderr, "You have to specify a sample name to play\n");
711 goto quit;
712 }
713
714 sample_name = strdup(argv[optind+1]);
715
716 if (optind+2 < argc)
717 device = strdup(argv[optind+2]);
718
719 } else if (!strcmp(argv[optind], "remove-sample")) {
720 action = REMOVE_SAMPLE;
721 if (optind+1 >= argc) {
722 fprintf(stderr, "You have to specify a sample name to remove\n");
723 goto quit;
724 }
725
726 sample_name = strdup(argv[optind+1]);
727 }
728 }
729
730 if (action == NONE) {
731 fprintf(stderr, "No valid command specified.\n");
732 goto quit;
733 }
734
735 if (!(m = pa_mainloop_new())) {
736 fprintf(stderr, "pa_mainloop_new() failed.\n");
737 goto quit;
738 }
739
740 mainloop_api = pa_mainloop_get_api(m);
741
742 r = pa_signal_init(mainloop_api);
743 assert(r == 0);
744 pa_signal_new(SIGINT, exit_signal_callback, NULL);
745 #ifdef SIGPIPE
746 signal(SIGPIPE, SIG_IGN);
747 #endif
748
749 if (!(context = pa_context_new(mainloop_api, client_name))) {
750 fprintf(stderr, "pa_context_new() failed.\n");
751 goto quit;
752 }
753
754 pa_context_set_state_callback(context, context_state_callback, NULL);
755 pa_context_connect(context, server, 1, NULL);
756
757 if (pa_mainloop_run(m, &ret) < 0) {
758 fprintf(stderr, "pa_mainloop_run() failed.\n");
759 goto quit;
760 }
761
762 quit:
763 if (sample_stream)
764 pa_stream_unref(sample_stream);
765
766 if (context)
767 pa_context_unref(context);
768
769 if (m) {
770 pa_signal_done();
771 pa_mainloop_free(m);
772 }
773
774 if (sndfile)
775 sf_close(sndfile);
776
777 free(server);
778 free(device);
779 free(sample_name);
780
781 return ret;
782 }