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()
505 uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, in uvc_video_clock_decode() argument
557 if (sample.dev_sof == stream->clock.last_sof) in uvc_video_clock_decode()
588 sample.host_sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_clock_decode()
597 if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) in uvc_video_clock_decode()
622 if (stream->clock.sof_offset == (u16)-1) { in uvc_video_clock_decode()
625 stream->clock.sof_offset = delta_sof; in uvc_video_clock_decode()
627 stream->clock.sof_offset = 0; in uvc_video_clock_decode()
630 sample.dev_sof = (sample.dev_sof + stream->clock.sof_offset) & 2047; in uvc_video_clock_decode()
631 uvc_video_clock_add_sample(&stream->clock, &sample); in uvc_video_clock_decode()
632 stream->clock.last_sof = sample.dev_sof; in uvc_video_clock_decode()
753 void uvc_video_clock_update(struct uvc_streaming *stream, in uvc_video_clock_update() argument
757 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_update()
818 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
820 stream->dev->name, buf->pts, in uvc_video_clock_update()
854 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
856 stream->dev->name, in uvc_video_clock_update()
873 static void uvc_video_stats_decode(struct uvc_streaming *stream, in uvc_video_stats_decode() argument
883 if (stream->stats.stream.nb_frames == 0 && in uvc_video_stats_decode()
884 stream->stats.frame.nb_packets == 0) in uvc_video_stats_decode()
885 stream->stats.stream.start_ts = ktime_get(); in uvc_video_stats_decode()
908 stream->stats.frame.nb_invalid++; in uvc_video_stats_decode()
922 if (has_pts && stream->stats.frame.nb_pts) { in uvc_video_stats_decode()
923 if (stream->stats.frame.pts != pts) { in uvc_video_stats_decode()
924 stream->stats.frame.nb_pts_diffs++; in uvc_video_stats_decode()
925 stream->stats.frame.last_pts_diff = in uvc_video_stats_decode()
926 stream->stats.frame.nb_packets; in uvc_video_stats_decode()
931 stream->stats.frame.nb_pts++; in uvc_video_stats_decode()
932 stream->stats.frame.pts = pts; in uvc_video_stats_decode()
939 if (stream->stats.frame.size == 0) { in uvc_video_stats_decode()
941 stream->stats.frame.has_initial_pts = has_pts; in uvc_video_stats_decode()
943 stream->stats.frame.has_early_pts = true; in uvc_video_stats_decode()
947 if (has_scr && stream->stats.frame.nb_scr) { in uvc_video_stats_decode()
948 if (stream->stats.frame.scr_stc != scr_stc) in uvc_video_stats_decode()
949 stream->stats.frame.nb_scr_diffs++; in uvc_video_stats_decode()
954 if (stream->stats.stream.nb_frames > 0 || in uvc_video_stats_decode()
955 stream->stats.frame.nb_scr > 0) in uvc_video_stats_decode()
956 stream->stats.stream.scr_sof_count += in uvc_video_stats_decode()
957 (scr_sof - stream->stats.stream.scr_sof) % 2048; in uvc_video_stats_decode()
958 stream->stats.stream.scr_sof = scr_sof; in uvc_video_stats_decode()
960 stream->stats.frame.nb_scr++; in uvc_video_stats_decode()
961 stream->stats.frame.scr_stc = scr_stc; in uvc_video_stats_decode()
962 stream->stats.frame.scr_sof = scr_sof; in uvc_video_stats_decode()
964 if (scr_sof < stream->stats.stream.min_sof) in uvc_video_stats_decode()
965 stream->stats.stream.min_sof = scr_sof; in uvc_video_stats_decode()
966 if (scr_sof > stream->stats.stream.max_sof) in uvc_video_stats_decode()
967 stream->stats.stream.max_sof = scr_sof; in uvc_video_stats_decode()
971 if (stream->stats.frame.size == 0 && len > header_size) in uvc_video_stats_decode()
972 stream->stats.frame.first_data = stream->stats.frame.nb_packets; in uvc_video_stats_decode()
975 stream->stats.frame.size += len - header_size; in uvc_video_stats_decode()
978 stream->stats.frame.nb_packets++; in uvc_video_stats_decode()
980 stream->stats.frame.nb_empty++; in uvc_video_stats_decode()
983 stream->stats.frame.nb_errors++; in uvc_video_stats_decode()
986 static void uvc_video_stats_update(struct uvc_streaming *stream) in uvc_video_stats_update() argument
988 struct uvc_stats_frame *frame = &stream->stats.frame; in uvc_video_stats_update()
990 uvc_dbg(stream->dev, STATS, in uvc_video_stats_update()
992 stream->sequence, frame->first_data, in uvc_video_stats_update()
1000 stream->stats.stream.nb_frames++; in uvc_video_stats_update()
1001 stream->stats.stream.nb_packets += stream->stats.frame.nb_packets; in uvc_video_stats_update()
1002 stream->stats.stream.nb_empty += stream->stats.frame.nb_empty; in uvc_video_stats_update()
1003 stream->stats.stream.nb_errors += stream->stats.frame.nb_errors; in uvc_video_stats_update()
1004 stream->stats.stream.nb_invalid += stream->stats.frame.nb_invalid; in uvc_video_stats_update()
1007 stream->stats.stream.nb_pts_early++; in uvc_video_stats_update()
1009 stream->stats.stream.nb_pts_initial++; in uvc_video_stats_update()
1011 stream->stats.stream.nb_pts_constant++; in uvc_video_stats_update()
1013 stream->stats.stream.nb_scr_count_ok++; in uvc_video_stats_update()
1015 stream->stats.stream.nb_scr_diffs_ok++; in uvc_video_stats_update()
1017 memset(&stream->stats.frame, 0, sizeof(stream->stats.frame)); in uvc_video_stats_update()
1020 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, in uvc_video_stats_dump() argument
1031 duration = ktime_ms_delta(stream->stats.stream.stop_ts, in uvc_video_stats_dump()
1032 stream->stats.stream.start_ts); in uvc_video_stats_dump()
1034 scr_sof_freq = stream->stats.stream.scr_sof_count * 1000 in uvc_video_stats_dump()
1042 stream->stats.stream.nb_frames, in uvc_video_stats_dump()
1043 stream->stats.stream.nb_packets, in uvc_video_stats_dump()
1044 stream->stats.stream.nb_empty, in uvc_video_stats_dump()
1045 stream->stats.stream.nb_errors, in uvc_video_stats_dump()
1046 stream->stats.stream.nb_invalid); in uvc_video_stats_dump()
1049 stream->stats.stream.nb_pts_early, in uvc_video_stats_dump()
1050 stream->stats.stream.nb_pts_initial, in uvc_video_stats_dump()
1051 stream->stats.stream.nb_pts_constant); in uvc_video_stats_dump()
1054 stream->stats.stream.nb_scr_count_ok, in uvc_video_stats_dump()
1055 stream->stats.stream.nb_scr_diffs_ok); in uvc_video_stats_dump()
1058 stream->stats.stream.min_sof, in uvc_video_stats_dump()
1059 stream->stats.stream.max_sof, in uvc_video_stats_dump()
1065 static void uvc_video_stats_start(struct uvc_streaming *stream) in uvc_video_stats_start() argument
1067 memset(&stream->stats, 0, sizeof(stream->stats)); in uvc_video_stats_start()
1068 stream->stats.stream.min_sof = 2048; in uvc_video_stats_start()
1071 static void uvc_video_stats_stop(struct uvc_streaming *stream) in uvc_video_stats_stop() argument
1073 stream->stats.stream.stop_ts = ktime_get(); in uvc_video_stats_stop()
1116 static int uvc_video_decode_start(struct uvc_streaming *stream, in uvc_video_decode_start() argument
1128 stream->stats.frame.nb_invalid++; in uvc_video_decode_start()
1138 if (stream->last_fid != fid) { in uvc_video_decode_start()
1139 stream->sequence++; in uvc_video_decode_start()
1140 if (stream->sequence) in uvc_video_decode_start()
1141 uvc_video_stats_update(stream); in uvc_video_decode_start()
1144 uvc_video_clock_decode(stream, buf, data, len); in uvc_video_decode_start()
1145 uvc_video_stats_decode(stream, data, len); in uvc_video_decode_start()
1152 stream->last_fid = fid; in uvc_video_decode_start()
1158 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1173 if (fid == stream->last_fid) { in uvc_video_decode_start()
1174 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1176 if ((stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && in uvc_video_decode_start()
1178 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_start()
1183 buf->buf.sequence = stream->sequence; in uvc_video_decode_start()
1206 if (fid != stream->last_fid && buf->bytesused != 0) { in uvc_video_decode_start()
1207 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1213 stream->last_fid = fid; in uvc_video_decode_start()
1219 struct uvc_streaming *stream) in uvc_stream_dir() argument
1221 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) in uvc_stream_dir()
1227 static inline struct device *uvc_stream_to_dmadev(struct uvc_streaming *stream) in uvc_stream_to_dmadev() argument
1229 return bus_to_hcd(stream->dev->udev->bus)->self.sysdev; in uvc_stream_to_dmadev()
1235 dma_sync_sgtable_for_device(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_submit_urb()
1237 uvc_stream_dir(uvc_urb->stream)); in uvc_submit_urb()
1264 dev_err(&uvc_urb->stream->intf->dev, in uvc_video_copy_data_work()
1292 uvc_dbg(uvc_urb->stream->dev, FRAME, in uvc_video_decode_data()
1301 static void uvc_video_decode_end(struct uvc_streaming *stream, in uvc_video_decode_end() argument
1306 uvc_dbg(stream->dev, FRAME, "Frame complete (EOF found)\n"); in uvc_video_decode_end()
1308 uvc_dbg(stream->dev, FRAME, "EOF in empty payload\n"); in uvc_video_decode_end()
1310 if (stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) in uvc_video_decode_end()
1311 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_end()
1327 static int uvc_video_encode_header(struct uvc_streaming *stream, in uvc_video_encode_header() argument
1332 | (stream->last_fid & UVC_STREAM_FID); in uvc_video_encode_header()
1336 static int uvc_video_encode_data(struct uvc_streaming *stream, in uvc_video_encode_data() argument
1339 struct uvc_video_queue *queue = &stream->queue; in uvc_video_encode_data()
1346 nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size, in uvc_video_encode_data()
1370 static void uvc_video_decode_meta(struct uvc_streaming *stream, in uvc_video_decode_meta() argument
1404 if (stream->meta.format == V4L2_META_FMT_UVC) in uvc_video_decode_meta()
1408 !memcmp(scr, stream->clock.last_scr, 6))) in uvc_video_decode_meta()
1414 sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_decode_meta()
1420 memcpy(stream->clock.last_scr, scr, 6); in uvc_video_decode_meta()
1427 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_meta()
1443 static void uvc_video_validate_buffer(const struct uvc_streaming *stream, in uvc_video_validate_buffer() argument
1446 if (stream->ctrl.dwMaxVideoFrameSize != buf->bytesused && in uvc_video_validate_buffer()
1447 !(stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)) in uvc_video_validate_buffer()
1455 static void uvc_video_next_buffers(struct uvc_streaming *stream, in uvc_video_next_buffers() argument
1458 uvc_video_validate_buffer(stream, *video_buf); in uvc_video_next_buffers()
1471 *meta_buf = uvc_queue_next_buffer(&stream->meta.queue, in uvc_video_next_buffers()
1474 *video_buf = uvc_queue_next_buffer(&stream->queue, *video_buf); in uvc_video_next_buffers()
1481 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_isoc() local
1487 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_isoc()
1499 ret = uvc_video_decode_start(stream, buf, mem, in uvc_video_decode_isoc()
1502 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1508 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_isoc()
1515 uvc_video_decode_end(stream, buf, mem, in uvc_video_decode_isoc()
1519 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1527 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_bulk() local
1535 if (urb->actual_length == 0 && stream->bulk.header_size == 0) in uvc_video_decode_bulk()
1540 stream->bulk.payload_size += len; in uvc_video_decode_bulk()
1546 if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) { in uvc_video_decode_bulk()
1548 ret = uvc_video_decode_start(stream, buf, mem, len); in uvc_video_decode_bulk()
1550 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1555 stream->bulk.skip_payload = 1; in uvc_video_decode_bulk()
1557 memcpy(stream->bulk.header, mem, ret); in uvc_video_decode_bulk()
1558 stream->bulk.header_size = ret; in uvc_video_decode_bulk()
1560 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_bulk()
1574 if (!stream->bulk.skip_payload && buf != NULL) in uvc_video_decode_bulk()
1582 stream->bulk.payload_size >= stream->bulk.max_payload_size) { in uvc_video_decode_bulk()
1583 if (!stream->bulk.skip_payload && buf != NULL) { in uvc_video_decode_bulk()
1584 uvc_video_decode_end(stream, buf, stream->bulk.header, in uvc_video_decode_bulk()
1585 stream->bulk.payload_size); in uvc_video_decode_bulk()
1587 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1590 stream->bulk.header_size = 0; in uvc_video_decode_bulk()
1591 stream->bulk.skip_payload = 0; in uvc_video_decode_bulk()
1592 stream->bulk.payload_size = 0; in uvc_video_decode_bulk()
1600 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_encode_bulk() local
1603 int len = stream->urb_size, ret; in uvc_video_encode_bulk()
1611 if (stream->bulk.header_size == 0) { in uvc_video_encode_bulk()
1612 ret = uvc_video_encode_header(stream, buf, mem, len); in uvc_video_encode_bulk()
1613 stream->bulk.header_size = ret; in uvc_video_encode_bulk()
1614 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1620 ret = uvc_video_encode_data(stream, buf, mem, len); in uvc_video_encode_bulk()
1622 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1625 if (buf->bytesused == stream->queue.buf_used || in uvc_video_encode_bulk()
1626 stream->bulk.payload_size == stream->bulk.max_payload_size) { in uvc_video_encode_bulk()
1627 if (buf->bytesused == stream->queue.buf_used) { in uvc_video_encode_bulk()
1628 stream->queue.buf_used = 0; in uvc_video_encode_bulk()
1630 buf->buf.sequence = ++stream->sequence; in uvc_video_encode_bulk()
1631 uvc_queue_next_buffer(&stream->queue, buf); in uvc_video_encode_bulk()
1632 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_encode_bulk()
1635 stream->bulk.header_size = 0; in uvc_video_encode_bulk()
1636 stream->bulk.payload_size = 0; in uvc_video_encode_bulk()
1639 urb->transfer_buffer_length = stream->urb_size - len; in uvc_video_encode_bulk()
1645 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_complete() local
1646 struct uvc_video_queue *queue = &stream->queue; in uvc_video_complete()
1647 struct uvc_video_queue *qmeta = &stream->meta.queue; in uvc_video_complete()
1648 struct vb2_queue *vb2_qmeta = stream->meta.vdev.queue; in uvc_video_complete()
1659 dev_warn(&stream->intf->dev, in uvc_video_complete()
1664 if (stream->frozen) in uvc_video_complete()
1689 dma_sync_sgtable_for_cpu(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_video_complete()
1690 uvc_urb->sgt, uvc_stream_dir(stream)); in uvc_video_complete()
1692 uvc_urb->stream->urb_size); in uvc_video_complete()
1698 stream->decode(uvc_urb, buf, buf_meta); in uvc_video_complete()
1704 dev_err(&stream->intf->dev, in uvc_video_complete()
1709 queue_work(stream->async_wq, &uvc_urb->work); in uvc_video_complete()
1715 static void uvc_free_urb_buffers(struct uvc_streaming *stream) in uvc_free_urb_buffers() argument
1717 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_free_urb_buffers()
1720 for_each_uvc_urb(uvc_urb, stream) { in uvc_free_urb_buffers()
1725 dma_free_noncontiguous(dma_dev, stream->urb_size, uvc_urb->sgt, in uvc_free_urb_buffers()
1726 uvc_stream_dir(stream)); in uvc_free_urb_buffers()
1732 stream->urb_size = 0; in uvc_free_urb_buffers()
1735 static bool uvc_alloc_urb_buffer(struct uvc_streaming *stream, in uvc_alloc_urb_buffer() argument
1738 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_alloc_urb_buffer()
1740 uvc_urb->sgt = dma_alloc_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1741 uvc_stream_dir(stream), in uvc_alloc_urb_buffer()
1747 uvc_urb->buffer = dma_vmap_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1750 dma_free_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1752 uvc_stream_dir(stream)); in uvc_alloc_urb_buffer()
1771 static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, in uvc_alloc_urb_buffers() argument
1778 if (stream->urb_size) in uvc_alloc_urb_buffers()
1779 return stream->urb_size / psize; in uvc_alloc_urb_buffers()
1791 stream->urb_size = psize * npackets; in uvc_alloc_urb_buffers()
1794 struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; in uvc_alloc_urb_buffers()
1796 if (!uvc_alloc_urb_buffer(stream, uvc_urb, gfp_flags)) { in uvc_alloc_urb_buffers()
1797 uvc_free_urb_buffers(stream); in uvc_alloc_urb_buffers()
1801 uvc_urb->stream = stream; in uvc_alloc_urb_buffers()
1805 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1812 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1821 static void uvc_video_stop_transfer(struct uvc_streaming *stream, in uvc_video_stop_transfer() argument
1826 uvc_video_stats_stop(stream); in uvc_video_stop_transfer()
1833 for_each_uvc_urb(uvc_urb, stream) in uvc_video_stop_transfer()
1836 flush_workqueue(stream->async_wq); in uvc_video_stop_transfer()
1838 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_stop_transfer()
1844 uvc_free_urb_buffers(stream); in uvc_video_stop_transfer()
1869 static int uvc_init_video_isoc(struct uvc_streaming *stream, in uvc_init_video_isoc() argument
1878 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_init_video_isoc()
1879 size = stream->ctrl.dwMaxVideoFrameSize; in uvc_init_video_isoc()
1881 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_isoc()
1887 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_isoc()
1890 uvc_video_stop_transfer(stream, 1); in uvc_init_video_isoc()
1894 urb->dev = stream->dev->udev; in uvc_init_video_isoc()
1896 urb->pipe = usb_rcvisocpipe(stream->dev->udev, in uvc_init_video_isoc()
1921 static int uvc_init_video_bulk(struct uvc_streaming *stream, in uvc_init_video_bulk() argument
1931 size = stream->ctrl.dwMaxPayloadTransferSize; in uvc_init_video_bulk()
1932 stream->bulk.max_payload_size = size; in uvc_init_video_bulk()
1934 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_bulk()
1941 pipe = usb_rcvbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1944 pipe = usb_sndbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1947 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) in uvc_init_video_bulk()
1950 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_bulk()
1953 uvc_video_stop_transfer(stream, 1); in uvc_init_video_bulk()
1957 usb_fill_bulk_urb(urb, stream->dev->udev, pipe, uvc_urb->buffer, in uvc_init_video_bulk()
1971 static int uvc_video_start_transfer(struct uvc_streaming *stream, in uvc_video_start_transfer() argument
1974 struct usb_interface *intf = stream->intf; in uvc_video_start_transfer()
1980 stream->sequence = -1; in uvc_video_start_transfer()
1981 stream->last_fid = -1; in uvc_video_start_transfer()
1982 stream->bulk.header_size = 0; in uvc_video_start_transfer()
1983 stream->bulk.skip_payload = 0; in uvc_video_start_transfer()
1984 stream->bulk.payload_size = 0; in uvc_video_start_transfer()
1986 uvc_video_stats_start(stream); in uvc_video_start_transfer()
1993 int intfnum = stream->intfnum; in uvc_video_start_transfer()
1996 bandwidth = stream->ctrl.dwMaxPayloadTransferSize; in uvc_video_start_transfer()
1999 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2003 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2014 stream->header.bEndpointAddress); in uvc_video_start_transfer()
2019 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_video_start_transfer()
2028 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2033 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2042 if (stream->dev->quirks & UVC_QUIRK_WAKE_AUTOSUSPEND) { in uvc_video_start_transfer()
2043 usb_set_interface(stream->dev->udev, intfnum, in uvc_video_start_transfer()
2045 usb_set_interface(stream->dev->udev, intfnum, 0); in uvc_video_start_transfer()
2048 ret = usb_set_interface(stream->dev->udev, intfnum, altsetting); in uvc_video_start_transfer()
2052 ret = uvc_init_video_isoc(stream, best_ep, gfp_flags); in uvc_video_start_transfer()
2056 stream->header.bEndpointAddress); in uvc_video_start_transfer()
2064 ret = uvc_init_video_bulk(stream, ep, gfp_flags); in uvc_video_start_transfer()
2071 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_start_transfer()
2074 dev_err(&stream->intf->dev, in uvc_video_start_transfer()
2077 uvc_video_stop_transfer(stream, 1); in uvc_video_start_transfer()
2086 if (stream->dev->quirks & UVC_QUIRK_RESTORE_CTRLS_ON_INIT) in uvc_video_start_transfer()
2087 uvc_ctrl_restore_values(stream->dev); in uvc_video_start_transfer()
2103 int uvc_video_suspend(struct uvc_streaming *stream) in uvc_video_suspend() argument
2105 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_suspend()
2108 stream->frozen = 1; in uvc_video_suspend()
2109 uvc_video_stop_transfer(stream, 0); in uvc_video_suspend()
2110 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_suspend()
2122 int uvc_video_resume(struct uvc_streaming *stream, int reset) in uvc_video_resume() argument
2133 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_resume()
2135 stream->frozen = 0; in uvc_video_resume()
2137 uvc_video_clock_reset(&stream->clock); in uvc_video_resume()
2139 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_resume()
2142 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_resume()
2146 return uvc_video_start_transfer(stream, GFP_NOIO); in uvc_video_resume()
2163 int uvc_video_init(struct uvc_streaming *stream) in uvc_video_init() argument
2165 struct uvc_streaming_control *probe = &stream->ctrl; in uvc_video_init()
2172 if (stream->nformats == 0) { in uvc_video_init()
2173 dev_info(&stream->intf->dev, in uvc_video_init()
2178 atomic_set(&stream->active, 0); in uvc_video_init()
2186 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_init()
2194 if (uvc_get_video_ctrl(stream, probe, 1, UVC_GET_DEF) == 0) in uvc_video_init()
2195 uvc_set_video_ctrl(stream, probe, 1); in uvc_video_init()
2203 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_video_init()
2213 usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k)) { in uvc_video_init()
2214 dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n"); in uvc_video_init()
2215 dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n"); in uvc_video_init()
2216 usb_reset_device(stream->dev->udev); in uvc_video_init()
2226 for (i = stream->nformats; i > 0; --i) { in uvc_video_init()
2227 format = &stream->formats[i-1]; in uvc_video_init()
2233 dev_info(&stream->intf->dev, in uvc_video_init()
2253 stream->def_format = format; in uvc_video_init()
2254 stream->cur_format = format; in uvc_video_init()
2255 stream->cur_frame = frame; in uvc_video_init()
2258 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { in uvc_video_init()
2259 if (stream->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) in uvc_video_init()
2260 stream->decode = uvc_video_decode_isight; in uvc_video_init()
2261 else if (stream->intf->num_altsetting > 1) in uvc_video_init()
2262 stream->decode = uvc_video_decode_isoc; in uvc_video_init()
2264 stream->decode = uvc_video_decode_bulk; in uvc_video_init()
2266 if (stream->intf->num_altsetting == 1) in uvc_video_init()
2267 stream->decode = uvc_video_encode_bulk; in uvc_video_init()
2269 dev_info(&stream->intf->dev, in uvc_video_init()
2276 for_each_uvc_urb(uvc_urb, stream) in uvc_video_init()
2282 int uvc_video_start_streaming(struct uvc_streaming *stream) in uvc_video_start_streaming() argument
2286 ret = uvc_video_clock_init(&stream->clock); in uvc_video_start_streaming()
2291 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_start_streaming()
2295 ret = uvc_video_start_transfer(stream, GFP_KERNEL); in uvc_video_start_streaming()
2302 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_start_streaming()
2304 uvc_video_clock_cleanup(&stream->clock); in uvc_video_start_streaming()
2309 void uvc_video_stop_streaming(struct uvc_streaming *stream) in uvc_video_stop_streaming() argument
2311 uvc_video_stop_transfer(stream, 1); in uvc_video_stop_streaming()
2313 if (stream->intf->num_altsetting > 1) { in uvc_video_stop_streaming()
2314 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_stop_streaming()
2322 unsigned int epnum = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2324 unsigned int dir = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2328 pipe = usb_sndbulkpipe(stream->dev->udev, epnum) | dir; in uvc_video_stop_streaming()
2329 usb_clear_halt(stream->dev->udev, pipe); in uvc_video_stop_streaming()
2332 uvc_video_clock_cleanup(&stream->clock); in uvc_video_stop_streaming()