2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
6 * OGG stream support initialy developed by Manuel Reimer <manuel.reimer@gmx.de>
8 * This code is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This code 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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 #include "decoder-ogg-stream.h"
31 // --- Ogg callbacks -----------------------------------------------------------
33 static size_t callback_read(void *ptr, size_t size, size_t nmemb, void *datasource)
35 cNetStream *nstr=(cNetStream*)datasource;
38 // Read in loop until we either get data or function "Stream" fails
40 if(!nstr->Stream(sdata,slen)) {
41 d(printf("oggstream-callback-read: EOF?\n"))
46 size_t read_size=size*nmemb;
48 // If someone ever gets this message, buffer handling has to be improved...
49 d(printf("oggstream-callback-read: buffer size too small...\n"))
52 memcpy(ptr,sdata,slen);
56 static int callback_close(void *datasource)
58 cNetStream *nstr=(cNetStream*)datasource;
63 static const ov_callbacks callbacks = {
70 // --- cNetOggFile -------------------------------------------------------------
72 cNetOggFile::cNetOggFile(const char *Filename)
75 nstr=new cNetStream(Filename);
78 bool cNetOggFile::Open(bool log)
80 if(opened) return true;
81 if(!nstr->Open(log)) return false;
82 int r=ov_open_callbacks(nstr,&vf,NULL,0,callbacks);
86 if(log) Error("open",r);
91 // --- cNetOggInfo -------------------------------------------------------------
93 cNetOggInfo::cNetOggInfo(cNetOggFile *File)
100 bool cNetOggInfo::DoScan(bool KeepOpen)
104 if(!Title) FakeTitle(nstr->Filename);
112 void cNetOggInfo::InfoHook()
114 if(nstr->IcyChanged()) IcyInfo();
115 vorbis_info *vi=ov_info(&nfile->vf,-1);
117 Channels=vi->channels;
118 ChMode=Channels>1 ? 3:0;
120 if(vi->bitrate_upper>0 && vi->bitrate_lower>0) {
121 Bitrate=vi->bitrate_lower;
122 MaxBitrate=vi->bitrate_upper;
125 Bitrate=vi->bitrate_nominal;
127 Total=(int)ov_time_total(&nfile->vf,-1);
131 void cNetOggInfo::IcyInfo(void)
133 const char *t=nstr->IcyTitle();
137 if(!a) a=nstr->IcyUrl();
143 if(t && (!Title || strcmp(t,Title))) {
147 if(a && (!Album || strcmp(a,Album))) {
153 // --- cOggStreamDecoder -------------------------------------------------------
155 cOggStreamDecoder::cOggStreamDecoder(const char *Filename)
156 :cOggDecoder(Filename,false)
158 nfile=new cNetOggFile(Filename);
160 info=new cNetOggInfo(nfile);