video: Add missing function prototypes
[GitHub/LineageOS/android_hardware_samsung_slsi_openmax.git] / component / video / dec / h264 / Exynos_OMX_H264dec.c
CommitLineData
c6f4bc34
YK
1/*
2 *
3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
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)
22 * @version 2.0.0
23 * @history
24 * 2012.02.20 : Create
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"
433e798a 35#include "Exynos_OMX_VdecControl.h"
c6f4bc34
YK
36#include "Exynos_OSAL_ETC.h"
37#include "Exynos_OSAL_Semaphore.h"
38#include "Exynos_OSAL_Thread.h"
39#include "library_register.h"
40#include "Exynos_OMX_H264dec.h"
41#include "ExynosVideoApi.h"
42#include "Exynos_OSAL_SharedMemory.h"
43#include "Exynos_OSAL_Event.h"
44
45#ifdef USE_ANB
46#include "Exynos_OSAL_Android.h"
47#endif
48
49/* To use CSC_METHOD_HW in EXYNOS OMX, gralloc should allocate physical memory using FIMC */
50/* It means GRALLOC_USAGE_HW_FIMC1 should be set on Native Window usage */
51#include "csc.h"
52
53#undef EXYNOS_LOG_TAG
54#define EXYNOS_LOG_TAG "EXYNOS_H264_DEC"
55#define EXYNOS_LOG_OFF
56//#define EXYNOS_TRACE_ON
57#include "Exynos_OSAL_Log.h"
58
59#define H264_DEC_NUM_OF_EXTRA_BUFFERS 7
60
61//#define ADD_SPS_PPS_I_FRAME
62//#define FULL_FRAME_SEARCH
63
64/* H.264 Decoder Supported Levels & profiles */
65EXYNOS_OMX_VIDEO_PROFILELEVEL supportedAVCProfileLevels[] ={
66 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1},
67 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1b},
68 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel11},
69 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel12},
70 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel13},
71 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel2},
72 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel21},
73 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel22},
74 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel3},
75 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel31},
76 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel32},
77 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel4},
78 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel41},
79 {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel42},
80
81 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel1},
82 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel1b},
83 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel11},
84 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel12},
85 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel13},
86 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel2},
87 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel21},
88 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel22},
89 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel3},
90 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel31},
91 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel32},
92 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel4},
93 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel41},
94 {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel42},
95
96 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel1},
97 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel1b},
98 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel11},
99 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel12},
100 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel13},
101 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel2},
102 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel21},
103 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel22},
104 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel3},
105 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel31},
106 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel32},
107 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel4},
108 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel41},
109 {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel42}};
110
cc46393d
AS
111OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent);
112
c6f4bc34
YK
113static OMX_ERRORTYPE GetCodecInputPrivateData(OMX_PTR codecBuffer, void *pVirtAddr, OMX_U32 *dataSize)
114{
115 OMX_ERRORTYPE ret = OMX_ErrorNone;
116
117EXIT:
118 return ret;
119}
120
121static OMX_ERRORTYPE GetCodecOutputPrivateData(OMX_PTR codecBuffer, void *addr[], int size[])
122{
123 OMX_ERRORTYPE ret = OMX_ErrorNone;
124 ExynosVideoBuffer *pCodecBuffer;
125
126 if (codecBuffer == NULL) {
127 ret = OMX_ErrorBadParameter;
128 goto EXIT;
129 }
130
131 pCodecBuffer = (ExynosVideoBuffer *)codecBuffer;
132
133 if (addr != NULL) {
134 addr[0] = pCodecBuffer->planes[0].addr;
135 addr[1] = pCodecBuffer->planes[1].addr;
136 addr[2] = pCodecBuffer->planes[2].addr;
137 }
138
139 if (size != NULL) {
140 size[0] = pCodecBuffer->planes[0].allocSize;
141 size[1] = pCodecBuffer->planes[1].allocSize;
142 size[2] = pCodecBuffer->planes[2].allocSize;
143 }
144
145EXIT:
146 return ret;
147}
148
149int Check_H264_Frame(
150 OMX_U8 *pInputStream,
151 OMX_U32 buffSize,
152 OMX_U32 flag,
153 OMX_BOOL bPreviousFrameEOF,
154 OMX_BOOL *pbEndOfFrame)
155{
156 OMX_U32 preFourByte = (OMX_U32)-1;
157 int accessUnitSize = 0;
158 int frameTypeBoundary = 0;
159 int nextNaluSize = 0;
160 int naluStart = 0;
161
162 if (bPreviousFrameEOF == OMX_TRUE)
163 naluStart = 0;
164 else
165 naluStart = 1;
166
167 while (1) {
168 int inputOneByte = 0;
169
170 if (accessUnitSize == (int)buffSize)
171 goto EXIT;
172
173 inputOneByte = *(pInputStream++);
174 accessUnitSize += 1;
175
176 if (preFourByte == 0x00000001 || (preFourByte << 8) == 0x00000100) {
177 int naluType = inputOneByte & 0x1F;
178
179 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NaluType : %d", naluType);
180 if (naluStart == 0) {
181#ifdef ADD_SPS_PPS_I_FRAME
182 if (naluType == 1 || naluType == 5)
183#else
184 if (naluType == 1 || naluType == 5 || naluType == 7 || naluType == 8)
185#endif
186 naluStart = 1;
187 } else {
188#ifdef OLD_DETECT
189 frameTypeBoundary = (8 - naluType) & (naluType - 10); //AUD(9)
190#else
191 if (naluType == 9)
192 frameTypeBoundary = -2;
193#endif
194 if (naluType == 1 || naluType == 5) {
195 if (accessUnitSize == (int)buffSize) {
196 accessUnitSize--;
197 goto EXIT;
198 }
199 inputOneByte = *pInputStream++;
200 accessUnitSize += 1;
201
202 if (inputOneByte >= 0x80)
203 frameTypeBoundary = -1;
204 }
205 if (frameTypeBoundary < 0) {
206 break;
207 }
208 }
209
210 }
211 preFourByte = (preFourByte << 8) + inputOneByte;
212 }
213
214 *pbEndOfFrame = OMX_TRUE;
215 nextNaluSize = -5;
216 if (frameTypeBoundary == -1)
217 nextNaluSize = -6;
218 if (preFourByte != 0x00000001)
219 nextNaluSize++;
220 return (accessUnitSize + nextNaluSize);
221
222EXIT:
223 *pbEndOfFrame = OMX_FALSE;
224
225 return accessUnitSize;
226}
227
228static OMX_BOOL Check_H264_StartCode(
229 OMX_U8 *pInputStream,
230 OMX_U32 streamSize)
231{
232 if (streamSize < 4) {
233 return OMX_FALSE;
234 }
235
236 if ((pInputStream[0] == 0x00) &&
237 (pInputStream[1] == 0x00) &&
238 (pInputStream[2] == 0x00) &&
239 (pInputStream[3] != 0x00) &&
240 ((pInputStream[3] >> 3) == 0x00)) {
241 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NaluType : %d, 0x%x, 0x%x, 0x%x", (pInputStream[4] & 0x1F), pInputStream[3], pInputStream[4], pInputStream[5]);
242 return OMX_TRUE;
243 } else if ((pInputStream[0] == 0x00) &&
244 (pInputStream[1] == 0x00) &&
245 (pInputStream[2] != 0x00) &&
246 ((pInputStream[2] >> 3) == 0x00)) {
247 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NaluType : %d, 0x%x, 0x%x, 0x%x", (pInputStream[3] & 0x1F), pInputStream[2], pInputStream[3], pInputStream[4]);
248 return OMX_TRUE;
249 } else {
250 return OMX_FALSE;
251 }
252}
253
254OMX_ERRORTYPE H264CodecOpen(EXYNOS_H264DEC_HANDLE *pH264Dec)
255{
256 OMX_ERRORTYPE ret = OMX_ErrorNone;
257 ExynosVideoDecOps *pDecOps = NULL;
258 ExynosVideoDecBufferOps *pInbufOps = NULL;
259 ExynosVideoDecBufferOps *pOutbufOps = NULL;
260
261 FunctionIn();
262
263 if (pH264Dec == NULL) {
264 ret = OMX_ErrorBadParameter;
265 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
266 goto EXIT;
267 }
268
269 /* alloc ops structure */
270 pDecOps = (ExynosVideoDecOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecOps));
271 pInbufOps = (ExynosVideoDecBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecBufferOps));
272 pOutbufOps = (ExynosVideoDecBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoDecBufferOps));
273
274 if ((pDecOps == NULL) || (pInbufOps == NULL) || (pOutbufOps == NULL)) {
275 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate decoder ops buffer");
276 ret = OMX_ErrorInsufficientResources;
277 goto EXIT;
278 }
279
280 pH264Dec->hMFCH264Handle.pDecOps = pDecOps;
281 pH264Dec->hMFCH264Handle.pInbufOps = pInbufOps;
282 pH264Dec->hMFCH264Handle.pOutbufOps = pOutbufOps;
283
284 /* function pointer mapping */
285 pDecOps->nSize = sizeof(ExynosVideoDecOps);
286 pInbufOps->nSize = sizeof(ExynosVideoDecBufferOps);
287 pOutbufOps->nSize = sizeof(ExynosVideoDecBufferOps);
288
289 Exynos_Video_Register_Decoder(pDecOps, pInbufOps, pOutbufOps);
290
291 /* check mandatory functions for decoder ops */
292 if ((pDecOps->Init == NULL) || (pDecOps->Finalize == NULL) ||
293 (pDecOps->Get_ActualBufferCount == NULL) || (pDecOps->Set_FrameTag == NULL) ||
064c4768
SKR
294#ifdef USE_S3D_SUPPORT
295 (pDecOps->Enable_SEIParsing == NULL) || (pDecOps->Get_FramePackingInfo == NULL) ||
296#endif
c6f4bc34
YK
297 (pDecOps->Get_FrameTag == NULL)) {
298 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied");
299 ret = OMX_ErrorInsufficientResources;
300 goto EXIT;
301 }
302
303 /* check mandatory functions for buffer ops */
304 if ((pInbufOps->Setup == NULL) || (pOutbufOps->Setup == NULL) ||
305 (pInbufOps->Run == NULL) || (pOutbufOps->Run == NULL) ||
306 (pInbufOps->Stop == NULL) || (pOutbufOps->Stop == NULL) ||
307 (pInbufOps->Enqueue == NULL) || (pOutbufOps->Enqueue == NULL) ||
308 (pInbufOps->Dequeue == NULL) || (pOutbufOps->Dequeue == NULL)) {
309 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied");
310 ret = OMX_ErrorInsufficientResources;
311 goto EXIT;
312 }
313
314 /* alloc context, open, querycap */
faa0e22c 315#ifdef USE_DMA_BUF
c6f4bc34 316 pH264Dec->hMFCH264Handle.hMFCHandle = pH264Dec->hMFCH264Handle.pDecOps->Init(V4L2_MEMORY_DMABUF);
faa0e22c
SKR
317#else
318 pH264Dec->hMFCH264Handle.hMFCHandle = pH264Dec->hMFCH264Handle.pDecOps->Init(V4L2_MEMORY_USERPTR);
319#endif
c6f4bc34
YK
320 if (pH264Dec->hMFCH264Handle.hMFCHandle == NULL) {
321 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer");
322 ret = OMX_ErrorInsufficientResources;
323 goto EXIT;
324 }
325
064c4768
SKR
326#ifdef USE_S3D_SUPPORT
327 /* S3D: Enable SEI parsing to check Frame Packing */
328 if (pDecOps->Enable_SEIParsing(pH264Dec->hMFCH264Handle.hMFCHandle) != VIDEO_ERROR_NONE) {
329 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Enable SEI Parsing");
330 ret = OMX_ErrorInsufficientResources;
331 goto EXIT;
332 }
333#endif
334
c6f4bc34
YK
335 ret = OMX_ErrorNone;
336
337EXIT:
338 if (ret != OMX_ErrorNone) {
339 if (pDecOps != NULL) {
340 Exynos_OSAL_Free(pDecOps);
341 pH264Dec->hMFCH264Handle.pDecOps = NULL;
342 }
343 if (pInbufOps != NULL) {
344 Exynos_OSAL_Free(pInbufOps);
345 pH264Dec->hMFCH264Handle.pInbufOps = NULL;
346 }
347 if (pOutbufOps != NULL) {
348 Exynos_OSAL_Free(pOutbufOps);
349 pH264Dec->hMFCH264Handle.pOutbufOps = NULL;
350 }
351 }
352
353 FunctionOut();
354
355 return ret;
356}
357
358OMX_ERRORTYPE H264CodecClose(EXYNOS_H264DEC_HANDLE *pH264Dec)
359{
e4e150b8 360 OMX_ERRORTYPE ret = OMX_ErrorNone;
c6f4bc34
YK
361 void *hMFCHandle = NULL;
362 ExynosVideoDecOps *pDecOps = NULL;
363 ExynosVideoDecBufferOps *pInbufOps = NULL;
364 ExynosVideoDecBufferOps *pOutbufOps = NULL;
365
366 FunctionIn();
367
368 if (pH264Dec == NULL) {
369 ret = OMX_ErrorBadParameter;
370 goto EXIT;
371 }
372
373 hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
374 pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
375 pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
376 pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
377
378 if (hMFCHandle != NULL) {
379 pDecOps->Finalize(hMFCHandle);
380 pH264Dec->hMFCH264Handle.hMFCHandle = NULL;
381 }
382 if (pOutbufOps != NULL) {
383 Exynos_OSAL_Free(pOutbufOps);
384 pH264Dec->hMFCH264Handle.pOutbufOps = NULL;
385 }
386 if (pInbufOps != NULL) {
387 Exynos_OSAL_Free(pInbufOps);
388 pH264Dec->hMFCH264Handle.pInbufOps = NULL;
389 }
390 if (pDecOps != NULL) {
391 Exynos_OSAL_Free(pDecOps);
392 pH264Dec->hMFCH264Handle.pDecOps = NULL;
393 }
394
395 ret = OMX_ErrorNone;
396
397EXIT:
398 FunctionOut();
399
400 return ret;
401}
402
403OMX_ERRORTYPE H264CodecStart(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
404{
405 OMX_ERRORTYPE ret = OMX_ErrorNone;
406 void *hMFCHandle = NULL;
407 ExynosVideoDecOps *pDecOps = NULL;
408 ExynosVideoDecBufferOps *pInbufOps = NULL;
409 ExynosVideoDecBufferOps *pOutbufOps = NULL;
410 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
411 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
412
413 FunctionIn();
414
415 if (pOMXComponent == NULL) {
416 ret = OMX_ErrorBadParameter;
417 goto EXIT;
418 }
419
420 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle;
421 if (pVideoDec == NULL) {
422 ret = OMX_ErrorBadParameter;
423 goto EXIT;
424 }
425
426 pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
427 if (pH264Dec == NULL) {
428 ret = OMX_ErrorBadParameter;
429 goto EXIT;
430 }
431
432 hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
433 pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
434 pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
435 pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
436
437 if (nPortIndex == INPUT_PORT_INDEX)
438 pInbufOps->Run(hMFCHandle);
439 else if (nPortIndex == OUTPUT_PORT_INDEX)
440 pOutbufOps->Run(hMFCHandle);
441
442 ret = OMX_ErrorNone;
443
444EXIT:
445 FunctionOut();
446
447 return ret;
448}
449
450OMX_ERRORTYPE H264CodecStop(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
451{
452 OMX_ERRORTYPE ret = OMX_ErrorNone;
453 void *hMFCHandle = NULL;
454 ExynosVideoDecOps *pDecOps = NULL;
455 ExynosVideoDecBufferOps *pInbufOps = NULL;
456 ExynosVideoDecBufferOps *pOutbufOps = NULL;
457 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
458 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
459
460 FunctionIn();
461
462 if (pOMXComponent == NULL) {
463 ret = OMX_ErrorBadParameter;
464 goto EXIT;
465 }
466
467 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle;
468 if (pVideoDec == NULL) {
469 ret = OMX_ErrorBadParameter;
470 goto EXIT;
471 }
472 pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
473 if (pH264Dec == NULL) {
474 ret = OMX_ErrorBadParameter;
475 goto EXIT;
476 }
477
478 hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
479 pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
480 pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
481 pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
482
483 if ((nPortIndex == INPUT_PORT_INDEX) && (pInbufOps != NULL))
484 pInbufOps->Stop(hMFCHandle);
485 else if ((nPortIndex == OUTPUT_PORT_INDEX) && (pOutbufOps != NULL))
486 pOutbufOps->Stop(hMFCHandle);
487
488 ret = OMX_ErrorNone;
489
490EXIT:
491 FunctionOut();
492
493 return ret;
494}
495
496OMX_ERRORTYPE H264CodecOutputBufferProcessRun(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
497{
498 OMX_ERRORTYPE ret = OMX_ErrorNone;
499 void *hMFCHandle = NULL;
500 ExynosVideoDecOps *pDecOps = NULL;
501 ExynosVideoDecBufferOps *pInbufOps = NULL;
502 ExynosVideoDecBufferOps *pOutbufOps = NULL;
503 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
504 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
505
506 FunctionIn();
507
508 if (pOMXComponent == NULL) {
509 ret = OMX_ErrorBadParameter;
510 goto EXIT;
511 }
512
513 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle;
514 if (pVideoDec == NULL) {
515 ret = OMX_ErrorBadParameter;
516 goto EXIT;
517 }
518 pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
519 if (pH264Dec == NULL) {
520 ret = OMX_ErrorBadParameter;
521 goto EXIT;
522 }
523
524 hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
525 pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
526 pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
527 pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
528
529 if (nPortIndex == INPUT_PORT_INDEX) {
530 if (pH264Dec->bSourceStart == OMX_FALSE) {
531 Exynos_OSAL_SignalSet(pH264Dec->hSourceStartEvent);
532 Exynos_OSAL_SleepMillisec(0);
533 }
534 }
535
536 if (nPortIndex == OUTPUT_PORT_INDEX) {
537 if (pH264Dec->bDestinationStart == OMX_FALSE) {
538 Exynos_OSAL_SignalSet(pH264Dec->hDestinationStartEvent);
539 Exynos_OSAL_SleepMillisec(0);
540 }
541 }
542
543 ret = OMX_ErrorNone;
544
545EXIT:
546 FunctionOut();
547
548 return ret;
549}
550
0641ae29
TK
551OMX_ERRORTYPE H264CodecRegistCodecBuffers(
552 OMX_COMPONENTTYPE *pOMXComponent,
553 OMX_U32 nPortIndex,
554 OMX_U32 nBufferCnt)
555{
556 OMX_ERRORTYPE ret = OMX_ErrorNone;
557 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
558 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
559 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
560 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
561 CODEC_DEC_BUFFER **ppCodecBuffer = NULL;
562 ExynosVideoDecBufferOps *pBufOps = NULL;
563 ExynosVideoPlane *pPlanes = NULL;
564
565 OMX_U32 nPlaneCnt = 0;
566 int i, j;
567
568 FunctionIn();
569
570 if (nPortIndex == INPUT_PORT_INDEX) {
571 ppCodecBuffer = &(pVideoDec->pMFCDecInputBuffer[0]);
0641ae29
TK
572 pBufOps = pH264Dec->hMFCH264Handle.pInbufOps;
573 } else {
574 ppCodecBuffer = &(pVideoDec->pMFCDecOutputBuffer[0]);
0641ae29
TK
575 pBufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
576 }
433e798a 577 nPlaneCnt = pExynosComponent->pExynosPort[nPortIndex].nPlaneCnt;
0641ae29
TK
578
579 pPlanes = (ExynosVideoPlane *)Exynos_OSAL_Malloc(sizeof(ExynosVideoPlane) * nPlaneCnt);
580 if (pPlanes == NULL) {
581 ret = OMX_ErrorInsufficientResources;
582 goto EXIT;
583 }
584
585 /* Register buffer */
586 for (i = 0; i < nBufferCnt; i++) {
587 for (j = 0; j < nPlaneCnt; j++) {
588 pPlanes[j].addr = ppCodecBuffer[i]->pVirAddr[j];
589 pPlanes[j].fd = ppCodecBuffer[i]->fd[j];
590 pPlanes[j].allocSize = ppCodecBuffer[i]->bufferSize[j];
591 }
592
593 if (pBufOps->Register(hMFCHandle, pPlanes, nPlaneCnt) != VIDEO_ERROR_NONE) {
594 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "PORT[%d]: Failed to Register buffer", nPortIndex);
595 ret = OMX_ErrorInsufficientResources;
596 Exynos_OSAL_Free(pPlanes);
597 goto EXIT;
598 }
599 }
600
601 Exynos_OSAL_Free(pPlanes);
602
603 ret = OMX_ErrorNone;
604
605EXIT:
606 FunctionOut();
607
608 return ret;
609}
610
405399e5
TK
611OMX_ERRORTYPE H264CodecReconfigAllBuffers(
612 OMX_COMPONENTTYPE *pOMXComponent,
613 OMX_U32 nPortIndex)
614{
615 OMX_ERRORTYPE ret = OMX_ErrorNone;
616 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
617 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
618 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
619 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
620 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
621 ExynosVideoDecBufferOps *pBufferOps = NULL;
622
623 FunctionIn();
624
625 if ((nPortIndex == INPUT_PORT_INDEX) &&
626 (pH264Dec->bSourceStart == OMX_TRUE)) {
627 ret = OMX_ErrorNotImplemented;
628 goto EXIT;
629 } else if ((nPortIndex == OUTPUT_PORT_INDEX) &&
630 (pH264Dec->bDestinationStart == OMX_TRUE)) {
631 pBufferOps = pH264Dec->hMFCH264Handle.pOutbufOps;
632
633 if (pExynosPort->bufferProcessType & BUFFER_COPY) {
634 /**********************************/
635 /* Codec Buffer Free & Unregister */
636 /**********************************/
637 Exynos_Free_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX);
638 Exynos_CodecBufferReset(pExynosComponent, OUTPUT_PORT_INDEX);
639 pBufferOps->Clear_RegisteredBuffer(hMFCHandle);
640 pBufferOps->Cleanup_Buffer(hMFCHandle);
641
642 /******************************************************/
643 /* V4L2 Destnation Setup for DPB Buffer Number Change */
644 /******************************************************/
645 H264CodecDstSetup(pOMXComponent);
646
647 pVideoDec->bReconfigDPB = OMX_FALSE;
648 } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) {
649 /**********************************/
650 /* Codec Buffer Unregister */
651 /**********************************/
652 pBufferOps->Clear_RegisteredBuffer(hMFCHandle);
653 pBufferOps->Cleanup_Buffer(hMFCHandle);
654 }
655 } else {
656 ret = OMX_ErrorBadParameter;
657 goto EXIT;
658 }
659
660EXIT:
661 FunctionOut();
662
663 return ret;
664}
665
c6f4bc34
YK
666OMX_ERRORTYPE H264CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex)
667{
668 OMX_ERRORTYPE ret = OMX_ErrorNone;
669 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
670 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
671 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
672 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
673 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
674 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
675 int i, nOutbufs;
676
677 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
678 ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
679 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
680
681 FunctionIn();
682
17c96630
TK
683 if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) {
684 ret = OMX_ErrorBadPortIndex;
685 goto EXIT;
686 }
687
c6f4bc34
YK
688 if ((nPortIndex == INPUT_PORT_INDEX) &&
689 (pH264Dec->bSourceStart == OMX_TRUE)) {
690 Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX);
691
692 for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) {
693 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]);
694 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->pVirAddr[0]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]);
695
696 Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]);
697 }
698
699 pInbufOps->Clear_Queue(hMFCHandle);
700 } else if ((nPortIndex == OUTPUT_PORT_INDEX) &&
701 (pH264Dec->bDestinationStart == OMX_TRUE)) {
c6f4bc34
YK
702 Exynos_CodecBufferReset(pExynosComponent, OUTPUT_PORT_INDEX);
703
e90eb9e8
TK
704 for (i = 0; i < pH264Dec->hMFCH264Handle.maxDPBNum; i++) {
705 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecOutputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecOutputBuffer[i]);
706 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecOutputBuffer[%d]->pVirAddr[0]: 0x%x", i, pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[0]);
707
708 Exynos_CodecBufferEnQueue(pExynosComponent, OUTPUT_PORT_INDEX, pVideoDec->pMFCDecOutputBuffer[i]);
c6f4bc34
YK
709 }
710 pOutbufOps->Clear_Queue(hMFCHandle);
c6f4bc34
YK
711 }
712
713EXIT:
714 FunctionOut();
715
716 return ret;
717}
718
064c4768
SKR
719#ifdef USE_S3D_SUPPORT
720OMX_BOOL H264CodecCheckFramePacking(OMX_COMPONENTTYPE *pOMXComponent)
721{
722 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
723 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
724 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
725 ExynosVideoFramePacking framePacking;
726 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
727 OMX_BOOL ret = OMX_FALSE;
728
729 /* Get Frame packing information*/
730 if (pDecOps->Get_FramePackingInfo(pH264Dec->hMFCH264Handle.hMFCHandle, &framePacking) != VIDEO_ERROR_NONE) {
731 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Get Frame Packing Information");
732 ret = OMX_FALSE;
733 goto EXIT;
734 }
735
736 if (framePacking.available) {
737 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "arrangement ID: 0x%08x", framePacking.arrangement_id);
738 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "arrangement_type: %d", framePacking.arrangement_type);
739 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "content_interpretation_type: %d", framePacking.content_interpretation_type);
740 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "current_frame_is_frame0_flag: %d", framePacking.current_frame_is_frame0_flag);
741 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "spatial_flipping_flag: %d", framePacking.spatial_flipping_flag);
742 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "fr0X:%d fr0Y:%d fr0X:%d fr0Y:%d", framePacking.frame0_grid_pos_x,
743 framePacking.frame0_grid_pos_y, framePacking.frame1_grid_pos_x, framePacking.frame1_grid_pos_y);
744
745 pH264Dec->hMFCH264Handle.S3DFPArgmtType = (EXYNOS_OMX_FPARGMT_TYPE) framePacking.arrangement_type;
746 /** Send Port Settings changed call back - output color format change */
31e78666 747 (*(pExynosComponent->pCallbacks->EventHandler))
064c4768
SKR
748 (pOMXComponent,
749 pExynosComponent->callbackData,
31e78666
TK
750 OMX_EventS3DInformation, /* The command was completed */
751 OMX_TRUE, /* S3D is enabled */
752 (OMX_S32)pH264Dec->hMFCH264Handle.S3DFPArgmtType, /* S3D FPArgmtType */
064c4768
SKR
753 NULL);
754
755 Exynos_OSAL_SleepMillisec(0);
433e798a
EC
756 } else {
757 pH264Dec->hMFCH264Handle.S3DFPArgmtType = OMX_SEC_FPARGMT_NONE;
064c4768
SKR
758 }
759
433e798a
EC
760 ret = OMX_TRUE;
761
064c4768
SKR
762EXIT:
763 return ret;
764}
765#endif
766
405399e5
TK
767OMX_ERRORTYPE H264CodecCheckResolutionChange(OMX_COMPONENTTYPE *pOMXComponent)
768{
769 OMX_ERRORTYPE ret = OMX_ErrorNone;
770 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
771 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
772 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
773 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
774 EXYNOS_OMX_BASEPORT *pInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
775 EXYNOS_OMX_BASEPORT *pOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
776 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
777 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
778
779 FunctionIn();
780 /* get geometry for output */
781 Exynos_OSAL_Memset(&pH264Dec->hMFCH264Handle.codecOutbufConf, 0, sizeof(ExynosVideoGeometry));
782 if (pOutbufOps->Get_Geometry(hMFCHandle, &pH264Dec->hMFCH264Handle.codecOutbufConf) != VIDEO_ERROR_NONE) {
783 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to get geometry for parsed header info");
784 ret = OMX_ErrorInsufficientResources;
785 goto EXIT;
786 }
787
788 /* get dpb count */
789 pH264Dec->hMFCH264Handle.maxDPBNum = pDecOps->Get_ActualBufferCount(hMFCHandle);
790 if (pVideoDec->bThumbnailMode == OMX_FALSE)
791 pH264Dec->hMFCH264Handle.maxDPBNum += EXTRA_DPB_NUM;
792 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "H264CodecSetup nOutbufs: %d", pH264Dec->hMFCH264Handle.maxDPBNum);
793
794 pH264Dec->hMFCH264Handle.bConfiguredMFCSrc = OMX_TRUE;
795
796 pOutputPort->cropRectangle.nTop = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nTop;
797 pOutputPort->cropRectangle.nLeft = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nLeft;
798 pOutputPort->cropRectangle.nWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nWidth;
799 pOutputPort->cropRectangle.nHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nHeight;
800
801 if (pVideoDec->bReconfigDPB == OMX_TRUE)
802 pVideoDec->nSavedDPBCnt = pOutputPort->portDefinition.nBufferCountActual;
803
804 if (pOutputPort->bufferProcessType & BUFFER_COPY) {
805 if ((pVideoDec->bReconfigDPB) ||
806 (pInputPort->portDefinition.format.video.nFrameWidth != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth) ||
807 (pInputPort->portDefinition.format.video.nFrameHeight != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight)) {
a947bcc1
TK
808 pOutputPort->exceptionFlag = NEED_PORT_DISABLE;
809
405399e5
TK
810 pInputPort->portDefinition.format.video.nFrameWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth;
811 pInputPort->portDefinition.format.video.nFrameHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight;
812 pInputPort->portDefinition.format.video.nStride = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth + 15) & (~15));
813 pInputPort->portDefinition.format.video.nSliceHeight = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight + 15) & (~15));
814
815 Exynos_UpdateFrameSize(pOMXComponent);
405399e5
TK
816
817 /** Send Port Settings changed call back **/
818 (*(pExynosComponent->pCallbacks->EventHandler))
819 (pOMXComponent,
820 pExynosComponent->callbackData,
821 OMX_EventPortSettingsChanged, /* The command was completed */
822 OMX_DirOutput, /* This is the port index */
823 0,
824 NULL);
825 }
826 } else if (pOutputPort->bufferProcessType & BUFFER_SHARE) {
827 if ((pVideoDec->bReconfigDPB) ||
828 (pInputPort->portDefinition.format.video.nFrameWidth != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth) ||
829 (pInputPort->portDefinition.format.video.nFrameHeight != pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight) ||
830 (pOutputPort->portDefinition.nBufferCountActual != pH264Dec->hMFCH264Handle.maxDPBNum)) {
a947bcc1
TK
831 pOutputPort->exceptionFlag = NEED_PORT_DISABLE;
832
405399e5
TK
833 pInputPort->portDefinition.format.video.nFrameWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth;
834 pInputPort->portDefinition.format.video.nFrameHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight;
835 pInputPort->portDefinition.format.video.nStride = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth + 15) & (~15));
836 pInputPort->portDefinition.format.video.nSliceHeight = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight + 15) & (~15));
837
838 pOutputPort->portDefinition.nBufferCountActual = pH264Dec->hMFCH264Handle.maxDPBNum - 2;
839 pOutputPort->portDefinition.nBufferCountMin = pH264Dec->hMFCH264Handle.maxDPBNum - 2;
840
841 Exynos_UpdateFrameSize(pOMXComponent);
405399e5
TK
842
843 /** Send Port Settings changed call back **/
844 (*(pExynosComponent->pCallbacks->EventHandler))
845 (pOMXComponent,
846 pExynosComponent->callbackData,
847 OMX_EventPortSettingsChanged, /* The command was completed */
848 OMX_DirOutput, /* This is the port index */
849 0,
850 NULL);
851 }
852 }
853 if ((pVideoDec->bReconfigDPB == OMX_TRUE) ||
854 (pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth != pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nWidth) ||
855 (pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight != pH264Dec->hMFCH264Handle.codecOutbufConf.cropRect.nHeight)) {
856 /* Check Crop */
857 pInputPort->portDefinition.format.video.nFrameWidth = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth;
858 pInputPort->portDefinition.format.video.nFrameHeight = pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight;
859 pInputPort->portDefinition.format.video.nStride = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameWidth + 15) & (~15));
860 pInputPort->portDefinition.format.video.nSliceHeight = ((pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight + 15) & (~15));
861 Exynos_UpdateFrameSize(pOMXComponent);
862
863 /** Send crop info call back **/
864 (*(pExynosComponent->pCallbacks->EventHandler))
865 (pOMXComponent,
866 pExynosComponent->callbackData,
867 OMX_EventPortSettingsChanged, /* The command was completed */
868 OMX_DirOutput, /* This is the port index */
869 OMX_IndexConfigCommonOutputCrop,
870 NULL);
871 }
872
873 ret = OMX_ErrorNone;
874
875EXIT:
876 FunctionOut();
877
878 return ret;
879}
880
c6f4bc34
YK
881OMX_ERRORTYPE H264CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData)
882{
883 OMX_ERRORTYPE ret = OMX_ErrorNone;
884 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
885 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
886 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
887 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
888 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
889 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
e4e150b8 890 OMX_U32 oneFrameSize = pSrcInputData->dataLen;
c6f4bc34
YK
891
892 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
893 ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
894 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
895 ExynosVideoGeometry bufferConf;
896 OMX_U32 inputBufferNumber = 0;
897 int i;
898
899 FunctionIn();
900
901 if ((oneFrameSize <= 0) && (pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS)) {
433e798a
EC
902 BYPASS_BUFFER_INFO *pBufferInfo = (BYPASS_BUFFER_INFO *)Exynos_OSAL_Malloc(sizeof(BYPASS_BUFFER_INFO));
903 if (pBufferInfo == NULL) {
904 ret = OMX_ErrorInsufficientResources;
c6f4bc34
YK
905 goto EXIT;
906 }
907
433e798a
EC
908 pBufferInfo->nFlags = pSrcInputData->nFlags;
909 pBufferInfo->timeStamp = pSrcInputData->timeStamp;
910 ret = Exynos_OSAL_Queue(&pH264Dec->bypassBufferInfoQ, (void *)pBufferInfo);
911 Exynos_OSAL_SignalSet(pH264Dec->hDestinationStartEvent);
c6f4bc34
YK
912
913 ret = OMX_ErrorNone;
914 goto EXIT;
915 }
916
917 if (pVideoDec->bThumbnailMode == OMX_TRUE)
918 pDecOps->Set_DisplayDelay(hMFCHandle, 0);
919
c70316c7
JY
920 if ((pDecOps->Enable_DTSMode != NULL) &&
921 (pVideoDec->bDTSMode == OMX_TRUE))
922 pDecOps->Enable_DTSMode(hMFCHandle);
923
c6f4bc34
YK
924 /* input buffer info */
925 Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf));
926 bufferConf.eCompressionFormat = VIDEO_CODING_AVC;
927 pInbufOps->Set_Shareable(hMFCHandle);
24ec2c82 928 if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) {
c6f4bc34
YK
929 bufferConf.nSizeImage = pExynosInputPort->portDefinition.format.video.nFrameWidth
930 * pExynosInputPort->portDefinition.format.video.nFrameHeight * 3 / 2;
24ec2c82 931 } else if (pExynosInputPort->bufferProcessType & BUFFER_COPY) {
c6f4bc34 932 bufferConf.nSizeImage = DEFAULT_MFC_INPUT_BUFFER_SIZE;
c6f4bc34 933 }
433e798a
EC
934 bufferConf.nPlaneCnt = pExynosInputPort->nPlaneCnt;
935 inputBufferNumber = MAX_INPUTBUFFER_NUM_DYNAMIC;
c6f4bc34
YK
936
937 /* should be done before prepare input buffer */
938 if (pInbufOps->Enable_Cacheable(hMFCHandle) != VIDEO_ERROR_NONE) {
939 ret = OMX_ErrorInsufficientResources;
940 goto EXIT;
941 }
942
943 /* set input buffer geometry */
944 if (pInbufOps->Set_Geometry(hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) {
945 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for input buffer");
946 ret = OMX_ErrorInsufficientResources;
947 goto EXIT;
948 }
949
950 /* setup input buffer */
951 if (pInbufOps->Setup(hMFCHandle, inputBufferNumber) != VIDEO_ERROR_NONE) {
952 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup input buffer");
953 ret = OMX_ErrorInsufficientResources;
954 goto EXIT;
955 }
956
c6f4bc34
YK
957 /* set output geometry */
958 Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf));
433e798a
EC
959
960#ifdef USE_DUALDPB_MODE
961 switch (pExynosOutputPort->portDefinition.format.video.eColorFormat) {
962 case OMX_COLOR_FormatYUV420SemiPlanar:
963 bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12;
964 break;
965 case OMX_COLOR_FormatYUV420Planar:
966 bufferConf.eColorFormat = VIDEO_COLORFORMAT_I420;
967 break;
968 case OMX_SEC_COLOR_FormatYVU420Planar:
969 bufferConf.eColorFormat = VIDEO_COLORFORMAT_YV12;
970 break;
971 case OMX_SEC_COLOR_FormatNV21Linear:
972 bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV21;
973 break;
974 case OMX_SEC_COLOR_FormatNV12Tiled:
975 bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED;
976 break;
977 default:
978 bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED;
979 break;
980 }
981
982 if (bufferConf.eColorFormat != VIDEO_COLORFORMAT_NV12_TILED) {
983 if ((pDecOps->Enable_DualDPBMode != NULL) &&
984 (pDecOps->Enable_DualDPBMode(hMFCHandle) == VIDEO_ERROR_NONE)) {
985 pVideoDec->bDualDPBMode = OMX_TRUE;
986 pExynosOutputPort->nPlaneCnt = Exynos_OSAL_GetPlaneCount(pExynosOutputPort->portDefinition.format.video.eColorFormat);
987 } else {
988 bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED;
989 pExynosOutputPort->nPlaneCnt = MFC_DEFAULT_OUTPUT_BUFFER_PLANE;
990 }
991 }
992 pH264Dec->hMFCH264Handle.MFCOutputColorType = bufferConf.eColorFormat;
993#else
c6f4bc34 994 pH264Dec->hMFCH264Handle.MFCOutputColorType = bufferConf.eColorFormat = VIDEO_COLORFORMAT_NV12_TILED;
433e798a
EC
995#endif
996 bufferConf.nPlaneCnt = pExynosOutputPort->nPlaneCnt;
c6f4bc34
YK
997 if (pOutbufOps->Set_Geometry(hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) {
998 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for output buffer");
999 ret = OMX_ErrorInsufficientResources;
1000 goto EXIT;
1001 }
1002
1003 /* input buffer enqueue for header parsing */
1004 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "oneFrameSize: %d", oneFrameSize);
433e798a
EC
1005 OMX_U32 nAllocLen[MAX_BUFFER_PLANE] = {pSrcInputData->bufferHeader->nAllocLen, 0, 0};
1006 if (pInbufOps->ExtensionEnqueue(hMFCHandle,
1007 (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.dataBuffer,
1008 (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.fd,
1009 (unsigned int *)nAllocLen, (unsigned int *)&oneFrameSize,
1010 pExynosInputPort->nPlaneCnt, pSrcInputData->bufferHeader) != VIDEO_ERROR_NONE) {
c6f4bc34
YK
1011 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to enqueue input buffer for header parsing");
1012// ret = OMX_ErrorInsufficientResources;
1013 ret = (OMX_ERRORTYPE)OMX_ErrorCodecInit;
1014 goto EXIT;
1015 }
1016
1017 /* start header parsing */
1018 if (pInbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) {
1019 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run input buffer for header parsing");
1020 ret = OMX_ErrorCodecInit;
1021 goto EXIT;
1022 }
1023
433e798a
EC
1024 ret = H264CodecCheckResolutionChange(pOMXComponent);
1025 if (ret != OMX_ErrorNone) {
1026 H264CodecStop(pOMXComponent, INPUT_PORT_INDEX);
1027 pInbufOps->Cleanup_Buffer(hMFCHandle);
1028 goto EXIT;
1029 }
c6f4bc34
YK
1030
1031 Exynos_OSAL_SleepMillisec(0);
1032 ret = OMX_ErrorInputDataDecodeYet;
1033 H264CodecStop(pOMXComponent, INPUT_PORT_INDEX);
1034
1035EXIT:
1036 FunctionOut();
1037
1038 return ret;
1039}
1040
1041OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent)
1042{
1043 OMX_ERRORTYPE ret = OMX_ErrorNone;
1044 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1045 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1046 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1047 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
1048 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1049 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1050
1051 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
1052 ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
1053 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
1054
1055 int i, nOutbufs;
1056
433e798a
EC
1057 OMX_U32 nAllocLen[MAX_BUFFER_PLANE] = {0, 0, 0};
1058 OMX_U32 dataLen[MAX_BUFFER_PLANE] = {0, 0, 0};
e02ebaac 1059
c6f4bc34
YK
1060 FunctionIn();
1061
433e798a
EC
1062 for (i = 0; i < pExynosOutputPort->nPlaneCnt; i++)
1063 nAllocLen[i] = pH264Dec->hMFCH264Handle.codecOutbufConf.nAlignPlaneSize[i];
e02ebaac
TK
1064
1065 pOutbufOps->Set_Shareable(hMFCHandle);
1066
24ec2c82 1067 if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) {
c6f4bc34
YK
1068 /* should be done before prepare output buffer */
1069 if (pOutbufOps->Enable_Cacheable(hMFCHandle) != VIDEO_ERROR_NONE) {
1070 ret = OMX_ErrorInsufficientResources;
1071 goto EXIT;
1072 }
c6f4bc34 1073
a38b0597
TK
1074 /* get dpb count */
1075 nOutbufs = pH264Dec->hMFCH264Handle.maxDPBNum;
1076 if (pOutbufOps->Setup(hMFCHandle, nOutbufs) != VIDEO_ERROR_NONE) {
1077 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup output buffer");
1078 ret = OMX_ErrorInsufficientResources;
1079 goto EXIT;
1080 }
1081
0641ae29
TK
1082 ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, nOutbufs, nAllocLen);
1083 if (ret != OMX_ErrorNone)
1084 goto EXIT;
c6f4bc34 1085
0641ae29
TK
1086 ret = H264CodecRegistCodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, nOutbufs);
1087 if (ret != OMX_ErrorNone)
1088 goto EXIT;
c6f4bc34 1089
0641ae29
TK
1090 /* Enqueue output buffer */
1091 for (i = 0; i < nOutbufs; i++) {
c6f4bc34 1092 pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr,
433e798a 1093 (unsigned int *)dataLen, pExynosOutputPort->nPlaneCnt, NULL);
c6f4bc34 1094 }
98034ac0
SK
1095
1096 if (pOutbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) {
1097 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer");
1098 ret = OMX_ErrorInsufficientResources;
1099 goto EXIT;
1100 }
24ec2c82 1101 } else if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) {
433e798a 1102 ExynosVideoPlane planes[MAX_BUFFER_PLANE] = {0, 0, 0};
e02ebaac
TK
1103 int plane;
1104
a38b0597
TK
1105 /* get dpb count */
1106 nOutbufs = pExynosOutputPort->portDefinition.nBufferCountActual;
1107 if (pOutbufOps->Setup(hMFCHandle, nOutbufs) != VIDEO_ERROR_NONE) {
1108 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup output buffer");
1109 ret = OMX_ErrorInsufficientResources;
1110 goto EXIT;
1111 }
1112
c6f4bc34
YK
1113 /* Register output buffer */
1114 /*************/
1115 /* TBD */
1116 /*************/
1117#ifdef USE_ANB
1118 if (pExynosOutputPort->bIsANBEnabled == OMX_TRUE) {
1119 for (i = 0; i < pExynosOutputPort->assignedBufferNum; i++) {
433e798a 1120 for (plane = 0; plane < pExynosOutputPort->nPlaneCnt; plane++) {
c6f4bc34
YK
1121 planes[plane].fd = pExynosOutputPort->extendBufferHeader[i].buf_fd[plane];
1122 planes[plane].addr = pExynosOutputPort->extendBufferHeader[i].pYUVBuf[plane];
1123 planes[plane].allocSize = nAllocLen[plane];
1124 }
1125
433e798a 1126 if (pOutbufOps->Register(hMFCHandle, planes, pExynosOutputPort->nPlaneCnt) != VIDEO_ERROR_NONE) {
c6f4bc34
YK
1127 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer");
1128 ret = OMX_ErrorInsufficientResources;
1129 goto EXIT;
1130 }
1131 pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pExynosOutputPort->extendBufferHeader[i].pYUVBuf,
433e798a 1132 (unsigned int *)dataLen, pExynosOutputPort->nPlaneCnt, NULL);
c6f4bc34 1133 }
98034ac0
SK
1134
1135 if (pOutbufOps->Apply_RegisteredBuffer(hMFCHandle) != VIDEO_ERROR_NONE) {
1136 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Apply output buffer");
1137 ret = OMX_ErrorHardware;
1138 goto EXIT;
1139 }
c6f4bc34
YK
1140 } else {
1141 ret = OMX_ErrorNotImplemented;
1142 goto EXIT;
1143 }
1144#else
1145 ret = OMX_ErrorNotImplemented;
1146 goto EXIT;
1147#endif
1148 }
1149
c6f4bc34
YK
1150 pH264Dec->hMFCH264Handle.bConfiguredMFCDst = OMX_TRUE;
1151
1152 ret = OMX_ErrorNone;
1153
1154EXIT:
1155 FunctionOut();
1156
1157 return ret;
1158}
1159
1160OMX_ERRORTYPE Exynos_H264Dec_GetParameter(
1161 OMX_IN OMX_HANDLETYPE hComponent,
1162 OMX_IN OMX_INDEXTYPE nParamIndex,
1163 OMX_INOUT OMX_PTR pComponentParameterStructure)
1164{
1165 OMX_ERRORTYPE ret = OMX_ErrorNone;
1166 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1167 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1168
1169 FunctionIn();
1170
1171 if (hComponent == NULL || pComponentParameterStructure == NULL) {
1172 ret = OMX_ErrorBadParameter;
1173 goto EXIT;
1174 }
1175 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1176 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1177 if (ret != OMX_ErrorNone) {
1178 goto EXIT;
1179 }
1180 if (pOMXComponent->pComponentPrivate == NULL) {
1181 ret = OMX_ErrorBadParameter;
1182 goto EXIT;
1183 }
1184
1185 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1186 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1187 ret = OMX_ErrorInvalidState;
1188 goto EXIT;
1189 }
1190
1191 switch (nParamIndex) {
1192 case OMX_IndexParamVideoAvc:
1193 {
1194 OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = (OMX_VIDEO_PARAM_AVCTYPE *)pComponentParameterStructure;
1195 OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = NULL;
1196 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1197
1198 ret = Exynos_OMX_Check_SizeVersion(pDstAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
1199 if (ret != OMX_ErrorNone) {
1200 goto EXIT;
1201 }
1202
1203 if (pDstAVCComponent->nPortIndex >= ALL_PORT_NUM) {
1204 ret = OMX_ErrorBadPortIndex;
1205 goto EXIT;
1206 }
1207
1208 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1209 pSrcAVCComponent = &pH264Dec->AVCComponent[pDstAVCComponent->nPortIndex];
1210
1211 Exynos_OSAL_Memcpy(pDstAVCComponent, pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
1212 }
1213 break;
1214 case OMX_IndexParamStandardComponentRole:
1215 {
1216 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure;
1217 ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1218 if (ret != OMX_ErrorNone) {
1219 goto EXIT;
1220 }
1221
1222 Exynos_OSAL_Strcpy((char *)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H264_DEC_ROLE);
1223 }
1224 break;
1225 case OMX_IndexParamVideoProfileLevelQuerySupported:
1226 {
1227 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)pComponentParameterStructure;
1228 EXYNOS_OMX_VIDEO_PROFILELEVEL *pProfileLevel = NULL;
1229 OMX_U32 maxProfileLevelNum = 0;
1230
1231 ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
1232 if (ret != OMX_ErrorNone) {
1233 goto EXIT;
1234 }
1235
1236 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) {
1237 ret = OMX_ErrorBadPortIndex;
1238 goto EXIT;
1239 }
1240
1241 pProfileLevel = supportedAVCProfileLevels;
1242 maxProfileLevelNum = sizeof(supportedAVCProfileLevels) / sizeof(EXYNOS_OMX_VIDEO_PROFILELEVEL);
1243
1244 if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) {
1245 ret = OMX_ErrorNoMore;
1246 goto EXIT;
1247 }
1248
1249 pProfileLevel += pDstProfileLevel->nProfileIndex;
1250 pDstProfileLevel->eProfile = pProfileLevel->profile;
1251 pDstProfileLevel->eLevel = pProfileLevel->level;
1252 }
1253 break;
1254 case OMX_IndexParamVideoProfileLevelCurrent:
1255 {
1256 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)pComponentParameterStructure;
1257 OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = NULL;
1258 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1259
1260 ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
1261 if (ret != OMX_ErrorNone) {
1262 goto EXIT;
1263 }
1264
1265 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) {
1266 ret = OMX_ErrorBadPortIndex;
1267 goto EXIT;
1268 }
1269
1270 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1271 pSrcAVCComponent = &pH264Dec->AVCComponent[pDstProfileLevel->nPortIndex];
1272
1273 pDstProfileLevel->eProfile = pSrcAVCComponent->eProfile;
1274 pDstProfileLevel->eLevel = pSrcAVCComponent->eLevel;
1275 }
1276 break;
1277 case OMX_IndexParamVideoErrorCorrection:
1278 {
1279 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure;
1280 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL;
1281 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1282
1283 ret = Exynos_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
1284 if (ret != OMX_ErrorNone) {
1285 goto EXIT;
1286 }
1287
1288 if (pDstErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) {
1289 ret = OMX_ErrorBadPortIndex;
1290 goto EXIT;
1291 }
1292
1293 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1294 pSrcErrorCorrectionType = &pH264Dec->errorCorrectionType[INPUT_PORT_INDEX];
1295
1296 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC;
1297 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync;
1298 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing;
1299 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning;
1300 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC;
1301 }
1302 break;
1303 default:
1304 ret = Exynos_OMX_VideoDecodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure);
1305 break;
1306 }
1307EXIT:
1308 FunctionOut();
1309
1310 return ret;
1311}
1312
1313OMX_ERRORTYPE Exynos_H264Dec_SetParameter(
1314 OMX_IN OMX_HANDLETYPE hComponent,
1315 OMX_IN OMX_INDEXTYPE nIndex,
1316 OMX_IN OMX_PTR pComponentParameterStructure)
1317{
1318 OMX_ERRORTYPE ret = OMX_ErrorNone;
1319 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1320 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1321
1322 FunctionIn();
1323
1324 if (hComponent == NULL || pComponentParameterStructure == NULL) {
1325 ret = OMX_ErrorBadParameter;
1326 goto EXIT;
1327 }
1328 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1329 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1330 if (ret != OMX_ErrorNone) {
1331 goto EXIT;
1332 }
1333 if (pOMXComponent->pComponentPrivate == NULL) {
1334 ret = OMX_ErrorBadParameter;
1335 goto EXIT;
1336 }
1337
1338 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1339 if (pExynosComponent->currentState == OMX_StateInvalid ) {
1340 ret = OMX_ErrorInvalidState;
1341 goto EXIT;
1342 }
1343
1344 switch (nIndex) {
1345 case OMX_IndexParamVideoAvc:
1346 {
1347 OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = NULL;
1348 OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = (OMX_VIDEO_PARAM_AVCTYPE *)pComponentParameterStructure;
1349 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1350
1351 ret = Exynos_OMX_Check_SizeVersion(pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
1352 if (ret != OMX_ErrorNone) {
1353 goto EXIT;
1354 }
1355
1356 if (pSrcAVCComponent->nPortIndex >= ALL_PORT_NUM) {
1357 ret = OMX_ErrorBadPortIndex;
1358 goto EXIT;
1359 }
1360
1361 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1362 pDstAVCComponent = &pH264Dec->AVCComponent[pSrcAVCComponent->nPortIndex];
1363
1364 Exynos_OSAL_Memcpy(pDstAVCComponent, pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
1365 }
1366 break;
1367 case OMX_IndexParamStandardComponentRole:
1368 {
1369 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure;
1370
1371 ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1372 if (ret != OMX_ErrorNone) {
1373 goto EXIT;
1374 }
1375
1376 if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) {
1377 ret = OMX_ErrorIncorrectStateOperation;
1378 goto EXIT;
1379 }
1380
1381 if (!Exynos_OSAL_Strcmp((char*)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H264_DEC_ROLE)) {
1382 pExynosComponent->pExynosPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
1383 } else {
1384 ret = OMX_ErrorBadParameter;
1385 goto EXIT;
1386 }
1387 }
1388 break;
1389 case OMX_IndexParamVideoProfileLevelCurrent:
1390 {
1391 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure;
1392 OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = NULL;
1393 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1394
1395 ret = Exynos_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE));
1396 if (ret != OMX_ErrorNone)
1397 goto EXIT;
1398
1399 if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) {
1400 ret = OMX_ErrorBadPortIndex;
1401 goto EXIT;
1402 }
1403
1404 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1405
1406 pDstAVCComponent = &pH264Dec->AVCComponent[pSrcProfileLevel->nPortIndex];
1407 pDstAVCComponent->eProfile = pSrcProfileLevel->eProfile;
1408 pDstAVCComponent->eLevel = pSrcProfileLevel->eLevel;
1409 }
1410 break;
1411 case OMX_IndexParamVideoErrorCorrection:
1412 {
1413 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure;
1414 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL;
1415 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1416
1417 ret = Exynos_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
1418 if (ret != OMX_ErrorNone) {
1419 goto EXIT;
1420 }
1421
1422 if (pSrcErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) {
1423 ret = OMX_ErrorBadPortIndex;
1424 goto EXIT;
1425 }
1426
1427 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1428 pDstErrorCorrectionType = &pH264Dec->errorCorrectionType[INPUT_PORT_INDEX];
1429
1430 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC;
1431 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync;
1432 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing;
1433 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning;
1434 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC;
1435 }
1436 break;
1437 default:
1438 ret = Exynos_OMX_VideoDecodeSetParameter(hComponent, nIndex, pComponentParameterStructure);
1439 break;
1440 }
1441EXIT:
1442 FunctionOut();
1443
1444 return ret;
1445}
1446
1447OMX_ERRORTYPE Exynos_H264Dec_GetConfig(
1448 OMX_HANDLETYPE hComponent,
1449 OMX_INDEXTYPE nIndex,
1450 OMX_PTR pComponentConfigStructure)
1451{
1452 OMX_ERRORTYPE ret = OMX_ErrorNone;
1453 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1454 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1455
1456 FunctionIn();
1457
1458 if (hComponent == NULL) {
1459 ret = OMX_ErrorBadParameter;
1460 goto EXIT;
1461 }
1462 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1463 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1464 if (ret != OMX_ErrorNone) {
1465 goto EXIT;
1466 }
1467 if (pOMXComponent->pComponentPrivate == NULL) {
1468 ret = OMX_ErrorBadParameter;
1469 goto EXIT;
1470 }
1471 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1472 if (pComponentConfigStructure == NULL) {
1473 ret = OMX_ErrorBadParameter;
1474 goto EXIT;
1475 }
1476 if (pExynosComponent->currentState == OMX_StateInvalid) {
1477 ret = OMX_ErrorInvalidState;
1478 goto EXIT;
1479 }
1480
1481 switch (nIndex) {
1482 case OMX_IndexConfigCommonOutputCrop:
1483 {
1484 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1485 OMX_CONFIG_RECTTYPE *pSrcRectType = NULL;
1486 OMX_CONFIG_RECTTYPE *pDstRectType = NULL;
1487 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1488
1489 if (pH264Dec->hMFCH264Handle.bConfiguredMFCSrc == OMX_FALSE) {
1490 ret = OMX_ErrorNotReady;
1491 break;
1492 }
1493
1494 pDstRectType = (OMX_CONFIG_RECTTYPE *)pComponentConfigStructure;
1495
1496 if ((pDstRectType->nPortIndex != INPUT_PORT_INDEX) &&
1497 (pDstRectType->nPortIndex != OUTPUT_PORT_INDEX)) {
1498 ret = OMX_ErrorBadPortIndex;
1499 goto EXIT;
1500 }
1501
1502 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[pDstRectType->nPortIndex];
1503
1504 pSrcRectType = &(pExynosPort->cropRectangle);
1505
1506 pDstRectType->nTop = pSrcRectType->nTop;
1507 pDstRectType->nLeft = pSrcRectType->nLeft;
1508 pDstRectType->nHeight = pSrcRectType->nHeight;
1509 pDstRectType->nWidth = pSrcRectType->nWidth;
1510 }
1511 break;
064c4768
SKR
1512#ifdef USE_S3D_SUPPORT
1513 case OMX_IndexVendorS3DMode:
1514 {
1515 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
1516 OMX_U32 *pS3DMode = NULL;
1517 pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1518
1519 pS3DMode = (OMX_U32 *)pComponentConfigStructure;
1520 *pS3DMode = (OMX_U32) pH264Dec->hMFCH264Handle.S3DFPArgmtType;
1521 }
1522 break;
1523#endif
c6f4bc34
YK
1524 default:
1525 ret = Exynos_OMX_VideoDecodeGetConfig(hComponent, nIndex, pComponentConfigStructure);
1526 break;
1527 }
1528
1529EXIT:
1530 FunctionOut();
1531
1532 return ret;
1533}
1534
1535OMX_ERRORTYPE Exynos_H264Dec_SetConfig(
1536 OMX_HANDLETYPE hComponent,
1537 OMX_INDEXTYPE nIndex,
1538 OMX_PTR pComponentConfigStructure)
1539{
1540 OMX_ERRORTYPE ret = OMX_ErrorNone;
1541 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1542 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1543
1544 FunctionIn();
1545
1546 if (hComponent == NULL) {
1547 ret = OMX_ErrorBadParameter;
1548 goto EXIT;
1549 }
1550 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1551 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1552 if (ret != OMX_ErrorNone) {
1553 goto EXIT;
1554 }
1555 if (pOMXComponent->pComponentPrivate == NULL) {
1556 ret = OMX_ErrorBadParameter;
1557 goto EXIT;
1558 }
1559 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1560 if (pComponentConfigStructure == NULL) {
1561 ret = OMX_ErrorBadParameter;
1562 goto EXIT;
1563 }
1564 if (pExynosComponent->currentState == OMX_StateInvalid) {
1565 ret = OMX_ErrorInvalidState;
1566 goto EXIT;
1567 }
1568
1569 switch (nIndex) {
1570 default:
1571 ret = Exynos_OMX_VideoDecodeSetConfig(hComponent, nIndex, pComponentConfigStructure);
1572 break;
1573 }
1574
1575EXIT:
1576 FunctionOut();
1577
1578 return ret;
1579}
1580
1581OMX_ERRORTYPE Exynos_H264Dec_GetExtensionIndex(
1582 OMX_IN OMX_HANDLETYPE hComponent,
1583 OMX_IN OMX_STRING cParameterName,
1584 OMX_OUT OMX_INDEXTYPE *pIndexType)
1585{
1586 OMX_ERRORTYPE ret = OMX_ErrorNone;
1587 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1588 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1589
1590 FunctionIn();
1591
1592 if (hComponent == NULL) {
1593 ret = OMX_ErrorBadParameter;
1594 goto EXIT;
1595 }
1596 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1597 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1598 if (ret != OMX_ErrorNone) {
1599 goto EXIT;
1600 }
1601 if (pOMXComponent->pComponentPrivate == NULL) {
1602 ret = OMX_ErrorBadParameter;
1603 goto EXIT;
1604 }
1605 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1606 if ((cParameterName == NULL) || (pIndexType == NULL)) {
1607 ret = OMX_ErrorBadParameter;
1608 goto EXIT;
1609 }
1610 if (pExynosComponent->currentState == OMX_StateInvalid) {
1611 ret = OMX_ErrorInvalidState;
1612 goto EXIT;
1613 }
1614
1615 if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_THUMBNAIL) == 0) {
1616 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1617 *pIndexType = OMX_IndexVendorThumbnailMode;
1618 ret = OMX_ErrorNone;
064c4768
SKR
1619 }
1620#ifdef USE_S3D_SUPPORT
1621 else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_GET_S3D) == 0) {
1622 *pIndexType = OMX_IndexVendorS3DMode;
1623 ret = OMX_ErrorNone;
1624 }
1625#endif
1626 else {
c6f4bc34
YK
1627 ret = Exynos_OMX_VideoDecodeGetExtensionIndex(hComponent, cParameterName, pIndexType);
1628 }
1629
1630EXIT:
1631 FunctionOut();
1632
1633 return ret;
1634}
1635
1636OMX_ERRORTYPE Exynos_H264Dec_ComponentRoleEnum(
1637 OMX_HANDLETYPE hComponent,
1638 OMX_U8 *cRole,
1639 OMX_U32 nIndex)
1640{
1641 OMX_ERRORTYPE ret = OMX_ErrorNone;
1642 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1643 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1644
1645 FunctionIn();
1646
1647 if ((hComponent == NULL) || (cRole == NULL)) {
1648 ret = OMX_ErrorBadParameter;
1649 goto EXIT;
1650 }
1651 if (nIndex == (MAX_COMPONENT_ROLE_NUM-1)) {
1652 Exynos_OSAL_Strcpy((char *)cRole, EXYNOS_OMX_COMPONENT_H264_DEC_ROLE);
1653 ret = OMX_ErrorNone;
1654 } else {
1655 ret = OMX_ErrorNoMore;
1656 }
1657
1658EXIT:
1659 FunctionOut();
1660
1661 return ret;
1662}
1663
1664/* MFC Init */
1665OMX_ERRORTYPE Exynos_H264Dec_Init(OMX_COMPONENTTYPE *pOMXComponent)
1666{
1667 OMX_ERRORTYPE ret = OMX_ErrorNone;
1668 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1669 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1670 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1671 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1672 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
1673 OMX_PTR hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
1674
1675 ExynosVideoDecOps *pDecOps = NULL;
1676 ExynosVideoDecBufferOps *pInbufOps = NULL;
1677 ExynosVideoDecBufferOps *pOutbufOps = NULL;
1678
1679 CSC_METHOD csc_method = CSC_METHOD_SW;
1680 int i, plane;
1681
1682 FunctionIn();
1683
1684 pH264Dec->hMFCH264Handle.bConfiguredMFCSrc = OMX_FALSE;
1685 pH264Dec->hMFCH264Handle.bConfiguredMFCDst = OMX_FALSE;
1686 pExynosComponent->bUseFlagEOF = OMX_TRUE;
1687 pExynosComponent->bSaveFlagEOS = OMX_FALSE;
e100a12d 1688 pExynosComponent->bBehaviorEOS = OMX_FALSE;
c6f4bc34
YK
1689
1690 /* H.264 Codec Open */
1691 ret = H264CodecOpen(pH264Dec);
1692 if (ret != OMX_ErrorNone) {
1693 goto EXIT;
1694 }
1695
1696 pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
1697 pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
1698 pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
1699
433e798a 1700 pExynosInputPort->nPlaneCnt = MFC_DEFAULT_INPUT_BUFFER_PLANE;
24ec2c82 1701 if (pExynosInputPort->bufferProcessType & BUFFER_COPY) {
433e798a 1702 OMX_U32 nPlaneSize[MAX_BUFFER_PLANE] = {DEFAULT_MFC_INPUT_BUFFER_SIZE, 0, 0};
c6f4bc34
YK
1703 Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID);
1704 Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS);
1705
0641ae29
TK
1706 ret = Exynos_Allocate_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX, nPlaneSize);
1707 if (ret != OMX_ErrorNone)
1708 goto EXIT;
c6f4bc34 1709
0641ae29 1710 for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++)
c6f4bc34 1711 Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]);
24ec2c82 1712 } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) {
c6f4bc34
YK
1713 /*************/
1714 /* TBD */
1715 /*************/
1716 /* Does not require any actions. */
1717 }
1718
433e798a 1719 pExynosOutputPort->nPlaneCnt = MFC_DEFAULT_OUTPUT_BUFFER_PLANE;
24ec2c82 1720 if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) {
c6f4bc34
YK
1721 Exynos_OSAL_SemaphoreCreate(&pExynosOutputPort->codecSemID);
1722 Exynos_OSAL_QueueCreate(&pExynosOutputPort->codecBufferQ, MAX_QUEUE_ELEMENTS);
24ec2c82 1723 } else if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) {
c6f4bc34
YK
1724 /*************/
1725 /* TBD */
1726 /*************/
1727 /* Does not require any actions. */
1728 }
1729
1730 pH264Dec->bSourceStart = OMX_FALSE;
1731 Exynos_OSAL_SignalCreate(&pH264Dec->hSourceStartEvent);
1732 pH264Dec->bDestinationStart = OMX_FALSE;
1733 Exynos_OSAL_SignalCreate(&pH264Dec->hDestinationStartEvent);
1734
1735 Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
1736 Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
1737 pH264Dec->hMFCH264Handle.indexTimestamp = 0;
1738 pH264Dec->hMFCH264Handle.outputIndexTimestamp = 0;
1739
1740 pExynosComponent->getAllDelayBuffer = OMX_FALSE;
1741
433e798a
EC
1742 Exynos_OSAL_QueueCreate(&pH264Dec->bypassBufferInfoQ, QUEUE_ELEMENTS);
1743
a80c3bc5
TK
1744#ifdef USE_CSC_HW
1745 csc_method = CSC_METHOD_HW;
c6f4bc34
YK
1746#endif
1747 if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
1748 pVideoDec->csc_handle = csc_init(CSC_METHOD_HW);
1749 csc_set_hw_property(pVideoDec->csc_handle, CSC_HW_PROPERTY_FIXED_NODE, 2);
1750 csc_set_hw_property(pVideoDec->csc_handle, CSC_HW_PROPERTY_MODE_DRM, pVideoDec->bDRMPlayerMode);
1751 } else {
1752 pVideoDec->csc_handle = csc_init(csc_method);
1753 }
1754
1755 if (pVideoDec->csc_handle == NULL) {
1756 ret = OMX_ErrorInsufficientResources;
1757 goto EXIT;
1758 }
1759 pVideoDec->csc_set_format = OMX_FALSE;
1760
1761EXIT:
1762 FunctionOut();
1763
1764 return ret;
1765}
1766
1767/* MFC Terminate */
1768OMX_ERRORTYPE Exynos_H264Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent)
1769{
1770 OMX_ERRORTYPE ret = OMX_ErrorNone;
1771 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1772 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1773 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1774 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1775 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1776 OMX_PTR hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
1777
1778 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
1779 ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
1780 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
1781
1782 int i, plane;
1783
1784 FunctionIn();
1785
1786 if (pVideoDec->csc_handle != NULL) {
1787 csc_deinit(pVideoDec->csc_handle);
1788 pVideoDec->csc_handle = NULL;
1789 }
1790
433e798a
EC
1791 Exynos_OSAL_QueueTerminate(&pH264Dec->bypassBufferInfoQ);
1792
c6f4bc34
YK
1793 Exynos_OSAL_SignalTerminate(pH264Dec->hDestinationStartEvent);
1794 pH264Dec->hDestinationStartEvent = NULL;
1795 pH264Dec->bDestinationStart = OMX_FALSE;
1796 Exynos_OSAL_SignalTerminate(pH264Dec->hSourceStartEvent);
1797 pH264Dec->hSourceStartEvent = NULL;
1798 pH264Dec->bSourceStart = OMX_FALSE;
1799
24ec2c82 1800 if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) {
0641ae29 1801 Exynos_Free_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX);
c6f4bc34
YK
1802 Exynos_OSAL_QueueTerminate(&pExynosOutputPort->codecBufferQ);
1803 Exynos_OSAL_SemaphoreTerminate(pExynosOutputPort->codecSemID);
24ec2c82 1804 } else if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) {
c6f4bc34
YK
1805 /*************/
1806 /* TBD */
1807 /*************/
1808 /* Does not require any actions. */
1809 }
1810
24ec2c82 1811 if (pExynosInputPort->bufferProcessType & BUFFER_COPY) {
0641ae29 1812 Exynos_Free_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX);
c6f4bc34
YK
1813 Exynos_OSAL_QueueTerminate(&pExynosInputPort->codecBufferQ);
1814 Exynos_OSAL_SemaphoreTerminate(pExynosInputPort->codecSemID);
24ec2c82 1815 } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) {
c6f4bc34
YK
1816 /*************/
1817 /* TBD */
1818 /*************/
1819 /* Does not require any actions. */
1820 }
1821 H264CodecClose(pH264Dec);
1822
e100a12d
SK
1823 Exynos_ResetAllPortConfig(pOMXComponent);
1824
c6f4bc34
YK
1825EXIT:
1826 FunctionOut();
1827
1828 return ret;
1829}
1830
1831OMX_ERRORTYPE Exynos_H264Dec_SrcIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData)
1832{
433e798a
EC
1833 OMX_ERRORTYPE ret = OMX_ErrorNone;
1834 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1835 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1836 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
1837 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
1838 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1839 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1840
1841 OMX_BUFFERHEADERTYPE tempBufferHeader;
1842 void *pPrivate = NULL;
1843
c6f4bc34 1844 OMX_U32 oneFrameSize = pSrcInputData->dataLen;
b907369f 1845 OMX_BOOL bInStartCode = OMX_FALSE;
433e798a
EC
1846
1847 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
1848 ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
1849 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
1850 ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE;
1851
c6f4bc34
YK
1852 int i;
1853
1854 FunctionIn();
1855
1856 if (pH264Dec->hMFCH264Handle.bConfiguredMFCSrc == OMX_FALSE) {
1857 ret = H264CodecSrcSetup(pOMXComponent, pSrcInputData);
1858 goto EXIT;
1859 }
1860 if (pH264Dec->hMFCH264Handle.bConfiguredMFCDst == OMX_FALSE) {
1861 ret = H264CodecDstSetup(pOMXComponent);
1862 }
1863
1864 if (((pVideoDec->bDRMPlayerMode == OMX_TRUE) ||
b907369f 1865 ((bInStartCode = Check_H264_StartCode(pSrcInputData->buffer.singlePlaneBuffer.dataBuffer, oneFrameSize)) == OMX_TRUE)) ||
c6f4bc34
YK
1866 ((pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) {
1867 pExynosComponent->timeStamp[pH264Dec->hMFCH264Handle.indexTimestamp] = pSrcInputData->timeStamp;
1868 pExynosComponent->nFlags[pH264Dec->hMFCH264Handle.indexTimestamp] = pSrcInputData->nFlags;
1869 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);
1870 pDecOps->Set_FrameTag(hMFCHandle, pH264Dec->hMFCH264Handle.indexTimestamp);
1871 pH264Dec->hMFCH264Handle.indexTimestamp++;
1872 pH264Dec->hMFCH264Handle.indexTimestamp %= MAX_TIMESTAMP;
433e798a
EC
1873#ifdef USE_QOS_CTRL
1874 if ((pVideoDec->bQosChanged == OMX_TRUE) &&
1875 (pDecOps->Set_QosRatio != NULL)) {
1876 pDecOps->Set_QosRatio(hMFCHandle, pVideoDec->nQosRatio);
1877 pVideoDec->bQosChanged = OMX_FALSE;
1878 }
1879#endif
c6f4bc34
YK
1880 /* queue work for input buffer */
1881 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "oneFrameSize: %d, bufferHeader: 0x%x, dataBuffer: 0x%x", oneFrameSize, pSrcInputData->bufferHeader, pSrcInputData->buffer.singlePlaneBuffer.dataBuffer);
433e798a
EC
1882 OMX_U32 nAllocLen[MAX_BUFFER_PLANE] = {pSrcInputData->bufferHeader->nAllocLen, 0, 0};
1883
1884 if (pExynosInputPort->bufferProcessType == BUFFER_COPY) {
1885 tempBufferHeader.nFlags = pSrcInputData->nFlags;
1886 tempBufferHeader.nTimeStamp = pSrcInputData->timeStamp;
1887 pPrivate = (void *)&tempBufferHeader;
1888 } else {
1889 pPrivate = (void *)pSrcInputData->bufferHeader;
1890 }
1891 codecReturn = pInbufOps->ExtensionEnqueue(hMFCHandle,
1892 (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.dataBuffer,
1893 (unsigned char **)&pSrcInputData->buffer.singlePlaneBuffer.fd,
1894 (unsigned int *)nAllocLen, (unsigned int *)&oneFrameSize,
1895 pExynosInputPort->nPlaneCnt, pPrivate);
c6f4bc34
YK
1896 if (codecReturn != VIDEO_ERROR_NONE) {
1897 ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
1898 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
1899 goto EXIT;
1900 }
1901 H264CodecStart(pOMXComponent, INPUT_PORT_INDEX);
1902 if (pH264Dec->bSourceStart == OMX_FALSE) {
1903 pH264Dec->bSourceStart = OMX_TRUE;
1904 Exynos_OSAL_SignalSet(pH264Dec->hSourceStartEvent);
1905 Exynos_OSAL_SleepMillisec(0);
1906 }
1907 if (pH264Dec->bDestinationStart == OMX_FALSE) {
1908 pH264Dec->bDestinationStart = OMX_TRUE;
1909 Exynos_OSAL_SignalSet(pH264Dec->hDestinationStartEvent);
1910 Exynos_OSAL_SleepMillisec(0);
1911 }
b907369f
TK
1912 } else if (bInStartCode == OMX_FALSE) {
1913 ret = OMX_ErrorCorruptedFrame;
1914 goto EXIT;
c6f4bc34
YK
1915 }
1916
1917 ret = OMX_ErrorNone;
1918
1919EXIT:
1920 FunctionOut();
1921
1922 return ret;
1923}
1924
1925OMX_ERRORTYPE Exynos_H264Dec_SrcOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData)
1926{
1927 OMX_ERRORTYPE ret = OMX_ErrorNone;
1928 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1929 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1930 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
1931 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
1932 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1933 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
1934 ExynosVideoDecBufferOps *pInbufOps = pH264Dec->hMFCH264Handle.pInbufOps;
1935 ExynosVideoBuffer *pVideoBuffer;
433e798a 1936 ExynosVideoBuffer videoBuffer;
c6f4bc34
YK
1937
1938 FunctionIn();
1939
433e798a
EC
1940 if (pInbufOps->ExtensionDequeue(hMFCHandle, &videoBuffer) == VIDEO_ERROR_NONE)
1941 pVideoBuffer = &videoBuffer;
1942 else
1943 pVideoBuffer = NULL;
c6f4bc34
YK
1944
1945 pSrcOutputData->dataLen = 0;
1946 pSrcOutputData->usedDataLen = 0;
1947 pSrcOutputData->remainDataLen = 0;
433e798a
EC
1948 pSrcOutputData->nFlags = 0;
1949 pSrcOutputData->timeStamp = 0;
1950 pSrcOutputData->bufferHeader = NULL;
c6f4bc34
YK
1951
1952 if (pVideoBuffer == NULL) {
1953 pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = NULL;
1954 pSrcOutputData->allocSize = 0;
1955 pSrcOutputData->pPrivate = NULL;
c6f4bc34
YK
1956 } else {
1957 pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = pVideoBuffer->planes[0].addr;
1958 pSrcOutputData->buffer.singlePlaneBuffer.fd = pVideoBuffer->planes[0].fd;
1959 pSrcOutputData->allocSize = pVideoBuffer->planes[0].allocSize;
1960
24ec2c82 1961 if (pExynosInputPort->bufferProcessType & BUFFER_COPY) {
9c39c5ff
TK
1962 int i;
1963 for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) {
1964 if (pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer ==
1965 pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]) {
1966 pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0;
1967 pSrcOutputData->pPrivate = pVideoDec->pMFCDecInputBuffer[i];
1968 break;
c6f4bc34 1969 }
c6f4bc34 1970 }
9c39c5ff
TK
1971
1972 if (i >= MFC_INPUT_BUFFER_NUM_MAX) {
1973 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not find buffer");
1974 ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
1975 goto EXIT;
1976 }
c6f4bc34
YK
1977 }
1978
1979 /* For Share Buffer */
433e798a
EC
1980 if (pExynosInputPort->bufferProcessType == BUFFER_SHARE)
1981 pSrcOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE*)pVideoBuffer->pPrivate;
c6f4bc34
YK
1982 }
1983
1984 ret = OMX_ErrorNone;
1985
1986EXIT:
1987 FunctionOut();
1988
1989 return ret;
1990}
1991
1992OMX_ERRORTYPE Exynos_H264Dec_DstIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData)
1993{
433e798a
EC
1994 OMX_ERRORTYPE ret = OMX_ErrorNone;
1995 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1996 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
1997 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
1998 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
1999 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
2000
2001 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
2002 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
2003 ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE;
2004
2005 OMX_U32 dataLen[MAX_BUFFER_PLANE] = {0, 0, 0};
2006 int i;
c6f4bc34
YK
2007
2008 FunctionIn();
2009
2010 if (pDstInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) {
2011 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to find input buffer");
2012 ret = OMX_ErrorBadParameter;
2013 goto EXIT;
2014 }
2015
433e798a
EC
2016 for (i = 0; i < pExynosOutputPort->nPlaneCnt; i++) {
2017 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s : %d => ADDR[%d]: 0x%x", __FUNCTION__, __LINE__, i,
2018 pDstInputData->buffer.multiPlaneBuffer.dataBuffer[i]);
2019 }
c6f4bc34 2020
405399e5 2021 if ((pVideoDec->bReconfigDPB == OMX_TRUE) &&
0a2897d8
TK
2022 (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) &&
2023 (pExynosOutputPort->exceptionFlag == GENERAL_STATE)) {
405399e5
TK
2024 ret = H264CodecDstSetup(pOMXComponent);
2025 if (ret != OMX_ErrorNone)
2026 goto EXIT;
2027 pVideoDec->bReconfigDPB = OMX_FALSE;
2028 }
2029
c6f4bc34 2030 codecReturn = pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pDstInputData->buffer.multiPlaneBuffer.dataBuffer,
433e798a 2031 (unsigned int *)dataLen, pExynosOutputPort->nPlaneCnt, pDstInputData->bufferHeader);
c6f4bc34
YK
2032
2033 if (codecReturn != VIDEO_ERROR_NONE) {
2034 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__);
2035 ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
2036 goto EXIT;
2037 }
2038 H264CodecStart(pOMXComponent, OUTPUT_PORT_INDEX);
2039
2040 ret = OMX_ErrorNone;
2041
2042EXIT:
2043 FunctionOut();
2044
2045 return ret;
2046}
2047
2048OMX_ERRORTYPE Exynos_H264Dec_DstOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData)
2049{
2050 OMX_ERRORTYPE ret = OMX_ErrorNone;
2051 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2052 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
2053 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
2054 void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle;
2055 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
2056 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
2057 ExynosVideoDecOps *pDecOps = pH264Dec->hMFCH264Handle.pDecOps;
2058 ExynosVideoDecBufferOps *pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps;
ca86e5fa 2059 ExynosVideoBuffer *pVideoBuffer = NULL;
c6f4bc34
YK
2060 ExynosVideoFrameStatusType displayStatus = VIDEO_FRAME_STATUS_UNKNOWN;
2061 ExynosVideoGeometry *bufferGeometry;
2062 DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
2063 OMX_S32 indexTimestamp = 0;
2064 int plane;
2065
2066 FunctionIn();
2067
2068 if (pH264Dec->bDestinationStart == OMX_FALSE) {
2069 ret = OMX_ErrorNone;
2070 goto EXIT;
2071 }
2072
2073 while (1) {
2a38c35a
SK
2074 pVideoBuffer = pOutbufOps->Dequeue(hMFCHandle);
2075 if (pVideoBuffer == (ExynosVideoBuffer *)VIDEO_ERROR_DQBUF_EIO) {
2076 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "HW is not available");
2077 ret = OMX_ErrorHardware;
2078 goto EXIT;
2079 }
2080
2081 if (pVideoBuffer == NULL) {
c6f4bc34
YK
2082 ret = OMX_ErrorNone;
2083 goto EXIT;
2084 }
2085 displayStatus = pVideoBuffer->displayStatus;
2086 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "displayStatus: 0x%x", displayStatus);
2087
2088 if ((displayStatus == VIDEO_FRAME_STATUS_DISPLAY_DECODING) ||
2089 (displayStatus == VIDEO_FRAME_STATUS_DISPLAY_ONLY) ||
2090 (displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) ||
405399e5 2091 (displayStatus == VIDEO_FRAME_STATUS_DECODING_FINISHED) ||
31e78666 2092 (displayStatus == VIDEO_FRAME_STATUS_ENABLED_S3D) ||
c6f4bc34 2093 (CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) {
ca86e5fa
TK
2094 ret = OMX_ErrorNone;
2095 break;
c6f4bc34
YK
2096 }
2097 }
2098
433e798a
EC
2099
2100#ifdef USE_S3D_SUPPORT
2101 /* Check Whether frame packing information is available */
2102 if ((pH264Dec->hMFCH264Handle.S3DFPArgmtType == OMX_SEC_FPARGMT_INVALID) &&
2103 (pVideoDec->bThumbnailMode == OMX_FALSE) &&
2104 ((displayStatus == VIDEO_FRAME_STATUS_DISPLAY_ONLY) ||
2105 (displayStatus == VIDEO_FRAME_STATUS_DISPLAY_DECODING) ||
2106 (displayStatus == VIDEO_FRAME_STATUS_ENABLED_S3D))) {
2107 if (H264CodecCheckFramePacking(pOMXComponent) != OMX_TRUE) {
2108 ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
2109 goto EXIT;
2110 }
2111 }
2112#endif
2113
405399e5 2114 if ((pVideoDec->bThumbnailMode == OMX_FALSE) &&
31e78666
TK
2115 ((displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) ||
2116 (displayStatus == VIDEO_FRAME_STATUS_ENABLED_S3D))) {
405399e5 2117 if (pVideoDec->bReconfigDPB != OMX_TRUE) {
0a2897d8 2118 pExynosOutputPort->exceptionFlag = NEED_PORT_FLUSH;
405399e5
TK
2119 pVideoDec->bReconfigDPB = OMX_TRUE;
2120 H264CodecCheckResolutionChange(pOMXComponent);
2121 pVideoDec->csc_set_format = OMX_FALSE;
433e798a
EC
2122#ifdef USE_S3D_SUPPORT
2123 pH264Dec->hMFCH264Handle.S3DFPArgmtType = OMX_SEC_FPARGMT_INVALID;
2124#endif
405399e5
TK
2125 }
2126 ret = OMX_ErrorNone;
2127 goto EXIT;
2128 }
2129
c6f4bc34
YK
2130 pH264Dec->hMFCH264Handle.outputIndexTimestamp++;
2131 pH264Dec->hMFCH264Handle.outputIndexTimestamp %= MAX_TIMESTAMP;
2132
2133 pDstOutputData->allocSize = pDstOutputData->dataLen = 0;
433e798a 2134 for (plane = 0; plane < pExynosOutputPort->nPlaneCnt; plane++) {
c6f4bc34
YK
2135 pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[plane] = pVideoBuffer->planes[plane].addr;
2136 pDstOutputData->buffer.multiPlaneBuffer.fd[plane] = pVideoBuffer->planes[plane].fd;
2137 pDstOutputData->allocSize += pVideoBuffer->planes[plane].allocSize;
2138 pDstOutputData->dataLen += pVideoBuffer->planes[plane].dataSize;
2139 }
2140 pDstOutputData->usedDataLen = 0;
2141 pDstOutputData->pPrivate = pVideoBuffer;
e90eb9e8
TK
2142 if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) {
2143 int i = 0;
2144 pDstOutputData->pPrivate = NULL;
2145 for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) {
2146 if (pDstOutputData->buffer.multiPlaneBuffer.dataBuffer[0] ==
2147 pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[0]) {
2148 pDstOutputData->pPrivate = pVideoDec->pMFCDecOutputBuffer[i];
2149 break;
2150 }
2151 }
2152
2153 if (pDstOutputData->pPrivate == NULL) {
2154 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not find buffer");
2155 ret = (OMX_ERRORTYPE)OMX_ErrorCodecDecode;
2156 goto EXIT;
2157 }
2158 }
2159
c6f4bc34
YK
2160 /* For Share Buffer */
2161 pDstOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE *)pVideoBuffer->pPrivate;
2162
2163 pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pDstOutputData->extInfo;
2164 bufferGeometry = &pH264Dec->hMFCH264Handle.codecOutbufConf;
2165 pBufferInfo->imageWidth = bufferGeometry->nFrameWidth;
2166 pBufferInfo->imageHeight = bufferGeometry->nFrameHeight;
2167 switch (bufferGeometry->eColorFormat) {
2168 case VIDEO_COLORFORMAT_NV12:
2169 pBufferInfo->ColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
2170 break;
433e798a
EC
2171#ifdef USE_DUALDPB_MODE
2172 case VIDEO_COLORFORMAT_I420:
2173 pBufferInfo->ColorFormat = OMX_COLOR_FormatYUV420Planar;
2174 break;
2175 case VIDEO_COLORFORMAT_YV12:
2176 pBufferInfo->ColorFormat = OMX_SEC_COLOR_FormatYVU420Planar;
2177 break;
2178 case VIDEO_COLORFORMAT_NV21:
2179 pBufferInfo->ColorFormat = OMX_SEC_COLOR_FormatNV21Linear;
2180 break;
2181#endif
c6f4bc34
YK
2182 case VIDEO_COLORFORMAT_NV12_TILED:
2183 default:
2184 pBufferInfo->ColorFormat = OMX_SEC_COLOR_FormatNV12Tiled;
2185 break;
2186 }
2187
2188 indexTimestamp = pDecOps->Get_FrameTag(hMFCHandle);
2189 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "out indexTimestamp: %d", indexTimestamp);
2190 if ((indexTimestamp < 0) || (indexTimestamp >= MAX_TIMESTAMP)) {
2191 if ((pExynosComponent->checkTimeStamp.needSetStartTimeStamp != OMX_TRUE) &&
2192 (pExynosComponent->checkTimeStamp.needCheckStartTimeStamp != OMX_TRUE)) {
f53da333
SK
2193 if (indexTimestamp == INDEX_AFTER_EOS) {
2194 pDstOutputData->timeStamp = 0x00;
2195 pDstOutputData->nFlags = 0x00;
2196 } else {
2197 pDstOutputData->timeStamp = pExynosComponent->timeStamp[pH264Dec->hMFCH264Handle.outputIndexTimestamp];
2198 pDstOutputData->nFlags = pExynosComponent->nFlags[pH264Dec->hMFCH264Handle.outputIndexTimestamp];
2199 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "missing out indexTimestamp: %d", indexTimestamp);
2200 }
c6f4bc34
YK
2201 } else {
2202 pDstOutputData->timeStamp = 0x00;
2203 pDstOutputData->nFlags = 0x00;
2204 }
2205 } else {
2206 /* For timestamp correction. if mfc support frametype detect */
2207 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "disp_pic_frame_type: %d", pVideoBuffer->frameType);
c70316c7
JY
2208
2209 /* NEED TIMESTAMP REORDER */
2210 if (pVideoDec->bDTSMode == OMX_TRUE) {
433e798a
EC
2211 if ((pVideoBuffer->frameType == VIDEO_FRAME_I) ||
2212 ((pVideoBuffer->frameType == VIDEO_FRAME_OTHERS) &&
2213 ((pExynosComponent->nFlags[indexTimestamp] & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) ||
2214 (pExynosComponent->checkTimeStamp.needCheckStartTimeStamp == OMX_TRUE))
c70316c7
JY
2215 pH264Dec->hMFCH264Handle.outputIndexTimestamp = indexTimestamp;
2216 else
2217 indexTimestamp = pH264Dec->hMFCH264Handle.outputIndexTimestamp;
c6f4bc34 2218 }
c70316c7 2219
c6f4bc34
YK
2220 pDstOutputData->timeStamp = pExynosComponent->timeStamp[indexTimestamp];
2221 pDstOutputData->nFlags = pExynosComponent->nFlags[indexTimestamp];
c70316c7 2222
c6f4bc34
YK
2223 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "timestamp %lld us (%.2f secs), indexTimestamp: %d, nFlags: 0x%x", pDstOutputData->timeStamp, pDstOutputData->timeStamp / 1E6, indexTimestamp, pDstOutputData->nFlags);
2224 }
2225
405399e5 2226 if ((displayStatus == VIDEO_FRAME_STATUS_DECODING_FINISHED) ||
c6f4bc34
YK
2227 ((pDstOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) {
2228 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "displayStatus:%d, nFlags0x%x", displayStatus, pDstOutputData->nFlags);
2229 pDstOutputData->remainDataLen = 0;
e100a12d
SK
2230
2231 if (((pDstOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) &&
2232 (pExynosComponent->bBehaviorEOS == OMX_TRUE)) {
2233 pDstOutputData->remainDataLen = bufferGeometry->nFrameWidth * bufferGeometry->nFrameHeight * 3 / 2;
2234 pExynosComponent->bBehaviorEOS = OMX_FALSE;
2235 }
c6f4bc34
YK
2236 } else {
2237 pDstOutputData->remainDataLen = bufferGeometry->nFrameWidth * bufferGeometry->nFrameHeight * 3 / 2;
2238 }
2239
2240 ret = OMX_ErrorNone;
2241
2242EXIT:
2243 FunctionOut();
2244
2245 return ret;
2246}
2247
2248OMX_ERRORTYPE Exynos_H264Dec_srcInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData)
2249{
2250 OMX_ERRORTYPE ret = OMX_ErrorNone;
2251 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2252 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
2253 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
2254
2255 FunctionIn();
2256
2257 if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) {
2258 ret = OMX_ErrorNone;
2259 goto EXIT;
2260 }
2261 if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) {
2262 ret = OMX_ErrorNone;
2263 goto EXIT;
2264 }
2265
2266 ret = Exynos_H264Dec_SrcIn(pOMXComponent, pSrcInputData);
b907369f
TK
2267 if ((ret != OMX_ErrorNone) &&
2268 (ret != OMX_ErrorInputDataDecodeYet) &&
2269 (ret != OMX_ErrorCorruptedFrame)) {
c6f4bc34
YK
2270 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
2271 pExynosComponent->callbackData,
2272 OMX_EventError, ret, 0, NULL);
2273 }
2274
2275EXIT:
2276 FunctionOut();
2277
2278 return ret;
2279}
2280
2281OMX_ERRORTYPE Exynos_H264Dec_srcOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData)
2282{
2283 OMX_ERRORTYPE ret = OMX_ErrorNone;
2284 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2285 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
2286 EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
2287
2288 FunctionIn();
2289
2290 if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) {
2291 ret = OMX_ErrorNone;
2292 goto EXIT;
2293 }
2294
24ec2c82 2295 if (pExynosInputPort->bufferProcessType & BUFFER_COPY) {
c6f4bc34
YK
2296 if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) {
2297 ret = OMX_ErrorNone;
2298 goto EXIT;
2299 }
2300 }
2301 if ((pH264Dec->bSourceStart == OMX_FALSE) &&
2302 (!CHECK_PORT_BEING_FLUSHED(pExynosInputPort))) {
2303 Exynos_OSAL_SignalWait(pH264Dec->hSourceStartEvent, DEF_MAX_WAIT_TIME);
2304 Exynos_OSAL_SignalReset(pH264Dec->hSourceStartEvent);
2305 }
2306
2307 ret = Exynos_H264Dec_SrcOut(pOMXComponent, pSrcOutputData);
2308 if ((ret != OMX_ErrorNone) && (pExynosComponent->currentState == OMX_StateExecuting)) {
2309 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
2310 pExynosComponent->callbackData,
2311 OMX_EventError, ret, 0, NULL);
2312 }
2313
2314EXIT:
2315 FunctionOut();
2316
2317 return ret;
2318}
2319
2320OMX_ERRORTYPE Exynos_H264Dec_dstInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData)
2321{
2322 OMX_ERRORTYPE ret = OMX_ErrorNone;
2323 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2324 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
2325 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
2326
2327 FunctionIn();
2328
2329 if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) {
2330 ret = OMX_ErrorNone;
2331 goto EXIT;
2332 }
2333 if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) {
2334 ret = OMX_ErrorNone;
2335 goto EXIT;
2336 }
24ec2c82 2337 if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) {
c6f4bc34
YK
2338 if ((pH264Dec->bDestinationStart == OMX_FALSE) &&
2339 (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) {
2340 Exynos_OSAL_SignalWait(pH264Dec->hDestinationStartEvent, DEF_MAX_WAIT_TIME);
2341 Exynos_OSAL_SignalReset(pH264Dec->hDestinationStartEvent);
2342 }
433e798a
EC
2343 if (Exynos_OSAL_GetElemNum(&pH264Dec->bypassBufferInfoQ) > 0) {
2344 BYPASS_BUFFER_INFO *pBufferInfo = (BYPASS_BUFFER_INFO *)Exynos_OSAL_Dequeue(&pH264Dec->bypassBufferInfoQ);
2345 if (pBufferInfo == NULL) {
2346 ret = OMX_ErrorUndefined;
2347 goto EXIT;
2348 }
2349
2350 pDstInputData->bufferHeader->nFlags = pBufferInfo->nFlags;
2351 pDstInputData->bufferHeader->nTimeStamp = pBufferInfo->timeStamp;
2352 Exynos_OMX_OutputBufferReturn(pOMXComponent, pDstInputData->bufferHeader);
2353 Exynos_OSAL_Free(pBufferInfo);
2354
2355 ret = OMX_ErrorNone;
2356 goto EXIT;
2357 }
c6f4bc34
YK
2358 }
2359 if (pH264Dec->hMFCH264Handle.bConfiguredMFCDst == OMX_TRUE) {
2360 ret = Exynos_H264Dec_DstIn(pOMXComponent, pDstInputData);
2361 if (ret != OMX_ErrorNone) {
2362 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
2363 pExynosComponent->callbackData,
2364 OMX_EventError, ret, 0, NULL);
2365 }
2366 }
2367
2368EXIT:
2369 FunctionOut();
2370
2371 return ret;
2372}
2373
2374OMX_ERRORTYPE Exynos_H264Dec_dstOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData)
2375{
2376 OMX_ERRORTYPE ret = OMX_ErrorNone;
2377 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2378 EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;
2379 EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
2380
2381 FunctionIn();
2382
2383 if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) {
2384 ret = OMX_ErrorNone;
2385 goto EXIT;
2386 }
2387 if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) {
2388 ret = OMX_ErrorNone;
2389 goto EXIT;
2390 }
2391
24ec2c82 2392 if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) {
c6f4bc34
YK
2393 if ((pH264Dec->bDestinationStart == OMX_FALSE) &&
2394 (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) {
2395 Exynos_OSAL_SignalWait(pH264Dec->hDestinationStartEvent, DEF_MAX_WAIT_TIME);
2396 Exynos_OSAL_SignalReset(pH264Dec->hDestinationStartEvent);
2397 }
433e798a
EC
2398
2399 if (Exynos_OSAL_GetElemNum(&pH264Dec->bypassBufferInfoQ) > 0) {
2400 EXYNOS_OMX_DATABUFFER *dstOutputUseBuffer = &pExynosOutputPort->way.port2WayDataBuffer.outputDataBuffer;
2401 OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
2402 BYPASS_BUFFER_INFO *pBufferInfo = NULL;
2403
2404 if (dstOutputUseBuffer->dataValid == OMX_FALSE) {
2405 pOMXBuffer = Exynos_OutputBufferGetQueue_Direct(pExynosComponent);
2406 if (pOMXBuffer == NULL) {
2407 ret = OMX_ErrorUndefined;
2408 goto EXIT;
2409 }
2410 } else {
2411 pOMXBuffer = dstOutputUseBuffer->bufferHeader;
2412 }
2413
2414 pBufferInfo = Exynos_OSAL_Dequeue(&pH264Dec->bypassBufferInfoQ);
2415 if (pBufferInfo == NULL) {
2416 ret = OMX_ErrorUndefined;
2417 goto EXIT;
2418 }
2419
2420 pOMXBuffer->nFlags = pBufferInfo->nFlags;
2421 pOMXBuffer->nTimeStamp = pBufferInfo->timeStamp;
2422 Exynos_OMX_OutputBufferReturn(pOMXComponent, pOMXBuffer);
2423 Exynos_OSAL_Free(pBufferInfo);
2424
2425 dstOutputUseBuffer->dataValid = OMX_FALSE;
2426
2427 ret = OMX_ErrorNone;
2428 goto EXIT;
2429 }
c6f4bc34
YK
2430 }
2431 ret = Exynos_H264Dec_DstOut(pOMXComponent, pDstOutputData);
2432 if ((ret != OMX_ErrorNone) && (pExynosComponent->currentState == OMX_StateExecuting)) {
2433 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
2434 pExynosComponent->callbackData,
2435 OMX_EventError, ret, 0, NULL);
2436 }
2437
2438EXIT:
2439 FunctionOut();
2440
2441 return ret;
2442}
2443
2444OSCL_EXPORT_REF OMX_ERRORTYPE Exynos_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName)
2445{
2446 OMX_ERRORTYPE ret = OMX_ErrorNone;
2447 OMX_COMPONENTTYPE *pOMXComponent = NULL;
2448 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
2449 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
2450 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
2451 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
2452 OMX_BOOL bDRMPlayerMode = OMX_FALSE;
2453 int i = 0;
2454
2455 FunctionIn();
2456
2457 if ((hComponent == NULL) || (componentName == NULL)) {
2458 ret = OMX_ErrorBadParameter;
2459 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
2460 goto EXIT;
2461 }
2462 if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_H264_DEC, componentName) == 0) {
2463 bDRMPlayerMode = OMX_FALSE;
2464 } else if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_H264_DRM_DEC, componentName) == 0) {
2465 bDRMPlayerMode = OMX_TRUE;
2466 } else {
2467 ret = OMX_ErrorBadParameter;
2468 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, componentName:%s, Line:%d", componentName, __LINE__);
2469 goto EXIT;
2470 }
2471
2472 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
2473 ret = Exynos_OMX_VideoDecodeComponentInit(pOMXComponent);
2474 if (ret != OMX_ErrorNone) {
2475 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
2476 goto EXIT;
2477 }
2478 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2479 pExynosComponent->codecType = HW_VIDEO_DEC_CODEC;
2480
2481 pExynosComponent->componentName = (OMX_STRING)Exynos_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE);
2482 if (pExynosComponent->componentName == NULL) {
2483 Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
2484 ret = OMX_ErrorInsufficientResources;
2485 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
2486 goto EXIT;
2487 }
2488 Exynos_OSAL_Memset(pExynosComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE);
2489
2490 pH264Dec = Exynos_OSAL_Malloc(sizeof(EXYNOS_H264DEC_HANDLE));
2491 if (pH264Dec == NULL) {
2492 Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
2493 ret = OMX_ErrorInsufficientResources;
2494 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
2495 goto EXIT;
2496 }
2497 Exynos_OSAL_Memset(pH264Dec, 0, sizeof(EXYNOS_H264DEC_HANDLE));
2498 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
2499 pVideoDec->hCodecHandle = (OMX_HANDLETYPE)pH264Dec;
2500
2501 if (bDRMPlayerMode == OMX_TRUE)
2502 Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_H264_DRM_DEC);
2503 else
2504 Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_H264_DEC);
2505
2506 pVideoDec->bDRMPlayerMode = bDRMPlayerMode;
064c4768 2507#ifdef USE_S3D_SUPPORT
433e798a 2508 pH264Dec->hMFCH264Handle.S3DFPArgmtType = OMX_SEC_FPARGMT_INVALID;
064c4768 2509#endif
c6f4bc34
YK
2510
2511 /* Set componentVersion */
2512 pExynosComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER;
2513 pExynosComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER;
2514 pExynosComponent->componentVersion.s.nRevision = REVISION_NUMBER;
2515 pExynosComponent->componentVersion.s.nStep = STEP_NUMBER;
2516 /* Set specVersion */
2517 pExynosComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER;
2518 pExynosComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER;
2519 pExynosComponent->specVersion.s.nRevision = REVISION_NUMBER;
2520 pExynosComponent->specVersion.s.nStep = STEP_NUMBER;
2521
2522 /* Input port */
2523 pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
2524 pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
2525 pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT;
2526 pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/
2527 pExynosPort->portDefinition.format.video.nSliceHeight = 0;
2528 pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE;
2529 pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
2530 Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE);
2531 Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "video/avc");
2532 pExynosPort->portDefinition.format.video.pNativeRender = 0;
2533 pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
2534 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
2535 pExynosPort->portDefinition.bEnabled = OMX_TRUE;
2536 pExynosPort->bufferProcessType = BUFFER_SHARE;
2537 if (bDRMPlayerMode == OMX_TRUE)
2538 pExynosPort->bufferProcessType = BUFFER_SHARE;
2539 pExynosPort->portWayType = WAY2_PORT;
2540
2541 /* Output port */
2542 pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
2543 pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
2544 pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT;
2545 pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/
2546 pExynosPort->portDefinition.format.video.nSliceHeight = 0;
2547 pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE;
2548 pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
2549 Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE);
2550 Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "raw/video");
2551 pExynosPort->portDefinition.format.video.pNativeRender = 0;
2552 pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
2553 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
2554 pExynosPort->portDefinition.bEnabled = OMX_TRUE;
2555 pExynosPort->bufferProcessType = BUFFER_COPY | BUFFER_ANBSHARE;
2556 pExynosPort->portWayType = WAY2_PORT;
2557
2558 for(i = 0; i < ALL_PORT_NUM; i++) {
2559 INIT_SET_SIZE_VERSION(&pH264Dec->AVCComponent[i], OMX_VIDEO_PARAM_AVCTYPE);
2560 pH264Dec->AVCComponent[i].nPortIndex = i;
2561 pH264Dec->AVCComponent[i].eProfile = OMX_VIDEO_AVCProfileBaseline;
2562 pH264Dec->AVCComponent[i].eLevel = OMX_VIDEO_AVCLevel4;
2563 }
2564
2565 pOMXComponent->GetParameter = &Exynos_H264Dec_GetParameter;
2566 pOMXComponent->SetParameter = &Exynos_H264Dec_SetParameter;
2567 pOMXComponent->GetConfig = &Exynos_H264Dec_GetConfig;
2568 pOMXComponent->SetConfig = &Exynos_H264Dec_SetConfig;
2569 pOMXComponent->GetExtensionIndex = &Exynos_H264Dec_GetExtensionIndex;
2570 pOMXComponent->ComponentRoleEnum = &Exynos_H264Dec_ComponentRoleEnum;
2571 pOMXComponent->ComponentDeInit = &Exynos_OMX_ComponentDeinit;
2572
2573 pExynosComponent->exynos_codec_componentInit = &Exynos_H264Dec_Init;
2574 pExynosComponent->exynos_codec_componentTerminate = &Exynos_H264Dec_Terminate;
2575
2576 pVideoDec->exynos_codec_srcInputProcess = &Exynos_H264Dec_srcInputBufferProcess;
2577 pVideoDec->exynos_codec_srcOutputProcess = &Exynos_H264Dec_srcOutputBufferProcess;
2578 pVideoDec->exynos_codec_dstInputProcess = &Exynos_H264Dec_dstInputBufferProcess;
2579 pVideoDec->exynos_codec_dstOutputProcess = &Exynos_H264Dec_dstOutputBufferProcess;
2580
2581 pVideoDec->exynos_codec_start = &H264CodecStart;
2582 pVideoDec->exynos_codec_stop = &H264CodecStop;
2583 pVideoDec->exynos_codec_bufferProcessRun = &H264CodecOutputBufferProcessRun;
2584 pVideoDec->exynos_codec_enqueueAllBuffer = &H264CodecEnQueueAllBuffer;
2585
2586 pVideoDec->exynos_checkInputFrame = &Check_H264_Frame;
2587 pVideoDec->exynos_codec_getCodecInputPrivateData = &GetCodecInputPrivateData;
2588 pVideoDec->exynos_codec_getCodecOutputPrivateData = &GetCodecOutputPrivateData;
405399e5 2589 pVideoDec->exynos_codec_reconfigAllBuffers = &H264CodecReconfigAllBuffers;
c6f4bc34
YK
2590
2591 pVideoDec->hSharedMemory = Exynos_OSAL_SharedMemory_Open();
2592 if (pVideoDec->hSharedMemory == NULL) {
2593 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
2594 Exynos_OSAL_Free(pH264Dec);
2595 pH264Dec = ((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle = NULL;
2596 Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
2597 ret = OMX_ErrorInsufficientResources;
2598 goto EXIT;
2599 }
2600
2601 pExynosComponent->currentState = OMX_StateLoaded;
2602
2603 ret = OMX_ErrorNone;
2604
2605EXIT:
2606 FunctionOut();
2607
2608 return ret;
2609}
2610
2611OMX_ERRORTYPE Exynos_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent)
2612{
2613 OMX_ERRORTYPE ret = OMX_ErrorNone;
2614 OMX_COMPONENTTYPE *pOMXComponent = NULL;
2615 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
2616 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
2617 EXYNOS_H264DEC_HANDLE *pH264Dec = NULL;
2618
2619 FunctionIn();
2620
2621 if (hComponent == NULL) {
2622 ret = OMX_ErrorBadParameter;
2623 goto EXIT;
2624 }
2625 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
2626 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
2627 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
2628
2629 Exynos_OSAL_SharedMemory_Close(pVideoDec->hSharedMemory);
2630
2631 Exynos_OSAL_Free(pExynosComponent->componentName);
2632 pExynosComponent->componentName = NULL;
2633
2634 pH264Dec = (EXYNOS_H264DEC_HANDLE *)pVideoDec->hCodecHandle;
2635 if (pH264Dec != NULL) {
2636 Exynos_OSAL_Free(pH264Dec);
2637 pH264Dec = pVideoDec->hCodecHandle = NULL;
2638 }
2639
2640 ret = Exynos_OMX_VideoDecodeComponentDeinit(pOMXComponent);
2641 if (ret != OMX_ErrorNone) {
2642 goto EXIT;
2643 }
2644
2645 ret = OMX_ErrorNone;
2646
2647EXIT:
2648 FunctionOut();
2649
2650 return ret;
2651}