Initial revision 6759
[qball-mpd.git] / src / inputPlugins / _ogg_common.c
blobc83e4610378a67ac7ec28851e4023b4008442b3e
1 /* the Music Player Daemon (MPD)
2 * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3 * This project's homepage is: http://www.musicpd.org
5 * Common functions used for Ogg data streams (Ogg-Vorbis and OggFLAC)
6 * (c) 2005 by Eric Wong <normalperson@yhbt.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "../inputPlugin.h"
24 #if defined(HAVE_OGGFLAC) || defined(HAVE_OGGVORBIS)
26 #include "../utils.h"
27 #include "_ogg_common.h"
29 #include <string.h>
31 ogg_stream_type ogg_stream_type_detect(InputStream * inStream)
33 /* oggflac detection based on code in ogg123 and this post
34 * http://lists.xiph.org/pipermail/flac/2004-December/000393.html
35 * ogg123 trunk still doesn't have this patch as of June 2005 */
36 unsigned char buf[41];
37 size_t r, to_read = 41;
39 seekInputStream(inStream, 0, SEEK_SET);
41 while (to_read) {
42 r = readFromInputStream(inStream, buf, 1, to_read);
43 if (inStream->error)
44 break;
45 to_read -= r;
46 if (!r && !inputStreamAtEOF(inStream))
47 my_usleep(10000);
48 else
49 break;
52 seekInputStream(inStream, 0, SEEK_SET);
54 if (r >= 32 && memcmp(buf, "OggS", 4) == 0 && ((memcmp
55 (buf + 29, "FLAC",
56 4) == 0
57 && memcmp(buf + 37,
58 "fLaC",
59 4) == 0)
61 (memcmp
62 (buf + 28, "FLAC",
63 4) == 0)
65 (memcmp
66 (buf + 28, "fLaC",
67 4) == 0))) {
68 return FLAC;
70 return VORBIS;
73 #endif /* defined(HAVE_OGGFLAC || defined(HAVE_OGGVORBIS) */