bluetooth: Fix HSP volume handling.
[pulseaudio-raopUDP/pulseaudio-raop-alac.git] / src / tests / parec-simple.c
blob9f19ff47c0f8c57e2acc7bcdda9d0bb99f6927fe
1 /***
2 This file is part of PulseAudio.
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA.
18 ***/
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <errno.h>
29 #include <pulse/simple.h>
30 #include <pulse/error.h>
31 #include <pulse/gccmacro.h>
33 #define BUFSIZE 1024
35 /* A simple routine calling UNIX write() in a loop */
36 static ssize_t loop_write(int fd, const void*data, size_t size) {
37 ssize_t ret = 0;
39 while (size > 0) {
40 ssize_t r;
42 if ((r = write(fd, data, size)) < 0)
43 return r;
45 if (r == 0)
46 break;
48 ret += r;
49 data = (const uint8_t*) data + r;
50 size -= (size_t) r;
53 return ret;
56 int main(int argc, char*argv[]) {
57 /* The sample type to use */
58 static const pa_sample_spec ss = {
59 .format = PA_SAMPLE_S16LE,
60 .rate = 44100,
61 .channels = 2
63 pa_simple *s = NULL;
64 int ret = 1;
65 int error;
67 /* Create the recording stream */
68 if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
69 fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
70 goto finish;
73 for (;;) {
74 uint8_t buf[BUFSIZE];
76 /* Record some data ... */
77 if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
78 fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
79 goto finish;
82 /* And write it to STDOUT */
83 if (loop_write(STDOUT_FILENO, buf, sizeof(buf)) != sizeof(buf)) {
84 fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
85 goto finish;
89 ret = 0;
91 finish:
93 if (s)
94 pa_simple_free(s);
96 return ret;