From 20572a6ed22ef54a511b731dc6044928d9ad5993 Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Wed, 4 Aug 2021 00:32:16 +0900 Subject: [PATCH] Fix regarding standard video stream request --- .../video_capture/src/usb_descriptors.h | 5 +++- src/class/video/video_device.c | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/device/video_capture/src/usb_descriptors.h b/examples/device/video_capture/src/usb_descriptors.h index 246125217..396131f83 100644 --- a/examples/device/video_capture/src/usb_descriptors.h +++ b/examples/device/video_capture/src/usb_descriptors.h @@ -56,6 +56,9 @@ enum { + 7/* Endpoint */\ ) +/* Windows support YUV2 and NV12 + * https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/usb-video-class-driver-overview */ + #define TUD_VIDEO_DESC_CS_VS_FMT_YUY2(_fmtidx, _numfmtdesc, _frmidx, _asrx, _asry, _interlace, _cp) \ TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR(_fmtidx, _numfmtdesc, TUD_VIDEO_GUID_YUY2, 16, _frmidx, _asrx, _asry, _interlace, _cp) #define TUD_VIDEO_DESC_CS_VS_FMT_NV12(_fmtidx, _numfmtdesc, _frmidx, _asrx, _asry, _interlace, _cp) \ @@ -88,7 +91,7 @@ enum { /*bStillCaptureMethod*/0, /*bTriggerSupport*/0, /*bTriggerUsage*/0, \ /*bControlSize*/1, /*bmaControls(1)*/0), \ /* Video stream format */ \ - TUD_VIDEO_DESC_CS_VS_FMT_I420(/*bFormatIndex*/1, /*bNumFrameDescriptors*/1,\ + TUD_VIDEO_DESC_CS_VS_FMT_NV12(/*bFormatIndex*/1, /*bNumFrameDescriptors*/1,\ /*bDefaultFrameIndex*/1, 0, 0, 0, /*bCopyProtect*/0), \ /* Video stream frame format */ \ TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT(/*bFrameIndex */1, 0, _width, _height, \ diff --git a/src/class/video/video_device.c b/src/class/video/video_device.c index 94ae325dc..bee80d6e8 100644 --- a/src/class/video/video_device.c +++ b/src/class/video/video_device.c @@ -321,6 +321,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_interface_t *self, unsigned itfn cur += tu_desc_len(cur); } *ofs = (void const*)vs - self->beg; + TU_LOG2(" done\r\n"); return true; } @@ -626,6 +627,7 @@ uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) { int err; + int (*handle_video_req)(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, unsigned itf) = NULL; if (request->bmRequestType_bit.recipient != TUSB_REQ_RCPT_INTERFACE) { return false; } @@ -635,20 +637,21 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_ tusb_desc_vc_itf_t const *vc = NULL; for (itf = 0; itf < CFG_TUD_VIDEO; ++itf) { vc = _get_desc_vc(&_videod_itf[itf]); - unsigned beg_itfnum = vc->std.bInterfaceNumber; - unsigned end_itfnum = vc->ctl.bInCollection; - if (beg_itfnum <= itfnum && itfnum < end_itfnum) + if (itfnum == vc->std.bInterfaceNumber) { + handle_video_req = handle_video_ctl_req; break; + } + int i; + int bInCollection = vc->ctl.bInCollection; + for (i = 0; i < bInCollection && itfnum != vc->ctl.baInterfaceNr[i]; ++i) ; + if (i < bInCollection) { + handle_video_req = handle_video_stm_req; + break; + } } if (itf == CFG_TUD_VIDEO) return false; - if (itfnum == vc->std.bInterfaceNumber) { - /* To video control interface */ - err = handle_video_ctl_req(rhport, stage, request, itf); - } else { - /* To video streaming interface */ - err = handle_video_stm_req(rhport, stage, request, itf); - } + err = handle_video_req(rhport, stage, request, itf); _videod_itf[itf].error_code = (uint8_t)err; if (err) return false; return true;