From nobody Sun Aug 9 17:01:44 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hJ4156lr5z6nm03 for ; Sun, 09 Aug 2026 17:01:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hJ41503Ktz3lkh for ; Sun, 09 Aug 2026 17:01:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786294905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n7Kyn1WKUJ3gVRNc+bKJtqJTYXKXmxgI8sn1T7RvmtQ=; b=esCTxIRNXn/wppL+kMvfvoengwPUVHUd4cd8rN0Uittp6dMFbmxPwRjpMAMkXC7uKK3y/7 9wS+99m/s816wbIueTqjtXvjZfwLz3Nfv6gaLxQjU+Tb90hHubZ0TeJGJH2W50XPhF2F+W 8DPOAjBl+/KYD+Tqrt+Szf177BsJMWijnC0vWbGaa+dNtcpBrSybUOI+3+kpuaH4H27oPz O2TFqLiW07ZcVdzSbwRtJuOLG/cSnvE46MqK8Wtyj812MjrtHSlcDcr03w3pGH2drWiNuu hly35OCx5n1LkNB3HHVYBQ+FVK+THfWz+5EOuiBfRTv/NhD2aT2q4uu5zZyblg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786294905; a=rsa-sha256; cv=none; b=tcbzdIMh5jVlgopNjyrBAYoalaq5kRPJsxQIQ1VInyFhvGEwX2vLyPoG5kIxlVeQULPByu sNhpS+gXSF5yMVRTpm0m3bajJl+/j7djXjYoVAbHqSLlV8rQewdVffYOlY+0wVQUQohykb swqdCx0403Q9pTdYlAxY0RXDF6GWDdIKAb8r+hsYrlAxXhxlGpdAVo5hJMLRFNdScFTy5b H/CCyPcb9pXRVPnO3xG3yvxlr8i0FHcL5sO+5StzMcXx+BsxAsJlHynoxDGEPL7Z5VPWgY RojDDAfnbcDG6gnE6tAg7Yjdrmo2yzbavMi8KnfkgEA//KBzp1fMzchTy6+nkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786294905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n7Kyn1WKUJ3gVRNc+bKJtqJTYXKXmxgI8sn1T7RvmtQ=; b=f96VMiZQs/4ffY6OtXyR9iI96JrXEyVcCxRJh9QNi+7dpGyNwm1ze70SLdQbWeLBtBPVYs Cl7lULVXwIuyr7Y1QfANNPLksK/Pq9vRZbCT2XttMpClFQUlDTWX9DlCvW7frOBQ9O2pn9 JcyDRYt99kpCsugkeoi64QuU1b1ZHZ5BbggbeCfCyaPCdFPIspQ4vfVg8Er6Cr2q1GCdcT pNSwtjyTr4dZdNkq0s8cONTUVpc9ZzJBUqcBsKe6c3yU5qbCRKOH/SoIWfiZvVM4vV9Bvw v5fLjhLk+y0KNrwscENzUFagzyoY/OSRa8Daka1WDwloFZfX0qo5HCloVLOs9w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hJ4145K0yzWpg for ; Sun, 09 Aug 2026 17:01:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3b176 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 09 Aug 2026 17:01:44 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Abdelkader Boudih From: Adrian Chadd Subject: git: 33fd5d168d32 - main - uvideo: do not reject unsupported pixel formats List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: adrian X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 33fd5d168d329f861e679a50c4b2431334bfcaf7 Auto-Submitted: auto-generated Date: Sun, 09 Aug 2026 17:01:44 +0000 Message-Id: <6a78b278.3b176.4fdc42cf@gitrepo.freebsd.org> The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=33fd5d168d329f861e679a50c4b2431334bfcaf7 commit 33fd5d168d329f861e679a50c4b2431334bfcaf7 Author: Abdelkader Boudih AuthorDate: 2026-08-09 16:59:44 +0000 Commit: Adrian Chadd CommitDate: 2026-08-09 16:59:46 +0000 uvideo: do not reject unsupported pixel formats Reviewed by: adrian, bapt Differential Revision: https://reviews.freebsd.org/D58503 --- sys/dev/usb/video/uvideo.c | 90 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 23 deletions(-) diff --git a/sys/dev/usb/video/uvideo.c b/sys/dev/usb/video/uvideo.c index 1e19ab42d869..e682f0ae6952 100644 --- a/sys/dev/usb/video/uvideo.c +++ b/sys/dev/usb/video/uvideo.c @@ -150,6 +150,9 @@ static int uvideo_hw_querycap(device_t, struct video_caps *); static int uvideo_hw_enum_format(device_t, uint32_t, struct video_format *); static int uvideo_hw_get_format(device_t, struct video_format *); static int uvideo_hw_try_format(device_t, struct video_format *); +static int uvideo_select_fmtgrp(struct uvideo_softc *, uint32_t); +static uint32_t uvideo_bytesperline(struct uvideo_format_group *, uint32_t); +static uint32_t uvideo_frame_sizeimage(struct usb_video_frame_desc *); static int uvideo_hw_set_format(device_t, const struct video_format *); static int uvideo_hw_enum_framesizes(device_t, struct video_frmsizeenum *); static int uvideo_hw_enum_frameintervals(device_t, @@ -2754,6 +2757,8 @@ uvideo_hw_get_format(device_t dev, struct video_format *fmt) if (frame != NULL) { fmt->width = UGETW(UVIDEO_FRAME_FIELD(frame, wWidth)); fmt->height = UGETW(UVIDEO_FRAME_FIELD(frame, wHeight)); + fmt->bytesperline = uvideo_bytesperline(sc->sc_fmtgrp_cur, + fmt->width); } fmt->sizeimage = UGETDW(sc->sc_desc_probe.dwMaxVideoFrameSize); @@ -2766,31 +2771,78 @@ uvideo_hw_get_format(device_t dev, struct video_format *fmt) return (0); } +/* + * VIDIOC_TRY_FMT and VIDIOC_S_FMT must not fail on an unsupported + * pixel format; they substitute one the device does support. + */ +static int +uvideo_select_fmtgrp(struct uvideo_softc *sc, uint32_t pixelformat) +{ + int i; + + for (i = 0; i < sc->sc_fmtgrp_num; i++) { + if (pixelformat == sc->sc_fmtgrp[i].pixelformat) + return (i); + } + if (sc->sc_fmtgrp_cur != NULL) + return (sc->sc_fmtgrp_cur - sc->sc_fmtgrp); + return (0); +} + +static uint32_t +uvideo_bytesperline(struct uvideo_format_group *fmtgrp, uint32_t width) +{ + uint8_t bpp; + + switch (fmtgrp->format->bDescriptorSubtype) { + case UDESCSUB_VS_FORMAT_UNCOMPRESSED: + bpp = fmtgrp->format->u.uc.bBitsPerPixel; + break; + case UDESCSUB_VS_FORMAT_FRAME_BASED: + bpp = fmtgrp->format->u.fb.bBitsPerPixel; + break; + default: + return (0); /* compressed */ + } + return (width * bpp / 8); +} + +static uint32_t +uvideo_frame_sizeimage(struct usb_video_frame_desc *frame) +{ + + switch (frame->bDescriptorSubtype) { + case UDESCSUB_VS_FRAME_UNCOMPRESSED: + case UDESCSUB_VS_FRAME_MJPEG: + return (UGETDW(frame->u.uc.dwMaxVideoFrameBufferSize)); + default: + return (0); + } +} + static int uvideo_hw_try_format(device_t dev, struct video_format *fmt) { struct uvideo_softc *sc = device_get_softc(dev); + struct usb_video_frame_desc *frame; struct uvideo_res r; - int found, i; - - for (found = 0, i = 0; i < sc->sc_fmtgrp_num; i++) { - if (fmt->pixelformat == sc->sc_fmtgrp[i].pixelformat) { - found = 1; - break; - } - } - if (found == 0) - return (EINVAL); + int i; - if (sc->sc_fmtgrp[i].frame_num == 0) + i = uvideo_select_fmtgrp(sc, fmt->pixelformat); + if (i >= sc->sc_fmtgrp_num || sc->sc_fmtgrp[i].frame_num == 0) return (EINVAL); uvideo_find_res(sc, i, fmt->width, fmt->height, &r); + frame = sc->sc_fmtgrp[i].frame[r.fidx]; + fmt->pixelformat = sc->sc_fmtgrp[i].pixelformat; fmt->width = r.width; fmt->height = r.height; fmt->field = V4L2_FIELD_NONE; - fmt->sizeimage = UGETDW(sc->sc_desc_probe.dwMaxVideoFrameSize); + fmt->bytesperline = uvideo_bytesperline(&sc->sc_fmtgrp[i], r.width); + fmt->sizeimage = uvideo_frame_sizeimage(frame); + if (fmt->sizeimage == 0) + fmt->sizeimage = UGETDW(sc->sc_desc_probe.dwMaxVideoFrameSize); if (sc->sc_fmtgrp[i].has_colorformat) { fmt->colorspace = sc->sc_fmtgrp[i].colorspace; @@ -2808,19 +2860,11 @@ uvideo_hw_set_format(device_t dev, const struct video_format *fmt) struct uvideo_format_group *fmtgrp_save; struct usb_video_frame_desc *frame_save; struct uvideo_res r; - int found, i; + int i; usb_error_t error; - for (found = 0, i = 0; i < sc->sc_fmtgrp_num; i++) { - if (fmt->pixelformat == sc->sc_fmtgrp[i].pixelformat) { - found = 1; - break; - } - } - if (found == 0) - return (EINVAL); - - if (sc->sc_fmtgrp[i].frame_num == 0) + i = uvideo_select_fmtgrp(sc, fmt->pixelformat); + if (i >= sc->sc_fmtgrp_num || sc->sc_fmtgrp[i].frame_num == 0) return (EINVAL); uvideo_find_res(sc, i, fmt->width, fmt->height, &r);