• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Intel Corporation.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 
19 #ifndef ISV_OMXCOMPONENT_H_
20 
21 #define ISV_OMXCOMPONENT_H_
22 
23 #include <utils/Mutex.h>
24 #include <utils/Vector.h>
25 #include <utils/RefBase.h>
26 #include "isv_omxcore.h"
27 #include "isv_processor.h"
28 #include "isv_profile.h"
29 #include "isv_worker.h"
30 #include "isv_bufmanager.h"
31 
32 #define ISV_COMPONENT_DEBUG 0
33 
34 #ifdef TARGET_VPP_USE_GEN
35 #define MIN_INPUT_NUM           (3)
36 #define MIN_OUTPUT_NUM          (3)
37 #else
38 #define MIN_INPUT_NUM           (4)    // forward reference frame number is 3 for merrifield/moorefield
39 #define MIN_OUTPUT_NUM          (10)   // 2.5FRC need hold 2 + 3 + 2 + 3= 10 buffers, without FRC we set to 6
40 #endif
41 #define MIN_ISV_BUFFER_NUM      ((MIN_OUTPUT_NUM) + (MIN_INPUT_NUM))
42 #define UNDEQUEUED_NUM          (4)   // display system hold 4 buffers
43 
44 using namespace android;
45 class ISVComponent;
46 
47 class ISVProcThreadObserver: public ISVProcessorObserver
48 {
49 public:
50     ISVProcThreadObserver(OMX_COMPONENTTYPE *pBaseComponent, OMX_COMPONENTTYPE *pComponent, OMX_CALLBACKTYPE *pCallBacks, sp<ISVBufferManager> bufferManager);
51     ~ISVProcThreadObserver();
52 
53     virtual OMX_ERRORTYPE releaseBuffer(PORT_INDEX index, OMX_BUFFERHEADERTYPE* pBuffer, bool flush);
54     virtual OMX_ERRORTYPE reportOutputCrop();
55 private:
56     OMX_COMPONENTTYPE *mBaseComponent;
57     OMX_COMPONENTTYPE *mComponent;
58     OMX_CALLBACKTYPE *mpCallBacks;
59     sp<ISVBufferManager> mISVBufferManager;
60 };
61 
62 class ISVComponent //: public RefBase
63 {
64 public:
65     /*
66      * construct & destruct
67      */
68     ISVComponent(OMX_PTR);
69     ~ISVComponent();
70 
71     // replace component callbacks
72     OMX_CALLBACKTYPE *getCallBacks(OMX_CALLBACKTYPE*);
73     // pass down the real component&core
setComponent(OMX_COMPONENTTYPE * pComp,ISVOMXCore * pCore)74     void setComponent(OMX_COMPONENTTYPE *pComp, ISVOMXCore *pCore){mComponent = pComp; mCore = pCore;return;}
75     // free the real component
freeComponent()76     OMX_ERRORTYPE freeComponent(){return (*(mCore->mFreeHandle))(static_cast<OMX_HANDLETYPE>(mComponent));}
77     // return ISV component handle
getBaseComponent()78     OMX_COMPONENTTYPE *getBaseComponent(){return &mBaseComponent;}
79 
80     static Vector<ISVComponent*> g_isv_components;
81 private:
82     /*
83      * component methods & helpers
84      */
85 
86     static OMX_ERRORTYPE SendCommand(
87         OMX_IN  OMX_HANDLETYPE hComponent,
88         OMX_IN  OMX_COMMANDTYPE Cmd,
89         OMX_IN  OMX_U32 nParam1,
90         OMX_IN  OMX_PTR pCmdData);
91     OMX_ERRORTYPE ISV_SendCommand(
92         OMX_IN  OMX_COMMANDTYPE Cmd,
93         OMX_IN  OMX_U32 nParam1,
94         OMX_IN  OMX_PTR pCmdData);
95 
96     static OMX_ERRORTYPE GetParameter(
97         OMX_IN  OMX_HANDLETYPE hComponent,
98         OMX_IN  OMX_INDEXTYPE nParamIndex,
99         OMX_INOUT OMX_PTR pComponentParameterStructure);
100     OMX_ERRORTYPE ISV_GetParameter(
101         OMX_IN  OMX_INDEXTYPE nParamIndex,
102         OMX_INOUT OMX_PTR pComponentParameterStructure);
103 
104     static OMX_ERRORTYPE SetParameter(
105         OMX_IN  OMX_HANDLETYPE hComponent,
106         OMX_IN  OMX_INDEXTYPE nIndex,
107         OMX_IN  OMX_PTR pComponentParameterStructure);
108     OMX_ERRORTYPE ISV_SetParameter(
109         OMX_IN  OMX_INDEXTYPE nIndex,
110         OMX_IN  OMX_PTR pComponentParameterStructure);
111 
112     static OMX_ERRORTYPE GetConfig(
113         OMX_IN  OMX_HANDLETYPE hComponent,
114         OMX_IN  OMX_INDEXTYPE nIndex,
115         OMX_INOUT OMX_PTR pComponentConfigStructure);
116     OMX_ERRORTYPE ISV_GetConfig(
117         OMX_IN  OMX_INDEXTYPE nIndex,
118         OMX_INOUT OMX_PTR pComponentConfigStructure);
119 
120     static OMX_ERRORTYPE SetConfig(
121         OMX_IN  OMX_HANDLETYPE hComponent,
122         OMX_IN  OMX_INDEXTYPE nIndex,
123         OMX_IN  OMX_PTR pComponentConfigStructure);
124     OMX_ERRORTYPE ISV_SetConfig(
125         OMX_IN  OMX_INDEXTYPE nIndex,
126         OMX_IN  OMX_PTR pComponentConfigStructure);
127 
128     static OMX_ERRORTYPE GetExtensionIndex(
129         OMX_IN  OMX_HANDLETYPE hComponent,
130         OMX_IN  OMX_STRING cParameterName,
131         OMX_OUT OMX_INDEXTYPE* pIndexType);
132     OMX_ERRORTYPE ISV_GetExtensionIndex(
133         OMX_IN  OMX_STRING cParameterName,
134         OMX_OUT OMX_INDEXTYPE* pIndexType);
135 
136     static OMX_ERRORTYPE GetState(
137         OMX_IN  OMX_HANDLETYPE hComponent,
138         OMX_OUT OMX_STATETYPE* pState);
139     OMX_ERRORTYPE ISV_GetState(
140         OMX_OUT OMX_STATETYPE* pState);
141 
142     static OMX_ERRORTYPE UseBuffer(
143         OMX_IN OMX_HANDLETYPE hComponent,
144         OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
145         OMX_IN OMX_U32 nPortIndex,
146         OMX_IN OMX_PTR pAppPrivate,
147         OMX_IN OMX_U32 nSizeBytes,
148         OMX_IN OMX_U8* pBuffer);
149     OMX_ERRORTYPE ISV_UseBuffer(
150         OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
151         OMX_IN OMX_U32 nPortIndex,
152         OMX_IN OMX_PTR pAppPrivate,
153         OMX_IN OMX_U32 nSizeBytes,
154         OMX_IN OMX_U8* pBuffer);
155 
156     static OMX_ERRORTYPE AllocateBuffer(
157         OMX_IN OMX_HANDLETYPE hComponent,
158         OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
159         OMX_IN OMX_U32 nPortIndex,
160         OMX_IN OMX_PTR pAppPrivate,
161         OMX_IN OMX_U32 nSizeBytes);
162     OMX_ERRORTYPE ISV_AllocateBuffer(
163         OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
164         OMX_IN OMX_U32 nPortIndex,
165         OMX_IN OMX_PTR pAppPrivate,
166         OMX_IN OMX_U32 nSizeBytes);
167 
168     static OMX_ERRORTYPE FreeBuffer(
169         OMX_IN  OMX_HANDLETYPE hComponent,
170         OMX_IN  OMX_U32 nPortIndex,
171         OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
172     OMX_ERRORTYPE ISV_FreeBuffer(
173         OMX_IN  OMX_U32 nPortIndex,
174         OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
175 
176     static OMX_ERRORTYPE EmptyThisBuffer(
177         OMX_IN  OMX_HANDLETYPE hComponent,
178         OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
179     OMX_ERRORTYPE ISV_EmptyThisBuffer(
180         OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
181 
182     static OMX_ERRORTYPE FillThisBuffer(
183         OMX_IN  OMX_HANDLETYPE hComponent,
184         OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
185     OMX_ERRORTYPE ISV_FillThisBuffer(
186         OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
187 
188     static OMX_ERRORTYPE SetCallbacks(
189         OMX_IN  OMX_HANDLETYPE hComponent,
190         OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
191         OMX_IN  OMX_PTR pAppData);
192     OMX_ERRORTYPE ISV_SetCallbacks(
193         OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
194         OMX_IN  OMX_PTR pAppData);
195 
196     static OMX_ERRORTYPE ComponentRoleEnum(
197         OMX_IN OMX_HANDLETYPE hComponent,
198         OMX_OUT OMX_U8 *cRole,
199         OMX_IN OMX_U32 nIndex);
200     OMX_ERRORTYPE ISV_ComponentRoleEnum(
201         OMX_OUT OMX_U8 *cRole,
202         OMX_IN OMX_U32 nIndex);
203 
204     static OMX_ERRORTYPE FillBufferDone(
205         OMX_OUT OMX_HANDLETYPE hComponent,
206         OMX_OUT OMX_PTR pAppData,
207         OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer);
208     OMX_ERRORTYPE ISV_FillBufferDone(
209         OMX_OUT OMX_HANDLETYPE hComponent,
210         OMX_OUT OMX_PTR pAppData,
211         OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer);
212 
213     static OMX_ERRORTYPE EventHandler(
214             OMX_IN OMX_HANDLETYPE hComponent,
215             OMX_IN OMX_PTR pAppData,
216             OMX_IN OMX_EVENTTYPE eEvent,
217             OMX_IN OMX_U32 nData1,
218             OMX_IN OMX_U32 nData2,
219             OMX_IN OMX_PTR pEventData);
220     OMX_ERRORTYPE ISV_EventHandler(
221             OMX_IN OMX_HANDLETYPE hComponent,
222             OMX_IN OMX_PTR pAppData,
223             OMX_IN OMX_EVENTTYPE eEvent,
224             OMX_IN OMX_U32 nData1,
225             OMX_IN OMX_U32 nData2,
226             OMX_IN OMX_PTR pEventData);
227     /* end of component methods & helpers */
228 
229     void SetTypeHeader(OMX_PTR type, OMX_U32 size);
230 
231     // init & deinit functions
232     status_t init(int32_t width, int32_t height);
233     void deinit();
234 
235     const static OMX_U8 OMX_SPEC_VERSION_MAJOR = 1;
236     const static OMX_U8 OMX_SPEC_VERSION_MINOR = 0;
237     const static OMX_U8 OMX_SPEC_VERSION_REVISION = 0;
238     const static OMX_U8 OMX_SPEC_VERSION_STEP = 0;
239 
240     const static OMX_U32 OMX_SPEC_VERSION = 0
241         | (OMX_SPEC_VERSION_MAJOR << 0)
242         | (OMX_SPEC_VERSION_MINOR << 8)
243         | (OMX_SPEC_VERSION_REVISION << 16)
244         | (OMX_SPEC_VERSION_STEP << 24);
245 
246     typedef enum OMX_ISVINDEXEXTTYPE {
247         OMX_IndexISVStartUsed = OMX_IndexVendorStartUnused + 0x0000F000,
248         OMX_IndexExtSetISVMode,                  /**< reference: OMX_U32 */
249     } OMX_ISVINDEXEXTTYPE;
250 
251     typedef enum {
252         ISV_DISABLE = 0,
253         ISV_AUTO,
254     } ISV_MODE;
255 
256 private:
257     OMX_COMPONENTTYPE mBaseComponent;  //returned by GetComponetHandle()
258     OMX_COMPONENTTYPE *mComponent;      // passed from the real OMX core
259     OMX_CALLBACKTYPE *mpCallBacks;
260     ISVOMXCore *mCore;                  // owend by mComponent
261     OMX_CALLBACKTYPE *mpISVCallBacks;
262 
263     // buffer manager
264     sp<ISVBufferManager> mISVBufferManager;
265 
266     bool mThreadRunning;
267 
268     // vpp thread observer
269     sp<ISVProcThreadObserver> mProcThreadObserver;
270 
271     // vpp input buffer count + output buffer count
272     int32_t mNumISVBuffers;
273     int32_t mNumDecoderBuffers;
274     int32_t mNumDecoderBuffersBak;
275     uint32_t mWidth;
276     uint32_t mHeight;
277     uint32_t mUseAndroidNativeBufferIndex;
278     uint32_t mStoreMetaDataInBuffersIndex;
279     uint32_t mHackFormat;
280 
281     bool mUseAndroidNativeBuffer;
282     bool mUseAndroidNativeBuffer2;
283 
284     bool mVPPEnabled;
285     bool mVPPOn;
286     bool mVPPFlushing;
287     bool mOutputCropChanged;
288     bool mInitialized;
289 #ifdef TARGET_VPP_USE_GEN
290     // vpp thread
291     sp<ISVProcessor> mProcThread;
292 #else
293     static sp<ISVProcessor> mProcThread;
294 #endif
295     // protect create mProcThread instance
296     bool mOwnProcessor;
297     static pthread_mutex_t ProcThreadInstanceLock;
298 };
299 
300 #endif  // #define ISV_OMXCOMPONENT_H_
301