Native camera issue on HTC One S fixed.

Camera connect->disconnect->connect leads to sigsegv.
Apply properties method reimplemented.
(cherry picked from commit 710e070990ac2375a1a450c2d215eb68f15139e5)
This commit is contained in:
Alexander Smorkalov 2012-09-07 12:43:45 +04:00 committed by Andrey Pavlenko
parent 04e9698685
commit c07ba32e16
4 changed files with 49 additions and 35 deletions

View File

@ -357,7 +357,6 @@ const char* CameraHandler::antibandingModesNames[ANDROID_CAMERA_ANTIBANDING_MODE
CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, int cameraId, void* userData, CameraParameters* prevCameraParameters)
{
typedef sp<Camera> (*Android22ConnectFuncType)();
typedef sp<Camera> (*Android23ConnectFuncType)(int);
typedef sp<Camera> (*Android3DConnectFuncType)(int, int);
@ -392,16 +391,19 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
{
LOGD("Connecting to CameraService v 2.2");
camera = Android22Connect();
LOGD("Connection to CameraService v 2.2 established");
}
else if (Android23ConnectFuncType Android23Connect = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
{
LOGD("Connecting to CameraService v 2.3");
camera = Android23Connect(cameraId);
LOGD("Connection to CameraService v 2.3 established");
}
else if (Android3DConnectFuncType Android3DConnect = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
{
LOGD("Connecting to CameraService v 3D");
camera = Android3DConnect(cameraId, CAMERA_SUPPORT_MODE_2D);
LOGD("Connection to CameraService v 3D established");
}
else
{
@ -412,19 +414,23 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
dlclose(CameraHALHandle);
if ( 0 == camera.get() )
if ( NULL == camera.get() )
{
LOGE("initCameraConnect: Unable to connect to CameraService\n");
return 0;
}
LOGD("Creating camera handler");
CameraHandler* handler = new CameraHandler(callback, userData);
LOGD("Setting camera listener");
camera->setListener(handler);
LOGD("Updating camera handler");
handler->camera = camera;
handler->cameraId = cameraId;
if (prevCameraParameters != 0)
LOGD("Checking previous camera parameters");
if (NULL != prevCameraParameters)
{
LOGI("initCameraConnect: Setting paramers from previous camera handler");
camera->setParameters(prevCameraParameters->flatten());
@ -454,7 +460,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
#if !defined(ANDROID_r2_2_0)
// Set focus mode to continuous-video if supported
const char* available_focus_modes = handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES);
if (available_focus_modes != 0)
if (NULL != available_focus_modes)
{
if (strstr(available_focus_modes, "continuous-video") != NULL)
{
@ -462,7 +468,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
status_t resParams = handler->camera->setParameters(handler->params.flatten());
if (resParams != 0)
if (0 != resParams)
{
LOGE("initCameraConnect: failed to set autofocus mode to \"continuous-video\"");
}
@ -576,7 +582,7 @@ void CameraHandler::closeCameraConnect()
camera->disconnect();
camera.clear();
camera=NULL;
camera = NULL;
// ATTENTION!!!!!!!!!!!!!!!!!!!!!!!!!!
// When we set
// camera=NULL
@ -808,43 +814,50 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
{
LOGD("CameraHandler::applyProperties()");
if (ppcameraHandler == 0)
if (NULL == ppcameraHandler)
{
LOGE("applyProperties: Passed NULL ppcameraHandler");
return;
}
if (*ppcameraHandler == 0)
if (NULL == *ppcameraHandler)
{
LOGE("applyProperties: Passed null *ppcameraHandler");
return;
}
LOGD("CameraHandler::applyProperties()");
CameraHandler* previousCameraHandler=*ppcameraHandler;
#if !defined(ANDROID_r2_2_0)
LOGD("Reconnect camera");
(*ppcameraHandler)->camera->reconnect();
(*ppcameraHandler)->params = (*ppcameraHandler)->camera->getParameters();
#else
CameraHandler* previousCameraHandler = *ppcameraHandler;
CameraParameters curCameraParameters(previousCameraHandler->params.flatten());
CameraCallback cameraCallback=previousCameraHandler->cameraCallback;
void* userData=previousCameraHandler->userData;
int cameraId=previousCameraHandler->cameraId;
CameraCallback cameraCallback = previousCameraHandler->cameraCallback;
void* userData = previousCameraHandler->userData;
int cameraId = previousCameraHandler->cameraId;
LOGD("CameraHandler::applyProperties(): before previousCameraHandler->closeCameraConnect");
previousCameraHandler->closeCameraConnect();
LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect");
LOGD("CameraHandler::applyProperties(): before initCameraConnect");
CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, &curCameraParameters);
CameraHandler* handler = initCameraConnect(cameraCallback, cameraId, userData, &curCameraParameters);
LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler);
if (handler == NULL) {
LOGE("ERROR in applyProperties --- cannot reinit camera");
handler=initCameraConnect(cameraCallback, cameraId, userData, NULL);
handler = initCameraConnect(cameraCallback, cameraId, userData, NULL);
LOGD("CameraHandler::applyProperties(): repeate initCameraConnect after ERROR, handler=0x%x", (int)handler);
if (handler == NULL) {
LOGE("ERROR in applyProperties --- cannot reinit camera AGAIN --- cannot do anything else");
}
}
(*ppcameraHandler)=handler;
(*ppcameraHandler) = handler;
#endif
}

View File

@ -204,7 +204,7 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib()
res = getSymbolFromLib(libHandle, SET_CAMERA_PROPERTY_SYMBOL_NAME, (void**)(&pSetProp_C));
if (res) return res;
\
res = getSymbolFromLib(libHandle, APPLY_CAMERA_PROPERTIES_SYMBOL_NAME, (void**)(&pApplyProp_C));
if (res) return res;
@ -386,16 +386,14 @@ void CameraActivity::applyProperties()
int CameraActivity::getFrameWidth()
{
if (frameWidth < 0)
frameWidth = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH);
return frameWidth;
LOGD("CameraActivity::getFrameWidth()");
return getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH);
}
int CameraActivity::getFrameHeight()
{
if (frameHeight < 0)
frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT);
return frameHeight;
LOGD("CameraActivity::getFrameHeight()");
return frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT);
}
void CameraActivity::setPathLibFolder(const char* path)

View File

@ -448,12 +448,14 @@ VideoCapture::~VideoCapture()
bool VideoCapture::open(const string& filename)
{
if (!isOpened())
cap = cvCreateFileCapture(filename.c_str());
return isOpened();
}
bool VideoCapture::open(int device)
{
if (!isOpened())
cap = cvCreateCameraCapture(device);
return isOpened();
}

View File

@ -204,6 +204,7 @@ CvCapture_Android::CvCapture_Android(int cameraId)
m_frameFormat = noformat;
//try connect to camera
LOGD("CvCapture_Android::CvCapture_Android(%i)", cameraId);
m_activity = new HighguiAndroidCameraActivity(this);
if (m_activity == 0) return;
@ -354,10 +355,10 @@ bool CvCapture_Android::grabFrame()
{
m_activity->applyProperties();
m_CameraParamsChanged = false;
m_dataState= CVCAPTURE_ANDROID_STATE_NO_FRAME;//we will wait new frame
m_dataState = CVCAPTURE_ANDROID_STATE_NO_FRAME;//we will wait new frame
}
if (m_dataState!=CVCAPTURE_ANDROID_STATE_HAS_NEW_FRAME_UNGRABBED)
if (m_dataState != CVCAPTURE_ANDROID_STATE_HAS_NEW_FRAME_UNGRABBED)
{
m_waitingNextFrame = true;
pthread_cond_wait(&m_nextFrameCond, &m_nextFrameMutex);