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.
17 #include <sys/types.h>
18 #include <sys/queue.h>
32 #include <vorbis/codec.h>
33 #include <vorbis/vorbisfile.h>
38 #define nitems(x) (sizeof(x)/sizeof(x[0]))
42 play_oggvorbis(int fd)
44 static uint8_t pcmout[4096];
47 int current_section, eof = 0;
49 if ((f = fdopen(fd, "r")) == NULL)
52 if (ov_open_callbacks(f, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0)
53 errx(1, "input is not an Ogg bitstream");
59 vi = ov_info(&vf, -1);
60 for (ptr = ov_comment(&vf, -1)->user_comments; *ptr; ++ptr)
63 printf("bitstream is %d channel, %ldHz\n", vi->channels, vi->rate);
65 if (player_setrate(vi->rate) == -1)
66 err(1, "player_setrate");
72 if (player_shouldstop())
75 ret = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1,
80 warnx("non-fatal error in the stream %ld", ret);
82 /* TODO: deal with sample rate changes */
83 sio_write(hdl, pcmout, ret);