From patchwork Fri Nov 8 14:23:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13868293 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 D678C1401C for ; Fri, 8 Nov 2024 14:23: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=1731075839; cv=none; b=Gr4ax0PW4HxDtZK9RgppTJHpGwCHw69FxUsabwHQQuYZ2C5xUEvzFu75Wb5aBoGm0ZFkf7CKmeTNmBkARozmhEWurNAeUdHSTcu80VZtFBW02tFpDBINLvgQNyXG5Ibk+Us/xXUwLiwPdpersrFF0eTtgXywEP8/keeGKqfv254= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731075839; c=relaxed/simple; bh=U5FXIWEmaVW/2zQOBF1R+jEthy2WZf5S59JvvAEX5xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D7tUOzckHcx6Uy1L9nxgkkNwlXe7U94FyroyCgj72dG28V0arQxfSDKmi2mcHAWHN4fYAChAEUJRXihzMKuGc1VR9yUc5W+Cn+ZfMAUIhGtmxRBInZCuAk+knpMt/FKEP4WGm3l24tVOMhvvM+v/PVsPTM6YrmBtjuMuwASoglk= 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=Y07Wjq4S; 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="Y07Wjq4S" 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 E04BB2E0; Fri, 8 Nov 2024 15:23:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731075827; bh=U5FXIWEmaVW/2zQOBF1R+jEthy2WZf5S59JvvAEX5xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y07Wjq4SVMHQsIyHEcnGK62hMBeB0lJYXA8S3PnzkxKzDDcSoq9kQCpoLk3MKexS9 PNrMft8ePg123LtVA+DxB/YFhXrEMQoHceJlT70OTLEFPlARQuLJwFNBdvVJ9yKlfz wOKbjG2AcTpwFK0fFVbaoonjSiuEKYEUOcktIjIs= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH 1/3] media: uvcvideo: Introduce header length Date: Fri, 8 Nov 2024 14:23:08 +0000 Message-ID: <20241108142310.19794-2-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108142310.19794-1-isaac.scott@ideasonboard.com> References: <20241108142310.19794-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 uvc_video_decode_start function returns the first byte of the header, which is in fact the length of the header. Improve readability by using an appropriately named variable. Signed-off-by: Isaac Scott --- drivers/media/usb/uvc/uvc_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index e00f38dd07d9..2fb9f2b59afc 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1117,6 +1117,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 = data[0]; /* * Sanity checks: @@ -1212,7 +1213,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, stream->last_fid = fid; - return data[0]; + return header_len; } static inline enum dma_data_direction uvc_stream_dir( From patchwork Fri Nov 8 14:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13868294 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 63AC61E5000 for ; Fri, 8 Nov 2024 14:23:59 +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=1731075840; cv=none; b=f+LG6UiFFIPHvP1dvTuggiAXypYe3OzLQFAlCnZuPUtXfMfFvHX/5Nyy3t2lvHSMyEWfZK1wKnbx9yg1JTTFRWiqIoGLenBV1I7KM8MmRaUpq9xAuuATk94aX9vrJr4Ig+ap9UFDu1WhzTX0Pm9JeoC2baPhGtejOBrYIWdJ8Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731075840; c=relaxed/simple; bh=nwezx+MzWYUp1sxZ5p8vu96Ca27g5M9sth8SL868hZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E5g8snXKEYJ1Hd1GptTwTpN6I/7azI1FAqZa0GCl7PxJ9N4K0cF0f4wuPeRKPkBFP4JAYS/VpjqqbL0ozd5/TMDPQHkJc00rtfV4vO7RKbDKf5TThlST0YKJ4E50zFcCo0z+SPoZAuPzIAk7VutwasR50qidUNTrFyiNjZ1v5ws= 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=UGPVkinZ; 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="UGPVkinZ" 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 F1FB12C5; Fri, 8 Nov 2024 15:23:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731075828; bh=nwezx+MzWYUp1sxZ5p8vu96Ca27g5M9sth8SL868hZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UGPVkinZj2Jbrt7lKjKhPqkls1/uqvNhR0pzustctJgcFSJHX3q+RszKjkI2o2SIR wBUHRiUXOS005sHBWlxcZ3rnDq8VkQsJOypDaTMS/J4h5nc4drzkKs4ueleNfg+Uuc UXP8xskddVD4B1x2nth7t1hbuxlgBtwOPaE32yo8= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH 2/3] media: uvcvideo: Add new quirk definition for the Sonix Technology Co. 292a camera Date: Fri, 8 Nov 2024 14:23:09 +0000 Message-ID: <20241108142310.19794-3-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108142310.19794-1-isaac.scott@ideasonboard.com> References: <20241108142310.19794-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 +++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 10 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, 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 Fri Nov 8 14:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 13868295 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 D93971401C for ; Fri, 8 Nov 2024 14:24: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=1731075842; cv=none; b=gGD2typEHsYtFcAg7Y/s31Z84MdroNexTYuSBtlsOm6fs/MEPDGc9AMpGX5oU8ruu4plQElUIen2yr1WYfjNSlS9dY2HYvEtZnsNWNV7FRgzGIpd4Er4Q8SJxFhv5Tcg4OL1QCPwmVP0MNY7nN9WYIPYsKwwTxDPinKag0ONdBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731075842; c=relaxed/simple; bh=Sqn9+HWWpQdz7MYA+L6Bmtb9dNvQnT5ZEPvL9moloz0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RwAqFeF+FXP1h9NtlLkOK9xVmuEuMJ/h6YC/s+njXDEzYqSfNu7p6xpFvLU5hGkciYwyJ+Wk8ArgStaMRdP+pmYGY2qV89ovB7vwZth2t6yBEJ1XhCyHWOJreM88G+wdxaYrRWvpsjfchs+veXnxcd9usJGrwot+gW4BAg+nofU= 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=dyn4Ocj7; 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="dyn4Ocj7" 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 14F0F7E9; Fri, 8 Nov 2024 15:23:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731075829; bh=Sqn9+HWWpQdz7MYA+L6Bmtb9dNvQnT5ZEPvL9moloz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyn4Ocj7B34EyPv14W++3yZMHmHtfWrxKG24hK+3ITQ+4nwJqg2Hjc7CsdtmzV+iP NhKbjFDwk2owTcxyNDNZLPeP120Z4hL97GwMEPA8iTL+KUJk8WuXK2vLaEfJxxpron 5m+IynJYjHmySuszVrX488Gefw1qcd03+GWRLGwU= From: Isaac Scott To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, Isaac Scott Subject: [PATCH 3/3] media: uvcvideo: Implement dual stream quirk to fix loss of usb packets Date: Fri, 8 Nov 2024 14:23:10 +0000 Message-ID: <20241108142310.19794-4-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108142310.19794-1-isaac.scott@ideasonboard.com> References: <20241108142310.19794-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, inverting the FID to make sure no frames are erroneously dropped. Signed-off-by: Isaac Scott --- drivers/media/usb/uvc/uvc_video.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 2fb9f2b59afc..f754109f5e96 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1211,6 +1211,30 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, return -EAGAIN; } + /* + * 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. + * + * Check the buffer for a new SOI on JPEG streams and complete the + * preceding buffer using EAGAIN, and invert the FID to make sure the + * erroneous frame is not dropped. + */ + 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 ((packet[0] == 0xff && packet[1] == 0xd8) && 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 header_len;