@@ -577,7 +577,7 @@ static int uvc_get_vs_probe_max_size(const struct device *dev, struct uvc_probe
577577{
578578 struct uvc_data * data = dev -> data ;
579579 struct video_format * fmt = & data -> video_fmt ;
580- uint32_t max_frame_size = MAX ( fmt -> pitch , fmt -> width ) * fmt -> height ;
580+ uint32_t max_frame_size = fmt -> size ;
581581 uint32_t max_payload_size = max_frame_size + UVC_MAX_HEADER_LENGTH ;
582582
583583 switch (request ) {
@@ -633,9 +633,8 @@ static int uvc_get_vs_format_from_desc(const struct device *dev, struct video_fo
633633 /* Fill the format according to what the host selected */
634634 fmt -> width = frame_desc -> wWidth ;
635635 fmt -> height = frame_desc -> wHeight ;
636- fmt -> pitch = fmt -> width * video_bits_per_pixel (fmt -> pixelformat ) / BITS_PER_BYTE ;
637636
638- return 0 ;
637+ return video_estimate_fmt_size ( fmt ) ;
639638}
640639
641640static int uvc_get_vs_probe_struct (const struct device * dev , struct uvc_probe * const probe ,
@@ -1480,8 +1479,7 @@ static void uvc_set_vs_bitrate_range(struct uvc_frame_discrete_descriptor *const
14801479 uint32_t bitrate_max = sys_le32_to_cpu (desc -> dwMaxBitRate );
14811480 uint32_t bitrate ;
14821481
1483- /* Multiplication/division in this order to avoid overflow */
1484- bitrate = MAX (fmt -> pitch , fmt -> width ) * frmival_nsec / (NSEC_PER_SEC / 100 ) * fmt -> height ;
1482+ bitrate = (uint64_t )fmt -> size * frmival_nsec / (NSEC_PER_SEC / 100 );
14851483
14861484 /* Extend the min/max value to include the bitrate of this format */
14871485 bitrate_min = MIN (bitrate_min , bitrate );
@@ -1531,7 +1529,6 @@ static int uvc_add_vs_frame_desc(const struct device *dev,
15311529 struct video_format fmt = {.pixelformat = cap -> pixelformat ,
15321530 .width = w , .height = h , .pitch = p };
15331531 struct video_frmival_enum fie = {.format = & fmt };
1534- uint32_t max_size = MAX (p , w ) * h ;
15351532 int first_err = 0 ;
15361533 int ret ;
15371534
@@ -1551,7 +1548,7 @@ static int uvc_add_vs_frame_desc(const struct device *dev,
15511548 desc -> bFrameIndex = format_desc -> bNumFrameDescriptors + 1 ;
15521549 desc -> wWidth = sys_cpu_to_le16 (w );
15531550 desc -> wHeight = sys_cpu_to_le16 (h );
1554- desc -> dwMaxVideoFrameBufferSize = sys_cpu_to_le32 (max_size );
1551+ desc -> dwMaxVideoFrameBufferSize = sys_cpu_to_le32 (fmt . size );
15551552 desc -> bDescriptorSubtype = (format_desc -> bDescriptorSubtype == UVC_VS_FORMAT_UNCOMPRESSED )
15561553 ? UVC_VS_FRAME_UNCOMPRESSED : UVC_VS_FRAME_MJPEG ;
15571554 desc -> dwMinBitRate = sys_cpu_to_le32 (UINT32_MAX );
0 commit comments