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