]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
[media] pwc: do not start isoc stream on /dev/video open
authorHans de Goede <hdegoede@redhat.com>
Tue, 16 Nov 2010 14:39:25 +0000 (11:39 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 29 Dec 2010 10:16:52 +0000 (08:16 -0200)
pwc was starting streaming on /dev/video# open rather then on STREAM_ON. Now
that the v4l1 compat code is removed from the pwc driver there is no reason
left to do this. So this patch changes the pwc driver to delay starting
the isoc stream (and thus using valuable usb bandwidth) until the application
does a STREAM_ON

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/pwc/pwc-ctrl.c
drivers/media/video/pwc/pwc-if.c
drivers/media/video/pwc/pwc-v4l.c
drivers/media/video/pwc/pwc.h

index 6b8fbddc0747654ff197e38f25343089699b641c..1593f8deb8105e18bc9fd1d5b09e5c8b8e9f68ea 100644 (file)
@@ -1386,11 +1386,16 @@ long pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
        {
                ARG_DEF(int, qual)
 
+               if (pdev->iso_init) {
+                       ret = -EBUSY;
+                       break;
+               }
+
                ARG_IN(qual)
                if (ARGR(qual) < 0 || ARGR(qual) > 3)
                        ret = -EINVAL;
                else
-                       ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, ARGR(qual), pdev->vsnapshot);
+                       ret = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, ARGR(qual), pdev->vsnapshot);
                if (ret >= 0)
                        pdev->vcompression = ARGR(qual);
                break;
index b821065e387057358c3e08965186f05472e5551d..6f8b682b9245ac143022c0d8e9403f165efb26fd 100644 (file)
@@ -966,36 +966,6 @@ void pwc_isoc_cleanup(struct pwc_device *pdev)
        PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n");
 }
 
-int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot)
-{
-       int ret, start;
-
-       /* Stop isoc stuff */
-       pwc_isoc_cleanup(pdev);
-       /* Reset parameters */
-       pwc_reset_buffers(pdev);
-       /* Try to set video mode... */
-       start = ret = pwc_set_video_mode(pdev, width, height, new_fps, new_compression, new_snapshot);
-       if (ret) {
-               PWC_DEBUG_FLOW("pwc_set_video_mode attempt 1 failed.\n");
-               /* That failed... restore old mode (we know that worked) */
-               start = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot);
-               if (start) {
-                       PWC_DEBUG_FLOW("pwc_set_video_mode attempt 2 failed.\n");
-               }
-       }
-       if (start == 0)
-       {
-               if (pwc_isoc_init(pdev) < 0)
-               {
-                       PWC_WARNING("Failed to restart ISOC transfers in pwc_try_video_mode.\n");
-                       ret = -EAGAIN; /* let's try again, who knows if it works a second time */
-               }
-       }
-       pdev->drop_frames++; /* try to avoid garbage during switch */
-       return ret; /* Return original error code */
-}
-
 /*********
  * sysfs
  *********/
@@ -1175,7 +1145,7 @@ static int pwc_video_open(struct file *file)
        /* Set some defaults */
        pdev->vsnapshot = 0;
 
-       /* Start iso pipe for video; first try the last used video size
+       /* Set video size, first try the last used video size
           (or the default one); if that fails try QCIF/10 or QSIF/10;
           it that fails too, give up.
         */
@@ -1202,15 +1172,6 @@ static int pwc_video_open(struct file *file)
                return i;
        }
 
-       i = pwc_isoc_init(pdev);
-       if (i) {
-               PWC_DEBUG_OPEN("Failed to init ISOC stuff = %d.\n", i);
-               pwc_isoc_cleanup(pdev);
-               pwc_free_buffers(pdev);
-               mutex_unlock(&pdev->modlock);
-               return i;
-       }
-
        /* Initialize the webcam to sane value */
        pwc_set_brightness(pdev, 0x7fff);
        pwc_set_agc(pdev, 1, 0);
@@ -1325,6 +1286,11 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
                goto err_out;
        }
 
+       /* Start the stream (if not already started) */
+       rv = pwc_isoc_init(pdev);
+       if (rv)
+               goto err_out;
+
        /* In case we're doing partial reads, we don't have to wait for a frame */
        if (pdev->image_read_pos == 0) {
                /* Do wait queueing according to the (doc)book */
@@ -1394,6 +1360,7 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
 {
        struct video_device *vdev = file->private_data;
        struct pwc_device *pdev;
+       int ret;
 
        if (vdev == NULL)
                return -EFAULT;
@@ -1401,6 +1368,13 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
        if (pdev == NULL)
                return -EFAULT;
 
+       /* Start the stream (if not already started) */
+       mutex_lock(&pdev->modlock);
+       ret = pwc_isoc_init(pdev);
+       mutex_unlock(&pdev->modlock);
+       if (ret)
+               return ret;
+
        poll_wait(file, &pdev->frameq, wait);
        if (pdev->error_status)
                return POLLERR;
index 7061a03f5cf1de8a2df38d8632ef6c57084c4cd6..2ef1668638f9694e2b28e0a4d7cb3adcc4f1d6fb 100644 (file)
@@ -309,7 +309,10 @@ static int pwc_vidioc_set_fmt(struct pwc_device *pdev, struct v4l2_format *f)
            pixelformat != V4L2_PIX_FMT_PWC2)
                return -EINVAL;
 
-       PWC_DEBUG_IOCTL("Try to change format to: width=%d height=%d fps=%d "
+       if (pdev->iso_init)
+               return -EBUSY;
+
+       PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d "
                        "compression=%d snapshot=%d format=%c%c%c%c\n",
                        f->fmt.pix.width, f->fmt.pix.height, fps,
                        compression, snapshot,
@@ -318,14 +321,14 @@ static int pwc_vidioc_set_fmt(struct pwc_device *pdev, struct v4l2_format *f)
                        (pixelformat>>16)&255,
                        (pixelformat>>24)&255);
 
-       ret = pwc_try_video_mode(pdev,
+       ret = pwc_set_video_mode(pdev,
                                 f->fmt.pix.width,
                                 f->fmt.pix.height,
                                 fps,
                                 compression,
                                 snapshot);
 
-       PWC_DEBUG_IOCTL("pwc_try_video_mode(), return=%d\n", ret);
+       PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret);
 
        if (ret)
                return ret;
@@ -882,9 +885,7 @@ long pwc_video_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
                case VIDIOC_STREAMON:
                {
-                       /* WARNING: pwc_try_video_mode() called pwc_isoc_init */
-                       pwc_isoc_init(pdev);
-                       return 0;
+                       return pwc_isoc_init(pdev);
                }
 
                case VIDIOC_STREAMOFF:
index 36a9c83b5f5dcc4d5762e87addd45807b6d212e0..16bbc6df9b075a82c4ec03b9f3553c2c22a80da5 100644 (file)
@@ -275,7 +275,6 @@ extern int pwc_trace;
 extern int pwc_mbufs;
 
 /** functions in pwc-if.c */
-int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot);
 int pwc_handle_frame(struct pwc_device *pdev);
 void pwc_next_image(struct pwc_device *pdev);
 int pwc_isoc_init(struct pwc_device *pdev);