summaryrefslogtreecommitdiff
path: root/vdr_decoder.h
blob: 74b200e921a33faee4e38b8fe0c04ce0b6e537af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*!
 * \file vdr_decoder.h
 * \brief A generic decoder for a VDR media plugin (muggle)
 *
 * \version $Revision: 1.2 $
 * \date    $Date: 2004/05/28 15:29:18 $
 * \author  Ralf Klueber, Lars von Wedel, Andreas Kellner
 * \author  Responsible author: $Author: lvw $
 *
 * $Id: vdr_decoder.h,v 1.2 2004/05/28 15:29:18 lvw Exp $
 *
 * Adapted from 
 * MP3/MPlayer plugin to VDR (C++)
 * (C) 2001,2002 Stefan Huelswitt <huels@iname.com>
 */

#ifndef ___DECODER_H
#define ___DECODER_H

#include <string>

#include <thread.h>
#include <string>

#define DEC_ID(a,b,c,d) (((a)<<24)+((b)<<16)+((c)<<8)+(d))

// --------From decoder_core.h ------------------------------------

/*! 
 * \brief The current status of the decoder
 */
enum eDecodeStatus
  { 
    dsOK=0, dsPlay, dsSkip, dsEof, dsError, dsSoftError 
  };

// ----------------------------------------------------------------

/*! 
 * \brief A data structure to put decoded PCM data
 */
struct mgDecode
{
  eDecodeStatus status;
  int index;
  struct mad_pcm *pcm;
};

// ----------------------------------------------------------------

/*! 
 * \brief Information about ???
 */
class mgPlayInfo
{
public:
  int m_index, m_total;
};

// ----------------------------------------------------------------

/*! 
 * \brief Media types
 */
enum mgMediaType
{
	MT_MP3, MT_MP3_STREAM, MT_OGG, MT_FLAC
};

/*! 
 * \brief A generic decoder class to handle conversion into PCM format
 */
class mgDecoder
{
protected:

  /*! \brief The currently playing file */
  std::string m_filename;

  /*! \brief Mutexes to coordinate threads */
  cMutex m_lock, m_locklock;
  int    m_locked;
  bool   m_urgentLock;
  
  /*! \brief Whether the decoder is currently active */
  bool m_playing;

  /*! \brief ??? */
  mgPlayInfo m_playinfo;

  /*! \brief Place a lock */
  virtual void lock( bool urgent = false );

  /*! \brief Release a lock */
  virtual void unlock(void);

  /*! \brief Try to obtain a lock */
  virtual bool tryLock(void);

public:

  /*! \brief The constructor */
  mgDecoder( std::string filename );

  /*! \brief The destructor */
  virtual ~mgDecoder();

  /*! \brief Whether a decoder instance is able to play the given file */
  virtual bool valid() = 0;

  /*! \brief Whether a stream (i.e. from the network is being decoded */
  virtual bool isStream() 
    { 
      return false; 
    }

  /*! \brief Start decoding */
  virtual bool start() = 0;

  /*! \brief Stop decoding */
  virtual bool stop() = 0;

  /*! \brief Skip an amount of time. Impossible by default */
  virtual bool skip( int seconds, int avail, int rate) 
    { 
      return false;
    }

  /*! \brief Return decoded data */
  virtual struct mgDecode *decode() = 0;

  /*! \brief Information about the current playback status */
  virtual mgPlayInfo *playInfo() 
    { 
      return 0;
    }
};
  
// ----------------------------------------------------------------

/*! 
 * \brief A generic decoder manager class to handle different decoders
 */
class mgDecoders
{
public:
  
  /*! \brief Try to find a valid decoder for a file 
   */
  static mgDecoder *findDecoder( std::string filename );

  /*! \brief determine the media type for a given source
   */
  static mgMediaType getMediaType( std::string filename );

};

#endif //___DECODER_H