Native camera issue on HTC One S fixed.
Camera connect->disconnect->connect leads to sigsegv. Apply properties method reimplemented.
This commit is contained in:
parent
19e1f89cd6
commit
710e070990
@ -357,26 +357,25 @@ const char* CameraHandler::antibandingModesNames[ANDROID_CAMERA_ANTIBANDING_MODE
|
|||||||
|
|
||||||
CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, int cameraId, void* userData, CameraParameters* prevCameraParameters)
|
CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, int cameraId, void* userData, CameraParameters* prevCameraParameters)
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef sp<Camera> (*Android22ConnectFuncType)();
|
typedef sp<Camera> (*Android22ConnectFuncType)();
|
||||||
typedef sp<Camera> (*Android23ConnectFuncType)(int);
|
typedef sp<Camera> (*Android23ConnectFuncType)(int);
|
||||||
typedef sp<Camera> (*Android3DConnectFuncType)(int, int);
|
typedef sp<Camera> (*Android3DConnectFuncType)(int, int);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CAMERA_SUPPORT_MODE_2D = 0x01, /* Camera Sensor supports 2D mode. */
|
CAMERA_SUPPORT_MODE_2D = 0x01, /* Camera Sensor supports 2D mode. */
|
||||||
CAMERA_SUPPORT_MODE_3D = 0x02, /* Camera Sensor supports 3D mode. */
|
CAMERA_SUPPORT_MODE_3D = 0x02, /* Camera Sensor supports 3D mode. */
|
||||||
CAMERA_SUPPORT_MODE_NONZSL = 0x04, /* Camera Sensor in NON-ZSL mode. */
|
CAMERA_SUPPORT_MODE_NONZSL = 0x04, /* Camera Sensor in NON-ZSL mode. */
|
||||||
CAMERA_SUPPORT_MODE_ZSL = 0x08 /* Camera Sensor supports ZSL mode. */
|
CAMERA_SUPPORT_MODE_ZSL = 0x08 /* Camera Sensor supports ZSL mode. */
|
||||||
};
|
};
|
||||||
|
|
||||||
const char Android22ConnectName[] = "_ZN7android6Camera7connectEv";
|
const char Android22ConnectName[] = "_ZN7android6Camera7connectEv";
|
||||||
const char Android23ConnectName[] = "_ZN7android6Camera7connectEi";
|
const char Android23ConnectName[] = "_ZN7android6Camera7connectEi";
|
||||||
const char Android3DConnectName[] = "_ZN7android6Camera7connectEii";
|
const char Android3DConnectName[] = "_ZN7android6Camera7connectEii";
|
||||||
|
|
||||||
LOGD("CameraHandler::initCameraConnect(%p, %d, %p, %p)", callback, cameraId, userData, prevCameraParameters);
|
LOGD("CameraHandler::initCameraConnect(%p, %d, %p, %p)", callback, cameraId, userData, prevCameraParameters);
|
||||||
|
|
||||||
sp<Camera> camera = 0;
|
sp<Camera> camera = 0;
|
||||||
|
|
||||||
void* CameraHALHandle = dlopen("libcamera_client.so", RTLD_LAZY);
|
void* CameraHALHandle = dlopen("libcamera_client.so", RTLD_LAZY);
|
||||||
|
|
||||||
if (!CameraHALHandle)
|
if (!CameraHALHandle)
|
||||||
@ -384,7 +383,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
|||||||
LOGE("Cannot link to \"libcamera_client.so\"");
|
LOGE("Cannot link to \"libcamera_client.so\"");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset errors
|
// reset errors
|
||||||
dlerror();
|
dlerror();
|
||||||
|
|
||||||
@ -392,16 +391,19 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
|||||||
{
|
{
|
||||||
LOGD("Connecting to CameraService v 2.2");
|
LOGD("Connecting to CameraService v 2.2");
|
||||||
camera = Android22Connect();
|
camera = Android22Connect();
|
||||||
|
LOGD("Connection to CameraService v 2.2 established");
|
||||||
}
|
}
|
||||||
else if (Android23ConnectFuncType Android23Connect = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
|
else if (Android23ConnectFuncType Android23Connect = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
|
||||||
{
|
{
|
||||||
LOGD("Connecting to CameraService v 2.3");
|
LOGD("Connecting to CameraService v 2.3");
|
||||||
camera = Android23Connect(cameraId);
|
camera = Android23Connect(cameraId);
|
||||||
|
LOGD("Connection to CameraService v 2.3 established");
|
||||||
}
|
}
|
||||||
else if (Android3DConnectFuncType Android3DConnect = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
|
else if (Android3DConnectFuncType Android3DConnect = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
|
||||||
{
|
{
|
||||||
LOGD("Connecting to CameraService v 3D");
|
LOGD("Connecting to CameraService v 3D");
|
||||||
camera = Android3DConnect(cameraId, CAMERA_SUPPORT_MODE_2D);
|
camera = Android3DConnect(cameraId, CAMERA_SUPPORT_MODE_2D);
|
||||||
|
LOGD("Connection to CameraService v 3D established");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -412,19 +414,23 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
|||||||
|
|
||||||
dlclose(CameraHALHandle);
|
dlclose(CameraHALHandle);
|
||||||
|
|
||||||
if ( 0 == camera.get() )
|
if ( NULL == camera.get() )
|
||||||
{
|
{
|
||||||
LOGE("initCameraConnect: Unable to connect to CameraService\n");
|
LOGE("initCameraConnect: Unable to connect to CameraService\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGD("Creating camera handler");
|
||||||
CameraHandler* handler = new CameraHandler(callback, userData);
|
CameraHandler* handler = new CameraHandler(callback, userData);
|
||||||
|
LOGD("Setting camera listener");
|
||||||
camera->setListener(handler);
|
camera->setListener(handler);
|
||||||
|
|
||||||
|
LOGD("Updating camera handler");
|
||||||
handler->camera = camera;
|
handler->camera = camera;
|
||||||
handler->cameraId = cameraId;
|
handler->cameraId = cameraId;
|
||||||
|
|
||||||
if (prevCameraParameters != 0)
|
LOGD("Checking previous camera parameters");
|
||||||
|
if (NULL != prevCameraParameters)
|
||||||
{
|
{
|
||||||
LOGI("initCameraConnect: Setting paramers from previous camera handler");
|
LOGI("initCameraConnect: Setting paramers from previous camera handler");
|
||||||
camera->setParameters(prevCameraParameters->flatten());
|
camera->setParameters(prevCameraParameters->flatten());
|
||||||
@ -454,7 +460,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
|||||||
#if !defined(ANDROID_r2_2_0)
|
#if !defined(ANDROID_r2_2_0)
|
||||||
// Set focus mode to continuous-video if supported
|
// Set focus mode to continuous-video if supported
|
||||||
const char* available_focus_modes = handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES);
|
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)
|
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());
|
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\"");
|
LOGE("initCameraConnect: failed to set autofocus mode to \"continuous-video\"");
|
||||||
}
|
}
|
||||||
@ -560,7 +566,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
|||||||
{
|
{
|
||||||
LOGD("Preview started successfully");
|
LOGD("Preview started successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +582,7 @@ void CameraHandler::closeCameraConnect()
|
|||||||
camera->disconnect();
|
camera->disconnect();
|
||||||
camera.clear();
|
camera.clear();
|
||||||
|
|
||||||
camera=NULL;
|
camera = NULL;
|
||||||
// ATTENTION!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// ATTENTION!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
// When we set
|
// When we set
|
||||||
// camera=NULL
|
// camera=NULL
|
||||||
@ -808,43 +814,50 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
|
|||||||
{
|
{
|
||||||
LOGD("CameraHandler::applyProperties()");
|
LOGD("CameraHandler::applyProperties()");
|
||||||
|
|
||||||
if (ppcameraHandler == 0)
|
if (NULL == ppcameraHandler)
|
||||||
{
|
{
|
||||||
LOGE("applyProperties: Passed NULL ppcameraHandler");
|
LOGE("applyProperties: Passed NULL ppcameraHandler");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ppcameraHandler == 0)
|
if (NULL == *ppcameraHandler)
|
||||||
{
|
{
|
||||||
LOGE("applyProperties: Passed null *ppcameraHandler");
|
LOGE("applyProperties: Passed null *ppcameraHandler");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGD("CameraHandler::applyProperties()");
|
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());
|
CameraParameters curCameraParameters(previousCameraHandler->params.flatten());
|
||||||
|
|
||||||
CameraCallback cameraCallback=previousCameraHandler->cameraCallback;
|
CameraCallback cameraCallback = previousCameraHandler->cameraCallback;
|
||||||
void* userData=previousCameraHandler->userData;
|
void* userData = previousCameraHandler->userData;
|
||||||
int cameraId=previousCameraHandler->cameraId;
|
int cameraId = previousCameraHandler->cameraId;
|
||||||
|
|
||||||
LOGD("CameraHandler::applyProperties(): before previousCameraHandler->closeCameraConnect");
|
LOGD("CameraHandler::applyProperties(): before previousCameraHandler->closeCameraConnect");
|
||||||
previousCameraHandler->closeCameraConnect();
|
previousCameraHandler->closeCameraConnect();
|
||||||
LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect");
|
LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect");
|
||||||
|
|
||||||
|
|
||||||
LOGD("CameraHandler::applyProperties(): before initCameraConnect");
|
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);
|
LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler);
|
||||||
if (handler == NULL) {
|
if (handler == NULL) {
|
||||||
LOGE("ERROR in applyProperties --- cannot reinit camera");
|
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);
|
LOGD("CameraHandler::applyProperties(): repeate initCameraConnect after ERROR, handler=0x%x", (int)handler);
|
||||||
if (handler == NULL) {
|
if (handler == NULL) {
|
||||||
LOGE("ERROR in applyProperties --- cannot reinit camera AGAIN --- cannot do anything else");
|
LOGE("ERROR in applyProperties --- cannot reinit camera AGAIN --- cannot do anything else");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(*ppcameraHandler)=handler;
|
|
||||||
|
(*ppcameraHandler) = handler;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib()
|
|||||||
|
|
||||||
res = getSymbolFromLib(libHandle, SET_CAMERA_PROPERTY_SYMBOL_NAME, (void**)(&pSetProp_C));
|
res = getSymbolFromLib(libHandle, SET_CAMERA_PROPERTY_SYMBOL_NAME, (void**)(&pSetProp_C));
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
\
|
|
||||||
res = getSymbolFromLib(libHandle, APPLY_CAMERA_PROPERTIES_SYMBOL_NAME, (void**)(&pApplyProp_C));
|
res = getSymbolFromLib(libHandle, APPLY_CAMERA_PROPERTIES_SYMBOL_NAME, (void**)(&pApplyProp_C));
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
|
|
||||||
@ -391,16 +391,14 @@ void CameraActivity::applyProperties()
|
|||||||
|
|
||||||
int CameraActivity::getFrameWidth()
|
int CameraActivity::getFrameWidth()
|
||||||
{
|
{
|
||||||
if (frameWidth < 0)
|
LOGD("CameraActivity::getFrameWidth()");
|
||||||
frameWidth = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH);
|
return getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH);
|
||||||
return frameWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CameraActivity::getFrameHeight()
|
int CameraActivity::getFrameHeight()
|
||||||
{
|
{
|
||||||
if (frameHeight < 0)
|
LOGD("CameraActivity::getFrameHeight()");
|
||||||
frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT);
|
return frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT);
|
||||||
return frameHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraActivity::setPathLibFolder(const char* path)
|
void CameraActivity::setPathLibFolder(const char* path)
|
||||||
|
@ -448,13 +448,15 @@ VideoCapture::~VideoCapture()
|
|||||||
|
|
||||||
bool VideoCapture::open(const string& filename)
|
bool VideoCapture::open(const string& filename)
|
||||||
{
|
{
|
||||||
cap = cvCreateFileCapture(filename.c_str());
|
if (!isOpened())
|
||||||
|
cap = cvCreateFileCapture(filename.c_str());
|
||||||
return isOpened();
|
return isOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoCapture::open(int device)
|
bool VideoCapture::open(int device)
|
||||||
{
|
{
|
||||||
cap = cvCreateCameraCapture(device);
|
if (!isOpened())
|
||||||
|
cap = cvCreateCameraCapture(device);
|
||||||
return isOpened();
|
return isOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,6 +203,7 @@ CvCapture_Android::CvCapture_Android(int cameraId)
|
|||||||
m_frameFormat = noformat;
|
m_frameFormat = noformat;
|
||||||
|
|
||||||
//try connect to camera
|
//try connect to camera
|
||||||
|
LOGD("CvCapture_Android::CvCapture_Android(%i)", cameraId);
|
||||||
m_activity = new HighguiAndroidCameraActivity(this);
|
m_activity = new HighguiAndroidCameraActivity(this);
|
||||||
|
|
||||||
if (m_activity == 0) return;
|
if (m_activity == 0) return;
|
||||||
@ -328,7 +329,7 @@ bool CvCapture_Android::setProperty( int propIdx, double propValue )
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CV_Error( CV_StsOutOfRange, "Failed attempt to SET unsupported camera property." );
|
CV_Error( CV_StsOutOfRange, "Failed attempt to SET unsupported camera property." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propIdx != CV_CAP_PROP_AUTOGRAB) {// property for highgui class CvCapture_Android only
|
if (propIdx != CV_CAP_PROP_AUTOGRAB) {// property for highgui class CvCapture_Android only
|
||||||
@ -353,10 +354,10 @@ bool CvCapture_Android::grabFrame()
|
|||||||
{
|
{
|
||||||
m_activity->applyProperties();
|
m_activity->applyProperties();
|
||||||
m_CameraParamsChanged = false;
|
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;
|
m_waitingNextFrame = true;
|
||||||
pthread_cond_wait(&m_nextFrameCond, &m_nextFrameMutex);
|
pthread_cond_wait(&m_nextFrameCond, &m_nextFrameMutex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user