From patchwork Thu May 23 13:59:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1272 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2DB5960E4C for ; Thu, 23 May 2019 15:59:06 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BD9BDB93; Thu, 23 May 2019 15:59:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1558619945; bh=ngTtArm6h9Ki5s6nJfol2JanyMaJy0woc7tnpLqFMmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VvTFYP7msVRyoxCgkJIcNS4TMYRu2F1WosbXpE+s6PvwLDFRVgrCZqOl4lHBRSjrv 9Gs0Z7TNRXX64bUZGWFLYL3r6gkjrZlg1Nl6coleiunpxqBYkeBn9UYE5IBMYVBivo MO2n1aVsoS7GzeAKj39iZuEhOTSY+AbEKHSjk9tk= From: Kieran Bingham To: LibCamera Devel Date: Thu, 23 May 2019 14:59:00 +0100 Message-Id: <20190523135900.24029-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523135900.24029-1-kieran.bingham@ideasonboard.com> References: <20190523135900.24029-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] libcamera: pipeline: uvc: Use the device to validate formats X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 May 2019 13:59:06 -0000 UVC pipelines are highly variable, and we can not define their configuration restrictions within the UVC pipeline handler directly. Update the UVCCameraConfiguration to store the UVCCameraData (storing a reference to the camera as a means of borrowing a reference to the camera data). We then validate the configuration by the tryFormat() operation on the UVC V4L2Device. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/uvcvideo.cpp | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 45260f34c8f5..df321c6e64a6 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -42,9 +42,18 @@ public: class UVCCameraConfiguration : public CameraConfiguration { public: - UVCCameraConfiguration(); + UVCCameraConfiguration(Camera *camera, UVCCameraData *data); Status validate() override; + +private: + /* + * The UVCCameraConfiguration instance is guaranteed to be valid as long + * as the corresponding Camera instance is valid. In order to borrow a + * reference to the camera data, store a new reference to the camera. + */ + std::shared_ptr camera_; + const UVCCameraData *data_; }; class PipelineHandlerUVC : public PipelineHandler @@ -76,9 +85,12 @@ private: } }; -UVCCameraConfiguration::UVCCameraConfiguration() +UVCCameraConfiguration::UVCCameraConfiguration(Camera *camera, + UVCCameraData *data) : CameraConfiguration() { + camera_ = camera->shared_from_this(); + data_ = data; } CameraConfiguration::Status UVCCameraConfiguration::validate() @@ -96,17 +108,20 @@ CameraConfiguration::Status UVCCameraConfiguration::validate() StreamConfiguration &cfg = config_[0]; - /* \todo: Validate the configuration against the device capabilities. */ - const unsigned int pixelFormat = cfg.pixelFormat; - const Size size = cfg.size; + V4L2DeviceFormat format; + format.fourcc = cfg.pixelFormat; + format.size = cfg.size; - cfg.pixelFormat = V4L2_PIX_FMT_YUYV; - cfg.size = { 640, 480 }; + /* Validate the format on the device. */ + data_->video_->tryFormat(&format); - if (cfg.pixelFormat != pixelFormat || cfg.size != size) { + if (cfg.pixelFormat != format.fourcc || cfg.size != format.size) { LOG(UVC, Debug) << "Adjusting configuration from " << cfg.toString() - << " to " << cfg.size.toString() << "-YUYV"; + << " to " << format.toString(); + + cfg.pixelFormat = format.fourcc; + cfg.size = format.size; status = Adjusted; } @@ -123,7 +138,8 @@ PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager) CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, const StreamRoles &roles) { - CameraConfiguration *config = new UVCCameraConfiguration(); + UVCCameraData *data = cameraData(camera); + CameraConfiguration *config = new UVCCameraConfiguration(camera, data); if (roles.empty()) return config;