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