summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-01-26 23:23:38 +0700
committerhathach <[email protected]>2024-01-26 23:23:38 +0700
commit0daf8ec51b9513fbab9601fedb2150dda3927b05 (patch)
tree3dc13921b3ac20f6232a007135a232cad686c13d
parentb5cd673330fc87f2981ecf139b24940df5cb3cfe (diff)
update example to work bulk mjpeg
-rw-r--r--examples/device/video_capture/src/usb_descriptors.c27
-rw-r--r--src/class/video/video.h10
2 files changed, 35 insertions, 2 deletions
diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c
index 8e54d3afd..90a6b27a2 100644
--- a/examples/device/video_capture/src/usb_descriptors.c
+++ b/examples/device/video_capture/src/usb_descriptors.c
@@ -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,
diff --git a/src/class/video/video.h b/src/class/video/video.h
index 162d4e4c4..bed8eeecf 100644
--- a/src/class/video/video.h
+++ b/src/class/video/video.h
@@ -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;