summaryrefslogtreecommitdiff
authorGuosong Zhou <guosong.zhou@amlogic.com>2015-05-13 10:42:03 (GMT)
committer Guosong Zhou <guosong.zhou@amlogic.com>2015-05-13 11:24:25 (GMT)
commit83447c531fba19a3f921ecd36d2fcb81b180f47b (patch)
tree5fa9ed06e064d3d74f2ab911e9c0b84654702efd
parent37e96b409068618ae1b347d4fc63bf5046bc9ca4 (diff)
downloadcamera-83447c531fba19a3f921ecd36d2fcb81b180f47b.zip
camera-83447c531fba19a3f921ecd36d2fcb81b180f47b.tar.gz
camera-83447c531fba19a3f921ecd36d2fcb81b180f47b.tar.bz2
PD #105070: fix usb camera suddenly close
Change-Id: Ida97cc67d5bdf4ea66520e68e5068cb755afdbbd
Diffstat
-rw-r--r--v3/EmulatedBaseCamera.cpp11
-rw-r--r--v3/EmulatedBaseCamera.h9
-rw-r--r--v3/EmulatedCamera3.cpp11
-rw-r--r--v3/EmulatedCamera3.h2
-rwxr-xr-xv3/EmulatedCameraFactory.cpp43
-rwxr-xr-xv3/EmulatedFakeCamera3.cpp24
-rwxr-xr-xv3/EmulatedFakeCamera3.h4
-rwxr-xr-xv3/fake-pipeline2/Sensor.cpp5
-rwxr-xr-xv3/fake-pipeline2/camera_hw.cpp190
-rwxr-xr-xv3/fake-pipeline2/camera_hw.h5
10 files changed, 201 insertions, 103 deletions
diff --git a/v3/EmulatedBaseCamera.cpp b/v3/EmulatedBaseCamera.cpp
index 5fe7d73..28b4063 100644
--- a/v3/EmulatedBaseCamera.cpp
+++ b/v3/EmulatedBaseCamera.cpp
@@ -55,6 +55,17 @@ EmulatedBaseCamera::~EmulatedBaseCamera()
{
}
+void EmulatedBaseCamera::setCameraStatus(camera_status_t status)
+{
+ ALOGE("%s: do nothing", __FUNCTION__);
+}
+
+camera_status_t EmulatedBaseCamera::getCameraStatus()
+{
+ ALOGE("%s: do nothing", __FUNCTION__);
+ return CAMERA_READY_REMOVE;
+}
+
status_t EmulatedBaseCamera::getCameraInfo(struct camera_info* info)
{
ALOGV("%s", __FUNCTION__);
diff --git a/v3/EmulatedBaseCamera.h b/v3/EmulatedBaseCamera.h
index 539b215..53cf329 100644
--- a/v3/EmulatedBaseCamera.h
+++ b/v3/EmulatedBaseCamera.h
@@ -33,6 +33,11 @@ namespace android {
* structures.
*/
+typedef enum camera_status {
+ CAMERA_INIT = 0,
+ CAMERA_READY_REMOVE,
+}camera_status_t;
+
class EmulatedBaseCamera {
public:
EmulatedBaseCamera(int cameraId,
@@ -52,7 +57,8 @@ class EmulatedBaseCamera {
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t Initialize() = 0;
-
+ virtual void setCameraStatus(camera_status_t status) = 0;
+ virtual camera_status_t getCameraStatus() = 0;
/****************************************************************************
* Camera API implementation
***************************************************************************/
@@ -111,6 +117,7 @@ class EmulatedBaseCamera {
/* Version of the camera device HAL implemented by this camera */
int mCameraDeviceVersion;
+ camera_status_t mstatus;
};
} /* namespace android */
diff --git a/v3/EmulatedCamera3.cpp b/v3/EmulatedCamera3.cpp
index 3a54794..30d6364 100644
--- a/v3/EmulatedCamera3.cpp
+++ b/v3/EmulatedCamera3.cpp
@@ -80,6 +80,17 @@ status_t EmulatedCamera3::Initialize() {
return NO_ERROR;
}
+void EmulatedCamera3::setCameraStatus(camera_status_t status)
+{
+ DBG_LOGB("%s : do nothing", __FUNCTION__);
+}
+
+camera_status_t EmulatedCamera3::getCameraStatus()
+{
+ DBG_LOGB("%s : do nothing", __FUNCTION__);
+ return CAMERA_READY_REMOVE;
+}
+
/****************************************************************************
* Camera API implementation
***************************************************************************/
diff --git a/v3/EmulatedCamera3.h b/v3/EmulatedCamera3.h
index 1cf5f33..b7be30e 100644
--- a/v3/EmulatedCamera3.h
+++ b/v3/EmulatedCamera3.h
@@ -67,6 +67,8 @@ public:
public:
virtual status_t Initialize();
+ virtual void setCameraStatus(camera_status_t status);
+ virtual camera_status_t getCameraStatus();
/****************************************************************************
* Camera module API and generic hardware device API implementation
diff --git a/v3/EmulatedCameraFactory.cpp b/v3/EmulatedCameraFactory.cpp
index eea5127..d857da2 100755
--- a/v3/EmulatedCameraFactory.cpp
+++ b/v3/EmulatedCameraFactory.cpp
@@ -414,25 +414,50 @@ int EmulatedCameraFactory::getFakeCameraHalVersion(int cameraId)
void EmulatedCameraFactory::onStatusChanged(int cameraId, int newStatus)
{
status_t res;
-
- EmulatedBaseCamera *cam = mEmulatedCameras[cameraId];
+ char dev_name[128];
+ int i = 0;
+ //EmulatedBaseCamera *cam = mEmulatedCameras[cameraId];
const camera_module_callbacks_t* cb = mCallbacks;
+ sprintf(dev_name, "%s%d", "/dev/video", cameraId);
CAMHAL_LOGDB("mEmulatedCameraNum =%d\n", mEmulatedCameraNum);
+ /*we release mEmulatedCameras[i] object for the last time construct*/
+ for (int i = 0; i < MAX_CAMERA_NUM; i++) {
+ if ((mEmulatedCameras[i] != NULL) && (mEmulatedCameras[i]->getCameraStatus() == CAMERA_READY_REMOVE)) {
+ mEmulatedCameras[i]->setCameraStatus(CAMERA_INIT);
+ delete mEmulatedCameras[i];
+ mEmulatedCameras[i] = NULL;
+ }
+ }
+
+ EmulatedBaseCamera *cam = mEmulatedCameras[cameraId];
+
if (!cam) {
/*suppose only usb camera produce uevent, and it is facing back*/
cam = new EmulatedFakeCamera3(cameraId, &HAL_MODULE_INFO_SYM.common);
+ cam->setCameraStatus(CAMERA_INIT);
if (cam != NULL) {
CAMHAL_LOGDB("%s: new camera device version is %d", __FUNCTION__,
getFakeCameraHalVersion(cameraId));
//sleep 10ms for /dev/video* create
- usleep(10000);
+ usleep(200000);
+ while (i < 4) {
+ if (0 == access(dev_name, F_OK | R_OK | W_OK)) {
+ DBG_LOGB("access %s success\n", dev_name);
+ break;
+ } else {
+ DBG_LOGB("access %s fail , i = %d .\n", dev_name,i);
+ usleep(200000);
+ i++;
+ }
+ }
res = cam->Initialize();
if (res != NO_ERROR) {
ALOGE("%s: Unable to intialize camera %d: %s (%d)",
__FUNCTION__, cameraId, strerror(-res), res);
delete cam;
+ return ;
}
}
@@ -459,17 +484,23 @@ void EmulatedCameraFactory::onStatusChanged(int cameraId, int newStatus)
return;
}
+/*here we don't notify cameraservice close camera, let app to close camera, or will generate crash*/
+#if 0
CAMHAL_LOGDB("mEmulatedCameraNum =%d\n", mEmulatedCameraNum);
if (cb != NULL && cb->camera_device_status_change != NULL) {
cb->camera_device_status_change(cb, cameraId, newStatus);
}
+#endif
CAMHAL_LOGDB("mEmulatedCameraNum =%d\n", mEmulatedCameraNum);
+
+/*don't delete mEmulatedCameras[i], or will generate crash*/
if (newStatus == CAMERA_DEVICE_STATUS_NOT_PRESENT) {
- cam->unplugCamera();
+ //cam->unplugCamera();
////
- delete mEmulatedCameras[cameraId];
- mEmulatedCameras[cameraId] = NULL;
+ //delete mEmulatedCameras[cameraId];
+ //mEmulatedCameras[cameraId] = NULL;
+ mEmulatedCameras[cameraId]->setCameraStatus(CAMERA_READY_REMOVE);
mEmulatedCameraNum --;
////
} else if (newStatus == CAMERA_DEVICE_STATUS_PRESENT) {
diff --git a/v3/EmulatedFakeCamera3.cpp b/v3/EmulatedFakeCamera3.cpp
index 1ebcaec..1d59eeb 100755
--- a/v3/EmulatedFakeCamera3.cpp
+++ b/v3/EmulatedFakeCamera3.cpp
@@ -174,6 +174,7 @@ EmulatedFakeCamera3::EmulatedFakeCamera3(int cameraId, struct hw_module_t* modul
*/
//TODO limited or full mode, read this from camera driver
//mFullMode = facingBack;
+ mCameraStatus = CAMERA_INIT;
mSupportCap = 0;
mSupportRotate = 0;
mFullMode = 0;
@@ -324,13 +325,24 @@ camera_device_status_t EmulatedFakeCamera3::getHotplugStatus() {
CAMERA_DEVICE_STATUS_NOT_PRESENT;
}
+void EmulatedFakeCamera3::setCameraStatus(camera_status_t status)
+{
+ mCameraStatus = status;
+}
+
+camera_status_t EmulatedFakeCamera3::getCameraStatus()
+{
+ CAMHAL_LOGVB("%s, mCameraStatus = %d",__FUNCTION__,mCameraStatus);
+ return mCameraStatus;
+}
+
status_t EmulatedFakeCamera3::closeCamera() {
CAMHAL_LOGVB("%s, %d\n", __FUNCTION__, __LINE__);
status_t res;
{
Mutex::Autolock l(mLock);
if (mStatus == STATUS_CLOSED) return OK;
- res = mSensor->streamOff();
+ //res = mSensor->streamOff();
res = mSensor->shutDown();
if (res != NO_ERROR) {
@@ -1579,6 +1591,7 @@ void EmulatedFakeCamera3::updateCameraMetaData(CameraMetadata *info) {
status_t EmulatedFakeCamera3::constructStaticInfo() {
+ status_t ret = OK;
CameraMetadata info;
uint32_t picSizes[64 * 8];
int64_t* duration = NULL;
@@ -1589,7 +1602,12 @@ status_t EmulatedFakeCamera3::constructStaticInfo() {
availablejpegsize = ARRAY_SIZE(mAvailableJpegSize);
memset(mAvailableJpegSize,0,(sizeof(uint32_t))*availablejpegsize);
sp<Sensor> s = new Sensor();
- s->startUp(mCameraID);
+ ret = s->startUp(mCameraID);
+ if (ret != OK) {
+ DBG_LOGA("sensor start up failed");
+ return ret;
+ }
+
mSensorType = s->getSensorType();
if ( mSensorType == SENSOR_USB) {
@@ -1983,7 +2001,7 @@ status_t EmulatedFakeCamera3::constructStaticInfo() {
}
camera_metadata_rational step;
- int maxExp, minExp, def, ret;
+ int maxExp, minExp, def;
ret = s->getExposure(&maxExp, &minExp, &def, &step);
if (ret < 0) {
static const int32_t aeExpCompensation = 0;
diff --git a/v3/EmulatedFakeCamera3.h b/v3/EmulatedFakeCamera3.h
index 6061fb2..3c47531 100755
--- a/v3/EmulatedFakeCamera3.h
+++ b/v3/EmulatedFakeCamera3.h
@@ -78,6 +78,8 @@ public:
virtual status_t closeCamera();
virtual status_t getCameraInfo(struct camera_info *info);
+ virtual void setCameraStatus(camera_status_t status);
+ virtual camera_status_t getCameraStatus();
/****************************************************************************
* EmulatedCamera3 abstract API implementation
@@ -250,7 +252,7 @@ private:
friend class JpegCompressor;
unsigned int mSupportCap;
unsigned int mSupportRotate;
-
+ camera_status_t mCameraStatus;
/** Processing thread for sending out results */
class ReadoutThread : public Thread, private JpegCompressor::JpegListener {
diff --git a/v3/fake-pipeline2/Sensor.cpp b/v3/fake-pipeline2/Sensor.cpp
index abce83b..aea3ab0 100755
--- a/v3/fake-pipeline2/Sensor.cpp
+++ b/v3/fake-pipeline2/Sensor.cpp
@@ -182,7 +182,7 @@ Sensor::Sensor():
}
Sensor::~Sensor() {
- shutDown();
+ //shutDown();
}
status_t Sensor::startUp(int idx) {
@@ -2015,6 +2015,9 @@ void Sensor::captureNV21(StreamBuffer b, uint32_t gain) {
return ;
}
while(1){
+ if (get_device_status(vinfo)) {
+ break;
+ }
src = (uint8_t *)get_frame(vinfo);
if (NULL == src) {
CAMHAL_LOGDA("get frame NULL, sleep 5ms");
diff --git a/v3/fake-pipeline2/camera_hw.cpp b/v3/fake-pipeline2/camera_hw.cpp
index 4234f69..67c5ece 100755
--- a/v3/fake-pipeline2/camera_hw.cpp
+++ b/v3/fake-pipeline2/camera_hw.cpp
@@ -22,8 +22,8 @@ static int set_rotate_value(int camera_fd, int value)
}
memset( &ctl, 0, sizeof(ctl));
ctl.value=value;
- ctl.id = V4L2_CID_ROTATE;
- ALOGD("set_rotate_value:: id =%x , value=%d",ctl.id,ctl.value);
+ ctl.id = V4L2_CID_ROTATE;
+ ALOGD("set_rotate_value:: id =%x , value=%d",ctl.id,ctl.value);
ret = ioctl(camera_fd, VIDIOC_S_CTRL, &ctl);
if(ret<0){
CAMHAL_LOGDB("Set rotate value fail: %s,errno=%d. ret=%d", strerror(errno),errno,ret);
@@ -31,6 +31,16 @@ static int set_rotate_value(int camera_fd, int value)
return ret ;
}
+void set_device_status(struct VideoInfo *vinfo)
+{
+ vinfo->dev_status = -1;
+}
+
+int get_device_status(struct VideoInfo *vinfo)
+{
+ return vinfo->dev_status;
+}
+
int camera_open(struct VideoInfo *cam_dev)
{
char dev_name[128];
@@ -65,7 +75,7 @@ int camera_open(struct VideoInfo *cam_dev)
int setBuffersFormat(struct VideoInfo *cam_dev)
{
int ret = 0;
- if ((cam_dev->preview.format.fmt.pix.width != 0) && (cam_dev->preview.format.fmt.pix.height != 0)) {
+ if ((cam_dev->preview.format.fmt.pix.width != 0) && (cam_dev->preview.format.fmt.pix.height != 0)) {
int pixelformat = cam_dev->preview.format.fmt.pix.pixelformat;
ret = ioctl(cam_dev->fd, VIDIOC_S_FMT, &cam_dev->preview.format);
@@ -78,7 +88,7 @@ int setBuffersFormat(struct VideoInfo *cam_dev)
cam_dev->preview.format.fmt.pix.height,
(char*)&pixelformat,
(char*)&cam_dev->preview.format.fmt.pix.pixelformat);
- }
+ }
return ret;
}
@@ -119,16 +129,17 @@ int start_capturing(struct VideoInfo *vinfo)
vinfo->preview.buf.memory = V4L2_MEMORY_MMAP;
vinfo->preview.buf.index = i;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QUERYBUF, &vinfo->preview.buf)){
+ if (ioctl(vinfo->fd, VIDIOC_QUERYBUF, &vinfo->preview.buf) < 0) {
DBG_LOGB("VIDIOC_QUERYBUF, errno=%d", errno);
}
-
- vinfo->mem[i] = mmap(NULL /* start anywhere */,
- vinfo->preview.buf.length,
+ /*pluge usb camera when preview, vinfo->preview.buf.length value will equal to 0, so save this value*/
+ vinfo->tempbuflen = vinfo->preview.buf.length;
+ vinfo->mem[i] = mmap(NULL /* start anywhere */,
+ vinfo->preview.buf.length,
PROT_READ | PROT_WRITE /* required */,
MAP_SHARED /* recommended */,
vinfo->fd,
- vinfo->preview.buf.m.offset);
+ vinfo->preview.buf.m.offset);
if (MAP_FAILED == vinfo->mem[i]) {
DBG_LOGB("mmap failed, errno=%d\n", errno);
@@ -142,16 +153,15 @@ int start_capturing(struct VideoInfo *vinfo)
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &buf))
+ if (ioctl(vinfo->fd, VIDIOC_QBUF, &buf) < 0)
DBG_LOGB("VIDIOC_QBUF failed, errno=%d\n", errno);
}
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (-1 == ioctl(vinfo->fd, VIDIOC_STREAMON, &type))
+ if (ioctl(vinfo->fd, VIDIOC_STREAMON, &type) < 0)
DBG_LOGB("VIDIOC_STREAMON, errno=%d\n", errno);
- vinfo->isStreaming = true;
-
+ vinfo->isStreaming = true;
return 0;
}
@@ -165,21 +175,20 @@ int stop_capturing(struct VideoInfo *vinfo)
return -1;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (-1 == ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type)){
+ if (ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type) < 0) {
DBG_LOGB("VIDIOC_STREAMOFF, errno=%d", errno);
res = -1;
}
for (i = 0; i < (int)vinfo->preview.rb.count; ++i) {
- if (-1 == munmap(vinfo->mem[i], vinfo->preview.buf.length)) {
+ if (munmap(vinfo->mem[i], vinfo->preview.buf.length) < 0) {
DBG_LOGB("munmap failed errno=%d", errno);
res = -1;
}
}
-
- vinfo->isStreaming = false;
- return res;
+ vinfo->isStreaming = false;
+ return res;
}
int releasebuf_and_stop_capturing(struct VideoInfo *vinfo)
@@ -192,19 +201,20 @@ int releasebuf_and_stop_capturing(struct VideoInfo *vinfo)
return -1;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (-1 == ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type)){
+ if (ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type) < 0) {
DBG_LOGB("VIDIOC_STREAMOFF, errno=%d", errno);
res = -1;
}
-
+ if (vinfo->dev_status == -1) {
+ vinfo->preview.buf.length = vinfo->tempbuflen;
+ }
for (i = 0; i < (int)vinfo->preview.rb.count; ++i) {
- if (-1 == munmap(vinfo->mem[i], vinfo->preview.buf.length)) {
+ if (munmap(vinfo->mem[i], vinfo->preview.buf.length) < 0) {
DBG_LOGB("munmap failed errno=%d", errno);
res = -1;
}
}
-
- vinfo->isStreaming = false;
+ vinfo->isStreaming = false;
vinfo->preview.format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
vinfo->preview.rb.memory = V4L2_MEMORY_MMAP;
@@ -217,8 +227,7 @@ int releasebuf_and_stop_capturing(struct VideoInfo *vinfo)
}else{
DBG_LOGA("VIDIOC_REQBUFS delete buffer success\n");
}
-
- return res;
+ return res;
}
@@ -229,7 +238,7 @@ uintptr_t get_frame_phys(struct VideoInfo *vinfo)
vinfo->preview.buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
vinfo->preview.buf.memory = V4L2_MEMORY_MMAP;
- if (-1 == ioctl(vinfo->fd, VIDIOC_DQBUF, &vinfo->preview.buf)) {
+ if (ioctl(vinfo->fd, VIDIOC_DQBUF, &vinfo->preview.buf) < 0) {
switch (errno) {
case EAGAIN:
return 0;
@@ -243,7 +252,7 @@ uintptr_t get_frame_phys(struct VideoInfo *vinfo)
DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
exit(1);
}
- DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
+ DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
}
return (uintptr_t)vinfo->preview.buf.m.userptr;
@@ -256,7 +265,7 @@ void *get_frame(struct VideoInfo *vinfo)
vinfo->preview.buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
vinfo->preview.buf.memory = V4L2_MEMORY_MMAP;
- if (-1 == ioctl(vinfo->fd, VIDIOC_DQBUF, &vinfo->preview.buf)) {
+ if (ioctl(vinfo->fd, VIDIOC_DQBUF, &vinfo->preview.buf) < 0) {
switch (errno) {
case EAGAIN:
return NULL;
@@ -268,9 +277,10 @@ void *get_frame(struct VideoInfo *vinfo)
default:
DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
- exit(1);
+ //exit(1); /*here will generate crash, so delete. when ocour error, should break while() loop*/
+ set_device_status(vinfo);
}
- DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
+ DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
}
//DBG_LOGA("get frame\n");
@@ -279,8 +289,10 @@ void *get_frame(struct VideoInfo *vinfo)
int putback_frame(struct VideoInfo *vinfo)
{
+ if (vinfo->dev_status == -1)
+ return 0;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &vinfo->preview.buf))
+ if (ioctl(vinfo->fd, VIDIOC_QBUF, &vinfo->preview.buf) < 0)
DBG_LOGB("QBUF failed error=%d\n", errno);
return 0;
@@ -289,7 +301,7 @@ int putback_frame(struct VideoInfo *vinfo)
int putback_picture_frame(struct VideoInfo *vinfo)
{
- if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &vinfo->picture.buf))
+ if (ioctl(vinfo->fd, VIDIOC_QBUF, &vinfo->picture.buf) < 0)
DBG_LOGB("QBUF failed error=%d\n", errno);
return 0;
@@ -297,21 +309,21 @@ int putback_picture_frame(struct VideoInfo *vinfo)
int start_picture(struct VideoInfo *vinfo, int rotate)
{
- int ret = 0;
+ int ret = 0;
int i;
enum v4l2_buf_type type;
struct v4l2_buffer buf;
bool usbcamera = false;
CLEAR(vinfo->picture.rb);
-
- //step 1 : ioctl VIDIOC_S_FMT
- ret = ioctl(vinfo->fd, VIDIOC_S_FMT, &vinfo->picture.format);
+
+ //step 1 : ioctl VIDIOC_S_FMT
+ ret = ioctl(vinfo->fd, VIDIOC_S_FMT, &vinfo->picture.format);
if (ret < 0) {
DBG_LOGB("Open: VIDIOC_S_FMT Failed: %s, ret=%d\n", strerror(errno), ret);
}
- //step 2 : request buffer
+ //step 2 : request buffer
vinfo->picture.rb.count = 1;
vinfo->picture.rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
//TODO DMABUF & ION
@@ -329,7 +341,7 @@ int start_picture(struct VideoInfo *vinfo, int rotate)
return -EINVAL;
}
- //step 3: mmap buffer
+ //step 3: mmap buffer
for (i = 0; i < (int)vinfo->picture.rb.count; ++i) {
CLEAR(vinfo->picture.buf);
@@ -338,23 +350,23 @@ int start_picture(struct VideoInfo *vinfo, int rotate)
vinfo->picture.buf.memory = V4L2_MEMORY_MMAP;
vinfo->picture.buf.index = i;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QUERYBUF, &vinfo->picture.buf)){
+ if (ioctl(vinfo->fd, VIDIOC_QUERYBUF, &vinfo->picture.buf) < 0) {
DBG_LOGB("VIDIOC_QUERYBUF, errno=%d", errno);
}
- vinfo->mem_pic[i] = mmap(NULL /* start anywhere */,
- vinfo->picture.buf.length,
+ vinfo->mem_pic[i] = mmap(NULL /* start anywhere */,
+ vinfo->picture.buf.length,
PROT_READ | PROT_WRITE /* required */,
MAP_SHARED /* recommended */,
vinfo->fd,
- vinfo->picture.buf.m.offset);
+ vinfo->picture.buf.m.offset);
if (MAP_FAILED == vinfo->mem_pic[i]) {
DBG_LOGB("mmap failed, errno=%d\n", errno);
}
}
- //step 4 : QBUF
- ////////////////////////////////
+ //step 4 : QBUF
+ ////////////////////////////////
for (i = 0; i < (int)vinfo->picture.rb.count; ++i) {
CLEAR(buf);
@@ -362,7 +374,7 @@ int start_picture(struct VideoInfo *vinfo, int rotate)
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &buf))
+ if (ioctl(vinfo->fd, VIDIOC_QBUF, &buf) < 0)
DBG_LOGB("VIDIOC_QBUF failed, errno=%d\n", errno);
}
@@ -374,33 +386,31 @@ int start_picture(struct VideoInfo *vinfo, int rotate)
usbcamera = true;
}
if (!usbcamera) {
- set_rotate_value(vinfo->fd,rotate);
+ set_rotate_value(vinfo->fd,rotate);
}
-
- //step 5: Stream ON
+ //step 5: Stream ON
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (-1 == ioctl(vinfo->fd, VIDIOC_STREAMON, &type))
+ if (ioctl(vinfo->fd, VIDIOC_STREAMON, &type) < 0)
DBG_LOGB("VIDIOC_STREAMON, errno=%d\n", errno);
vinfo->isPicture = true;
- return 0;
-
+ return 0;
}
void *get_picture(struct VideoInfo *vinfo)
{
CLEAR(vinfo->picture.buf);
-
+
vinfo->picture.buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
vinfo->picture.buf.memory = V4L2_MEMORY_MMAP;
- if (-1 == ioctl(vinfo->fd, VIDIOC_DQBUF, &vinfo->picture.buf)) {
- switch (errno) {
+ if (ioctl(vinfo->fd, VIDIOC_DQBUF, &vinfo->picture.buf) < 0) {
+ switch (errno) {
case EAGAIN:
- return NULL;
- case EIO:
+ return NULL;
+ case EIO:
/* Could ignore EIO, see spec. */
- /* fall through */
+ /* fall through */
default:
DBG_LOGB("VIDIOC_DQBUF failed, errno=%d\n", errno);
exit(1);
@@ -412,72 +422,71 @@ void *get_picture(struct VideoInfo *vinfo)
void stop_picture(struct VideoInfo *vinfo)
{
- enum v4l2_buf_type type;
- struct v4l2_buffer buf;
+ enum v4l2_buf_type type;
+ struct v4l2_buffer buf;
int i;
if (!vinfo->isPicture)
return ;
-
- //QBUF
- for (i = 0; i < (int)vinfo->picture.rb.count; ++i) {
+
+ //QBUF
+ for (i = 0; i < (int)vinfo->picture.rb.count; ++i) {
CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &buf))
+ if (ioctl(vinfo->fd, VIDIOC_QBUF, &buf) < 0)
DBG_LOGB("VIDIOC_QBUF failed, errno=%d\n", errno);
}
-
- //stream off and unmap buffer
+
+ //stream off and unmap buffer
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (-1 == ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type))
+ if (ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type) < 0)
DBG_LOGB("VIDIOC_STREAMOFF, errno=%d", errno);
-
+
for (i = 0; i < (int)vinfo->picture.rb.count; i++)
{
- if (-1 == munmap(vinfo->mem_pic[i], vinfo->picture.buf.length))
- DBG_LOGB("munmap failed errno=%d", errno);
+ if (munmap(vinfo->mem_pic[i], vinfo->picture.buf.length) < 0)
+ DBG_LOGB("munmap failed errno=%d", errno);
}
- set_rotate_value(vinfo->fd,0);
- vinfo->isPicture = false;
- setBuffersFormat(vinfo);
- start_capturing(vinfo);
-
+ set_rotate_value(vinfo->fd,0);
+ vinfo->isPicture = false;
+ setBuffersFormat(vinfo);
+ start_capturing(vinfo);
}
void releasebuf_and_stop_picture(struct VideoInfo *vinfo)
{
- enum v4l2_buf_type type;
- struct v4l2_buffer buf;
+ enum v4l2_buf_type type;
+ struct v4l2_buffer buf;
int i,ret;
if (!vinfo->isPicture)
return ;
-
- //QBUF
- for (i = 0; i < (int)vinfo->picture.rb.count; ++i) {
+
+ //QBUF
+ for (i = 0; i < (int)vinfo->picture.rb.count; ++i) {
CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
- if (-1 == ioctl(vinfo->fd, VIDIOC_QBUF, &buf))
+ if (ioctl(vinfo->fd, VIDIOC_QBUF, &buf) < 0)
DBG_LOGB("VIDIOC_QBUF failed, errno=%d\n", errno);
}
-
- //stream off and unmap buffer
+
+ //stream off and unmap buffer
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (-1 == ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type))
+ if (ioctl(vinfo->fd, VIDIOC_STREAMOFF, &type) < 0)
DBG_LOGB("VIDIOC_STREAMOFF, errno=%d", errno);
-
+
for (i = 0; i < (int)vinfo->picture.rb.count; i++)
{
- if (-1 == munmap(vinfo->mem_pic[i], vinfo->picture.buf.length))
- DBG_LOGB("munmap failed errno=%d", errno);
+ if (munmap(vinfo->mem_pic[i], vinfo->picture.buf.length) < 0)
+ DBG_LOGB("munmap failed errno=%d", errno);
}
- vinfo->isPicture = false;
+ vinfo->isPicture = false;
vinfo->picture.format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
vinfo->picture.rb.memory = V4L2_MEMORY_MMAP;
@@ -489,9 +498,8 @@ void releasebuf_and_stop_picture(struct VideoInfo *vinfo)
}else{
DBG_LOGA("VIDIOC_REQBUFS delete buffer success\n");
}
-
- setBuffersFormat(vinfo);
- start_capturing(vinfo);
+ setBuffersFormat(vinfo);
+ start_capturing(vinfo);
}
void camera_close(struct VideoInfo *vinfo)
@@ -501,7 +509,7 @@ void camera_close(struct VideoInfo *vinfo)
return ;
}
- if (-1 == close(vinfo->fd))
+ if (close(vinfo->fd) != 0)
DBG_LOGB("close failed, errno=%d\n", errno);
vinfo->fd = -1;
diff --git a/v3/fake-pipeline2/camera_hw.h b/v3/fake-pipeline2/camera_hw.h
index 30a1fb4..3de2e22 100755
--- a/v3/fake-pipeline2/camera_hw.h
+++ b/v3/fake-pipeline2/camera_hw.h
@@ -52,6 +52,9 @@ struct VideoInfo {
int idx;
int fd;
+
+ int tempbuflen;
+ int dev_status;
};
extern int camera_open(struct VideoInfo *cam_dev);
@@ -65,6 +68,8 @@ extern int stop_capturing(struct VideoInfo *vinfo);
extern int releasebuf_and_stop_capturing(struct VideoInfo *vinfo);
extern uintptr_t get_frame_phys(struct VideoInfo *vinfo);
+extern void set_device_status(struct VideoInfo *vinfo);
+extern int get_device_status(struct VideoInfo *vinfo);
extern void *get_frame(struct VideoInfo *vinfo);
extern void *get_picture(struct VideoInfo *vinfo);