Lines Matching refs:video
28 uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf, in uvc_video_encode_header() argument
31 struct uvc_device *uvc = container_of(video, struct uvc_device, video); in uvc_video_encode_header()
36 data[1] = UVC_STREAM_EOH | video->fid; in uvc_video_encode_header()
38 if (video->queue.buf_used == 0 && ts.tv_sec) { in uvc_video_encode_header()
62 if (buf->bytesused - video->queue.buf_used <= len - pos) in uvc_video_encode_header()
69 uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf, in uvc_video_encode_data() argument
72 struct uvc_video_queue *queue = &video->queue; in uvc_video_encode_data()
87 uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video, in uvc_video_encode_bulk() argument
92 int len = video->req_size; in uvc_video_encode_bulk()
96 if (video->payload_size == 0) { in uvc_video_encode_bulk()
97 ret = uvc_video_encode_header(video, buf, mem, len); in uvc_video_encode_bulk()
98 video->payload_size += ret; in uvc_video_encode_bulk()
104 len = min((int)(video->max_payload_size - video->payload_size), len); in uvc_video_encode_bulk()
105 ret = uvc_video_encode_data(video, buf, mem, len); in uvc_video_encode_bulk()
107 video->payload_size += ret; in uvc_video_encode_bulk()
110 req->length = video->req_size - len; in uvc_video_encode_bulk()
111 req->zero = video->payload_size == video->max_payload_size; in uvc_video_encode_bulk()
113 if (buf->bytesused == video->queue.buf_used) { in uvc_video_encode_bulk()
114 video->queue.buf_used = 0; in uvc_video_encode_bulk()
117 video->fid ^= UVC_STREAM_FID; in uvc_video_encode_bulk()
120 video->payload_size = 0; in uvc_video_encode_bulk()
123 if (video->payload_size == video->max_payload_size || in uvc_video_encode_bulk()
124 video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE || in uvc_video_encode_bulk()
125 buf->bytesused == video->queue.buf_used) in uvc_video_encode_bulk()
126 video->payload_size = 0; in uvc_video_encode_bulk()
130 uvc_video_encode_isoc_sg(struct usb_request *req, struct uvc_video *video, in uvc_video_encode_isoc_sg() argument
133 unsigned int pending = buf->bytesused - video->queue.buf_used; in uvc_video_encode_isoc_sg()
136 unsigned int len = video->req_size; in uvc_video_encode_isoc_sg()
145 header_len = uvc_video_encode_header(video, buf, ureq->header, in uvc_video_encode_isoc_sg()
146 video->req_size); in uvc_video_encode_isoc_sg()
154 len + header_len : video->req_size; in uvc_video_encode_isoc_sg()
183 video->queue.buf_used += req->length - header_len; in uvc_video_encode_isoc_sg()
185 if (buf->bytesused == video->queue.buf_used || !buf->sg || in uvc_video_encode_isoc_sg()
186 video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) { in uvc_video_encode_isoc_sg()
187 video->queue.buf_used = 0; in uvc_video_encode_isoc_sg()
191 video->fid ^= UVC_STREAM_FID; in uvc_video_encode_isoc_sg()
197 uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video, in uvc_video_encode_isoc() argument
202 int len = video->req_size; in uvc_video_encode_isoc()
206 ret = uvc_video_encode_header(video, buf, mem, len); in uvc_video_encode_isoc()
211 ret = uvc_video_encode_data(video, buf, mem, len); in uvc_video_encode_isoc()
214 req->length = video->req_size - len; in uvc_video_encode_isoc()
216 if (buf->bytesused == video->queue.buf_used || in uvc_video_encode_isoc()
217 video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) { in uvc_video_encode_isoc()
218 video->queue.buf_used = 0; in uvc_video_encode_isoc()
221 video->fid ^= UVC_STREAM_FID; in uvc_video_encode_isoc()
230 static int uvcg_video_ep_queue(struct uvc_video *video, struct usb_request *req) in uvcg_video_ep_queue() argument
234 ret = usb_ep_queue(video->ep, req, GFP_ATOMIC); in uvcg_video_ep_queue()
236 uvcg_err(&video->uvc->func, "Failed to queue request (%d).\n", in uvcg_video_ep_queue()
240 if (video->ep->desc) { in uvcg_video_ep_queue()
242 if (usb_endpoint_xfer_bulk(video->ep->desc)) in uvcg_video_ep_queue()
243 usb_ep_set_halt(video->ep); in uvcg_video_ep_queue()
254 struct uvc_video *video = ureq->video; in uvc_video_complete() local
255 struct uvc_video_queue *queue = &video->queue; in uvc_video_complete()
256 struct uvc_device *uvc = video->uvc; in uvc_video_complete()
264 uvcg_dbg(&video->uvc->func, "VS request missed xfer.\n"); in uvc_video_complete()
269 uvcg_dbg(&video->uvc->func, "VS request cancelled.\n"); in uvc_video_complete()
274 uvcg_warn(&video->uvc->func, in uvc_video_complete()
281 uvcg_complete_buffer(&video->queue, ureq->last_buf); in uvc_video_complete()
285 spin_lock_irqsave(&video->req_lock, flags); in uvc_video_complete()
286 list_add_tail(&req->list, &video->req_free); in uvc_video_complete()
287 spin_unlock_irqrestore(&video->req_lock, flags); in uvc_video_complete()
290 queue_work(video->async_wq, &video->pump); in uvc_video_complete()
294 uvc_video_free_requests(struct uvc_video *video) in uvc_video_free_requests() argument
298 if (video->ureq) { in uvc_video_free_requests()
299 for (i = 0; i < video->uvc_num_requests; ++i) { in uvc_video_free_requests()
300 sg_free_table(&video->ureq[i].sgt); in uvc_video_free_requests()
302 if (video->ureq[i].req) { in uvc_video_free_requests()
303 usb_ep_free_request(video->ep, video->ureq[i].req); in uvc_video_free_requests()
304 video->ureq[i].req = NULL; in uvc_video_free_requests()
307 if (video->ureq[i].req_buffer) { in uvc_video_free_requests()
308 kfree(video->ureq[i].req_buffer); in uvc_video_free_requests()
309 video->ureq[i].req_buffer = NULL; in uvc_video_free_requests()
313 kfree(video->ureq); in uvc_video_free_requests()
314 video->ureq = NULL; in uvc_video_free_requests()
317 INIT_LIST_HEAD(&video->req_free); in uvc_video_free_requests()
318 video->req_size = 0; in uvc_video_free_requests()
323 uvc_video_alloc_requests(struct uvc_video *video) in uvc_video_alloc_requests() argument
329 BUG_ON(video->req_size); in uvc_video_alloc_requests()
331 req_size = video->ep->maxpacket in uvc_video_alloc_requests()
332 * max_t(unsigned int, video->ep->maxburst, 1) in uvc_video_alloc_requests()
333 * (video->ep->mult); in uvc_video_alloc_requests()
335 video->ureq = kcalloc(video->uvc_num_requests, sizeof(struct uvc_request), GFP_KERNEL); in uvc_video_alloc_requests()
336 if (video->ureq == NULL) in uvc_video_alloc_requests()
339 for (i = 0; i < video->uvc_num_requests; ++i) { in uvc_video_alloc_requests()
340 video->ureq[i].req_buffer = kmalloc(req_size, GFP_KERNEL); in uvc_video_alloc_requests()
341 if (video->ureq[i].req_buffer == NULL) in uvc_video_alloc_requests()
344 video->ureq[i].req = usb_ep_alloc_request(video->ep, GFP_KERNEL); in uvc_video_alloc_requests()
345 if (video->ureq[i].req == NULL) in uvc_video_alloc_requests()
348 video->ureq[i].req->buf = video->ureq[i].req_buffer; in uvc_video_alloc_requests()
349 video->ureq[i].req->length = 0; in uvc_video_alloc_requests()
350 video->ureq[i].req->complete = uvc_video_complete; in uvc_video_alloc_requests()
351 video->ureq[i].req->context = &video->ureq[i]; in uvc_video_alloc_requests()
352 video->ureq[i].video = video; in uvc_video_alloc_requests()
353 video->ureq[i].last_buf = NULL; in uvc_video_alloc_requests()
355 list_add_tail(&video->ureq[i].req->list, &video->req_free); in uvc_video_alloc_requests()
357 sg_alloc_table(&video->ureq[i].sgt, in uvc_video_alloc_requests()
362 video->req_size = req_size; in uvc_video_alloc_requests()
367 uvc_video_free_requests(video); in uvc_video_alloc_requests()
383 struct uvc_video *video = container_of(work, struct uvc_video, pump); in uvcg_video_pump() local
384 struct uvc_video_queue *queue = &video->queue; in uvcg_video_pump()
390 while (video->ep->enabled) { in uvcg_video_pump()
395 spin_lock_irqsave(&video->req_lock, flags); in uvcg_video_pump()
396 if (list_empty(&video->req_free)) { in uvcg_video_pump()
397 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
400 req = list_first_entry(&video->req_free, struct usb_request, in uvcg_video_pump()
403 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
416 video->encode(req, video, buf); in uvcg_video_pump()
423 if (list_empty(&video->req_free) || in uvcg_video_pump()
425 !(video->req_int_count % in uvcg_video_pump()
426 DIV_ROUND_UP(video->uvc_num_requests, 4))) { in uvcg_video_pump()
427 video->req_int_count = 0; in uvcg_video_pump()
434 ret = uvcg_video_ep_queue(video, req); in uvcg_video_pump()
445 video->req_int_count++; in uvcg_video_pump()
451 spin_lock_irqsave(&video->req_lock, flags); in uvcg_video_pump()
452 list_add_tail(&req->list, &video->req_free); in uvcg_video_pump()
453 spin_unlock_irqrestore(&video->req_lock, flags); in uvcg_video_pump()
460 int uvcg_video_enable(struct uvc_video *video, int enable) in uvcg_video_enable() argument
465 if (video->ep == NULL) { in uvcg_video_enable()
466 uvcg_info(&video->uvc->func, in uvcg_video_enable()
472 cancel_work_sync(&video->pump); in uvcg_video_enable()
473 uvcg_queue_cancel(&video->queue, 0); in uvcg_video_enable()
475 for (i = 0; i < video->uvc_num_requests; ++i) in uvcg_video_enable()
476 if (video->ureq && video->ureq[i].req) in uvcg_video_enable()
477 usb_ep_dequeue(video->ep, video->ureq[i].req); in uvcg_video_enable()
479 uvc_video_free_requests(video); in uvcg_video_enable()
480 uvcg_queue_enable(&video->queue, 0); in uvcg_video_enable()
484 if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) in uvcg_video_enable()
487 if ((ret = uvc_video_alloc_requests(video)) < 0) in uvcg_video_enable()
490 if (video->max_payload_size) { in uvcg_video_enable()
491 video->encode = uvc_video_encode_bulk; in uvcg_video_enable()
492 video->payload_size = 0; in uvcg_video_enable()
494 video->encode = video->queue.use_sg ? in uvcg_video_enable()
497 video->req_int_count = 0; in uvcg_video_enable()
499 queue_work(video->async_wq, &video->pump); in uvcg_video_enable()
507 int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc) in uvcg_video_init() argument
509 INIT_LIST_HEAD(&video->req_free); in uvcg_video_init()
510 spin_lock_init(&video->req_lock); in uvcg_video_init()
511 INIT_WORK(&video->pump, uvcg_video_pump); in uvcg_video_init()
514 video->async_wq = alloc_workqueue("uvcgadget", WQ_UNBOUND | WQ_HIGHPRI, 0); in uvcg_video_init()
515 if (!video->async_wq) in uvcg_video_init()
518 video->uvc = uvc; in uvcg_video_init()
519 video->fcc = V4L2_PIX_FMT_YUYV; in uvcg_video_init()
520 video->bpp = 16; in uvcg_video_init()
521 video->width = 320; in uvcg_video_init()
522 video->height = 240; in uvcg_video_init()
523 video->imagesize = 320 * 240 * 2; in uvcg_video_init()
526 uvcg_queue_init(&video->queue, uvc->v4l2_dev.dev->parent, in uvcg_video_init()
527 V4L2_BUF_TYPE_VIDEO_OUTPUT, &video->mutex); in uvcg_video_init()