From patchwork Tue Dec 28 21:59:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15227 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7A52FBF415 for ; Tue, 28 Dec 2021 22:00:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8ADFB60913; Tue, 28 Dec 2021 22:59:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UbClrQaV"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BBD73608E9 for ; Tue, 28 Dec 2021 22:59:57 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6203E895 for ; Tue, 28 Dec 2021 22:59:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728797; bh=3I3vAIHb+uMi8YL3WHkzjPZoLjHt0cqbeCgCRKbR1Jw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UbClrQaVBKFcoADjT6mgtdjtfhCAlBxxPo9+oaOa89KUhJ751MbkkAr6Q7bByUXd7 U0O8V29OE73is/xpQYguaZSwzxIOlnoa+0zt+hIOfaqaQV0cHjOz/3E1HqbF4Lmnte hAzPOAlKVPd4Bu6g8JfyRHNdGvBTSpNm2X7r+bWk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:47 +0200 Message-Id: <20211228215951.32396-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/5] v4l2: v4l2_compat_manager: Print path and fd in openat() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The V4L2 compat layer prints debug messages that mention the file descriptor of the video device, but no message that links the device path to the file descriptor. Fix it by adding a debug message in openat(). Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_compat_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index 690a191fe2bf..c64cdb862489 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -158,6 +158,7 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod V4L2CameraProxy *proxy = proxies_[ret].get(); files_.emplace(efd, std::make_shared(efd, oflag & O_NONBLOCK, proxy)); + LOG(V4L2Compat, Debug) << "Opened " << path << " -> fd " << efd; return efd; } From patchwork Tue Dec 28 21:59:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15228 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C200CC3258 for ; Tue, 28 Dec 2021 22:00:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 067056091C; Tue, 28 Dec 2021 23:00:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="K8yBROvq"; dkim-atps=neutral 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 50F6C608E9 for ; Tue, 28 Dec 2021 22:59:58 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E93413E7 for ; Tue, 28 Dec 2021 22:59:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728798; bh=zvuQC9WPq43vhHmWWlaS9LD1cwEdf0G0itcmYG0Tgx8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K8yBROvqnq9lyBqeAX07B8lWfx4aYjAiqf7rdVX0fRbuaCjHBq9bkCQT555Q2HzxL 0KuGQ74bKUgopOgKZo646FbZ280bppSJy5vgczmB5pRq74JcyeJDNV9gfU3KhntZ8I dcREbPIfobOXO1WW/8Ihq8OCC3EMJu1DgxIx65GM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:48 +0200 Message-Id: <20211228215951.32396-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/5] v4l2: v4l2_camera_file: Store file description X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create a string that describe the file from the path and file descriptor. This will be used in log messages to clearly identify which file an operation is related to. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_camera_file.cpp | 28 +++++++++++++++++++++++++++- src/v4l2/v4l2_camera_file.h | 8 +++++++- src/v4l2/v4l2_compat_manager.cpp | 4 +++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/v4l2/v4l2_camera_file.cpp b/src/v4l2/v4l2_camera_file.cpp index a07679b587ce..0a41587ca90b 100644 --- a/src/v4l2/v4l2_camera_file.cpp +++ b/src/v4l2/v4l2_camera_file.cpp @@ -7,20 +7,46 @@ #include "v4l2_camera_file.h" +#include +#include +#include + #include #include "v4l2_camera_proxy.h" using namespace libcamera; -V4L2CameraFile::V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy) +V4L2CameraFile::V4L2CameraFile(int dirfd, const char *path, int efd, + bool nonBlocking, V4L2CameraProxy *proxy) : proxy_(proxy), nonBlocking_(nonBlocking), efd_(efd), priority_(V4L2_PRIORITY_DEFAULT) { proxy_->open(this); + + if (path[0] != '/') { + if (dirfd == AT_FDCWD) { + char *cwd = getcwd(nullptr, 0); + if (cwd) { + description_ = std::string(cwd) + "/"; + free(cwd); + } else { + description_ = std::string("(unreachable)/"); + } + } else { + description_ = "(dirfd:" + std::to_string(dirfd) + ")/"; + } + } + + description_ += std::string(path) + " (fd:" + std::to_string(efd) + ")"; } V4L2CameraFile::~V4L2CameraFile() { proxy_->close(this); } + +const std::string &V4L2CameraFile::description() const +{ + return description_; +} diff --git a/src/v4l2/v4l2_camera_file.h b/src/v4l2/v4l2_camera_file.h index 6c4cb5d89dbf..1a7b6a63ae95 100644 --- a/src/v4l2/v4l2_camera_file.h +++ b/src/v4l2/v4l2_camera_file.h @@ -7,6 +7,8 @@ #pragma once +#include + #include class V4L2CameraProxy; @@ -14,7 +16,8 @@ class V4L2CameraProxy; class V4L2CameraFile { public: - V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy); + V4L2CameraFile(int dirfd, const char *path, int efd, bool nonBlocking, + V4L2CameraProxy *proxy); ~V4L2CameraFile(); V4L2CameraProxy *proxy() const { return proxy_; } @@ -25,9 +28,12 @@ public: enum v4l2_priority priority() const { return priority_; } void setPriority(enum v4l2_priority priority) { priority_ = priority; } + const std::string &description() const; + private: V4L2CameraProxy *proxy_; + std::string description_; bool nonBlocking_; int efd_; enum v4l2_priority priority_; diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index c64cdb862489..585046e97e4b 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -156,7 +156,9 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod return efd; V4L2CameraProxy *proxy = proxies_[ret].get(); - files_.emplace(efd, std::make_shared(efd, oflag & O_NONBLOCK, proxy)); + files_.emplace(efd, std::make_shared(dirfd, path, efd, + oflag & O_NONBLOCK, + proxy)); LOG(V4L2Compat, Debug) << "Opened " << path << " -> fd " << efd; return efd; From patchwork Tue Dec 28 21:59:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15229 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B09EFBF415 for ; Tue, 28 Dec 2021 22:00:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5EC5D6091A; Tue, 28 Dec 2021 23:00:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rtKHSv1r"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0DA4D608E9 for ; Tue, 28 Dec 2021 22:59:59 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 54EFE895 for ; Tue, 28 Dec 2021 22:59:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728798; bh=B7vytGfSodr0BIgBR1pAZBaXOj+6bL7ZFaLyGSMd3PI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rtKHSv1rZmTA0hw1t0q1ai7u/61KGd6dnwuU2Ypz9xQ90NNlQFlToewh07eSTQSvO pwaWwRicQ2bvrtp6P60YRE600xYD/LTdHP0Pq90qpP/0oTIM84xKU6sQ1LWe38goBT duAYJx2vW/2VHek9hETO2fHn3FH2UZLy8Pp41oYY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:49 +0200 Message-Id: <20211228215951.32396-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/5] v4l2: v4l2_camera_proxy: Drop trace message from freeBuffers() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The freeBuffers() function is only called from vidioc_reqbufs(), which already logs a trace message. Remove the duplicate. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_camera_proxy.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index c1375777c185..80e6624bc9b7 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -445,8 +445,6 @@ int V4L2CameraProxy::vidioc_s_input(V4L2CameraFile *file, int *arg) void V4L2CameraProxy::freeBuffers() { - LOG(V4L2Compat, Debug) << "Freeing libcamera bufs"; - vcam_->freeBuffers(); buffers_.clear(); bufferCount_ = 0; From patchwork Tue Dec 28 21:59:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15230 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 88FA4C3259 for ; Tue, 28 Dec 2021 22:00:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1D21060917; Tue, 28 Dec 2021 23:00:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hIteENsB"; dkim-atps=neutral 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 4339560868 for ; Tue, 28 Dec 2021 22:59:59 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DC95C3E7 for ; Tue, 28 Dec 2021 22:59:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728799; bh=MjWKeZN9GqCHXj+cYSixOLC838Yfriuc6ECgBJSnzzg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hIteENsBsjVSXaGBGNlwQ/btk8JUmsPDMnCsIgrJsfdOA50wgf4XIiXls1F+idgHk BrLvHR25FRBAu9zx+ZXNbd9/445c9onF0QP6+LYxRIx25TxcIkTz2xREO8qrWQ8HOB 7XXfqjiQAbq8paPuw/zfYoqkEvs6umGwXTOSJXsg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:50 +0200 Message-Id: <20211228215951.32396-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 4/5] v4l2: v4l2_compat_manager: Store V4L2CameraFile in mmaps_ X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The mmaps_ map stores a pointer to the V4L2CameraProxy to avoid increasing the reference count on the V4L2CameraFile shared pointer needlessly. While this provides a small optimization, it prevents accessing the V4L2CameraFile from the munmap() function which doesn't take an fd as argument. To prepare for improved debugging that will require access to V4L2CameraFile in munmap(), store the V4L2CameraFile pointer in mmaps_. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_compat_manager.cpp | 10 +++------- src/v4l2/v4l2_compat_manager.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index 585046e97e4b..ded568beb60e 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -198,11 +198,7 @@ void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags, if (map == MAP_FAILED) return map; - /* - * Map to V4L2CameraProxy directly to prevent adding more references - * to V4L2CameraFile. - */ - mmaps_[map] = file->proxy(); + mmaps_[map] = file; return map; } @@ -212,9 +208,9 @@ int V4L2CompatManager::munmap(void *addr, size_t length) if (device == mmaps_.end()) return fops_.munmap(addr, length); - V4L2CameraProxy *proxy = device->second; + V4L2CameraFile *file = device->second.get(); - int ret = proxy->munmap(addr, length); + int ret = file->proxy()->munmap(addr, length); if (ret < 0) return ret; diff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h index f52069f7b62d..64af9a8c008f 100644 --- a/src/v4l2/v4l2_compat_manager.h +++ b/src/v4l2/v4l2_compat_manager.h @@ -65,5 +65,5 @@ private: std::vector> proxies_; std::map> files_; - std::map mmaps_; + std::map> mmaps_; }; From patchwork Tue Dec 28 21:59:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15231 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 30A4FBF415 for ; Tue, 28 Dec 2021 22:00:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD8446090D; Tue, 28 Dec 2021 23:00:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hQjJkXpt"; dkim-atps=neutral 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 A93786091A for ; Tue, 28 Dec 2021 22:59:59 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4727A895 for ; Tue, 28 Dec 2021 22:59:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640728799; bh=eJoX2ye7HNkZYahMKX0B6FF8m61c0oNmmEEPOXFp4y0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hQjJkXpt0FIH0LHAot91yXdx7mDCHlOezfyUgHnSUJ55lmgB9AMkp6aSA0bpGlYr/ SxqYpYdlZC24xBFe6/9zfIFEdivuJjtg6sOW7zU/LhzmxjEM7BcLt6Lz6DZykbcwTr e+f87psVpj2UF6/p1orazXYGHxobiNPPPmbVQ4w0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Dec 2021 23:59:51 +0200 Message-Id: <20211228215951.32396-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> References: <20211228215951.32396-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 5/5] v4l2: v4l2_camera_proxy: Use file description in debug messages X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Debug messages in V4L2CameraProxy print the numerical file descriptor, which isn't very human-friendly. Replace it with the V4L2CameraFile description that includes the full path. While at it, refactor the messages to use __func__ instead of manually copying function names. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/v4l2/v4l2_camera_proxy.cpp | 74 ++++++++++++++++++++------------ src/v4l2/v4l2_camera_proxy.h | 7 +-- src/v4l2/v4l2_compat_manager.cpp | 5 ++- 3 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 80e6624bc9b7..5ccf40b9692c 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -46,7 +46,8 @@ V4L2CameraProxy::V4L2CameraProxy(unsigned int index, int V4L2CameraProxy::open(V4L2CameraFile *file) { - LOG(V4L2Compat, Debug) << "Servicing open fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; MutexLocker locker(proxyMutex_); @@ -80,7 +81,8 @@ int V4L2CameraProxy::open(V4L2CameraFile *file) void V4L2CameraProxy::close(V4L2CameraFile *file) { - LOG(V4L2Compat, Debug) << "Servicing close fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; MutexLocker locker(proxyMutex_); @@ -94,10 +96,11 @@ void V4L2CameraProxy::close(V4L2CameraFile *file) vcam_->close(); } -void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags, - off64_t offset) +void *V4L2CameraProxy::mmap(V4L2CameraFile *file, void *addr, size_t length, + int prot, int flags, off64_t offset) { - LOG(V4L2Compat, Debug) << "Servicing mmap"; + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; MutexLocker locker(proxyMutex_); @@ -131,9 +134,10 @@ void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags, return map; } -int V4L2CameraProxy::munmap(void *addr, size_t length) +int V4L2CameraProxy::munmap(V4L2CameraFile *file, void *addr, size_t length) { - LOG(V4L2Compat, Debug) << "Servicing munmap"; + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; MutexLocker locker(proxyMutex_); @@ -233,9 +237,10 @@ void V4L2CameraProxy::updateBuffers() } } -int V4L2CameraProxy::vidioc_querycap(struct v4l2_capability *arg) +int V4L2CameraProxy::vidioc_querycap(V4L2CameraFile *file, struct v4l2_capability *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_querycap"; + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; *arg = capabilities_; @@ -244,7 +249,8 @@ int V4L2CameraProxy::vidioc_querycap(struct v4l2_capability *arg) int V4L2CameraProxy::vidioc_enum_framesizes(V4L2CameraFile *file, struct v4l2_frmsizeenum *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_enum_framesizes fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->pixel_format); PixelFormat format = v4l2Format.toPixelFormat(); @@ -267,7 +273,8 @@ int V4L2CameraProxy::vidioc_enum_framesizes(V4L2CameraFile *file, struct v4l2_fr int V4L2CameraProxy::vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_enum_fmt fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (!validateBufferType(arg->type) || arg->index >= streamConfig_.formats().pixelformats().size()) @@ -288,7 +295,8 @@ int V4L2CameraProxy::vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc * int V4L2CameraProxy::vidioc_g_fmt(V4L2CameraFile *file, struct v4l2_format *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_g_fmt fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (!validateBufferType(arg->type)) return -EINVAL; @@ -331,7 +339,8 @@ int V4L2CameraProxy::tryFormat(struct v4l2_format *arg) int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_s_fmt fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (!validateBufferType(arg->type)) return -EINVAL; @@ -361,7 +370,8 @@ int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg) int V4L2CameraProxy::vidioc_try_fmt(V4L2CameraFile *file, struct v4l2_format *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_try_fmt fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (!validateBufferType(arg->type)) return -EINVAL; @@ -384,7 +394,8 @@ enum v4l2_priority V4L2CameraProxy::maxPriority() int V4L2CameraProxy::vidioc_g_priority(V4L2CameraFile *file, enum v4l2_priority *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_g_priority fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; *arg = maxPriority(); @@ -394,7 +405,7 @@ int V4L2CameraProxy::vidioc_g_priority(V4L2CameraFile *file, enum v4l2_priority int V4L2CameraProxy::vidioc_s_priority(V4L2CameraFile *file, enum v4l2_priority *arg) { LOG(V4L2Compat, Debug) - << "Servicing vidioc_s_priority fd = " << file->efd(); + << "[" << file->description() << "] " << __func__ << "()"; if (*arg > V4L2_PRIORITY_RECORD) return -EINVAL; @@ -409,7 +420,8 @@ int V4L2CameraProxy::vidioc_s_priority(V4L2CameraFile *file, enum v4l2_priority int V4L2CameraProxy::vidioc_enuminput(V4L2CameraFile *file, struct v4l2_input *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_enuminput fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (arg->index != 0) return -EINVAL; @@ -426,7 +438,8 @@ int V4L2CameraProxy::vidioc_enuminput(V4L2CameraFile *file, struct v4l2_input *a int V4L2CameraProxy::vidioc_g_input(V4L2CameraFile *file, int *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_g_input fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; *arg = 0; @@ -435,7 +448,8 @@ int V4L2CameraProxy::vidioc_g_input(V4L2CameraFile *file, int *arg) int V4L2CameraProxy::vidioc_s_input(V4L2CameraFile *file, int *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_s_input fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (*arg != 0) return -EINVAL; @@ -452,7 +466,8 @@ void V4L2CameraProxy::freeBuffers() int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuffers *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_reqbufs fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (!validateBufferType(arg->type) || !validateMemoryType(arg->memory)) @@ -526,7 +541,8 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf int V4L2CameraProxy::vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_querybuf fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (arg->index >= bufferCount_) return -EINVAL; @@ -544,8 +560,9 @@ int V4L2CameraProxy::vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *a int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_qbuf, index = " - << arg->index << " fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ + << "(index=" << arg->index << ")"; if (arg->index >= bufferCount_) return -EINVAL; @@ -575,7 +592,8 @@ int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, Mutex *lock) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_dqbuf fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (arg->index >= bufferCount_) return -EINVAL; @@ -624,7 +642,8 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_streamon fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (bufferCount_ == 0) return -EINVAL; @@ -648,7 +667,8 @@ int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg) int V4L2CameraProxy::vidioc_streamoff(V4L2CameraFile *file, int *arg) { - LOG(V4L2Compat, Debug) << "Servicing vidioc_streamoff fd = " << file->efd(); + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ << "()"; if (!validateBufferType(*arg)) return -EINVAL; @@ -709,7 +729,7 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar int ret; switch (request) { case VIDIOC_QUERYCAP: - ret = vidioc_querycap(static_cast(arg)); + ret = vidioc_querycap(file, static_cast(arg)); break; case VIDIOC_ENUM_FRAMESIZES: ret = vidioc_enum_framesizes(file, static_cast(arg)); diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index fa0a49e0439b..08f0295a92dd 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -29,8 +29,9 @@ public: int open(V4L2CameraFile *file); void close(V4L2CameraFile *file); - void *mmap(void *addr, size_t length, int prot, int flags, off64_t offset); - int munmap(void *addr, size_t length); + void *mmap(V4L2CameraFile *file, void *addr, size_t length, int prot, + int flags, off64_t offset); + int munmap(V4L2CameraFile *file, void *addr, size_t length); int ioctl(V4L2CameraFile *file, unsigned long request, void *arg); @@ -44,7 +45,7 @@ private: void updateBuffers(); void freeBuffers(); - int vidioc_querycap(struct v4l2_capability *arg); + int vidioc_querycap(V4L2CameraFile *file, struct v4l2_capability *arg); int vidioc_enum_framesizes(V4L2CameraFile *file, struct v4l2_frmsizeenum *arg); int vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc *arg); int vidioc_g_fmt(V4L2CameraFile *file, struct v4l2_format *arg); diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index ded568beb60e..0f7575c54b22 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -194,7 +194,8 @@ void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags, if (!file) return fops_.mmap(addr, length, prot, flags, fd, offset); - void *map = file->proxy()->mmap(addr, length, prot, flags, offset); + void *map = file->proxy()->mmap(file.get(), addr, length, prot, flags, + offset); if (map == MAP_FAILED) return map; @@ -210,7 +211,7 @@ int V4L2CompatManager::munmap(void *addr, size_t length) V4L2CameraFile *file = device->second.get(); - int ret = file->proxy()->munmap(addr, length); + int ret = file->proxy()->munmap(file, addr, length); if (ret < 0) return ret;