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:
parent
04e9698685
commit
c07ba32e16
@ -357,26 +357,25 @@ 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);
|
||||
|
||||
|
||||
enum {
|
||||
CAMERA_SUPPORT_MODE_2D = 0x01, /* Camera Sensor supports 2D 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_ZSL = 0x08 /* Camera Sensor supports ZSL mode. */
|
||||
};
|
||||
|
||||
|
||||
const char Android22ConnectName[] = "_ZN7android6Camera7connectEv";
|
||||
const char Android23ConnectName[] = "_ZN7android6Camera7connectEi";
|
||||
const char Android3DConnectName[] = "_ZN7android6Camera7connectEii";
|
||||
|
||||
|
||||
LOGD("CameraHandler::initCameraConnect(%p, %d, %p, %p)", callback, cameraId, userData, prevCameraParameters);
|
||||
|
||||
|
||||
sp<Camera> camera = 0;
|
||||
|
||||
|
||||
void* CameraHALHandle = dlopen("libcamera_client.so", RTLD_LAZY);
|
||||
|
||||
if (!CameraHALHandle)
|
||||
@ -384,7 +383,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
LOGE("Cannot link to \"libcamera_client.so\"");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// reset errors
|
||||
dlerror();
|
||||
|
||||
@ -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\"");
|
||||
}
|
||||
@ -560,7 +566,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
{
|
||||
LOGD("Preview started successfully");
|
||||
}
|
||||
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -448,13 +448,15 @@ VideoCapture::~VideoCapture()
|
||||
|
||||
bool VideoCapture::open(const string& filename)
|
||||
{
|
||||
cap = cvCreateFileCapture(filename.c_str());
|
||||
if (!isOpened())
|
||||
cap = cvCreateFileCapture(filename.c_str());
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
bool VideoCapture::open(int device)
|
||||
{
|
||||
cap = cvCreateCameraCapture(device);
|
||||
if (!isOpened())
|
||||
cap = cvCreateCameraCapture(device);
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -329,7 +330,7 @@ bool CvCapture_Android::setProperty( int propIdx, double propValue )
|
||||
break;
|
||||
default:
|
||||
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
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user