Lines Matching defs:video

14 #include <linux/usb/video.h>
28 uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf,
31 struct uvc_device *uvc = container_of(video, struct uvc_device, video);
36 data[1] = UVC_STREAM_EOH | video->fid;
38 if (video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE)
41 if (video->queue.buf_used == 0 && ts.tv_sec) {
65 if (buf->bytesused - video->queue.buf_used <= len - pos)
72 uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf,
75 struct uvc_video_queue *queue = &video->queue;
79 /* Copy video data to the USB buffer. */
90 uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
95 int len = video->req_size;
99 if (video->payload_size == 0) {
100 ret = uvc_video_encode_header(video, buf, mem, len);
101 video->payload_size += ret;
106 /* Process video data. */
107 len = min((int)(video->max_payload_size - video->payload_size), len);
108 ret = uvc_video_encode_data(video, buf, mem, len);
110 video->payload_size += ret;
113 req->length = video->req_size - len;
114 req->zero = video->payload_size == video->max_payload_size;
116 if (buf->bytesused == video->queue.buf_used) {
117 video->queue.buf_used = 0;
120 video->fid ^= UVC_STREAM_FID;
123 video->payload_size = 0;
126 if (video->payload_size == video->max_payload_size ||
127 video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE ||
128 buf->bytesused == video->queue.buf_used)
129 video->payload_size = 0;
133 uvc_video_encode_isoc_sg(struct usb_request *req, struct uvc_video *video,
136 unsigned int pending = buf->bytesused - video->queue.buf_used;
139 unsigned int len = video->req_size;
148 header_len = uvc_video_encode_header(video, buf, ureq->header,
149 video->req_size);
157 len + header_len : video->req_size;
180 /* Assign the video data with header. */
186 video->queue.buf_used += req->length - header_len;
188 if (buf->bytesused == video->queue.buf_used || !buf->sg ||
189 video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) {
190 video->queue.buf_used = 0;
194 video->fid ^= UVC_STREAM_FID;
200 uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
205 int len = video->req_size;
209 ret = uvc_video_encode_header(video, buf, mem, len);
213 /* Process video data. */
214 ret = uvc_video_encode_data(video, buf, mem, len);
217 req->length = video->req_size - len;
219 if (buf->bytesused == video->queue.buf_used ||
220 video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) {
221 video->queue.buf_used = 0;
224 video->fid ^= UVC_STREAM_FID;
255 static int uvcg_video_ep_queue(struct uvc_video *video, struct usb_request *req)
259 ret = usb_ep_queue(video->ep, req, GFP_ATOMIC);
261 uvcg_err(&video->uvc->func, "Failed to queue request (%d).\n",
265 if (video->ep->desc) {
267 if (usb_endpoint_xfer_bulk(video->ep->desc))
268 usb_ep_set_halt(video->ep);
275 /* This function must be called with video->req_lock held. */
276 static int uvcg_video_usb_req_queue(struct uvc_video *video,
279 bool is_bulk = video->max_payload_size;
282 if (!video->is_enabled)
296 * - When this is request is the last request for the video
297 * buffer, as we want to start sending the next video buffer
302 * indicated by video->uvc_num_requests), as a trade-off
305 if (list_empty(&video->req_free) || ureq->last_buf ||
306 !(video->req_int_count %
307 DIV_ROUND_UP(video->uvc_num_requests, 4))) {
308 video->req_int_count = 0;
313 video->req_int_count++;
314 return uvcg_video_ep_queue(video, req);
320 list = is_bulk ? &video->req_free : &video->req_ready;
331 static void uvc_video_ep_queue_initial_requests(struct uvc_video *video)
346 unsigned int half_list_size = video->uvc_num_requests / 2;
348 spin_lock_irqsave(&video->req_lock, flags);
355 req = list_first_entry(&video->req_free, struct usb_request,
359 ret = uvcg_video_ep_queue(video, req);
361 uvcg_queue_cancel(&video->queue, 0);
366 spin_unlock_irqrestore(&video->req_lock, flags);
373 struct uvc_video *video = ureq->video;
374 struct uvc_video_queue *queue = &video->queue;
378 bool is_bulk = video->max_payload_size;
381 spin_lock_irqsave(&video->req_lock, flags);
382 if (!video->is_enabled) {
390 spin_unlock_irqrestore(&video->req_lock, flags);
396 spin_unlock_irqrestore(&video->req_lock, flags);
403 uvcg_dbg(&video->uvc->func, "VS request missed xfer.\n");
409 uvcg_dbg(&video->uvc->func, "VS request cancelled.\n");
414 uvcg_warn(&video->uvc->func,
426 spin_lock_irqsave(&video->req_lock, flags);
433 if (!video->is_enabled) {
435 spin_unlock_irqrestore(&video->req_lock, flags);
452 if (!list_empty(&video->req_ready)) {
453 to_queue = list_first_entry(&video->req_ready,
456 list_add_tail(&req->list, &video->req_free);
468 queue_work(video->async_wq, &video->pump);
475 ret = uvcg_video_usb_req_queue(video, to_queue, !is_bulk);
482 list_add_tail(&to_queue->list, &video->req_free);
485 spin_unlock_irqrestore(&video->req_lock, flags);
489 uvc_video_free_requests(struct uvc_video *video)
493 list_for_each_entry_safe(ureq, temp, &video->ureqs, list)
494 uvc_video_free_request(ureq, video->ep);
496 INIT_LIST_HEAD(&video->ureqs);
497 INIT_LIST_HEAD(&video->req_free);
498 INIT_LIST_HEAD(&video->req_ready);
499 video->req_size = 0;
504 uvc_video_alloc_requests(struct uvc_video *video)
511 BUG_ON(video->req_size);
513 req_size = video->ep->maxpacket
514 * max_t(unsigned int, video->ep->maxburst, 1)
515 * (video->ep->mult);
517 for (i = 0; i < video->uvc_num_requests; i++) {
524 list_add_tail(&ureq->list, &video->ureqs);
530 ureq->req = usb_ep_alloc_request(video->ep, GFP_KERNEL);
538 ureq->video = video;
541 list_add_tail(&ureq->req->list, &video->req_free);
548 video->req_size = req_size;
553 uvc_video_free_requests(video);
562 * uvcg_video_pump - Pump video data into the USB requests
565 * video data from the queued buffers.
569 struct uvc_video *video = container_of(work, struct uvc_video, pump);
570 struct uvc_video_queue *queue = &video->queue;
571 /* video->max_payload_size is only set when using bulk transfer */
572 bool is_bulk = video->max_payload_size;
579 if (!video->ep->enabled)
586 spin_lock_irqsave(&video->req_lock, flags);
587 if (!video->is_enabled || list_empty(&video->req_free)) {
588 spin_unlock_irqrestore(&video->req_lock, flags);
591 req = list_first_entry(&video->req_free, struct usb_request,
594 spin_unlock_irqrestore(&video->req_lock, flags);
597 * Retrieve the first available video buffer and fill the
598 * request, protected by the video queue irqlock.
604 * Either the queue has been disconnected or no video buffer
612 video->encode(req, video, buf);
616 spin_lock_irqsave(&video->req_lock, flags);
623 ret = uvcg_video_usb_req_queue(video, req, is_bulk);
624 spin_unlock_irqrestore(&video->req_lock, flags);
631 spin_lock_irqsave(&video->req_lock, flags);
632 if (video->is_enabled)
633 list_add_tail(&req->list, &video->req_free);
635 uvc_video_free_request(req->context, video->ep);
636 spin_unlock_irqrestore(&video->req_lock, flags);
640 * Disable the video stream
643 uvcg_video_disable(struct uvc_video *video)
651 if (video->ep == NULL) {
652 uvcg_info(&video->uvc->func,
658 spin_lock_irqsave(&video->req_lock, flags);
659 video->is_enabled = false;
668 list_for_each_entry(ureq, &video->ureqs, list) {
674 spin_unlock_irqrestore(&video->req_lock, flags);
676 cancel_work_sync(&video->pump);
677 uvcg_queue_cancel(&video->queue, 0);
679 spin_lock_irqsave(&video->req_lock, flags);
686 list_for_each_entry_safe(ureq, utemp, &video->ureqs, list)
689 list_for_each_entry_safe(req, temp, &video->req_free, list) {
691 uvc_video_free_request(req->context, video->ep);
694 list_for_each_entry_safe(req, temp, &video->req_ready, list) {
696 uvc_video_free_request(req->context, video->ep);
699 INIT_LIST_HEAD(&video->ureqs);
700 INIT_LIST_HEAD(&video->req_free);
701 INIT_LIST_HEAD(&video->req_ready);
702 video->req_size = 0;
703 spin_unlock_irqrestore(&video->req_lock, flags);
706 * Return all the video buffers before disabling the queue.
708 spin_lock_irqsave(&video->queue.irqlock, flags);
711 uvcg_complete_buffer(&video->queue, buf);
713 spin_unlock_irqrestore(&video->queue.irqlock, flags);
715 uvcg_queue_enable(&video->queue, 0);
720 * Enable the video stream.
722 int uvcg_video_enable(struct uvc_video *video)
726 if (video->ep == NULL) {
727 uvcg_info(&video->uvc->func,
738 video->is_enabled = true;
740 if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0)
743 if ((ret = uvc_video_alloc_requests(video)) < 0)
746 if (video->max_payload_size) {
747 video->encode = uvc_video_encode_bulk;
748 video->payload_size = 0;
750 video->encode = video->queue.use_sg ?
753 video->req_int_count = 0;
755 uvc_video_ep_queue_initial_requests(video);
761 * Initialize the UVC video stream.
763 int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc)
765 video->is_enabled = false;
766 INIT_LIST_HEAD(&video->ureqs);
767 INIT_LIST_HEAD(&video->req_free);
768 INIT_LIST_HEAD(&video->req_ready);
769 spin_lock_init(&video->req_lock);
770 INIT_WORK(&video->pump, uvcg_video_pump);
772 /* Allocate a work queue for asynchronous video pump handler. */
773 video->async_wq = alloc_workqueue("uvcgadget", WQ_UNBOUND | WQ_HIGHPRI, 0);
774 if (!video->async_wq)
777 video->uvc = uvc;
778 video->fcc = V4L2_PIX_FMT_YUYV;
779 video->bpp = 16;
780 video->width = 320;
781 video->height = 240;
782 video->imagesize = 320 * 240 * 2;
784 /* Initialize the video buffers queue. */
785 uvcg_queue_init(&video->queue, uvc->v4l2_dev.dev->parent,
786 V4L2_BUF_TYPE_VIDEO_OUTPUT, &video->mutex);