]>
code.delx.au - pulseaudio/blob - src/tests/pacat-simple.c
4 This file is part of PulseAudio.
6 PulseAudio 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.
11 PulseAudio 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.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <pulse/simple.h>
33 #include <pulse/error.h>
34 #include <pulsecore/gccmacro.h>
38 int main(PA_GCC_UNUSED
int argc
, char*argv
[]) {
40 /* The Sample format to use */
41 static const pa_sample_spec ss
= {
42 .format
= PA_SAMPLE_S16LE
,
51 /* replace STDIN with the specified file if needed */
55 if ((fd
= open(argv
[1], O_RDONLY
)) < 0) {
56 fprintf(stderr
, __FILE__
": open() failed: %s\n", strerror(errno
));
60 if (dup2(fd
, STDIN_FILENO
) < 0) {
61 fprintf(stderr
, __FILE__
": dup2() failed: %s\n", strerror(errno
));
68 /* Create a new playback stream */
69 if (!(s
= pa_simple_new(NULL
, argv
[0], PA_STREAM_PLAYBACK
, NULL
, "playback", &ss
, NULL
, NULL
, &error
))) {
70 fprintf(stderr
, __FILE__
": pa_simple_new() failed: %s\n", pa_strerror(error
));
81 if ((latency
= pa_simple_get_latency(s
, &error
)) == (pa_usec_t
) -1) {
82 fprintf(stderr
, __FILE__
": pa_simple_get_latency() failed: %s\n", pa_strerror(error
));
86 fprintf(stderr
, "%0.0f usec \r", (float)latency
);
89 /* Read some data ... */
90 if ((r
= read(STDIN_FILENO
, buf
, sizeof(buf
))) <= 0) {
94 fprintf(stderr
, __FILE__
": read() failed: %s\n", strerror(errno
));
99 if (pa_simple_write(s
, buf
, r
, &error
) < 0) {
100 fprintf(stderr
, __FILE__
": pa_simple_write() failed: %s\n", pa_strerror(error
));
105 /* Make sure that every single sample was played */
106 if (pa_simple_drain(s
, &error
) < 0) {
107 fprintf(stderr
, __FILE__
": pa_simple_drain() failed: %s\n", pa_strerror(error
));