Lines Matching full:stream
132 static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, in uvc_fixup_video_ctrl() argument
154 if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) && in uvc_fixup_video_ctrl()
158 uvc_dbg(stream->dev, VIDEO, in uvc_fixup_video_ctrl()
166 for (i = 0; i < stream->nformats; ++i) { in uvc_fixup_video_ctrl()
167 if (stream->format[i].index == ctrl->bFormatIndex) { in uvc_fixup_video_ctrl()
168 format = &stream->format[i]; in uvc_fixup_video_ctrl()
188 stream->dev->uvc_version < 0x0110)) in uvc_fixup_video_ctrl()
202 stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && in uvc_fixup_video_ctrl()
203 stream->intf->num_altsetting > 1) { in uvc_fixup_video_ctrl()
221 if (stream->dev->udev->speed == USB_SPEED_HIGH) in uvc_fixup_video_ctrl()
239 static size_t uvc_video_ctrl_size(struct uvc_streaming *stream) in uvc_video_ctrl_size() argument
245 if (stream->dev->uvc_version < 0x0110) in uvc_video_ctrl_size()
247 else if (stream->dev->uvc_version < 0x0150) in uvc_video_ctrl_size()
253 static int uvc_get_video_ctrl(struct uvc_streaming *stream, in uvc_get_video_ctrl() argument
256 u16 size = uvc_video_ctrl_size(stream); in uvc_get_video_ctrl()
260 if ((stream->dev->quirks & UVC_QUIRK_PROBE_DEF) && in uvc_get_video_ctrl()
268 ret = __uvc_query_ctrl(stream->dev, query, 0, stream->intfnum, in uvc_get_video_ctrl()
278 uvc_warn_once(stream->dev, UVC_WARN_MINMAX, "UVC non " in uvc_get_video_ctrl()
291 uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non " in uvc_get_video_ctrl()
297 dev_err(&stream->intf->dev, in uvc_get_video_ctrl()
323 ctrl->dwClockFrequency = stream->dev->clock_frequency; in uvc_get_video_ctrl()
335 uvc_fixup_video_ctrl(stream, ctrl); in uvc_get_video_ctrl()
343 static int uvc_set_video_ctrl(struct uvc_streaming *stream, in uvc_set_video_ctrl() argument
346 u16 size = uvc_video_ctrl_size(stream); in uvc_set_video_ctrl()
374 ret = __uvc_query_ctrl(stream->dev, UVC_SET_CUR, 0, stream->intfnum, in uvc_set_video_ctrl()
378 dev_err(&stream->intf->dev, in uvc_set_video_ctrl()
388 int uvc_probe_video(struct uvc_streaming *stream, in uvc_probe_video() argument
403 ret = uvc_set_video_ctrl(stream, probe, 1); in uvc_probe_video()
408 if (!(stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { in uvc_probe_video()
409 ret = uvc_get_video_ctrl(stream, &probe_min, 1, UVC_GET_MIN); in uvc_probe_video()
412 ret = uvc_get_video_ctrl(stream, &probe_max, 1, UVC_GET_MAX); in uvc_probe_video()
420 ret = uvc_set_video_ctrl(stream, probe, 1); in uvc_probe_video()
423 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_probe_video()
427 if (stream->intf->num_altsetting == 1) in uvc_probe_video()
430 if (probe->dwMaxPayloadTransferSize <= stream->maxpsize) in uvc_probe_video()
433 if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { in uvc_probe_video()
449 static int uvc_commit_video(struct uvc_streaming *stream, in uvc_commit_video() argument
452 return uvc_set_video_ctrl(stream, probe, 0); in uvc_commit_video()
468 uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, in uvc_video_clock_decode() argument
522 if (dev_sof == stream->clock.last_sof) in uvc_video_clock_decode()
525 stream->clock.last_sof = dev_sof; in uvc_video_clock_decode()
527 host_sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_clock_decode()
550 if (stream->clock.sof_offset == (u16)-1) { in uvc_video_clock_decode()
553 stream->clock.sof_offset = delta_sof; in uvc_video_clock_decode()
555 stream->clock.sof_offset = 0; in uvc_video_clock_decode()
558 dev_sof = (dev_sof + stream->clock.sof_offset) & 2047; in uvc_video_clock_decode()
560 spin_lock_irqsave(&stream->clock.lock, flags); in uvc_video_clock_decode()
562 sample = &stream->clock.samples[stream->clock.head]; in uvc_video_clock_decode()
569 stream->clock.head = (stream->clock.head + 1) % stream->clock.size; in uvc_video_clock_decode()
571 if (stream->clock.count < stream->clock.size) in uvc_video_clock_decode()
572 stream->clock.count++; in uvc_video_clock_decode()
574 spin_unlock_irqrestore(&stream->clock.lock, flags); in uvc_video_clock_decode()
577 static void uvc_video_clock_reset(struct uvc_streaming *stream) in uvc_video_clock_reset() argument
579 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_reset()
587 static int uvc_video_clock_init(struct uvc_streaming *stream) in uvc_video_clock_init() argument
589 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_init()
599 uvc_video_clock_reset(stream); in uvc_video_clock_init()
604 static void uvc_video_clock_cleanup(struct uvc_streaming *stream) in uvc_video_clock_cleanup() argument
606 kfree(stream->clock.samples); in uvc_video_clock_cleanup()
607 stream->clock.samples = NULL; in uvc_video_clock_cleanup()
698 void uvc_video_clock_update(struct uvc_streaming *stream, in uvc_video_clock_update() argument
702 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_update()
751 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
753 stream->dev->name, buf->pts, in uvc_video_clock_update()
787 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
789 stream->dev->name, in uvc_video_clock_update()
803 * Stream statistics
806 static void uvc_video_stats_decode(struct uvc_streaming *stream, in uvc_video_stats_decode() argument
816 if (stream->stats.stream.nb_frames == 0 && in uvc_video_stats_decode()
817 stream->stats.frame.nb_packets == 0) in uvc_video_stats_decode()
818 stream->stats.stream.start_ts = ktime_get(); in uvc_video_stats_decode()
841 stream->stats.frame.nb_invalid++; in uvc_video_stats_decode()
855 if (has_pts && stream->stats.frame.nb_pts) { in uvc_video_stats_decode()
856 if (stream->stats.frame.pts != pts) { in uvc_video_stats_decode()
857 stream->stats.frame.nb_pts_diffs++; in uvc_video_stats_decode()
858 stream->stats.frame.last_pts_diff = in uvc_video_stats_decode()
859 stream->stats.frame.nb_packets; in uvc_video_stats_decode()
864 stream->stats.frame.nb_pts++; in uvc_video_stats_decode()
865 stream->stats.frame.pts = pts; in uvc_video_stats_decode()
872 if (stream->stats.frame.size == 0) { in uvc_video_stats_decode()
874 stream->stats.frame.has_initial_pts = has_pts; in uvc_video_stats_decode()
876 stream->stats.frame.has_early_pts = true; in uvc_video_stats_decode()
880 if (has_scr && stream->stats.frame.nb_scr) { in uvc_video_stats_decode()
881 if (stream->stats.frame.scr_stc != scr_stc) in uvc_video_stats_decode()
882 stream->stats.frame.nb_scr_diffs++; in uvc_video_stats_decode()
887 if (stream->stats.stream.nb_frames > 0 || in uvc_video_stats_decode()
888 stream->stats.frame.nb_scr > 0) in uvc_video_stats_decode()
889 stream->stats.stream.scr_sof_count += in uvc_video_stats_decode()
890 (scr_sof - stream->stats.stream.scr_sof) % 2048; in uvc_video_stats_decode()
891 stream->stats.stream.scr_sof = scr_sof; in uvc_video_stats_decode()
893 stream->stats.frame.nb_scr++; in uvc_video_stats_decode()
894 stream->stats.frame.scr_stc = scr_stc; in uvc_video_stats_decode()
895 stream->stats.frame.scr_sof = scr_sof; in uvc_video_stats_decode()
897 if (scr_sof < stream->stats.stream.min_sof) in uvc_video_stats_decode()
898 stream->stats.stream.min_sof = scr_sof; in uvc_video_stats_decode()
899 if (scr_sof > stream->stats.stream.max_sof) in uvc_video_stats_decode()
900 stream->stats.stream.max_sof = scr_sof; in uvc_video_stats_decode()
904 if (stream->stats.frame.size == 0 && len > header_size) in uvc_video_stats_decode()
905 stream->stats.frame.first_data = stream->stats.frame.nb_packets; in uvc_video_stats_decode()
908 stream->stats.frame.size += len - header_size; in uvc_video_stats_decode()
911 stream->stats.frame.nb_packets++; in uvc_video_stats_decode()
913 stream->stats.frame.nb_empty++; in uvc_video_stats_decode()
916 stream->stats.frame.nb_errors++; in uvc_video_stats_decode()
919 static void uvc_video_stats_update(struct uvc_streaming *stream) in uvc_video_stats_update() argument
921 struct uvc_stats_frame *frame = &stream->stats.frame; in uvc_video_stats_update()
923 uvc_dbg(stream->dev, STATS, in uvc_video_stats_update()
925 stream->sequence, frame->first_data, in uvc_video_stats_update()
933 stream->stats.stream.nb_frames++; in uvc_video_stats_update()
934 stream->stats.stream.nb_packets += stream->stats.frame.nb_packets; in uvc_video_stats_update()
935 stream->stats.stream.nb_empty += stream->stats.frame.nb_empty; in uvc_video_stats_update()
936 stream->stats.stream.nb_errors += stream->stats.frame.nb_errors; in uvc_video_stats_update()
937 stream->stats.stream.nb_invalid += stream->stats.frame.nb_invalid; in uvc_video_stats_update()
940 stream->stats.stream.nb_pts_early++; in uvc_video_stats_update()
942 stream->stats.stream.nb_pts_initial++; in uvc_video_stats_update()
944 stream->stats.stream.nb_pts_constant++; in uvc_video_stats_update()
946 stream->stats.stream.nb_scr_count_ok++; in uvc_video_stats_update()
948 stream->stats.stream.nb_scr_diffs_ok++; in uvc_video_stats_update()
950 memset(&stream->stats.frame, 0, sizeof(stream->stats.frame)); in uvc_video_stats_update()
953 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, in uvc_video_stats_dump() argument
964 duration = ktime_ms_delta(stream->stats.stream.stop_ts, in uvc_video_stats_dump()
965 stream->stats.stream.start_ts); in uvc_video_stats_dump()
967 scr_sof_freq = stream->stats.stream.scr_sof_count * 1000 in uvc_video_stats_dump()
975 stream->stats.stream.nb_frames, in uvc_video_stats_dump()
976 stream->stats.stream.nb_packets, in uvc_video_stats_dump()
977 stream->stats.stream.nb_empty, in uvc_video_stats_dump()
978 stream->stats.stream.nb_errors, in uvc_video_stats_dump()
979 stream->stats.stream.nb_invalid); in uvc_video_stats_dump()
982 stream->stats.stream.nb_pts_early, in uvc_video_stats_dump()
983 stream->stats.stream.nb_pts_initial, in uvc_video_stats_dump()
984 stream->stats.stream.nb_pts_constant); in uvc_video_stats_dump()
987 stream->stats.stream.nb_scr_count_ok, in uvc_video_stats_dump()
988 stream->stats.stream.nb_scr_diffs_ok); in uvc_video_stats_dump()
991 stream->stats.stream.min_sof, in uvc_video_stats_dump()
992 stream->stats.stream.max_sof, in uvc_video_stats_dump()
998 static void uvc_video_stats_start(struct uvc_streaming *stream) in uvc_video_stats_start() argument
1000 memset(&stream->stats, 0, sizeof(stream->stats)); in uvc_video_stats_start()
1001 stream->stats.stream.min_sof = 2048; in uvc_video_stats_start()
1004 static void uvc_video_stats_stop(struct uvc_streaming *stream) in uvc_video_stats_stop() argument
1006 stream->stats.stream.stop_ts = ktime_get(); in uvc_video_stats_stop()
1049 static int uvc_video_decode_start(struct uvc_streaming *stream, in uvc_video_decode_start() argument
1061 stream->stats.frame.nb_invalid++; in uvc_video_decode_start()
1071 if (stream->last_fid != fid) { in uvc_video_decode_start()
1072 stream->sequence++; in uvc_video_decode_start()
1073 if (stream->sequence) in uvc_video_decode_start()
1074 uvc_video_stats_update(stream); in uvc_video_decode_start()
1077 uvc_video_clock_decode(stream, buf, data, len); in uvc_video_decode_start()
1078 uvc_video_stats_decode(stream, data, len); in uvc_video_decode_start()
1085 stream->last_fid = fid; in uvc_video_decode_start()
1091 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1097 * Synchronize to the input stream by waiting for the FID bit to be in uvc_video_decode_start()
1099 * stream->last_fid is initialized to -1, so the first isochronous in uvc_video_decode_start()
1102 * If the device doesn't toggle the FID bit, invert stream->last_fid in uvc_video_decode_start()
1106 if (fid == stream->last_fid) { in uvc_video_decode_start()
1107 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1109 if ((stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && in uvc_video_decode_start()
1111 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_start()
1116 buf->buf.sequence = stream->sequence; in uvc_video_decode_start()
1131 * stream->last_fid is initialized to -1, so the first isochronous in uvc_video_decode_start()
1139 if (fid != stream->last_fid && buf->bytesused != 0) { in uvc_video_decode_start()
1140 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1146 stream->last_fid = fid; in uvc_video_decode_start()
1152 struct uvc_streaming *stream) in uvc_stream_dir() argument
1154 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) in uvc_stream_dir()
1160 static inline struct device *uvc_stream_to_dmadev(struct uvc_streaming *stream) in uvc_stream_to_dmadev() argument
1162 return bus_to_hcd(stream->dev->udev->bus)->self.sysdev; in uvc_stream_to_dmadev()
1168 dma_sync_sgtable_for_device(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_submit_urb()
1170 uvc_stream_dir(uvc_urb->stream)); in uvc_submit_urb()
1197 dev_err(&uvc_urb->stream->intf->dev, in uvc_video_copy_data_work()
1225 uvc_dbg(uvc_urb->stream->dev, FRAME, in uvc_video_decode_data()
1234 static void uvc_video_decode_end(struct uvc_streaming *stream, in uvc_video_decode_end() argument
1239 uvc_dbg(stream->dev, FRAME, "Frame complete (EOF found)\n"); in uvc_video_decode_end()
1241 uvc_dbg(stream->dev, FRAME, "EOF in empty payload\n"); in uvc_video_decode_end()
1243 if (stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) in uvc_video_decode_end()
1244 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_end()
1260 static int uvc_video_encode_header(struct uvc_streaming *stream, in uvc_video_encode_header() argument
1265 | (stream->last_fid & UVC_STREAM_FID); in uvc_video_encode_header()
1269 static int uvc_video_encode_data(struct uvc_streaming *stream, in uvc_video_encode_data() argument
1272 struct uvc_video_queue *queue = &stream->queue; in uvc_video_encode_data()
1279 nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size, in uvc_video_encode_data()
1303 static void uvc_video_decode_meta(struct uvc_streaming *stream, in uvc_video_decode_meta() argument
1337 if (stream->meta.format == V4L2_META_FMT_UVC) in uvc_video_decode_meta()
1341 !memcmp(scr, stream->clock.last_scr, 6))) in uvc_video_decode_meta()
1347 sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_decode_meta()
1353 memcpy(stream->clock.last_scr, scr, 6); in uvc_video_decode_meta()
1358 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_meta()
1374 static void uvc_video_validate_buffer(const struct uvc_streaming *stream, in uvc_video_validate_buffer() argument
1377 if (stream->ctrl.dwMaxVideoFrameSize != buf->bytesused && in uvc_video_validate_buffer()
1378 !(stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)) in uvc_video_validate_buffer()
1386 static void uvc_video_next_buffers(struct uvc_streaming *stream, in uvc_video_next_buffers() argument
1389 uvc_video_validate_buffer(stream, *video_buf); in uvc_video_next_buffers()
1402 *meta_buf = uvc_queue_next_buffer(&stream->meta.queue, in uvc_video_next_buffers()
1405 *video_buf = uvc_queue_next_buffer(&stream->queue, *video_buf); in uvc_video_next_buffers()
1412 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_isoc() local
1418 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_isoc()
1430 ret = uvc_video_decode_start(stream, buf, mem, in uvc_video_decode_isoc()
1433 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1439 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_isoc()
1446 uvc_video_decode_end(stream, buf, mem, in uvc_video_decode_isoc()
1450 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1458 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_bulk() local
1466 if (urb->actual_length == 0 && stream->bulk.header_size == 0) in uvc_video_decode_bulk()
1471 stream->bulk.payload_size += len; in uvc_video_decode_bulk()
1477 if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) { in uvc_video_decode_bulk()
1479 ret = uvc_video_decode_start(stream, buf, mem, len); in uvc_video_decode_bulk()
1481 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1486 stream->bulk.skip_payload = 1; in uvc_video_decode_bulk()
1488 memcpy(stream->bulk.header, mem, ret); in uvc_video_decode_bulk()
1489 stream->bulk.header_size = ret; in uvc_video_decode_bulk()
1491 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_bulk()
1505 if (!stream->bulk.skip_payload && buf != NULL) in uvc_video_decode_bulk()
1513 stream->bulk.payload_size >= stream->bulk.max_payload_size) { in uvc_video_decode_bulk()
1514 if (!stream->bulk.skip_payload && buf != NULL) { in uvc_video_decode_bulk()
1515 uvc_video_decode_end(stream, buf, stream->bulk.header, in uvc_video_decode_bulk()
1516 stream->bulk.payload_size); in uvc_video_decode_bulk()
1518 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1521 stream->bulk.header_size = 0; in uvc_video_decode_bulk()
1522 stream->bulk.skip_payload = 0; in uvc_video_decode_bulk()
1523 stream->bulk.payload_size = 0; in uvc_video_decode_bulk()
1531 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_encode_bulk() local
1534 int len = stream->urb_size, ret; in uvc_video_encode_bulk()
1542 if (stream->bulk.header_size == 0) { in uvc_video_encode_bulk()
1543 ret = uvc_video_encode_header(stream, buf, mem, len); in uvc_video_encode_bulk()
1544 stream->bulk.header_size = ret; in uvc_video_encode_bulk()
1545 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1551 ret = uvc_video_encode_data(stream, buf, mem, len); in uvc_video_encode_bulk()
1553 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1556 if (buf->bytesused == stream->queue.buf_used || in uvc_video_encode_bulk()
1557 stream->bulk.payload_size == stream->bulk.max_payload_size) { in uvc_video_encode_bulk()
1558 if (buf->bytesused == stream->queue.buf_used) { in uvc_video_encode_bulk()
1559 stream->queue.buf_used = 0; in uvc_video_encode_bulk()
1561 buf->buf.sequence = ++stream->sequence; in uvc_video_encode_bulk()
1562 uvc_queue_next_buffer(&stream->queue, buf); in uvc_video_encode_bulk()
1563 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_encode_bulk()
1566 stream->bulk.header_size = 0; in uvc_video_encode_bulk()
1567 stream->bulk.payload_size = 0; in uvc_video_encode_bulk()
1570 urb->transfer_buffer_length = stream->urb_size - len; in uvc_video_encode_bulk()
1576 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_complete() local
1577 struct uvc_video_queue *queue = &stream->queue; in uvc_video_complete()
1578 struct uvc_video_queue *qmeta = &stream->meta.queue; in uvc_video_complete()
1579 struct vb2_queue *vb2_qmeta = stream->meta.vdev.queue; in uvc_video_complete()
1590 dev_warn(&stream->intf->dev, in uvc_video_complete()
1595 if (stream->frozen) in uvc_video_complete()
1620 dma_sync_sgtable_for_cpu(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_video_complete()
1621 uvc_urb->sgt, uvc_stream_dir(stream)); in uvc_video_complete()
1623 uvc_urb->stream->urb_size); in uvc_video_complete()
1629 stream->decode(uvc_urb, buf, buf_meta); in uvc_video_complete()
1635 dev_err(&stream->intf->dev, in uvc_video_complete()
1640 queue_work(stream->async_wq, &uvc_urb->work); in uvc_video_complete()
1646 static void uvc_free_urb_buffers(struct uvc_streaming *stream) in uvc_free_urb_buffers() argument
1648 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_free_urb_buffers()
1651 for_each_uvc_urb(uvc_urb, stream) { in uvc_free_urb_buffers()
1656 dma_free_noncontiguous(dma_dev, stream->urb_size, uvc_urb->sgt, in uvc_free_urb_buffers()
1657 uvc_stream_dir(stream)); in uvc_free_urb_buffers()
1663 stream->urb_size = 0; in uvc_free_urb_buffers()
1666 static bool uvc_alloc_urb_buffer(struct uvc_streaming *stream, in uvc_alloc_urb_buffer() argument
1669 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_alloc_urb_buffer()
1671 uvc_urb->sgt = dma_alloc_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1672 uvc_stream_dir(stream), in uvc_alloc_urb_buffer()
1678 uvc_urb->buffer = dma_vmap_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1681 dma_free_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1683 uvc_stream_dir(stream)); in uvc_alloc_urb_buffer()
1702 static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, in uvc_alloc_urb_buffers() argument
1709 if (stream->urb_size) in uvc_alloc_urb_buffers()
1710 return stream->urb_size / psize; in uvc_alloc_urb_buffers()
1722 stream->urb_size = psize * npackets; in uvc_alloc_urb_buffers()
1725 struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; in uvc_alloc_urb_buffers()
1727 if (!uvc_alloc_urb_buffer(stream, uvc_urb, gfp_flags)) { in uvc_alloc_urb_buffers()
1728 uvc_free_urb_buffers(stream); in uvc_alloc_urb_buffers()
1732 uvc_urb->stream = stream; in uvc_alloc_urb_buffers()
1736 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1743 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1752 static void uvc_video_stop_transfer(struct uvc_streaming *stream, in uvc_video_stop_transfer() argument
1757 uvc_video_stats_stop(stream); in uvc_video_stop_transfer()
1764 for_each_uvc_urb(uvc_urb, stream) in uvc_video_stop_transfer()
1767 flush_workqueue(stream->async_wq); in uvc_video_stop_transfer()
1769 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_stop_transfer()
1775 uvc_free_urb_buffers(stream); in uvc_video_stop_transfer()
1800 static int uvc_init_video_isoc(struct uvc_streaming *stream, in uvc_init_video_isoc() argument
1809 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_init_video_isoc()
1810 size = stream->ctrl.dwMaxVideoFrameSize; in uvc_init_video_isoc()
1812 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_isoc()
1818 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_isoc()
1821 uvc_video_stop_transfer(stream, 1); in uvc_init_video_isoc()
1825 urb->dev = stream->dev->udev; in uvc_init_video_isoc()
1827 urb->pipe = usb_rcvisocpipe(stream->dev->udev, in uvc_init_video_isoc()
1852 static int uvc_init_video_bulk(struct uvc_streaming *stream, in uvc_init_video_bulk() argument
1862 size = stream->ctrl.dwMaxPayloadTransferSize; in uvc_init_video_bulk()
1863 stream->bulk.max_payload_size = size; in uvc_init_video_bulk()
1865 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_bulk()
1872 pipe = usb_rcvbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1875 pipe = usb_sndbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1878 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) in uvc_init_video_bulk()
1881 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_bulk()
1884 uvc_video_stop_transfer(stream, 1); in uvc_init_video_bulk()
1888 usb_fill_bulk_urb(urb, stream->dev->udev, pipe, uvc_urb->buffer, in uvc_init_video_bulk()
1902 static int uvc_video_start_transfer(struct uvc_streaming *stream, in uvc_video_start_transfer() argument
1905 struct usb_interface *intf = stream->intf; in uvc_video_start_transfer()
1911 stream->sequence = -1; in uvc_video_start_transfer()
1912 stream->last_fid = -1; in uvc_video_start_transfer()
1913 stream->bulk.header_size = 0; in uvc_video_start_transfer()
1914 stream->bulk.skip_payload = 0; in uvc_video_start_transfer()
1915 stream->bulk.payload_size = 0; in uvc_video_start_transfer()
1917 uvc_video_stats_start(stream); in uvc_video_start_transfer()
1924 int intfnum = stream->intfnum; in uvc_video_start_transfer()
1927 bandwidth = stream->ctrl.dwMaxPayloadTransferSize; in uvc_video_start_transfer()
1930 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
1934 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
1945 stream->header.bEndpointAddress); in uvc_video_start_transfer()
1950 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_video_start_transfer()
1959 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
1964 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
1968 ret = usb_set_interface(stream->dev->udev, intfnum, altsetting); in uvc_video_start_transfer()
1972 ret = uvc_init_video_isoc(stream, best_ep, gfp_flags); in uvc_video_start_transfer()
1976 stream->header.bEndpointAddress); in uvc_video_start_transfer()
1984 ret = uvc_init_video_bulk(stream, ep, gfp_flags); in uvc_video_start_transfer()
1991 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_start_transfer()
1994 dev_err(&stream->intf->dev, in uvc_video_start_transfer()
1997 uvc_video_stop_transfer(stream, 1); in uvc_video_start_transfer()
2006 if (stream->dev->quirks & UVC_QUIRK_RESTORE_CTRLS_ON_INIT) in uvc_video_start_transfer()
2007 uvc_ctrl_restore_values(stream->dev); in uvc_video_start_transfer()
2023 int uvc_video_suspend(struct uvc_streaming *stream) in uvc_video_suspend() argument
2025 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_suspend()
2028 stream->frozen = 1; in uvc_video_suspend()
2029 uvc_video_stop_transfer(stream, 0); in uvc_video_suspend()
2030 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_suspend()
2042 int uvc_video_resume(struct uvc_streaming *stream, int reset) in uvc_video_resume() argument
2053 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_resume()
2055 stream->frozen = 0; in uvc_video_resume()
2057 uvc_video_clock_reset(stream); in uvc_video_resume()
2059 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_resume()
2062 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_resume()
2066 return uvc_video_start_transfer(stream, GFP_NOIO); in uvc_video_resume()
2083 int uvc_video_init(struct uvc_streaming *stream) in uvc_video_init() argument
2085 struct uvc_streaming_control *probe = &stream->ctrl; in uvc_video_init()
2092 if (stream->nformats == 0) { in uvc_video_init()
2093 dev_info(&stream->intf->dev, in uvc_video_init()
2098 atomic_set(&stream->active, 0); in uvc_video_init()
2106 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_init()
2114 if (uvc_get_video_ctrl(stream, probe, 1, UVC_GET_DEF) == 0) in uvc_video_init()
2115 uvc_set_video_ctrl(stream, probe, 1); in uvc_video_init()
2123 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_video_init()
2131 for (i = stream->nformats; i > 0; --i) { in uvc_video_init()
2132 format = &stream->format[i-1]; in uvc_video_init()
2138 dev_info(&stream->intf->dev, in uvc_video_init()
2144 * Zero bFrameIndex might be correct. Stream-based formats (including in uvc_video_init()
2158 stream->def_format = format; in uvc_video_init()
2159 stream->cur_format = format; in uvc_video_init()
2160 stream->cur_frame = frame; in uvc_video_init()
2163 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { in uvc_video_init()
2164 if (stream->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) in uvc_video_init()
2165 stream->decode = uvc_video_decode_isight; in uvc_video_init()
2166 else if (stream->intf->num_altsetting > 1) in uvc_video_init()
2167 stream->decode = uvc_video_decode_isoc; in uvc_video_init()
2169 stream->decode = uvc_video_decode_bulk; in uvc_video_init()
2171 if (stream->intf->num_altsetting == 1) in uvc_video_init()
2172 stream->decode = uvc_video_encode_bulk; in uvc_video_init()
2174 dev_info(&stream->intf->dev, in uvc_video_init()
2181 for_each_uvc_urb(uvc_urb, stream) in uvc_video_init()
2187 int uvc_video_start_streaming(struct uvc_streaming *stream) in uvc_video_start_streaming() argument
2191 ret = uvc_video_clock_init(stream); in uvc_video_start_streaming()
2196 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_start_streaming()
2200 ret = uvc_video_start_transfer(stream, GFP_KERNEL); in uvc_video_start_streaming()
2207 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_start_streaming()
2209 uvc_video_clock_cleanup(stream); in uvc_video_start_streaming()
2214 void uvc_video_stop_streaming(struct uvc_streaming *stream) in uvc_video_stop_streaming() argument
2216 uvc_video_stop_transfer(stream, 1); in uvc_video_stop_streaming()
2218 if (stream->intf->num_altsetting > 1) { in uvc_video_stop_streaming()
2219 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_stop_streaming()
2223 * when the video stream is stopped. Windows sends a in uvc_video_stop_streaming()
2227 unsigned int epnum = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2229 unsigned int dir = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2233 pipe = usb_sndbulkpipe(stream->dev->udev, epnum) | dir; in uvc_video_stop_streaming()
2234 usb_clear_halt(stream->dev->udev, pipe); in uvc_video_stop_streaming()
2237 uvc_video_clock_cleanup(stream); in uvc_video_stop_streaming()