@@ -74,10 +74,13 @@ typedef union {
7474
7575typedef union {
7676 struct TU_ATTR_PACKED {
77- uint8_t bLength ;
78- uint8_t bDescriptorType ;
79- uint8_t bDescriptorSubType ;
80- uint8_t bFrameIndex ;
77+ uint8_t bLength ;
78+ uint8_t bDescriptorType ;
79+ uint8_t bDescriptorSubType ;
80+ uint8_t bFrameIndex ;
81+ uint8_t bmCapabilities ;
82+ uint16_t wWidth ;
83+ uint16_t wHeight ;
8184 };
8285 tusb_desc_cs_video_frm_uncompressed_t uncompressed ;
8386 tusb_desc_cs_video_frm_mjpeg_t mjpeg ;
@@ -396,10 +399,10 @@ static bool _update_streaming_parameters(videod_streaming_interface_t const *stm
396399 if (!frame_size ) {
397400 switch (fmt -> bDescriptorSubType ) {
398401 case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED :
399- frame_size = (uint_fast32_t )frm -> uncompressed . wWidth * frm -> uncompressed . wHeight * fmt -> uncompressed .bBitsPerPixel / 8 ;
402+ frame_size = (uint_fast32_t )frm -> wWidth * frm -> wHeight * fmt -> uncompressed .bBitsPerPixel / 8 ;
400403 break ;
401404 case VIDEO_CS_ITF_VS_FORMAT_MJPEG :
402- frame_size = (uint_fast32_t )frm -> mjpeg . wWidth * frm -> mjpeg . wHeight * 16 / 8 ; /* YUV422 */
405+ frame_size = (uint_fast32_t )frm -> wWidth * frm -> wHeight * 16 / 8 ; /* YUV422 */
403406 break ;
404407 default : break ;
405408 }
@@ -467,7 +470,7 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
467470 tusb_desc_vs_itf_t const * vs = _get_desc_vs (stm );
468471 TU_ASSERT (vs );
469472 void const * end = _end_of_streaming_descriptor (vs );
470- tusb_desc_cs_video_fmt_uncompressed_t const * fmt = _find_desc_format (tu_desc_next (vs ), end , fmtnum );
473+ tusb_desc_cs_video_fmt_t const * fmt = _find_desc_format (tu_desc_next (vs ), end , fmtnum );
471474 switch (request ) {
472475 case VIDEO_REQUEST_GET_MAX :
473476 frmnum = fmt -> bNumFrameDescriptors ;
@@ -476,57 +479,75 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
476479 frmnum = 1 ;
477480 break ;
478481 case VIDEO_REQUEST_GET_DEF :
479- frmnum = fmt -> bDefaultFrameIndex ;
482+ switch (fmt -> bDescriptorSubType ) {
483+ case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED :
484+ frmnum = fmt -> uncompressed .bDefaultFrameIndex ;
485+ break ;
486+ case VIDEO_CS_ITF_VS_FORMAT_MJPEG :
487+ frmnum = fmt -> mjpeg .bDefaultFrameIndex ;
488+ break ;
489+ default : return false;
490+ }
480491 break ;
481492 default : return false;
482493 }
483494 param -> bFrameIndex = (uint8_t )frmnum ;
484495 /* Set the parameters determined by the frame */
485- tusb_desc_cs_video_frm_uncompressed_t const * frm = _find_desc_frame (tu_desc_next (fmt ), end , frmnum );
486- param -> dwMaxVideoFrameSize = (uint32_t )(frm -> wWidth * frm -> wHeight * fmt -> bBitsPerPixel / 8 );
496+ tusb_desc_cs_video_frm_t const * frm = _find_desc_frame (tu_desc_next (fmt ), end , frmnum );
497+ uint_fast32_t frame_size ;
498+ switch (fmt -> bDescriptorSubType ) {
499+ case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED :
500+ frame_size = (uint_fast32_t )frm -> wWidth * frm -> wHeight * fmt -> uncompressed .bBitsPerPixel / 8 ;
501+ break ;
502+ case VIDEO_CS_ITF_VS_FORMAT_MJPEG :
503+ frame_size = (uint_fast32_t )frm -> wWidth * frm -> wHeight * 16 / 8 ; /* YUV422 */
504+ break ;
505+ default : return false;
506+ }
507+ param -> dwMaxVideoFrameSize = frame_size ;
487508 return true;
488509 }
489510
490511 if (!param -> dwFrameInterval ) {
491512 tusb_desc_vs_itf_t const * vs = _get_desc_vs (stm );
492513 TU_ASSERT (vs );
493514 void const * end = _end_of_streaming_descriptor (vs );
494- tusb_desc_cs_video_fmt_uncompressed_t const * fmt = _find_desc_format (tu_desc_next (vs ), end , fmtnum );
495- tusb_desc_cs_video_frm_uncompressed_t const * frm = _find_desc_frame (tu_desc_next (fmt ), end , frmnum );
515+ tusb_desc_cs_video_fmt_t const * fmt = _find_desc_format (tu_desc_next (vs ), end , fmtnum );
516+ tusb_desc_cs_video_frm_t const * frm = _find_desc_frame (tu_desc_next (fmt ), end , frmnum );
496517
497518 uint_fast32_t interval , interval_ms ;
498519 switch (request ) {
499520 case VIDEO_REQUEST_GET_MAX :
500521 {
501522 uint_fast32_t min_interval , max_interval ;
502- uint_fast8_t num_intervals = frm -> bFrameIntervalType ;
503- max_interval = num_intervals ? frm -> dwFrameInterval [num_intervals - 1 ]: frm -> dwFrameInterval [1 ];
504- min_interval = frm -> dwFrameInterval [0 ];
523+ uint_fast8_t num_intervals = frm -> uncompressed . bFrameIntervalType ;
524+ max_interval = num_intervals ? frm -> uncompressed . dwFrameInterval [num_intervals - 1 ]: frm -> uncompressed . dwFrameInterval [1 ];
525+ min_interval = frm -> uncompressed . dwFrameInterval [0 ];
505526 interval = max_interval ;
506527 interval_ms = min_interval / 10000 ;
507528 }
508529 break ;
509530 case VIDEO_REQUEST_GET_MIN :
510531 {
511532 uint_fast32_t min_interval , max_interval ;
512- uint_fast8_t num_intervals = frm -> bFrameIntervalType ;
513- max_interval = num_intervals ? frm -> dwFrameInterval [num_intervals - 1 ]: frm -> dwFrameInterval [1 ];
514- min_interval = frm -> dwFrameInterval [0 ];
533+ uint_fast8_t num_intervals = frm -> uncompressed . bFrameIntervalType ;
534+ max_interval = num_intervals ? frm -> uncompressed . dwFrameInterval [num_intervals - 1 ]: frm -> uncompressed . dwFrameInterval [1 ];
535+ min_interval = frm -> uncompressed . dwFrameInterval [0 ];
515536 interval = min_interval ;
516537 interval_ms = max_interval / 10000 ;
517538 }
518539 break ;
519540 case VIDEO_REQUEST_GET_DEF :
520- interval = frm -> dwDefaultFrameInterval ;
541+ interval = frm -> uncompressed . dwDefaultFrameInterval ;
521542 interval_ms = interval / 10000 ;
522543 break ;
523544 case VIDEO_REQUEST_GET_RES :
524545 {
525- uint_fast8_t num_intervals = frm -> bFrameIntervalType ;
546+ uint_fast8_t num_intervals = frm -> uncompressed . bFrameIntervalType ;
526547 if (num_intervals ) {
527548 interval = 0 ;
528549 } else {
529- interval = frm -> dwFrameInterval [2 ];
550+ interval = frm -> uncompressed . dwFrameInterval [2 ];
530551 interval_ms = interval / 10000 ;
531552 }
532553 }
0 commit comments