{"id":493,"url":"https://patchwork.libcamera.org/api/1.1/patches/493/?format=json","web_url":"https://patchwork.libcamera.org/patch/493/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190203110102.5663-7-kieran.bingham@ideasonboard.com>","date":"2019-02-03T11:00:57","name":"[libcamera-devel,06/11] libcamera: v4l2_device: Implement stream{On, Off}","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9125b1439670e48298a0c77c8084b0fc422438e6","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/493/mbox/","series":[{"id":165,"url":"https://patchwork.libcamera.org/api/1.1/series/165/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=165","date":"2019-02-03T11:00:51","name":"libcamera: V4L2 Streams","version":1,"mbox":"https://patchwork.libcamera.org/series/165/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/493/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/493/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@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 2D24C60B1B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  3 Feb 2019 12:01:08 +0100 (CET)","from localhost.localdomain\n\t(218.182-78-194.adsl-static.isp.belgacom.be [194.78.182.218])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CADFB41;\n\tSun,  3 Feb 2019 12:01:07 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549191667;\n\tbh=0fw5UjSZFZh+JNXV5ehFKNSCl3dpJv03wlB0ejGnFxw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=d4JlOo9nWB+zXVff09eLt7wMSA3D7HqN2nwHd4WcCPLNXCd5OsnQF7KxuxgCgQMa8\n\tbOGOUUKKOWkaaKJ5hQTdfeAAH4GpL+y8wi4qJnrDvcfItzQETKc4+JTotUdbuihAgi\n\tr0Ul37tvl+m+MBPwAHp8ZcppX9PEsnlUEqEvtafM=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Sun,  3 Feb 2019 12:00:57 +0100","Message-Id":"<20190203110102.5663-7-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.19.1","In-Reply-To":"<20190203110102.5663-1-kieran.bingham@ideasonboard.com>","References":"<20190203110102.5663-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 06/11] libcamera: v4l2_device: Implement\n\tstream{On, Off}","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Sun, 03 Feb 2019 11:01:08 -0000"},"content":"Support starting and stopping a stream on a V4L2 device. This requires\nhaving buffers queued, thus both queueBuffer() and dequeueBuffer() are\nalso added.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/v4l2_device.h |   6 ++\n src/libcamera/v4l2_device.cpp       | 134 ++++++++++++++++++++++++++++\n 2 files changed, 140 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex f445f98f97a4..d3dad355be58 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -101,6 +101,12 @@ public:\n \n \tBufferPool *requestBuffers(unsigned int qty = 8);\n \n+\tint queueBuffer(Buffer *frame);\n+\tBuffer *dequeueBuffer();\n+\n+\tint streamOn();\n+\tint streamOff();\n+\n private:\n \tint getFormatSingleplane(V4L2DeviceFormat *fmt);\n \tint setFormatSingleplane(V4L2DeviceFormat *fmt);\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 728478a1ae8f..1fd289137b36 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -592,4 +592,138 @@ int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *fmt)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Queue a buffer into the device.\n+ *\n+ * For Capture devices the buffer will be operated on and can be dequeued later\n+ * with active data.\n+ *\n+ * For Output devices the buffer should contain valid data and will be processed\n+ * by the receiving device. The buffer will be available to dequeue when it is\n+ * no longer in use by the Output device.\n+ *\n+ * \\return 0 if the operation completes or a negative error number otherwise\n+ */\n+int V4L2Device::queueBuffer(Buffer *frame)\n+{\n+\tstruct v4l2_buffer buf = {};\n+\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n+\tint ret;\n+\n+\tbuf.index = frame->index();\n+\tbuf.type = bufferType_;\n+\tbuf.memory = memoryType_;\n+\n+\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n+\t\tbuf.length = frame->planes().size();\n+\t\tbuf.m.planes = planes;\n+\t}\n+\n+\tLOG(V4L2, Debug) << \"Queueing buffer idx: \" << buf.index;\n+\n+\tret = ioctl(fd_, VIDIOC_QBUF, &buf);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to queue buffer: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief dequeue a buffer from the device\n+ *\n+ * For Capture devices the buffer will be contain valid data and can be used for\n+ * further processing. The buffer should be re-queued when it is no longer in\n+ * use.\n+ *\n+ * For Output devices the buffer has been processed by the hardware and can now\n+ * be freely re-used.\n+ *\n+ * \\return A Buffer pointer if the operation completes or a nullptr otherwise\n+ */\n+Buffer *V4L2Device::dequeueBuffer()\n+{\n+\tstruct v4l2_buffer buf = {};\n+\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n+\tint ret;\n+\n+\tbuf.type = bufferType_;\n+\tbuf.memory = memoryType_;\n+\n+\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n+\t\tbuf.length = VIDEO_MAX_PLANES;\n+\t\tbuf.m.planes = planes;\n+\t}\n+\n+\tret = ioctl(fd_, VIDIOC_DQBUF, &buf);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to dequeue buffer: \" << strerror(-ret);\n+\t\treturn nullptr;\n+\t}\n+\n+\tif (buf.index >= bufferPool_->buffers().size()) {\n+\t\tLOG(V4L2, Error) << \"Invalid buffer index dequeued\";\n+\t\treturn nullptr;\n+\t}\n+\n+\treturn bufferPool_->buffers()[buf.index];\n+}\n+\n+/**\n+ * \\brief Request that the V4L2Device commences streaming\n+ *\n+ * Prepares the device to start processing Buffers, and connects the completion\n+ * handler to the bufferAvailable Slot.\n+ *\n+ * \\return 0 if the operation completes or a negative error number otherwise\n+ */\n+int V4L2Device::streamOn()\n+{\n+\tint ret;\n+\n+\tif (caps_.isCapture()) {\n+\t\tfor (Buffer *b : bufferPool_->buffers()) {\n+\t\t\tret = queueBuffer(b);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\tret = ioctl(fd_, VIDIOC_STREAMON, &bufferType_);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to start streaming: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Request that the V4L2Device stops streaming\n+ *\n+ * Asks the device to halt any current streaming operations.\n+ *\n+ * \\return 0 if the operation completes or a negative error number otherwise\n+ */\n+int V4L2Device::streamOff()\n+{\n+\tint ret;\n+\n+\tret = ioctl(fd_, VIDIOC_STREAMOFF, &bufferType_);\n+\tif (ret < 0) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to stop streaming: \" << strerror(errno);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","06/11"]}