[media] uvcvideo: Implement vb2 queue start and stop stream operations
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 21 Oct 2014 16:03:08 +0000 (13:03 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Tue, 25 Nov 2014 10:40:08 +0000 (08:40 -0200)
To work propertly the videobuf2 core code needs to be in charge of
stream start/stop control. Implement the start_streaming and
stop_streaming vb2 operations and move video enable/disable code to
them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/usb/uvc/uvc_queue.c
drivers/media/usb/uvc/uvc_v4l2.c

index 97036559bb923dde928b5f75e3f9821f40ea6547..758247048ee1a7a2e17ab64ce847fd9e4f7d9c50 100644 (file)
@@ -135,6 +135,29 @@ static void uvc_wait_finish(struct vb2_queue *vq)
        mutex_lock(&queue->mutex);
 }
 
+static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
+{
+       struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
+       struct uvc_streaming *stream = uvc_queue_to_stream(queue);
+
+       queue->buf_used = 0;
+
+       return uvc_video_enable(stream, 1);
+}
+
+static void uvc_stop_streaming(struct vb2_queue *vq)
+{
+       struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
+       struct uvc_streaming *stream = uvc_queue_to_stream(queue);
+       unsigned long flags;
+
+       uvc_video_enable(stream, 0);
+
+       spin_lock_irqsave(&queue->irqlock, flags);
+       INIT_LIST_HEAD(&queue->irqqueue);
+       spin_unlock_irqrestore(&queue->irqlock, flags);
+}
+
 static struct vb2_ops uvc_queue_qops = {
        .queue_setup = uvc_queue_setup,
        .buf_prepare = uvc_buffer_prepare,
@@ -142,6 +165,8 @@ static struct vb2_ops uvc_queue_qops = {
        .buf_finish = uvc_buffer_finish,
        .wait_prepare = uvc_wait_prepare,
        .wait_finish = uvc_wait_finish,
+       .start_streaming = uvc_start_streaming,
+       .stop_streaming = uvc_stop_streaming,
 };
 
 int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
@@ -310,27 +335,15 @@ int uvc_queue_allocated(struct uvc_video_queue *queue)
  */
 int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
 {
-       unsigned long flags;
        int ret;
 
        mutex_lock(&queue->mutex);
-       if (enable) {
-               ret = vb2_streamon(&queue->queue, queue->queue.type);
-               if (ret < 0)
-                       goto done;
 
-               queue->buf_used = 0;
-       } else {
+       if (enable)
+               ret = vb2_streamon(&queue->queue, queue->queue.type);
+       else
                ret = vb2_streamoff(&queue->queue, queue->queue.type);
-               if (ret < 0)
-                       goto done;
-
-               spin_lock_irqsave(&queue->irqlock, flags);
-               INIT_LIST_HEAD(&queue->irqqueue);
-               spin_unlock_irqrestore(&queue->irqlock, flags);
-       }
 
-done:
        mutex_unlock(&queue->mutex);
        return ret;
 }
index e8bf4f149a26c1d64f24d308d611717c43050c51..4619fd6b0494c51dab4ae323bdcafc3171ba12de 100644 (file)
@@ -531,7 +531,6 @@ static int uvc_v4l2_release(struct file *file)
 
        /* Only free resources if this is a privileged handle. */
        if (uvc_has_privileges(handle)) {
-               uvc_video_enable(stream, 0);
                uvc_queue_enable(&stream->queue, 0);
                uvc_free_buffers(&stream->queue);
        }
@@ -768,14 +767,6 @@ static int uvc_ioctl_streamon(struct file *file, void *fh,
 
        mutex_lock(&stream->mutex);
        ret = uvc_queue_enable(&stream->queue, 1);
-       if (ret < 0)
-               goto done;
-
-       ret = uvc_video_enable(stream, 1);
-       if (ret < 0)
-               uvc_queue_enable(&stream->queue, 0);
-
-done:
        mutex_unlock(&stream->mutex);
 
        return ret;
@@ -794,7 +785,6 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh,
                return -EBUSY;
 
        mutex_lock(&stream->mutex);
-       uvc_video_enable(stream, 0);
        uvc_queue_enable(&stream->queue, 0);
        mutex_unlock(&stream->mutex);