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()
148 struct uvc_video *video = req->context; in uvc_video_complete() local
149 struct uvc_video_queue *queue = &video->queue; in uvc_video_complete()
157 uvcg_dbg(&video->uvc->func, "VS request cancelled.\n"); in uvc_video_complete()
162 uvcg_warn(&video->uvc->func, in uvc_video_complete()
168 spin_lock_irqsave(&video->req_lock, flags); in uvc_video_complete()
169 list_add_tail(&req->list, &video->req_free); in uvc_video_complete()
170 spin_unlock_irqrestore(&video->req_lock, flags); in uvc_video_complete()
172 schedule_work(&video->pump); in uvc_video_complete()
176 uvc_video_free_requests(struct uvc_video *video) in uvc_video_free_requests() argument
181 if (video->req[i]) { in uvc_video_free_requests()
182 usb_ep_free_request(video->ep, video->req[i]); in uvc_video_free_requests()
183 video->req[i] = NULL; in uvc_video_free_requests()
186 if (video->req_buffer[i]) { in uvc_video_free_requests()
187 kfree(video->req_buffer[i]); in uvc_video_free_requests()
188 video->req_buffer[i] = NULL; in uvc_video_free_requests()
192 INIT_LIST_HEAD(&video->req_free); in uvc_video_free_requests()
193 video->req_size = 0; in uvc_video_free_requests()
198 uvc_video_alloc_requests(struct uvc_video *video) in uvc_video_alloc_requests() argument
204 BUG_ON(video->req_size); in uvc_video_alloc_requests()
206 req_size = video->ep->maxpacket in uvc_video_alloc_requests()
207 * max_t(unsigned int, video->ep->maxburst, 1) in uvc_video_alloc_requests()
208 * (video->ep->mult); in uvc_video_alloc_requests()
211 video->req_buffer[i] = kmalloc(req_size, GFP_KERNEL); in uvc_video_alloc_requests()
212 if (video->req_buffer[i] == NULL) in uvc_video_alloc_requests()
215 video->req[i] = usb_ep_alloc_request(video->ep, GFP_KERNEL); in uvc_video_alloc_requests()
216 if (video->req[i] == NULL) in uvc_video_alloc_requests()
219 video->req[i]->buf = video->req_buffer[i]; in uvc_video_alloc_requests()
220 video->req[i]->length = 0; in uvc_video_alloc_requests()
221 video->req[i]->complete = uvc_video_complete; in uvc_video_alloc_requests()
222 video->req[i]->context = video; in uvc_video_alloc_requests()
224 list_add_tail(&video->req[i]->list, &video->req_free); in uvc_video_alloc_requests()
227 video->req_size = req_size; in uvc_video_alloc_requests()
232 uvc_video_free_requests(video); in uvc_video_alloc_requests()
237 * Video streaming
241 * uvcg_video_pump - Pump video data into the USB requests
244 * video data from the queued buffers.
248 struct uvc_video *video = container_of(work, struct uvc_video, pump); in uvcg_video_pump() local
249 struct uvc_video_queue *queue = &video->queue; in uvcg_video_pump()
259 spin_lock_irqsave(&video->req_lock, flags); in uvcg_video_pump()
260 if (list_empty(&video->req_free)) { in uvcg_video_pump()
261 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
264 req = list_first_entry(&video->req_free, struct usb_request, in uvcg_video_pump()
267 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
269 /* Retrieve the first available video buffer and fill the in uvcg_video_pump()
270 * request, protected by the video queue irqlock. in uvcg_video_pump()
279 video->encode(req, video, buf); in uvcg_video_pump()
282 ret = uvcg_video_ep_queue(video, req); in uvcg_video_pump()
291 spin_lock_irqsave(&video->req_lock, flags); in uvcg_video_pump()
292 list_add_tail(&req->list, &video->req_free); in uvcg_video_pump()
293 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
298 * Enable or disable the video stream.
300 int uvcg_video_enable(struct uvc_video *video, int enable) in uvcg_video_enable() argument
305 if (video->ep == NULL) { in uvcg_video_enable()
306 uvcg_info(&video->uvc->func, in uvcg_video_enable()
307 "Video enable failed, device is uninitialized.\n"); in uvcg_video_enable()
312 cancel_work_sync(&video->pump); in uvcg_video_enable()
313 uvcg_queue_cancel(&video->queue, 0); in uvcg_video_enable()
316 if (video->req[i]) in uvcg_video_enable()
317 usb_ep_dequeue(video->ep, video->req[i]); in uvcg_video_enable()
319 uvc_video_free_requests(video); in uvcg_video_enable()
320 uvcg_queue_enable(&video->queue, 0); in uvcg_video_enable()
324 if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) in uvcg_video_enable()
327 if ((ret = uvc_video_alloc_requests(video)) < 0) in uvcg_video_enable()
330 if (video->max_payload_size) { in uvcg_video_enable()
331 video->encode = uvc_video_encode_bulk; in uvcg_video_enable()
332 video->payload_size = 0; in uvcg_video_enable()
334 video->encode = uvc_video_encode_isoc; in uvcg_video_enable()
336 schedule_work(&video->pump); in uvcg_video_enable()
342 * Initialize the UVC video stream.
344 int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc) in uvcg_video_init() argument
346 INIT_LIST_HEAD(&video->req_free); in uvcg_video_init()
347 spin_lock_init(&video->req_lock); in uvcg_video_init()
348 INIT_WORK(&video->pump, uvcg_video_pump); in uvcg_video_init()
350 video->uvc = uvc; in uvcg_video_init()
351 video->fcc = V4L2_PIX_FMT_YUYV; in uvcg_video_init()
352 video->bpp = 16; in uvcg_video_init()
353 video->width = 320; in uvcg_video_init()
354 video->height = 240; in uvcg_video_init()
355 video->imagesize = 320 * 240 * 2; in uvcg_video_init()
357 /* Initialize the video buffers queue. */ in uvcg_video_init()
358 uvcg_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT, in uvcg_video_init()
359 &video->mutex); in uvcg_video_init()