[{"id":5245,"web_url":"https://patchwork.libcamera.org/comment/5245/","msgid":"<20200617150740.gzhf4lrrjyp2fal6@uno.localdomain>","date":"2020-06-17T15:07:40","subject":"Re: [libcamera-devel] [PATCH 09/15] v4l2: v4l2_cammera_proxy: Reset\n\tbuffer flags on streamoff when already off","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Paul,\n\nOn Tue, Jun 16, 2020 at 10:12:38PM +0900, Paul Elder wrote:\n> If VIDIOC_STREAMOFF is called when the stream is already off, just reset\n> the buffer status flags and return. Add a streaming flag to\n> V4L2CameraProxy to track the streaming status.\n>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  src/v4l2/v4l2_camera_proxy.cpp | 18 +++++++++++++++++-\n>  src/v4l2/v4l2_camera_proxy.h   |  1 +\n>  2 files changed, 18 insertions(+), 1 deletion(-)\n>\n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index fd2785f..63b4124 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -34,7 +34,8 @@ V4L2CameraProxy::V4L2CameraProxy(unsigned int index,\n>  \t\t\t\t std::shared_ptr<Camera> camera)\n>  \t: refcount_(0), index_(index), bufferCount_(0), currentBuf_(0),\n>  \t  vcam_(std::make_unique<V4L2Camera>(camera)), efd_(-1),\n> -\t  v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false)\n> +\t  v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false),\n> +\t  streaming_(false)\n>  {\n>  \tquerycap(camera);\n>  }\n> @@ -628,6 +629,9 @@ int V4L2CameraProxy::vidioc_dqbuf(int fd, struct v4l2_buffer *arg)\n>  \tif (arg == nullptr)\n>  \t\treturn -EFAULT;\n>\n> +\tif (!streaming_)\n\nDoesn't this flag replicate the same information stored in\nV4L2Camera::isRuning_ ? Why keep two status flags for the same purpose ?\n\n> +\t\treturn -EINVAL;\n> +\n>  \tint ret = lock(fd);\n>  \tif (ret < 0)\n>  \t\treturn ret;\n> @@ -666,6 +670,9 @@ int V4L2CameraProxy::vidioc_streamon(int fd, int *arg)\n>  \tif (arg == nullptr)\n>  \t\treturn -EFAULT;\n>\n> +\tif (streaming_)\n> +\t\treturn 0;\n> +\n>  \tint ret = lock(fd);\n>  \tif (ret < 0)\n>  \t\treturn ret;\n> @@ -674,6 +681,7 @@ int V4L2CameraProxy::vidioc_streamon(int fd, int *arg)\n>  \t\treturn -EINVAL;\n>\n>  \tcurrentBuf_ = 0;\n> +\tstreaming_ = true;\n>\n>  \treturn vcam_->streamOn();\n>  }\n> @@ -685,6 +693,12 @@ int V4L2CameraProxy::vidioc_streamoff(int fd, int *arg)\n>  \tif (arg == nullptr)\n>  \t\treturn -EFAULT;\n>\n> +\tif (!streaming_) {\n> +\t\tfor (unsigned int i = 0; i < bufferCount_; i++)\n> +\t\t\tbuffers_[i].flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE);\n> +\t\treturn 0;\n> +\t}\n\nShouldn't this come after the buffer type validation ?\nV4L2Camera::streamOff() is already a no-op if isRunning_, so I think\nthis hunk is not needed.\n\nWhat's left is preventing calling a few ioctls (dqbuf, streamon) when\nthe camera is not running. Something which could be done V4L2Camera,\nor here by adding an isRunning() function to V4L2Camera.\n\nThanks\n  j\n\n> +\n>  \tint ret = lock(fd);\n>  \tif (ret < 0)\n>  \t\treturn ret;\n> @@ -697,6 +711,8 @@ int V4L2CameraProxy::vidioc_streamoff(int fd, int *arg)\n>  \tfor (struct v4l2_buffer &buf : buffers_)\n>  \t\tbuf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE);\n>\n> +\tstreaming_ = false;\n> +\n>  \treturn ret;\n>  }\n>\n> diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\n> index 2ff9571..28b2fa0 100644\n> --- a/src/v4l2/v4l2_camera_proxy.h\n> +++ b/src/v4l2/v4l2_camera_proxy.h\n> @@ -103,6 +103,7 @@ private:\n>  \tint acquiredFd_;\n>\n>  \tbool initialized_;\n> +\tbool streaming_;\n>  };\n>\n>  #endif /* __V4L2_CAMERA_PROXY_H__ */\n> --\n> 2.27.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72D4B603BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Jun 2020 17:04:16 +0200 (CEST)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id F345440011;\n\tWed, 17 Jun 2020 15:04:15 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","Date":"Wed, 17 Jun 2020 17:07:40 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200617150740.gzhf4lrrjyp2fal6@uno.localdomain>","References":"<20200616131244.70308-1-paul.elder@ideasonboard.com>\n\t<20200616131244.70308-10-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200616131244.70308-10-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 09/15] v4l2: v4l2_cammera_proxy: Reset\n\tbuffer flags on streamoff when already off","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 17 Jun 2020 15:04:16 -0000"}}]