Commit | Line | Data |
---|---|---|
20d3e6e3 JC |
1 | /* |
2 | * | |
38ef2572 | 3 | * Copyright 2012 Samsung Electronics S.LSI Co. LTD |
20d3e6e3 JC |
4 | * |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | /* | |
19 | * @file Exynos_OMX_H264dec.c | |
20 | * @brief | |
21 | * @author SeungBeom Kim (sbcrux.kim@samsung.com) | |
38ef2572 | 22 | * @version 2.0.0 |
20d3e6e3 | 23 | * @history |
38ef2572 | 24 | * 2012.02.20 : Create |
20d3e6e3 JC |
25 | */ |
26 | ||
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | ||
31 | #include "Exynos_OMX_Macros.h" | |
32 | #include "Exynos_OMX_Basecomponent.h" | |
33 | #include "Exynos_OMX_Baseport.h" | |
34 | #include "Exynos_OMX_Vdec.h" | |
35 | #include "Exynos_OSAL_ETC.h" | |
36 | #include "Exynos_OSAL_Semaphore.h" | |
37 | #include "Exynos_OSAL_Thread.h" | |
38 | #include "library_register.h" | |
39 | #include "Exynos_OMX_H264dec.h" | |
40 | #include "ExynosVideoApi.h" | |
800a8d75 | 41 | #include "Exynos_OSAL_SharedMemory.h" |
38ef2572 | 42 | #include "Exynos_OSAL_Event.h" |
20d3e6e3 JC |
43 | |
44 | #ifdef USE_ANB | |
45 | #include "Exynos_OSAL_Android.h" | |
46 | #endif | |
47 | ||
38ef2572 | 48 | /* To use CSC_METHOD_HW in EXYNOS OMX, gralloc should allocate physical memory using FIMC */ |
20d3e6e3 JC |
49 | /* It means GRALLOC_USAGE_HW_FIMC1 should be set on Native Window usage */ |
50 | #include "csc.h" | |
51 | ||
52 | #undef EXYNOS_LOG_TAG | |
53 | #define EXYNOS_LOG_TAG "EXYNOS_H264_DEC" | |
54 | #define EXYNOS_LOG_OFF | |
38ef2572 | 55 | //#define EXYNOS_TRACE_ON |
20d3e6e3 JC |
56 | #include "Exynos_OSAL_Log.h" |
57 | ||
58 | #define H264_DEC_NUM_OF_EXTRA_BUFFERS 7 | |
59 | ||
38ef2572 | 60 | //#define ADD_SPS_PPS_I_FRAME |
20d3e6e3 JC |
61 | //#define FULL_FRAME_SEARCH |
62 | ||
63 | /* H.264 Decoder Supported Levels & profiles */ | |
64 | EXYNOS_OMX_VIDEO_PROFILELEVEL supportedAVCProfileLevels[] ={ | |
65 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1}, | |
66 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1b}, | |
67 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel11}, | |
68 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel12}, | |
69 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel13}, | |
70 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel2}, | |
71 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel21}, | |
72 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel22}, | |
73 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel3}, | |
74 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel31}, | |
75 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel32}, | |
76 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel4}, | |
800a8d75 JC |
77 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel41}, |
78 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel42}, | |
20d3e6e3 JC |
79 | |
80 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel1}, | |
81 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel1b}, | |
82 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel11}, | |
83 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel12}, | |
84 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel13}, | |
85 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel2}, | |
86 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel21}, | |
87 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel22}, | |
88 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel3}, | |
89 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel31}, | |
90 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel32}, | |
91 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel4}, | |
800a8d75 JC |
92 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel41}, |
93 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel42}, | |
20d3e6e3 JC |
94 | |
95 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel1}, | |
96 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel1b}, | |
97 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel11}, | |
98 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel12}, | |
99 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel13}, | |
100 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel2}, | |
101 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel21}, | |
102 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel22}, | |
103 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel3}, | |
104 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel31}, | |
105 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel32}, | |
800a8d75 JC |
106 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel4}, |
107 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel41}, | |
108 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel42}}; | |
20d3e6e3 | 109 | |
38ef2572 JC |
110 | static OMX_ERRORTYPE GetCodecInputPrivateData(OMX_PTR codecBuffer, void *pVirtAddr, OMX_U32 *dataSize) |
111 | { | |
112 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
113 | ||
114 | EXIT: | |
115 | return ret; | |
116 | } | |
117 | ||
118 | static OMX_ERRORTYPE GetCodecOutputPrivateData(OMX_PTR codecBuffer, void *addr[], int size[]) | |
119 | { | |
120 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
121 | ExynosVideoBuffer *pCodecBuffer; | |
122 | ||
123 | if (codecBuffer == NULL) { | |
124 | ret = OMX_ErrorBadParameter; | |
125 | goto EXIT; | |
126 | } | |
127 | ||
128 | pCodecBuffer = (ExynosVideoBuffer *)codecBuffer; | |
129 | ||
130 | if (addr != NULL) { | |
131 | addr[0] = pCodecBuffer->planes[0].addr; | |
132 | addr[1] = pCodecBuffer->planes[1].addr; | |
133 | addr[2] = pCodecBuffer->planes[2].addr; | |
134 | } | |
135 | ||
136 | if (size != NULL) { | |
137 | size[0] = pCodecBuffer->planes[0].allocSize; | |
138 | size[1] = pCodecBuffer->planes[1].allocSize; | |
139 | size[2] = pCodecBuffer->planes[2].allocSize; | |
140 | } | |
141 | ||
142 | EXIT: | |
143 | return ret; | |
144 | } | |
20d3e6e3 | 145 | |
800a8d75 | 146 | int Check_H264_Frame( |
20d3e6e3 JC |
147 | OMX_U8 *pInputStream, |
148 | OMX_U32 buffSize, | |
149 | OMX_U32 flag, | |
150 | OMX_BOOL bPreviousFrameEOF, | |
151 | OMX_BOOL *pbEndOfFrame) | |
152 | { | |
153 | OMX_U32 preFourByte = (OMX_U32)-1; | |
154 | int accessUnitSize = 0; | |
155 | int frameTypeBoundary = 0; | |
156 | int nextNaluSize = 0; | |
157 | int naluStart = 0; | |
158 | ||
159 | if (bPreviousFrameEOF == OMX_TRUE) | |
160 | naluStart = 0; | |
161 | else | |
162 | naluStart = 1; | |
163 | ||
164 | while (1) { | |
165 | int inputOneByte = 0; | |
166 | ||
167 | if (accessUnitSize == (int)buffSize) | |
168 | goto EXIT; | |
169 | ||
170 | inputOneByte = *(pInputStream++); | |
171 | accessUnitSize += 1; | |
172 | ||
173 | if (preFourByte == 0x00000001 || (preFourByte << 8) == 0x00000100) { | |
174 | int naluType = inputOneByte & 0x1F; | |
175 | ||
176 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NaluType : %d", naluType); | |
177 | if (naluStart == 0) { | |
178 | #ifdef ADD_SPS_PPS_I_FRAME | |
179 | if (naluType == 1 || naluType == 5) | |
180 | #else | |
181 | if (naluType == 1 || naluType == 5 || naluType == 7 || naluType == 8) | |
182 | #endif | |
183 | naluStart = 1; | |
184 | } else { | |
185 | #ifdef OLD_DETECT | |
186 | frameTypeBoundary = (8 - naluType) & (naluType - 10); //AUD(9) | |
187 | #else | |
188 | if (naluType == 9) | |
189 | frameTypeBoundary = -2; | |
190 | #endif | |
191 | if (naluType == 1 || naluType == 5) { | |
192 | if (accessUnitSize == (int)buffSize) { | |
193 | accessUnitSize--; | |
194 | goto EXIT; | |
195 | } | |
196 | inputOneByte = *pInputStream++; | |
197 | accessUnitSize += 1; | |
198 | ||
199 | if (inputOneByte >= 0x80) | |
200 | frameTypeBoundary = -1; | |
201 | } | |
202 | if (frameTypeBoundary < 0) { | |
203 | break; | |
204 | } | |
205 | } | |
206 | ||
207 | } | |
208 | preFourByte = (preFourByte << 8) + inputOneByte; | |
209 | } | |
210 | ||
211 | *pbEndOfFrame = OMX_TRUE; | |
212 | nextNaluSize = -5; | |
213 | if (frameTypeBoundary == -1) | |
214 | nextNaluSize = -6; | |
215 | if (preFourByte != 0x00000001) | |
216 | nextNaluSize++; | |
217 | return (accessUnitSize + nextNaluSize); | |
218 | ||
219 | EXIT: | |
220 | *pbEndOfFrame = OMX_FALSE; | |
221 | ||
222 | return accessUnitSize; | |
223 | } | |
224 | ||
800a8d75 | 225 | static OMX_BOOL Check_H264_StartCode( |
20d3e6e3 JC |
226 | OMX_U8 *pInputStream, |
227 | OMX_U32 streamSize) | |
228 | { | |
229 | if (streamSize < 4) { | |
230 | return OMX_FALSE; | |
38ef2572 JC |
231 | } |
232 | ||
233 | if ((pInputStream[0] == 0x00) && | |
234 | (pInputStream[1] == 0x00) && | |
235 | (pInputStream[2] == 0x00) && | |
236 | (pInputStream[3] != 0x00) && | |
237 | ((pInputStream[3] >> 3) == 0x00)) { | |
238 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NaluType : %d, 0x%x, 0x%x, 0x%x", (pInputStream[4] & 0x1F), pInputStream[3], pInputStream[4], pInputStream[5]); | |
20d3e6e3 JC |
239 | return OMX_TRUE; |
240 | } else if ((pInputStream[0] == 0x00) && | |
38ef2572 JC |
241 | (pInputStream[1] == 0x00) && |
242 | (pInputStream[2] != 0x00) && | |
243 | ((pInputStream[2] >> 3) == 0x00)) { | |
244 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NaluType : %d, 0x%x, 0x%x, 0x%x", (pInputStream[3] & 0x1F), pInputStream[2], pInputStream[3], pInputStream[4]); | |
20d3e6e3 JC |
245 | return OMX_TRUE; |
246 | } else { | |
247 | return OMX_FALSE; | |
248 | } | |
249 | } | |
250 | ||
38ef2572 JC |
251 | OMX_ERRORTYPE H264CodecOpen(EXYNOS_H264DEC_HANDLE *pH264Dec) |
252 | { | |
3e79a27e | 253 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
38ef2572 JC |
254 | ExynosVideoDecOps *pDecOps = NULL; |
255 | ExynosVideoDecBufferOps *pInbufOps = NULL; | |
256 | ExynosVideoDecBufferOps *pOutbufOps = NULL; | |
257 | ||
258 | FunctionIn(); | |
259 | ||
260 | if (pH264Dec == NULL) { | |
261 | ret = OMX_ErrorBadParameter; | |
262 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); | |
263 | goto EXIT; | |
264 | } | |
265 | ||
38ef2572 JC |
266 | /* alloc ops structure */ |
267 | pDecOps = (ExynosVideoDecOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecOps)); | |
268 | pInbufOps = (ExynosVideoDecBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecBufferOps)); | |
269 | pOutbufOps = (ExynosVideoDecBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecBufferOps)); | |
270 | ||
271 | if ((pDecOps == NULL) || (pInbufOps == NULL) || (pOutbufOps == NULL)) { | |
272 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate decoder ops buffer"); | |
273 | ret = OMX_ErrorInsufficientResources; | |
274 | goto EXIT; | |
275 | } | |
276 | ||
277 | pH264Dec->hMFCH264Handle.pDecOps = pDecOps; | |
278 | pH264Dec->hMFCH264Handle.pInbufOps = pInbufOps; | |
279 | pH264Dec->hMFCH264Handle.pOutbufOps = pOutbufOps; | |
280 | ||
281 | /* function pointer mapping */ | |
282 | pDecOps->nSize = sizeof(ExynosVideoDecOps); | |
283 | pInbufOps->nSize = sizeof(ExynosVideoDecBufferOps); | |
284 | pOutbufOps->nSize = sizeof(ExynosVideoDecBufferOps); | |
285 | ||
286 | Exynos_Video_Register_Decoder(pDecOps, pInbufOps, pOutbufOps); | |
3e79a27e | 287 | |
38ef2572 JC |
288 | /* check mandatory functions for decoder ops */ |
289 | if ((pDecOps->Init == NULL) || (pDecOps->Finalize == NULL) || | |
290 | (pDecOps->Get_ActualBufferCount == NULL) || (pDecOps->Set_FrameTag == NULL) || | |
291 | (pDecOps->Get_FrameTag == NULL)) { | |
292 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied"); | |
293 | ret = OMX_ErrorInsufficientResources; | |
294 | goto EXIT; | |
295 | } | |
296 | ||
297 | /* check mandatory functions for buffer ops */ | |
298 | if ((pInbufOps->Setup == NULL) || (pOutbufOps->Setup == NULL) || | |
299 | (pInbufOps->Run == NULL) || (pOutbufOps->Run == NULL) || | |
300 | (pInbufOps->Stop == NULL) || (pOutbufOps->Stop == NULL) || | |
301 | (pInbufOps->Enqueue == NULL) || (pOutbufOps->Enqueue == NULL) || | |
302 | (pInbufOps->Dequeue == NULL) || (pOutbufOps->Dequeue == NULL)) { | |
303 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied"); | |
304 | ret = OMX_ErrorInsufficientResources; | |
305 | goto EXIT; | |
306 | } | |
307 | ||
308 | /* alloc context, open, querycap */ | |
c94beaeb | 309 | pH264Dec->hMFCH264Handle.hMFCHandle = pH264Dec->hMFCH264Handle.pDecOps->Init(V4L2_MEMORY_DMABUF); |
38ef2572 JC |
310 | if (pH264Dec->hMFCH264Handle.hMFCHandle == NULL) { |
311 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); | |
312 | ret = OMX_ErrorInsufficientResources; | |
313 | goto EXIT; | |
314 | } | |
315 | ||
316 | ret = OMX_ErrorNone; | |
317 | ||
318 | EXIT: | |
44025235 SK |
319 | if (ret != OMX_ErrorNone) { |
320 | if (pDecOps != NULL) { | |
321 | Exynos_OSAL_Free(pDecOps); | |
322 | pH264Dec->hMFCH264Handle.pDecOps = NULL; | |
323 | } | |
324 | if (pInbufOps != NULL) { | |
325 | Exynos_OSAL_Free(pInbufOps); | |
326 | pH264Dec->hMFCH264Handle.pInbufOps = NULL; | |
327 | } | |
328 | if (pOutbufOps != NULL) { | |
329 | Exynos_OSAL_Free(pOutbufOps); | |
330 | pH264Dec->hMFCH264Handle.pOutbufOps = NULL; | |
331 | } | |
332 | } | |
333 | ||
38ef2572 JC |
334 | FunctionOut(); |
335 | ||
336 | return ret; | |
337 | } | |
338 | ||
339 | OMX_ERRORTYPE H264CodecClose(EXYNOS_H264DEC_HANDLE *pH264Dec) | |
340 | { | |
341 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
342 | void *hMFCHandle = NULL; | |
343 | ExynosVideoDecOps *pDecOps = NULL; | |
344 | ExynosVideoDecBufferOps *pInbufOps = NULL; | |
345 | ExynosVideoDecBufferOps *pOutbufOps = NULL; | |
346 | ||
3e79a27e SK |
347 | FunctionIn(); |
348 | ||
38ef2572 JC |
349 | if (pH264Dec == NULL) { |
350 | ret = OMX_ErrorBadParameter; | |
351 | goto EXIT; | |
352 | } | |
353 | ||
354 | hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
355 | pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
356 | pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
357 | pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
358 | ||
359 | if (hMFCHandle != NULL) { | |
360 | pDecOps->Finalize(hMFCHandle); | |
3e79a27e | 361 | pH264Dec->hMFCH264Handle.hMFCHandle = NULL; |
38ef2572 JC |
362 | } |
363 | if (pOutbufOps != NULL) { | |
364 | Exynos_OSAL_Free(pOutbufOps); | |
3e79a27e | 365 | pH264Dec->hMFCH264Handle.pOutbufOps = NULL; |
38ef2572 JC |
366 | } |
367 | if (pInbufOps != NULL) { | |
368 | Exynos_OSAL_Free(pInbufOps); | |
3e79a27e | 369 | pH264Dec->hMFCH264Handle.pInbufOps = NULL; |
38ef2572 JC |
370 | } |
371 | if (pDecOps != NULL) { | |
372 | Exynos_OSAL_Free(pDecOps); | |
3e79a27e | 373 | pH264Dec->hMFCH264Handle.pDecOps = NULL; |
38ef2572 JC |
374 | } |
375 | ||
376 | ret = OMX_ErrorNone; | |
377 | ||
378 | EXIT: | |
379 | FunctionOut(); | |
380 | ||
381 | return ret; | |
382 | } | |
383 | ||
384 | OMX_ERRORTYPE H264CodecStart(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) | |
385 | { | |
386 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
387 | void *hMFCHandle = NULL; | |
388 | ExynosVideoDecOps *pDecOps = NULL; | |
389 | ExynosVideoDecBufferOps *pInbufOps = NULL; | |
390 | ExynosVideoDecBufferOps *pOutbufOps = NULL; | |
391 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
392 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
393 | ||
3e79a27e SK |
394 | FunctionIn(); |
395 | ||
38ef2572 JC |
396 | if (pOMXComponent == NULL) { |
397 | ret = OMX_ErrorBadParameter; | |
398 | goto EXIT; | |
399 | } | |
400 | ||
401 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle; | |
402 | if (pVideoDec == NULL) { | |
403 | ret = OMX_ErrorBadParameter; | |
404 | goto EXIT; | |
405 | } | |
3e79a27e | 406 | |
38ef2572 JC |
407 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle; |
408 | if (pH264Dec == NULL) { | |
409 | ret = OMX_ErrorBadParameter; | |
410 | goto EXIT; | |
411 | } | |
412 | ||
413 | hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
414 | pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
415 | pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
416 | pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
417 | ||
418 | if (nPortIndex == INPUT_PORT_INDEX) | |
419 | pInbufOps->Run(hMFCHandle); | |
420 | else if (nPortIndex == OUTPUT_PORT_INDEX) | |
421 | pOutbufOps->Run(hMFCHandle); | |
422 | ||
38ef2572 JC |
423 | ret = OMX_ErrorNone; |
424 | ||
425 | EXIT: | |
426 | FunctionOut(); | |
427 | ||
428 | return ret; | |
429 | } | |
430 | ||
431 | OMX_ERRORTYPE H264CodecStop(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) | |
432 | { | |
433 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
434 | void *hMFCHandle = NULL; | |
435 | ExynosVideoDecOps *pDecOps = NULL; | |
436 | ExynosVideoDecBufferOps *pInbufOps = NULL; | |
437 | ExynosVideoDecBufferOps *pOutbufOps = NULL; | |
438 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
439 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
440 | ||
3e79a27e SK |
441 | FunctionIn(); |
442 | ||
38ef2572 JC |
443 | if (pOMXComponent == NULL) { |
444 | ret = OMX_ErrorBadParameter; | |
445 | goto EXIT; | |
446 | } | |
447 | ||
448 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle; | |
449 | if (pVideoDec == NULL) { | |
450 | ret = OMX_ErrorBadParameter; | |
451 | goto EXIT; | |
452 | } | |
453 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle; | |
454 | if (pH264Dec == NULL) { | |
455 | ret = OMX_ErrorBadParameter; | |
456 | goto EXIT; | |
457 | } | |
458 | ||
459 | hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
460 | pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
461 | pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
462 | pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
463 | ||
464 | if ((nPortIndex == INPUT_PORT_INDEX) && (pInbufOps != NULL)) | |
465 | pInbufOps->Stop(hMFCHandle); | |
466 | else if ((nPortIndex == OUTPUT_PORT_INDEX) && (pOutbufOps != NULL)) | |
467 | pOutbufOps->Stop(hMFCHandle); | |
468 | ||
469 | ret = OMX_ErrorNone; | |
470 | ||
471 | EXIT: | |
472 | FunctionOut(); | |
473 | ||
474 | return ret; | |
475 | } | |
476 | ||
477 | OMX_ERRORTYPE H264CodecOutputBufferProcessRun(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) | |
478 | { | |
479 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
480 | void *hMFCHandle = NULL; | |
481 | ExynosVideoDecOps *pDecOps = NULL; | |
482 | ExynosVideoDecBufferOps *pInbufOps = NULL; | |
483 | ExynosVideoDecBufferOps *pOutbufOps = NULL; | |
484 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
485 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
486 | ||
487 | FunctionIn(); | |
488 | ||
489 | if (pOMXComponent == NULL) { | |
490 | ret = OMX_ErrorBadParameter; | |
491 | goto EXIT; | |
492 | } | |
493 | ||
494 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle; | |
495 | if (pVideoDec == NULL) { | |
496 | ret = OMX_ErrorBadParameter; | |
497 | goto EXIT; | |
498 | } | |
499 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle; | |
500 | if (pH264Dec == NULL) { | |
501 | ret = OMX_ErrorBadParameter; | |
502 | goto EXIT; | |
503 | } | |
504 | ||
505 | hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
506 | pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
507 | pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
508 | pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
509 | ||
510 | if (nPortIndex == INPUT_PORT_INDEX) { | |
511 | if (pH264Dec->bSourceStart == OMX_FALSE) { | |
512 | Exynos_OSAL_SignalSet(pH264Dec->hSourceStartEvent); | |
513 | Exynos_OSAL_SleepMillisec(0); | |
514 | } | |
515 | } | |
516 | ||
517 | if (nPortIndex == OUTPUT_PORT_INDEX) { | |
518 | if (pH264Dec->bDestinationStart == OMX_FALSE) { | |
519 | Exynos_OSAL_SignalSet(pH264Dec->hDestinationStartEvent); | |
520 | Exynos_OSAL_SleepMillisec(0); | |
521 | } | |
522 | } | |
523 | ||
524 | ret = OMX_ErrorNone; | |
525 | ||
526 | EXIT: | |
527 | FunctionOut(); | |
528 | ||
529 | return ret; | |
530 | } | |
531 | ||
532 | OMX_ERRORTYPE H264CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) | |
800a8d75 | 533 | { |
38ef2572 | 534 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
800a8d75 | 535 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
38ef2572 JC |
536 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; |
537 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
538 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
539 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
540 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
541 | int i, nOutbufs; | |
38ef2572 JC |
542 | |
543 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
544 | ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
545 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
800a8d75 JC |
546 | |
547 | FunctionIn(); | |
548 | ||
38ef2572 JC |
549 | if ((nPortIndex == INPUT_PORT_INDEX) && |
550 | (pH264Dec->bSourceStart == OMX_TRUE)) { | |
551 | Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); | |
552 | ||
553 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { | |
554 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]); | |
555 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->VirAddr: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]->VirAddr); | |
556 | ||
557 | Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]); | |
558 | } | |
559 | ||
560 | pInbufOps->Clear_Queue(hMFCHandle); | |
561 | } else if ((nPortIndex == OUTPUT_PORT_INDEX) && | |
562 | (pH264Dec->bDestinationStart == OMX_TRUE)) { | |
563 | OMX_U32 dataLen[2] = {0, 0}; | |
564 | ExynosVideoBuffer *pBuffer = NULL; | |
565 | ||
566 | Exynos_CodecBufferReset(pExynosComponent, OUTPUT_PORT_INDEX); | |
567 | ||
568 | nOutbufs = pDecOps->Get_ActualBufferCount(hMFCHandle); | |
569 | nOutbufs += EXTRA_DPB_NUM; | |
570 | for (i = 0; i < nOutbufs; i++) { | |
571 | pOutbufOps->Get_Buffer(hMFCHandle, i, &pBuffer); | |
572 | Exynos_CodecBufferEnQueue(pExynosComponent, OUTPUT_PORT_INDEX, (OMX_PTR)pBuffer); | |
573 | } | |
574 | pOutbufOps->Clear_Queue(hMFCHandle); | |
575 | } else { | |
576 | ret = OMX_ErrorBadParameter; | |
577 | goto EXIT; | |
578 | } | |
579 | ||
580 | EXIT: | |
581 | FunctionOut(); | |
582 | ||
583 | return ret; | |
584 | } | |
585 | ||
586 | OMX_ERRORTYPE H264CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData) | |
587 | { | |
588 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
589 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
590 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
591 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
592 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
593 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
594 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
595 | OMX_U32 oneFrameSize = pSrcInputData->dataLen; | |
38ef2572 JC |
596 | |
597 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
598 | ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
599 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
600 | ExynosVideoGeometry bufferConf; | |
601 | OMX_U32 inputBufferNumber = 0; | |
602 | int i; | |
603 | ||
38ef2572 JC |
604 | FunctionIn(); |
605 | ||
606 | if ((oneFrameSize <= 0) && (pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS)) { | |
54cbf397 SK |
607 | OMX_BUFFERHEADERTYPE *OMXBuffer = NULL; |
608 | OMXBuffer = Exynos_OutputBufferGetQueue_Direct(pExynosComponent); | |
609 | if (OMXBuffer == NULL) { | |
38ef2572 JC |
610 | ret = OMX_ErrorUndefined; |
611 | goto EXIT; | |
612 | } | |
38ef2572 | 613 | |
54cbf397 SK |
614 | OMXBuffer->nTimeStamp = pSrcInputData->timeStamp; |
615 | OMXBuffer->nFlags = pSrcInputData->nFlags; | |
616 | Exynos_OMX_OutputBufferReturn(pOMXComponent, OMXBuffer); | |
38ef2572 JC |
617 | |
618 | ret = OMX_ErrorNone; | |
619 | goto EXIT; | |
620 | } | |
621 | ||
622 | if (pVideoDec->bThumbnailMode == OMX_TRUE) | |
623 | pDecOps->Set_DisplayDelay(hMFCHandle, 0); | |
624 | ||
625 | /* input buffer info */ | |
626 | Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf)); | |
627 | bufferConf.eCompressionFormat = VIDEO_CODING_AVC; | |
1ed2fc89 | 628 | pInbufOps->Set_Shareable(hMFCHandle); |
38ef2572 JC |
629 | if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { |
630 | bufferConf.nSizeImage = pExynosInputPort->portDefinition.format.video.nFrameWidth * pExynosInputPort->portDefinition.format.video.nFrameHeight * 3 / 2; | |
631 | inputBufferNumber = MAX_VIDEO_INPUTBUFFER_NUM; | |
632 | } else if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
633 | bufferConf.nSizeImage = DEFAULT_MFC_INPUT_BUFFER_SIZE; | |
634 | inputBufferNumber = MFC_INPUT_BUFFER_NUM_MAX; | |
635 | } | |
636 | ||
637 | /* should be done before prepare input buffer */ | |
638 | if (pInbufOps->Enable_Cacheable(hMFCHandle) != VIDEO_ERROR_NONE) { | |
639 | ret = OMX_ErrorInsufficientResources; | |
640 | goto EXIT; | |
641 | } | |
642 | ||
643 | /* set input buffer geometry */ | |
644 | if (pInbufOps->Set_Geometry(hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) { | |
645 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for input buffer"); | |
646 | ret = OMX_ErrorInsufficientResources; | |
647 | goto EXIT; | |
648 | } | |
649 | ||
650 | /* setup input buffer */ | |
651 | if (pInbufOps->Setup(hMFCHandle, inputBufferNumber) != VIDEO_ERROR_NONE) { | |
652 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup input buffer"); | |
653 | ret = OMX_ErrorInsufficientResources; | |
654 | goto EXIT; | |
655 | } | |
656 | ||
657 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
658 | /* Register input buffer */ | |
659 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { | |
01fa64f5 DZ |
660 | ExynosVideoPlane plane; |
661 | plane.addr = pVideoDec->pMFCDecInputBuffer[i]->VirAddr; | |
662 | plane.allocSize = pVideoDec->pMFCDecInputBuffer[i]->bufferSize; | |
663 | plane.fd = 0; | |
664 | if (pInbufOps->Register(hMFCHandle, &plane, 1) != VIDEO_ERROR_NONE) { | |
38ef2572 JC |
665 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); |
666 | ret = OMX_ErrorInsufficientResources; | |
667 | goto EXIT; | |
668 | } | |
669 | } | |
670 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
671 | /* Register input buffer */ | |
672 | for (i = 0; i < pExynosInputPort->portDefinition.nBufferCountActual; i++) { | |
01fa64f5 DZ |
673 | ExynosVideoPlane plane; |
674 | plane.addr = pExynosInputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer; | |
675 | plane.allocSize = pExynosInputPort->extendBufferHeader[i].OMXBufferHeader->nAllocLen; | |
676 | plane.fd = pExynosInputPort->extendBufferHeader[i].buf_fd[0]; | |
677 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, | |
678 | "%s: registering buf %d (hdr=%p) (addr=%p alloc_sz=%ld fd=%d)\n", __func__, | |
679 | i, &pExynosInputPort->extendBufferHeader[i], plane.addr, plane.allocSize, | |
680 | plane.fd); | |
681 | ||
682 | if (pInbufOps->Register(hMFCHandle, &plane, 1) != VIDEO_ERROR_NONE) { | |
38ef2572 JC |
683 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); |
684 | ret = OMX_ErrorInsufficientResources; | |
685 | goto EXIT; | |
686 | } | |
687 | } | |
688 | } | |
689 | ||
690 | /* set output geometry */ | |
691 | Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf)); | |
692 | #if 0 | |
693 | pH264Dec->hMFCH264Handle.MFCOutputColorType = bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED; | |
694 | #else /* This is temporal code to fix broken thumbnail until 3D ddk supports tiled mode */ | |
695 | if (pExynosOutputPort->bIsANBEnabled == OMX_TRUE) | |
696 | pH264Dec->hMFCH264Handle.MFCOutputColorType = bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12; | |
697 | else | |
698 | pH264Dec->hMFCH264Handle.MFCOutputColorType = bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED; | |
699 | #endif | |
3e79a27e | 700 | |
38ef2572 JC |
701 | if (pOutbufOps->Set_Geometry(hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) { |
702 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for output buffer"); | |
703 | ret = OMX_ErrorInsufficientResources; | |
704 | goto EXIT; | |
705 | } | |
706 | ||
707 | /* input buffer enqueue for header parsing */ | |
708 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "oneFrameSize: %d", oneFrameSize); | |
709 | if (pInbufOps->Enqueue(hMFCHandle, (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.dataBuffer, (unsigned int *)&oneFrameSize, 1, pSrcInputData->bufferHeader) != VIDEO_ERROR_NONE) { | |
710 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to enqueue input buffer for header parsing"); | |
711 | // ret = OMX_ErrorInsufficientResources; | |
712 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecInit; | |
713 | goto EXIT; | |
714 | } | |
715 | ||
716 | /* start header parsing */ | |
717 | if (pInbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) { | |
718 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run input buffer for header parsing"); | |
719 | ret = OMX_ErrorCodecInit; | |
800a8d75 JC |
720 | goto EXIT; |
721 | } | |
722 | ||
38ef2572 JC |
723 | /* get geometry for output */ |
724 | Exynos_OSAL_Memset(&pH264Dec->hMFCH264Handle.codecOutbufConf, 0, sizeof(ExynosVideoGeometry)); | |
725 | if (pOutbufOps->Get_Geometry(hMFCHandle, &pH264Dec->hMFCH264Handle.codecOutbufConf) != VIDEO_ERROR_NONE) { | |
726 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to get geometry for parsed header info"); | |
800a8d75 JC |
727 | ret = OMX_ErrorInsufficientResources; |
728 | goto EXIT; | |
729 | } | |
730 | ||
38ef2572 | 731 | /* get dpb count */ |
bef62093 | 732 | pH264Dec->hMFCH264Handle.maxDPBNum = pDecOps->Get_ActualBufferCount(hMFCHandle); |
38ef2572 | 733 | if (pVideoDec->bThumbnailMode == OMX_FALSE) |
bef62093 SK |
734 | pH264Dec->hMFCH264Handle.maxDPBNum += EXTRA_DPB_NUM; |
735 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "H264CodecSetup nOutbufs: %d", pH264Dec->hMFCH264Handle.maxDPBNum); | |
38ef2572 JC |
736 | |
737 | pH264Dec->hMFCH264Handle.bConfiguredMFCSrc = OMX_TRUE; | |
738 | ||
739 | pExynosOutputPort->cropRectangle.nTop = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nTop; | |
740 | pExynosOutputPort->cropRectangle.nLeft = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nLeft; | |
741 | pExynosOutputPort->cropRectangle.nWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nWidth; | |
742 | pExynosOutputPort->cropRectangle.nHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nHeight; | |
743 | ||
38ef2572 JC |
744 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
745 | if ((pExynosInputPort->portDefinition.format.video.nFrameWidth != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth) || | |
746 | (pExynosInputPort->portDefinition.format.video.nFrameHeight != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight)) { | |
747 | pExynosInputPort->portDefinition.format.video.nFrameWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth; | |
748 | pExynosInputPort->portDefinition.format.video.nFrameHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight; | |
749 | pExynosInputPort->portDefinition.format.video.nStride = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth + 15) & (~15)); | |
750 | pExynosInputPort->portDefinition.format.video.nSliceHeight = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight + 15) & (~15)); | |
751 | ||
752 | Exynos_UpdateFrameSize(pOMXComponent); | |
753 | pExynosOutputPort->exceptionFlag = NEED_PORT_DISABLE; | |
754 | ||
755 | /** Send Port Settings changed call back **/ | |
756 | (*(pExynosComponent->pCallbacks->EventHandler)) | |
757 | (pOMXComponent, | |
758 | pExynosComponent->callbackData, | |
759 | OMX_EventPortSettingsChanged, /* The command was completed */ | |
760 | OMX_DirOutput, /* This is the port index */ | |
761 | 0, | |
762 | NULL); | |
763 | } | |
764 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
765 | if ((pExynosInputPort->portDefinition.format.video.nFrameWidth != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth) || | |
766 | (pExynosInputPort->portDefinition.format.video.nFrameHeight != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight) || | |
bef62093 | 767 | (pExynosOutputPort->portDefinition.nBufferCountActual != pH264Dec->hMFCH264Handle.maxDPBNum)) { |
38ef2572 JC |
768 | pExynosInputPort->portDefinition.format.video.nFrameWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth; |
769 | pExynosInputPort->portDefinition.format.video.nFrameHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight; | |
770 | pExynosInputPort->portDefinition.format.video.nStride = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth + 15) & (~15)); | |
771 | pExynosInputPort->portDefinition.format.video.nSliceHeight = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight + 15) & (~15)); | |
772 | ||
bef62093 SK |
773 | pExynosOutputPort->portDefinition.nBufferCountActual = pH264Dec->hMFCH264Handle.maxDPBNum - 2; |
774 | pExynosOutputPort->portDefinition.nBufferCountMin = pH264Dec->hMFCH264Handle.maxDPBNum - 2; | |
38ef2572 JC |
775 | |
776 | Exynos_UpdateFrameSize(pOMXComponent); | |
777 | pExynosOutputPort->exceptionFlag = NEED_PORT_DISABLE; | |
778 | ||
779 | /** Send Port Settings changed call back **/ | |
780 | (*(pExynosComponent->pCallbacks->EventHandler)) | |
781 | (pOMXComponent, | |
782 | pExynosComponent->callbackData, | |
783 | OMX_EventPortSettingsChanged, /* The command was completed */ | |
784 | OMX_DirOutput, /* This is the port index */ | |
785 | 0, | |
786 | NULL); | |
787 | } | |
788 | } | |
495cf062 SK |
789 | if ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth != pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nWidth) || |
790 | (pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight != pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nHeight)) { | |
791 | /* Check Crop */ | |
792 | pExynosInputPort->portDefinition.format.video.nFrameWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth; | |
793 | pExynosInputPort->portDefinition.format.video.nFrameHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight; | |
794 | pExynosInputPort->portDefinition.format.video.nStride = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth + 15) & (~15)); | |
795 | pExynosInputPort->portDefinition.format.video.nSliceHeight = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight + 15) & (~15)); | |
796 | Exynos_UpdateFrameSize(pOMXComponent); | |
797 | ||
798 | /** Send crop info call back **/ | |
799 | (*(pExynosComponent->pCallbacks->EventHandler)) | |
800 | (pOMXComponent, | |
801 | pExynosComponent->callbackData, | |
802 | OMX_EventPortSettingsChanged, /* The command was completed */ | |
803 | OMX_DirOutput, /* This is the port index */ | |
804 | OMX_IndexConfigCommonOutputCrop, | |
805 | NULL); | |
806 | } | |
807 | ||
38ef2572 JC |
808 | Exynos_OSAL_SleepMillisec(0); |
809 | ret = OMX_ErrorInputDataDecodeYet; | |
810 | H264CodecStop(pOMXComponent, INPUT_PORT_INDEX); | |
800a8d75 JC |
811 | |
812 | EXIT: | |
813 | FunctionOut(); | |
38ef2572 | 814 | |
800a8d75 JC |
815 | return ret; |
816 | } | |
817 | ||
38ef2572 | 818 | OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) |
800a8d75 | 819 | { |
38ef2572 | 820 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
800a8d75 | 821 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
38ef2572 JC |
822 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; |
823 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
824 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
825 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
826 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
38ef2572 JC |
827 | |
828 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
829 | ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
830 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
57fbf5ba | 831 | |
38ef2572 | 832 | int i, nOutbufs; |
800a8d75 JC |
833 | |
834 | FunctionIn(); | |
835 | ||
38ef2572 | 836 | /* get dpb count */ |
bef62093 | 837 | nOutbufs = pH264Dec->hMFCH264Handle.maxDPBNum; |
38ef2572 JC |
838 | |
839 | /* should be done before prepare output buffer */ | |
840 | if (pOutbufOps->Enable_Cacheable(hMFCHandle) != VIDEO_ERROR_NONE) { | |
841 | ret = OMX_ErrorInsufficientResources; | |
800a8d75 JC |
842 | goto EXIT; |
843 | } | |
844 | ||
38ef2572 JC |
845 | pOutbufOps->Set_Shareable(hMFCHandle); |
846 | if (pOutbufOps->Setup(hMFCHandle, nOutbufs) != VIDEO_ERROR_NONE) { | |
847 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup output buffer"); | |
848 | ret = OMX_ErrorInsufficientResources; | |
800a8d75 JC |
849 | goto EXIT; |
850 | } | |
851 | ||
38ef2572 JC |
852 | int YBufferSize = calc_plane(pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth, pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight); |
853 | int CBufferSize = calc_plane(pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth, pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight >> 1); | |
854 | OMX_U32 dataLen[2] = {0, 0}; | |
855 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
01fa64f5 DZ |
856 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: using copy buf\n", __func__); |
857 | /* Register output buffer */ | |
38ef2572 | 858 | for (i = 0; i < nOutbufs; i++) { |
01fa64f5 DZ |
859 | ExynosVideoPlane planes[2]; |
860 | int plane; | |
861 | ||
38ef2572 JC |
862 | pVideoDec->pMFCDecOutputBuffer[i] = (CODEC_DEC_OUTPUT_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_DEC_OUTPUT_BUFFER)); |
863 | if (pVideoDec->bDRMPlayerMode == OMX_TRUE) { | |
864 | pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[0] = | |
865 | (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, YBufferSize, SECURE_MEMORY); | |
866 | pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[1] = | |
867 | (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, CBufferSize, SECURE_MEMORY); | |
868 | pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[0] = YBufferSize; | |
869 | pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[1] = CBufferSize; | |
870 | } else { | |
871 | pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[0] = | |
872 | (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, YBufferSize, NORMAL_MEMORY); | |
873 | pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[1] = | |
874 | (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, CBufferSize, NORMAL_MEMORY); | |
875 | pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[0] = YBufferSize; | |
876 | pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[1] = CBufferSize; | |
877 | } | |
01fa64f5 DZ |
878 | |
879 | pVideoDec->pMFCDecOutputBuffer[i]->fd[0] = | |
880 | Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, | |
881 | pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[0]); | |
882 | pVideoDec->pMFCDecOutputBuffer[i]->fd[1] = | |
883 | Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, | |
884 | pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[1]); | |
885 | ||
38ef2572 JC |
886 | if ((pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[0] == NULL) || |
887 | (pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[1] == NULL)) { | |
888 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); | |
889 | ret = OMX_ErrorInsufficientResources; | |
890 | goto EXIT; | |
891 | } | |
01fa64f5 DZ |
892 | |
893 | for (plane = 0; plane < 2; plane++) { | |
894 | planes[plane].addr = pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[plane]; | |
895 | planes[plane].allocSize = pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[plane]; | |
896 | planes[plane].fd = pVideoDec->pMFCDecOutputBuffer[i]->fd[plane]; | |
897 | } | |
898 | ||
899 | if (pOutbufOps->Register(hMFCHandle, planes, 2) != VIDEO_ERROR_NONE) { | |
38ef2572 JC |
900 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); |
901 | ret = OMX_ErrorInsufficientResources; | |
902 | goto EXIT; | |
903 | } | |
904 | pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->VirAddr, (unsigned int *)dataLen, 2, NULL); | |
905 | } | |
906 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
01fa64f5 | 907 | /* Register output buffer */ |
38ef2572 JC |
908 | /*************/ |
909 | /* TBD */ | |
910 | /*************/ | |
38ef2572 JC |
911 | // OMX_U32 width = pExynosOutputPort->portDefinition.format.video.nFrameWidth; |
912 | // OMX_U32 height = pExynosOutputPort->portDefinition.format.video.nFrameHeight; | |
913 | // OMX_U32 stride; | |
914 | for (i = 0; i < pExynosOutputPort->assignedBufferNum; i++) { | |
01fa64f5 DZ |
915 | EXYNOS_OMX_BUFFERHEADERTYPE *buffer = &pExynosOutputPort->extendBufferHeader[i]; |
916 | ExynosVideoPlane planes[2]; | |
917 | ||
918 | /* luma */ | |
919 | planes[0].addr = buffer->pYUVBuf[0]; | |
920 | planes[0].fd = buffer->buf_fd[0]; | |
921 | planes[0].allocSize = YBufferSize; | |
922 | /* chroma */ | |
923 | planes[1].addr = buffer->pYUVBuf[1]; | |
924 | planes[1].fd = buffer->buf_fd[1]; | |
925 | planes[1].allocSize = CBufferSize; | |
926 | ||
927 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, | |
928 | "%s: registering buf %d (hdr=%p) (l_addr=%p l_fd=%d c_addr=%p c_fd=%d)\n", | |
929 | __func__, i, buffer, planes[0].addr, planes[0].fd, planes[1].addr, | |
930 | planes[1].fd); | |
931 | ||
38ef2572 JC |
932 | // Exynos_OSAL_LockANB(pExynosOutputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer, width, height, |
933 | // pExynosOutputPort->portDefinition.format.video.eColorFormat, | |
934 | // &stride, pExynosOutputPort->extendBufferHeader[i].pYUVBuf); | |
01fa64f5 | 935 | if (pOutbufOps->Register(hMFCHandle, planes, 2) != VIDEO_ERROR_NONE) { |
38ef2572 JC |
936 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); |
937 | ret = OMX_ErrorInsufficientResources; | |
938 | goto EXIT; | |
939 | } | |
940 | pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pExynosOutputPort->extendBufferHeader[i].pYUVBuf, (unsigned int *)dataLen, 2, NULL); | |
941 | // Exynos_OSAL_UnlockANB(pExynosOutputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer); | |
942 | } | |
943 | } | |
944 | if (pOutbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) { | |
945 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer"); | |
946 | ret = OMX_ErrorInsufficientResources; | |
947 | goto EXIT; | |
948 | } | |
949 | ||
950 | if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
951 | H264CodecStop(pOMXComponent, OUTPUT_PORT_INDEX); | |
952 | } | |
953 | pH264Dec->hMFCH264Handle.bConfiguredMFCDst = OMX_TRUE; | |
954 | ||
955 | ret = OMX_ErrorNone; | |
800a8d75 JC |
956 | |
957 | EXIT: | |
958 | FunctionOut(); | |
38ef2572 | 959 | |
800a8d75 JC |
960 | return ret; |
961 | } | |
962 | ||
963 | OMX_ERRORTYPE Exynos_H264Dec_GetParameter( | |
20d3e6e3 JC |
964 | OMX_IN OMX_HANDLETYPE hComponent, |
965 | OMX_IN OMX_INDEXTYPE nParamIndex, | |
966 | OMX_INOUT OMX_PTR pComponentParameterStructure) | |
967 | { | |
968 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
969 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
970 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
971 | ||
972 | FunctionIn(); | |
973 | ||
974 | if (hComponent == NULL || pComponentParameterStructure == NULL) { | |
975 | ret = OMX_ErrorBadParameter; | |
976 | goto EXIT; | |
977 | } | |
978 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
979 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
980 | if (ret != OMX_ErrorNone) { | |
981 | goto EXIT; | |
982 | } | |
983 | if (pOMXComponent->pComponentPrivate == NULL) { | |
984 | ret = OMX_ErrorBadParameter; | |
985 | goto EXIT; | |
986 | } | |
987 | ||
988 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
989 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
990 | ret = OMX_ErrorInvalidState; | |
991 | goto EXIT; | |
992 | } | |
993 | ||
994 | switch (nParamIndex) { | |
995 | case OMX_IndexParamVideoAvc: | |
996 | { | |
997 | OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = (OMX_VIDEO_PARAM_AVCTYPE *)pComponentParameterStructure; | |
998 | OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = NULL; | |
999 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
1000 | ||
1001 | ret = Exynos_OMX_Check_SizeVersion(pDstAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
1002 | if (ret != OMX_ErrorNone) { | |
1003 | goto EXIT; | |
1004 | } | |
1005 | ||
1006 | if (pDstAVCComponent->nPortIndex >= ALL_PORT_NUM) { | |
1007 | ret = OMX_ErrorBadPortIndex; | |
1008 | goto EXIT; | |
1009 | } | |
1010 | ||
1011 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1012 | pSrcAVCComponent = &pH264Dec->AVCComponent[pDstAVCComponent->nPortIndex]; | |
1013 | ||
1014 | Exynos_OSAL_Memcpy(pDstAVCComponent, pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
1015 | } | |
1016 | break; | |
1017 | case OMX_IndexParamStandardComponentRole: | |
1018 | { | |
1019 | OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure; | |
1020 | ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); | |
1021 | if (ret != OMX_ErrorNone) { | |
1022 | goto EXIT; | |
1023 | } | |
1024 | ||
1025 | Exynos_OSAL_Strcpy((char *)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H264_DEC_ROLE); | |
1026 | } | |
1027 | break; | |
1028 | case OMX_IndexParamVideoProfileLevelQuerySupported: | |
1029 | { | |
1030 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)pComponentParameterStructure; | |
1031 | EXYNOS_OMX_VIDEO_PROFILELEVEL *pProfileLevel = NULL; | |
1032 | OMX_U32 maxProfileLevelNum = 0; | |
1033 | ||
1034 | ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); | |
1035 | if (ret != OMX_ErrorNone) { | |
1036 | goto EXIT; | |
1037 | } | |
1038 | ||
1039 | if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { | |
1040 | ret = OMX_ErrorBadPortIndex; | |
1041 | goto EXIT; | |
1042 | } | |
1043 | ||
1044 | pProfileLevel = supportedAVCProfileLevels; | |
1045 | maxProfileLevelNum = sizeof(supportedAVCProfileLevels) / sizeof(EXYNOS_OMX_VIDEO_PROFILELEVEL); | |
1046 | ||
1047 | if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) { | |
1048 | ret = OMX_ErrorNoMore; | |
1049 | goto EXIT; | |
1050 | } | |
1051 | ||
1052 | pProfileLevel += pDstProfileLevel->nProfileIndex; | |
1053 | pDstProfileLevel->eProfile = pProfileLevel->profile; | |
1054 | pDstProfileLevel->eLevel = pProfileLevel->level; | |
1055 | } | |
1056 | break; | |
1057 | case OMX_IndexParamVideoProfileLevelCurrent: | |
1058 | { | |
1059 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)pComponentParameterStructure; | |
1060 | OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = NULL; | |
1061 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
1062 | ||
1063 | ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); | |
1064 | if (ret != OMX_ErrorNone) { | |
1065 | goto EXIT; | |
1066 | } | |
1067 | ||
1068 | if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { | |
1069 | ret = OMX_ErrorBadPortIndex; | |
1070 | goto EXIT; | |
1071 | } | |
1072 | ||
1073 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1074 | pSrcAVCComponent = &pH264Dec->AVCComponent[pDstProfileLevel->nPortIndex]; | |
1075 | ||
1076 | pDstProfileLevel->eProfile = pSrcAVCComponent->eProfile; | |
1077 | pDstProfileLevel->eLevel = pSrcAVCComponent->eLevel; | |
1078 | } | |
1079 | break; | |
1080 | case OMX_IndexParamVideoErrorCorrection: | |
1081 | { | |
1082 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; | |
1083 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL; | |
1084 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
1085 | ||
1086 | ret = Exynos_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); | |
1087 | if (ret != OMX_ErrorNone) { | |
1088 | goto EXIT; | |
1089 | } | |
1090 | ||
1091 | if (pDstErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) { | |
1092 | ret = OMX_ErrorBadPortIndex; | |
1093 | goto EXIT; | |
1094 | } | |
1095 | ||
1096 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1097 | pSrcErrorCorrectionType = &pH264Dec->errorCorrectionType[INPUT_PORT_INDEX]; | |
1098 | ||
1099 | pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; | |
1100 | pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; | |
1101 | pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; | |
1102 | pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; | |
1103 | pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; | |
1104 | } | |
1105 | break; | |
1106 | default: | |
1107 | ret = Exynos_OMX_VideoDecodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure); | |
1108 | break; | |
1109 | } | |
1110 | EXIT: | |
1111 | FunctionOut(); | |
1112 | ||
1113 | return ret; | |
1114 | } | |
1115 | ||
800a8d75 | 1116 | OMX_ERRORTYPE Exynos_H264Dec_SetParameter( |
20d3e6e3 JC |
1117 | OMX_IN OMX_HANDLETYPE hComponent, |
1118 | OMX_IN OMX_INDEXTYPE nIndex, | |
1119 | OMX_IN OMX_PTR pComponentParameterStructure) | |
1120 | { | |
1121 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1122 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1123 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1124 | ||
1125 | FunctionIn(); | |
1126 | ||
1127 | if (hComponent == NULL || pComponentParameterStructure == NULL) { | |
1128 | ret = OMX_ErrorBadParameter; | |
1129 | goto EXIT; | |
1130 | } | |
1131 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1132 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1133 | if (ret != OMX_ErrorNone) { | |
1134 | goto EXIT; | |
1135 | } | |
1136 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1137 | ret = OMX_ErrorBadParameter; | |
1138 | goto EXIT; | |
1139 | } | |
1140 | ||
1141 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1142 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
1143 | ret = OMX_ErrorInvalidState; | |
1144 | goto EXIT; | |
1145 | } | |
1146 | ||
1147 | switch (nIndex) { | |
1148 | case OMX_IndexParamVideoAvc: | |
1149 | { | |
1150 | OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = NULL; | |
1151 | OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = (OMX_VIDEO_PARAM_AVCTYPE *)pComponentParameterStructure; | |
1152 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
1153 | ||
1154 | ret = Exynos_OMX_Check_SizeVersion(pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
1155 | if (ret != OMX_ErrorNone) { | |
1156 | goto EXIT; | |
1157 | } | |
1158 | ||
1159 | if (pSrcAVCComponent->nPortIndex >= ALL_PORT_NUM) { | |
1160 | ret = OMX_ErrorBadPortIndex; | |
1161 | goto EXIT; | |
1162 | } | |
1163 | ||
1164 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1165 | pDstAVCComponent = &pH264Dec->AVCComponent[pSrcAVCComponent->nPortIndex]; | |
1166 | ||
1167 | Exynos_OSAL_Memcpy(pDstAVCComponent, pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
1168 | } | |
1169 | break; | |
1170 | case OMX_IndexParamStandardComponentRole: | |
1171 | { | |
1172 | OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure; | |
1173 | ||
1174 | ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); | |
1175 | if (ret != OMX_ErrorNone) { | |
1176 | goto EXIT; | |
1177 | } | |
1178 | ||
1179 | if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) { | |
1180 | ret = OMX_ErrorIncorrectStateOperation; | |
1181 | goto EXIT; | |
1182 | } | |
38ef2572 JC |
1183 | |
1184 | if (!Exynos_OSAL_Strcmp((char*)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H264_DEC_ROLE)) { | |
1185 | pExynosComponent->pExynosPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; | |
1186 | } else { | |
1187 | ret = OMX_ErrorBadParameter; | |
1188 | goto EXIT; | |
1189 | } | |
20d3e6e3 JC |
1190 | } |
1191 | break; | |
1192 | case OMX_IndexParamVideoProfileLevelCurrent: | |
1193 | { | |
1194 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; | |
38ef2572 JC |
1195 | OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = NULL; |
1196 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
20d3e6e3 JC |
1197 | |
1198 | ret = Exynos_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); | |
1199 | if (ret != OMX_ErrorNone) | |
1200 | goto EXIT; | |
1201 | ||
1202 | if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) { | |
1203 | ret = OMX_ErrorBadPortIndex; | |
1204 | goto EXIT; | |
1205 | } | |
1206 | ||
1207 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1208 | ||
1209 | pDstAVCComponent = &pH264Dec->AVCComponent[pSrcProfileLevel->nPortIndex]; | |
1210 | pDstAVCComponent->eProfile = pSrcProfileLevel->eProfile; | |
1211 | pDstAVCComponent->eLevel = pSrcProfileLevel->eLevel; | |
1212 | } | |
1213 | break; | |
1214 | case OMX_IndexParamVideoErrorCorrection: | |
1215 | { | |
1216 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; | |
1217 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL; | |
38ef2572 | 1218 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; |
20d3e6e3 JC |
1219 | |
1220 | ret = Exynos_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); | |
1221 | if (ret != OMX_ErrorNone) { | |
1222 | goto EXIT; | |
1223 | } | |
1224 | ||
1225 | if (pSrcErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) { | |
1226 | ret = OMX_ErrorBadPortIndex; | |
1227 | goto EXIT; | |
1228 | } | |
1229 | ||
1230 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1231 | pDstErrorCorrectionType = &pH264Dec->errorCorrectionType[INPUT_PORT_INDEX]; | |
1232 | ||
1233 | pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; | |
1234 | pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; | |
1235 | pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; | |
1236 | pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; | |
1237 | pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; | |
1238 | } | |
1239 | break; | |
1240 | default: | |
1241 | ret = Exynos_OMX_VideoDecodeSetParameter(hComponent, nIndex, pComponentParameterStructure); | |
1242 | break; | |
1243 | } | |
1244 | EXIT: | |
1245 | FunctionOut(); | |
1246 | ||
1247 | return ret; | |
1248 | } | |
1249 | ||
800a8d75 | 1250 | OMX_ERRORTYPE Exynos_H264Dec_GetConfig( |
20d3e6e3 JC |
1251 | OMX_HANDLETYPE hComponent, |
1252 | OMX_INDEXTYPE nIndex, | |
1253 | OMX_PTR pComponentConfigStructure) | |
1254 | { | |
1255 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1256 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1257 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1258 | ||
1259 | FunctionIn(); | |
1260 | ||
1261 | if (hComponent == NULL) { | |
1262 | ret = OMX_ErrorBadParameter; | |
1263 | goto EXIT; | |
1264 | } | |
1265 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1266 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1267 | if (ret != OMX_ErrorNone) { | |
1268 | goto EXIT; | |
1269 | } | |
20d3e6e3 JC |
1270 | if (pOMXComponent->pComponentPrivate == NULL) { |
1271 | ret = OMX_ErrorBadParameter; | |
1272 | goto EXIT; | |
1273 | } | |
1274 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
20d3e6e3 JC |
1275 | if (pComponentConfigStructure == NULL) { |
1276 | ret = OMX_ErrorBadParameter; | |
1277 | goto EXIT; | |
1278 | } | |
1279 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1280 | ret = OMX_ErrorInvalidState; | |
1281 | goto EXIT; | |
1282 | } | |
1283 | ||
1284 | switch (nIndex) { | |
1285 | case OMX_IndexConfigCommonOutputCrop: | |
1286 | { | |
1287 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
1288 | OMX_CONFIG_RECTTYPE *pSrcRectType = NULL; | |
1289 | OMX_CONFIG_RECTTYPE *pDstRectType = NULL; | |
1290 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1291 | ||
38ef2572 | 1292 | if (pH264Dec->hMFCH264Handle.bConfiguredMFCSrc == OMX_FALSE) { |
20d3e6e3 JC |
1293 | ret = OMX_ErrorNotReady; |
1294 | break; | |
1295 | } | |
1296 | ||
1297 | pDstRectType = (OMX_CONFIG_RECTTYPE *)pComponentConfigStructure; | |
1298 | ||
1299 | if ((pDstRectType->nPortIndex != INPUT_PORT_INDEX) && | |
1300 | (pDstRectType->nPortIndex != OUTPUT_PORT_INDEX)) { | |
1301 | ret = OMX_ErrorBadPortIndex; | |
1302 | goto EXIT; | |
1303 | } | |
1304 | ||
1305 | EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[pDstRectType->nPortIndex]; | |
1306 | ||
1307 | pSrcRectType = &(pExynosPort->cropRectangle); | |
1308 | ||
1309 | pDstRectType->nTop = pSrcRectType->nTop; | |
1310 | pDstRectType->nLeft = pSrcRectType->nLeft; | |
1311 | pDstRectType->nHeight = pSrcRectType->nHeight; | |
1312 | pDstRectType->nWidth = pSrcRectType->nWidth; | |
1313 | } | |
1314 | break; | |
1315 | default: | |
1316 | ret = Exynos_OMX_VideoDecodeGetConfig(hComponent, nIndex, pComponentConfigStructure); | |
1317 | break; | |
1318 | } | |
1319 | ||
1320 | EXIT: | |
1321 | FunctionOut(); | |
1322 | ||
1323 | return ret; | |
1324 | } | |
1325 | ||
800a8d75 | 1326 | OMX_ERRORTYPE Exynos_H264Dec_SetConfig( |
20d3e6e3 JC |
1327 | OMX_HANDLETYPE hComponent, |
1328 | OMX_INDEXTYPE nIndex, | |
1329 | OMX_PTR pComponentConfigStructure) | |
1330 | { | |
1331 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1332 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1333 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1334 | ||
1335 | FunctionIn(); | |
1336 | ||
1337 | if (hComponent == NULL) { | |
1338 | ret = OMX_ErrorBadParameter; | |
1339 | goto EXIT; | |
1340 | } | |
1341 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1342 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1343 | if (ret != OMX_ErrorNone) { | |
1344 | goto EXIT; | |
1345 | } | |
20d3e6e3 JC |
1346 | if (pOMXComponent->pComponentPrivate == NULL) { |
1347 | ret = OMX_ErrorBadParameter; | |
1348 | goto EXIT; | |
1349 | } | |
1350 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
20d3e6e3 JC |
1351 | if (pComponentConfigStructure == NULL) { |
1352 | ret = OMX_ErrorBadParameter; | |
1353 | goto EXIT; | |
1354 | } | |
1355 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1356 | ret = OMX_ErrorInvalidState; | |
1357 | goto EXIT; | |
1358 | } | |
1359 | ||
1360 | switch (nIndex) { | |
1361 | default: | |
1362 | ret = Exynos_OMX_VideoDecodeSetConfig(hComponent, nIndex, pComponentConfigStructure); | |
1363 | break; | |
1364 | } | |
1365 | ||
1366 | EXIT: | |
1367 | FunctionOut(); | |
1368 | ||
1369 | return ret; | |
1370 | } | |
1371 | ||
800a8d75 | 1372 | OMX_ERRORTYPE Exynos_H264Dec_GetExtensionIndex( |
20d3e6e3 JC |
1373 | OMX_IN OMX_HANDLETYPE hComponent, |
1374 | OMX_IN OMX_STRING cParameterName, | |
1375 | OMX_OUT OMX_INDEXTYPE *pIndexType) | |
1376 | { | |
1377 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1378 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1379 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1380 | ||
1381 | FunctionIn(); | |
1382 | ||
1383 | if (hComponent == NULL) { | |
1384 | ret = OMX_ErrorBadParameter; | |
1385 | goto EXIT; | |
1386 | } | |
1387 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1388 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1389 | if (ret != OMX_ErrorNone) { | |
1390 | goto EXIT; | |
1391 | } | |
20d3e6e3 JC |
1392 | if (pOMXComponent->pComponentPrivate == NULL) { |
1393 | ret = OMX_ErrorBadParameter; | |
1394 | goto EXIT; | |
1395 | } | |
1396 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
20d3e6e3 JC |
1397 | if ((cParameterName == NULL) || (pIndexType == NULL)) { |
1398 | ret = OMX_ErrorBadParameter; | |
1399 | goto EXIT; | |
1400 | } | |
1401 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1402 | ret = OMX_ErrorInvalidState; | |
1403 | goto EXIT; | |
1404 | } | |
1405 | ||
1406 | if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_THUMBNAIL) == 0) { | |
1407 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
20d3e6e3 | 1408 | *pIndexType = OMX_IndexVendorThumbnailMode; |
20d3e6e3 JC |
1409 | ret = OMX_ErrorNone; |
1410 | } else { | |
1411 | ret = Exynos_OMX_VideoDecodeGetExtensionIndex(hComponent, cParameterName, pIndexType); | |
1412 | } | |
1413 | ||
1414 | EXIT: | |
1415 | FunctionOut(); | |
1416 | ||
1417 | return ret; | |
1418 | } | |
1419 | ||
800a8d75 | 1420 | OMX_ERRORTYPE Exynos_H264Dec_ComponentRoleEnum( |
20d3e6e3 JC |
1421 | OMX_HANDLETYPE hComponent, |
1422 | OMX_U8 *cRole, | |
1423 | OMX_U32 nIndex) | |
1424 | { | |
1425 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1426 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1427 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1428 | ||
1429 | FunctionIn(); | |
1430 | ||
1431 | if ((hComponent == NULL) || (cRole == NULL)) { | |
1432 | ret = OMX_ErrorBadParameter; | |
1433 | goto EXIT; | |
1434 | } | |
1435 | if (nIndex == (MAX_COMPONENT_ROLE_NUM-1)) { | |
1436 | Exynos_OSAL_Strcpy((char *)cRole, EXYNOS_OMX_COMPONENT_H264_DEC_ROLE); | |
1437 | ret = OMX_ErrorNone; | |
1438 | } else { | |
1439 | ret = OMX_ErrorNoMore; | |
1440 | } | |
1441 | ||
1442 | EXIT: | |
1443 | FunctionOut(); | |
1444 | ||
1445 | return ret; | |
1446 | } | |
1447 | ||
20d3e6e3 | 1448 | /* MFC Init */ |
800a8d75 | 1449 | OMX_ERRORTYPE Exynos_H264Dec_Init(OMX_COMPONENTTYPE *pOMXComponent) |
20d3e6e3 JC |
1450 | { |
1451 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1452 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1453 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
38ef2572 | 1454 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; |
20d3e6e3 | 1455 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; |
3e79a27e | 1456 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle; |
38ef2572 | 1457 | OMX_PTR hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; |
20d3e6e3 | 1458 | |
38ef2572 JC |
1459 | ExynosVideoDecOps *pDecOps = NULL; |
1460 | ExynosVideoDecBufferOps *pInbufOps = NULL; | |
1461 | ExynosVideoDecBufferOps *pOutbufOps = NULL; | |
20d3e6e3 JC |
1462 | |
1463 | CSC_METHOD csc_method = CSC_METHOD_SW; | |
38ef2572 | 1464 | int i = 0; |
20d3e6e3 JC |
1465 | |
1466 | FunctionIn(); | |
1467 | ||
38ef2572 JC |
1468 | pH264Dec->hMFCH264Handle.bConfiguredMFCSrc = OMX_FALSE; |
1469 | pH264Dec->hMFCH264Handle.bConfiguredMFCDst = OMX_FALSE; | |
1470 | pExynosComponent->bUseFlagEOF = OMX_TRUE; | |
20d3e6e3 JC |
1471 | pExynosComponent->bSaveFlagEOS = OMX_FALSE; |
1472 | ||
38ef2572 JC |
1473 | /* H.264 Codec Open */ |
1474 | ret = H264CodecOpen(pH264Dec); | |
1475 | if (ret != OMX_ErrorNone) { | |
20d3e6e3 JC |
1476 | goto EXIT; |
1477 | } | |
800a8d75 | 1478 | |
38ef2572 JC |
1479 | pDecOps = pH264Dec->hMFCH264Handle.pDecOps; |
1480 | pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
1481 | pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
1482 | ||
1483 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1484 | Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); | |
1485 | Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); | |
1486 | ||
3e79a27e | 1487 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { |
38ef2572 JC |
1488 | /*************/ |
1489 | /* TBD */ | |
1490 | /*************/ | |
1491 | /* Use ION Allocator */ | |
1492 | pVideoDec->pMFCDecInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_DEC_INPUT_BUFFER)); | |
1493 | pVideoDec->pMFCDecInputBuffer[i]->VirAddr = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, DEFAULT_MFC_INPUT_BUFFER_SIZE, NORMAL_MEMORY); | |
1494 | if (pVideoDec->pMFCDecInputBuffer[i]->VirAddr == NULL) { | |
1495 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); | |
1496 | ret = OMX_ErrorInsufficientResources; | |
1497 | goto EXIT; | |
1498 | } | |
01fa64f5 | 1499 | pVideoDec->pMFCDecInputBuffer[i]->fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->VirAddr); |
38ef2572 JC |
1500 | pVideoDec->pMFCDecInputBuffer[i]->bufferSize = DEFAULT_MFC_INPUT_BUFFER_SIZE; |
1501 | pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0; | |
20d3e6e3 | 1502 | |
38ef2572 JC |
1503 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]); |
1504 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->VirAddr: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]->VirAddr); | |
20d3e6e3 | 1505 | |
38ef2572 | 1506 | Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]); |
20d3e6e3 | 1507 | } |
38ef2572 JC |
1508 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { |
1509 | /*************/ | |
1510 | /* TBD */ | |
1511 | /*************/ | |
1512 | /* Does not require any actions. */ | |
20d3e6e3 JC |
1513 | } |
1514 | ||
38ef2572 JC |
1515 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
1516 | Exynos_OSAL_SemaphoreCreate(&pExynosOutputPort->codecSemID); | |
1517 | Exynos_OSAL_QueueCreate(&pExynosOutputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); | |
1518 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
1519 | /*************/ | |
1520 | /* TBD */ | |
1521 | /*************/ | |
1522 | /* Does not require any actions. */ | |
20d3e6e3 JC |
1523 | } |
1524 | ||
38ef2572 JC |
1525 | pH264Dec->bSourceStart = OMX_FALSE; |
1526 | Exynos_OSAL_SignalCreate(&pH264Dec->hSourceStartEvent); | |
1527 | pH264Dec->bDestinationStart = OMX_FALSE; | |
1528 | Exynos_OSAL_SignalCreate(&pH264Dec->hDestinationStartEvent); | |
20d3e6e3 JC |
1529 | |
1530 | Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); | |
1531 | Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); | |
1532 | pH264Dec->hMFCH264Handle.indexTimestamp = 0; | |
1533 | pH264Dec->hMFCH264Handle.outputIndexTimestamp = 0; | |
1534 | ||
1535 | pExynosComponent->getAllDelayBuffer = OMX_FALSE; | |
1536 | ||
38ef2572 JC |
1537 | #if 0//defined(USE_CSC_GSCALER) |
1538 | csc_method = CSC_METHOD_HW; //in case of Use ION buffer. | |
20d3e6e3 | 1539 | #endif |
38ef2572 JC |
1540 | pVideoDec->csc_handle = csc_init(csc_method); |
1541 | if (pVideoDec->csc_handle == NULL) { | |
1542 | ret = OMX_ErrorInsufficientResources; | |
1543 | goto EXIT; | |
800a8d75 | 1544 | } |
20d3e6e3 JC |
1545 | pVideoDec->csc_set_format = OMX_FALSE; |
1546 | ||
1547 | EXIT: | |
1548 | FunctionOut(); | |
1549 | ||
1550 | return ret; | |
1551 | } | |
1552 | ||
1553 | /* MFC Terminate */ | |
800a8d75 | 1554 | OMX_ERRORTYPE Exynos_H264Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) |
20d3e6e3 JC |
1555 | { |
1556 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1557 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1558 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
20d3e6e3 JC |
1559 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; |
1560 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
38ef2572 JC |
1561 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; |
1562 | OMX_PTR hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
20d3e6e3 | 1563 | |
38ef2572 JC |
1564 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; |
1565 | ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
1566 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
20d3e6e3 | 1567 | |
38ef2572 | 1568 | int i = 0; |
20d3e6e3 | 1569 | |
38ef2572 | 1570 | FunctionIn(); |
20d3e6e3 | 1571 | |
38ef2572 JC |
1572 | if (pVideoDec->csc_handle != NULL) { |
1573 | csc_deinit(pVideoDec->csc_handle); | |
1574 | pVideoDec->csc_handle = NULL; | |
20d3e6e3 JC |
1575 | } |
1576 | ||
38ef2572 JC |
1577 | Exynos_OSAL_SignalTerminate(pH264Dec->hDestinationStartEvent); |
1578 | pH264Dec->hDestinationStartEvent = NULL; | |
1579 | pH264Dec->bDestinationStart = OMX_FALSE; | |
1580 | Exynos_OSAL_SignalTerminate(pH264Dec->hSourceStartEvent); | |
1581 | pH264Dec->hSourceStartEvent = NULL; | |
1582 | pH264Dec->bSourceStart = OMX_FALSE; | |
1583 | ||
1584 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
3e79a27e | 1585 | for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { |
38ef2572 JC |
1586 | if (pVideoDec->pMFCDecOutputBuffer[i] != NULL) { |
1587 | if (pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[0] != NULL) | |
1588 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[0]); | |
1589 | if (pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[1] != NULL) | |
1590 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecOutputBuffer[i]->VirAddr[1]); | |
1591 | Exynos_OSAL_Free(pVideoDec->pMFCDecOutputBuffer[i]); | |
1592 | pVideoDec->pMFCDecOutputBuffer[i] = NULL; | |
1593 | } | |
800a8d75 | 1594 | } |
20d3e6e3 | 1595 | |
38ef2572 JC |
1596 | Exynos_OSAL_QueueTerminate(&pExynosOutputPort->codecBufferQ); |
1597 | Exynos_OSAL_SemaphoreTerminate(pExynosOutputPort->codecSemID); | |
1598 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
38ef2572 JC |
1599 | /*************/ |
1600 | /* TBD */ | |
1601 | /*************/ | |
1602 | /* Does not require any actions. */ | |
20d3e6e3 JC |
1603 | } |
1604 | ||
38ef2572 | 1605 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
3e79a27e | 1606 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { |
38ef2572 JC |
1607 | if (pVideoDec->pMFCDecInputBuffer[i] != NULL) { |
1608 | if (pVideoDec->pMFCDecInputBuffer[i]->VirAddr != NULL) | |
1609 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->VirAddr); | |
1610 | Exynos_OSAL_Free(pVideoDec->pMFCDecInputBuffer[i]); | |
1611 | pVideoDec->pMFCDecInputBuffer[i] = NULL; | |
1612 | } | |
20d3e6e3 | 1613 | } |
800a8d75 | 1614 | |
38ef2572 JC |
1615 | Exynos_OSAL_QueueTerminate(&pExynosInputPort->codecBufferQ); |
1616 | Exynos_OSAL_SemaphoreTerminate(pExynosInputPort->codecSemID); | |
1617 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
38ef2572 JC |
1618 | /*************/ |
1619 | /* TBD */ | |
1620 | /*************/ | |
1621 | /* Does not require any actions. */ | |
38ef2572 JC |
1622 | } |
1623 | H264CodecClose(pH264Dec); | |
20d3e6e3 JC |
1624 | |
1625 | EXIT: | |
38ef2572 JC |
1626 | FunctionOut(); |
1627 | ||
20d3e6e3 JC |
1628 | return ret; |
1629 | } | |
1630 | ||
38ef2572 | 1631 | OMX_ERRORTYPE Exynos_H264Dec_SrcIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData) |
20d3e6e3 | 1632 | { |
38ef2572 JC |
1633 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
1634 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1635 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1636 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1637 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
1638 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1639 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1640 | OMX_U32 oneFrameSize = pSrcInputData->dataLen; | |
38ef2572 JC |
1641 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; |
1642 | ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
1643 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
1644 | ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE; | |
1645 | int i; | |
20d3e6e3 JC |
1646 | |
1647 | FunctionIn(); | |
1648 | ||
38ef2572 JC |
1649 | if (pH264Dec->hMFCH264Handle.bConfiguredMFCSrc == OMX_FALSE) { |
1650 | ret = H264CodecSrcSetup(pOMXComponent, pSrcInputData); | |
20d3e6e3 JC |
1651 | goto EXIT; |
1652 | } | |
38ef2572 JC |
1653 | if (pH264Dec->hMFCH264Handle.bConfiguredMFCDst == OMX_FALSE) { |
1654 | ret = H264CodecDstSetup(pOMXComponent); | |
1655 | } | |
1656 | ||
1657 | if ((Check_H264_StartCode(pSrcInputData->buffer.singlePlaneBuffer.dataBuffer, oneFrameSize) == OMX_TRUE) || | |
1658 | ((pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)){ | |
1659 | pExynosComponent->timeStamp[pH264Dec->hMFCH264Handle.indexTimestamp] = pSrcInputData->timeStamp; | |
1660 | pExynosComponent->nFlags[pH264Dec->hMFCH264Handle.indexTimestamp] = pSrcInputData->nFlags; | |
1661 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "input timestamp %lld us (%.2f secs), Tag: %d, nFlags: 0x%x", pSrcInputData->timeStamp, pSrcInputData->timeStamp / 1E6, pH264Dec->hMFCH264Handle.indexTimestamp, pSrcInputData->nFlags); | |
1662 | pDecOps->Set_FrameTag(hMFCHandle, pH264Dec->hMFCH264Handle.indexTimestamp); | |
1663 | pH264Dec->hMFCH264Handle.indexTimestamp++; | |
1664 | pH264Dec->hMFCH264Handle.indexTimestamp %= MAX_TIMESTAMP; | |
1665 | ||
1666 | /* queue work for input buffer */ | |
1667 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "oneFrameSize: %d, bufferHeader: 0x%x, dataBuffer: 0x%x", oneFrameSize, pSrcInputData->bufferHeader, pSrcInputData->buffer.singlePlaneBuffer.dataBuffer); | |
1668 | codecReturn = pInbufOps->Enqueue(hMFCHandle, (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.dataBuffer, (unsigned int *)&oneFrameSize, 1, pSrcInputData->bufferHeader); | |
1669 | if (codecReturn != VIDEO_ERROR_NONE) { | |
1670 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode; | |
1671 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__); | |
1672 | goto EXIT; | |
1673 | } | |
1674 | H264CodecStart(pOMXComponent, INPUT_PORT_INDEX); | |
1675 | if (pH264Dec->bSourceStart == OMX_FALSE) { | |
1676 | pH264Dec->bSourceStart = OMX_TRUE; | |
1677 | Exynos_OSAL_SignalSet(pH264Dec->hSourceStartEvent); | |
1678 | Exynos_OSAL_SleepMillisec(0); | |
20d3e6e3 | 1679 | } |
38ef2572 JC |
1680 | if (pH264Dec->bDestinationStart == OMX_FALSE) { |
1681 | pH264Dec->bDestinationStart = OMX_TRUE; | |
1682 | Exynos_OSAL_SignalSet(pH264Dec->hDestinationStartEvent); | |
1683 | Exynos_OSAL_SleepMillisec(0); | |
1684 | } | |
1685 | } | |
20d3e6e3 | 1686 | |
38ef2572 | 1687 | ret = OMX_ErrorNone; |
20d3e6e3 | 1688 | |
38ef2572 | 1689 | EXIT: |
38ef2572 | 1690 | FunctionOut(); |
20d3e6e3 | 1691 | |
38ef2572 JC |
1692 | return ret; |
1693 | } | |
20d3e6e3 | 1694 | |
38ef2572 JC |
1695 | OMX_ERRORTYPE Exynos_H264Dec_SrcOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData) |
1696 | { | |
1697 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1698 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1699 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1700 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1701 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
1702 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1703 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
1704 | ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps; | |
1705 | ExynosVideoBuffer *pVideoBuffer; | |
20d3e6e3 | 1706 | |
38ef2572 | 1707 | FunctionIn(); |
20d3e6e3 | 1708 | |
38ef2572 | 1709 | pVideoBuffer = pInbufOps->Dequeue(hMFCHandle); |
20d3e6e3 | 1710 | |
38ef2572 JC |
1711 | pSrcOutputData->dataLen = 0; |
1712 | pSrcOutputData->usedDataLen = 0; | |
1713 | pSrcOutputData->remainDataLen = 0; | |
1714 | pSrcOutputData->nFlags = 0; | |
1715 | pSrcOutputData->timeStamp = 0; | |
1716 | ||
1717 | if (pVideoBuffer == NULL) { | |
1718 | pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = NULL; | |
1719 | pSrcOutputData->allocSize = 0; | |
1720 | pSrcOutputData->pPrivate = NULL; | |
1721 | pSrcOutputData->bufferHeader = NULL; | |
20d3e6e3 | 1722 | } else { |
38ef2572 | 1723 | pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = pVideoBuffer->planes[0].addr; |
01fa64f5 | 1724 | pSrcOutputData->buffer.singlePlaneBuffer.fd = pVideoBuffer->planes[0].fd; |
38ef2572 JC |
1725 | pSrcOutputData->allocSize = pVideoBuffer->planes[0].allocSize; |
1726 | ||
1727 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1728 | int i = 0; | |
1729 | while (pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer != pVideoDec->pMFCDecInputBuffer[i]->VirAddr) { | |
1730 | if (i >= MFC_INPUT_BUFFER_NUM_MAX) { | |
38ef2572 | 1731 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not find buffer"); |
3e79a27e | 1732 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode; |
38ef2572 JC |
1733 | goto EXIT; |
1734 | } | |
1735 | i++; | |
1736 | } | |
38ef2572 JC |
1737 | pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0; |
1738 | pSrcOutputData->pPrivate = pVideoDec->pMFCDecInputBuffer[i]; | |
20d3e6e3 JC |
1739 | } |
1740 | ||
38ef2572 JC |
1741 | /* For Share Buffer */ |
1742 | pSrcOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE*)pVideoBuffer->pPrivate; | |
20d3e6e3 JC |
1743 | } |
1744 | ||
38ef2572 | 1745 | ret = OMX_ErrorNone; |
20d3e6e3 | 1746 | |
38ef2572 JC |
1747 | EXIT: |
1748 | FunctionOut(); | |
20d3e6e3 | 1749 | |
38ef2572 JC |
1750 | return ret; |
1751 | } | |
20d3e6e3 | 1752 | |
38ef2572 JC |
1753 | OMX_ERRORTYPE Exynos_H264Dec_DstIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData) |
1754 | { | |
1755 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1756 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1757 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1758 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1759 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
1760 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
1761 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
1762 | OMX_U32 dataLen = 0; | |
1763 | ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE; | |
800a8d75 | 1764 | |
38ef2572 | 1765 | FunctionIn(); |
20d3e6e3 | 1766 | |
38ef2572 JC |
1767 | if (pDstInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) { |
1768 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to find input buffer"); | |
1769 | ret = OMX_ErrorBadParameter; | |
1770 | goto EXIT; | |
1771 | } | |
20d3e6e3 | 1772 | |
38ef2572 JC |
1773 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s : %d => ADDR: 0x%x", __FUNCTION__, __LINE__, pDstInputData->buffer.multiPlaneBuffer.dataBuffer[0]); |
1774 | codecReturn = pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pDstInputData->buffer.multiPlaneBuffer.dataBuffer, (unsigned int *)&dataLen, 2, pDstInputData->bufferHeader); | |
1775 | if (codecReturn != VIDEO_ERROR_NONE) { | |
38ef2572 | 1776 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__); |
3e79a27e | 1777 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode; |
38ef2572 JC |
1778 | goto EXIT; |
1779 | } | |
1780 | H264CodecStart(pOMXComponent, OUTPUT_PORT_INDEX); | |
800a8d75 | 1781 | |
38ef2572 | 1782 | ret = OMX_ErrorNone; |
20d3e6e3 | 1783 | |
38ef2572 JC |
1784 | EXIT: |
1785 | FunctionOut(); | |
20d3e6e3 | 1786 | |
38ef2572 JC |
1787 | return ret; |
1788 | } | |
20d3e6e3 | 1789 | |
38ef2572 JC |
1790 | OMX_ERRORTYPE Exynos_H264Dec_DstOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData) |
1791 | { | |
1792 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1793 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1794 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1795 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1796 | void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; | |
1797 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1798 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1799 | ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps; | |
1800 | ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; | |
1801 | ExynosVideoBuffer *pVideoBuffer; | |
1802 | ExynosVideoFrameStatusType displayStatus = VIDEO_FRAME_STATUS_UNKNOWN; | |
1803 | ExynosVideoGeometry *bufferGeometry; | |
1804 | DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL; | |
1805 | OMX_S32 indexTimestamp = 0; | |
20d3e6e3 | 1806 | |
38ef2572 | 1807 | FunctionIn(); |
20d3e6e3 | 1808 | |
38ef2572 JC |
1809 | if (pH264Dec->bDestinationStart == OMX_FALSE) { |
1810 | ret = OMX_ErrorNone; | |
1811 | goto EXIT; | |
1812 | } | |
20d3e6e3 | 1813 | |
38ef2572 JC |
1814 | while (1) { |
1815 | if ((pVideoBuffer = pOutbufOps->Dequeue(hMFCHandle)) == NULL) { | |
1816 | ret = OMX_ErrorNone; | |
1817 | goto EXIT; | |
20d3e6e3 | 1818 | } |
38ef2572 JC |
1819 | displayStatus = pVideoBuffer->displayStatus; |
1820 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "displayStatus: 0x%x", displayStatus); | |
1821 | ||
1822 | if ((displayStatus == VIDEO_FRAME_STATUS_DISPLAY_DECODING) || | |
1823 | (displayStatus == VIDEO_FRAME_STATUS_DISPLAY_ONLY) || | |
1824 | (displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) || | |
1825 | (CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) { | |
1826 | if (pVideoBuffer != NULL) { | |
1827 | ret = OMX_ErrorNone; | |
20d3e6e3 | 1828 | break; |
38ef2572 JC |
1829 | } else { |
1830 | ret = OMX_ErrorUndefined; | |
20d3e6e3 JC |
1831 | break; |
1832 | } | |
38ef2572 JC |
1833 | } |
1834 | } | |
20d3e6e3 | 1835 | |
38ef2572 JC |
1836 | if (ret != OMX_ErrorNone) |
1837 | goto EXIT; | |
1838 | ||
1839 | pH264Dec->hMFCH264Handle.outputIndexTimestamp++; | |
1840 | pH264Dec->hMFCH264Handle.outputIndexTimestamp %= MAX_TIMESTAMP; | |
1841 | ||
1842 | pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[0] = pVideoBuffer->planes[0].addr; | |
01fa64f5 | 1843 | pDstOutputData->buffer.multiPlaneBuffer.fd[0] = pVideoBuffer->planes[0].fd; |
38ef2572 | 1844 | pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[1] = pVideoBuffer->planes[1].addr; |
01fa64f5 | 1845 | pDstOutputData->buffer.multiPlaneBuffer.fd[1] = pVideoBuffer->planes[1].fd; |
38ef2572 | 1846 | pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[2] = pVideoBuffer->planes[2].addr; |
01fa64f5 | 1847 | pDstOutputData->buffer.multiPlaneBuffer.fd[2] = pVideoBuffer->planes[2].fd; |
38ef2572 JC |
1848 | pDstOutputData->allocSize = pVideoBuffer->planes[0].allocSize + pVideoBuffer->planes[1].allocSize + pVideoBuffer->planes[2].allocSize; |
1849 | pDstOutputData->dataLen = pVideoBuffer->planes[0].dataSize + pVideoBuffer->planes[1].dataSize + pVideoBuffer->planes[2].dataSize; | |
1850 | pDstOutputData->usedDataLen = 0; | |
1851 | pDstOutputData->pPrivate = pVideoBuffer; | |
1852 | /* For Share Buffer */ | |
1853 | pDstOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE *)pVideoBuffer->pPrivate; | |
1854 | ||
1855 | pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pDstOutputData->extInfo; | |
1856 | bufferGeometry = &pH264Dec->hMFCH264Handle.codecOutbufConf; | |
1857 | pBufferInfo->imageWidth = bufferGeometry->nFrameWidth; | |
1858 | pBufferInfo->imageHeight = bufferGeometry->nFrameHeight; | |
1859 | switch (bufferGeometry->eColorFormat) { | |
1860 | case VIDEO_COLORFORMAT_NV12: | |
1861 | pBufferInfo->ColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; | |
1862 | break; | |
1863 | case VIDEO_COLORFORMAT_NV12_TILED: | |
1864 | default: | |
1865 | pBufferInfo->ColorFormat = OMX_SEC_COLOR_FormatNV12Tiled; | |
1866 | break; | |
1867 | } | |
1868 | ||
1869 | indexTimestamp = pDecOps->Get_FrameTag(hMFCHandle); | |
1870 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "out indexTimestamp: %d", indexTimestamp); | |
1871 | if ((indexTimestamp < 0) || (indexTimestamp >= MAX_TIMESTAMP)) { | |
1872 | if ((pExynosComponent->checkTimeStamp.needSetStartTimeStamp != OMX_TRUE) && | |
1873 | (pExynosComponent->checkTimeStamp.needCheckStartTimeStamp != OMX_TRUE)) { | |
1874 | pDstOutputData->timeStamp = pExynosComponent->timeStamp[pH264Dec->hMFCH264Handle.outputIndexTimestamp]; | |
1875 | pDstOutputData->nFlags = pExynosComponent->nFlags[pH264Dec->hMFCH264Handle.outputIndexTimestamp]; | |
1876 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "missing out indexTimestamp: %d", indexTimestamp); | |
1877 | } else { | |
1878 | pDstOutputData->timeStamp = 0x00; | |
1879 | pDstOutputData->nFlags = 0x00; | |
20d3e6e3 | 1880 | } |
38ef2572 JC |
1881 | } else { |
1882 | /* For timestamp correction. if mfc support frametype detect */ | |
1883 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "disp_pic_frame_type: %d", pVideoBuffer->frameType); | |
1884 | #ifdef NEED_TIMESTAMP_REORDER | |
1885 | if ((pVideoBuffer->frameType == VIDEO_FRAME_I)) { | |
1886 | pDstOutputData->timeStamp = pExynosComponent->timeStamp[indexTimestamp]; | |
1887 | pDstOutputData->nFlags = pExynosComponent->nFlags[indexTimestamp]; | |
1888 | pH264Dec->hMFCH264Handle.outputIndexTimestamp = indexTimestamp; | |
1889 | } else { | |
1890 | pDstOutputData->timeStamp = pExynosComponent->timeStamp[pH264Dec->hMFCH264Handle.outputIndexTimestamp]; | |
1891 | pDstOutputData->nFlags = pExynosComponent->nFlags[pH264Dec->hMFCH264Handle.outputIndexTimestamp]; | |
20d3e6e3 | 1892 | } |
38ef2572 JC |
1893 | #else |
1894 | pDstOutputData->timeStamp = pExynosComponent->timeStamp[indexTimestamp]; | |
1895 | pDstOutputData->nFlags = pExynosComponent->nFlags[indexTimestamp]; | |
20d3e6e3 | 1896 | #endif |
38ef2572 JC |
1897 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "timestamp %lld us (%.2f secs), indexTimestamp: %d, nFlags: 0x%x", pDstOutputData->timeStamp, pDstOutputData->timeStamp / 1E6, indexTimestamp, pDstOutputData->nFlags); |
1898 | } | |
1899 | ||
1900 | if ((displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) || | |
1901 | ((pDstOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) { | |
3e79a27e | 1902 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "displayStatus:%d, nFlags0x%x", displayStatus, pDstOutputData->nFlags); |
38ef2572 | 1903 | pDstOutputData->remainDataLen = 0; |
20d3e6e3 | 1904 | } else { |
38ef2572 | 1905 | pDstOutputData->remainDataLen = bufferGeometry->nFrameWidth * bufferGeometry->nFrameHeight * 3 / 2; |
20d3e6e3 JC |
1906 | } |
1907 | ||
38ef2572 JC |
1908 | ret = OMX_ErrorNone; |
1909 | ||
20d3e6e3 JC |
1910 | EXIT: |
1911 | FunctionOut(); | |
1912 | ||
1913 | return ret; | |
1914 | } | |
1915 | ||
38ef2572 | 1916 | OMX_ERRORTYPE Exynos_H264Dec_srcInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData) |
20d3e6e3 | 1917 | { |
38ef2572 JC |
1918 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
1919 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1920 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1921 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
20d3e6e3 JC |
1922 | |
1923 | FunctionIn(); | |
1924 | ||
38ef2572 | 1925 | if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) { |
20d3e6e3 JC |
1926 | ret = OMX_ErrorNone; |
1927 | goto EXIT; | |
1928 | } | |
38ef2572 | 1929 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) { |
20d3e6e3 JC |
1930 | ret = OMX_ErrorNone; |
1931 | goto EXIT; | |
1932 | } | |
1933 | ||
38ef2572 JC |
1934 | ret = Exynos_H264Dec_SrcIn(pOMXComponent, pSrcInputData); |
1935 | if ((ret != OMX_ErrorNone) && (ret != OMX_ErrorInputDataDecodeYet)) { | |
1936 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
1937 | pExynosComponent->callbackData, | |
1938 | OMX_EventError, ret, 0, NULL); | |
20d3e6e3 JC |
1939 | } |
1940 | ||
1941 | EXIT: | |
1942 | FunctionOut(); | |
1943 | ||
1944 | return ret; | |
1945 | } | |
1946 | ||
38ef2572 | 1947 | OMX_ERRORTYPE Exynos_H264Dec_srcOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData) |
800a8d75 | 1948 | { |
38ef2572 JC |
1949 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
1950 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1951 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1952 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
800a8d75 JC |
1953 | |
1954 | FunctionIn(); | |
1955 | ||
38ef2572 JC |
1956 | if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) { |
1957 | ret = OMX_ErrorNone; | |
1958 | goto EXIT; | |
1959 | } | |
800a8d75 | 1960 | |
38ef2572 JC |
1961 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
1962 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) { | |
1963 | ret = OMX_ErrorNone; | |
1964 | goto EXIT; | |
1965 | } | |
1966 | } | |
1967 | if ((pH264Dec->bSourceStart == OMX_FALSE) && | |
1968 | (!CHECK_PORT_BEING_FLUSHED(pExynosInputPort))) { | |
1969 | Exynos_OSAL_SignalWait(pH264Dec->hSourceStartEvent, DEF_MAX_WAIT_TIME); | |
1970 | Exynos_OSAL_SignalReset(pH264Dec->hSourceStartEvent); | |
1971 | } | |
800a8d75 | 1972 | |
38ef2572 JC |
1973 | ret = Exynos_H264Dec_SrcOut(pOMXComponent, pSrcOutputData); |
1974 | if ((ret != OMX_ErrorNone) && (pExynosComponent->currentState == OMX_StateExecuting)) { | |
1975 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
1976 | pExynosComponent->callbackData, | |
1977 | OMX_EventError, ret, 0, NULL); | |
1978 | } | |
800a8d75 | 1979 | |
38ef2572 JC |
1980 | EXIT: |
1981 | FunctionOut(); | |
1982 | ||
1983 | return ret; | |
1984 | } | |
800a8d75 | 1985 | |
38ef2572 JC |
1986 | OMX_ERRORTYPE Exynos_H264Dec_dstInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData) |
1987 | { | |
1988 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1989 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1990 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1991 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
800a8d75 | 1992 | |
38ef2572 | 1993 | FunctionIn(); |
800a8d75 | 1994 | |
38ef2572 JC |
1995 | if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) { |
1996 | ret = OMX_ErrorNone; | |
800a8d75 JC |
1997 | goto EXIT; |
1998 | } | |
38ef2572 JC |
1999 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) { |
2000 | ret = OMX_ErrorNone; | |
2001 | goto EXIT; | |
2002 | } | |
2003 | if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
2004 | if ((pH264Dec->bDestinationStart == OMX_FALSE) && | |
2005 | (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) { | |
2006 | Exynos_OSAL_SignalWait(pH264Dec->hDestinationStartEvent, DEF_MAX_WAIT_TIME); | |
2007 | Exynos_OSAL_SignalReset(pH264Dec->hDestinationStartEvent); | |
2008 | } | |
2009 | } | |
2010 | if (pH264Dec->hMFCH264Handle.bConfiguredMFCDst == OMX_TRUE) { | |
2011 | ret = Exynos_H264Dec_DstIn(pOMXComponent, pDstInputData); | |
2012 | if (ret != OMX_ErrorNone) { | |
2013 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
2014 | pExynosComponent->callbackData, | |
2015 | OMX_EventError, ret, 0, NULL); | |
2016 | } | |
2017 | } | |
2018 | ||
2019 | EXIT: | |
2020 | FunctionOut(); | |
800a8d75 | 2021 | |
38ef2572 JC |
2022 | return ret; |
2023 | } | |
800a8d75 | 2024 | |
38ef2572 JC |
2025 | OMX_ERRORTYPE Exynos_H264Dec_dstOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData) |
2026 | { | |
2027 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
2028 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2029 | EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
2030 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
800a8d75 | 2031 | |
38ef2572 | 2032 | FunctionIn(); |
800a8d75 | 2033 | |
38ef2572 JC |
2034 | if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) { |
2035 | ret = OMX_ErrorNone; | |
800a8d75 JC |
2036 | goto EXIT; |
2037 | } | |
38ef2572 JC |
2038 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) { |
2039 | ret = OMX_ErrorNone; | |
800a8d75 JC |
2040 | goto EXIT; |
2041 | } | |
2042 | ||
38ef2572 JC |
2043 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
2044 | if ((pH264Dec->bDestinationStart == OMX_FALSE) && | |
2045 | (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) { | |
2046 | Exynos_OSAL_SignalWait(pH264Dec->hDestinationStartEvent, DEF_MAX_WAIT_TIME); | |
2047 | Exynos_OSAL_SignalReset(pH264Dec->hDestinationStartEvent); | |
2048 | } | |
2049 | } | |
2050 | ret = Exynos_H264Dec_DstOut(pOMXComponent, pDstOutputData); | |
2051 | if ((ret != OMX_ErrorNone) && (pExynosComponent->currentState == OMX_StateExecuting)) { | |
2052 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
2053 | pExynosComponent->callbackData, | |
2054 | OMX_EventError, ret, 0, NULL); | |
800a8d75 JC |
2055 | } |
2056 | ||
2057 | EXIT: | |
2058 | FunctionOut(); | |
2059 | ||
2060 | return ret; | |
2061 | } | |
2062 | ||
38ef2572 | 2063 | OSCL_EXPORT_REF OMX_ERRORTYPE Exynos_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) |
20d3e6e3 | 2064 | { |
3e79a27e SK |
2065 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
2066 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
20d3e6e3 | 2067 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
3e79a27e SK |
2068 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
2069 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
2070 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
2071 | OMX_BOOL bDRMPlayerMode = OMX_FALSE; | |
20d3e6e3 JC |
2072 | int i = 0; |
2073 | ||
2074 | FunctionIn(); | |
2075 | ||
2076 | if ((hComponent == NULL) || (componentName == NULL)) { | |
2077 | ret = OMX_ErrorBadParameter; | |
2078 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); | |
2079 | goto EXIT; | |
2080 | } | |
38ef2572 JC |
2081 | if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_H264_DEC, componentName) == 0) { |
2082 | bDRMPlayerMode = OMX_FALSE; | |
2083 | } else if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_H264_DRM_DEC, componentName) == 0) { | |
800a8d75 | 2084 | bDRMPlayerMode = OMX_TRUE; |
38ef2572 | 2085 | } else { |
20d3e6e3 JC |
2086 | ret = OMX_ErrorBadParameter; |
2087 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, componentName:%s, Line:%d", componentName, __LINE__); | |
2088 | goto EXIT; | |
2089 | } | |
2090 | ||
2091 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
2092 | ret = Exynos_OMX_VideoDecodeComponentInit(pOMXComponent); | |
2093 | if (ret != OMX_ErrorNone) { | |
2094 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__); | |
2095 | goto EXIT; | |
2096 | } | |
2097 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2098 | pExynosComponent->codecType = HW_VIDEO_DEC_CODEC; | |
2099 | ||
2100 | pExynosComponent->componentName = (OMX_STRING)Exynos_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); | |
2101 | if (pExynosComponent->componentName == NULL) { | |
2102 | Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent); | |
2103 | ret = OMX_ErrorInsufficientResources; | |
2104 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); | |
2105 | goto EXIT; | |
2106 | } | |
2107 | Exynos_OSAL_Memset(pExynosComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); | |
2108 | ||
2109 | pH264Dec = Exynos_OSAL_Malloc(sizeof(EXYNOS_H264DEC_HANDLE)); | |
2110 | if (pH264Dec == NULL) { | |
2111 | Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent); | |
2112 | ret = OMX_ErrorInsufficientResources; | |
2113 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); | |
2114 | goto EXIT; | |
2115 | } | |
2116 | Exynos_OSAL_Memset(pH264Dec, 0, sizeof(EXYNOS_H264DEC_HANDLE)); | |
2117 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
2118 | pVideoDec->hCodecHandle = (OMX_HANDLETYPE)pH264Dec; | |
2119 | ||
38ef2572 | 2120 | if (bDRMPlayerMode == OMX_TRUE) |
800a8d75 | 2121 | Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_H264_DRM_DEC); |
20d3e6e3 JC |
2122 | else |
2123 | Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_H264_DEC); | |
2124 | ||
800a8d75 | 2125 | pVideoDec->bDRMPlayerMode = bDRMPlayerMode; |
20d3e6e3 JC |
2126 | |
2127 | /* Set componentVersion */ | |
2128 | pExynosComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; | |
2129 | pExynosComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; | |
2130 | pExynosComponent->componentVersion.s.nRevision = REVISION_NUMBER; | |
2131 | pExynosComponent->componentVersion.s.nStep = STEP_NUMBER; | |
2132 | /* Set specVersion */ | |
2133 | pExynosComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; | |
2134 | pExynosComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; | |
2135 | pExynosComponent->specVersion.s.nRevision = REVISION_NUMBER; | |
2136 | pExynosComponent->specVersion.s.nStep = STEP_NUMBER; | |
2137 | ||
20d3e6e3 JC |
2138 | /* Input port */ |
2139 | pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
2140 | pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; | |
2141 | pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; | |
2142 | pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/ | |
2143 | pExynosPort->portDefinition.format.video.nSliceHeight = 0; | |
2144 | pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; | |
2145 | pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; | |
2146 | Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); | |
2147 | Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "video/avc"); | |
2148 | pExynosPort->portDefinition.format.video.pNativeRender = 0; | |
2149 | pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; | |
2150 | pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; | |
2151 | pExynosPort->portDefinition.bEnabled = OMX_TRUE; | |
38ef2572 JC |
2152 | pExynosPort->bufferProcessType = BUFFER_SHARE; |
2153 | if (bDRMPlayerMode == OMX_TRUE) | |
2154 | pExynosPort->bufferProcessType = BUFFER_SHARE; | |
2155 | pExynosPort->portWayType = WAY2_PORT; | |
20d3e6e3 JC |
2156 | |
2157 | /* Output port */ | |
2158 | pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
2159 | pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; | |
2160 | pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; | |
2161 | pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/ | |
2162 | pExynosPort->portDefinition.format.video.nSliceHeight = 0; | |
2163 | pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; | |
2164 | pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; | |
2165 | Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); | |
2166 | Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "raw/video"); | |
2167 | pExynosPort->portDefinition.format.video.pNativeRender = 0; | |
2168 | pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; | |
2169 | pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar; | |
2170 | pExynosPort->portDefinition.bEnabled = OMX_TRUE; | |
38ef2572 JC |
2171 | pExynosPort->bufferProcessType = BUFFER_COPY | BUFFER_ANBSHARE; |
2172 | pExynosPort->portWayType = WAY2_PORT; | |
20d3e6e3 JC |
2173 | |
2174 | for(i = 0; i < ALL_PORT_NUM; i++) { | |
2175 | INIT_SET_SIZE_VERSION(&pH264Dec->AVCComponent[i], OMX_VIDEO_PARAM_AVCTYPE); | |
2176 | pH264Dec->AVCComponent[i].nPortIndex = i; | |
2177 | pH264Dec->AVCComponent[i].eProfile = OMX_VIDEO_AVCProfileBaseline; | |
2178 | pH264Dec->AVCComponent[i].eLevel = OMX_VIDEO_AVCLevel4; | |
2179 | } | |
2180 | ||
800a8d75 JC |
2181 | pOMXComponent->GetParameter = &Exynos_H264Dec_GetParameter; |
2182 | pOMXComponent->SetParameter = &Exynos_H264Dec_SetParameter; | |
2183 | pOMXComponent->GetConfig = &Exynos_H264Dec_GetConfig; | |
2184 | pOMXComponent->SetConfig = &Exynos_H264Dec_SetConfig; | |
2185 | pOMXComponent->GetExtensionIndex = &Exynos_H264Dec_GetExtensionIndex; | |
2186 | pOMXComponent->ComponentRoleEnum = &Exynos_H264Dec_ComponentRoleEnum; | |
20d3e6e3 JC |
2187 | pOMXComponent->ComponentDeInit = &Exynos_OMX_ComponentDeinit; |
2188 | ||
38ef2572 JC |
2189 | pExynosComponent->exynos_codec_componentInit = &Exynos_H264Dec_Init; |
2190 | pExynosComponent->exynos_codec_componentTerminate = &Exynos_H264Dec_Terminate; | |
800a8d75 | 2191 | |
38ef2572 JC |
2192 | pVideoDec->exynos_codec_srcInputProcess = &Exynos_H264Dec_srcInputBufferProcess; |
2193 | pVideoDec->exynos_codec_srcOutputProcess = &Exynos_H264Dec_srcOutputBufferProcess; | |
2194 | pVideoDec->exynos_codec_dstInputProcess = &Exynos_H264Dec_dstInputBufferProcess; | |
2195 | pVideoDec->exynos_codec_dstOutputProcess = &Exynos_H264Dec_dstOutputBufferProcess; | |
2196 | ||
3e79a27e SK |
2197 | pVideoDec->exynos_codec_start = &H264CodecStart; |
2198 | pVideoDec->exynos_codec_stop = &H264CodecStop; | |
38ef2572 JC |
2199 | pVideoDec->exynos_codec_bufferProcessRun = &H264CodecOutputBufferProcessRun; |
2200 | pVideoDec->exynos_codec_enqueueAllBuffer = &H264CodecEnQueueAllBuffer; | |
2201 | ||
2202 | pVideoDec->exynos_checkInputFrame = &Check_H264_Frame; | |
2203 | pVideoDec->exynos_codec_getCodecInputPrivateData = &GetCodecInputPrivateData; | |
2204 | pVideoDec->exynos_codec_getCodecOutputPrivateData = &GetCodecOutputPrivateData; | |
2205 | ||
2206 | pVideoDec->hSharedMemory = Exynos_OSAL_SharedMemory_Open(); | |
2207 | if (pVideoDec->hSharedMemory == NULL) { | |
3e79a27e | 2208 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); |
38ef2572 JC |
2209 | Exynos_OSAL_Free(pH264Dec); |
2210 | pH264Dec = ((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle = NULL; | |
2211 | Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent); | |
2212 | ret = OMX_ErrorInsufficientResources; | |
2213 | goto EXIT; | |
800a8d75 | 2214 | } |
20d3e6e3 JC |
2215 | |
2216 | pExynosComponent->currentState = OMX_StateLoaded; | |
2217 | ||
2218 | ret = OMX_ErrorNone; | |
2219 | ||
2220 | EXIT: | |
2221 | FunctionOut(); | |
2222 | ||
2223 | return ret; | |
2224 | } | |
2225 | ||
2226 | OMX_ERRORTYPE Exynos_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent) | |
2227 | { | |
2228 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
2229 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
2230 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
2231 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
2232 | EXYNOS_H264DEC_HANDLE *pH264Dec = NULL; | |
2233 | ||
2234 | FunctionIn(); | |
2235 | ||
2236 | if (hComponent == NULL) { | |
2237 | ret = OMX_ErrorBadParameter; | |
2238 | goto EXIT; | |
2239 | } | |
2240 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
2241 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2242 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
2243 | ||
38ef2572 JC |
2244 | Exynos_OSAL_SharedMemory_Close(pVideoDec->hSharedMemory); |
2245 | ||
20d3e6e3 JC |
2246 | Exynos_OSAL_Free(pExynosComponent->componentName); |
2247 | pExynosComponent->componentName = NULL; | |
2248 | ||
38ef2572 | 2249 | pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle; |
20d3e6e3 JC |
2250 | if (pH264Dec != NULL) { |
2251 | Exynos_OSAL_Free(pH264Dec); | |
38ef2572 | 2252 | pH264Dec = pVideoDec->hCodecHandle = NULL; |
20d3e6e3 JC |
2253 | } |
2254 | ||
2255 | ret = Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent); | |
2256 | if (ret != OMX_ErrorNone) { | |
2257 | goto EXIT; | |
2258 | } | |
2259 | ||
2260 | ret = OMX_ErrorNone; | |
2261 | ||
2262 | EXIT: | |
2263 | FunctionOut(); | |
2264 | ||
2265 | return ret; | |
2266 | } |