Lines Matching full:video

3  *	uvc_video.c  --  USB Video Class Gadget driver
14 #include <linux/usb/video.h>
23 * Video codecs
27 uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf, in uvc_video_encode_header() argument
31 data[1] = UVC_STREAM_EOH | video->fid; in uvc_video_encode_header()
33 if (buf->bytesused - video->queue.buf_used <= len - 2) in uvc_video_encode_header()
40 uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf, in uvc_video_encode_data() argument
43 struct uvc_video_queue *queue = &video->queue; in uvc_video_encode_data()
47 /* Copy video data to the USB buffer. */ in uvc_video_encode_data()
58 uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video, in uvc_video_encode_bulk() argument
62 int len = video->req_size; in uvc_video_encode_bulk()
66 if (video->payload_size == 0) { in uvc_video_encode_bulk()
67 ret = uvc_video_encode_header(video, buf, mem, len); in uvc_video_encode_bulk()
68 video->payload_size += ret; in uvc_video_encode_bulk()
73 /* Process video data. */ in uvc_video_encode_bulk()
74 len = min((int)(video->max_payload_size - video->payload_size), len); in uvc_video_encode_bulk()
75 ret = uvc_video_encode_data(video, buf, mem, len); in uvc_video_encode_bulk()
77 video->payload_size += ret; in uvc_video_encode_bulk()
80 req->length = video->req_size - len; in uvc_video_encode_bulk()
81 req->zero = video->payload_size == video->max_payload_size; in uvc_video_encode_bulk()
83 if (buf->bytesused == video->queue.buf_used) { in uvc_video_encode_bulk()
84 video->queue.buf_used = 0; in uvc_video_encode_bulk()
86 uvcg_queue_next_buffer(&video->queue, buf); in uvc_video_encode_bulk()
87 video->fid ^= UVC_STREAM_FID; in uvc_video_encode_bulk()
89 video->payload_size = 0; in uvc_video_encode_bulk()
92 if (video->payload_size == video->max_payload_size || in uvc_video_encode_bulk()
93 buf->bytesused == video->queue.buf_used) in uvc_video_encode_bulk()
94 video->payload_size = 0; in uvc_video_encode_bulk()
98 uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video, in uvc_video_encode_isoc() argument
102 int len = video->req_size; in uvc_video_encode_isoc()
106 ret = uvc_video_encode_header(video, buf, mem, len); in uvc_video_encode_isoc()
110 /* Process video data. */ in uvc_video_encode_isoc()
111 ret = uvc_video_encode_data(video, buf, mem, len); in uvc_video_encode_isoc()
114 req->length = video->req_size - len; in uvc_video_encode_isoc()
116 if (buf->bytesused == video->queue.buf_used) { in uvc_video_encode_isoc()
117 video->queue.buf_used = 0; in uvc_video_encode_isoc()
119 uvcg_queue_next_buffer(&video->queue, buf); in uvc_video_encode_isoc()
120 video->fid ^= UVC_STREAM_FID; in uvc_video_encode_isoc()
128 static int uvcg_video_ep_queue(struct uvc_video *video, struct usb_request *req) in uvcg_video_ep_queue() argument
132 ret = usb_ep_queue(video->ep, req, GFP_ATOMIC); in uvcg_video_ep_queue()
134 uvcg_err(&video->uvc->func, "Failed to queue request (%d).\n", in uvcg_video_ep_queue()
138 if (usb_endpoint_xfer_bulk(video->ep->desc)) in uvcg_video_ep_queue()
139 usb_ep_set_halt(video->ep); in uvcg_video_ep_queue()
150 * if a video buffer is available.
153 * the handler will start streaming if a video buffer is available and if
154 * video is not currently streaming.
156 * - V4L2 buffer queueing: the driver will start streaming if video is not
162 * The "video currently streaming" condition can't be detected by the irqqueue
173 * handler will restart the video stream.
178 struct uvc_video *video = req->context; in uvc_video_complete() local
179 struct uvc_video_queue *queue = &video->queue; in uvc_video_complete()
189 uvcg_dbg(&video->uvc->func, "VS request cancelled.\n"); in uvc_video_complete()
194 uvcg_info(&video->uvc->func, in uvc_video_complete()
201 spin_lock_irqsave(&video->queue.irqlock, flags); in uvc_video_complete()
202 buf = uvcg_queue_head(&video->queue); in uvc_video_complete()
204 spin_unlock_irqrestore(&video->queue.irqlock, flags); in uvc_video_complete()
208 video->encode(req, video, buf); in uvc_video_complete()
210 ret = uvcg_video_ep_queue(video, req); in uvc_video_complete()
211 spin_unlock_irqrestore(&video->queue.irqlock, flags); in uvc_video_complete()
221 spin_lock_irqsave(&video->req_lock, flags); in uvc_video_complete()
222 list_add_tail(&req->list, &video->req_free); in uvc_video_complete()
223 spin_unlock_irqrestore(&video->req_lock, flags); in uvc_video_complete()
227 uvc_video_free_requests(struct uvc_video *video) in uvc_video_free_requests() argument
232 if (video->req[i]) { in uvc_video_free_requests()
233 usb_ep_free_request(video->ep, video->req[i]); in uvc_video_free_requests()
234 video->req[i] = NULL; in uvc_video_free_requests()
237 if (video->req_buffer[i]) { in uvc_video_free_requests()
238 kfree(video->req_buffer[i]); in uvc_video_free_requests()
239 video->req_buffer[i] = NULL; in uvc_video_free_requests()
243 INIT_LIST_HEAD(&video->req_free); in uvc_video_free_requests()
244 video->req_size = 0; in uvc_video_free_requests()
249 uvc_video_alloc_requests(struct uvc_video *video) in uvc_video_alloc_requests() argument
255 BUG_ON(video->req_size); in uvc_video_alloc_requests()
257 req_size = video->ep->maxpacket in uvc_video_alloc_requests()
258 * max_t(unsigned int, video->ep->maxburst, 1) in uvc_video_alloc_requests()
259 * (video->ep->mult); in uvc_video_alloc_requests()
262 video->req_buffer[i] = kmalloc(req_size, GFP_KERNEL); in uvc_video_alloc_requests()
263 if (video->req_buffer[i] == NULL) in uvc_video_alloc_requests()
266 video->req[i] = usb_ep_alloc_request(video->ep, GFP_KERNEL); in uvc_video_alloc_requests()
267 if (video->req[i] == NULL) in uvc_video_alloc_requests()
270 video->req[i]->buf = video->req_buffer[i]; in uvc_video_alloc_requests()
271 video->req[i]->length = 0; in uvc_video_alloc_requests()
272 video->req[i]->complete = uvc_video_complete; in uvc_video_alloc_requests()
273 video->req[i]->context = video; in uvc_video_alloc_requests()
275 list_add_tail(&video->req[i]->list, &video->req_free); in uvc_video_alloc_requests()
278 video->req_size = req_size; in uvc_video_alloc_requests()
283 uvc_video_free_requests(video); in uvc_video_alloc_requests()
288 * Video streaming
292 * uvcg_video_pump - Pump video data into the USB requests
295 * video data from the queued buffers.
297 int uvcg_video_pump(struct uvc_video *video) in uvcg_video_pump() argument
299 struct uvc_video_queue *queue = &video->queue; in uvcg_video_pump()
313 spin_lock_irqsave(&video->req_lock, flags); in uvcg_video_pump()
314 if (list_empty(&video->req_free)) { in uvcg_video_pump()
315 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
318 req = list_first_entry(&video->req_free, struct usb_request, in uvcg_video_pump()
321 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
323 /* Retrieve the first available video buffer and fill the in uvcg_video_pump()
324 * request, protected by the video queue irqlock. in uvcg_video_pump()
333 video->encode(req, video, buf); in uvcg_video_pump()
336 ret = uvcg_video_ep_queue(video, req); in uvcg_video_pump()
345 spin_lock_irqsave(&video->req_lock, flags); in uvcg_video_pump()
346 list_add_tail(&req->list, &video->req_free); in uvcg_video_pump()
347 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
352 * Enable or disable the video stream.
354 int uvcg_video_enable(struct uvc_video *video, int enable) in uvcg_video_enable() argument
359 if (video->ep == NULL) { in uvcg_video_enable()
360 uvcg_info(&video->uvc->func, in uvcg_video_enable()
361 "Video enable failed, device is uninitialized.\n"); in uvcg_video_enable()
367 if (video->req[i]) in uvcg_video_enable()
368 usb_ep_dequeue(video->ep, video->req[i]); in uvcg_video_enable()
370 uvc_video_free_requests(video); in uvcg_video_enable()
371 uvcg_queue_enable(&video->queue, 0); in uvcg_video_enable()
375 if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) in uvcg_video_enable()
378 if ((ret = uvc_video_alloc_requests(video)) < 0) in uvcg_video_enable()
381 if (video->max_payload_size) { in uvcg_video_enable()
382 video->encode = uvc_video_encode_bulk; in uvcg_video_enable()
383 video->payload_size = 0; in uvcg_video_enable()
385 video->encode = uvc_video_encode_isoc; in uvcg_video_enable()
387 return uvcg_video_pump(video); in uvcg_video_enable()
391 * Initialize the UVC video stream.
393 int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc) in uvcg_video_init() argument
395 INIT_LIST_HEAD(&video->req_free); in uvcg_video_init()
396 spin_lock_init(&video->req_lock); in uvcg_video_init()
398 video->uvc = uvc; in uvcg_video_init()
399 video->fcc = V4L2_PIX_FMT_YUYV; in uvcg_video_init()
400 video->bpp = 16; in uvcg_video_init()
401 video->width = 320; in uvcg_video_init()
402 video->height = 240; in uvcg_video_init()
403 video->imagesize = 320 * 240 * 2; in uvcg_video_init()
405 /* Initialize the video buffers queue. */ in uvcg_video_init()
406 uvcg_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT, in uvcg_video_init()
407 &video->mutex); in uvcg_video_init()