[{"id":826,"web_url":"https://patchwork.libcamera.org/comment/826/","msgid":"<20190213172526.GS5332@pendragon.ideasonboard.com>","date":"2019-02-13T17:25:26","subject":"Re: [libcamera-devel] [PATCH v3 3/3] test: v4l2_device: Provide\n\tbuffer sharing test","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 Wed, Feb 13, 2019 at 05:14:53PM +0000, Kieran Bingham wrote:\n> Obtain two V4L2Devices and use one to obtain a BufferPool.\n> \n> Propagate the formats from the first to the second device and then commence\n> sending buffers between the two devices in a ping-pong fashion.\n> \n> Signed-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\n> \n> diff --git a/test/v4l2_device/buffer_sharing.cpp b/test/v4l2_device/buffer_sharing.cpp\n> new file mode 100644\n> index 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\nHow about writing it in English, \"Failed to start streaming on capture\ndevice\" ? :-) Same comment for the other streamOn() below.\n\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\nAnd same here and for the next one.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\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);\n> diff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build\n> index 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","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 CA61A60DBB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 18:25:30 +0100 (CET)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 45394304;\n\tWed, 13 Feb 2019 18:25:30 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550078730;\n\tbh=nqUTv3pomtATlCkX5IsGFN7zfo+oIGeoqIo+TTAzvJM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=FYm5TD+e+/T9n+oxdaY4nNKSX7bi55phzQP/sbVRxjVZMc5op71Pg81eR63FIEV7z\n\tl8EusaXz7oK8XUhpnePQNv81vtklU4omYI5wNCgLCmA5FRZy7niwjB96FSliLN8MO7\n\tzpwiJiwWoou6hxfqseamrJcXZndQXTyHuTB5zlRo=","Date":"Wed, 13 Feb 2019 19:25:26 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190213172526.GS5332@pendragon.ideasonboard.com>","References":"<20190213171453.13852-1-kieran.bingham@ideasonboard.com>\n\t<20190213171453.13852-4-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190213171453.13852-4-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 3/3] test: v4l2_device: Provide\n\tbuffer sharing 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:25:31 -0000"}}]