From patchwork Mon Nov 11 17:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13871035 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 F34211A9B3A for ; Mon, 11 Nov 2024 17:36:56 +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=1731346618; cv=none; b=SfBSKbl4FZJm+Z09jMhNt+MbJs79+XqGpm8HqLCg81MPeaKB1uoz+FSVCe4HYS4tthFay+gqBiLOQZ6UpVx6xjrNQO+hR06o6ER9xbmZfmJahF6FFS9PyaJ2Egl21ZBRlGZS7+cbsp/+H4DyN3lGPNNyEQVri81QZzmL1LL1Wc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731346618; c=relaxed/simple; bh=D4id7VakC7hPHNlsGaJB5JUJdfd4//iCnmao+BNS7cY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FsDfNNSAF3DaVPGRln3ae3dt1Dyzz8eTKA8KKudwsE7D1oRa3APHN41vYCrzlQqhOFLquqGqZeYE9dc0RKyDFFkr3Jp4mlhrrSekoi0gNyqgXVui2aKsXv6oOsWdo8sTdQnZAJIODv6IKvMjROSD60sNWlKxi4ubvP6XxeDAaN8= 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=FMue2rJH; 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="FMue2rJH" Received: from isaac-ThinkPad-T16-Gen-2.local (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8F2DBFF6; Mon, 11 Nov 2024 18:36:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731346597; bh=D4id7VakC7hPHNlsGaJB5JUJdfd4//iCnmao+BNS7cY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FMue2rJHZ8OQsFCjImMvcSyzIfh3lo0C4GnCJi61vOm+YaZg+frg4iB8CvPbj0iBa FK6Aa3Hgg6y6qL+uOmlIReoFBF4iIJ0H5h75p2yL2IbWSiQTPLaomml4oNtwQYePMX TWC/tSOgxXw5Ky+RwlayEzlEAzYLJdpJsmMwy2rI= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH v5 1/2] media: uvcvideo: Implement dual stream quirk to fix loss of usb packets Date: Mon, 11 Nov 2024 17:36:38 +0000 Message-ID: <20241111173639.25131-2-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241111173639.25131-1-isaac.scott@ideasonboard.com> References: <20241111173639.25131-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 --- 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..028f16dc189a 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -21,6 +21,7 @@ #include #include +#include #include "uvcvideo.h" @@ -1117,6 +1118,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, struct uvc_buffer *buf, const u8 *data, int len) { u8 fid; + u8 header_len; /* * Sanity checks: @@ -1129,6 +1131,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, return -EINVAL; } + header_len = data[0]; + fid = data[1] & UVC_STREAM_FID; /* @@ -1210,9 +1214,30 @@ 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. + */ + 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 = ((const u8 *)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..116b1e383c25 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 Mon Nov 11 17:36:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13871036 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 730541B3B28 for ; Mon, 11 Nov 2024 17:37: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=1731346621; cv=none; b=Zi8yHkwYYq95fe5HAPrG9mxe/ovrLg+NGFeIEIWgAji8YuF6ZV9Ebu5QSVwhpJCSbbEa8PXlNyPd5lj2q5Qj9ufLod8kf8KKGIqkfIwJgfpFpz/AuQGubPwsEQ8J1dkKiCN5/zhdQxf4vmWdQbXgCTzAKg8O2HT+lfOYfTyDOCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731346621; c=relaxed/simple; bh=1E47PqxTJ5L7o8edDg7vV3GOuHVMnxQaST22oQSQedg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y2+1K/W7y+J0SlXK7l80frJ7Imp7kAH/IxPVK5vp2Sw/K0ae2H8thyrTDOniGl6iBjHNYHb13EiGVWirfPbXLU2GZ68bHTsS9Jz10Sq+RDq802wlTVtRRxKPadhWY3gfSNiyekih+3XMfygCN5a4Uan1o7S0gHxnAXf0r3SDBuI= 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=IwHyR2lY; 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="IwHyR2lY" Received: from isaac-ThinkPad-T16-Gen-2.local (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5C39010D8; Mon, 11 Nov 2024 18:36:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731346600; bh=1E47PqxTJ5L7o8edDg7vV3GOuHVMnxQaST22oQSQedg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwHyR2lY/oMqjI0QTO+toohulmV/DW2gZhiG6DU74tk7ao9pL6pEo3QDLMX1EGkVT lXBV50leAbce/6OB/ShHptjp7NuRXlr5WhuB1RpZer+P8G0qmqDctD3VCXzXtE1Fl3 Gnqp7SwN3PV19kKBlELl4qhLhCRE3wqDYdOt5Isk= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH v5 2/2] media: uvcvideo: Add new quirk definition for the Sonix Technology Co. 292a camera Date: Mon, 11 Nov 2024 17:36:39 +0000 Message-ID: <20241111173639.25131-3-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241111173639.25131-1-isaac.scott@ideasonboard.com> References: <20241111173639.25131-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 the definition of a new quirk that supports the Sonix Technology Co. 292A camera, which uses the AR0330 sensor. The camera supports the output of two simultaneous streams, which need to be handled appropriately by the driver. 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,