1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
* MP3/MPlayer plugin to VDR (C++)
*
* (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
*
* OGG stream support initialy developed by Manuel Reimer <manuel.reimer@gmx.de>
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*/
#include <stdlib.h>
#include <stdio.h>
#include "common.h"
#include "decoder-ogg-stream.h"
#include "stream.h"
// --- Ogg callbacks -----------------------------------------------------------
static size_t callback_read(void *ptr, size_t size, size_t nmemb, void *datasource)
{
cNetStream *nstr=(cNetStream*)datasource;
unsigned char *sdata;
unsigned long slen=0;
// Read in loop until we either get data or function "Stream" fails
do {
if(!nstr->Stream(sdata,slen)) {
d(printf("oggstream-callback-read: EOF?\n"))
return 0;
}
} while(slen==0);
size_t read_size=size*nmemb;
if(slen>read_size) {
// If someone ever gets this message, buffer handling has to be improved...
d(printf("oggstream-callback-read: buffer size too small...\n"))
slen=read_size;
}
memcpy(ptr,sdata,slen);
return slen/size;
}
static int callback_close(void *datasource)
{
cNetStream *nstr=(cNetStream*)datasource;
nstr->Close();
return 0;
}
static const ov_callbacks callbacks = {
callback_read,
NULL,
callback_close,
NULL
};
// --- cNetOggFile -------------------------------------------------------------
cNetOggFile::cNetOggFile(const char *Filename)
:cOggFile(Filename)
{
nstr=new cNetStream(Filename);
}
bool cNetOggFile::Open(bool log)
{
if(opened) return true;
if(!nstr->Open(log)) return false;
int r=ov_open_callbacks(nstr,&vf,NULL,0,callbacks);
if(!r) opened=true;
else {
nstr->Close();
if(log) Error("open",r);
}
return opened;
}
// --- cNetOggInfo -------------------------------------------------------------
cNetOggInfo::cNetOggInfo(cNetOggFile *File)
:cOggInfo(File)
{
nfile=File;
nstr=nfile->nstr;
}
bool cNetOggInfo::DoScan(bool KeepOpen)
{
Clear();
IcyInfo();
if(!Title) FakeTitle(nstr->Filename);
Total=0;
ChMode=3;
DecoderID=DEC_OGGS;
InfoDone();
return true;
}
void cNetOggInfo::InfoHook()
{
if(nstr->IcyChanged()) IcyInfo();
vorbis_info *vi=ov_info(&nfile->vf,-1);
if(!vi) return;
Channels=vi->channels;
ChMode=Channels>1 ? 3:0;
SampleFreq=vi->rate;
if(vi->bitrate_upper>0 && vi->bitrate_lower>0) {
Bitrate=vi->bitrate_lower;
MaxBitrate=vi->bitrate_upper;
}
else
Bitrate=vi->bitrate_nominal;
Total=(int)ov_time_total(&nfile->vf,-1);
Frames=-1;
}
void cNetOggInfo::IcyInfo(void)
{
const char *t=nstr->IcyTitle();
const char *a;
if(t) {
a=nstr->IcyName();
if(!a) a=nstr->IcyUrl();
}
else {
t=nstr->IcyName();
a=nstr->IcyUrl();
}
if(t && (!Title || strcmp(t,Title))) {
free(Title);
Title=strdup(t);
}
if(a && (!Album || strcmp(a,Album))) {
free(Album);
Album=strdup(a);
}
}
// --- cOggStreamDecoder -------------------------------------------------------
cOggStreamDecoder::cOggStreamDecoder(const char *Filename)
:cOggDecoder(Filename,false)
{
nfile=new cNetOggFile(Filename);
file=nfile;
info=new cNetOggInfo(nfile);
}
|