Lines Matching refs:stream
137 static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, in uvc_fixup_video_ctrl() argument
156 if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) && in uvc_fixup_video_ctrl()
160 uvc_dbg(stream->dev, VIDEO, in uvc_fixup_video_ctrl()
168 for (i = 0; i < stream->nformats; ++i) { in uvc_fixup_video_ctrl()
169 if (stream->formats[i].index == ctrl->bFormatIndex) { in uvc_fixup_video_ctrl()
170 format = &stream->formats[i]; in uvc_fixup_video_ctrl()
190 stream->dev->uvc_version < 0x0110)) in uvc_fixup_video_ctrl()
204 stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && in uvc_fixup_video_ctrl()
205 stream->intf->num_altsetting > 1) { in uvc_fixup_video_ctrl()
223 if (stream->dev->udev->speed >= USB_SPEED_HIGH) in uvc_fixup_video_ctrl()
241 static size_t uvc_video_ctrl_size(struct uvc_streaming *stream) in uvc_video_ctrl_size() argument
247 if (stream->dev->uvc_version < 0x0110) in uvc_video_ctrl_size()
249 else if (stream->dev->uvc_version < 0x0150) in uvc_video_ctrl_size()
255 static int uvc_get_video_ctrl(struct uvc_streaming *stream, in uvc_get_video_ctrl() argument
258 u16 size = uvc_video_ctrl_size(stream); in uvc_get_video_ctrl()
262 if ((stream->dev->quirks & UVC_QUIRK_PROBE_DEF) && in uvc_get_video_ctrl()
270 ret = __uvc_query_ctrl(stream->dev, query, 0, stream->intfnum, in uvc_get_video_ctrl()
280 uvc_warn_once(stream->dev, UVC_WARN_MINMAX, "UVC non " in uvc_get_video_ctrl()
293 uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non " in uvc_get_video_ctrl()
299 dev_err(&stream->intf->dev, in uvc_get_video_ctrl()
325 ctrl->dwClockFrequency = stream->dev->clock_frequency; in uvc_get_video_ctrl()
337 uvc_fixup_video_ctrl(stream, ctrl); in uvc_get_video_ctrl()
345 static int uvc_set_video_ctrl(struct uvc_streaming *stream, in uvc_set_video_ctrl() argument
348 u16 size = uvc_video_ctrl_size(stream); in uvc_set_video_ctrl()
376 ret = __uvc_query_ctrl(stream->dev, UVC_SET_CUR, 0, stream->intfnum, in uvc_set_video_ctrl()
380 dev_err(&stream->intf->dev, in uvc_set_video_ctrl()
390 int uvc_probe_video(struct uvc_streaming *stream, in uvc_probe_video() argument
405 ret = uvc_set_video_ctrl(stream, probe, 1); in uvc_probe_video()
410 if (!(stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { in uvc_probe_video()
411 ret = uvc_get_video_ctrl(stream, &probe_min, 1, UVC_GET_MIN); in uvc_probe_video()
414 ret = uvc_get_video_ctrl(stream, &probe_max, 1, UVC_GET_MAX); in uvc_probe_video()
422 ret = uvc_set_video_ctrl(stream, probe, 1); in uvc_probe_video()
425 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_probe_video()
429 if (stream->intf->num_altsetting == 1) in uvc_probe_video()
432 if (probe->dwMaxPayloadTransferSize <= stream->maxpsize) in uvc_probe_video()
435 if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { in uvc_probe_video()
451 static int uvc_commit_video(struct uvc_streaming *stream, in uvc_commit_video() argument
454 return uvc_set_video_ctrl(stream, probe, 0); in uvc_commit_video()
470 uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, in uvc_video_clock_decode() argument
527 if (dev_sof == stream->clock.last_sof) in uvc_video_clock_decode()
558 stream->clock.last_sof = dev_sof; in uvc_video_clock_decode()
560 host_sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_clock_decode()
569 if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) in uvc_video_clock_decode()
594 if (stream->clock.sof_offset == (u16)-1) { in uvc_video_clock_decode()
597 stream->clock.sof_offset = delta_sof; in uvc_video_clock_decode()
599 stream->clock.sof_offset = 0; in uvc_video_clock_decode()
602 dev_sof = (dev_sof + stream->clock.sof_offset) & 2047; in uvc_video_clock_decode()
604 spin_lock_irqsave(&stream->clock.lock, flags); in uvc_video_clock_decode()
606 sample = &stream->clock.samples[stream->clock.head]; in uvc_video_clock_decode()
613 stream->clock.head = (stream->clock.head + 1) % stream->clock.size; in uvc_video_clock_decode()
615 if (stream->clock.count < stream->clock.size) in uvc_video_clock_decode()
616 stream->clock.count++; in uvc_video_clock_decode()
618 spin_unlock_irqrestore(&stream->clock.lock, flags); in uvc_video_clock_decode()
621 static void uvc_video_clock_reset(struct uvc_streaming *stream) in uvc_video_clock_reset() argument
623 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_reset()
631 static int uvc_video_clock_init(struct uvc_streaming *stream) in uvc_video_clock_init() argument
633 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_init()
643 uvc_video_clock_reset(stream); in uvc_video_clock_init()
648 static void uvc_video_clock_cleanup(struct uvc_streaming *stream) in uvc_video_clock_cleanup() argument
650 kfree(stream->clock.samples); in uvc_video_clock_cleanup()
651 stream->clock.samples = NULL; in uvc_video_clock_cleanup()
742 void uvc_video_clock_update(struct uvc_streaming *stream, in uvc_video_clock_update() argument
746 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_update()
795 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
797 stream->dev->name, buf->pts, in uvc_video_clock_update()
831 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
833 stream->dev->name, in uvc_video_clock_update()
850 static void uvc_video_stats_decode(struct uvc_streaming *stream, in uvc_video_stats_decode() argument
860 if (stream->stats.stream.nb_frames == 0 && in uvc_video_stats_decode()
861 stream->stats.frame.nb_packets == 0) in uvc_video_stats_decode()
862 stream->stats.stream.start_ts = ktime_get(); in uvc_video_stats_decode()
885 stream->stats.frame.nb_invalid++; in uvc_video_stats_decode()
899 if (has_pts && stream->stats.frame.nb_pts) { in uvc_video_stats_decode()
900 if (stream->stats.frame.pts != pts) { in uvc_video_stats_decode()
901 stream->stats.frame.nb_pts_diffs++; in uvc_video_stats_decode()
902 stream->stats.frame.last_pts_diff = in uvc_video_stats_decode()
903 stream->stats.frame.nb_packets; in uvc_video_stats_decode()
908 stream->stats.frame.nb_pts++; in uvc_video_stats_decode()
909 stream->stats.frame.pts = pts; in uvc_video_stats_decode()
916 if (stream->stats.frame.size == 0) { in uvc_video_stats_decode()
918 stream->stats.frame.has_initial_pts = has_pts; in uvc_video_stats_decode()
920 stream->stats.frame.has_early_pts = true; in uvc_video_stats_decode()
924 if (has_scr && stream->stats.frame.nb_scr) { in uvc_video_stats_decode()
925 if (stream->stats.frame.scr_stc != scr_stc) in uvc_video_stats_decode()
926 stream->stats.frame.nb_scr_diffs++; in uvc_video_stats_decode()
931 if (stream->stats.stream.nb_frames > 0 || in uvc_video_stats_decode()
932 stream->stats.frame.nb_scr > 0) in uvc_video_stats_decode()
933 stream->stats.stream.scr_sof_count += in uvc_video_stats_decode()
934 (scr_sof - stream->stats.stream.scr_sof) % 2048; in uvc_video_stats_decode()
935 stream->stats.stream.scr_sof = scr_sof; in uvc_video_stats_decode()
937 stream->stats.frame.nb_scr++; in uvc_video_stats_decode()
938 stream->stats.frame.scr_stc = scr_stc; in uvc_video_stats_decode()
939 stream->stats.frame.scr_sof = scr_sof; in uvc_video_stats_decode()
941 if (scr_sof < stream->stats.stream.min_sof) in uvc_video_stats_decode()
942 stream->stats.stream.min_sof = scr_sof; in uvc_video_stats_decode()
943 if (scr_sof > stream->stats.stream.max_sof) in uvc_video_stats_decode()
944 stream->stats.stream.max_sof = scr_sof; in uvc_video_stats_decode()
948 if (stream->stats.frame.size == 0 && len > header_size) in uvc_video_stats_decode()
949 stream->stats.frame.first_data = stream->stats.frame.nb_packets; in uvc_video_stats_decode()
952 stream->stats.frame.size += len - header_size; in uvc_video_stats_decode()
955 stream->stats.frame.nb_packets++; in uvc_video_stats_decode()
957 stream->stats.frame.nb_empty++; in uvc_video_stats_decode()
960 stream->stats.frame.nb_errors++; in uvc_video_stats_decode()
963 static void uvc_video_stats_update(struct uvc_streaming *stream) in uvc_video_stats_update() argument
965 struct uvc_stats_frame *frame = &stream->stats.frame; in uvc_video_stats_update()
967 uvc_dbg(stream->dev, STATS, in uvc_video_stats_update()
969 stream->sequence, frame->first_data, in uvc_video_stats_update()
977 stream->stats.stream.nb_frames++; in uvc_video_stats_update()
978 stream->stats.stream.nb_packets += stream->stats.frame.nb_packets; in uvc_video_stats_update()
979 stream->stats.stream.nb_empty += stream->stats.frame.nb_empty; in uvc_video_stats_update()
980 stream->stats.stream.nb_errors += stream->stats.frame.nb_errors; in uvc_video_stats_update()
981 stream->stats.stream.nb_invalid += stream->stats.frame.nb_invalid; in uvc_video_stats_update()
984 stream->stats.stream.nb_pts_early++; in uvc_video_stats_update()
986 stream->stats.stream.nb_pts_initial++; in uvc_video_stats_update()
988 stream->stats.stream.nb_pts_constant++; in uvc_video_stats_update()
990 stream->stats.stream.nb_scr_count_ok++; in uvc_video_stats_update()
992 stream->stats.stream.nb_scr_diffs_ok++; in uvc_video_stats_update()
994 memset(&stream->stats.frame, 0, sizeof(stream->stats.frame)); in uvc_video_stats_update()
997 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, in uvc_video_stats_dump() argument
1008 duration = ktime_ms_delta(stream->stats.stream.stop_ts, in uvc_video_stats_dump()
1009 stream->stats.stream.start_ts); in uvc_video_stats_dump()
1011 scr_sof_freq = stream->stats.stream.scr_sof_count * 1000 in uvc_video_stats_dump()
1019 stream->stats.stream.nb_frames, in uvc_video_stats_dump()
1020 stream->stats.stream.nb_packets, in uvc_video_stats_dump()
1021 stream->stats.stream.nb_empty, in uvc_video_stats_dump()
1022 stream->stats.stream.nb_errors, in uvc_video_stats_dump()
1023 stream->stats.stream.nb_invalid); in uvc_video_stats_dump()
1026 stream->stats.stream.nb_pts_early, in uvc_video_stats_dump()
1027 stream->stats.stream.nb_pts_initial, in uvc_video_stats_dump()
1028 stream->stats.stream.nb_pts_constant); in uvc_video_stats_dump()
1031 stream->stats.stream.nb_scr_count_ok, in uvc_video_stats_dump()
1032 stream->stats.stream.nb_scr_diffs_ok); in uvc_video_stats_dump()
1035 stream->stats.stream.min_sof, in uvc_video_stats_dump()
1036 stream->stats.stream.max_sof, in uvc_video_stats_dump()
1042 static void uvc_video_stats_start(struct uvc_streaming *stream) in uvc_video_stats_start() argument
1044 memset(&stream->stats, 0, sizeof(stream->stats)); in uvc_video_stats_start()
1045 stream->stats.stream.min_sof = 2048; in uvc_video_stats_start()
1048 static void uvc_video_stats_stop(struct uvc_streaming *stream) in uvc_video_stats_stop() argument
1050 stream->stats.stream.stop_ts = ktime_get(); in uvc_video_stats_stop()
1093 static int uvc_video_decode_start(struct uvc_streaming *stream, in uvc_video_decode_start() argument
1105 stream->stats.frame.nb_invalid++; in uvc_video_decode_start()
1115 if (stream->last_fid != fid) { in uvc_video_decode_start()
1116 stream->sequence++; in uvc_video_decode_start()
1117 if (stream->sequence) in uvc_video_decode_start()
1118 uvc_video_stats_update(stream); in uvc_video_decode_start()
1121 uvc_video_clock_decode(stream, buf, data, len); in uvc_video_decode_start()
1122 uvc_video_stats_decode(stream, data, len); in uvc_video_decode_start()
1129 stream->last_fid = fid; in uvc_video_decode_start()
1135 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1150 if (fid == stream->last_fid) { in uvc_video_decode_start()
1151 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1153 if ((stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && in uvc_video_decode_start()
1155 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_start()
1160 buf->buf.sequence = stream->sequence; in uvc_video_decode_start()
1183 if (fid != stream->last_fid && buf->bytesused != 0) { in uvc_video_decode_start()
1184 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1190 stream->last_fid = fid; in uvc_video_decode_start()
1196 struct uvc_streaming *stream) in uvc_stream_dir() argument
1198 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) in uvc_stream_dir()
1204 static inline struct device *uvc_stream_to_dmadev(struct uvc_streaming *stream) in uvc_stream_to_dmadev() argument
1206 return bus_to_hcd(stream->dev->udev->bus)->self.sysdev; in uvc_stream_to_dmadev()
1212 dma_sync_sgtable_for_device(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_submit_urb()
1214 uvc_stream_dir(uvc_urb->stream)); in uvc_submit_urb()
1241 dev_err(&uvc_urb->stream->intf->dev, in uvc_video_copy_data_work()
1269 uvc_dbg(uvc_urb->stream->dev, FRAME, in uvc_video_decode_data()
1278 static void uvc_video_decode_end(struct uvc_streaming *stream, in uvc_video_decode_end() argument
1283 uvc_dbg(stream->dev, FRAME, "Frame complete (EOF found)\n"); in uvc_video_decode_end()
1285 uvc_dbg(stream->dev, FRAME, "EOF in empty payload\n"); in uvc_video_decode_end()
1287 if (stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) in uvc_video_decode_end()
1288 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_end()
1304 static int uvc_video_encode_header(struct uvc_streaming *stream, in uvc_video_encode_header() argument
1309 | (stream->last_fid & UVC_STREAM_FID); in uvc_video_encode_header()
1313 static int uvc_video_encode_data(struct uvc_streaming *stream, in uvc_video_encode_data() argument
1316 struct uvc_video_queue *queue = &stream->queue; in uvc_video_encode_data()
1323 nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size, in uvc_video_encode_data()
1347 static void uvc_video_decode_meta(struct uvc_streaming *stream, in uvc_video_decode_meta() argument
1381 if (stream->meta.format == V4L2_META_FMT_UVC) in uvc_video_decode_meta()
1385 !memcmp(scr, stream->clock.last_scr, 6))) in uvc_video_decode_meta()
1391 sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_decode_meta()
1397 memcpy(stream->clock.last_scr, scr, 6); in uvc_video_decode_meta()
1404 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_meta()
1420 static void uvc_video_validate_buffer(const struct uvc_streaming *stream, in uvc_video_validate_buffer() argument
1423 if (stream->ctrl.dwMaxVideoFrameSize != buf->bytesused && in uvc_video_validate_buffer()
1424 !(stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)) in uvc_video_validate_buffer()
1432 static void uvc_video_next_buffers(struct uvc_streaming *stream, in uvc_video_next_buffers() argument
1435 uvc_video_validate_buffer(stream, *video_buf); in uvc_video_next_buffers()
1448 *meta_buf = uvc_queue_next_buffer(&stream->meta.queue, in uvc_video_next_buffers()
1451 *video_buf = uvc_queue_next_buffer(&stream->queue, *video_buf); in uvc_video_next_buffers()
1458 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_isoc() local
1464 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_isoc()
1476 ret = uvc_video_decode_start(stream, buf, mem, in uvc_video_decode_isoc()
1479 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1485 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_isoc()
1492 uvc_video_decode_end(stream, buf, mem, in uvc_video_decode_isoc()
1496 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1504 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_bulk() local
1512 if (urb->actual_length == 0 && stream->bulk.header_size == 0) in uvc_video_decode_bulk()
1517 stream->bulk.payload_size += len; in uvc_video_decode_bulk()
1523 if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) { in uvc_video_decode_bulk()
1525 ret = uvc_video_decode_start(stream, buf, mem, len); in uvc_video_decode_bulk()
1527 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1532 stream->bulk.skip_payload = 1; in uvc_video_decode_bulk()
1534 memcpy(stream->bulk.header, mem, ret); in uvc_video_decode_bulk()
1535 stream->bulk.header_size = ret; in uvc_video_decode_bulk()
1537 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_bulk()
1551 if (!stream->bulk.skip_payload && buf != NULL) in uvc_video_decode_bulk()
1559 stream->bulk.payload_size >= stream->bulk.max_payload_size) { in uvc_video_decode_bulk()
1560 if (!stream->bulk.skip_payload && buf != NULL) { in uvc_video_decode_bulk()
1561 uvc_video_decode_end(stream, buf, stream->bulk.header, in uvc_video_decode_bulk()
1562 stream->bulk.payload_size); in uvc_video_decode_bulk()
1564 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1567 stream->bulk.header_size = 0; in uvc_video_decode_bulk()
1568 stream->bulk.skip_payload = 0; in uvc_video_decode_bulk()
1569 stream->bulk.payload_size = 0; in uvc_video_decode_bulk()
1577 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_encode_bulk() local
1580 int len = stream->urb_size, ret; in uvc_video_encode_bulk()
1588 if (stream->bulk.header_size == 0) { in uvc_video_encode_bulk()
1589 ret = uvc_video_encode_header(stream, buf, mem, len); in uvc_video_encode_bulk()
1590 stream->bulk.header_size = ret; in uvc_video_encode_bulk()
1591 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1597 ret = uvc_video_encode_data(stream, buf, mem, len); in uvc_video_encode_bulk()
1599 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1602 if (buf->bytesused == stream->queue.buf_used || in uvc_video_encode_bulk()
1603 stream->bulk.payload_size == stream->bulk.max_payload_size) { in uvc_video_encode_bulk()
1604 if (buf->bytesused == stream->queue.buf_used) { in uvc_video_encode_bulk()
1605 stream->queue.buf_used = 0; in uvc_video_encode_bulk()
1607 buf->buf.sequence = ++stream->sequence; in uvc_video_encode_bulk()
1608 uvc_queue_next_buffer(&stream->queue, buf); in uvc_video_encode_bulk()
1609 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_encode_bulk()
1612 stream->bulk.header_size = 0; in uvc_video_encode_bulk()
1613 stream->bulk.payload_size = 0; in uvc_video_encode_bulk()
1616 urb->transfer_buffer_length = stream->urb_size - len; in uvc_video_encode_bulk()
1622 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_complete() local
1623 struct uvc_video_queue *queue = &stream->queue; in uvc_video_complete()
1624 struct uvc_video_queue *qmeta = &stream->meta.queue; in uvc_video_complete()
1625 struct vb2_queue *vb2_qmeta = stream->meta.vdev.queue; in uvc_video_complete()
1636 dev_warn(&stream->intf->dev, in uvc_video_complete()
1641 if (stream->frozen) in uvc_video_complete()
1666 dma_sync_sgtable_for_cpu(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_video_complete()
1667 uvc_urb->sgt, uvc_stream_dir(stream)); in uvc_video_complete()
1669 uvc_urb->stream->urb_size); in uvc_video_complete()
1675 stream->decode(uvc_urb, buf, buf_meta); in uvc_video_complete()
1681 dev_err(&stream->intf->dev, in uvc_video_complete()
1686 queue_work(stream->async_wq, &uvc_urb->work); in uvc_video_complete()
1692 static void uvc_free_urb_buffers(struct uvc_streaming *stream) in uvc_free_urb_buffers() argument
1694 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_free_urb_buffers()
1697 for_each_uvc_urb(uvc_urb, stream) { in uvc_free_urb_buffers()
1702 dma_free_noncontiguous(dma_dev, stream->urb_size, uvc_urb->sgt, in uvc_free_urb_buffers()
1703 uvc_stream_dir(stream)); in uvc_free_urb_buffers()
1709 stream->urb_size = 0; in uvc_free_urb_buffers()
1712 static bool uvc_alloc_urb_buffer(struct uvc_streaming *stream, in uvc_alloc_urb_buffer() argument
1715 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_alloc_urb_buffer()
1717 uvc_urb->sgt = dma_alloc_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1718 uvc_stream_dir(stream), in uvc_alloc_urb_buffer()
1724 uvc_urb->buffer = dma_vmap_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1727 dma_free_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1729 uvc_stream_dir(stream)); in uvc_alloc_urb_buffer()
1748 static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, in uvc_alloc_urb_buffers() argument
1755 if (stream->urb_size) in uvc_alloc_urb_buffers()
1756 return stream->urb_size / psize; in uvc_alloc_urb_buffers()
1768 stream->urb_size = psize * npackets; in uvc_alloc_urb_buffers()
1771 struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; in uvc_alloc_urb_buffers()
1773 if (!uvc_alloc_urb_buffer(stream, uvc_urb, gfp_flags)) { in uvc_alloc_urb_buffers()
1774 uvc_free_urb_buffers(stream); in uvc_alloc_urb_buffers()
1778 uvc_urb->stream = stream; in uvc_alloc_urb_buffers()
1782 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1789 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1798 static void uvc_video_stop_transfer(struct uvc_streaming *stream, in uvc_video_stop_transfer() argument
1803 uvc_video_stats_stop(stream); in uvc_video_stop_transfer()
1810 for_each_uvc_urb(uvc_urb, stream) in uvc_video_stop_transfer()
1813 flush_workqueue(stream->async_wq); in uvc_video_stop_transfer()
1815 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_stop_transfer()
1821 uvc_free_urb_buffers(stream); in uvc_video_stop_transfer()
1846 static int uvc_init_video_isoc(struct uvc_streaming *stream, in uvc_init_video_isoc() argument
1855 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_init_video_isoc()
1856 size = stream->ctrl.dwMaxVideoFrameSize; in uvc_init_video_isoc()
1858 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_isoc()
1864 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_isoc()
1867 uvc_video_stop_transfer(stream, 1); in uvc_init_video_isoc()
1871 urb->dev = stream->dev->udev; in uvc_init_video_isoc()
1873 urb->pipe = usb_rcvisocpipe(stream->dev->udev, in uvc_init_video_isoc()
1898 static int uvc_init_video_bulk(struct uvc_streaming *stream, in uvc_init_video_bulk() argument
1908 size = stream->ctrl.dwMaxPayloadTransferSize; in uvc_init_video_bulk()
1909 stream->bulk.max_payload_size = size; in uvc_init_video_bulk()
1911 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_bulk()
1918 pipe = usb_rcvbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1921 pipe = usb_sndbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1924 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) in uvc_init_video_bulk()
1927 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_bulk()
1930 uvc_video_stop_transfer(stream, 1); in uvc_init_video_bulk()
1934 usb_fill_bulk_urb(urb, stream->dev->udev, pipe, uvc_urb->buffer, in uvc_init_video_bulk()
1948 static int uvc_video_start_transfer(struct uvc_streaming *stream, in uvc_video_start_transfer() argument
1951 struct usb_interface *intf = stream->intf; in uvc_video_start_transfer()
1957 stream->sequence = -1; in uvc_video_start_transfer()
1958 stream->last_fid = -1; in uvc_video_start_transfer()
1959 stream->bulk.header_size = 0; in uvc_video_start_transfer()
1960 stream->bulk.skip_payload = 0; in uvc_video_start_transfer()
1961 stream->bulk.payload_size = 0; in uvc_video_start_transfer()
1963 uvc_video_stats_start(stream); in uvc_video_start_transfer()
1970 int intfnum = stream->intfnum; in uvc_video_start_transfer()
1973 bandwidth = stream->ctrl.dwMaxPayloadTransferSize; in uvc_video_start_transfer()
1976 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
1980 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
1991 stream->header.bEndpointAddress); in uvc_video_start_transfer()
1996 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_video_start_transfer()
2005 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2010 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2019 if (stream->dev->quirks & UVC_QUIRK_WAKE_AUTOSUSPEND) { in uvc_video_start_transfer()
2020 usb_set_interface(stream->dev->udev, intfnum, in uvc_video_start_transfer()
2022 usb_set_interface(stream->dev->udev, intfnum, 0); in uvc_video_start_transfer()
2025 ret = usb_set_interface(stream->dev->udev, intfnum, altsetting); in uvc_video_start_transfer()
2029 ret = uvc_init_video_isoc(stream, best_ep, gfp_flags); in uvc_video_start_transfer()
2033 stream->header.bEndpointAddress); in uvc_video_start_transfer()
2041 ret = uvc_init_video_bulk(stream, ep, gfp_flags); in uvc_video_start_transfer()
2048 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_start_transfer()
2051 dev_err(&stream->intf->dev, in uvc_video_start_transfer()
2054 uvc_video_stop_transfer(stream, 1); in uvc_video_start_transfer()
2063 if (stream->dev->quirks & UVC_QUIRK_RESTORE_CTRLS_ON_INIT) in uvc_video_start_transfer()
2064 uvc_ctrl_restore_values(stream->dev); in uvc_video_start_transfer()
2080 int uvc_video_suspend(struct uvc_streaming *stream) in uvc_video_suspend() argument
2082 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_suspend()
2085 stream->frozen = 1; in uvc_video_suspend()
2086 uvc_video_stop_transfer(stream, 0); in uvc_video_suspend()
2087 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_suspend()
2099 int uvc_video_resume(struct uvc_streaming *stream, int reset) in uvc_video_resume() argument
2110 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_resume()
2112 stream->frozen = 0; in uvc_video_resume()
2114 uvc_video_clock_reset(stream); in uvc_video_resume()
2116 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_resume()
2119 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_resume()
2123 return uvc_video_start_transfer(stream, GFP_NOIO); in uvc_video_resume()
2140 int uvc_video_init(struct uvc_streaming *stream) in uvc_video_init() argument
2142 struct uvc_streaming_control *probe = &stream->ctrl; in uvc_video_init()
2149 if (stream->nformats == 0) { in uvc_video_init()
2150 dev_info(&stream->intf->dev, in uvc_video_init()
2155 atomic_set(&stream->active, 0); in uvc_video_init()
2163 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_init()
2171 if (uvc_get_video_ctrl(stream, probe, 1, UVC_GET_DEF) == 0) in uvc_video_init()
2172 uvc_set_video_ctrl(stream, probe, 1); in uvc_video_init()
2180 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_video_init()
2190 usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k)) { in uvc_video_init()
2191 dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n"); in uvc_video_init()
2192 dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n"); in uvc_video_init()
2193 usb_reset_device(stream->dev->udev); in uvc_video_init()
2203 for (i = stream->nformats; i > 0; --i) { in uvc_video_init()
2204 format = &stream->formats[i-1]; in uvc_video_init()
2210 dev_info(&stream->intf->dev, in uvc_video_init()
2230 stream->def_format = format; in uvc_video_init()
2231 stream->cur_format = format; in uvc_video_init()
2232 stream->cur_frame = frame; in uvc_video_init()
2235 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { in uvc_video_init()
2236 if (stream->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) in uvc_video_init()
2237 stream->decode = uvc_video_decode_isight; in uvc_video_init()
2238 else if (stream->intf->num_altsetting > 1) in uvc_video_init()
2239 stream->decode = uvc_video_decode_isoc; in uvc_video_init()
2241 stream->decode = uvc_video_decode_bulk; in uvc_video_init()
2243 if (stream->intf->num_altsetting == 1) in uvc_video_init()
2244 stream->decode = uvc_video_encode_bulk; in uvc_video_init()
2246 dev_info(&stream->intf->dev, in uvc_video_init()
2253 for_each_uvc_urb(uvc_urb, stream) in uvc_video_init()
2259 int uvc_video_start_streaming(struct uvc_streaming *stream) in uvc_video_start_streaming() argument
2263 ret = uvc_video_clock_init(stream); in uvc_video_start_streaming()
2268 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_start_streaming()
2272 ret = uvc_video_start_transfer(stream, GFP_KERNEL); in uvc_video_start_streaming()
2279 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_start_streaming()
2281 uvc_video_clock_cleanup(stream); in uvc_video_start_streaming()
2286 void uvc_video_stop_streaming(struct uvc_streaming *stream) in uvc_video_stop_streaming() argument
2288 uvc_video_stop_transfer(stream, 1); in uvc_video_stop_streaming()
2290 if (stream->intf->num_altsetting > 1) { in uvc_video_stop_streaming()
2291 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_stop_streaming()
2299 unsigned int epnum = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2301 unsigned int dir = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2305 pipe = usb_sndbulkpipe(stream->dev->udev, epnum) | dir; in uvc_video_stop_streaming()
2306 usb_clear_halt(stream->dev->udev, pipe); in uvc_video_stop_streaming()
2309 uvc_video_clock_cleanup(stream); in uvc_video_stop_streaming()