From patchwork Tue Jun 16 13:12:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 4048 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E08E2603C1 for ; Tue, 16 Jun 2020 15:13:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BH4WwXXY"; dkim-atps=neutral Received: from jade.flets-east.jp (unknown [IPv6:2400:4051:61:600:2807:bdfa:f6a:8e53]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 677EFF9; Tue, 16 Jun 2020 15:13:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592313187; bh=1L1rh8oULEbcXBYHA607Rw3RyBVtMB3vEmT1OMSyPLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BH4WwXXYCSVUFpQSdz1yKQEFNZRPcLSvQ4pWsrYjsH6/RZJl3HUSzaJ4ic+fdaMHI Cc75FYg7YhcmNqFrbZOJR/vH2gQgkLWucdHGKzNRN9XBuAOzUmhWu2r8wUyRt2r5p4 jOMjR4+f9O8MHDPGbzutl7apPYpzRUyRtbD/RYWw= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Jun 2020 22:12:33 +0900 Message-Id: <20200616131244.70308-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200616131244.70308-1-paul.elder@ideasonboard.com> References: <20200616131244.70308-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/15] v4l2: v4l2_camera_proxy: Implement VIDIOC_G/S_PRIORITY 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: , X-List-Received-Date: Tue, 16 Jun 2020 13:13:08 -0000 Implement VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY, according to what v4l2-compliance wants. Signed-off-by: Paul Elder Reviewed-by: Jacopo Mondi --- src/v4l2/v4l2_camera_proxy.cpp | 48 +++++++++++++++++++++++++++++++++- src/v4l2/v4l2_camera_proxy.h | 4 +++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index d899853..f268f7a 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -34,7 +34,7 @@ V4L2CameraProxy::V4L2CameraProxy(unsigned int index, std::shared_ptr camera) : refcount_(0), index_(index), bufferCount_(0), currentBuf_(0), vcam_(std::make_unique(camera)), efd_(-1), - acquiredFd_(-1), initialized_(false) + v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false) { querycap(camera); } @@ -44,6 +44,7 @@ int V4L2CameraProxy::open(int fd, bool nonBlocking) LOG(V4L2Compat, Debug) << "Servicing open fd = " << fd; nonBlockingFds_[fd] = nonBlocking; + priorities_[fd] = V4L2_PRIORITY_DEFAULT; refcount_++; @@ -77,6 +78,7 @@ int V4L2CameraProxy::open(int fd, bool nonBlocking) void V4L2CameraProxy::dup(int oldfd, int newfd) { nonBlockingFds_[newfd] = nonBlockingFds_[oldfd]; + priorities_[newfd] = V4L2_PRIORITY_DEFAULT; refcount_++; } @@ -85,6 +87,7 @@ void V4L2CameraProxy::close(int fd) LOG(V4L2Compat, Debug) << "Servicing close fd = " << fd; nonBlockingFds_.erase(fd); + priorities_.erase(fd); if (acquiredFd_ == fd) acquiredFd_ = -1; @@ -357,6 +360,43 @@ int V4L2CameraProxy::vidioc_try_fmt(int fd, struct v4l2_format *arg) return 0; } +int V4L2CameraProxy::vidioc_g_priority(int fd, enum v4l2_priority *arg) +{ + LOG(V4L2Compat, Debug) << "Servicing vidioc_g_priority fd = " << fd; + + if (arg == nullptr) + return -EFAULT; + + if (v4l2RecordPriorityFd_ != -1) + *arg = V4L2_PRIORITY_RECORD; + else + *arg = priorities_[fd]; + + return 0; +} + +int V4L2CameraProxy::vidioc_s_priority(int fd, enum v4l2_priority *arg) +{ + LOG(V4L2Compat, Debug) + << "Servicing vidioc_s_priority fd = " << fd + << " prio = " << ((arg == nullptr) ? -1 : (int)*arg); + + if (arg == nullptr) + return -EFAULT; + + if (v4l2RecordPriorityFd_ != -1 && v4l2RecordPriorityFd_ != fd) + return -EBUSY; + + if (*arg == V4L2_PRIORITY_RECORD) + v4l2RecordPriorityFd_ = fd; + else if (v4l2RecordPriorityFd_ == fd) + v4l2RecordPriorityFd_ = -1; + + priorities_[fd] = *arg; + + return 0; +} + int V4L2CameraProxy::freeBuffers() { LOG(V4L2Compat, Debug) << "Freeing libcamera bufs"; @@ -603,6 +643,12 @@ int V4L2CameraProxy::ioctl(int fd, unsigned long request, void *arg) case VIDIOC_TRY_FMT: ret = vidioc_try_fmt(fd, static_cast(arg)); break; + case VIDIOC_G_PRIORITY: + ret = vidioc_g_priority(fd, static_cast(arg)); + break; + case VIDIOC_S_PRIORITY: + ret = vidioc_s_priority(fd, static_cast(arg)); + break; case VIDIOC_REQBUFS: ret = vidioc_reqbufs(fd, static_cast(arg)); break; diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 90e518c..a0c373d 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -49,6 +49,8 @@ private: int vidioc_g_fmt(int fd, struct v4l2_format *arg); int vidioc_s_fmt(int fd, struct v4l2_format *arg); int vidioc_try_fmt(int fd, struct v4l2_format *arg); + int vidioc_g_priority(int fd, enum v4l2_priority *arg); + int vidioc_s_priority(int fd, enum v4l2_priority *arg); int vidioc_reqbufs(int fd, struct v4l2_requestbuffers *arg); int vidioc_querybuf(int fd, struct v4l2_buffer *arg); int vidioc_qbuf(int fd, struct v4l2_buffer *arg); @@ -84,6 +86,8 @@ private: int efd_; std::map nonBlockingFds_; + std::map priorities_; + int v4l2RecordPriorityFd_; /* * This is an exclusive lock on the camera. When this is not taken, * anybody can call any ioctl before reqbufs. reqbufs with count > 0