2 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 #include <vorbis/codec.h>
28 #include <vorbis/vorbisfile.h>
34 #define nitems(x) (sizeof(x)/sizeof(x[0]))
38 play_oggvorbis(int fd, const char **errstr)
40 static char pcmout[4096];
45 int current_section, ret = 0;
47 if ((f = fdopen(fd, "r")) == NULL) {
48 *errstr = "fdopen failed";
53 if (ov_open_callbacks(f, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
54 *errstr = "input is not an Ogg bitstream";
60 * we could extract some tags by looping over the NULL
61 * terminated array returned by ov_comment(&vf, -1), see
62 * previous revision of this file.
64 vi = ov_info(&vf, -1);
65 if (player_setup(16, vi->rate, vi->channels) == -1)
66 err(1, "player_setup");
68 player_setduration(ov_time_total(&vf, -1) * vi->rate);
74 r = ov_pcm_seek(&vf, seek);
80 r = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1,
85 /* TODO: deal with sample rate changes */
86 if (!play(pcmout, r, &seek)) {