Skip to content

Commit 14f6e20

Browse files
ribaldahverkuil
authored andcommitted
media: uvcvideo: Keep streaming state in the file handle
Add a variable in the file handle state to figure out if a camera is in the streaming state or not. This variable will be used in the future for power management policies. Now that we are at it, make use of guards to simplify the code. Reviewed-by: Laurent Pinchart <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Message-ID: <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent f8953ee commit 14f6e20

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

drivers/media/usb/uvc/uvc_v4l2.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,18 @@ static int uvc_ioctl_streamon(struct file *file, void *fh,
841841
if (!uvc_has_privileges(handle))
842842
return -EBUSY;
843843

844-
mutex_lock(&stream->mutex);
844+
guard(mutex)(&stream->mutex);
845+
846+
if (handle->is_streaming)
847+
return 0;
848+
845849
ret = uvc_queue_streamon(&stream->queue, type);
846-
mutex_unlock(&stream->mutex);
850+
if (ret)
851+
return ret;
847852

848-
return ret;
853+
handle->is_streaming = true;
854+
855+
return 0;
849856
}
850857

851858
static int uvc_ioctl_streamoff(struct file *file, void *fh,
@@ -857,9 +864,10 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh,
857864
if (!uvc_has_privileges(handle))
858865
return -EBUSY;
859866

860-
mutex_lock(&stream->mutex);
867+
guard(mutex)(&stream->mutex);
868+
861869
uvc_queue_streamoff(&stream->queue, type);
862-
mutex_unlock(&stream->mutex);
870+
handle->is_streaming = false;
863871

864872
return 0;
865873
}

drivers/media/usb/uvc/uvcvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ struct uvc_fh {
630630
struct uvc_streaming *stream;
631631
enum uvc_handle_state state;
632632
unsigned int pending_async_ctrls;
633+
bool is_streaming;
633634
};
634635

635636
/* ------------------------------------------------------------------------

0 commit comments

Comments
 (0)