From patchwork Thu Nov 28 14:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13888097 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65ED725761 for ; Thu, 28 Nov 2024 14:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732805519; cv=none; b=Jm9N1c31XbXCAcnwVIXO6gpd1+nm5jW58cLzjiWNflNVySABYkKePRgUfoXA3Pt2NxrPkypJZH7CPCFhclikzbYrNZvpUZ6IYx2nwaIwGt9n5HUEyRVpEvbcNAHROksaEs/WOYnpklk2UQdGq0d/h8fdJ+9pfAlIwgAZgejN/IM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732805519; c=relaxed/simple; bh=ds8I9t+lul7skH+kL3SwaEMh0S5SE+8WSPxu5E8/3dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LpIWi8oh4TCGRewRcFzcsC2mXzKUXCtCV0qLb8BYfrnnJwtItms1uvPeaYj/ELbcbg8dtIIZMpfniS/uUiMGL/9TVBS72ka9uoDV7zhWf8Et+KOFdIDZAONK9+EcDuGek6/pEV9cbRI9XRjedP5FNzz6UUp8m2llQlrWHonXvQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ZaVeZwET; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZaVeZwET" Received: from isaac-ThinkPad-T16-Gen-2.lan (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 61D04842; Thu, 28 Nov 2024 15:51:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732805486; bh=ds8I9t+lul7skH+kL3SwaEMh0S5SE+8WSPxu5E8/3dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZaVeZwET3IFDxXBmc+rFrCf1NN0hO64Dm0zNao/Cx4SICXgpsO3wlPj6Ao4Jhhs1a CfQYxb0LSPfJH4xGWaJ1zFs32S5awzqT/pAXSHWfeCC6enS6CgGHA0BuQt2PqTUWJT 1Fxljg3u1ObSdfxrjz/PJ39gP9OPuOogYHXEoPoE= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH v8 1/2] media: uvcvideo: Implement dual stream quirk to fix loss of usb packets Date: Thu, 28 Nov 2024 14:51:43 +0000 Message-ID: <20241128145144.61475-2-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128145144.61475-1-isaac.scott@ideasonboard.com> References: <20241128145144.61475-1-isaac.scott@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some cameras, such as the Sonix Technology Co. 292A, exhibit issues when running two parallel streams, causing USB packets to be dropped when an H.264 stream posts a keyframe while an MJPEG stream is running simultaneously. This occasionally causes the driver to erroneously output two consecutive JPEG images as a single frame. To fix this, we inspect the buffer, and trigger a new frame when we find an SOI. Signed-off-by: Isaac Scott Reviewed-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 27 ++++++++++++++++++++++++++- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index e00f38dd07d9..6d800a099749 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -20,6 +20,7 @@ #include #include +#include #include #include "uvcvideo.h" @@ -1116,6 +1117,7 @@ static void uvc_video_stats_stop(struct uvc_streaming *stream) static int uvc_video_decode_start(struct uvc_streaming *stream, struct uvc_buffer *buf, const u8 *data, int len) { + u8 header_len; u8 fid; /* @@ -1129,6 +1131,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, return -EINVAL; } + header_len = data[0]; fid = data[1] & UVC_STREAM_FID; /* @@ -1210,9 +1213,31 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, return -EAGAIN; } + /* + * Some cameras, when running two parallel streams (one MJPEG alongside + * another non-MJPEG stream), are known to lose the EOF packet for a frame. + * We can detect the end of a frame by checking for a new SOI marker, as + * the SOI always lies on the packet boundary between two frames for + * these devices. + */ + if (stream->dev->quirks & UVC_QUIRK_MJPEG_NO_EOF && + (stream->cur_format->fcc == V4L2_PIX_FMT_MJPEG || + stream->cur_format->fcc == V4L2_PIX_FMT_JPEG)) { + const u8 *packet = data + header_len; + + if (len >= header_len + 2 && + packet[0] == 0xff && packet[1] == JPEG_MARKER_SOI && + buf->bytesused != 0) { + buf->state = UVC_BUF_STATE_READY; + buf->error = 1; + stream->last_fid ^= UVC_STREAM_FID; + return -EAGAIN; + } + } + stream->last_fid = fid; - return data[0]; + return header_len; } static inline enum dma_data_direction uvc_stream_dir( diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index b7d24a853ce4..040073326a24 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -76,6 +76,7 @@ #define UVC_QUIRK_NO_RESET_RESUME 0x00004000 #define UVC_QUIRK_DISABLE_AUTOSUSPEND 0x00008000 #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000 +#define UVC_QUIRK_MJPEG_NO_EOF 0x00020000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 From patchwork Thu Nov 28 14:51:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13888099 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 197151BCA0E for ; Thu, 28 Nov 2024 14:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732805522; cv=none; b=Bfiw95eszrVS+i6bk/izQWyWmvCnbPfOkwMWTlP5/M5ltQm9ZuXKYWRG/Z6PySp6Ikpfka8+d8giwjl4vx5ENMZ5ykMfNS5gun4zHvN5fXBIjnm+p1LsTsfHX/OHuBsebvjGyhZ+VSzCwaKI+EZvYQ6X7b6VLiPEvA/8SFvKaLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732805522; c=relaxed/simple; bh=wOe/fwOqMrq2Pfo5yzQgmriasDxgmlPfXlg498NyXJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G3r9VqWby1kiKt9GWQSAwh8NfS+vuzxmSw9doreAWRcj3MgyXLHBD9KbFMpW5z9PFbNIKkdtgMY/A6NIdn+lYIfsWlPa8ul7c0mM7cghJ2u+lUr0zL8UAuV8rkGrmSnVTwdoWiPSxfM3U4lUINVhgkiyn9v2MqYtcx3I+Z7FJic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=DhKwMi3o; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DhKwMi3o" Received: from isaac-ThinkPad-T16-Gen-2.lan (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A8C31C21; Thu, 28 Nov 2024 15:51:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732805486; bh=wOe/fwOqMrq2Pfo5yzQgmriasDxgmlPfXlg498NyXJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DhKwMi3oYKfnFNEzF52WrfynWU8ujEErkanoM5acxpbH5FE+JE/OxYdY4ttjncPFG 0WwPB6+GnFIiiORsuI73unNQQ5gGs6FCshmrwL1AZ9b0p4idUuHILZc/W1BlU2r/eA Vhl/fSkxQZk+03CfnsqmG8ck9l4Uriv9She3uVsc= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH v8 2/2] media: uvcvideo: Add new quirk definition for the Sonix Technology Co. 292a camera Date: Thu, 28 Nov 2024 14:51:44 +0000 Message-ID: <20241128145144.61475-3-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128145144.61475-1-isaac.scott@ideasonboard.com> References: <20241128145144.61475-1-isaac.scott@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The Sonix Technology Co. 292A camera (which uses an AR0330 sensor), can produce MJPEG and H.264 streams concurrently. When doing so, it drops the last packets of MJPEG frames every time the H.264 stream generates a key frame. Set the UVC_QUIRK_MJPEG_NO_EOF quirk to work around the issue. Reviewed-by: Laurent Pinchart Signed-off-by: Isaac Scott --- drivers/media/usb/uvc/uvc_driver.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 0fac689c6350..15aee3f2b5f9 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2752,6 +2752,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, + /* Sonix Technology Co. Ltd. - 292A IPC AR0330 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x0c45, + .idProduct = 0x6366, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) }, /* MT6227 */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, From patchwork Tue Dec 17 11:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13911650 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDEFA12C80C for ; Tue, 17 Dec 2024 11:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734434044; cv=none; b=qu/A2TK4NJdC2WRM5iCwO1QlNyRTOrXuLrZJyPNXE6Emz4nJDOHx5ZKZKixYeHXkVMX5rqLXTSmdDt1ykqJjqmEo1zxP9pv+cvdlCoG6lsaM6PuDtO+WlpAX0Awdoy+GXc41UctKUBA2n/bk+pVJkmEmJerzbG09CiJtcW3cOeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734434044; c=relaxed/simple; bh=8SoE1vviwSn3XgmzdGVI5fEkumKe7td4ofxojT72G0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YF/MQDo2ReXO8BlnqIoeFYzDBCSoVDDWwirlP4wk5lurJ17s+MIlxY8THNA5ALQcXfBM3+dLC42RnM/c33X/Wk+JQNRo/ljvCUAbfnMSIi6GSIbmlAzNiWctev0KXcfu+UfFDQcKXOwcm0hZBn5tL17IInH0RaWpfxLkd4LaVy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=jwblr6t1; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jwblr6t1" Received: from isaac-ThinkPad-T16-Gen-2.lan (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 914A255; Tue, 17 Dec 2024 12:13:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1734434003; bh=8SoE1vviwSn3XgmzdGVI5fEkumKe7td4ofxojT72G0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jwblr6t1plSsV+p4DklWXjTLjTMUWPfE0cjhbaym0surTp6+hZGjyYTGZcvQ+07qS hC/oVPguUwyDEpqYXrrbNfHJCnKz+AzwrVCeBzYlPDkEL1sZNMT/O/2Jhc0BkV4g5o rm+huO1newBjg9MjpmX8PGj97O4DhL5WClvC4H3g= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH 3/2] media: uvcvideo: Add Kurokesu C1 PRO camera Date: Tue, 17 Dec 2024 11:13:51 +0000 Message-ID: <20241217111351.1890805-1-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128145144.61475-1-isaac.scott@ideasonboard.com> References: <20241128145144.61475-1-isaac.scott@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for the Kurokesu C1 PRO camera. This camera experiences the same issues faced by the Sonix Technology Co. 292A IPC AR0330. As such, enable the UVC_QUIRK_MJPEG_NO_EOF quirk for this device to prevent frames from being erroneously dropped. Signed-off-by: Isaac Scott Reviewed-by: Laurent Pinchart --- This camera experiences the same issues as the other camera in this series. As it is dependent on the series that is not yet merged, I am appending it here so they can be merged together. drivers/media/usb/uvc/uvc_driver.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 1d029ef654bd..45028b45906a 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2768,6 +2768,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) }, + /* Kurokesu C1 PRO */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x16d0, + .idProduct = 0x0ed1, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_MJPEG_NO_EOF) }, /* MT6227 */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,