nathan@0
|
1 |
/*
|
nathan@0
|
2 |
* MP3/MPlayer plugin to VDR (C++)
|
nathan@0
|
3 |
*
|
nathan@2
|
4 |
* (C) 2001-2007 Stefan Huelswitt <s.huelswitt@gmx.de>
|
nathan@0
|
5 |
*
|
nathan@0
|
6 |
* This code is free software; you can redistribute it and/or
|
nathan@0
|
7 |
* modify it under the terms of the GNU General Public License
|
nathan@0
|
8 |
* as published by the Free Software Foundation; either version 2
|
nathan@0
|
9 |
* of the License, or (at your option) any later version.
|
nathan@0
|
10 |
*
|
nathan@0
|
11 |
* This code is distributed in the hope that it will be useful,
|
nathan@0
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nathan@0
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nathan@0
|
14 |
* GNU General Public License for more details.
|
nathan@0
|
15 |
*
|
nathan@0
|
16 |
* You should have received a copy of the GNU General Public License
|
nathan@0
|
17 |
* along with this program; if not, write to the Free Software
|
nathan@0
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
nathan@0
|
19 |
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
|
nathan@0
|
20 |
*/
|
nathan@0
|
21 |
|
nathan@0
|
22 |
#ifndef ___DECODER_H
|
nathan@0
|
23 |
#define ___DECODER_H
|
nathan@0
|
24 |
|
nathan@0
|
25 |
#include <vdr/thread.h>
|
nathan@0
|
26 |
#include <vdr/tools.h>
|
nathan@0
|
27 |
|
nathan@0
|
28 |
// ----------------------------------------------------------------
|
nathan@0
|
29 |
|
nathan@0
|
30 |
class cCacheData;
|
nathan@0
|
31 |
class cFileObj;
|
nathan@0
|
32 |
|
nathan@0
|
33 |
extern int MakeHashBuff(const char *buff, int len);
|
nathan@0
|
34 |
#define MakeHash(str) MakeHashBuff((str),strlen(str))
|
nathan@0
|
35 |
|
nathan@0
|
36 |
// ----------------------------------------------------------------
|
nathan@0
|
37 |
|
nathan@0
|
38 |
class cSongInfo {
|
nathan@0
|
39 |
private:
|
nathan@0
|
40 |
bool infoDone;
|
nathan@0
|
41 |
protected:
|
nathan@0
|
42 |
void Clear(void);
|
nathan@0
|
43 |
void Set(cSongInfo *si);
|
nathan@0
|
44 |
void FakeTitle(const char *filename, const char *extention=0);
|
nathan@0
|
45 |
void InfoDone(void) { infoDone=true; }
|
nathan@0
|
46 |
public:
|
nathan@0
|
47 |
cSongInfo(void);
|
nathan@0
|
48 |
~cSongInfo();
|
nathan@0
|
49 |
bool HasInfo(void) { return infoDone; }
|
nathan@0
|
50 |
// Song
|
nathan@0
|
51 |
char *Title, *Artist, *Album;
|
nathan@0
|
52 |
int Year, Frames, Total;
|
nathan@0
|
53 |
int SampleFreq, Channels, Bitrate, MaxBitrate, ChMode;
|
nathan@0
|
54 |
// Normalize
|
nathan@0
|
55 |
double Level, Peak;
|
nathan@0
|
56 |
// Decoder
|
nathan@0
|
57 |
int DecoderID;
|
nathan@0
|
58 |
};
|
nathan@0
|
59 |
|
nathan@0
|
60 |
// ----------------------------------------------------------------
|
nathan@0
|
61 |
|
nathan@0
|
62 |
class cFileInfo {
|
nathan@0
|
63 |
private:
|
nathan@0
|
64 |
bool infoDone;
|
nathan@0
|
65 |
int removable;
|
nathan@0
|
66 |
protected:
|
nathan@0
|
67 |
void Clear(void);
|
nathan@0
|
68 |
void Set(cFileInfo *fi);
|
nathan@0
|
69 |
void InfoDone(void) { infoDone=true; }
|
nathan@0
|
70 |
public:
|
nathan@0
|
71 |
cFileInfo(void);
|
nathan@0
|
72 |
cFileInfo(const char *Name);
|
nathan@0
|
73 |
~cFileInfo();
|
nathan@0
|
74 |
bool FileInfo(bool log=true);
|
nathan@0
|
75 |
bool HasInfo(void) { return infoDone; }
|
nathan@0
|
76 |
bool Removable(void);
|
nathan@0
|
77 |
//
|
nathan@0
|
78 |
char *Filename, *FsID;
|
nathan@0
|
79 |
unsigned long long Filesize;
|
nathan@0
|
80 |
time_t CTime;
|
nathan@0
|
81 |
long FsType;
|
nathan@0
|
82 |
};
|
nathan@0
|
83 |
|
nathan@0
|
84 |
// ----------------------------------------------------------------
|
nathan@0
|
85 |
|
nathan@0
|
86 |
class cPlayInfo {
|
nathan@0
|
87 |
public:
|
nathan@0
|
88 |
int Index, Total;
|
nathan@0
|
89 |
};
|
nathan@0
|
90 |
|
nathan@0
|
91 |
// ----------------------------------------------------------------
|
nathan@0
|
92 |
|
nathan@0
|
93 |
class cDecoder {
|
nathan@0
|
94 |
protected:
|
nathan@0
|
95 |
char *filename;
|
nathan@0
|
96 |
cMutex lock, locklock;
|
nathan@0
|
97 |
int locked;
|
nathan@0
|
98 |
bool urgentLock;
|
nathan@0
|
99 |
//
|
nathan@0
|
100 |
cPlayInfo pi;
|
nathan@0
|
101 |
bool playing;
|
nathan@0
|
102 |
//
|
nathan@0
|
103 |
void Lock(bool urgent=false);
|
nathan@0
|
104 |
void Unlock(void);
|
nathan@0
|
105 |
bool TryLock(void);
|
nathan@0
|
106 |
public:
|
nathan@0
|
107 |
cDecoder(const char *Filename);
|
nathan@0
|
108 |
virtual ~cDecoder();
|
nathan@0
|
109 |
//
|
nathan@0
|
110 |
virtual cFileInfo *FileInfo(void) { return 0; }
|
nathan@0
|
111 |
virtual cSongInfo *SongInfo(bool get) { return 0; }
|
nathan@0
|
112 |
virtual cPlayInfo *PlayInfo(void) { return 0; }
|
nathan@0
|
113 |
//
|
nathan@0
|
114 |
virtual bool Valid(void)=0;
|
nathan@0
|
115 |
virtual bool IsStream(void) { return false; }
|
nathan@0
|
116 |
virtual bool Start(void)=0;
|
nathan@0
|
117 |
virtual bool Stop(void)=0;
|
nathan@0
|
118 |
virtual bool Skip(int Seconds, float bsecs) { return false; }
|
nathan@0
|
119 |
virtual struct Decode *Decode(void)=0;
|
nathan@0
|
120 |
};
|
nathan@0
|
121 |
|
nathan@0
|
122 |
// ----------------------------------------------------------------
|
nathan@0
|
123 |
|
nathan@0
|
124 |
class cDecoders {
|
nathan@0
|
125 |
public:
|
nathan@0
|
126 |
static cDecoder *FindDecoder(cFileObj *Obj);
|
nathan@0
|
127 |
static const char *ID2Str(int id);
|
nathan@0
|
128 |
static int Str2ID(const char *str);
|
nathan@0
|
129 |
};
|
nathan@0
|
130 |
|
nathan@0
|
131 |
// ----------------------------------------------------------------
|
nathan@0
|
132 |
|
nathan@0
|
133 |
#define CACHELINES 32
|
nathan@0
|
134 |
|
nathan@0
|
135 |
class cInfoCache : public cThread {
|
nathan@0
|
136 |
private:
|
nathan@0
|
137 |
cMutex lock;
|
nathan@0
|
138 |
cList<cCacheData> lists[CACHELINES];
|
nathan@0
|
139 |
time_t lasttime, lastpurge;
|
nathan@0
|
140 |
bool modified, lastmod;
|
nathan@0
|
141 |
//
|
nathan@0
|
142 |
char *CacheFile(void);
|
nathan@0
|
143 |
void AddEntry(cCacheData *dat);
|
nathan@0
|
144 |
void DelEntry(cCacheData *dat);
|
nathan@0
|
145 |
cCacheData *FirstEntry(int hash);
|
nathan@0
|
146 |
void Modified(void) { modified=lastmod=true; }
|
nathan@0
|
147 |
protected:
|
nathan@0
|
148 |
virtual void Action(void);
|
nathan@0
|
149 |
public:
|
nathan@0
|
150 |
cInfoCache(void);
|
nathan@2
|
151 |
void Shutdown(void);
|
nathan@0
|
152 |
void Save(bool force=false);
|
nathan@0
|
153 |
void Load(void);
|
nathan@0
|
154 |
bool Purge(void);
|
nathan@0
|
155 |
void Cache(cSongInfo *info, cFileInfo *file);
|
nathan@0
|
156 |
cCacheData *Search(cFileInfo *file);
|
nathan@0
|
157 |
};
|
nathan@0
|
158 |
|
nathan@0
|
159 |
extern cInfoCache InfoCache;
|
nathan@0
|
160 |
extern char *cachedir;
|
nathan@0
|
161 |
|
nathan@0
|
162 |
#endif //___DECODER_H
|