From patchwork Sun Apr 26 00:43:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3548 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 DCC3F62E55 for ; Sun, 26 Apr 2020 02:43:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="N14KFo+L"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6364D4F7 for ; Sun, 26 Apr 2020 02:43:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1587861807; bh=T9p/zxTLJga5VcZfg96mQ2fjPHvxb56eV5Oq4+Jsaqc=; h=From:To:Subject:Date:From; b=N14KFo+L+0H+OTBnDkQ3Ka73Kv8MQy8UUClgpSgLPI34juIVaeVJh4O/SyxIIqIdE bobsr8p7SBzwRB2tCEgaEBQJE19Z58BddiyaBoI2+n3OcR1I74nRR7Lw5bSu0QqG+/ W2PI9ws/Hzb8is9sZtOpD5jAJcXpi8zDAyt/1k3U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 26 Apr 2020 03:43:08 +0300 Message-Id: <20200426004309.2743-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: v4l2_videodevice: Rename fdEvent_ to fdBufferNotifier_ 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: Sun, 26 Apr 2020 00:43:28 -0000 To prepare for the addition of a second notifier for V4L2 events, rename the current fdEvent_ member to fdBufferNotifier_ to better reflect its usage. While at it, simplify allocation of the fdEvent_ notifier. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/libcamera/include/v4l2_videodevice.h | 2 +- src/libcamera/v4l2_videodevice.cpp | 36 ++++++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index f21b9264a40d..ee63d28da734 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -270,7 +270,7 @@ private: V4L2BufferCache *cache_; std::map queuedBuffers_; - EventNotifier *fdEvent_; + EventNotifier *fdBufferNotifier_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index a959cfe65c43..18a71e4f8a7f 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -544,7 +544,7 @@ const std::string V4L2DeviceFormat::toString() const * \param[in] deviceNode The file-system path to the video device node */ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) - : V4L2Device(deviceNode), cache_(nullptr), fdEvent_(nullptr) + : V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr) { /* * We default to an MMAP based CAPTURE video device, however this will @@ -610,29 +610,32 @@ int V4L2VideoDevice::open() * devices (POLLIN), and write notifications for OUTPUT video devices * (POLLOUT). */ + EventNotifier::Type notifierType; + if (caps_.isVideoCapture()) { - fdEvent_ = new EventNotifier(fd(), EventNotifier::Read); + notifierType = EventNotifier::Read; bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : V4L2_BUF_TYPE_VIDEO_CAPTURE; } else if (caps_.isVideoOutput()) { - fdEvent_ = new EventNotifier(fd(), EventNotifier::Write); + notifierType = EventNotifier::Write; bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : V4L2_BUF_TYPE_VIDEO_OUTPUT; } else if (caps_.isMetaCapture()) { - fdEvent_ = new EventNotifier(fd(), EventNotifier::Read); + notifierType = EventNotifier::Read; bufferType_ = V4L2_BUF_TYPE_META_CAPTURE; } else if (caps_.isMetaOutput()) { - fdEvent_ = new EventNotifier(fd(), EventNotifier::Write); + notifierType = EventNotifier::Write; bufferType_ = V4L2_BUF_TYPE_META_OUTPUT; } else { LOG(V4L2, Error) << "Device is not a supported type"; return -EINVAL; } - fdEvent_->activated.connect(this, &V4L2VideoDevice::bufferAvailable); - fdEvent_->setEnabled(false); + fdBufferNotifier_ = new EventNotifier(fd(), notifierType); + fdBufferNotifier_->activated.connect(this, &V4L2VideoDevice::bufferAvailable); + fdBufferNotifier_->setEnabled(false); LOG(V4L2, Debug) << "Opened device " << caps_.bus_info() << ": " @@ -699,15 +702,17 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type) * devices (POLLIN), and write notifications for OUTPUT video devices * (POLLOUT). */ + EventNotifier::Type notifierType; + switch (type) { case V4L2_BUF_TYPE_VIDEO_OUTPUT: - fdEvent_ = new EventNotifier(fd(), EventNotifier::Write); + notifierType = EventNotifier::Write; bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : V4L2_BUF_TYPE_VIDEO_OUTPUT; break; case V4L2_BUF_TYPE_VIDEO_CAPTURE: - fdEvent_ = new EventNotifier(fd(), EventNotifier::Read); + notifierType = EventNotifier::Read; bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -717,8 +722,9 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type) return -EINVAL; } - fdEvent_->activated.connect(this, &V4L2VideoDevice::bufferAvailable); - fdEvent_->setEnabled(false); + fdBufferNotifier_ = new EventNotifier(fd(), notifierType); + fdBufferNotifier_->activated.connect(this, &V4L2VideoDevice::bufferAvailable); + fdBufferNotifier_->setEnabled(false); LOG(V4L2, Debug) << "Opened device " << caps_.bus_info() << ": " @@ -736,7 +742,7 @@ void V4L2VideoDevice::close() return; releaseBuffers(); - delete fdEvent_; + delete fdBufferNotifier_; V4L2Device::close(); } @@ -1477,7 +1483,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) } if (queuedBuffers_.empty()) - fdEvent_->setEnabled(true); + fdBufferNotifier_->setEnabled(true); queuedBuffers_[buf.index] = buffer; @@ -1544,7 +1550,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() queuedBuffers_.erase(it); if (queuedBuffers_.empty()) - fdEvent_->setEnabled(false); + fdBufferNotifier_->setEnabled(false); buffer->metadata_.status = buf.flags & V4L2_BUF_FLAG_ERROR ? FrameMetadata::FrameError @@ -1617,7 +1623,7 @@ int V4L2VideoDevice::streamOff() } queuedBuffers_.clear(); - fdEvent_->setEnabled(false); + fdBufferNotifier_->setEnabled(false); return 0; }