Skip to content

Commit 0daf8ec

Browse files
committed
update example to work bulk mjpeg
1 parent b5cd673 commit 0daf8ec

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

examples/device/video_capture/src/usb_descriptors.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ uint8_t const* tud_descriptor_device_cb(void) {
109109
#define EPNUM_VIDEO_IN 0x81
110110
#endif
111111

112+
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
113+
#define USE_MJPEG
114+
#endif
115+
112116
// For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
113117
// To further reduce the size, we use MJPEG format instead of YUY2.
114118
// Select interface descriptor and length accordingly.
@@ -197,8 +201,15 @@ typedef struct TU_ATTR_PACKED {
197201
typedef struct TU_ATTR_PACKED {
198202
tusb_desc_interface_t itf;
199203
tusb_desc_video_streaming_input_header_1byte_t header;
204+
205+
#ifdef USE_MJPEG
206+
tusb_desc_video_format_mjpeg_t format;
207+
tusb_desc_video_frame_mjpeg_continuous_t frame;
208+
#else
200209
tusb_desc_video_format_uncompressed_t format;
201210
tusb_desc_video_frame_uncompressed_continuous_t frame;
211+
#endif
212+
202213
tusb_desc_video_streaming_color_matching_t color;
203214
tusb_desc_endpoint_t ep;
204215
} uvc_streaming_desc_t;
@@ -316,24 +327,38 @@ const uvc_cfg_desc_t config_desc = {
316327
.bmaControls = { 0 }
317328
},
318329
.format = {
330+
#ifdef USE_MJPEG
331+
.bLength = sizeof(tusb_desc_video_format_mjpeg_t),
332+
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
333+
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_MJPEG,
334+
.bFormatIndex = 1, // 1-based index
335+
.bNumFrameDescriptors = 1,
336+
.bmFlags = 0,
337+
#else
319338
.bLength = sizeof(tusb_desc_video_format_uncompressed_t),
320339
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
321340
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED,
322-
323341
.bFormatIndex = 1, // 1-based index
324342
.bNumFrameDescriptors = 1,
325343
.guidFormat = { TUD_VIDEO_GUID_YUY2 },
326344
.bBitsPerPixel = 16,
345+
#endif
327346
.bDefaultFrameIndex = 1,
328347
.bAspectRatioX = 0,
329348
.bAspectRatioY = 0,
330349
.bmInterlaceFlags = 0,
331350
.bCopyProtect = 0
332351
},
333352
.frame = {
353+
#ifdef USE_MJPEG
354+
.bLength = sizeof(tusb_desc_video_frame_mjpeg_continuous_t),
355+
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
356+
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_MJPEG,
357+
#else
334358
.bLength = sizeof(tusb_desc_video_frame_uncompressed_continuous_t),
335359
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
336360
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_UNCOMPRESSED,
361+
#endif
337362

338363
.bFrameIndex = 1, // 1-based index
339364
.bmCapabilities = 0,

src/class/video/video.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ typedef struct TU_ATTR_PACKED {
405405
uint8_t bDescriptorSubType;
406406
uint8_t bFormatIndex;
407407
uint8_t bNumFrameDescriptors;
408-
uint8_t bmFlags;
408+
uint8_t bmFlags; // Bit 0: fixed size samples (1 = yes)
409409
uint8_t bDefaultFrameIndex;
410410
uint8_t bAspectRatioX;
411411
uint8_t bAspectRatioY;
@@ -415,7 +415,15 @@ typedef struct TU_ATTR_PACKED {
415415

416416
// MJPEG payload specs: 3.1.2 frame descriptor (same as uncompressed)
417417
typedef tusb_desc_video_frame_uncompressed_t tusb_desc_video_frame_mjpeg_t;
418+
typedef tusb_desc_video_frame_uncompressed_1int_t tusb_desc_video_frame_mjpeg_1int_t;
419+
typedef tusb_desc_video_frame_uncompressed_2int_t tusb_desc_video_frame_mjpeg_2int_t;
420+
typedef tusb_desc_video_frame_uncompressed_3int_t tusb_desc_video_frame_mjpeg_3int_t;
421+
typedef tusb_desc_video_frame_uncompressed_4int_t tusb_desc_video_frame_mjpeg_4int_t;
418422

423+
// continuous = 3 intervals: min, max, step
424+
typedef tusb_desc_video_frame_mjpeg_3int_t tusb_desc_video_frame_mjpeg_continuous_t;
425+
426+
//------------- DV -------------//
419427
// DV payload specs: 3.1.1
420428
typedef struct TU_ATTR_PACKED {
421429
uint8_t bLength;

0 commit comments

Comments
 (0)