summaryrefslogtreecommitdiffstats
path: root/camera/CameraHal.cpp
diff options
context:
space:
mode:
authorAnu Sundararajan <sanuradha@ti.com>2012-03-27 20:53:42 -0500
committerDaniel Levin <dendy@ti.com>2012-07-25 08:56:18 -0500
commit620c8e83d379416aee21b17ff2e48b2ac721e331 (patch)
treedebb2d1833a079dd2d643f2f43cf4a6f7dd69a64 /camera/CameraHal.cpp
parent48026da3e66b50b57108b997864b152bf5b2df30 (diff)
downloadhardware_ti_omap4-620c8e83d379416aee21b17ff2e48b2ac721e331.zip
hardware_ti_omap4-620c8e83d379416aee21b17ff2e48b2ac721e331.tar.gz
hardware_ti_omap4-620c8e83d379416aee21b17ff2e48b2ac721e331.tar.bz2
CameraHal: Changes necessitated by slice based processing
Slice based processing requires a tunnel to be set up between camera and encoder. Because of tunneling, the OMX state transtion must happen in a particular order. Therefore, new commands have been added to allow the application to control the state transition. Existing cameraHal clients like CameraService need not do anything different. Initialization: --------------- Application creates an instance of the camera. At this point, camera is in loaded state. Application calls setParameter(sliceheight/encoder handle) to set up the tunnel and slice parameters. Application calls sendCommand(CAMERA_CMD_PREVIEW_INITIALIZATION, ...) to move the camera to idle state. Application calls startPreview() to move the camera to executing state. Deinitialization: ----------------- Application calls sendCommand(CAMERA_CMD_PREVIEW_DEINITIALIZATION, ...) to move the camera to idle state. Application calls stopPreview() to move the camera to loaded state. If the application does not call sendCommand(CAMERA_CMD_PREVIEW_INITIALIZATION, ...), then during startPreview, the camera moves from loaded to idle to executing like before. Similarly, if the application does not call sendCommand(CAMERA_CMD_PREVIEW_DEINITIALIZATION, ...)then during stopPreview, the camera moves from executing to idle to loaded like before. Disabling the preview port and freeing the buffers caused ducati to go into a bad state. This issue is observed only during slice mode. Therefore, preview port disable/enable has been removed and the preview buffers are now freed when moving from idle to loaded state. Change-Id: I7039c854f1358c22b6f5e116dcadfd025185bee1 Signed-off-by: Prasanna Kumar M.R. <prasanna.kumarmr@ti.com> Signed-off-by: Anu Sundararajan <sanuradha@ti.com>
Diffstat (limited to 'camera/CameraHal.cpp')
-rw-r--r--camera/CameraHal.cpp235
1 files changed, 176 insertions, 59 deletions
diff --git a/camera/CameraHal.cpp b/camera/CameraHal.cpp
index dfd4fc9..d1667b2 100644
--- a/camera/CameraHal.cpp
+++ b/camera/CameraHal.cpp
@@ -341,6 +341,26 @@ int CameraHal::setParameters(const CameraParameters& params)
}
}
+ if ((valstr = params.get(TICameraParameters::KEY_VTC_HINT)) != NULL ) {
+ mParameters.set(TICameraParameters::KEY_VTC_HINT, valstr);
+ if (strcmp(valstr, CameraParameters::TRUE) == 0) {
+ mVTCUseCase = true;
+ } else {
+ mVTCUseCase = false;
+ }
+ CAMHAL_LOGDB("VTC Hint = %d", mVTCUseCase);
+ }
+
+ if (mVTCUseCase) {
+ if ((valstr = params.get(TICameraParameters::KEY_VIDEO_ENCODER_HANDLE)) != NULL ) {
+ mParameters.set(TICameraParameters::KEY_VIDEO_ENCODER_HANDLE, valstr);
+ }
+
+ if ((valstr = params.get(TICameraParameters::KEY_VIDEO_ENCODER_SLICE_HEIGHT)) != NULL ) {
+ mParameters.set(TICameraParameters::KEY_VIDEO_ENCODER_SLICE_HEIGHT, valstr);
+ }
+ }
+
}
if ( (valstr = params.get(TICameraParameters::KEY_S3D_PRV_FRAME_LAYOUT)) != NULL )
@@ -407,11 +427,11 @@ int CameraHal::setParameters(const CameraParameters& params)
mVideoWidth = w;
mVideoHeight = h;
CAMHAL_LOGVB("%s Video Width=%d Height=%d\n", __FUNCTION__, mVideoWidth, mVideoHeight);
-
- restartPreviewRequired = setPreferredPreviewRes(params, w, h);
- mParameters.getPreviewSize(&w, &h);
- CAMHAL_LOGVB("%s Preview Width=%d Height=%d\n", __FUNCTION__, w, h);
-
+ if (!mVTCUseCase) {
+ restartPreviewRequired = setPreferredPreviewRes(params, w, h);
+ mParameters.getPreviewSize(&w, &h);
+ CAMHAL_LOGVB("%s Preview Width=%d Height=%d\n", __FUNCTION__, w, h);
+ }
restartPreviewRequired |= setVideoModeParameters(params);
}
else if(strcmp(valstr, CameraParameters::FALSE) == 0)
@@ -1029,6 +1049,19 @@ int CameraHal::setParameters(const CameraParameters& params)
mParameters.remove(TICameraParameters::KEY_TEMP_BRACKETING);
}
+ if (mVTCUseCase && !mTunnelSetup && (mCameraAdapter != NULL) &&
+ ((mParameters.get(TICameraParameters::KEY_VIDEO_ENCODER_HANDLE)) != NULL )&&
+ ((mParameters.get(TICameraParameters::KEY_VIDEO_ENCODER_SLICE_HEIGHT)) != NULL )) {
+
+ uint32_t sliceHeight = mParameters.getInt(TICameraParameters::KEY_VIDEO_ENCODER_SLICE_HEIGHT);
+ uint32_t encoderHandle = mParameters.getInt(TICameraParameters::KEY_VIDEO_ENCODER_HANDLE);
+ int w, h;
+ mParameters.getPreviewSize(&w, &h);
+ status_t done = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_SETUP_TUNNEL, sliceHeight, encoderHandle, w, h);
+ if (done == NO_ERROR) mTunnelSetup = true;
+ ret |= done;
+ }
+
// Only send parameters to adapter if preview is already
// enabled or doesSetParameterNeedUpdate says so. Initial setParameters to camera adapter,
// will be called in startPreview()
@@ -1505,13 +1538,115 @@ status_t CameraHal::freeRawBufs()
@todo Update function header with the different errors that are possible
*/
-status_t CameraHal::startPreview()
+status_t CameraHal::startPreview() {
+ // When tunneling is enabled during VTC, startPreview happens in 2 steps:
+ // When the application sends the command CAMERA_CMD_PREVIEW_INITIALIZATION,
+ // cameraPreviewInitialization() is called, which in turn causes the CameraAdapter
+ // to move from loaded to idle state. And when the application calls startPreview,
+ // the CameraAdapter moves from idle to executing state.
+ //
+ // If the application calls startPreview() without sending the command
+ // CAMERA_CMD_PREVIEW_INITIALIZATION, then the function cameraPreviewInitialization()
+ // AND startPreview() are executed. In other words, if the application calls
+ // startPreview() without sending the command CAMERA_CMD_PREVIEW_INITIALIZATION,
+ // then the CameraAdapter moves from loaded to idle to executing state in one shot.
+ status_t ret = cameraPreviewInitialization();
+
+ // The flag mPreviewInitializationDone is set to true at the end of the function
+ // cameraPreviewInitialization(). Therefore, if everything goes alright, then the
+ // flag will be set. Sometimes, the function cameraPreviewInitialization() may
+ // return prematurely if all the resources are not available for starting preview.
+ // For example, if the preview window is not set, then it would return NO_ERROR.
+ // Under such circumstances, one should return from startPreview as well and should
+ // not continue execution. That is why, we check the flag and not the return value.
+ if (!mPreviewInitializationDone) return ret;
+
+ // Once startPreview is called, there is no need to continue to remember whether
+ // the function cameraPreviewInitialization() was called earlier or not. And so
+ // the flag mPreviewInitializationDone is reset here. Plus, this preserves the
+ // current behavior of startPreview under the circumstances where the application
+ // calls startPreview twice or more.
+ mPreviewInitializationDone = false;
+
+ ///Enable the display adapter if present, actual overlay enable happens when we post the buffer
+ if(mDisplayAdapter.get() != NULL) {
+ CAMHAL_LOGDA("Enabling display");
+ int width, height;
+ mParameters.getPreviewSize(&width, &height);
+
+#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
+ ret = mDisplayAdapter->enableDisplay(width, height, &mStartPreview);
+#else
+ ret = mDisplayAdapter->enableDisplay(width, height, NULL);
+#endif
+
+ if ( ret != NO_ERROR ) {
+ CAMHAL_LOGEA("Couldn't enable display");
+
+ // FIXME: At this stage mStateSwitchLock is locked and unlock is supposed to be called
+ // only from mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_PREVIEW)
+ // below. But this will never happen because of goto error. Thus at next
+ // startPreview() call CameraHAL will be deadlocked.
+ // Need to revisit mStateSwitch lock, for now just abort the process.
+ CAMHAL_ASSERT_X(false,
+ "At this stage mCameraAdapter->mStateSwitchLock is still locked, "
+ "deadlock is guaranteed");
+
+ goto error;
+ }
+
+ }
+
+ ///Send START_PREVIEW command to adapter
+ CAMHAL_LOGDA("Starting CameraAdapter preview mode");
+
+ ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_PREVIEW);
+
+ if(ret!=NO_ERROR) {
+ CAMHAL_LOGEA("Couldn't start preview w/ CameraAdapter");
+ goto error;
+ }
+ CAMHAL_LOGDA("Started preview");
+
+ mPreviewEnabled = true;
+ mPreviewStartInProgress = false;
+ return ret;
+
+ error:
+
+ CAMHAL_LOGEA("Performing cleanup after error");
+
+ //Do all the cleanup
+ freePreviewBufs();
+ mCameraAdapter->sendCommand(CameraAdapter::CAMERA_STOP_PREVIEW);
+ if(mDisplayAdapter.get() != NULL) {
+ mDisplayAdapter->disableDisplay(false);
+ }
+ mAppCallbackNotifier->stop();
+ mPreviewStartInProgress = false;
+ mPreviewEnabled = false;
+ LOG_FUNCTION_NAME_EXIT;
+
+ return ret;
+}
+
+////////////
+/**
+ @brief Set preview mode related initialization
+ -> Camera Adapter set params
+ -> Allocate buffers
+ -> Set use buffers for preview
+ @param none
+ @return NO_ERROR
+ @todo Update function header with the different errors that are possible
+
+ */
+status_t CameraHal::cameraPreviewInitialization()
{
status_t ret = NO_ERROR;
CameraAdapter::BuffersDescriptor desc;
CameraFrame frame;
- const char *valstr = NULL;
unsigned int required_buffer_count;
unsigned int max_queueble_buffers;
@@ -1521,6 +1656,10 @@ status_t CameraHal::startPreview()
LOG_FUNCTION_NAME;
+ if (mPreviewInitializationDone) {
+ return NO_ERROR;
+ }
+
if ( mPreviewEnabled ){
CAMHAL_LOGDA("Preview already running");
LOG_FUNCTION_NAME_EXIT;
@@ -1666,55 +1805,7 @@ status_t CameraHal::startPreview()
goto error;
}
- ///Enable the display adapter if present, actual overlay enable happens when we post the buffer
- if(mDisplayAdapter.get() != NULL)
- {
- CAMHAL_LOGDA("Enabling display");
- int width, height;
- mParameters.getPreviewSize(&width, &height);
-
-#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS
-
- ret = mDisplayAdapter->enableDisplay(width, height, &mStartPreview);
-
-#else
-
- ret = mDisplayAdapter->enableDisplay(width, height, NULL);
-
-#endif
-
- if ( ret != NO_ERROR )
- {
- CAMHAL_LOGEA("Couldn't enable display");
-
- // FIXME: At this stage mStateSwitchLock is locked and unlock is supposed to be called
- // only from mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_PREVIEW)
- // below. But this will never happen because of goto error. Thus at next
- // startPreview() call CameraHAL will be deadlocked.
- // Need to revisit mStateSwitch lock, for now just abort the process.
- CAMHAL_ASSERT_X(false,
- "At this stage mCameraAdapter->mStateSwitchLock is still locked, "
- "deadlock is guaranteed");
-
- goto error;
- }
-
- }
-
- ///Send START_PREVIEW command to adapter
- CAMHAL_LOGDA("Starting CameraAdapter preview mode");
-
- ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_START_PREVIEW);
-
- if(ret!=NO_ERROR)
- {
- CAMHAL_LOGEA("Couldn't start preview w/ CameraAdapter");
- goto error;
- }
- CAMHAL_LOGDA("Started preview");
-
- mPreviewEnabled = true;
- mPreviewStartInProgress = false;
+ if (ret == NO_ERROR) mPreviewInitializationDone = true;
return ret;
error:
@@ -2800,11 +2891,11 @@ status_t CameraHal::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
return -EINVAL;
}
- if ( ( NO_ERROR == ret ) && ( !previewEnabled() ))
- {
+ if ( ( NO_ERROR == ret ) && ( !previewEnabled() ) &&
+ (cmd != CAMERA_CMD_PREVIEW_INITIALIZATION)) {
CAMHAL_LOGEA("Preview is not running");
ret = -EINVAL;
- }
+ }
if ( NO_ERROR == ret )
{
@@ -2832,6 +2923,29 @@ status_t CameraHal::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
break;
+ case CAMERA_CMD_PREVIEW_DEINITIALIZATION:
+ if(mDisplayAdapter.get() != NULL) {
+ ///Stop the buffer display first
+ mDisplayAdapter->disableDisplay();
+ }
+
+ if(mAppCallbackNotifier.get() != NULL) {
+ //Stop the callback sending
+ mAppCallbackNotifier->stop();
+ mAppCallbackNotifier->flushAndReturnFrames();
+ mAppCallbackNotifier->stopPreviewCallbacks();
+ }
+
+ ret = mCameraAdapter->sendCommand(CameraAdapter::CAMERA_DESTROY_TUNNEL);
+ mTunnelSetup = false;
+
+ break;
+
+ case CAMERA_CMD_PREVIEW_INITIALIZATION:
+ ret = cameraPreviewInitialization();
+
+ break;
+
default:
break;
};
@@ -2943,6 +3057,9 @@ CameraHal::CameraHal(int cameraId)
mSensorListener = NULL;
mVideoWidth = 0;
mVideoHeight = 0;
+ mVTCUseCase = false;
+ mTunnelSetup = false;
+ mPreviewInitializationDone = false;
//These values depends on the sensor characteristics