1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/decoder.h Sat Dec 29 14:47:40 2007 +0100
1.3 @@ -0,0 +1,161 @@
1.4 +/*
1.5 + * MP3/MPlayer plugin to VDR (C++)
1.6 + *
1.7 + * (C) 2001-2005 Stefan Huelswitt <s.huelswitt@gmx.de>
1.8 + *
1.9 + * This code is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License
1.11 + * as published by the Free Software Foundation; either version 2
1.12 + * of the License, or (at your option) any later version.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1.22 + * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
1.23 + */
1.24 +
1.25 +#ifndef ___DECODER_H
1.26 +#define ___DECODER_H
1.27 +
1.28 +#include <vdr/thread.h>
1.29 +#include <vdr/tools.h>
1.30 +
1.31 +// ----------------------------------------------------------------
1.32 +
1.33 +class cCacheData;
1.34 +class cFileObj;
1.35 +
1.36 +extern int MakeHashBuff(const char *buff, int len);
1.37 +#define MakeHash(str) MakeHashBuff((str),strlen(str))
1.38 +
1.39 +// ----------------------------------------------------------------
1.40 +
1.41 +class cSongInfo {
1.42 +private:
1.43 + bool infoDone;
1.44 +protected:
1.45 + void Clear(void);
1.46 + void Set(cSongInfo *si);
1.47 + void FakeTitle(const char *filename, const char *extention=0);
1.48 + void InfoDone(void) { infoDone=true; }
1.49 +public:
1.50 + cSongInfo(void);
1.51 + ~cSongInfo();
1.52 + bool HasInfo(void) { return infoDone; }
1.53 + // Song
1.54 + char *Title, *Artist, *Album;
1.55 + int Year, Frames, Total;
1.56 + int SampleFreq, Channels, Bitrate, MaxBitrate, ChMode;
1.57 + // Normalize
1.58 + double Level, Peak;
1.59 + // Decoder
1.60 + int DecoderID;
1.61 + };
1.62 +
1.63 +// ----------------------------------------------------------------
1.64 +
1.65 +class cFileInfo {
1.66 +private:
1.67 + bool infoDone;
1.68 + int removable;
1.69 +protected:
1.70 + void Clear(void);
1.71 + void Set(cFileInfo *fi);
1.72 + void InfoDone(void) { infoDone=true; }
1.73 +public:
1.74 + cFileInfo(void);
1.75 + cFileInfo(const char *Name);
1.76 + ~cFileInfo();
1.77 + bool FileInfo(bool log=true);
1.78 + bool HasInfo(void) { return infoDone; }
1.79 + bool Removable(void);
1.80 + //
1.81 + char *Filename, *FsID;
1.82 + unsigned long long Filesize;
1.83 + time_t CTime;
1.84 + long FsType;
1.85 + };
1.86 +
1.87 +// ----------------------------------------------------------------
1.88 +
1.89 +class cPlayInfo {
1.90 +public:
1.91 + int Index, Total;
1.92 + };
1.93 +
1.94 +// ----------------------------------------------------------------
1.95 +
1.96 +class cDecoder {
1.97 +protected:
1.98 + char *filename;
1.99 + cMutex lock, locklock;
1.100 + int locked;
1.101 + bool urgentLock;
1.102 + //
1.103 + cPlayInfo pi;
1.104 + bool playing;
1.105 + //
1.106 + void Lock(bool urgent=false);
1.107 + void Unlock(void);
1.108 + bool TryLock(void);
1.109 +public:
1.110 + cDecoder(const char *Filename);
1.111 + virtual ~cDecoder();
1.112 + //
1.113 + virtual cFileInfo *FileInfo(void) { return 0; }
1.114 + virtual cSongInfo *SongInfo(bool get) { return 0; }
1.115 + virtual cPlayInfo *PlayInfo(void) { return 0; }
1.116 + //
1.117 + virtual bool Valid(void)=0;
1.118 + virtual bool IsStream(void) { return false; }
1.119 + virtual bool Start(void)=0;
1.120 + virtual bool Stop(void)=0;
1.121 + virtual bool Skip(int Seconds, float bsecs) { return false; }
1.122 + virtual struct Decode *Decode(void)=0;
1.123 + };
1.124 +
1.125 +// ----------------------------------------------------------------
1.126 +
1.127 +class cDecoders {
1.128 +public:
1.129 + static cDecoder *FindDecoder(cFileObj *Obj);
1.130 + static const char *ID2Str(int id);
1.131 + static int Str2ID(const char *str);
1.132 + };
1.133 +
1.134 +// ----------------------------------------------------------------
1.135 +
1.136 +#define CACHELINES 32
1.137 +
1.138 +class cInfoCache : public cThread {
1.139 +private:
1.140 + cMutex lock;
1.141 + cList<cCacheData> lists[CACHELINES];
1.142 + time_t lasttime, lastpurge;
1.143 + bool modified, lastmod;
1.144 + //
1.145 + char *CacheFile(void);
1.146 + void AddEntry(cCacheData *dat);
1.147 + void DelEntry(cCacheData *dat);
1.148 + cCacheData *FirstEntry(int hash);
1.149 + void Modified(void) { modified=lastmod=true; }
1.150 +protected:
1.151 + virtual void Action(void);
1.152 +public:
1.153 + cInfoCache(void);
1.154 + void Save(bool force=false);
1.155 + void Load(void);
1.156 + bool Purge(void);
1.157 + void Cache(cSongInfo *info, cFileInfo *file);
1.158 + cCacheData *Search(cFileInfo *file);
1.159 + };
1.160 +
1.161 +extern cInfoCache InfoCache;
1.162 +extern char *cachedir;
1.163 +
1.164 +#endif //___DECODER_H