]> code.delx.au - pulseaudio/blob - src/parec-simple.c
adjust file references due to renaming
[pulseaudio] / src / parec-simple.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <errno.h>
5
6 #include "polyplib-simple.h"
7 #include "polyplib-error.h"
8
9 #define BUFSIZE 1024
10
11 static ssize_t loop_write(int fd, const void*data, size_t size) {
12 ssize_t ret = 0;
13
14 while (size > 0) {
15 ssize_t r;
16
17 if ((r = write(fd, data, size)) < 0)
18 return r;
19
20 if (r == 0)
21 break;
22
23 ret += r;
24 data += r;
25 size -= r;
26 }
27
28 return ret;
29 }
30
31 int main(int argc, char*argv[]) {
32 static const struct pa_sample_spec ss = {
33 .format = PA_SAMPLE_S16LE,
34 .rate = 44100,
35 .channels = 2
36 };
37 struct pa_simple *s = NULL;
38 int ret = 1;
39 int error;
40
41 if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, &error))) {
42 fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
43 goto finish;
44 }
45
46 for (;;) {
47 uint8_t buf[BUFSIZE];
48 ssize_t r;
49
50 if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
51 fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
52 goto finish;
53 }
54
55 if ((r = loop_write(STDOUT_FILENO, buf, sizeof(buf))) <= 0) {
56 fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
57 goto finish;
58 }
59 }
60
61 ret = 0;
62
63 finish:
64
65 if (s)
66 pa_simple_free(s);
67
68 return ret;
69 }