1 /*
2 * Copyright (c) 2009-2011 Intel Corporation. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #define LOG_TAG "OMXVideoEncoderBase"
19 #include "OMXVideoEncoderBase.h"
20 #include "IntelMetadataBuffer.h"
21 #include <cutils/properties.h>
22 #include <wrs_omxil_core/log.h>
23
24 static const char *RAW_MIME_TYPE = "video/raw";
25
OMXVideoEncoderBase()26 OMXVideoEncoderBase::OMXVideoEncoderBase()
27 :mVideoEncoder(NULL)
28 ,mEncoderParams(NULL)
29 ,mFrameInputCount(0)
30 ,mFrameOutputCount(0)
31 ,mFirstFrame(OMX_TRUE)
32 ,mFrameRetrieved(OMX_TRUE)
33 ,mStoreMetaDataInBuffers(OMX_FALSE)
34 ,mSyncEncoding(OMX_TRUE)
35 ,mOmxLogLevel(0)
36 ,mBlackFramePointer(NULL) {
37 mEncoderParams = new VideoParamsCommon();
38 if (!mEncoderParams) LOGE("OMX_ErrorInsufficientResources");
39
40 char logLevelProp[128];
41 if (property_get("omxenc.debug", logLevelProp, NULL)) {
42 mOmxLogLevel = atoi(logLevelProp);
43 LOGD("Debug level is %d", mOmxLogLevel);
44 }
45
46 LOGV("OMXVideoEncoderBase::OMXVideoEncoderBase end");
47 }
48
~OMXVideoEncoderBase()49 OMXVideoEncoderBase::~OMXVideoEncoderBase() {
50
51 // destroy ports
52 if (this->ports) {
53 if (this->ports[INPORT_INDEX]) {
54 delete this->ports[INPORT_INDEX];
55 this->ports[INPORT_INDEX] = NULL;
56 }
57
58 if (this->ports[OUTPORT_INDEX]) {
59 delete this->ports[OUTPORT_INDEX];
60 this->ports[OUTPORT_INDEX] = NULL;
61 }
62 }
63
64 if (mBlackFramePointer) {
65 free(mBlackFramePointer);
66 mBlackFramePointer = NULL;
67 }
68 // Release video encoder object
69 if(mVideoEncoder) {
70 releaseVideoEncoder(mVideoEncoder);
71 mVideoEncoder = NULL;
72 }
73
74 if(mEncoderParams) {
75 delete mEncoderParams;
76 mEncoderParams = NULL;
77 }
78
79 }
80
InitInputPort(void)81 OMX_ERRORTYPE OMXVideoEncoderBase::InitInputPort(void) {
82 this->ports[INPORT_INDEX] = new PortVideo;
83 if (this->ports[INPORT_INDEX] == NULL) {
84 return OMX_ErrorInsufficientResources;
85 }
86
87 PortVideo *port = static_cast<PortVideo *>(this->ports[INPORT_INDEX]);
88
89 // OMX_PARAM_PORTDEFINITIONTYPE
90 OMX_PARAM_PORTDEFINITIONTYPE paramPortDefinitionInput;
91 memset(¶mPortDefinitionInput, 0, sizeof(paramPortDefinitionInput));
92 SetTypeHeader(¶mPortDefinitionInput, sizeof(paramPortDefinitionInput));
93 paramPortDefinitionInput.nPortIndex = INPORT_INDEX;
94 paramPortDefinitionInput.eDir = OMX_DirInput;
95 paramPortDefinitionInput.nBufferCountActual = INPORT_ACTUAL_BUFFER_COUNT;
96 paramPortDefinitionInput.nBufferCountMin = INPORT_MIN_BUFFER_COUNT;
97 paramPortDefinitionInput.nBufferSize = INPORT_BUFFER_SIZE;
98 paramPortDefinitionInput.bEnabled = OMX_TRUE;
99 paramPortDefinitionInput.bPopulated = OMX_FALSE;
100 paramPortDefinitionInput.eDomain = OMX_PortDomainVideo;
101 paramPortDefinitionInput.format.video.cMIMEType = (OMX_STRING)RAW_MIME_TYPE;
102 paramPortDefinitionInput.format.video.pNativeRender = NULL;
103 paramPortDefinitionInput.format.video.nFrameWidth = 176;
104 paramPortDefinitionInput.format.video.nFrameHeight = 144;
105 paramPortDefinitionInput.format.video.nStride = 0;
106 paramPortDefinitionInput.format.video.nSliceHeight = 0;
107 paramPortDefinitionInput.format.video.nBitrate = 64000;
108 paramPortDefinitionInput.format.video.xFramerate = 15 << 16;
109 paramPortDefinitionInput.format.video.bFlagErrorConcealment = OMX_FALSE;
110 paramPortDefinitionInput.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
111 paramPortDefinitionInput.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
112 paramPortDefinitionInput.format.video.pNativeWindow = NULL;
113 paramPortDefinitionInput.bBuffersContiguous = OMX_FALSE;
114 paramPortDefinitionInput.nBufferAlignment = 0;
115
116 // Nothing specific to initialize input port.
117 InitInputPortFormatSpecific(¶mPortDefinitionInput);
118
119 port->SetPortDefinition(¶mPortDefinitionInput, true);
120
121 // Set port buffer 4k aligned
122 port->SetMemAlignment(4096);
123
124 // OMX_VIDEO_PARAM_PORTFORMATTYPE
125 OMX_VIDEO_PARAM_PORTFORMATTYPE paramPortFormat;
126 memset(¶mPortFormat, 0, sizeof(paramPortFormat));
127 SetTypeHeader(¶mPortFormat, sizeof(paramPortFormat));
128 paramPortFormat.nPortIndex = INPORT_INDEX;
129 paramPortFormat.nIndex = 0;
130 paramPortFormat.eCompressionFormat = paramPortDefinitionInput.format.video.eCompressionFormat;
131 paramPortFormat.eColorFormat = paramPortDefinitionInput.format.video.eColorFormat;
132 paramPortFormat.xFramerate = paramPortDefinitionInput.format.video.xFramerate;
133
134 port->SetPortVideoParam(¶mPortFormat, true);
135
136 return OMX_ErrorNone;
137 }
138
139
InitOutputPort(void)140 OMX_ERRORTYPE OMXVideoEncoderBase::InitOutputPort(void) {
141 this->ports[OUTPORT_INDEX] = new PortVideo;
142 if (this->ports[OUTPORT_INDEX] == NULL) {
143 return OMX_ErrorInsufficientResources;
144 }
145
146 PortVideo *port = static_cast<PortVideo *>(this->ports[OUTPORT_INDEX]);
147
148 // OMX_VIDEO_PARAM_BITRATETYPE
149 memset(&mParamBitrate, 0, sizeof(mParamBitrate));
150 SetTypeHeader(&mParamBitrate, sizeof(mParamBitrate));
151 mParamBitrate.nPortIndex = OUTPORT_INDEX;
152 mParamBitrate.eControlRate = OMX_Video_ControlRateVariable;
153 mParamBitrate.nTargetBitrate = 192000; // to be overridden
154
155 // OMX_VIDEO_CONFIG_PRI_INFOTYPE
156 memset(&mConfigPriInfo, 0, sizeof(mConfigPriInfo));
157 SetTypeHeader(&mConfigPriInfo, sizeof(mConfigPriInfo));
158 mConfigPriInfo.nPortIndex = OUTPORT_INDEX;
159 mConfigPriInfo.nCapacity = 0;
160 mConfigPriInfo.nHolder = NULL;
161
162 // OMX_VIDEO_CONFIG_INTEL_BITRATETYPE
163 memset(&mConfigIntelBitrate, 0, sizeof(mConfigIntelBitrate));
164 SetTypeHeader(&mConfigIntelBitrate, sizeof(mConfigIntelBitrate));
165 mConfigIntelBitrate.nPortIndex = OUTPORT_INDEX;
166 mConfigIntelBitrate.nMaxEncodeBitrate = 0; // Maximum bitrate
167 mConfigIntelBitrate.nTargetPercentage = 95; // Target bitrate as percentage of maximum bitrate; e.g. 95 is 95%
168 mConfigIntelBitrate.nWindowSize = 0; // Window size in milliseconds allowed for bitrate to reach target
169 mConfigIntelBitrate.nInitialQP = 0; // Initial QP for I frames
170 mConfigIntelBitrate.nMinQP = 0;
171 mConfigIntelBitrate.nMaxQP = 0;
172 mConfigIntelBitrate.nFrameRate = 0;
173 mConfigIntelBitrate.nTemporalID = 0;
174
175 // OMX_VIDEO_CONFIG_INTEL_AIR
176 memset(&mConfigIntelAir, 0, sizeof(mConfigIntelAir));
177 SetTypeHeader(&mConfigIntelAir, sizeof(mConfigIntelAir));
178 mConfigIntelAir.nPortIndex = OUTPORT_INDEX;
179 mConfigIntelAir.bAirEnable = OMX_FALSE;
180 mConfigIntelAir.bAirAuto = OMX_FALSE;
181 mConfigIntelAir.nAirMBs = 0;
182 mConfigIntelAir.nAirThreshold = 0;
183
184 // OMX_VIDEO_CONFIG_INTEL_AIR
185 memset(&mParamVideoRefresh, 0, sizeof(mParamVideoRefresh));
186 SetTypeHeader(&mParamVideoRefresh, sizeof(mParamVideoRefresh));
187 mParamVideoRefresh.nPortIndex = OUTPORT_INDEX;
188 mParamVideoRefresh.eRefreshMode = OMX_VIDEO_IntraRefreshAdaptive;
189 mParamVideoRefresh.nAirMBs = 0;
190 mParamVideoRefresh.nAirRef = 0;
191 mParamVideoRefresh.nCirMBs = 0;
192
193 // OMX_CONFIG_FRAMERATETYPE
194 memset(&mConfigFramerate, 0, sizeof(mConfigFramerate));
195 SetTypeHeader(&mConfigFramerate, sizeof(mConfigFramerate));
196 mConfigFramerate.nPortIndex = OUTPORT_INDEX;
197 mConfigFramerate.xEncodeFramerate = 0; // Q16 format
198
199 // OMX_VIDEO_PARAM_INTEL_ADAPTIVE_SLICE_CONTROL
200 memset(&mParamIntelAdaptiveSliceControl, 0, sizeof(mParamIntelAdaptiveSliceControl));
201 SetTypeHeader(&mParamIntelAdaptiveSliceControl, sizeof(mParamIntelAdaptiveSliceControl));
202 mParamIntelAdaptiveSliceControl.nPortIndex = OUTPORT_INDEX;
203 mParamIntelAdaptiveSliceControl.bEnable = OMX_FALSE;
204 mParamIntelAdaptiveSliceControl.nMinPSliceNumber = 5;
205 mParamIntelAdaptiveSliceControl.nNumPFramesToSkip = 8;
206 mParamIntelAdaptiveSliceControl.nSliceSizeThreshold = 1200;
207
208 // OMX_VIDEO_PARAM_PROFILELEVELTYPE
209 memset(&mParamProfileLevel, 0, sizeof(mParamProfileLevel));
210 SetTypeHeader(&mParamProfileLevel, sizeof(mParamProfileLevel));
211 mParamProfileLevel.nPortIndex = OUTPORT_INDEX;
212 mParamProfileLevel.eProfile = 0; // undefined profile, to be overridden
213 mParamProfileLevel.eLevel = 0; // undefined level, to be overridden
214
215 // OMX_PARAM_PORTDEFINITIONTYPE
216 OMX_PARAM_PORTDEFINITIONTYPE paramPortDefinitionOutput;
217 memset(¶mPortDefinitionOutput, 0, sizeof(paramPortDefinitionOutput));
218 SetTypeHeader(¶mPortDefinitionOutput, sizeof(paramPortDefinitionOutput));
219 paramPortDefinitionOutput.nPortIndex = OUTPORT_INDEX;
220 paramPortDefinitionOutput.eDir = OMX_DirOutput;
221 paramPortDefinitionOutput.nBufferCountActual = OUTPORT_ACTUAL_BUFFER_COUNT; // to be overridden
222 paramPortDefinitionOutput.nBufferCountMin = OUTPORT_MIN_BUFFER_COUNT;
223 paramPortDefinitionOutput.nBufferSize = OUTPORT_BUFFER_SIZE; // to be overridden
224 paramPortDefinitionOutput.bEnabled = OMX_TRUE;
225 paramPortDefinitionOutput.bPopulated = OMX_FALSE;
226 paramPortDefinitionOutput.eDomain = OMX_PortDomainVideo;
227 paramPortDefinitionOutput.format.video.cMIMEType = NULL; // to be overridden
228 paramPortDefinitionOutput.format.video.pNativeRender = NULL;
229 paramPortDefinitionOutput.format.video.nFrameWidth = 176;
230 paramPortDefinitionOutput.format.video.nFrameHeight = 144;
231 paramPortDefinitionOutput.format.video.nStride = 176;
232 paramPortDefinitionOutput.format.video.nSliceHeight = 144;
233 paramPortDefinitionOutput.format.video.nBitrate = 64000;
234 paramPortDefinitionOutput.format.video.xFramerate = 15 << 16;
235 paramPortDefinitionOutput.format.video.bFlagErrorConcealment = OMX_FALSE;
236 paramPortDefinitionOutput.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; // to be overridden
237 paramPortDefinitionOutput.format.video.eColorFormat = OMX_COLOR_FormatUnused;
238 paramPortDefinitionOutput.format.video.pNativeWindow = NULL;
239 paramPortDefinitionOutput.bBuffersContiguous = OMX_FALSE;
240 paramPortDefinitionOutput.nBufferAlignment = 0;
241
242 InitOutputPortFormatSpecific(¶mPortDefinitionOutput);
243
244 port->SetPortDefinition(¶mPortDefinitionOutput, true);
245 port->SetPortBitrateParam(&mParamBitrate, true);
246
247 // OMX_VIDEO_PARAM_PORTFORMATTYPE
248 OMX_VIDEO_PARAM_PORTFORMATTYPE paramPortFormat;
249 memset(¶mPortFormat, 0, sizeof(paramPortFormat));
250 SetTypeHeader(¶mPortFormat, sizeof(paramPortFormat));
251 paramPortFormat.nPortIndex = OUTPORT_INDEX;
252 paramPortFormat.nIndex = 0;
253 paramPortFormat.eCompressionFormat = paramPortDefinitionOutput.format.video.eCompressionFormat;
254 paramPortFormat.eColorFormat = paramPortDefinitionOutput.format.video.eColorFormat;
255 paramPortFormat.xFramerate = paramPortDefinitionOutput.format.video.xFramerate;
256
257 port->SetPortVideoParam(¶mPortFormat, true);
258 return OMX_ErrorNone;
259 }
260
InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *)261 OMX_ERRORTYPE OMXVideoEncoderBase::InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *) {
262 // no format specific to initialize input
263 return OMX_ErrorNone;
264 }
265
SetVideoEncoderParam()266 OMX_ERRORTYPE OMXVideoEncoderBase::SetVideoEncoderParam() {
267
268 Encode_Status ret = ENCODE_SUCCESS;
269 PortVideo *port_in = NULL;
270 PortVideo *port_out = NULL;
271 OMX_VIDEO_CONTROLRATETYPE controlrate;
272 const OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput = NULL;
273 LOGV("OMXVideoEncoderBase::SetVideoEncoderParam called\n");
274
275 port_in = static_cast<PortVideo *>(ports[INPORT_INDEX]);
276 port_out = static_cast<PortVideo *>(ports[OUTPORT_INDEX]);
277 paramPortDefinitionInput = port_in->GetPortDefinition();
278 mEncoderParams->resolution.height = paramPortDefinitionInput->format.video.nFrameHeight;
279 mEncoderParams->resolution.width = paramPortDefinitionInput->format.video.nFrameWidth;
280 const OMX_VIDEO_PARAM_BITRATETYPE *bitrate = port_out->GetPortBitrateParam();
281
282 mEncoderParams->frameRate.frameRateDenom = 1;
283 if(mConfigFramerate.xEncodeFramerate != 0) {
284 mEncoderParams->frameRate.frameRateNum = mConfigFramerate.xEncodeFramerate;
285 } else {
286 mEncoderParams->frameRate.frameRateNum = paramPortDefinitionInput->format.video.xFramerate >> 16;
287 mConfigFramerate.xEncodeFramerate = paramPortDefinitionInput->format.video.xFramerate >> 16;
288 }
289
290 if(mEncoderParams->intraPeriod == 0) {
291 OMX_U32 intraPeriod = mEncoderParams->frameRate.frameRateNum / 2;
292 mEncoderParams->intraPeriod = (intraPeriod < 15) ? 15 : intraPeriod; // Limit intra frame period to ensure video quality for low bitrate application.
293 }
294
295 if (paramPortDefinitionInput->format.video.eColorFormat == OMX_COLOR_FormatAndroidOpaque)
296 mEncoderParams->rawFormat = RAW_FORMAT_OPAQUE;
297 else
298 mEncoderParams->rawFormat = RAW_FORMAT_NV12;
299
300 LOGV("frameRate.frameRateDenom = %d\n", mEncoderParams->frameRate.frameRateDenom);
301 LOGV("frameRate.frameRateNum = %d\n", mEncoderParams->frameRate.frameRateNum);
302 LOGV("intraPeriod = %d\n ", mEncoderParams->intraPeriod);
303 mEncoderParams->rcParams.initQP = mConfigIntelBitrate.nInitialQP;
304 mEncoderParams->rcParams.minQP = mConfigIntelBitrate.nMinQP;
305 mEncoderParams->rcParams.maxQP = 0;
306 mEncoderParams->rcParams.I_minQP = 0;
307 mEncoderParams->rcParams.I_maxQP = 0;
308 mEncoderParams->rcParams.windowSize = mConfigIntelBitrate.nWindowSize;
309 mEncoderParams->rcParams.targetPercentage = mConfigIntelBitrate.nTargetPercentage;
310 mEncoderParams->rcParams.enableIntraFrameQPControl = 0;
311
312 mEncoderParams->rcParams.bitRate = mParamBitrate.nTargetBitrate;
313 if ((mParamBitrate.eControlRate == OMX_Video_ControlRateConstant )||
314 (mParamBitrate.eControlRate == OMX_Video_ControlRateConstantSkipFrames)) {
315 LOGV("%s(), eControlRate == OMX_Video_Intel_ControlRateConstant", __func__);
316 mEncoderParams->rcMode = RATE_CONTROL_CBR;
317 } else if ((mParamBitrate.eControlRate == OMX_Video_ControlRateVariable) ||
318 (mParamBitrate.eControlRate == OMX_Video_ControlRateVariableSkipFrames)) {
319 LOGV("%s(), eControlRate == OMX_Video_Intel_ControlRateVariable", __func__);
320 mEncoderParams->rcMode = RATE_CONTROL_VBR;
321 } else if (mParamBitrate.eControlRate == (OMX_VIDEO_CONTROLRATETYPE)OMX_Video_Intel_ControlRateVideoConferencingMode) {
322 LOGV("%s(), eControlRate == OMX_Video_Intel_ControlRateVideoConferencingMode ", __func__);
323 mEncoderParams->rcMode = RATE_CONTROL_VCM;
324 if(mConfigIntelBitrate.nMaxEncodeBitrate >0)
325 mEncoderParams->rcParams.bitRate = mConfigIntelBitrate.nMaxEncodeBitrate;
326 if(mConfigIntelAir.bAirEnable == OMX_TRUE) {
327 mEncoderParams->airParams.airAuto = mConfigIntelAir.bAirAuto;
328 mEncoderParams->airParams.airMBs = mConfigIntelAir.nAirMBs;
329 mEncoderParams->airParams.airThreshold = mConfigIntelAir.nAirThreshold;
330 mEncoderParams->refreshType = VIDEO_ENC_AIR;
331 } else {
332 mEncoderParams->refreshType = VIDEO_ENC_NONIR;
333 }
334 LOGV("refreshType = %d\n", mEncoderParams->refreshType);
335 } else {
336 mEncoderParams->rcMode = RATE_CONTROL_NONE;
337 }
338
339 ret = mVideoEncoder->setParameters(mEncoderParams);
340 CHECK_ENCODE_STATUS("setParameters");
341 return OMX_ErrorNone;
342 }
343
ProcessorInit(void)344 OMX_ERRORTYPE OMXVideoEncoderBase::ProcessorInit(void) {
345 OMX_ERRORTYPE ret = OMX_ErrorNone;
346 ret = SetVideoEncoderParam();
347 CHECK_STATUS("SetVideoEncoderParam");
348
349 Encode_Status status = mVideoEncoder->start();
350 if (status != ENCODE_SUCCESS) {
351 LOGE("Start failed, status = 0x%08x\n", status);
352 return OMX_ErrorUndefined;
353 }
354
355 return OMX_ErrorNone;
356 }
357
ProcessorDeinit(void)358 OMX_ERRORTYPE OMXVideoEncoderBase::ProcessorDeinit(void) {
359 OMX_ERRORTYPE ret;
360
361 if(mVideoEncoder) {
362 mVideoEncoder->stop();
363 }
364
365 return OMX_ErrorNone;
366 }
367
ProcessorStop(void)368 OMX_ERRORTYPE OMXVideoEncoderBase::ProcessorStop(void) {
369
370 this->ports[INPORT_INDEX]->ReturnAllRetainedBuffers();
371 return OMX_ErrorNone;
372 }
ProcessorProcess(OMX_BUFFERHEADERTYPE **,buffer_retain_t *,OMX_U32)373 OMX_ERRORTYPE OMXVideoEncoderBase:: ProcessorProcess(
374 OMX_BUFFERHEADERTYPE **,
375 buffer_retain_t *,
376 OMX_U32) {
377
378 LOGV("OMXVideoEncoderBase:: ProcessorProcess \n");
379 return OMX_ErrorNone;
380 }
381
ProcessorFlush(OMX_U32 portIndex)382 OMX_ERRORTYPE OMXVideoEncoderBase::ProcessorFlush(OMX_U32 portIndex) {
383 LOGV("OMXVideoEncoderBase::ProcessorFlush\n");
384 if (portIndex == INPORT_INDEX || portIndex == OMX_ALL) {
385 this->ports[INPORT_INDEX]->ReturnAllRetainedBuffers();
386 mVideoEncoder->flush();
387 }
388 return OMX_ErrorNone;
389 }
390
BuildHandlerList(void)391 OMX_ERRORTYPE OMXVideoEncoderBase::BuildHandlerList(void) {
392 OMXComponentCodecBase::BuildHandlerList();
393 AddHandler(OMX_IndexParamVideoPortFormat, GetParamVideoPortFormat, SetParamVideoPortFormat);
394 AddHandler(OMX_IndexParamVideoBitrate, GetParamVideoBitrate, SetParamVideoBitrate);
395 AddHandler((OMX_INDEXTYPE)OMX_IndexIntelPrivateInfo, GetIntelPrivateInfo, SetIntelPrivateInfo);
396 AddHandler((OMX_INDEXTYPE)OMX_IndexConfigIntelBitrate, GetConfigIntelBitrate, SetConfigIntelBitrate);
397 AddHandler((OMX_INDEXTYPE)OMX_IndexConfigIntelAIR, GetConfigIntelAIR, SetConfigIntelAIR);
398 AddHandler((OMX_INDEXTYPE)OMX_IndexParamVideoIntraRefresh, GetParamVideoIntraRefresh, SetParamVideoIntraRefresh);
399 AddHandler(OMX_IndexConfigVideoFramerate, GetConfigVideoFramerate, SetConfigVideoFramerate);
400 AddHandler(OMX_IndexConfigVideoIntraVOPRefresh, GetConfigVideoIntraVOPRefresh, SetConfigVideoIntraVOPRefresh);
401 //AddHandler(OMX_IndexParamIntelAdaptiveSliceControl, GetParamIntelAdaptiveSliceControl, SetParamIntelAdaptiveSliceControl);
402 //AddHandler(OMX_IndexParamVideoProfileLevelQuerySupported, GetParamVideoProfileLevelQuerySupported, SetParamVideoProfileLevelQuerySupported);
403 AddHandler((OMX_INDEXTYPE)OMX_IndexStoreMetaDataInBuffers, GetStoreMetaDataInBuffers, SetStoreMetaDataInBuffers);
404 AddHandler((OMX_INDEXTYPE)OMX_IndexExtSyncEncoding, GetSyncEncoding, SetSyncEncoding);
405 AddHandler((OMX_INDEXTYPE)OMX_IndexExtPrependSPSPPS, GetPrependSPSPPS, SetPrependSPSPPS);
406 AddHandler((OMX_INDEXTYPE)OMX_IndexExtTemporalLayer, GetTemporalLayer,SetTemporalLayer);
407 AddHandler((OMX_INDEXTYPE)OMX_IndexExtRequestBlackFramePointer, GetBlackFramePointer, GetBlackFramePointer);
408 return OMX_ErrorNone;
409 }
410
GetParamVideoPortFormat(OMX_PTR pStructure)411 OMX_ERRORTYPE OMXVideoEncoderBase::GetParamVideoPortFormat(OMX_PTR pStructure) {
412 OMX_ERRORTYPE ret;
413 OMX_U32 index;
414 OMX_VIDEO_PARAM_PORTFORMATTYPE *p = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pStructure;
415
416 CHECK_TYPE_HEADER(p);
417 CHECK_PORT_INDEX_RANGE(p);
418 CHECK_ENUMERATION_RANGE(p->nIndex, 2);
419
420 PortVideo *port = NULL;
421 port = static_cast<PortVideo *>(this->ports[p->nPortIndex]);
422 index = p->nIndex;
423 memcpy(p, port->GetPortVideoParam(), sizeof(*p));
424 // port supports OMX_COLOR_FormatYUV420SemiPlanar & OMX_COLOR_FormatAndroidOpaque
425 if (index == 1) {
426 p->nIndex = 1;
427 p->eColorFormat = OMX_COLOR_FormatAndroidOpaque;
428 }
429 return OMX_ErrorNone;
430 }
431
SetParamVideoPortFormat(OMX_PTR pStructure)432 OMX_ERRORTYPE OMXVideoEncoderBase::SetParamVideoPortFormat(OMX_PTR pStructure) {
433 OMX_ERRORTYPE ret;
434 OMX_VIDEO_PARAM_PORTFORMATTYPE *p = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pStructure;
435
436 CHECK_TYPE_HEADER(p);
437 CHECK_PORT_INDEX_RANGE(p);
438 CHECK_SET_PARAM_STATE();
439
440 // TODO: do we need to check if port is enabled?
441 PortVideo *port = NULL;
442 port = static_cast<PortVideo *>(this->ports[p->nPortIndex]);
443 #if 0
444 if (p->eColorFormat == OMX_COLOR_FormatAndroidOpaque) {
445 p->nIndex = 0;
446 p->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
447 }
448 #endif
449 port->SetPortVideoParam(p, false);
450 return OMX_ErrorNone;
451 }
452
GetParamVideoBitrate(OMX_PTR pStructure)453 OMX_ERRORTYPE OMXVideoEncoderBase::GetParamVideoBitrate(OMX_PTR pStructure) {
454 OMX_ERRORTYPE ret;
455 OMX_VIDEO_PARAM_BITRATETYPE *p = (OMX_VIDEO_PARAM_BITRATETYPE *)pStructure;
456
457 CHECK_TYPE_HEADER(p);
458 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
459 memcpy(p, &mParamBitrate, sizeof(*p));
460 return OMX_ErrorNone;
461 }
462
SetParamVideoBitrate(OMX_PTR pStructure)463 OMX_ERRORTYPE OMXVideoEncoderBase::SetParamVideoBitrate(OMX_PTR pStructure) {
464 OMX_ERRORTYPE ret;
465 OMX_VIDEO_PARAM_BITRATETYPE *p = (OMX_VIDEO_PARAM_BITRATETYPE *)pStructure;
466 CHECK_TYPE_HEADER(p);
467 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
468 CHECK_SET_PARAM_STATE();
469 OMX_U32 index = p->nPortIndex;
470 PortVideo *port = NULL;
471 // This disables other type of bitrate control mechanism
472 // TODO: check if it is desired
473
474 // TODO: can we override mParamBitrate.nPortIndex (See SetPortBitrateParam)
475 mParamBitrate.eControlRate = p->eControlRate;
476 mParamBitrate.nTargetBitrate = p->nTargetBitrate;
477
478 port = static_cast<PortVideo *>(ports[index]);
479 ret = port->SetPortBitrateParam(p, false);
480 return OMX_ErrorNone;
481 }
482
GetIntelPrivateInfo(OMX_PTR pStructure)483 OMX_ERRORTYPE OMXVideoEncoderBase::GetIntelPrivateInfo(OMX_PTR pStructure) {
484 OMX_ERRORTYPE ret;
485 OMX_VIDEO_CONFIG_PRI_INFOTYPE *p = (OMX_VIDEO_CONFIG_PRI_INFOTYPE *)pStructure;
486
487 CHECK_TYPE_HEADER(p);
488 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
489 memcpy(p, &mConfigPriInfo, sizeof(*p));
490 return OMX_ErrorNone;
491 }
492
SetIntelPrivateInfo(OMX_PTR pStructure)493 OMX_ERRORTYPE OMXVideoEncoderBase::SetIntelPrivateInfo(OMX_PTR pStructure) {
494 OMX_ERRORTYPE ret;
495 OMX_VIDEO_CONFIG_PRI_INFOTYPE *p = (OMX_VIDEO_CONFIG_PRI_INFOTYPE *)pStructure;
496 CHECK_TYPE_HEADER(p);
497 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
498
499 // OMX_VIDEO_CONFIG_PRI_INFOTYPE is static parameter?
500 CHECK_SET_PARAM_STATE();
501
502 // TODO: can we override mConfigPriInfo.nPortIndex (See SetPortPrivateInfoParam)
503
504 if(p->nHolder != NULL) {
505 // TODO: do we need to free nHolder?
506 if (mConfigPriInfo.nHolder) {
507 free(mConfigPriInfo.nHolder);
508 }
509 mConfigPriInfo.nCapacity = p->nCapacity;
510 // TODO: nCapacity is in 8-bit unit or 32-bit unit?
511 // TODO: check memory allocation
512 mConfigPriInfo.nHolder = (OMX_PTR)malloc(sizeof(OMX_U32) * p->nCapacity);
513 memcpy(mConfigPriInfo.nHolder, p->nHolder, sizeof(OMX_U32) * p->nCapacity);
514 } else {
515 mConfigPriInfo.nCapacity = 0;
516 mConfigPriInfo.nHolder = NULL;
517 }
518
519 return OMX_ErrorNone;
520 }
521
GetConfigIntelBitrate(OMX_PTR pStructure)522 OMX_ERRORTYPE OMXVideoEncoderBase::GetConfigIntelBitrate(OMX_PTR pStructure) {
523 OMX_ERRORTYPE ret;
524 OMX_VIDEO_CONFIG_INTEL_BITRATETYPE *p = (OMX_VIDEO_CONFIG_INTEL_BITRATETYPE *)pStructure;
525
526 CHECK_TYPE_HEADER(p);
527 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
528 memcpy(p, &mConfigIntelBitrate, sizeof(*p));
529 return OMX_ErrorNone;
530 }
531
SetConfigIntelBitrate(OMX_PTR pStructure)532 OMX_ERRORTYPE OMXVideoEncoderBase::SetConfigIntelBitrate(OMX_PTR pStructure) {
533 OMX_ERRORTYPE ret;
534 Encode_Status retStatus = ENCODE_SUCCESS;
535 if (mParamBitrate.eControlRate == OMX_Video_ControlRateMax){
536 LOGE("SetConfigIntelBitrate failed. Feature is disabled.");
537 return OMX_ErrorUnsupportedIndex;
538 }
539 OMX_VIDEO_CONFIG_INTEL_BITRATETYPE *p = (OMX_VIDEO_CONFIG_INTEL_BITRATETYPE *)pStructure;
540 CHECK_TYPE_HEADER(p);
541 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
542
543 // set in either Loaded state (ComponentSetParam) or Executing state (ComponentSetConfig)
544 mConfigIntelBitrate = *p;
545
546 // return OMX_ErrorNone if not in Executing state
547 // TODO: return OMX_ErrorIncorrectStateOperation?
548 CHECK_SET_CONFIG_STATE();
549
550 VideoConfigBitRate configBitRate;
551 configBitRate.rcParams.bitRate = mConfigIntelBitrate.nMaxEncodeBitrate;
552 configBitRate.rcParams.initQP = mConfigIntelBitrate.nInitialQP;
553 configBitRate.rcParams.minQP = mConfigIntelBitrate.nMinQP;
554 configBitRate.rcParams.maxQP = mConfigIntelBitrate.nMaxQP;
555 configBitRate.rcParams.I_minQP = 0;
556 configBitRate.rcParams.I_maxQP = 0;
557 configBitRate.rcParams.windowSize = mConfigIntelBitrate.nWindowSize;
558 configBitRate.rcParams.targetPercentage = mConfigIntelBitrate.nTargetPercentage;
559 configBitRate.rcParams.enableIntraFrameQPControl = 0;
560 configBitRate.rcParams.temporalFrameRate = mConfigIntelBitrate.nFrameRate;
561 configBitRate.rcParams.temporalID = mConfigIntelBitrate.nTemporalID;
562 retStatus = mVideoEncoder->setConfig(&configBitRate);
563 if(retStatus != ENCODE_SUCCESS) {
564 LOGW("failed to set IntelBitrate");
565 }
566 return OMX_ErrorNone;
567 }
568
GetConfigIntelAIR(OMX_PTR pStructure)569 OMX_ERRORTYPE OMXVideoEncoderBase::GetConfigIntelAIR(OMX_PTR pStructure) {
570 OMX_ERRORTYPE ret;
571 OMX_VIDEO_CONFIG_INTEL_AIR *p = (OMX_VIDEO_CONFIG_INTEL_AIR *)pStructure;
572
573 CHECK_TYPE_HEADER(p);
574 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
575 memcpy(p, &mConfigIntelAir, sizeof(*p));
576 return OMX_ErrorNone;
577 }
578
SetConfigIntelAIR(OMX_PTR pStructure)579 OMX_ERRORTYPE OMXVideoEncoderBase::SetConfigIntelAIR(OMX_PTR pStructure) {
580 OMX_ERRORTYPE ret;
581 Encode_Status retStatus = ENCODE_SUCCESS;
582
583 OMX_VIDEO_CONFIG_INTEL_AIR *p = (OMX_VIDEO_CONFIG_INTEL_AIR *)pStructure;
584 CHECK_TYPE_HEADER(p);
585 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
586
587 // set in either Loaded state (ComponentSetParam) or Executing state (ComponentSetConfig)
588 mConfigIntelAir = *p;
589
590 // return OMX_ErrorNone if not in Executing state
591 // TODO: return OMX_ErrorIncorrectStateOperation?
592 CHECK_SET_CONFIG_STATE();
593
594 VideoConfigAIR configAIR;
595 VideoConfigIntraRefreshType configIntraRefreshType;
596 if(mConfigIntelAir.bAirEnable == OMX_TRUE) {
597 configAIR.airParams.airAuto = mConfigIntelAir.bAirAuto;
598 configAIR.airParams.airMBs = mConfigIntelAir.nAirMBs;
599 configAIR.airParams.airThreshold = mConfigIntelAir.nAirThreshold;
600 configIntraRefreshType.refreshType = VIDEO_ENC_AIR;
601 } else {
602 configIntraRefreshType.refreshType = VIDEO_ENC_NONIR;
603 }
604
605 retStatus = mVideoEncoder->setConfig(&configAIR);
606 if(retStatus != ENCODE_SUCCESS) {
607 LOGW("Failed to set AIR config");
608 }
609
610 retStatus = mVideoEncoder->setConfig(&configIntraRefreshType);
611 if(retStatus != ENCODE_SUCCESS) {
612 LOGW("Failed to set refresh config");
613 }
614 return OMX_ErrorNone;
615 }
616
GetParamVideoIntraRefresh(OMX_PTR pStructure)617 OMX_ERRORTYPE OMXVideoEncoderBase::GetParamVideoIntraRefresh(OMX_PTR pStructure) {
618 OMX_ERRORTYPE ret;
619 OMX_VIDEO_PARAM_INTRAREFRESHTYPE *p = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)pStructure;
620
621 CHECK_TYPE_HEADER(p);
622 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
623 memcpy(p, &mParamVideoRefresh, sizeof(*p));
624 return OMX_ErrorNone;
625 }
626
SetParamVideoIntraRefresh(OMX_PTR pStructure)627 OMX_ERRORTYPE OMXVideoEncoderBase::SetParamVideoIntraRefresh(OMX_PTR pStructure) {
628 OMX_ERRORTYPE ret;
629 Encode_Status retStatus = ENCODE_SUCCESS;
630
631 OMX_VIDEO_PARAM_INTRAREFRESHTYPE *p = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)pStructure;
632 CHECK_TYPE_HEADER(p);
633 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
634
635 // set in either Loaded state (ComponentSetParam) or Executing state (ComponentSetConfig)
636 mParamVideoRefresh = *p;
637
638 // return OMX_ErrorNone if not in Executing state
639 // TODO: return OMX_ErrorIncorrectStateOperation?
640 CHECK_SET_PARAM_STATE();
641
642 VideoConfigIntraRefreshType configIntraRefreshType;
643 configIntraRefreshType.refreshType = (VideoIntraRefreshType)(mParamVideoRefresh.eRefreshMode + 1);
644 if(configIntraRefreshType.refreshType == VIDEO_ENC_CIR){
645 VideoConfigCIR configCIR;
646 VideoConfigIntraRefreshType configIntraRefreshType;
647 configCIR.cirParams.cir_num_mbs = mParamVideoRefresh.nCirMBs;
648 configIntraRefreshType.refreshType = VIDEO_ENC_CIR;
649
650 retStatus = mVideoEncoder->setConfig(&configCIR);
651 if(retStatus != ENCODE_SUCCESS) {
652 LOGW("Failed to set CIR config");
653 }
654 }else{
655 VideoConfigAIR configAIR;
656
657 configAIR.airParams.airMBs = mParamVideoRefresh.nAirMBs;
658 configAIR.airParams.airThreshold = mParamVideoRefresh.nAirRef;
659
660 retStatus = mVideoEncoder->setConfig(&configAIR);
661 if(retStatus != ENCODE_SUCCESS) {
662 LOGW("Failed to set AIR config");
663 }
664
665 }
666
667 retStatus = mVideoEncoder->setConfig(&configIntraRefreshType);
668 if(retStatus != ENCODE_SUCCESS) {
669 LOGW("Failed to set refresh config");
670 }
671
672 return OMX_ErrorNone;
673 }
674
GetConfigVideoFramerate(OMX_PTR pStructure)675 OMX_ERRORTYPE OMXVideoEncoderBase::GetConfigVideoFramerate(OMX_PTR pStructure) {
676 OMX_ERRORTYPE ret;
677 OMX_CONFIG_FRAMERATETYPE *p = (OMX_CONFIG_FRAMERATETYPE *)pStructure;
678
679 CHECK_TYPE_HEADER(p);
680 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
681 memcpy(p, &mConfigFramerate, sizeof(*p));
682 return OMX_ErrorNone;
683 }
684
SetConfigVideoFramerate(OMX_PTR pStructure)685 OMX_ERRORTYPE OMXVideoEncoderBase::SetConfigVideoFramerate(OMX_PTR pStructure) {
686 OMX_ERRORTYPE ret;
687 Encode_Status retStatus = ENCODE_SUCCESS;
688 if (mParamBitrate.eControlRate == OMX_Video_ControlRateMax){
689 LOGE("SetConfigVideoFramerate failed. Feature is disabled.");
690 return OMX_ErrorUnsupportedIndex;
691 }
692 OMX_CONFIG_FRAMERATETYPE *p = (OMX_CONFIG_FRAMERATETYPE *)pStructure;
693 CHECK_TYPE_HEADER(p);
694 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
695
696 // set in either Loaded state (ComponentSetParam) or Executing state (ComponentSetConfig)
697 mConfigFramerate = *p;
698
699 // return OMX_ErrorNone if not in Executing state
700 // TODO, return OMX_ErrorIncorrectStateOperation?
701 CHECK_SET_CONFIG_STATE();
702
703 VideoConfigFrameRate framerate;
704 framerate.frameRate.frameRateDenom = 1;
705 framerate.frameRate.frameRateNum = mConfigFramerate.xEncodeFramerate >> 16;
706 retStatus = mVideoEncoder->setConfig(&framerate);
707 if(retStatus != ENCODE_SUCCESS) {
708 LOGW("Failed to set frame rate config");
709 }
710 return OMX_ErrorNone;
711 }
712
GetConfigVideoIntraVOPRefresh(OMX_PTR)713 OMX_ERRORTYPE OMXVideoEncoderBase::GetConfigVideoIntraVOPRefresh(OMX_PTR) {
714 LOGW("GetConfigVideoIntraVOPRefresh is not supported.");
715 return OMX_ErrorUnsupportedSetting;
716 }
717
SetConfigVideoIntraVOPRefresh(OMX_PTR pStructure)718 OMX_ERRORTYPE OMXVideoEncoderBase::SetConfigVideoIntraVOPRefresh(OMX_PTR pStructure) {
719 OMX_ERRORTYPE ret;
720 Encode_Status retStatus = ENCODE_SUCCESS;
721 OMX_CONFIG_INTRAREFRESHVOPTYPE *p = (OMX_CONFIG_INTRAREFRESHVOPTYPE *)pStructure;
722 CHECK_TYPE_HEADER(p);
723 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
724
725 // return OMX_ErrorNone if not in Executing state
726 // TODO: return OMX_ErrorIncorrectStateOperation?
727 CHECK_SET_CONFIG_STATE();
728
729 if(p->IntraRefreshVOP == OMX_TRUE) {
730 VideoParamConfigSet configIDRRequest;
731 configIDRRequest.type = VideoConfigTypeIDRRequest;
732 retStatus = mVideoEncoder->setConfig(&configIDRRequest);
733 if(retStatus != ENCODE_SUCCESS) {
734 LOGW("Failed to set refresh config");
735 }
736 }
737
738 return OMX_ErrorNone;
739 }
740
GetParamIntelAdaptiveSliceControl(OMX_PTR pStructure)741 OMX_ERRORTYPE OMXVideoEncoderBase::GetParamIntelAdaptiveSliceControl(OMX_PTR pStructure) {
742
743 OMX_ERRORTYPE ret;
744 OMX_VIDEO_PARAM_INTEL_ADAPTIVE_SLICE_CONTROL *p = (OMX_VIDEO_PARAM_INTEL_ADAPTIVE_SLICE_CONTROL *)pStructure;
745
746 CHECK_TYPE_HEADER(p);
747 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
748 memcpy(p, &mParamIntelAdaptiveSliceControl, sizeof(*p));
749
750 return OMX_ErrorNone;
751 }
752
SetParamIntelAdaptiveSliceControl(OMX_PTR pStructure)753 OMX_ERRORTYPE OMXVideoEncoderBase::SetParamIntelAdaptiveSliceControl(OMX_PTR pStructure) {
754
755 OMX_ERRORTYPE ret;
756 if (mParamBitrate.eControlRate == OMX_Video_ControlRateMax) {
757 LOGE("SetParamIntelAdaptiveSliceControl failed. Feature is disabled.");
758 return OMX_ErrorUnsupportedIndex;
759 }
760 OMX_VIDEO_PARAM_INTEL_ADAPTIVE_SLICE_CONTROL *p = (OMX_VIDEO_PARAM_INTEL_ADAPTIVE_SLICE_CONTROL *)pStructure;
761 CHECK_TYPE_HEADER(p);
762 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
763
764 // set only in Loaded state (ComponentSetParam)
765 CHECK_SET_PARAM_STATE();
766
767 mParamIntelAdaptiveSliceControl = *p;
768
769 return OMX_ErrorNone;
770 }
771
772 /*
773 OMX_ERRORTYPE OMXVideoEncoderBase::GetParamVideoProfileLevelQuerySupported(OMX_PTR pStructure) {
774 OMX_ERRORTYPE ret;
775 OMX_VIDEO_PARAM_PROFILELEVELTYPE *p = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pStructure;
776
777 CHECK_TYPE_HEADER(p);
778 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
779
780 // assign values instead of memory coping to avoid nProfileIndex being overridden
781 p->eProfile = mParamProfileLevel.eProfile;
782 p->eLevel = mParamProfileLevel.eLevel;
783
784 return OMX_ErrorNone;
785 }
786
787 OMX_ERRORTYPE OMXVideoEncoderBase::SetParamVideoProfileLevelQuerySupported(OMX_PTR pStructure) {
788 LOGW("SetParamVideoProfileLevelQuerySupported is not supported.");
789 return OMX_ErrorUnsupportedSetting;
790 }
791 */
792
GetStoreMetaDataInBuffers(OMX_PTR pStructure)793 OMX_ERRORTYPE OMXVideoEncoderBase::GetStoreMetaDataInBuffers(OMX_PTR pStructure) {
794 OMX_ERRORTYPE ret;
795 StoreMetaDataInBuffersParams *p = (StoreMetaDataInBuffersParams *)pStructure;
796
797 CHECK_TYPE_HEADER(p);
798 CHECK_PORT_INDEX(p, INPORT_INDEX);
799
800 p->bStoreMetaData = mStoreMetaDataInBuffers;
801
802 return OMX_ErrorNone;
803 };
SetStoreMetaDataInBuffers(OMX_PTR pStructure)804 OMX_ERRORTYPE OMXVideoEncoderBase::SetStoreMetaDataInBuffers(OMX_PTR pStructure) {
805 OMX_ERRORTYPE ret;
806 StoreMetaDataInBuffersParams *p = (StoreMetaDataInBuffersParams *)pStructure;
807 VideoParamsStoreMetaDataInBuffers StoreMetaDataInBuffers;
808 PortVideo *port = static_cast<PortVideo *>(this->ports[INPORT_INDEX]);
809 PortVideo *output_port = static_cast<PortVideo *>(this->ports[OUTPORT_INDEX]);
810 uint32_t maxSize = 0;
811
812 CHECK_TYPE_HEADER(p);
813 CHECK_PORT_INDEX(p, INPORT_INDEX);
814
815 LOGD("SetStoreMetaDataInBuffers (enabled = %x)", p->bStoreMetaData);
816 if(mStoreMetaDataInBuffers == p->bStoreMetaData)
817 return OMX_ErrorNone;
818
819 StoreMetaDataInBuffers.isEnabled = p->bStoreMetaData;
820 if (mVideoEncoder->setParameters(&StoreMetaDataInBuffers) != ENCODE_SUCCESS)
821 return OMX_ErrorNotReady;
822
823 mStoreMetaDataInBuffers = p->bStoreMetaData;
824
825 if(mStoreMetaDataInBuffers){
826 // for input port buffer
827 OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput;
828 const OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput_get;
829
830 paramPortDefinitionInput_get = port->GetPortDefinition();
831 paramPortDefinitionInput = (OMX_PARAM_PORTDEFINITIONTYPE *)paramPortDefinitionInput_get;
832 paramPortDefinitionInput->nBufferSize = IntelMetadataBuffer::GetMaxBufferSize();
833 }
834 else
835 {
836 const OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput_get;
837
838 paramPortDefinitionInput_get = port->GetPortDefinition();
839 port->SetPortDefinition(paramPortDefinitionInput_get, true);
840 }
841
842 LOGD("SetStoreMetaDataInBuffers success");
843 return OMX_ErrorNone;
844 };
845
GetSyncEncoding(OMX_PTR pStructure)846 OMX_ERRORTYPE OMXVideoEncoderBase::GetSyncEncoding(OMX_PTR pStructure) {
847 OMX_BOOL* syncEncoding = static_cast<OMX_BOOL*>(pStructure);
848
849 *syncEncoding = mSyncEncoding;
850
851 return OMX_ErrorNone;
852 };
853
SetSyncEncoding(OMX_PTR pStructure)854 OMX_ERRORTYPE OMXVideoEncoderBase::SetSyncEncoding(OMX_PTR pStructure) {
855 CHECK_SET_PARAM_STATE();
856
857 mSyncEncoding = *(static_cast<OMX_BOOL*>(pStructure));
858
859 LOGD("SetSyncEncoding %d", mSyncEncoding);
860
861 return OMX_ErrorNone;
862 };
863
GetPrependSPSPPS(OMX_PTR)864 OMX_ERRORTYPE OMXVideoEncoderBase::GetPrependSPSPPS(OMX_PTR) {
865 return OMX_ErrorNone;
866 };
867
SetPrependSPSPPS(OMX_PTR)868 OMX_ERRORTYPE OMXVideoEncoderBase::SetPrependSPSPPS(OMX_PTR) {
869 LOGD("SetPrependSPSPPS success");
870 return OMX_ErrorNone;
871 };
872
GetTemporalLayer(OMX_PTR pStructure)873 OMX_ERRORTYPE OMXVideoEncoderBase::GetTemporalLayer(OMX_PTR pStructure) {
874 OMX_ERRORTYPE ret;
875 OMX_VIDEO_PARAM_INTEL_TEMPORAL_LAYER* p = static_cast<OMX_VIDEO_PARAM_INTEL_TEMPORAL_LAYER*>(pStructure);
876
877 CHECK_TYPE_HEADER(p);
878 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
879 memcpy(p, &mTemporalLayer, sizeof(*p));
880 return OMX_ErrorNone;
881 }
882
SetTemporalLayer(OMX_PTR pStructure)883 OMX_ERRORTYPE OMXVideoEncoderBase::SetTemporalLayer(OMX_PTR pStructure) {
884 OMX_ERRORTYPE ret;
885 OMX_VIDEO_PARAM_INTEL_TEMPORAL_LAYER *p = (OMX_VIDEO_PARAM_INTEL_TEMPORAL_LAYER *)pStructure;
886 VideoParamsTemporalLayer TemporalLayer;
887 OMX_U32 i;
888
889 CHECK_TYPE_HEADER(p);
890 CHECK_PORT_INDEX(p, OUTPORT_INDEX);
891
892 LOGE("SetTemporalLayer (enabled = %d)", p->nNumberOfTemporalLayer);
893
894 TemporalLayer.numberOfLayer = p->nNumberOfTemporalLayer;
895 TemporalLayer.nPeriodicity = p->nPeriodicity;
896 for(i=0;i<p->nPeriodicity;i++)
897 TemporalLayer.nLayerID[i] = p->nLayerID[i];
898
899 if (mVideoEncoder->setParameters(&TemporalLayer) != ENCODE_SUCCESS)
900 return OMX_ErrorNotReady;
901
902 LOGE("SetTemporalLayer success");
903 return OMX_ErrorNone;
904 }
905
GetBlackFramePointer(OMX_PTR pStructure)906 OMX_ERRORTYPE OMXVideoEncoderBase::GetBlackFramePointer(OMX_PTR pStructure) {
907 OMX_ERRORTYPE ret;
908 OMX_VIDEO_INTEL_REQUEST_BALCK_FRAME_POINTER *p = (OMX_VIDEO_INTEL_REQUEST_BALCK_FRAME_POINTER *)pStructure;
909
910 CHECK_TYPE_HEADER(p);
911 CHECK_PORT_INDEX(p, INPORT_INDEX);
912
913 PortVideo *port_in = static_cast<PortVideo *>(ports[INPORT_INDEX]);
914 const OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput = port_in->GetPortDefinition();
915 OMX_U32 width = paramPortDefinitionInput->format.video.nFrameWidth;
916 OMX_U32 height = paramPortDefinitionInput->format.video.nFrameHeight;
917 OMX_U32 lumaSize = width * height;
918 OMX_U32 bufferSize = width * height * 3 / 2;
919
920 if(mBlackFramePointer) {
921 free(mBlackFramePointer);
922 mBlackFramePointer = NULL;
923 } else {
924 mBlackFramePointer = (OMX_PTR)memalign(4096, bufferSize); // align to page size
925 if(!mBlackFramePointer) {
926 return OMX_ErrorInsufficientResources;
927 }
928 memset(mBlackFramePointer, 0x0, lumaSize);
929 memset((OMX_PTR)((uint64_t)mBlackFramePointer + lumaSize), 0x80, lumaSize / 2);
930 p->nFramePointer = (OMX_U32)mBlackFramePointer;
931 }
932 return OMX_ErrorNone;
933 }
934
SetBlackFramePointer(OMX_PTR)935 OMX_ERRORTYPE OMXVideoEncoderBase::SetBlackFramePointer(OMX_PTR) {
936 return OMX_ErrorUnsupportedSetting;
937 }
938