Android Camera OMXCameraAdapter.cpp初始化分析
2019-07-13 20:16发布
生成海报
这几天一直在研究android 的omx机制,我针对的android是4.0.3,主要是TI 的4430,4460的omx方式实现,这里还是简单的说一下为什么要研究这个文件
之前有一篇文章已经比较详细的说过了OMAP4系列芯片了,这里这个OMXCameraAdapter其实就是omap4 A9端的omx client,通过这个client与ducati端(也就是omap4的DSP端)的omx进行通信,可以把ducati端的这个omx简单理解为omx servicer,之前已经说了很多了andriod camera了,但是之前文章都是针对V4LCameraAdapter这个适配器进行的,这是大家都比较了解的,就是app通过V4L2这种方式与kernel
camera driver实现交互,进而实现camera 的使用,包括数据回调等过程,但是这里的OMX方法完全颠覆了我之前的想法,开始在研究OMX的时候自己就是调用这个死胡同里了,一直在试图在OMX的实现中找到他到底是在哪么访问设备的,本来我是以后最终他还是通过V4L2这种方式,事实证明我错了,OMX是一种完全不同于V4L2 的访问camera的策略,他通过A9端的omx client和DSP端的omx通信,而且最终访问camera的方法是在DSP端omx server接到到A9端的omx client配置后按照指定方法实现camera
的控制的,这里ducati端到底是怎么处理的我暂时没有关注,暂时精力有限啊!
以上是我自己的见解,也许是完全错误的,待确认,这里只是总结我的分析过程
经过上面我的概述,自然A9端的这个OMXCameraAdapter对于我来说就是一切了,分析它是必经之路啊
现在就开始:
首先要知道在哪里实例化了这个类的对象,这个在之前已经说到过了,这个不在说明,重点看看他的initialize方法都干了些甚么?
-
/*--------------------Camera
Adapter Class STARTS here-----------------------------*/
-
-
status_t OMXCameraAdapter::initialize(CameraProperties::Properties* caps)
-
{
-
LOG_FUNCTION_NAME;
-
-
char value[PROPERTY_VALUE_MAX];
-
const char *mountOrientationString = NULL;
-
-
property_get("debug.camera.showfps", value, "0");
-
mDebugFps = atoi(value);
-
property_get("debug.camera.framecounts", value, "0");
-
mDebugFcs = atoi(value);
-
-
#ifdef CAMERAHAL_OMX_PROFILING
-
-
property_get("debug.camera.profile", value, "0");
-
mDebugProfile = atoi(value);
-
-
#endif
-
-
TIMM_OSAL_ERRORTYPE osalError = OMX_ErrorNone;
-
OMX_ERRORTYPE eError = OMX_ErrorNone;
-
status_t ret = NO_ERROR;
-
-
mLocalVersionParam.s.nVersionMajor = 0x1;
-
mLocalVersionParam.s.nVersionMinor = 0x1;
-
mLocalVersionParam.s.nRevision = 0x0 ;
-
mLocalVersionParam.s.nStep = 0x0;
-
-
mPending3Asettings = 0;//E3AsettingsAll;
-
mPendingCaptureSettings = 0;
-
mPendingPreviewSettings = 0;
-
-
if ( 0 != mInitSem.Count() )
-
{
-
CAMHAL_LOGEB("Error mInitSem semaphore count %d", mInitSem.Count());
-
LOG_FUNCTION_NAME_EXIT;
-
return NO_INIT;
-
}
-
-
///Update the preview and image
capture port indexes
-
mCameraAdapterParameters.mPrevPortIndex = OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW;
-
// temp changed in order to build
OMX_CAMERA_PORT_VIDEO_OUT_IMAGE;
-
mCameraAdapterParameters.mImagePortIndex = OMX_CAMERA_PORT_IMAGE_OUT_IMAGE;
-
mCameraAdapterParameters.mMeasurementPortIndex = OMX_CAMERA_PORT_VIDEO_OUT_MEASUREMENT;
-
//currently not supported use preview port instead
-
mCameraAdapterParameters.mVideoPortIndex = OMX_CAMERA_PORT_VIDEO_OUT_VIDEO;
-
mCameraAdapterParameters.mVideoInPortIndex = OMX_CAMERA_PORT_VIDEO_IN_VIDEO;
-
// 1.OMX_Init
-
eError = OMX_Init();
-
if (eError != OMX_ErrorNone) {
-
CAMHAL_LOGEB("OMX_Init() failed, error: 0x%x", eError);
-
return ErrorUtils::omxToAndroidError(eError);
-
}
-
mOmxInitialized = true;
-
-
// 2.Initialize
the callback handles
-
OMX_CALLBACKTYPE callbacks;
-
callbacks.EventHandler = android::OMXCameraAdapterEventHandler;
-
callbacks.EmptyBufferDone = android::OMXCameraAdapterEmptyBufferDone;
-
callbacks.FillBufferDone = android::OMXCameraAdapterFillBufferDone;
-
-
// 3.Get the
handle to the OMX Component
-
eError = OMXCameraAdapter::OMXCameraGetHandle(&mCameraAdapterParameters.mHandleComp, this, callbacks);
-
if(eError != OMX_ErrorNone) {
-
CAMHAL_LOGEB("OMX_GetHandle -0x%x", eError);
-
}
-
GOTO_EXIT_IF((eError != OMX_ErrorNone), eError);
-
-
// 4.设置component的初始状态
-
mComponentState = OMX_StateLoaded;
-
-
CAMHAL_LOGVB("OMX_GetHandle -0x%x sensor_index = %lu", eError, mSensorIndex);
-
initDccFileDataSave(&mCameraAdapterParameters.mHandleComp, mCameraAdapterParameters.mPrevPortIndex);
-
-
// 5.disable所以的component
-
eError = OMX_SendCommand(mCameraAdapterParameters.mHandleComp,
-
OMX_CommandPortDisable,
-
OMX_ALL,
-
NULL);
-
-
if(eError != OMX_ErrorNone) {
-
CAMHAL_LOGEB("OMX_SendCommand(OMX_CommandPortDisable) -0x%x", eError);
-
}
-
GOTO_EXIT_IF((eError != OMX_ErrorNone), eError);
-
-
// 6.Register for port
enable event
-
ret = RegisterForEvent(mCameraAdapterParameters.mHandleComp,
-
OMX_EventCmdComplete,
-
OMX_CommandPortEnable,
-
mCameraAdapterParameters.mPrevPortIndex,
-
mInitSem);
-
if(ret != NO_ERROR) {
-
CAMHAL_LOGEB("Error in registering for event %d", ret);
-
goto EXIT;
-
}
-
-
// 7.Enable
PREVIEW Port
-
eError = OMX_SendCommand(mCameraAdapterParameters.mHandleComp,
-
OMX_CommandPortEnable,
-
mCameraAdapterParameters.mPrevPortIndex,
-
NULL);
-
if(eError != OMX_ErrorNone) {
-
CAMHAL_LOGEB("OMX_SendCommand(OMX_CommandPortEnable) -0x%x", eError);
-
}
-
GOTO_EXIT_IF((eError!=OMX_ErrorNone), eError);
-
-
// 8.Wait for the
port enable event to occur
-
ret = mInitSem.WaitTimeout(OMX_CMD_TIMEOUT);
-
if ( NO_ERROR == ret ) {
-
CAMHAL_LOGDA("-Port enable event arrived");
-
} else {
-
ret |= RemoveEvent(mCameraAdapterParameters.mHandleComp,
-
OMX_EventCmdComplete,
-
OMX_CommandPortEnable,
-
mCameraAdapterParameters.mPrevPortIndex,
-
NULL);
-
CAMHAL_LOGEA("Timeout for enabling preview port expired!");
-
goto EXIT;
-
}
-
-
// 9.Select the
sensor
-
OMX_CONFIG_SENSORSELECTTYPE sensorSelect;
-
OMX_INIT_STRUCT_PTR (&sensorSelect, OMX_CONFIG_SENSORSELECTTYPE);
-
sensorSelect.eSensor = (OMX_SENSORSELECT) mSensorIndex;
-
eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, ( OMX_INDEXTYPE ) OMX_TI_IndexConfigSensorSelect, &sensorSelect);
-
if ( OMX_ErrorNone != eError ) {
-
CAMHAL_LOGEB("Error while selecting the sensor index as %d - 0x%x", mSensorIndex, eError);
-
return BAD_VALUE;
-
} else {
-
CAMHAL_LOGDB("Sensor %d selected successfully", mSensorIndex);
-
}
-
-
#ifdef CAMERAHAL_DEBUG
-
-
printComponentVersion(mCameraAdapterParameters.mHandleComp);
-
-
#endif
-
//
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮