From patchwork Tue Jun 16 13:12:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 4053 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D13061F72 for ; Tue, 16 Jun 2020 15:13:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XEn7KEX8"; 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 E741AF9; Tue, 16 Jun 2020 15:13:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592313197; bh=d0nXpwSQo/5EWRBjCr9n31E3PtQ9sPzZ/S0qcDne9TY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XEn7KEX8Y15DhxMEwOGd45pgem/doN3K0BBmpXK7o/juXw5Z3d4z8UKb9D/sf9EyK 3y9NrnPVIzsO7OlmA/GHjBA4Ce5rvDQrNxHW3AmKB+qOeS5U4dtDCnqPH4FiW7/nC/ zy0xOnYY4Oiu0tnTbYYstYp4MhgtCJk6es4Mx6Is= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Jun 2020 22:12:38 +0900 Message-Id: <20200616131244.70308-10-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 09/15] v4l2: v4l2_cammera_proxy: Reset buffer flags on streamoff when already off 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:17 -0000 If VIDIOC_STREAMOFF is called when the stream is already off, just reset the buffer status flags and return. Add a streaming flag to V4L2CameraProxy to track the streaming status. Signed-off-by: Paul Elder --- src/v4l2/v4l2_camera_proxy.cpp | 18 +++++++++++++++++- src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index fd2785f..63b4124 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -34,7 +34,8 @@ V4L2CameraProxy::V4L2CameraProxy(unsigned int index, std::shared_ptr camera) : refcount_(0), index_(index), bufferCount_(0), currentBuf_(0), vcam_(std::make_unique(camera)), efd_(-1), - v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false) + v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false), + streaming_(false) { querycap(camera); } @@ -628,6 +629,9 @@ int V4L2CameraProxy::vidioc_dqbuf(int fd, struct v4l2_buffer *arg) if (arg == nullptr) return -EFAULT; + if (!streaming_) + return -EINVAL; + int ret = lock(fd); if (ret < 0) return ret; @@ -666,6 +670,9 @@ int V4L2CameraProxy::vidioc_streamon(int fd, int *arg) if (arg == nullptr) return -EFAULT; + if (streaming_) + return 0; + int ret = lock(fd); if (ret < 0) return ret; @@ -674,6 +681,7 @@ int V4L2CameraProxy::vidioc_streamon(int fd, int *arg) return -EINVAL; currentBuf_ = 0; + streaming_ = true; return vcam_->streamOn(); } @@ -685,6 +693,12 @@ int V4L2CameraProxy::vidioc_streamoff(int fd, int *arg) if (arg == nullptr) return -EFAULT; + if (!streaming_) { + for (unsigned int i = 0; i < bufferCount_; i++) + buffers_[i].flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE); + return 0; + } + int ret = lock(fd); if (ret < 0) return ret; @@ -697,6 +711,8 @@ int V4L2CameraProxy::vidioc_streamoff(int fd, int *arg) for (struct v4l2_buffer &buf : buffers_) buf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE); + streaming_ = false; + return ret; } diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 2ff9571..28b2fa0 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -103,6 +103,7 @@ private: int acquiredFd_; bool initialized_; + bool streaming_; }; #endif /* __V4L2_CAMERA_PROXY_H__ */