nathan@0: /* nathan@0: * MP3/MPlayer plugin to VDR (C++) nathan@0: * nathan@0: * (C) 2001-2005 Stefan Huelswitt nathan@0: * nathan@0: * This code is free software; you can redistribute it and/or nathan@0: * modify it under the terms of the GNU General Public License nathan@0: * as published by the Free Software Foundation; either version 2 nathan@0: * of the License, or (at your option) any later version. nathan@0: * nathan@0: * This code is distributed in the hope that it will be useful, nathan@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of nathan@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nathan@0: * GNU General Public License for more details. nathan@0: * nathan@0: * You should have received a copy of the GNU General Public License nathan@0: * along with this program; if not, write to the Free Software nathan@0: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. nathan@0: * Or, point your browser to http://www.gnu.org/copyleft/gpl.html nathan@0: */ nathan@0: nathan@0: #include nathan@0: #include nathan@0: #include nathan@0: #include nathan@0: nathan@0: #include "common.h" nathan@0: #include "decoder-mp3-stream.h" nathan@0: #include "stream.h" nathan@0: nathan@0: // --- cNetScanID3 ------------------------------------------------------------- nathan@0: nathan@0: class cNetScanID3 : public cScanID3 { nathan@0: private: nathan@0: cNetStream *nstr; nathan@0: // nathan@0: void IcyInfo(void); nathan@0: public: nathan@0: cNetScanID3(cNetStream *Str, bool *Urgent); nathan@0: virtual bool DoScan(bool KeepOpen=false); nathan@0: virtual void InfoHook(struct mad_header *header); nathan@0: }; nathan@0: nathan@0: cNetScanID3::cNetScanID3(cNetStream *Str, bool *Urgent) nathan@0: :cScanID3(Str,Urgent) nathan@0: { nathan@0: nstr=Str; nathan@0: } nathan@0: nathan@0: bool cNetScanID3::DoScan(bool KeepOpen) nathan@0: { nathan@0: Clear(); nathan@0: IcyInfo(); nathan@0: if(!Title) FakeTitle(nstr->Filename); nathan@0: Total=0; nathan@0: ChMode=3; nathan@0: DecoderID=DEC_MP3S; nathan@0: InfoDone(); nathan@0: return true; nathan@0: } nathan@0: nathan@0: void cNetScanID3::InfoHook(struct mad_header *header) nathan@0: { nathan@0: if(nstr->IcyChanged()) IcyInfo(); nathan@0: SampleFreq=header->samplerate; nathan@0: Channels=MAD_NCHANNELS(header); nathan@0: ChMode=header->mode; nathan@0: nathan@0: int br=header->bitrate; nathan@0: if(Bitrate<0) Bitrate=br; nathan@0: else if(Bitrate!=br) { nathan@0: if(MaxBitrate<0) { nathan@0: if(BitrateMaxBitrate) MaxBitrate=br; nathan@0: if(brIcyTitle(); nathan@0: const char *a; nathan@0: if(t) { nathan@0: a=nstr->IcyName(); nathan@0: if(!a) a=nstr->IcyUrl(); nathan@0: } nathan@0: else { nathan@0: t=nstr->IcyName(); nathan@0: a=nstr->IcyUrl(); nathan@0: } nathan@0: if(t && (!Title || strcmp(t,Title))) { nathan@0: free(Title); nathan@0: Title=strdup(t); nathan@0: } nathan@0: if(a && (!Album || strcmp(a,Album))) { nathan@0: free(Album); nathan@0: Album=strdup(a); nathan@0: } nathan@0: } nathan@0: nathan@0: // --- cMP3StreamDecoder ------------------------------------------------------- nathan@0: nathan@0: cMP3StreamDecoder::cMP3StreamDecoder(const char *Filename) nathan@0: :cMP3Decoder(Filename,false) nathan@0: { nathan@0: nstr=new cNetStream(filename); nathan@0: str=nstr; nathan@0: nscan=new cNetScanID3(nstr,&urgentLock); nathan@0: scan=nscan; nathan@0: isStream=true; nathan@0: } nathan@0: nathan@0: bool cMP3StreamDecoder::Valid(void) nathan@0: { nathan@0: bool res=false; nathan@0: if(TryLock()) { nathan@0: if(nstr->Valid()) res=true; nathan@0: Unlock(); nathan@0: } nathan@0: return res; nathan@0: }