nathan@0: /* nathan@0: * MP3/MPlayer plugin to VDR (C++) nathan@0: * nathan@2: * (C) 2001-2007 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: #ifndef ___DECODER_H nathan@0: #define ___DECODER_H nathan@0: nathan@0: #include nathan@0: #include nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cCacheData; nathan@0: class cFileObj; nathan@0: nathan@0: extern int MakeHashBuff(const char *buff, int len); nathan@0: #define MakeHash(str) MakeHashBuff((str),strlen(str)) nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cSongInfo { nathan@0: private: nathan@0: bool infoDone; nathan@0: protected: nathan@0: void Clear(void); nathan@0: void Set(cSongInfo *si); nathan@0: void FakeTitle(const char *filename, const char *extention=0); nathan@0: void InfoDone(void) { infoDone=true; } nathan@0: public: nathan@0: cSongInfo(void); nathan@0: ~cSongInfo(); nathan@0: bool HasInfo(void) { return infoDone; } nathan@0: // Song nathan@0: char *Title, *Artist, *Album; nathan@0: int Year, Frames, Total; nathan@0: int SampleFreq, Channels, Bitrate, MaxBitrate, ChMode; nathan@0: // Normalize nathan@0: double Level, Peak; nathan@0: // Decoder nathan@0: int DecoderID; nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cFileInfo { nathan@0: private: nathan@0: bool infoDone; nathan@0: int removable; nathan@0: protected: nathan@0: void Clear(void); nathan@0: void Set(cFileInfo *fi); nathan@0: void InfoDone(void) { infoDone=true; } nathan@0: public: nathan@0: cFileInfo(void); nathan@0: cFileInfo(const char *Name); nathan@0: ~cFileInfo(); nathan@0: bool FileInfo(bool log=true); nathan@0: bool HasInfo(void) { return infoDone; } nathan@0: bool Removable(void); nathan@0: // nathan@0: char *Filename, *FsID; nathan@0: unsigned long long Filesize; nathan@0: time_t CTime; nathan@0: long FsType; nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cPlayInfo { nathan@0: public: nathan@0: int Index, Total; nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cDecoder { nathan@0: protected: nathan@0: char *filename; nathan@0: cMutex lock, locklock; nathan@0: int locked; nathan@0: bool urgentLock; nathan@0: // nathan@0: cPlayInfo pi; nathan@0: bool playing; nathan@0: // nathan@0: void Lock(bool urgent=false); nathan@0: void Unlock(void); nathan@0: bool TryLock(void); nathan@0: public: nathan@0: cDecoder(const char *Filename); nathan@0: virtual ~cDecoder(); nathan@0: // nathan@0: virtual cFileInfo *FileInfo(void) { return 0; } nathan@0: virtual cSongInfo *SongInfo(bool get) { return 0; } nathan@0: virtual cPlayInfo *PlayInfo(void) { return 0; } nathan@0: // nathan@0: virtual bool Valid(void)=0; nathan@0: virtual bool IsStream(void) { return false; } nathan@0: virtual bool Start(void)=0; nathan@0: virtual bool Stop(void)=0; nathan@0: virtual bool Skip(int Seconds, float bsecs) { return false; } nathan@0: virtual struct Decode *Decode(void)=0; nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cDecoders { nathan@0: public: nathan@0: static cDecoder *FindDecoder(cFileObj *Obj); nathan@0: static const char *ID2Str(int id); nathan@0: static int Str2ID(const char *str); nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: #define CACHELINES 32 nathan@0: nathan@0: class cInfoCache : public cThread { nathan@0: private: nathan@0: cMutex lock; nathan@0: cList lists[CACHELINES]; nathan@0: time_t lasttime, lastpurge; nathan@0: bool modified, lastmod; nathan@0: // nathan@0: char *CacheFile(void); nathan@0: void AddEntry(cCacheData *dat); nathan@0: void DelEntry(cCacheData *dat); nathan@0: cCacheData *FirstEntry(int hash); nathan@0: void Modified(void) { modified=lastmod=true; } nathan@0: protected: nathan@0: virtual void Action(void); nathan@0: public: nathan@0: cInfoCache(void); nathan@2: void Shutdown(void); nathan@0: void Save(bool force=false); nathan@0: void Load(void); nathan@0: bool Purge(void); nathan@0: void Cache(cSongInfo *info, cFileInfo *file); nathan@0: cCacheData *Search(cFileInfo *file); nathan@0: }; nathan@0: nathan@0: extern cInfoCache InfoCache; nathan@0: extern char *cachedir; nathan@0: nathan@0: #endif //___DECODER_H