[{"id":2955,"web_url":"https://patchwork.libcamera.org/comment/2955/","msgid":"<20191023150842.GE1904@pendragon.ideasonboard.com>","date":"2019-10-23T15:08:42","subject":"Re: [libcamera-devel] [RFC PATCH] libcamera: v4l2_videodevice:\n\tTrack streaming state","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Oct 22, 2019 at 05:01:10PM +0100, Kieran Bingham wrote:\n> Track the state of streamon/streamoff calls to simplify error paths.\n> \n> Ensuring that streamOff() can be called on non-streaming streams facilitates simpler\n> error code paths, where a set of devices can all call streamOff regardless of their\n> initialisation state.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n> \n> This is a patch I have while developing the RPi ISP handler.\n> It means I can do the following for error paths:\n> \n> \tdata->isp_.stats_->streamOff();\n> \tdata->isp_.capture1_->streamOff();\n>  \tdata->isp_.capture0_->streamOff();\n>  \tdata->isp_.output_->streamOff();\n>  \tdata->unicam_->streamOff();\n> \n> which essentially means I can just call stop(camera) for cleanup, without\n> having to track which ones were successfully started or not.\n> \n> So - Reasonable or not ?\n\nAcked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI hope this answers your question :-)\n\n> Patch will not apply directly to master, as it's currently based on my dev\n> branch, hence RFC\n> \n>  src/libcamera/include/v4l2_videodevice.h | 2 ++\n>  src/libcamera/v4l2_videodevice.cpp       | 9 ++++++++-\n>  2 files changed, 10 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 60fca01670c6..d6e0c0e7bf02 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -188,6 +188,8 @@ private:\n>  \tstd::map<unsigned int, Buffer *> queuedBuffers_;\n>  \n>  \tEventNotifier *fdEvent_;\n> +\n> +\tbool streaming_;\n>  };\n>  \n>  class V4L2M2MDevice\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 71c32766fc2d..01e11597cfb0 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -273,7 +273,7 @@ const std::string V4L2DeviceFormat::toString() const\n>   */\n>  V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n>  \t: V4L2Device(deviceNode), multiPlanar_(false), bufferPool_(nullptr),\n> -\t  fdEvent_(nullptr)\n> +\t  fdEvent_(nullptr), streaming_(false)\n>  {\n>  \t/*\n>  \t * We default to an MMAP based CAPTURE video device, however this will\n> @@ -1197,6 +1197,8 @@ int V4L2VideoDevice::streamOn()\n>  \t\treturn ret;\n>  \t}\n>  \n> +\tstreaming_ = true;\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -1214,6 +1216,9 @@ int V4L2VideoDevice::streamOff()\n>  {\n>  \tint ret;\n>  \n> +\tif (!streaming_)\n> +\t\treturn 0;\n> +\n>  \tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n>  \tif (ret < 0) {\n>  \t\tLOG(V4L2, Error)\n> @@ -1234,6 +1239,8 @@ int V4L2VideoDevice::streamOff()\n>  \tqueuedBuffers_.clear();\n>  \tfdEvent_->setEnabled(false);\n>  \n> +\tstreaming_ = false;\n> +\n>  \treturn 0;\n>  }\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EF33E60BF7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Oct 2019 17:08:48 +0200 (CEST)","from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net\n\t[93.2.121.143])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5F80E33A;\n\tWed, 23 Oct 2019 17:08:48 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1571843328;\n\tbh=q5dmZh7tjk/SJtdy1NOQ54UXX+F/LfQTJHidLdnTQvQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=kbE62y7MwKLxqakNvKFUc76iQYj30Ap6R4ZjJSDBnioBjGVJADGqkT+6IaQ+5ofQU\n\tSgCDDMDSd4YZ4u090CJwu/PiucMjWQSDoGNR5r1PWQeHNWatZZ6Msvcgm2QPITrmPe\n\tqrXFXF8tQDiO/5utze3LYA/GHdsOFMfAElkKJHwA=","Date":"Wed, 23 Oct 2019 18:08:42 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20191023150842.GE1904@pendragon.ideasonboard.com>","References":"<20191022160110.19419-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191022160110.19419-1-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [RFC PATCH] libcamera: v4l2_videodevice:\n\tTrack streaming state","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, 23 Oct 2019 15:08:49 -0000"}}]