{"id":581,"url":"https://patchwork.libcamera.org/api/1.1/patches/581/?format=json","web_url":"https://patchwork.libcamera.org/patch/581/","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":"<20190213171453.13852-4-kieran.bingham@ideasonboard.com>","date":"2019-02-13T17:14:53","name":"[libcamera-devel,v3,3/3] test: v4l2_device: Provide buffer sharing test","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b8c8ac83a5575758eefefcec8e76583bab1e1c3d","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/581/mbox/","series":[{"id":182,"url":"https://patchwork.libcamera.org/api/1.1/series/182/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=182","date":"2019-02-13T17:14:50","name":"libcamera: test: buffer_sharing","version":3,"mbox":"https://patchwork.libcamera.org/series/182/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/581/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/581/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6707C610BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 18:14:58 +0100 (CET)","from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0806E9B0;\n\tWed, 13 Feb 2019 18:14:57 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550078098;\n\tbh=gmHHXnyno4nEJWCzxm3k5mpDrMgxpkZmOlaQrUbzRVM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=K4YPGF5TGOxU/t7mJAA2/IwtExjjwsiws3zJdCptISpJNBnsIREuQ2UVzX+zMh9iF\n\tjbpVN8h29cQpzQiaqbHdYU+GFEOEJUq3QKZdKZ3+6RXr9VIlQH9sWqjjn7taa1bKIB\n\tKP80aKs5fMYEs1JXw/TH1+RYJgThDtSYE6I6sOtY=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 13 Feb 2019 17:14:53 +0000","Message-Id":"<20190213171453.13852-4-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.19.1","In-Reply-To":"<20190213171453.13852-1-kieran.bingham@ideasonboard.com>","References":"<20190213171453.13852-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 3/3] test: v4l2_device: Provide buffer\n\tsharing test","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":"Wed, 13 Feb 2019 17:14:58 -0000"},"content":"Obtain two V4L2Devices and use one to obtain a BufferPool.\n\nPropagate the formats from the first to the second device and then commence\nsending buffers between the two devices in a ping-pong fashion.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n test/v4l2_device/buffer_sharing.cpp | 187 ++++++++++++++++++++++++++++\n test/v4l2_device/meson.build        |   1 +\n 2 files changed, 188 insertions(+)\n create mode 100644 test/v4l2_device/buffer_sharing.cpp","diff":"diff --git a/test/v4l2_device/buffer_sharing.cpp b/test/v4l2_device/buffer_sharing.cpp\nnew file mode 100644\nindex 000000000000..78173a03f2a2\n--- /dev/null\n+++ b/test/v4l2_device/buffer_sharing.cpp\n@@ -0,0 +1,187 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * libcamera V4L2 API tests\n+ *\n+ * Validate the function of exporting buffers from a V4L2Device and\n+ * the ability to import them to another V4L2Device instance.\n+ * Ensure that the Buffers can successfully be queued and dequeued\n+ * between both devices.\n+ */\n+\n+#include <iostream>\n+\n+#include <libcamera/buffer.h>\n+#include <libcamera/camera_manager.h>\n+#include <libcamera/event_dispatcher.h>\n+#include <libcamera/timer.h>\n+\n+#include \"v4l2_device_test.h\"\n+\n+class BufferSharingTest : public V4L2DeviceTest\n+{\n+public:\n+\tBufferSharingTest()\n+\t\t: output_(nullptr), framesCaptured_(0), framesOutput_(0)\n+\t{\n+\t}\n+\n+private:\n+\tconst unsigned int bufferCount = 4;\n+\n+\tV4L2Device *output_;\n+\n+\tunsigned int framesCaptured_;\n+\tunsigned int framesOutput_;\n+\n+protected:\n+\tint init()\n+\t{\n+\t\tint ret = V4L2DeviceTest::init();\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\t/* media_ already represents VIVID */\n+\t\tMediaEntity *entity = media_->getEntityByName(\"vivid-000-vid-out\");\n+\t\tif (!entity)\n+\t\t\treturn TestSkip;\n+\n+\t\toutput_ = new V4L2Device(entity);\n+\t\tif (!output_) {\n+\t\t\tstd::cout << \"Failed to create output device\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = output_->open();\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to open output device\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tV4L2DeviceFormat format = {};\n+\n+\t\tret = capture_->getFormat(&format);\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to get capture format\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = output_->setFormat(&format);\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to set output format\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tpool_.createBuffers(bufferCount);\n+\n+\t\tret = capture_->exportBuffers(&pool_);\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to export buffers\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = output_->importBuffers(&pool_);\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to import buffers\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tvoid captureBufferReady(Buffer *buffer)\n+\t{\n+\t\tstd::cout << \"Received capture buffer: \" << buffer->index()\n+\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n+\n+\t\toutput_->queueBuffer(buffer);\n+\t\tframesCaptured_++;\n+\t}\n+\n+\tvoid outputBufferReady(Buffer *buffer)\n+\t{\n+\t\tstd::cout << \"Received output buffer: \" << buffer->index()\n+\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n+\n+\t\tcapture_->queueBuffer(buffer);\n+\t\tframesOutput_++;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n+\t\tTimer timeout;\n+\t\tint ret;\n+\n+\t\tcapture_->bufferReady.connect(this, &BufferSharingTest::captureBufferReady);\n+\t\toutput_->bufferReady.connect(this, &BufferSharingTest::outputBufferReady);\n+\n+\t\t/* Queue all the buffers to the capture device. */\n+\t\tfor (Buffer &buffer : pool_.buffers()) {\n+\t\t\tif (capture_->queueBuffer(&buffer))\n+\t\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = capture_->streamOn();\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to streamOn capture device\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = output_->streamOn();\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to streamOn output device\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ttimeout.start(10000);\n+\t\twhile (timeout.isRunning()) {\n+\t\t\tdispatcher->processEvents();\n+\t\t\tif (framesCaptured_ > 30 && framesOutput_ > 30)\n+\t\t\t\tbreak;\n+\t\t}\n+\n+\t\tif ((framesCaptured_ < 1) || (framesOutput_ < 1)) {\n+\t\t\tstd::cout << \"Failed to process any frames within timeout.\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif ((framesCaptured_ < 30) || (framesOutput_ < 30)) {\n+\t\t\tstd::cout << \"Failed to process 30 frames within timeout.\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = capture_->streamOff();\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to streamOff capture.\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tret = output_->streamOff();\n+\t\tif (ret) {\n+\t\t\tstd::cout << \"Failed to streamOff output.\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup()\n+\t{\n+\t\tstd::cout\n+\t\t\t<< \"Captured \" << framesCaptured_ << \" frames and \"\n+\t\t\t<< \"output \" << framesOutput_ << \" frames\"\n+\t\t\t<< std::endl;\n+\n+\t\toutput_->streamOff();\n+\t\toutput_->releaseBuffers();\n+\t\toutput_->close();\n+\n+\t\tdelete output_;\n+\n+\t\tV4L2DeviceTest::cleanup();\n+\t}\n+};\n+\n+TEST_REGISTER(BufferSharingTest);\ndiff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build\nindex ec2c7f9f11ff..9f7a7545ac9b 100644\n--- a/test/v4l2_device/meson.build\n+++ b/test/v4l2_device/meson.build\n@@ -5,6 +5,7 @@ v4l2_device_tests = [\n   [ 'request_buffers',    'request_buffers.cpp' ],\n   [ 'stream_on_off',      'stream_on_off.cpp' ],\n   [ 'capture_async',      'capture_async.cpp' ],\n+  [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n ]\n \n foreach t : v4l2_device_tests\n","prefixes":["libcamera-devel","v3","3/3"]}