summaryrefslogtreecommitdiff
path: root/audio.h
blob: a4ade817338ab9922e03f46278c9720431ad0ea9 (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
/*
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#ifndef AUDIO_H
#define AUDIO_H

extern "C"
{
#include <libavcodec/avcodec.h>
}

class cMutex;

class cAudioDecoder
{

public:

	enum eCodec {
		ePCM,
		eMPG,
		eAC3,
		eEAC3,
		eAAC,
		eDTS,
		eNumCodecs
	};

	enum ePort {
		eLocal,
		eHDMI
	};

	static const char* CodecStr(eCodec codec)
	{
		return  (codec == ePCM)  ? "PCM"   :
				(codec == eMPG)  ? "MPG"   :
				(codec == eAC3)  ? "AC3"   :
				(codec == eEAC3) ? "E-AC3" :
				(codec == eAAC)  ? "AAC"   :
				(codec == eDTS)  ? "DTS"   : "unknown";
	}

    cAudioDecoder();
	virtual ~cAudioDecoder();

	virtual int Init(void);
	virtual int DeInit(void);

	virtual bool SetupAudioCodec(const unsigned char *data, int length);

	virtual eCodec GetCodec(void) { return m_codec; }
	virtual eCodec GetOutputFormat(void) { return m_outputFormat; }
	virtual ePort GetOutputPort(void) { return m_outputPort; }
	virtual int GetChannels(void) { return m_channels; }
	virtual int GetSamplingrate(void) { return m_samplingRate; }

	virtual unsigned int DecodeAudio(const unsigned char *data, int length,
			unsigned char *outbuf, int bufsize);

private:

	struct Codec
	{
		AVCodec 		*codec;
	    AVCodecContext 	*context;
	};

	Codec	 m_codecs[eNumCodecs];
	eCodec	 m_codec;
	eCodec	 m_outputFormat;
	ePort	 m_outputPort;
	int		 m_channels;
	int		 m_samplingRate;

	bool	 m_passthrough;

    AVFrame *m_frame;
    cMutex	*m_mutex;
};

#endif