-
Notifications
You must be signed in to change notification settings - Fork 500
/
OMXCore.h
228 lines (189 loc) · 7.65 KB
/
OMXCore.h
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#pragma once
/*
* Copyright (C) 2010-2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#if defined(HAVE_OMXLIB)
#include <string>
#include <queue>
// TODO: should this be in configure
#ifndef OMX_SKIP64BIT
#define OMX_SKIP64BIT
#endif
#include "DllOMX.h"
#include <semaphore.h>
////////////////////////////////////////////////////////////////////////////////////////////
// debug spew defines
#if 0
#define OMX_DEBUG_VERBOSE
#define OMX_DEBUG_EVENTHANDLER
#endif
#define OMX_INIT_STRUCTURE(a) \
memset(&(a), 0, sizeof(a)); \
(a).nSize = sizeof(a); \
(a).nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
(a).nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
(a).nVersion.s.nRevision = OMX_VERSION_REVISION; \
(a).nVersion.s.nStep = OMX_VERSION_STEP
#include "DllAvFormat.h"
#define OMX_MAX_PORTS 10
typedef struct omx_event {
OMX_EVENTTYPE eEvent;
OMX_U32 nData1;
OMX_U32 nData2;
} omx_event;
class DllLibOMXCore;
class COMXCore;
class COMXCoreComponent;
class COMXCoreTunel;
class COMXCoreClock;
class COMXCoreTunel
{
public:
COMXCoreTunel();
~COMXCoreTunel();
void Initialize(COMXCoreComponent *src_component, unsigned int src_port, COMXCoreComponent *dst_component, unsigned int dst_port);
OMX_ERRORTYPE Flush();
OMX_ERRORTYPE Deestablish(bool noWait = false);
OMX_ERRORTYPE Establish(bool portSettingsChanged);
private:
pthread_mutex_t m_lock;
bool m_portSettingsChanged;
COMXCoreComponent *m_src_component;
COMXCoreComponent *m_dst_component;
unsigned int m_src_port;
unsigned int m_dst_port;
DllOMX *m_DllOMX;
bool m_DllOMXOpen;
void Lock();
void UnLock();
};
class COMXCoreComponent
{
public:
COMXCoreComponent();
~COMXCoreComponent();
OMX_HANDLETYPE GetComponent() { return m_handle; };
unsigned int GetInputPort() { return m_input_port; };
unsigned int GetOutputPort() { return m_output_port; };
std::string GetName() { return m_componentName; };
OMX_ERRORTYPE DisableAllPorts();
void Remove(OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2);
OMX_ERRORTYPE AddEvent(OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2);
OMX_ERRORTYPE WaitForEvent(OMX_EVENTTYPE event, long timeout = 300);
OMX_ERRORTYPE WaitForCommand(OMX_U32 command, OMX_U32 nData2, long timeout = 2000);
OMX_ERRORTYPE SetStateForComponent(OMX_STATETYPE state);
OMX_STATETYPE GetState();
OMX_ERRORTYPE SetParameter(OMX_INDEXTYPE paramIndex, OMX_PTR paramStruct);
OMX_ERRORTYPE GetParameter(OMX_INDEXTYPE paramIndex, OMX_PTR paramStruct);
OMX_ERRORTYPE SetConfig(OMX_INDEXTYPE configIndex, OMX_PTR configStruct);
OMX_ERRORTYPE GetConfig(OMX_INDEXTYPE configIndex, OMX_PTR configStruct);
OMX_ERRORTYPE SendCommand(OMX_COMMANDTYPE cmd, OMX_U32 cmdParam, OMX_PTR cmdParamData);
OMX_ERRORTYPE EnablePort(unsigned int port, bool wait = true);
OMX_ERRORTYPE DisablePort(unsigned int port, bool wait = true);
OMX_ERRORTYPE UseEGLImage(OMX_BUFFERHEADERTYPE** ppBufferHdr, OMX_U32 nPortIndex, OMX_PTR pAppPrivate, void* eglImage);
bool Initialize( const std::string &component_name, OMX_INDEXTYPE index);
bool Deinitialize();
// OMXCore Decoder delegate callback routines.
static OMX_ERRORTYPE DecoderEventHandlerCallback(OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData);
static OMX_ERRORTYPE DecoderEmptyBufferDoneCallback(
OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer);
static OMX_ERRORTYPE DecoderFillBufferDoneCallback(
OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBufferHeader);
// OMXCore decoder callback routines.
OMX_ERRORTYPE DecoderEventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData);
OMX_ERRORTYPE DecoderEmptyBufferDone(
OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer);
OMX_ERRORTYPE DecoderFillBufferDone(
OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer);
OMX_ERRORTYPE EmptyThisBuffer(OMX_BUFFERHEADERTYPE *omx_buffer);
OMX_ERRORTYPE FillThisBuffer(OMX_BUFFERHEADERTYPE *omx_buffer);
OMX_ERRORTYPE FreeOutputBuffer(OMX_BUFFERHEADERTYPE *omx_buffer);
unsigned int GetInputBufferSize();
unsigned int GetOutputBufferSize();
unsigned int GetInputBufferSpace();
unsigned int GetOutputBufferSpace();
void FlushAll();
void FlushInput();
void FlushOutput();
OMX_BUFFERHEADERTYPE *GetInputBuffer(long timeout=200);
OMX_BUFFERHEADERTYPE *GetOutputBuffer();
OMX_ERRORTYPE AllocInputBuffers(bool use_buffers = false);
OMX_ERRORTYPE AllocOutputBuffers(bool use_buffers = false);
OMX_ERRORTYPE FreeInputBuffers(bool wait);
OMX_ERRORTYPE FreeOutputBuffers(bool wait);
bool IsEOS() { return m_eos; };
void SetCustomDecoderFillBufferDoneHandler(OMX_ERRORTYPE (*p)(OMX_HANDLETYPE, OMX_PTR, OMX_BUFFERHEADERTYPE*)){ CustomDecoderFillBufferDoneHandler = p;};
void SetCustomDecoderEmptyBufferDoneHandler(OMX_ERRORTYPE (*p)(OMX_HANDLETYPE, OMX_PTR, OMX_BUFFERHEADERTYPE*)){ CustomDecoderEmptyBufferDoneHandler = p;};
private:
OMX_HANDLETYPE m_handle;
unsigned int m_input_port;
unsigned int m_output_port;
std::string m_componentName;
pthread_mutex_t m_omx_event_mutex;
pthread_mutex_t m_lock;
std::vector<omx_event> m_omx_events;
OMX_CALLBACKTYPE m_callbacks;
//additional event handlers
OMX_ERRORTYPE (*CustomDecoderFillBufferDoneHandler)(OMX_HANDLETYPE, OMX_PTR, OMX_BUFFERHEADERTYPE*);
OMX_ERRORTYPE (*CustomDecoderEmptyBufferDoneHandler)(OMX_HANDLETYPE, OMX_PTR, OMX_BUFFERHEADERTYPE*);
// OMXCore input buffers (demuxer packets)
pthread_mutex_t m_omx_input_mutex;
std::queue<OMX_BUFFERHEADERTYPE*> m_omx_input_avaliable;
std::vector<OMX_BUFFERHEADERTYPE*> m_omx_input_buffers;
unsigned int m_input_alignment;
unsigned int m_input_buffer_size;
unsigned int m_input_buffer_count;
bool m_omx_input_use_buffers;
// OMXCore output buffers (video frames)
pthread_mutex_t m_omx_output_mutex;
std::queue<OMX_BUFFERHEADERTYPE*> m_omx_output_available;
std::vector<OMX_BUFFERHEADERTYPE*> m_omx_output_buffers;
unsigned int m_output_alignment;
unsigned int m_output_buffer_size;
unsigned int m_output_buffer_count;
bool m_omx_output_use_buffers;
sem_t m_omx_fill_buffer_done;
bool m_exit;
DllOMX *m_DllOMX;
bool m_DllOMXOpen;
pthread_cond_t m_input_buffer_cond;
pthread_cond_t m_output_buffer_cond;
pthread_cond_t m_omx_event_cond;
bool m_eos;
bool m_flush_input;
bool m_flush_output;
void Lock();
void UnLock();
};
class COMXCore
{
public:
COMXCore();
~COMXCore();
// initialize OMXCore and get decoder component
bool Initialize();
void Deinitialize();
protected:
bool m_is_open;
bool m_Initialized;
DllOMX *m_DllOMX;
};
#endif