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