decoder.h
author nathan
Sun, 12 Dec 2010 11:31:54 +0100
branchtrunk
changeset 38 79b272a68eb4
parent 25 887faebaba0a
permissions -rw-r--r--
fix compile without OGG library
     1 /*
     2  * MP3/MPlayer plugin to VDR (C++)
     3  *
     4  * (C) 2001-2009 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, utf8clean;
    41 protected:
    42   void Clear(void);
    43   void Set(cSongInfo *si, bool update=false);
    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   bool Utf8Clean(void) { return utf8clean; }
    51   void ConvertToSys(void);
    52   // Song
    53   char *Title, *Artist, *Album;
    54   int Year, Frames, Total;
    55   int SampleFreq, Channels, Bitrate, MaxBitrate, ChMode;
    56   // Normalize
    57   double Level, Peak;
    58   // Decoder
    59   int DecoderID;
    60   };
    61 
    62 // ----------------------------------------------------------------
    63 
    64 class cFileInfo {
    65 private:
    66   bool infoDone;
    67   int removable;
    68 protected:
    69   void Clear(void);
    70   void Set(cFileInfo *fi);
    71   void InfoDone(void) { infoDone=true; }
    72 public:
    73   cFileInfo(void);
    74   cFileInfo(const char *Name);
    75   ~cFileInfo();
    76   bool FileInfo(bool log=true);
    77   bool HasInfo(void) { return infoDone; }
    78   bool Removable(void);
    79   //
    80   char *Filename, *FsID;
    81   unsigned long long Filesize;
    82   time_t CTime;
    83   long FsType;
    84   };
    85 
    86 // ----------------------------------------------------------------
    87 
    88 class cPlayInfo {
    89 public:
    90   int Index, Total;
    91   };
    92 
    93 // ----------------------------------------------------------------
    94 
    95 class cDecoder {
    96 protected:
    97   char *filename;
    98   cMutex lock, locklock;
    99   int locked;
   100   bool urgentLock;
   101   //
   102   cPlayInfo pi;
   103   bool playing;
   104   //
   105   void Lock(bool urgent=false);
   106   void Unlock(void);
   107   bool TryLock(void);
   108 public:
   109   cDecoder(const char *Filename);
   110   virtual ~cDecoder();
   111   //
   112   virtual cFileInfo *FileInfo(void) { return 0; }
   113   virtual cSongInfo *SongInfo(bool get) { return 0; }
   114   virtual cPlayInfo *PlayInfo(void) { return 0; }
   115   //
   116   virtual bool Valid(void)=0;
   117   virtual bool IsStream(void) { return false; }
   118   virtual bool Start(void)=0;
   119   virtual bool Stop(void)=0;
   120   virtual bool Skip(int Seconds, float bsecs) { return false; }
   121   virtual struct Decode *Decode(void)=0;
   122   };
   123   
   124 // ----------------------------------------------------------------
   125 
   126 class cDecoders {
   127 public:
   128   static cDecoder *FindDecoder(cFileObj *Obj);
   129   static const char *ID2Str(int id);
   130   static int Str2ID(const char *str);
   131   };
   132 
   133 // ----------------------------------------------------------------
   134 
   135 #define CACHELINES 32
   136 
   137 class cInfoCache : public cThread {
   138 private:
   139   cMutex lock;
   140   cList<cCacheData> lists[CACHELINES];
   141   time_t lasttime, lastpurge;
   142   bool modified, lastmod;
   143   //
   144   char *CacheFile(void);
   145   void AddEntry(cCacheData *dat);
   146   void DelEntry(cCacheData *dat);
   147   cCacheData *FirstEntry(int hash);
   148   void Modified(void) { modified=lastmod=true; }
   149 protected:
   150   virtual void Action(void);
   151 public:
   152   cInfoCache(void);
   153   void Shutdown(void);
   154   void Save(bool force=false);
   155   void Load(void);
   156   bool Purge(void);
   157   void Cache(cSongInfo *info, cFileInfo *file);
   158   cCacheData *Search(cFileInfo *file);
   159   };
   160 
   161 extern cInfoCache InfoCache;
   162 extern char *cachedir;
   163 
   164 #endif //___DECODER_H