Lines Matching full:stream
159 static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, in uvc_fixup_video_ctrl() argument
178 if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) && in uvc_fixup_video_ctrl()
182 uvc_dbg(stream->dev, VIDEO, in uvc_fixup_video_ctrl()
190 for (i = 0; i < stream->nformats; ++i) { in uvc_fixup_video_ctrl()
191 if (stream->formats[i].index == ctrl->bFormatIndex) { in uvc_fixup_video_ctrl()
192 format = &stream->formats[i]; in uvc_fixup_video_ctrl()
212 stream->dev->uvc_version < 0x0110)) in uvc_fixup_video_ctrl()
226 stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && in uvc_fixup_video_ctrl()
227 stream->intf->num_altsetting > 1) { in uvc_fixup_video_ctrl()
245 if (stream->dev->udev->speed >= USB_SPEED_HIGH) in uvc_fixup_video_ctrl()
263 static size_t uvc_video_ctrl_size(struct uvc_streaming *stream) in uvc_video_ctrl_size() argument
269 if (stream->dev->uvc_version < 0x0110) in uvc_video_ctrl_size()
271 else if (stream->dev->uvc_version < 0x0150) in uvc_video_ctrl_size()
277 static int uvc_get_video_ctrl(struct uvc_streaming *stream, in uvc_get_video_ctrl() argument
280 u16 size = uvc_video_ctrl_size(stream); in uvc_get_video_ctrl()
284 if ((stream->dev->quirks & UVC_QUIRK_PROBE_DEF) && in uvc_get_video_ctrl()
292 ret = __uvc_query_ctrl(stream->dev, query, 0, stream->intfnum, in uvc_get_video_ctrl()
302 uvc_warn_once(stream->dev, UVC_WARN_MINMAX, "UVC non " in uvc_get_video_ctrl()
315 uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non " in uvc_get_video_ctrl()
321 dev_err(&stream->intf->dev, in uvc_get_video_ctrl()
347 ctrl->dwClockFrequency = stream->dev->clock_frequency; in uvc_get_video_ctrl()
359 uvc_fixup_video_ctrl(stream, ctrl); in uvc_get_video_ctrl()
367 static int uvc_set_video_ctrl(struct uvc_streaming *stream, in uvc_set_video_ctrl() argument
370 u16 size = uvc_video_ctrl_size(stream); in uvc_set_video_ctrl()
398 ret = __uvc_query_ctrl(stream->dev, UVC_SET_CUR, 0, stream->intfnum, in uvc_set_video_ctrl()
402 dev_err(&stream->intf->dev, in uvc_set_video_ctrl()
412 int uvc_probe_video(struct uvc_streaming *stream, in uvc_probe_video() argument
427 ret = uvc_set_video_ctrl(stream, probe, 1); in uvc_probe_video()
432 if (!(stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { in uvc_probe_video()
433 ret = uvc_get_video_ctrl(stream, &probe_min, 1, UVC_GET_MIN); in uvc_probe_video()
436 ret = uvc_get_video_ctrl(stream, &probe_max, 1, UVC_GET_MAX); in uvc_probe_video()
444 ret = uvc_set_video_ctrl(stream, probe, 1); in uvc_probe_video()
447 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_probe_video()
451 if (stream->intf->num_altsetting == 1) in uvc_probe_video()
454 if (probe->dwMaxPayloadTransferSize <= stream->maxpsize) in uvc_probe_video()
457 if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { in uvc_probe_video()
473 static int uvc_commit_video(struct uvc_streaming *stream, in uvc_commit_video() argument
476 return uvc_set_video_ctrl(stream, probe, 0); in uvc_commit_video()
492 uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, in uvc_video_clock_decode() argument
549 if (dev_sof == stream->clock.last_sof) in uvc_video_clock_decode()
580 stream->clock.last_sof = dev_sof; in uvc_video_clock_decode()
582 host_sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_clock_decode()
591 if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) in uvc_video_clock_decode()
616 if (stream->clock.sof_offset == (u16)-1) { in uvc_video_clock_decode()
619 stream->clock.sof_offset = delta_sof; in uvc_video_clock_decode()
621 stream->clock.sof_offset = 0; in uvc_video_clock_decode()
624 dev_sof = (dev_sof + stream->clock.sof_offset) & 2047; in uvc_video_clock_decode()
626 spin_lock_irqsave(&stream->clock.lock, flags); in uvc_video_clock_decode()
628 sample = &stream->clock.samples[stream->clock.head]; in uvc_video_clock_decode()
635 stream->clock.head = (stream->clock.head + 1) % stream->clock.size; in uvc_video_clock_decode()
637 if (stream->clock.count < stream->clock.size) in uvc_video_clock_decode()
638 stream->clock.count++; in uvc_video_clock_decode()
640 spin_unlock_irqrestore(&stream->clock.lock, flags); in uvc_video_clock_decode()
643 static void uvc_video_clock_reset(struct uvc_streaming *stream) in uvc_video_clock_reset() argument
645 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_reset()
653 static int uvc_video_clock_init(struct uvc_streaming *stream) in uvc_video_clock_init() argument
655 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_init()
665 uvc_video_clock_reset(stream); in uvc_video_clock_init()
670 static void uvc_video_clock_cleanup(struct uvc_streaming *stream) in uvc_video_clock_cleanup() argument
672 kfree(stream->clock.samples); in uvc_video_clock_cleanup()
673 stream->clock.samples = NULL; in uvc_video_clock_cleanup()
764 void uvc_video_clock_update(struct uvc_streaming *stream, in uvc_video_clock_update() argument
768 struct uvc_clock *clock = &stream->clock; in uvc_video_clock_update()
817 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
819 stream->dev->name, buf->pts, in uvc_video_clock_update()
853 uvc_dbg(stream->dev, CLOCK, in uvc_video_clock_update()
855 stream->dev->name, in uvc_video_clock_update()
869 * Stream statistics
872 static void uvc_video_stats_decode(struct uvc_streaming *stream, in uvc_video_stats_decode() argument
882 if (stream->stats.stream.nb_frames == 0 && in uvc_video_stats_decode()
883 stream->stats.frame.nb_packets == 0) in uvc_video_stats_decode()
884 stream->stats.stream.start_ts = ktime_get(); in uvc_video_stats_decode()
907 stream->stats.frame.nb_invalid++; in uvc_video_stats_decode()
921 if (has_pts && stream->stats.frame.nb_pts) { in uvc_video_stats_decode()
922 if (stream->stats.frame.pts != pts) { in uvc_video_stats_decode()
923 stream->stats.frame.nb_pts_diffs++; in uvc_video_stats_decode()
924 stream->stats.frame.last_pts_diff = in uvc_video_stats_decode()
925 stream->stats.frame.nb_packets; in uvc_video_stats_decode()
930 stream->stats.frame.nb_pts++; in uvc_video_stats_decode()
931 stream->stats.frame.pts = pts; in uvc_video_stats_decode()
938 if (stream->stats.frame.size == 0) { in uvc_video_stats_decode()
940 stream->stats.frame.has_initial_pts = has_pts; in uvc_video_stats_decode()
942 stream->stats.frame.has_early_pts = true; in uvc_video_stats_decode()
946 if (has_scr && stream->stats.frame.nb_scr) { in uvc_video_stats_decode()
947 if (stream->stats.frame.scr_stc != scr_stc) in uvc_video_stats_decode()
948 stream->stats.frame.nb_scr_diffs++; in uvc_video_stats_decode()
953 if (stream->stats.stream.nb_frames > 0 || in uvc_video_stats_decode()
954 stream->stats.frame.nb_scr > 0) in uvc_video_stats_decode()
955 stream->stats.stream.scr_sof_count += in uvc_video_stats_decode()
956 (scr_sof - stream->stats.stream.scr_sof) % 2048; in uvc_video_stats_decode()
957 stream->stats.stream.scr_sof = scr_sof; in uvc_video_stats_decode()
959 stream->stats.frame.nb_scr++; in uvc_video_stats_decode()
960 stream->stats.frame.scr_stc = scr_stc; in uvc_video_stats_decode()
961 stream->stats.frame.scr_sof = scr_sof; in uvc_video_stats_decode()
963 if (scr_sof < stream->stats.stream.min_sof) in uvc_video_stats_decode()
964 stream->stats.stream.min_sof = scr_sof; in uvc_video_stats_decode()
965 if (scr_sof > stream->stats.stream.max_sof) in uvc_video_stats_decode()
966 stream->stats.stream.max_sof = scr_sof; in uvc_video_stats_decode()
970 if (stream->stats.frame.size == 0 && len > header_size) in uvc_video_stats_decode()
971 stream->stats.frame.first_data = stream->stats.frame.nb_packets; in uvc_video_stats_decode()
974 stream->stats.frame.size += len - header_size; in uvc_video_stats_decode()
977 stream->stats.frame.nb_packets++; in uvc_video_stats_decode()
979 stream->stats.frame.nb_empty++; in uvc_video_stats_decode()
982 stream->stats.frame.nb_errors++; in uvc_video_stats_decode()
985 static void uvc_video_stats_update(struct uvc_streaming *stream) in uvc_video_stats_update() argument
987 struct uvc_stats_frame *frame = &stream->stats.frame; in uvc_video_stats_update()
989 uvc_dbg(stream->dev, STATS, in uvc_video_stats_update()
991 stream->sequence, frame->first_data, in uvc_video_stats_update()
999 stream->stats.stream.nb_frames++; in uvc_video_stats_update()
1000 stream->stats.stream.nb_packets += stream->stats.frame.nb_packets; in uvc_video_stats_update()
1001 stream->stats.stream.nb_empty += stream->stats.frame.nb_empty; in uvc_video_stats_update()
1002 stream->stats.stream.nb_errors += stream->stats.frame.nb_errors; in uvc_video_stats_update()
1003 stream->stats.stream.nb_invalid += stream->stats.frame.nb_invalid; in uvc_video_stats_update()
1006 stream->stats.stream.nb_pts_early++; in uvc_video_stats_update()
1008 stream->stats.stream.nb_pts_initial++; in uvc_video_stats_update()
1010 stream->stats.stream.nb_pts_constant++; in uvc_video_stats_update()
1012 stream->stats.stream.nb_scr_count_ok++; in uvc_video_stats_update()
1014 stream->stats.stream.nb_scr_diffs_ok++; in uvc_video_stats_update()
1016 memset(&stream->stats.frame, 0, sizeof(stream->stats.frame)); in uvc_video_stats_update()
1019 size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, in uvc_video_stats_dump() argument
1030 duration = ktime_ms_delta(stream->stats.stream.stop_ts, in uvc_video_stats_dump()
1031 stream->stats.stream.start_ts); in uvc_video_stats_dump()
1033 scr_sof_freq = stream->stats.stream.scr_sof_count * 1000 in uvc_video_stats_dump()
1041 stream->stats.stream.nb_frames, in uvc_video_stats_dump()
1042 stream->stats.stream.nb_packets, in uvc_video_stats_dump()
1043 stream->stats.stream.nb_empty, in uvc_video_stats_dump()
1044 stream->stats.stream.nb_errors, in uvc_video_stats_dump()
1045 stream->stats.stream.nb_invalid); in uvc_video_stats_dump()
1048 stream->stats.stream.nb_pts_early, in uvc_video_stats_dump()
1049 stream->stats.stream.nb_pts_initial, in uvc_video_stats_dump()
1050 stream->stats.stream.nb_pts_constant); in uvc_video_stats_dump()
1053 stream->stats.stream.nb_scr_count_ok, in uvc_video_stats_dump()
1054 stream->stats.stream.nb_scr_diffs_ok); in uvc_video_stats_dump()
1057 stream->stats.stream.min_sof, in uvc_video_stats_dump()
1058 stream->stats.stream.max_sof, in uvc_video_stats_dump()
1064 static void uvc_video_stats_start(struct uvc_streaming *stream) in uvc_video_stats_start() argument
1066 memset(&stream->stats, 0, sizeof(stream->stats)); in uvc_video_stats_start()
1067 stream->stats.stream.min_sof = 2048; in uvc_video_stats_start()
1070 static void uvc_video_stats_stop(struct uvc_streaming *stream) in uvc_video_stats_stop() argument
1072 stream->stats.stream.stop_ts = ktime_get(); in uvc_video_stats_stop()
1115 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()
1139 if (stream->last_fid != fid) { in uvc_video_decode_start()
1140 stream->sequence++; in uvc_video_decode_start()
1141 if (stream->sequence) in uvc_video_decode_start()
1142 uvc_video_stats_update(stream); in uvc_video_decode_start()
1145 uvc_video_clock_decode(stream, buf, data, len); in uvc_video_decode_start()
1146 uvc_video_stats_decode(stream, data, len); in uvc_video_decode_start()
1153 stream->last_fid = fid; in uvc_video_decode_start()
1159 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1165 * Synchronize to the input stream by waiting for the FID bit to be in uvc_video_decode_start()
1167 * stream->last_fid is initialized to -1, so the first isochronous in uvc_video_decode_start()
1170 * If the device doesn't toggle the FID bit, invert stream->last_fid in uvc_video_decode_start()
1174 if (fid == stream->last_fid) { in uvc_video_decode_start()
1175 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1177 if ((stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && in uvc_video_decode_start()
1179 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_start()
1184 buf->buf.sequence = stream->sequence; in uvc_video_decode_start()
1199 * stream->last_fid is initialized to -1, so the first isochronous in uvc_video_decode_start()
1207 if (fid != stream->last_fid && buf->bytesused != 0) { in uvc_video_decode_start()
1208 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_start()
1216 * another non-MJPEG stream), are known to lose the EOF packet for a frame. in uvc_video_decode_start()
1221 if (stream->dev->quirks & UVC_QUIRK_MJPEG_NO_EOF && in uvc_video_decode_start()
1222 (stream->cur_format->fcc == V4L2_PIX_FMT_MJPEG || in uvc_video_decode_start()
1223 stream->cur_format->fcc == V4L2_PIX_FMT_JPEG)) { in uvc_video_decode_start()
1231 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_start()
1236 stream->last_fid = fid; in uvc_video_decode_start()
1242 struct uvc_streaming *stream) in uvc_stream_dir() argument
1244 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) in uvc_stream_dir()
1250 static inline struct device *uvc_stream_to_dmadev(struct uvc_streaming *stream) in uvc_stream_to_dmadev() argument
1252 return bus_to_hcd(stream->dev->udev->bus)->self.sysdev; in uvc_stream_to_dmadev()
1258 dma_sync_sgtable_for_device(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_submit_urb()
1260 uvc_stream_dir(uvc_urb->stream)); in uvc_submit_urb()
1287 dev_err(&uvc_urb->stream->intf->dev, in uvc_video_copy_data_work()
1315 uvc_dbg(uvc_urb->stream->dev, FRAME, in uvc_video_decode_data()
1324 static void uvc_video_decode_end(struct uvc_streaming *stream, in uvc_video_decode_end() argument
1329 uvc_dbg(stream->dev, FRAME, "Frame complete (EOF found)\n"); in uvc_video_decode_end()
1331 uvc_dbg(stream->dev, FRAME, "EOF in empty payload\n"); in uvc_video_decode_end()
1333 if (stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) in uvc_video_decode_end()
1334 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_decode_end()
1350 static int uvc_video_encode_header(struct uvc_streaming *stream, in uvc_video_encode_header() argument
1355 | (stream->last_fid & UVC_STREAM_FID); in uvc_video_encode_header()
1359 static int uvc_video_encode_data(struct uvc_streaming *stream, in uvc_video_encode_data() argument
1362 struct uvc_video_queue *queue = &stream->queue; in uvc_video_encode_data()
1369 nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size, in uvc_video_encode_data()
1393 static void uvc_video_decode_meta(struct uvc_streaming *stream, in uvc_video_decode_meta() argument
1427 if (stream->meta.format == V4L2_META_FMT_UVC) in uvc_video_decode_meta()
1431 !memcmp(scr, stream->clock.last_scr, 6))) in uvc_video_decode_meta()
1437 sof = usb_get_current_frame_number(stream->dev->udev); in uvc_video_decode_meta()
1443 memcpy(stream->clock.last_scr, scr, 6); in uvc_video_decode_meta()
1450 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_meta()
1466 static void uvc_video_validate_buffer(const struct uvc_streaming *stream, in uvc_video_validate_buffer() argument
1469 if (stream->ctrl.dwMaxVideoFrameSize != buf->bytesused && in uvc_video_validate_buffer()
1470 !(stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)) in uvc_video_validate_buffer()
1478 static void uvc_video_next_buffers(struct uvc_streaming *stream, in uvc_video_next_buffers() argument
1481 uvc_video_validate_buffer(stream, *video_buf); in uvc_video_next_buffers()
1494 *meta_buf = uvc_queue_next_buffer(&stream->meta.queue, in uvc_video_next_buffers()
1497 *video_buf = uvc_queue_next_buffer(&stream->queue, *video_buf); in uvc_video_next_buffers()
1504 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_isoc() local
1510 uvc_dbg(stream->dev, FRAME, in uvc_video_decode_isoc()
1522 ret = uvc_video_decode_start(stream, buf, mem, in uvc_video_decode_isoc()
1525 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1531 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_isoc()
1538 uvc_video_decode_end(stream, buf, mem, in uvc_video_decode_isoc()
1542 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_isoc()
1550 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_decode_bulk() local
1558 if (urb->actual_length == 0 && stream->bulk.header_size == 0) in uvc_video_decode_bulk()
1563 stream->bulk.payload_size += len; in uvc_video_decode_bulk()
1569 if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) { in uvc_video_decode_bulk()
1571 ret = uvc_video_decode_start(stream, buf, mem, len); in uvc_video_decode_bulk()
1573 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1578 stream->bulk.skip_payload = 1; in uvc_video_decode_bulk()
1580 memcpy(stream->bulk.header, mem, ret); in uvc_video_decode_bulk()
1581 stream->bulk.header_size = ret; in uvc_video_decode_bulk()
1583 uvc_video_decode_meta(stream, meta_buf, mem, ret); in uvc_video_decode_bulk()
1597 if (!stream->bulk.skip_payload && buf != NULL) in uvc_video_decode_bulk()
1605 stream->bulk.payload_size >= stream->bulk.max_payload_size) { in uvc_video_decode_bulk()
1606 if (!stream->bulk.skip_payload && buf != NULL) { in uvc_video_decode_bulk()
1607 uvc_video_decode_end(stream, buf, stream->bulk.header, in uvc_video_decode_bulk()
1608 stream->bulk.payload_size); in uvc_video_decode_bulk()
1610 uvc_video_next_buffers(stream, &buf, &meta_buf); in uvc_video_decode_bulk()
1613 stream->bulk.header_size = 0; in uvc_video_decode_bulk()
1614 stream->bulk.skip_payload = 0; in uvc_video_decode_bulk()
1615 stream->bulk.payload_size = 0; in uvc_video_decode_bulk()
1623 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_encode_bulk() local
1626 int len = stream->urb_size, ret; in uvc_video_encode_bulk()
1634 if (stream->bulk.header_size == 0) { in uvc_video_encode_bulk()
1635 ret = uvc_video_encode_header(stream, buf, mem, len); in uvc_video_encode_bulk()
1636 stream->bulk.header_size = ret; in uvc_video_encode_bulk()
1637 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1643 ret = uvc_video_encode_data(stream, buf, mem, len); in uvc_video_encode_bulk()
1645 stream->bulk.payload_size += ret; in uvc_video_encode_bulk()
1648 if (buf->bytesused == stream->queue.buf_used || in uvc_video_encode_bulk()
1649 stream->bulk.payload_size == stream->bulk.max_payload_size) { in uvc_video_encode_bulk()
1650 if (buf->bytesused == stream->queue.buf_used) { in uvc_video_encode_bulk()
1651 stream->queue.buf_used = 0; in uvc_video_encode_bulk()
1653 buf->buf.sequence = ++stream->sequence; in uvc_video_encode_bulk()
1654 uvc_queue_next_buffer(&stream->queue, buf); in uvc_video_encode_bulk()
1655 stream->last_fid ^= UVC_STREAM_FID; in uvc_video_encode_bulk()
1658 stream->bulk.header_size = 0; in uvc_video_encode_bulk()
1659 stream->bulk.payload_size = 0; in uvc_video_encode_bulk()
1662 urb->transfer_buffer_length = stream->urb_size - len; in uvc_video_encode_bulk()
1668 struct uvc_streaming *stream = uvc_urb->stream; in uvc_video_complete() local
1669 struct uvc_video_queue *queue = &stream->queue; in uvc_video_complete()
1670 struct uvc_video_queue *qmeta = &stream->meta.queue; in uvc_video_complete()
1671 struct vb2_queue *vb2_qmeta = stream->meta.vdev.queue; in uvc_video_complete()
1682 dev_warn(&stream->intf->dev, in uvc_video_complete()
1687 if (stream->frozen) in uvc_video_complete()
1712 dma_sync_sgtable_for_cpu(uvc_stream_to_dmadev(uvc_urb->stream), in uvc_video_complete()
1713 uvc_urb->sgt, uvc_stream_dir(stream)); in uvc_video_complete()
1715 uvc_urb->stream->urb_size); in uvc_video_complete()
1721 stream->decode(uvc_urb, buf, buf_meta); in uvc_video_complete()
1727 dev_err(&stream->intf->dev, in uvc_video_complete()
1732 queue_work(stream->async_wq, &uvc_urb->work); in uvc_video_complete()
1738 static void uvc_free_urb_buffers(struct uvc_streaming *stream) in uvc_free_urb_buffers() argument
1740 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_free_urb_buffers()
1743 for_each_uvc_urb(uvc_urb, stream) { in uvc_free_urb_buffers()
1748 dma_free_noncontiguous(dma_dev, stream->urb_size, uvc_urb->sgt, in uvc_free_urb_buffers()
1749 uvc_stream_dir(stream)); in uvc_free_urb_buffers()
1755 stream->urb_size = 0; in uvc_free_urb_buffers()
1758 static bool uvc_alloc_urb_buffer(struct uvc_streaming *stream, in uvc_alloc_urb_buffer() argument
1761 struct device *dma_dev = uvc_stream_to_dmadev(stream); in uvc_alloc_urb_buffer()
1763 uvc_urb->sgt = dma_alloc_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1764 uvc_stream_dir(stream), in uvc_alloc_urb_buffer()
1770 uvc_urb->buffer = dma_vmap_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1773 dma_free_noncontiguous(dma_dev, stream->urb_size, in uvc_alloc_urb_buffer()
1775 uvc_stream_dir(stream)); in uvc_alloc_urb_buffer()
1794 static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, in uvc_alloc_urb_buffers() argument
1801 if (stream->urb_size) in uvc_alloc_urb_buffers()
1802 return stream->urb_size / psize; in uvc_alloc_urb_buffers()
1814 stream->urb_size = psize * npackets; in uvc_alloc_urb_buffers()
1817 struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; in uvc_alloc_urb_buffers()
1819 if (!uvc_alloc_urb_buffer(stream, uvc_urb, gfp_flags)) { in uvc_alloc_urb_buffers()
1820 uvc_free_urb_buffers(stream); in uvc_alloc_urb_buffers()
1824 uvc_urb->stream = stream; in uvc_alloc_urb_buffers()
1828 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1835 uvc_dbg(stream->dev, VIDEO, in uvc_alloc_urb_buffers()
1844 static void uvc_video_stop_transfer(struct uvc_streaming *stream, in uvc_video_stop_transfer() argument
1849 uvc_video_stats_stop(stream); in uvc_video_stop_transfer()
1856 for_each_uvc_urb(uvc_urb, stream) in uvc_video_stop_transfer()
1859 flush_workqueue(stream->async_wq); in uvc_video_stop_transfer()
1861 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_stop_transfer()
1867 uvc_free_urb_buffers(stream); in uvc_video_stop_transfer()
1892 static int uvc_init_video_isoc(struct uvc_streaming *stream, in uvc_init_video_isoc() argument
1901 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_init_video_isoc()
1902 size = stream->ctrl.dwMaxVideoFrameSize; in uvc_init_video_isoc()
1904 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_isoc()
1910 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_isoc()
1913 uvc_video_stop_transfer(stream, 1); in uvc_init_video_isoc()
1917 urb->dev = stream->dev->udev; in uvc_init_video_isoc()
1919 urb->pipe = usb_rcvisocpipe(stream->dev->udev, in uvc_init_video_isoc()
1944 static int uvc_init_video_bulk(struct uvc_streaming *stream, in uvc_init_video_bulk() argument
1954 size = stream->ctrl.dwMaxPayloadTransferSize; in uvc_init_video_bulk()
1955 stream->bulk.max_payload_size = size; in uvc_init_video_bulk()
1957 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); in uvc_init_video_bulk()
1964 pipe = usb_rcvbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1967 pipe = usb_sndbulkpipe(stream->dev->udev, in uvc_init_video_bulk()
1970 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) in uvc_init_video_bulk()
1973 for_each_uvc_urb(uvc_urb, stream) { in uvc_init_video_bulk()
1976 uvc_video_stop_transfer(stream, 1); in uvc_init_video_bulk()
1980 usb_fill_bulk_urb(urb, stream->dev->udev, pipe, uvc_urb->buffer, in uvc_init_video_bulk()
1994 static int uvc_video_start_transfer(struct uvc_streaming *stream, in uvc_video_start_transfer() argument
1997 struct usb_interface *intf = stream->intf; in uvc_video_start_transfer()
2003 stream->sequence = -1; in uvc_video_start_transfer()
2004 stream->last_fid = -1; in uvc_video_start_transfer()
2005 stream->bulk.header_size = 0; in uvc_video_start_transfer()
2006 stream->bulk.skip_payload = 0; in uvc_video_start_transfer()
2007 stream->bulk.payload_size = 0; in uvc_video_start_transfer()
2009 uvc_video_stats_start(stream); in uvc_video_start_transfer()
2016 int intfnum = stream->intfnum; in uvc_video_start_transfer()
2019 bandwidth = stream->ctrl.dwMaxPayloadTransferSize; in uvc_video_start_transfer()
2022 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2026 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2037 stream->header.bEndpointAddress); in uvc_video_start_transfer()
2042 psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); in uvc_video_start_transfer()
2051 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2056 uvc_dbg(stream->dev, VIDEO, in uvc_video_start_transfer()
2065 if (stream->dev->quirks & UVC_QUIRK_WAKE_AUTOSUSPEND) { in uvc_video_start_transfer()
2066 usb_set_interface(stream->dev->udev, intfnum, in uvc_video_start_transfer()
2068 usb_set_interface(stream->dev->udev, intfnum, 0); in uvc_video_start_transfer()
2071 ret = usb_set_interface(stream->dev->udev, intfnum, altsetting); in uvc_video_start_transfer()
2075 ret = uvc_init_video_isoc(stream, best_ep, gfp_flags); in uvc_video_start_transfer()
2079 stream->header.bEndpointAddress); in uvc_video_start_transfer()
2087 ret = uvc_init_video_bulk(stream, ep, gfp_flags); in uvc_video_start_transfer()
2094 for_each_uvc_urb(uvc_urb, stream) { in uvc_video_start_transfer()
2097 dev_err(&stream->intf->dev, in uvc_video_start_transfer()
2100 uvc_video_stop_transfer(stream, 1); in uvc_video_start_transfer()
2109 if (stream->dev->quirks & UVC_QUIRK_RESTORE_CTRLS_ON_INIT) in uvc_video_start_transfer()
2110 uvc_ctrl_restore_values(stream->dev); in uvc_video_start_transfer()
2126 int uvc_video_suspend(struct uvc_streaming *stream) in uvc_video_suspend() argument
2128 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_suspend()
2131 stream->frozen = 1; in uvc_video_suspend()
2132 uvc_video_stop_transfer(stream, 0); in uvc_video_suspend()
2133 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_suspend()
2145 int uvc_video_resume(struct uvc_streaming *stream, int reset) in uvc_video_resume() argument
2156 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_resume()
2158 stream->frozen = 0; in uvc_video_resume()
2160 uvc_video_clock_reset(stream); in uvc_video_resume()
2162 if (!uvc_queue_streaming(&stream->queue)) in uvc_video_resume()
2165 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_resume()
2169 return uvc_video_start_transfer(stream, GFP_NOIO); in uvc_video_resume()
2186 int uvc_video_init(struct uvc_streaming *stream) in uvc_video_init() argument
2188 struct uvc_streaming_control *probe = &stream->ctrl; in uvc_video_init()
2195 if (stream->nformats == 0) { in uvc_video_init()
2196 dev_info(&stream->intf->dev, in uvc_video_init()
2201 atomic_set(&stream->active, 0); in uvc_video_init()
2209 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_init()
2217 if (uvc_get_video_ctrl(stream, probe, 1, UVC_GET_DEF) == 0) in uvc_video_init()
2218 uvc_set_video_ctrl(stream, probe, 1); in uvc_video_init()
2226 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); in uvc_video_init()
2236 usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k)) { in uvc_video_init()
2237 dev_err(&stream->intf->dev, "Elgato Cam Link 4K firmware crash detected\n"); in uvc_video_init()
2238 dev_err(&stream->intf->dev, "Resetting the device, unplug and replug to recover\n"); in uvc_video_init()
2239 usb_reset_device(stream->dev->udev); in uvc_video_init()
2249 for (i = stream->nformats; i > 0; --i) { in uvc_video_init()
2250 format = &stream->formats[i-1]; in uvc_video_init()
2256 dev_info(&stream->intf->dev, in uvc_video_init()
2262 * Zero bFrameIndex might be correct. Stream-based formats (including in uvc_video_init()
2276 stream->def_format = format; in uvc_video_init()
2277 stream->cur_format = format; in uvc_video_init()
2278 stream->cur_frame = frame; in uvc_video_init()
2281 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { in uvc_video_init()
2282 if (stream->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) in uvc_video_init()
2283 stream->decode = uvc_video_decode_isight; in uvc_video_init()
2284 else if (stream->intf->num_altsetting > 1) in uvc_video_init()
2285 stream->decode = uvc_video_decode_isoc; in uvc_video_init()
2287 stream->decode = uvc_video_decode_bulk; in uvc_video_init()
2289 if (stream->intf->num_altsetting == 1) in uvc_video_init()
2290 stream->decode = uvc_video_encode_bulk; in uvc_video_init()
2292 dev_info(&stream->intf->dev, in uvc_video_init()
2299 for_each_uvc_urb(uvc_urb, stream) in uvc_video_init()
2305 int uvc_video_start_streaming(struct uvc_streaming *stream) in uvc_video_start_streaming() argument
2309 ret = uvc_video_clock_init(stream); in uvc_video_start_streaming()
2314 ret = uvc_commit_video(stream, &stream->ctrl); in uvc_video_start_streaming()
2318 ret = uvc_video_start_transfer(stream, GFP_KERNEL); in uvc_video_start_streaming()
2325 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_start_streaming()
2327 uvc_video_clock_cleanup(stream); in uvc_video_start_streaming()
2332 void uvc_video_stop_streaming(struct uvc_streaming *stream) in uvc_video_stop_streaming() argument
2334 uvc_video_stop_transfer(stream, 1); in uvc_video_stop_streaming()
2336 if (stream->intf->num_altsetting > 1) { in uvc_video_stop_streaming()
2337 usb_set_interface(stream->dev->udev, stream->intfnum, 0); in uvc_video_stop_streaming()
2341 * when the video stream is stopped. Windows sends a in uvc_video_stop_streaming()
2345 unsigned int epnum = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2347 unsigned int dir = stream->header.bEndpointAddress in uvc_video_stop_streaming()
2351 pipe = usb_sndbulkpipe(stream->dev->udev, epnum) | dir; in uvc_video_stop_streaming()
2352 usb_clear_halt(stream->dev->udev, pipe); in uvc_video_stop_streaming()
2355 uvc_video_clock_cleanup(stream); in uvc_video_stop_streaming()