Skip to content

Commit 87d76b5

Browse files
mgrzeschikgregkh
authored andcommitted
usb: gadget: uvc: calculate the number of request depending on framesize
The current limitation of possible number of requests being handled is dependent on the gadget speed. It makes more sense to depend on the typical frame size when calculating the number of requests. This patch is changing this and is using the previous limits as boundaries for reasonable minimum and maximum number of requests. For a 1080p jpeg encoded video stream with a maximum imagesize of e.g. 800kB with a maxburst of 8 and an multiplier of 1 the resulting number of requests is calculated to 49. 800768 1 nreqs = ------ * -------------- ~= 49 2 (1024 * 8 * 1) Tested-by: Dan Vacura <[email protected]> Signed-off-by: Michael Grzeschik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e84e3e9 commit 87d76b5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/usb/gadget/function/uvc_queue.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ static int uvc_queue_setup(struct vb2_queue *vq,
4444
{
4545
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
4646
struct uvc_video *video = container_of(queue, struct uvc_video, queue);
47-
struct usb_composite_dev *cdev = video->uvc->func.config->cdev;
47+
unsigned int req_size;
48+
unsigned int nreq;
4849

4950
if (*nbuffers > UVC_MAX_VIDEO_BUFFERS)
5051
*nbuffers = UVC_MAX_VIDEO_BUFFERS;
@@ -53,10 +54,16 @@ static int uvc_queue_setup(struct vb2_queue *vq,
5354

5455
sizes[0] = video->imagesize;
5556

56-
if (cdev->gadget->speed < USB_SPEED_SUPER)
57-
video->uvc_num_requests = 4;
58-
else
59-
video->uvc_num_requests = 64;
57+
req_size = video->ep->maxpacket
58+
* max_t(unsigned int, video->ep->maxburst, 1)
59+
* (video->ep->mult);
60+
61+
/* We divide by two, to increase the chance to run
62+
* into fewer requests for smaller framesizes.
63+
*/
64+
nreq = DIV_ROUND_UP(DIV_ROUND_UP(sizes[0], 2), req_size);
65+
nreq = clamp(nreq, 4U, 64U);
66+
video->uvc_num_requests = nreq;
6067

6168
return 0;
6269
}

0 commit comments

Comments
 (0)