]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - sitara-linux/dual-camera-demo.git/commitdiff
added support for demo working with single or dual camera. Earlier it worked only...
authormanisha <manisha.agrawal@ti.com>
Thu, 27 Aug 2015 21:08:40 +0000 (16:08 -0500)
committermanisha <manisha.agrawal@ti.com>
Thu, 27 Aug 2015 21:08:40 +0000 (16:08 -0500)
loopback.c

index afe5510a902b1f9ff1d469aae7dd8211abd7866c..feca218ad489c99256afe08176106269a850f5db 100644 (file)
@@ -287,8 +287,8 @@ static int v4l2_init_device(struct v4l2_device_info *device)
                streamparam.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (ioctl(device->fd, VIDIOC_G_PARM, &streamparam) < 0){
                        perror("VIDIOC_G_PARM");
-               goto ERROR;
-       }
+                       goto ERROR;
+               }
        }
 
        device->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -304,15 +304,15 @@ static int v4l2_init_device(struct v4l2_device_info *device)
        device->fmt.fmt.pix.height = device->height;
 
        ret = ioctl(device->fd, VIDIOC_S_FMT, &device->fmt);
-               if (ret < 0) {
+       if (ret < 0) {
                perror("VIDIOC_S_FMT");
                goto ERROR;
-               }
+       }
 
        //Initialize the dma frame buffers to -1
        for(i = 0; i < NBUF; i++){
                device->b[i] = NULL;
-               }
+       }
 
        MSG("%s: Init done successfully\n", device->name);
        return 0;
@@ -394,7 +394,7 @@ static int v4l2_request_buffer(struct v4l2_device_info *device, struct dmabuf_bu
                (reqbuf.memory != V4L2_MEMORY_DMABUF)) {
                        ERROR("unsupported..");
                        return -1;
-               }
+       }
 
        device->num_buffers = reqbuf.count;
        device->buffers = bufs;
@@ -458,15 +458,15 @@ static int v4l2_queue_buffer(struct v4l2_device_info *device, struct dmabuf_buff
 
        if (!v4l2buf) {
                ERROR("invalid buffer");
-                       return -1;
-               }
+               return -1;
+       }
        ret = ioctl(device->fd, VIDIOC_QBUF, v4l2buf);
        if (ret) {
                ERROR("VIDIOC_QBUF failed: %s (%d)", strerror(errno), ret);
        }
 
        return ret;
-       }
+}
 
 /*
 * DeQueue V4L2 buffer
@@ -502,7 +502,7 @@ uint32_t drm_reserve_plane(int fd)
        drmModePlaneRes *res = drmModeGetPlaneResources(fd);
        if(res == NULL){
                ERROR("plane resources not found\n");
-               }
+       }
 
        for (i = 0; i < res->count_planes; i++) {
                uint32_t plane_id = res->planes[i];
@@ -525,7 +525,7 @@ uint32_t drm_reserve_plane(int fd)
                idx = find_reserved_plane(0);
                if(res == NULL){
                        ERROR("reserved plane index not valid\n");
-       }
+               }
 
                reserved_plane_ids[idx] = plane_id;
 
@@ -546,7 +546,7 @@ void drm_crtc_resolution(struct drm_device_info *device)
        int i;
 
        drmModeResPtr res = drmModeGetResources(device->fd);
-       
+
        if (res == NULL){
                ERROR("drmModeGetResources failed: %s\n", strerror(errno));
                exit(0);
@@ -566,7 +566,7 @@ void drm_crtc_resolution(struct drm_device_info *device)
                }
 
                printf("CRTCs size: %dx%d\n", crtc->width, crtc->height);
-        device->crtc_id = crtc_id;
+               device->crtc_id = crtc_id;
                device->width = crtc->width;
                device->height = crtc->height;
 
@@ -633,7 +633,7 @@ static int drm_init_dss(void)
        drmModePropertyRes *propRes;
        unsigned int prop_trans_key_mode = 0;
        unsigned int prop_alpha_blender = 0;
-    unsigned int j;
+       unsigned int j;
 
        props = drmModeObjectGetProperties(drm_device.fd, drm_device.crtc_id,
                DRM_MODE_OBJECT_CRTC);
@@ -646,11 +646,11 @@ static int drm_init_dss(void)
 
                if (strcmp(propRes->name, "trans-key-mode") == 0) {
                        prop_trans_key_mode = props->props[j];
-       }
+               }
 
                if (strcmp(propRes->name, "alpha_blender") == 0) {
                        prop_alpha_blender = props->props[j];
-       }
+               }
 
                if(prop_alpha_blender & prop_trans_key_mode){
                        break;
@@ -665,14 +665,14 @@ static int drm_init_dss(void)
        if(prop_alpha_blender == 0){
                ERROR("ALPHA BLENDER PROPERTY NOT FOUND\n");
                return -1;
-}
+       }
 
        /* Enable the transparency color key */
        if (drmModeObjectSetProperty(drm_device.fd,  drm_device.crtc_id,
                DRM_MODE_OBJECT_CRTC, prop_trans_key_mode, 1) < 0) {
                        ERROR("error setting drm property for transparency key mode\n");
                        return -1;
-}
+       }
 
        /* Enable the LCD alpha blender */
        if (drmModeObjectSetProperty(drm_device.fd,  drm_device.crtc_id,
@@ -700,7 +700,7 @@ int drm_disable_pip(void)
 * Display v4l2 frame on drm device
 */
 static int display_frame(struct v4l2_device_info *v4l2_device, 
-       struct drm_device_info *drm_device, bool pip)
+struct drm_device_info *drm_device, bool pip)
 {
        struct dmabuf_buffer *buf;
        int ret =0, i;
@@ -718,7 +718,7 @@ static int display_frame(struct v4l2_device_info *v4l2_device,
        buf = v4l2_dequeue_buffer(v4l2_device);
 
        v4l2_device->b[NBUF-1] = buf;
-    i = 0;
+       i = 0;
        do{
                v4l2_device->b[i] = v4l2_device->b[i+1];
                i++;
@@ -815,7 +815,7 @@ void default_parameters(void)
                status.pip=false;
        }
        else{
-       status.pip=true;
+               status.pip=true;
        }
        status.jpeg=false;
        status.exit=false;
@@ -858,6 +858,9 @@ void end_streaming(void)
 */
 int init_loopback(void)
 {
+       bool status_cam0 = 0;
+       bool status_cam1 = 0;
+
        /* Declare properties for video and capture devices */
        default_parameters();
 
@@ -879,7 +882,10 @@ int init_loopback(void)
 
        /* Initialize the v4l2 capture devices */
        if (v4l2_init_device(&cap0_device) < 0) {
-               goto Error;
+               /* If there is not a second camera, program can still continue */
+               status.num_cams=1;
+               status.main_cam=1;
+               status.pip=false;
        }
        else{
                unsigned int i;
@@ -899,12 +905,19 @@ int init_loopback(void)
                        v4l2_queue_buffer(&cap0_device, buffers[i]);
                }
 
+               status_cam0 = 1;
        }
        if (v4l2_init_device(&cap1_device) < 0) {
                /* If there is not a second camera, program can still continue */
-               status.num_cams=1;
-               status.pip=false;
-               printf("Only one camera detected\n");
+               if(status.num_cams ==2){
+                       status.num_cams=1;
+                       status.pip=false;
+                       printf("Only one camera detected\n");
+               }
+               else{
+                       printf("No camera detected\n");
+                       goto Error;
+               }
        }
        else{
                unsigned int i;
@@ -922,12 +935,16 @@ int init_loopback(void)
                for (i = 0; i < cap1_device.num_buffers; i++) {
                        v4l2_queue_buffer(&cap1_device, buffers[i]);
                }
+
+               status_cam1 = 1;
        }
 
        /* Enable streaming for the v4l2 capture devices */
-       if (v4l2_stream_on(&cap0_device) < 0) goto Error;
+       if(status_cam0){
+               if (v4l2_stream_on(&cap0_device) < 0) goto Error;
+       }
 
-       if (status.num_cams==2) {
+       if (status_cam1) {
                if (v4l2_stream_on(&cap1_device) < 0) goto Error;
        }