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