2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2004-07-16 19:56:36 +00:00
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-07-06 00:08:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
2006-05-06 20:56:43 +00:00
|
|
|
#include <fcntl.h>
|
2004-07-06 00:08:44 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/simple.h>
|
|
|
|
|
#include <pulse/error.h>
|
2008-05-15 23:34:41 +00:00
|
|
|
#include <pulse/gccmacro.h>
|
2004-07-06 00:08:44 +00:00
|
|
|
|
|
|
|
|
#define BUFSIZE 1024
|
|
|
|
|
|
2008-08-09 16:20:29 +02:00
|
|
|
int main(int argc, char*argv[]) {
|
2004-08-17 17:17:22 +00:00
|
|
|
|
|
|
|
|
/* The Sample format to use */
|
2006-01-11 01:17:39 +00:00
|
|
|
static const pa_sample_spec ss = {
|
2004-07-06 00:08:44 +00:00
|
|
|
.format = PA_SAMPLE_S16LE,
|
|
|
|
|
.rate = 44100,
|
|
|
|
|
.channels = 2
|
|
|
|
|
};
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_simple *s = NULL;
|
2004-07-06 00:08:44 +00:00
|
|
|
int ret = 1;
|
|
|
|
|
int error;
|
|
|
|
|
|
2006-05-06 20:56:43 +00:00
|
|
|
/* replace STDIN with the specified file if needed */
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
if ((fd = open(argv[1], O_RDONLY)) < 0) {
|
|
|
|
|
fprintf(stderr, __FILE__": open() failed: %s\n", strerror(errno));
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dup2(fd, STDIN_FILENO) < 0) {
|
|
|
|
|
fprintf(stderr, __FILE__": dup2() failed: %s\n", strerror(errno));
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-05-06 20:56:43 +00:00
|
|
|
close(fd);
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-08-17 17:17:22 +00:00
|
|
|
/* Create a new playback stream */
|
2006-05-17 18:52:34 +00:00
|
|
|
if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
|
2004-07-07 00:22:46 +00:00
|
|
|
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
|
2004-07-06 00:08:44 +00:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
uint8_t buf[BUFSIZE];
|
|
|
|
|
ssize_t r;
|
2004-08-17 17:17:22 +00:00
|
|
|
|
2004-09-12 19:37:04 +00:00
|
|
|
#if 0
|
|
|
|
|
pa_usec_t latency;
|
|
|
|
|
|
2006-05-20 14:59:02 +00:00
|
|
|
if ((latency = pa_simple_get_latency(s, &error)) == (pa_usec_t) -1) {
|
|
|
|
|
fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error));
|
2004-09-12 19:37:04 +00:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "%0.0f usec \r", (float)latency);
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-08-17 17:17:22 +00:00
|
|
|
/* Read some data ... */
|
2004-07-06 00:08:44 +00:00
|
|
|
if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
|
2004-08-17 17:17:22 +00:00
|
|
|
if (r == 0) /* EOF */
|
2004-07-06 00:08:44 +00:00
|
|
|
break;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-07-07 00:22:46 +00:00
|
|
|
fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
|
2004-07-06 00:08:44 +00:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-17 17:17:22 +00:00
|
|
|
/* ... and play it */
|
2008-08-19 22:39:54 +02:00
|
|
|
if (pa_simple_write(s, buf, (size_t) r, &error) < 0) {
|
2004-07-07 00:22:46 +00:00
|
|
|
fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
|
2004-07-06 00:08:44 +00:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-07 00:22:46 +00:00
|
|
|
|
2004-08-17 17:17:22 +00:00
|
|
|
/* Make sure that every single sample was played */
|
2004-07-07 22:02:15 +00:00
|
|
|
if (pa_simple_drain(s, &error) < 0) {
|
|
|
|
|
fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error));
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-06 00:08:44 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
|
pa_simple_free(s);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-07-06 00:08:44 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|