From patchwork Mon Sep 4 08:14:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Rojtberg X-Patchwork-Id: 9936791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 572AA60237 for ; Mon, 4 Sep 2017 08:15:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 487CC2876E for ; Mon, 4 Sep 2017 08:15:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D86328779; Mon, 4 Sep 2017 08:15:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0112876E for ; Mon, 4 Sep 2017 08:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753342AbdIDIOj (ORCPT ); Mon, 4 Sep 2017 04:14:39 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:38032 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751949AbdIDIOc (ORCPT ); Mon, 4 Sep 2017 04:14:32 -0400 Received: by mail-wm0-f66.google.com with SMTP id u26so5670944wma.5 for ; Mon, 04 Sep 2017 01:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=42d+61oM9rqnP0QRiEPIM5H+jh/lZ52pmDZO0yUf2yU=; b=LdZwPvN/XXVgVWaUq2Z7KvB3XRzhJM6aqk8sC4heZWzrtt38/snanZHArb3dULRhnl gFhQwZ9OYMJ2GVDjWgI7FpF45OpHb+bc5BHCfP2SLEVnEzSM+litTPVFbjlYaLY2hHOB e1cjDEqQS4UnNCm2OGukRxdCXd6C8FkvabnJl4P9myv4tF7CA4ailwkO+uzmaBEJ+J3Z wthQuQmnoOMDTbTBOwoBcRAzhqeDKafbeKhtwJyMuQhF4KE6cw16+/hnJHvdGgBwYZ9x HQ/ty1pduF+AwhprZAJO1y8kX6yVDh6C0thHc9YDYHxRlNt4miWP8eCq/GdYkLYUjmf4 4PNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=42d+61oM9rqnP0QRiEPIM5H+jh/lZ52pmDZO0yUf2yU=; b=Gr8EsKh4/V/0dV5R8cFSPg72Ebzqhnuby8Xv+OU9xQVAlNQ2IJhUVQ2iwqjF2Ke5du J6l6ZSbtOjwWPhUraTmcL+mw9CK5v2k7sp4lauVSyn2pDBFtOehWZhYETE/QSzEXK1zD acxxVmm6X173K3FYfIdODfDUJ5HtZ66CnZKbGZYSOMQbHCJImT9q4v2s4fKo2lMNw7Fs bhhniQPNplddKo0TnrOEpPb+5RCIWFE42YmsqQ+cHwzGA05gxHqdyrjIO1MyQp6NKmb9 IXyNlLdPSGIjZTz30Lg59wT4TzpgVvWGaiyk0AXAlpWsBBi99ZOg58vwUxTuMUB0sbvg s8pQ== X-Gm-Message-State: AHPjjUhxOK22/QYEFXyrkEzIOSbTh+iWFhJWKvp7Xn2T07U2jKNlEd4B wHfvdxe7hUNCmQDk X-Google-Smtp-Source: ADKCNb4jQgu29I7jscMxWJaFjWA0lBtHqCr+SaWv/EEDaraaSXqFX168bOPhOMw9FyJOHdb9H4LNdQ== X-Received: by 10.28.174.11 with SMTP id x11mr2952407wme.71.1504512870710; Mon, 04 Sep 2017 01:14:30 -0700 (PDT) Received: from deepwhite.fritz.box (p5793923B.dip0.t-ipconnect.de. [87.147.146.59]) by smtp.gmail.com with ESMTPSA id o26sm2054888wro.46.2017.09.04.01.14.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 01:14:29 -0700 (PDT) From: Pavel Rojtberg X-Google-Original-From: Pavel Rojtberg < rojtberg@gmail.com > To: mchehab@kernel.org, laurent.pinchart@ideasonboard.com, linux-media@vger.kernel.org Cc: Pavel Rojtberg Subject: [PATCH] uvcvideo: extend UVC_QUIRK_FIX_BANDWIDTH to MJPEG streams Date: Mon, 4 Sep 2017 10:14:17 +0200 Message-Id: <1504512857-4202-1-git-send-email-rojtberg@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pavel Rojtberg attaching two Logitech C615 webcams currently results in VIDIOC_STREAMON: No space left on device as the required bandwidth is not estimated correctly by the device. In fact it always requests 3060 bytes - no matter the format or resolution. setting UVC_QUIRK_FIX_BANDWIDTH does not help either as it is only implemented for uncompressed streams. This patch extends UVC_QUIRK_FIX_BANDWIDTH to MJPEG streams by making a (conservative) assumption of 4bpp for MJPEG streams. As the actual compression ration is often closer to 1bpp this can be overridden via the new mjpeg_bpp parameter. Based on: https://www.mail-archive.com/linux-uvc-devel@lists.berlios.de/msg05724.html --- drivers/media/usb/uvc/uvc_driver.c | 14 +++++++++++++- drivers/media/usb/uvc/uvc_video.c | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 70842c5..f7b759e 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -37,6 +37,7 @@ unsigned int uvc_no_drop_param; static unsigned int uvc_quirks_param = -1; unsigned int uvc_trace_param; unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT; +static unsigned int uvc_mjpeg_bpp_param; /* ------------------------------------------------------------------------ * Video formats @@ -463,7 +464,16 @@ static int uvc_parse_format(struct uvc_device *dev, strlcpy(format->name, "MJPEG", sizeof format->name); format->fcc = V4L2_PIX_FMT_MJPEG; format->flags = UVC_FMT_FLAG_COMPRESSED; - format->bpp = 0; + if ((uvc_mjpeg_bpp_param >= 1) && (uvc_mjpeg_bpp_param <= 16)) { + format->bpp = uvc_mjpeg_bpp_param; + } else { + /* conservative estimate. Actual values are around 1bpp. + * see e.g. + * https://developers.google.com/speed/webp/docs/webp_study + */ + format->bpp = 4; + } + ftype = UVC_VS_FRAME_MJPEG; break; @@ -2274,6 +2284,8 @@ module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR); MODULE_PARM_DESC(trace, "Trace level bitmask"); module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR); MODULE_PARM_DESC(timeout, "Streaming control requests timeout"); +module_param_named(mjpeg_bpp, uvc_mjpeg_bpp_param, uint, S_IRUGO|S_IWUSR); +MODULE_PARM_DESC(mjpeg_bpp, "MJPEG bits per pixel for bandwidth quirk"); /* ------------------------------------------------------------------------ * Driver initialization and cleanup diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index fb86d6a..382a0be 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -127,7 +127,8 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, if ((ctrl->dwMaxPayloadTransferSize & 0xffff0000) == 0xffff0000) ctrl->dwMaxPayloadTransferSize &= ~0xffff0000; - if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) && + if ((!(format->flags & UVC_FMT_FLAG_COMPRESSED) || + (format->fcc == V4L2_PIX_FMT_MJPEG)) && stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && stream->intf->num_altsetting > 1) { u32 interval;