00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026 #include <stdio.h>
00027 #include <unistd.h>
00028 #include <string.h>
00029 #include <errno.h>
00030
00031 #include <pulse/simple.h>
00032 #include <pulse/error.h>
00033 #include <pulsecore/gccmacro.h>
00034
00035 #define BUFSIZE 1024
00036
00037
00038 static ssize_t loop_write(int fd, const void*data, size_t size) {
00039 ssize_t ret = 0;
00040
00041 while (size > 0) {
00042 ssize_t r;
00043
00044 if ((r = write(fd, data, size)) < 0)
00045 return r;
00046
00047 if (r == 0)
00048 break;
00049
00050 ret += r;
00051 data = (const uint8_t*) data + r;
00052 size -= r;
00053 }
00054
00055 return ret;
00056 }
00057
00058 int main(PA_GCC_UNUSED int argc, char*argv[]) {
00059
00060 static const pa_sample_spec ss = {
00061 .format = PA_SAMPLE_S16LE,
00062 .rate = 44100,
00063 .channels = 2
00064 };
00065 pa_simple *s = NULL;
00066 int ret = 1;
00067 int error;
00068
00069
00070 if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
00071 fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
00072 goto finish;
00073 }
00074
00075 for (;;) {
00076 uint8_t buf[BUFSIZE];
00077 ssize_t r;
00078
00079
00080 if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
00081 fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
00082 goto finish;
00083 }
00084
00085
00086 if ((r = loop_write(STDOUT_FILENO, buf, sizeof(buf))) <= 0) {
00087 fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
00088 goto finish;
00089 }
00090 }
00091
00092 ret = 0;
00093
00094 finish:
00095
00096 if (s)
00097 pa_simple_free(s);
00098
00099 return ret;
00100 }