update example to work bulk mjpeg

This commit is contained in:
hathach 2024-01-26 23:23:38 +07:00
parent b5cd673330
commit 0daf8ec51b
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
2 changed files with 35 additions and 2 deletions

View File

@ -109,6 +109,10 @@ uint8_t const* tud_descriptor_device_cb(void) {
#define EPNUM_VIDEO_IN 0x81
#endif
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
#define USE_MJPEG
#endif
// For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
// To further reduce the size, we use MJPEG format instead of YUY2.
// Select interface descriptor and length accordingly.
@ -197,8 +201,15 @@ typedef struct TU_ATTR_PACKED {
typedef struct TU_ATTR_PACKED {
tusb_desc_interface_t itf;
tusb_desc_video_streaming_input_header_1byte_t header;
#ifdef USE_MJPEG
tusb_desc_video_format_mjpeg_t format;
tusb_desc_video_frame_mjpeg_continuous_t frame;
#else
tusb_desc_video_format_uncompressed_t format;
tusb_desc_video_frame_uncompressed_continuous_t frame;
#endif
tusb_desc_video_streaming_color_matching_t color;
tusb_desc_endpoint_t ep;
} uvc_streaming_desc_t;
@ -316,14 +327,22 @@ const uvc_cfg_desc_t config_desc = {
.bmaControls = { 0 }
},
.format = {
#ifdef USE_MJPEG
.bLength = sizeof(tusb_desc_video_format_mjpeg_t),
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_MJPEG,
.bFormatIndex = 1, // 1-based index
.bNumFrameDescriptors = 1,
.bmFlags = 0,
#else
.bLength = sizeof(tusb_desc_video_format_uncompressed_t),
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED,
.bFormatIndex = 1, // 1-based index
.bNumFrameDescriptors = 1,
.guidFormat = { TUD_VIDEO_GUID_YUY2 },
.bBitsPerPixel = 16,
#endif
.bDefaultFrameIndex = 1,
.bAspectRatioX = 0,
.bAspectRatioY = 0,
@ -331,9 +350,15 @@ const uvc_cfg_desc_t config_desc = {
.bCopyProtect = 0
},
.frame = {
#ifdef USE_MJPEG
.bLength = sizeof(tusb_desc_video_frame_mjpeg_continuous_t),
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_MJPEG,
#else
.bLength = sizeof(tusb_desc_video_frame_uncompressed_continuous_t),
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_UNCOMPRESSED,
#endif
.bFrameIndex = 1, // 1-based index
.bmCapabilities = 0,

View File

@ -405,7 +405,7 @@ typedef struct TU_ATTR_PACKED {
uint8_t bDescriptorSubType;
uint8_t bFormatIndex;
uint8_t bNumFrameDescriptors;
uint8_t bmFlags;
uint8_t bmFlags; // Bit 0: fixed size samples (1 = yes)
uint8_t bDefaultFrameIndex;
uint8_t bAspectRatioX;
uint8_t bAspectRatioY;
@ -415,7 +415,15 @@ typedef struct TU_ATTR_PACKED {
// MJPEG payload specs: 3.1.2 frame descriptor (same as uncompressed)
typedef tusb_desc_video_frame_uncompressed_t tusb_desc_video_frame_mjpeg_t;
typedef tusb_desc_video_frame_uncompressed_1int_t tusb_desc_video_frame_mjpeg_1int_t;
typedef tusb_desc_video_frame_uncompressed_2int_t tusb_desc_video_frame_mjpeg_2int_t;
typedef tusb_desc_video_frame_uncompressed_3int_t tusb_desc_video_frame_mjpeg_3int_t;
typedef tusb_desc_video_frame_uncompressed_4int_t tusb_desc_video_frame_mjpeg_4int_t;
// continuous = 3 intervals: min, max, step
typedef tusb_desc_video_frame_mjpeg_3int_t tusb_desc_video_frame_mjpeg_continuous_t;
//------------- DV -------------//
// DV payload specs: 3.1.1
typedef struct TU_ATTR_PACKED {
uint8_t bLength;