Skip to content

Commit

Permalink
Lets always use 2 cameras. Exteral cam can be added on demand.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerArtem committed Feb 25, 2012
1 parent c535656 commit 1de3742
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
39 changes: 23 additions & 16 deletions libcamera/CameraFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,31 @@ int CameraFactory::cameraDeviceOpen(const hw_module_t* module,int camera_id, hw_
return -EINVAL;
}

if (camera_id==0) {
if (!mCamera)
mCamera = new CameraHardware(module, "/dev/video0");
/* Lets destroy the main cam so we can use a new /dev/videoX */
if (mCamera != NULL) {
delete mCamera;
mCamera = NULL;
}

return mCamera->connectCamera(device);
if (camera_id==0) {
if (!mCamera) {
int handle = ::open("/dev/video1", O_RDONLY);
if (handle >= 0) {
::close(handle);
LOGI("Using 2 cameras!");
mCamera = new CameraHardware(module, "/dev/video1");
} else {
LOGI("Using 1 camera!");
mCamera = new CameraHardware(module, "/dev/video0");
}
}

return mCamera->connectCamera(device);
} else {
if (!sCamera)
sCamera = new CameraHardware(module, "/dev/video1");
if (!sCamera)
sCamera = new CameraHardware(module, "/dev/video0");

return sCamera->connectCamera(device);
return sCamera->connectCamera(device);
}

return 0;
Expand All @@ -96,15 +111,7 @@ int CameraFactory::getCameraNum()
{
LOGD("CameraFactory::getCameraNum");

int handle = ::open("/dev/video1", O_RDONLY);
if (handle >= 0) {
::close(handle);
LOGI("Using 2 cameras!");
return 2;
}

LOGI("Using 1 camera!");
return 1;
return 2;
}


Expand Down
5 changes: 3 additions & 2 deletions libcamera/CameraHardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ CameraHardware::CameraHardware(const hw_module_t* module, const char* videodev)
/*
* Initialize camera_device descriptor for this object.
*/
LOGI("Using camera %s", videodev);
strncpy(videodevice, videodev, sizeof(videodevice));

/* Common header */
Expand Down Expand Up @@ -320,10 +321,10 @@ status_t CameraHardware::getCameraInfo(int camera_id, struct camera_info* info)
LOGD("CameraHardware::getCameraInfo");

if (camera_id == 0) {
info->facing = CAMERA_FACING_FRONT;
info->facing = CAMERA_FACING_BACK;
info->orientation = 0;
} else {
info->facing = CAMERA_FACING_BACK;
info->facing = CAMERA_FACING_FRONT;
info->orientation = 0;
}

Expand Down

0 comments on commit 1de3742

Please sign in to comment.