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

#ifndef OMX_H
#define OMX_H

#include "types.h"

extern "C"
{
#include "ilclient.h"
}

class cMutex;

class cOmx
{

public:

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

	static OMX_TICKS ToOmxTicks(int64_t val);
	static int64_t FromOmxTicks(OMX_TICKS &ticks);
	static void PtsToTicks(uint64_t pts, OMX_TICKS &ticks);
	static uint64_t TicksToPts(OMX_TICKS &ticks);

	int64_t GetSTC(void);
	bool IsClockRunning(void);

	enum eClockState {
		eClockStateRun,
		eClockStateStop,
		eClockStateWaitForVideo,
		eClockStateWaitForAudio,
		eClockStateWaitForAudioVideo
	};

	void SetClockState(eClockState clockState);
	void SetClockScale(float scale);
	void SetMediaTime(uint64_t pts);
	unsigned int GetMediaTime(void);

	enum eClockReference {
		eClockRefAudio,
		eClockRefVideo
	};

	void SetClockReference(eClockReference clockReference);
	void SetVolume(int vol);
	void SendEos(void);
	void Stop(void);

	void FlushAudio(void);
	void FlushVideo(bool flushRender = false);

	int SetVideoCodec(cVideoCodec::eCodec codec);
	int SetupAudioRender(cAudioCodec::eCodec outputFormat,
			int channels, int samplingRate, cAudioPort::ePort audioPort);

	OMX_BUFFERHEADERTYPE* GetAudioBuffer(uint64_t pts = 0);
	OMX_BUFFERHEADERTYPE* GetVideoBuffer(uint64_t pts = 0);
	bool PollVideoBuffers(int minBuffers = 0);
	bool PollAudioBuffers(int minBuffers = 0);

	bool EmptyAudioBuffer(OMX_BUFFERHEADERTYPE *buf);
	bool EmptyVideoBuffer(OMX_BUFFERHEADERTYPE *buf);

private:

	static const char* errStr(int err);

	enum eOmxComponent {
		eClock = 0,
		eVideoDecoder,
		eVideoScheduler,
		eVideoRender,
		eAudioRender,
		eNumComponents
	};

	enum eOmxTunnel {
		eVideoDecoderToVideoScheduler = 0,
		eVideoSchedulerToVideoRender,
		eClockToVideoScheduler,
		eClockToAudioRender,
		eNumTunnels
	};

	ILCLIENT_T 	*m_client;
	COMPONENT_T	*m_comp[cOmx::eNumComponents + 1];
	TUNNEL_T 	 m_tun[cOmx::eNumTunnels + 1];

	cMutex	*m_mutex;

	bool m_setVideoStartTime;
	bool m_setAudioStartTime;
	bool m_setVideoDiscontinuity;

	int m_freeAudioBuffers;
	int m_freeVideoBuffers;

	eClockReference	m_clockReference;

	void HandleEndOfStream(unsigned int portId);
	void HandlePortSettingsChanged(unsigned int portId);
	void HandleBufferEmpty(COMPONENT_T *comp);

	static void OnBufferEmpty(void *instance, COMPONENT_T *comp);
	static void OnPortSettingsChanged(void *instance, COMPONENT_T *comp, unsigned int data);
	static void OnEndOfStream(void *instance, COMPONENT_T *comp, unsigned int data);
	static void OnError(void *instance, COMPONENT_T *comp, unsigned int data);

};

#endif