2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2010 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
24 #ifdef HAVE_VORBISFILE
30 #include "decoder-ogg-stream.h"
33 // --- Ogg callbacks -----------------------------------------------------------
35 static size_t callback_read(void *ptr, size_t size, size_t nmemb, void *datasource)
37 cNetStream *nstr=(cNetStream*)datasource;
40 // Read in loop until we either get data or function "Stream" fails
42 if(!nstr->Stream(sdata,slen)) {
43 d(printf("oggstream-callback-read: EOF?\n"))
48 size_t read_size=size*nmemb;
50 // If someone ever gets this message, buffer handling has to be improved...
51 d(printf("oggstream-callback-read: buffer size too small...\n"))
54 memcpy(ptr,sdata,slen);
58 static int callback_close(void *datasource)
60 cNetStream *nstr=(cNetStream*)datasource;
65 static const ov_callbacks callbacks = {
72 // --- cNetOggFile -------------------------------------------------------------
74 cNetOggFile::cNetOggFile(const char *Filename)
77 nstr=new cNetStream(Filename);
80 bool cNetOggFile::Open(bool log)
82 if(opened) return true;
83 if(!nstr->Open(log)) return false;
84 int r=ov_open_callbacks(nstr,&vf,NULL,0,callbacks);
88 if(log) Error("open",r);
93 // --- cNetOggInfo -------------------------------------------------------------
95 cNetOggInfo::cNetOggInfo(cNetOggFile *File)
102 bool cNetOggInfo::DoScan(bool KeepOpen)
106 if(!Title) FakeTitle(nstr->Filename);
114 void cNetOggInfo::InfoHook()
116 if(nstr->IcyChanged()) IcyInfo();
117 vorbis_info *vi=ov_info(&nfile->vf,-1);
119 Channels=vi->channels;
120 ChMode=Channels>1 ? 3:0;
122 if(vi->bitrate_upper>0 && vi->bitrate_lower>0) {
123 Bitrate=vi->bitrate_lower;
124 MaxBitrate=vi->bitrate_upper;
127 Bitrate=vi->bitrate_nominal;
129 Total=(int)ov_time_total(&nfile->vf,-1);
133 void cNetOggInfo::IcyInfo(void)
135 const char *t=nstr->IcyTitle();
139 if(!a) a=nstr->IcyUrl();
145 if(t && (!Title || strcmp(t,Title))) {
149 if(a && (!Album || strcmp(a,Album))) {
155 // --- cOggStreamDecoder -------------------------------------------------------
157 cOggStreamDecoder::cOggStreamDecoder(const char *Filename)
158 :cOggDecoder(Filename,false)
160 nfile=new cNetOggFile(Filename);
162 info=new cNetOggInfo(nfile);
165 #endif //HAVE_VORBISFILE