[{"id":771,"web_url":"https://patchwork.libcamera.org/comment/771/","msgid":"<20190208172826.GH4562@pendragon.ideasonboard.com>","date":"2019-02-08T17:28:26","subject":"Re: [libcamera-devel] [PATCH 3/5] test: v4l2_device: Provide buffer\n\tsharing 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 Thu, Feb 07, 2019 at 09:21:17PM +0000, Kieran Bingham wrote:\n> Obtain two V4L2Devices and use one to obtain a BufferPool.\n> \n> Propogate the formats from the first to the second device and then commence\n\ns/Propogate/Propagate/\n\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 | 178 ++++++++++++++++++++++++++++\n>  test/v4l2_device/meson.build        |   1 +\n>  2 files changed, 179 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..0e96f7b894bd\n> --- /dev/null\n> +++ b/test/v4l2_device/buffer_sharing.cpp\n> @@ -0,0 +1,178 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera V4L2 API tests\n\nShould this be updated ?\n\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> +#include \"log.h\"\n> +\n> +LOG_DEFINE_CATEGORY(Test)\n\nThe logger is internal to libcamera, let's not use it for tests. We\nshould define a test-specific logging infrastructure instead, to suit\nthe specific needs of tests.\n\n> +class BufferSharingTest : public V4L2DeviceTest\n> +{\n> +public:\n> +\tBufferSharingTest()\n> +\t\t: output_(nullptr), framesCapture(0), framesOutput(0){};\n> +\n> +private:\n> +\tconst unsigned int bufferCount = 4;\n> +\n> +\tV4L2Device *output_;\n> +\tstd::shared_ptr<MediaDevice> secondMedia_;\n> +\n> +\tunsigned int framesCapture;\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\tDeviceMatch uvcvideo(\"uvcvideo\");\n> +\t\tuvcvideo.add(\"Logitech BRIO\");\n\nThis is *very* specific to your setup, we need a more generic solution.\nOne option is to switch to vivid, as it has both a video capture and a\nvideo output device.\n\n> +\t\tsecondMedia_ = std::move(enumerator_->search(uvcvideo));\n> +\t\tif (!secondMedia_) {\n> +\t\t\tLOG(Test, Info) << \"No Brio found\";\n> +\t\t\treturn TestSkip;\n> +\t\t}\n> +\n> +\t\tsecondMedia_->acquire();\n> +\n> +\t\tMediaEntity *entity = secondMedia_->defaultEntity();\n> +\t\tif (!entity)\n> +\t\t\treturn TestFail;\n> +\n> +\t\toutput_ = new V4L2Device(entity);\n> +\t\tif (!output_)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tret = output_->open();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n\nHow about adding an openDevice(const DeviceMatch &dm, ...) function to\nV4L2DeviceTest to do all this, and call it both from\nV4L2DeviceTest::init() and here ?\n\n> +\t\tV4L2DeviceFormat format;\n> +\n> +\t\tret = dev_->getFormat(&format);\n> +\t\tif (ret) {\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tLOG(Test, Info) << \"Successfully obtained format from source\";\n> +\n> +\t\tret = output_->setFormat(&format);\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tLOG(Test, Info) << \"Successfully set format to output\";\n> +\n> +\t\tpool_.createBuffers(bufferCount);\n> +\n> +\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tret = output_->importBuffers(&pool_);\n> +\t\tif (ret) {\n> +\t\t\tstd::cerr << \"Failed to import buffers\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tvoid receiveSourceBuffer(Buffer *buffer)\n> +\t{\n> +\t\tstd::cout << \"Received source buffer: \" << buffer->index()\n> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> +\n> +\t\toutput_->queueBuffer(buffer);\n> +\t\tframesCapture++;\n> +\t}\n> +\n> +\tvoid receiveDestinationBuffer(Buffer *buffer)\n> +\t{\n> +\t\tstd::cout << \"Received destination buffer: \" << buffer->index()\n> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> +\n> +\t\tdev_->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\tdev_->bufferReady.connect(this, &BufferSharingTest::receiveSourceBuffer);\n> +\t\toutput_->bufferReady.connect(this, &BufferSharingTest::receiveDestinationBuffer);\n> +\n> +\t\t/* Queue all the buffers to the device. */\n> +\t\tfor (Buffer &b : pool_.buffers()) {\n> +\t\t\tif (dev_->queueBuffer(&b))\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = dev_->streamOn();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tret = output_->streamOn();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\ttimeout.start(5000);\n> +\t\twhile (timeout.isRunning())\n> +\t\t\tdispatcher->processEvents();\n> +\n> +\t\tif ((framesCapture < 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 ((framesCapture < 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\tstd::cout\n> +\t\t\t<< \"Processed \" << framesCapture << \" capture frames\"\n> +\t\t\t<< \" and \" << framesOutput << \" output frames\"\n> +\t\t\t<< std::endl;\n> +\n> +\t\tret = dev_->streamOff();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tret = output_->streamOff();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\tif (secondMedia_)\n> +\t\t\tsecondMedia_->release();\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 430E86101F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Feb 2019 18:28:32 +0100 (CET)","from pendragon.ideasonboard.com (d51A4137F.access.telenet.be\n\t[81.164.19.127])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 96309F9;\n\tFri,  8 Feb 2019 18:28:31 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549646911;\n\tbh=QDekxYXeHa/1Wscep6+A3I9qgnbs0OgdWw6dutxPc3o=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=td7bDIfgqrM7KNI30r0mQyODRnZDZAB4Tm785Own53ydKgrCpQAWPBLcn2gteiZQk\n\tTDFQYEh2oOnwwakAvphR6DtrFe/r7KglFZmz2wwhfqVeYnPnhgNoSY4Db7r09JnjpE\n\tE1BEKsuJdRxzwT3xoFGEUbWJRnu/AH5zjbGRv0uA=","Date":"Fri, 8 Feb 2019 19:28: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":"<20190208172826.GH4562@pendragon.ideasonboard.com>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-4-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190207212119.30299-4-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/5] 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":"Fri, 08 Feb 2019 17:28:32 -0000"}},{"id":779,"web_url":"https://patchwork.libcamera.org/comment/779/","msgid":"<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>","date":"2019-02-11T11:52:35","subject":"Re: [libcamera-devel] [PATCH 3/5] test: v4l2_device: Provide buffer\n\tsharing test","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 08/02/2019 17:28, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> Thank you for the patch.\n> \n> On Thu, Feb 07, 2019 at 09:21:17PM +0000, Kieran Bingham wrote:\n>> Obtain two V4L2Devices and use one to obtain a BufferPool.\n>>\n>> Propogate the formats from the first to the second device and then commence\n> \n> s/Propogate/Propagate/\n\nAck.\n\n> \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 | 178 ++++++++++++++++++++++++++++\n>>  test/v4l2_device/meson.build        |   1 +\n>>  2 files changed, 179 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..0e96f7b894bd\n>> --- /dev/null\n>> +++ b/test/v4l2_device/buffer_sharing.cpp\n>> @@ -0,0 +1,178 @@\n>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n>> +/*\n>> + * Copyright (C) 2019, Google Inc.\n>> + *\n>> + * libcamera V4L2 API tests\n> \n> Should this be updated ?\n\nIt's part of the V4L2 API tests, no?\n\n\n> \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>> +#include \"log.h\"\n>> +\n>> +LOG_DEFINE_CATEGORY(Test)\n> \n> The logger is internal to libcamera, let's not use it for tests. We\n> should define a test-specific logging infrastructure instead, to suit\n> the specific needs of tests.\n> \n\nAh yes - I should have dropped this - That part was just me playing\naround with the code.\n\nIt works in this instance because this code is an 'internal' test and\nthus has access to all internals including the logging mechanism - but I\nagree the Tests need their own.\n\nCare to write a TestLoggger sometime so we can actually fix all this up?\n\n\n\n>> +class BufferSharingTest : public V4L2DeviceTest\n>> +{\n>> +public:\n>> +\tBufferSharingTest()\n>> +\t\t: output_(nullptr), framesCapture(0), framesOutput(0){};\n>> +\n>> +private:\n>> +\tconst unsigned int bufferCount = 4;\n>> +\n>> +\tV4L2Device *output_;\n>> +\tstd::shared_ptr<MediaDevice> secondMedia_;\n>> +\n>> +\tunsigned int framesCapture;\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\tDeviceMatch uvcvideo(\"uvcvideo\");\n>> +\t\tuvcvideo.add(\"Logitech BRIO\");\n> \n> This is *very* specific to your setup, we need a more generic solution.\n> One option is to switch to vivid, as it has both a video capture and a\n> video output device.\n\n\nYes, of course it is - as was detailed in the cover letter.\n\nThe main purpose of this posting is to support Jacopo in his continued\ndevelopment on the IPU3 which needs buffer imports.\n\n\n\n> \n>> +\t\tsecondMedia_ = std::move(enumerator_->search(uvcvideo));\n>> +\t\tif (!secondMedia_) {\n>> +\t\t\tLOG(Test, Info) << \"No Brio found\";\n>> +\t\t\treturn TestSkip;\n>> +\t\t}\n>> +\n>> +\t\tsecondMedia_->acquire();\n>> +\n>> +\t\tMediaEntity *entity = secondMedia_->defaultEntity();\n>> +\t\tif (!entity)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\toutput_ = new V4L2Device(entity);\n>> +\t\tif (!output_)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tret = output_->open();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n> \n> How about adding an openDevice(const DeviceMatch &dm, ...) function to\n> V4L2DeviceTest to do all this, and call it both from\n> V4L2DeviceTest::init() and here ?\n\n\nThis function certainly got long fast. A helper would be useful yes.\n\n\n> \n>> +\t\tV4L2DeviceFormat format;\n>> +\n>> +\t\tret = dev_->getFormat(&format);\n>> +\t\tif (ret) {\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tLOG(Test, Info) << \"Successfully obtained format from source\";\n>> +\n>> +\t\tret = output_->setFormat(&format);\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tLOG(Test, Info) << \"Successfully set format to output\";\n>> +\n>> +\t\tpool_.createBuffers(bufferCount);\n>> +\n>> +\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tret = output_->importBuffers(&pool_);\n>> +\t\tif (ret) {\n>> +\t\t\tstd::cerr << \"Failed to import buffers\" << std::endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\treturn 0;\n>> +\t}\n>> +\n>> +\tvoid receiveSourceBuffer(Buffer *buffer)\n>> +\t{\n>> +\t\tstd::cout << \"Received source buffer: \" << buffer->index()\n>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n>> +\n>> +\t\toutput_->queueBuffer(buffer);\n>> +\t\tframesCapture++;\n>> +\t}\n>> +\n>> +\tvoid receiveDestinationBuffer(Buffer *buffer)\n>> +\t{\n>> +\t\tstd::cout << \"Received destination buffer: \" << buffer->index()\n>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n>> +\n>> +\t\tdev_->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\tdev_->bufferReady.connect(this, &BufferSharingTest::receiveSourceBuffer);\n>> +\t\toutput_->bufferReady.connect(this, &BufferSharingTest::receiveDestinationBuffer);\n>> +\n>> +\t\t/* Queue all the buffers to the device. */\n>> +\t\tfor (Buffer &b : pool_.buffers()) {\n>> +\t\t\tif (dev_->queueBuffer(&b))\n>> +\t\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tret = dev_->streamOn();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tret = output_->streamOn();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\ttimeout.start(5000);\n>> +\t\twhile (timeout.isRunning())\n>> +\t\t\tdispatcher->processEvents();\n>> +\n>> +\t\tif ((framesCapture < 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 ((framesCapture < 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\tstd::cout\n>> +\t\t\t<< \"Processed \" << framesCapture << \" capture frames\"\n>> +\t\t\t<< \" and \" << framesOutput << \" output frames\"\n>> +\t\t\t<< std::endl;\n>> +\n>> +\t\tret = dev_->streamOff();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tret = output_->streamOff();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\treturn TestPass;\n>> +\t}\n>> +\n>> +\tvoid cleanup()\n>> +\t{\n>> +\t\tif (secondMedia_)\n>> +\t\t\tsecondMedia_->release();\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\n>","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 7B80F610B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 11 Feb 2019 12:52:39 +0100 (CET)","from [192.168.0.21]\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 803F92E4;\n\tMon, 11 Feb 2019 12:52:38 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549885958;\n\tbh=pSAxx+QzNOs+ZyeIaYkChcKGieKXlro+62DZEY1ckas=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=OCCCTRdDMwYvRkhb/elJCLcPXj0iO2O5UApb3/oX3C/05QXYSpFMKnElDSvPudULI\n\tPfV0/tEUXrn4vZSZX35kjwgPak7z/Czjp+CjmJ2m1MR0hlQPSCFZ62WUCRQkepPdaQ\n\tN4AnpDWzew8k94CcuZllrs0zu0PirFapShXz6B4Q=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-4-kieran.bingham@ideasonboard.com>\n\t<20190208172826.GH4562@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>","Date":"Mon, 11 Feb 2019 11:52:35 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.4.0","MIME-Version":"1.0","In-Reply-To":"<20190208172826.GH4562@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 3/5] 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":"Mon, 11 Feb 2019 11:52:39 -0000"}},{"id":785,"web_url":"https://patchwork.libcamera.org/comment/785/","msgid":"<20190212092052.GC6279@pendragon.ideasonboard.com>","date":"2019-02-12T09:20:52","subject":"Re: [libcamera-devel] [PATCH 3/5] test: v4l2_device: Provide buffer\n\tsharing test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Mon, Feb 11, 2019 at 11:52:35AM +0000, Kieran Bingham wrote:\n> On 08/02/2019 17:28, Laurent Pinchart wrote:\n> > On Thu, Feb 07, 2019 at 09:21:17PM +0000, Kieran Bingham wrote:\n> >> Obtain two V4L2Devices and use one to obtain a BufferPool.\n> >>\n> >> Propogate the formats from the first to the second device and then commence\n> > \n> > s/Propogate/Propagate/\n> \n> Ack.\n> \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 | 178 ++++++++++++++++++++++++++++\n> >>  test/v4l2_device/meson.build        |   1 +\n> >>  2 files changed, 179 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..0e96f7b894bd\n> >> --- /dev/null\n> >> +++ b/test/v4l2_device/buffer_sharing.cpp\n> >> @@ -0,0 +1,178 @@\n> >> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> >> +/*\n> >> + * Copyright (C) 2019, Google Inc.\n> >> + *\n> >> + * libcamera V4L2 API tests\n> > \n> > Should this be updated ?\n> \n> It's part of the V4L2 API tests, no?\n\nSure, but it wouldn't hurt to be a tad more specific :-)\n\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> >> +#include \"log.h\"\n> >> +\n> >> +LOG_DEFINE_CATEGORY(Test)\n> > \n> > The logger is internal to libcamera, let's not use it for tests. We\n> > should define a test-specific logging infrastructure instead, to suit\n> > the specific needs of tests.\n> \n> Ah yes - I should have dropped this - That part was just me playing\n> around with the code.\n> \n> It works in this instance because this code is an 'internal' test and\n> thus has access to all internals including the logging mechanism - but I\n> agree the Tests need their own.\n> \n> Care to write a TestLoggger sometime so we can actually fix all this up?\n\nI've added a task for that, let's see who can tackle it first :-)\n\n> >> +class BufferSharingTest : public V4L2DeviceTest\n> >> +{\n> >> +public:\n> >> +\tBufferSharingTest()\n> >> +\t\t: output_(nullptr), framesCapture(0), framesOutput(0){};\n> >> +\n> >> +private:\n> >> +\tconst unsigned int bufferCount = 4;\n> >> +\n> >> +\tV4L2Device *output_;\n> >> +\tstd::shared_ptr<MediaDevice> secondMedia_;\n> >> +\n> >> +\tunsigned int framesCapture;\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\tDeviceMatch uvcvideo(\"uvcvideo\");\n> >> +\t\tuvcvideo.add(\"Logitech BRIO\");\n> > \n> > This is *very* specific to your setup, we need a more generic solution.\n> > One option is to switch to vivid, as it has both a video capture and a\n> > video output device.\n> \n> Yes, of course it is - as was detailed in the cover letter.\n> \n> The main purpose of this posting is to support Jacopo in his continued\n> development on the IPU3 which needs buffer imports.\n\nDo you think it would be lots of work to move this to vivid ?\n\n> >> +\t\tsecondMedia_ = std::move(enumerator_->search(uvcvideo));\n> >> +\t\tif (!secondMedia_) {\n> >> +\t\t\tLOG(Test, Info) << \"No Brio found\";\n> >> +\t\t\treturn TestSkip;\n> >> +\t\t}\n> >> +\n> >> +\t\tsecondMedia_->acquire();\n> >> +\n> >> +\t\tMediaEntity *entity = secondMedia_->defaultEntity();\n> >> +\t\tif (!entity)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\toutput_ = new V4L2Device(entity);\n> >> +\t\tif (!output_)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tret = output_->open();\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> > \n> > How about adding an openDevice(const DeviceMatch &dm, ...) function to\n> > V4L2DeviceTest to do all this, and call it both from\n> > V4L2DeviceTest::init() and here ?\n> \n> This function certainly got long fast. A helper would be useful yes.\n> \n> >> +\t\tV4L2DeviceFormat format;\n> >> +\n> >> +\t\tret = dev_->getFormat(&format);\n> >> +\t\tif (ret) {\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\tLOG(Test, Info) << \"Successfully obtained format from source\";\n> >> +\n> >> +\t\tret = output_->setFormat(&format);\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tLOG(Test, Info) << \"Successfully set format to output\";\n> >> +\n> >> +\t\tpool_.createBuffers(bufferCount);\n> >> +\n> >> +\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tret = output_->importBuffers(&pool_);\n> >> +\t\tif (ret) {\n> >> +\t\t\tstd::cerr << \"Failed to import buffers\" << std::endl;\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\treturn 0;\n> >> +\t}\n> >> +\n> >> +\tvoid receiveSourceBuffer(Buffer *buffer)\n> >> +\t{\n> >> +\t\tstd::cout << \"Received source buffer: \" << buffer->index()\n> >> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> >> +\n> >> +\t\toutput_->queueBuffer(buffer);\n> >> +\t\tframesCapture++;\n> >> +\t}\n> >> +\n> >> +\tvoid receiveDestinationBuffer(Buffer *buffer)\n> >> +\t{\n> >> +\t\tstd::cout << \"Received destination buffer: \" << buffer->index()\n> >> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> >> +\n> >> +\t\tdev_->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\tdev_->bufferReady.connect(this, &BufferSharingTest::receiveSourceBuffer);\n> >> +\t\toutput_->bufferReady.connect(this, &BufferSharingTest::receiveDestinationBuffer);\n> >> +\n> >> +\t\t/* Queue all the buffers to the device. */\n> >> +\t\tfor (Buffer &b : pool_.buffers()) {\n> >> +\t\t\tif (dev_->queueBuffer(&b))\n> >> +\t\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\tret = dev_->streamOn();\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tret = output_->streamOn();\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\ttimeout.start(5000);\n> >> +\t\twhile (timeout.isRunning())\n> >> +\t\t\tdispatcher->processEvents();\n> >> +\n> >> +\t\tif ((framesCapture < 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 ((framesCapture < 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\tstd::cout\n> >> +\t\t\t<< \"Processed \" << framesCapture << \" capture frames\"\n> >> +\t\t\t<< \" and \" << framesOutput << \" output frames\"\n> >> +\t\t\t<< std::endl;\n> >> +\n> >> +\t\tret = dev_->streamOff();\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tret = output_->streamOff();\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\treturn TestPass;\n> >> +\t}\n> >> +\n> >> +\tvoid cleanup()\n> >> +\t{\n> >> +\t\tif (secondMedia_)\n> >> +\t\t\tsecondMedia_->release();\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[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7676460DBB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Feb 2019 10:20:55 +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 DA38F85;\n\tTue, 12 Feb 2019 10:20:54 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549963255;\n\tbh=W9MDSY40VsEPm6IXXetRzCRh3ip/dMIL4E5IpXa0Als=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=aiQuGkMga07mXrbpyuhgms2o//z/fQh4oa2LEzI1+IaLuNzekVp9xYaeSnWavsekm\n\tBl+QyAZjbN1ebppNkLTesKSBymopshIUKCfZ2CP7dzjfRlzs1b1ixPOS0YVl+sBvld\n\tq234j/Wmw53PZiu1L6YmAnbP1ol8JVu7andG+c4s=","Date":"Tue, 12 Feb 2019 11:20:52 +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":"<20190212092052.GC6279@pendragon.ideasonboard.com>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-4-kieran.bingham@ideasonboard.com>\n\t<20190208172826.GH4562@pendragon.ideasonboard.com>\n\t<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/5] 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":"Tue, 12 Feb 2019 09:20:55 -0000"}},{"id":786,"web_url":"https://patchwork.libcamera.org/comment/786/","msgid":"<3b145698-1f77-91ce-1eca-99c36f6e1cfd@ideasonboard.com>","date":"2019-02-12T09:47:45","subject":"Re: [libcamera-devel] [PATCH 3/5] test: v4l2_device: Provide buffer\n\tsharing test","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 12/02/2019 09:20, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> On Mon, Feb 11, 2019 at 11:52:35AM +0000, Kieran Bingham wrote:\n>> On 08/02/2019 17:28, Laurent Pinchart wrote:\n>>> On Thu, Feb 07, 2019 at 09:21:17PM +0000, Kieran Bingham wrote:\n>>>> Obtain two V4L2Devices and use one to obtain a BufferPool.\n>>>>\n>>>> Propogate the formats from the first to the second device and then commence\n>>>\n>>> s/Propogate/Propagate/\n>>\n>> Ack.\n>>\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 | 178 ++++++++++++++++++++++++++++\n>>>>  test/v4l2_device/meson.build        |   1 +\n>>>>  2 files changed, 179 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..0e96f7b894bd\n>>>> --- /dev/null\n>>>> +++ b/test/v4l2_device/buffer_sharing.cpp\n>>>> @@ -0,0 +1,178 @@\n>>>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n>>>> +/*\n>>>> + * Copyright (C) 2019, Google Inc.\n>>>> + *\n>>>> + * libcamera V4L2 API tests\n>>>\n>>> Should this be updated ?\n>>\n>> It's part of the V4L2 API tests, no?\n> \n> Sure, but it wouldn't hurt to be a tad more specific :-)\n> \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>>>> +#include \"log.h\"\n>>>> +\n>>>> +LOG_DEFINE_CATEGORY(Test)\n>>>\n>>> The logger is internal to libcamera, let's not use it for tests. We\n>>> should define a test-specific logging infrastructure instead, to suit\n>>> the specific needs of tests.\n>>\n>> Ah yes - I should have dropped this - That part was just me playing\n>> around with the code.\n>>\n>> It works in this instance because this code is an 'internal' test and\n>> thus has access to all internals including the logging mechanism - but I\n>> agree the Tests need their own.\n>>\n>> Care to write a TestLoggger sometime so we can actually fix all this up?\n> \n> I've added a task for that, let's see who can tackle it first :-)\n> \n>>>> +class BufferSharingTest : public V4L2DeviceTest\n>>>> +{\n>>>> +public:\n>>>> +\tBufferSharingTest()\n>>>> +\t\t: output_(nullptr), framesCapture(0), framesOutput(0){};\n>>>> +\n>>>> +private:\n>>>> +\tconst unsigned int bufferCount = 4;\n>>>> +\n>>>> +\tV4L2Device *output_;\n>>>> +\tstd::shared_ptr<MediaDevice> secondMedia_;\n>>>> +\n>>>> +\tunsigned int framesCapture;\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\tDeviceMatch uvcvideo(\"uvcvideo\");\n>>>> +\t\tuvcvideo.add(\"Logitech BRIO\");\n>>>\n>>> This is *very* specific to your setup, we need a more generic solution.\n>>> One option is to switch to vivid, as it has both a video capture and a\n>>> video output device.\n>>\n>> Yes, of course it is - as was detailed in the cover letter.\n>>\n>> The main purpose of this posting is to support Jacopo in his continued\n>> development on the IPU3 which needs buffer imports.\n> \n> Do you think it would be lots of work to move this to vivid ?\n\nYou know my initial blocker was my inaccurate association of VIVID/VIMC.\nand VIVID != VIMC which is not packaged by my distro :S\n (I should file a bug on Ubuntu)\n\nkbingham@Q:~/projects$ sudo modprobe vimc\nmodprobe: FATAL: Module vimc not found in directory\n/lib/modules/4.18.0-14-generic\nkbingham@Q:~/projects$ sudo modprobe vivid\nkbingham@Q:~/projects$ lsv4l2\nvideo0: HP Wide Vision FHD Camera: HP W\nvideo1: HP Wide Vision FHD Camera: HP W\nvideo2: HP Wide Vision FHD Camera: HP I\nvideo3: HP Wide Vision FHD Camera: HP I\nvideo4: vivid-000-vid-cap\nvideo5: vivid-000-vid-out\n\n\nSo I have vivid - but it does not provide a media device. So we can't\nenumerate it with our current DeviceMatch...\n\nI hear rumours that Linux v4.20 now provides a media device for VIVID\n... should we restrict our tests to v4.20+ or add support for\nnon-media-controller devices?\n\n\n\n>>>> +\t\tsecondMedia_ = std::move(enumerator_->search(uvcvideo));\n>>>> +\t\tif (!secondMedia_) {\n>>>> +\t\t\tLOG(Test, Info) << \"No Brio found\";\n>>>> +\t\t\treturn TestSkip;\n>>>> +\t\t}\n>>>> +\n>>>> +\t\tsecondMedia_->acquire();\n>>>> +\n>>>> +\t\tMediaEntity *entity = secondMedia_->defaultEntity();\n>>>> +\t\tif (!entity)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\toutput_ = new V4L2Device(entity);\n>>>> +\t\tif (!output_)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\tret = output_->open();\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>\n>>> How about adding an openDevice(const DeviceMatch &dm, ...) function to\n>>> V4L2DeviceTest to do all this, and call it both from\n>>> V4L2DeviceTest::init() and here ?\n>>\n>> This function certainly got long fast. A helper would be useful yes.\n>>\n>>>> +\t\tV4L2DeviceFormat format;\n>>>> +\n>>>> +\t\tret = dev_->getFormat(&format);\n>>>> +\t\tif (ret) {\n>>>> +\t\t\treturn TestFail;\n>>>> +\t\t}\n>>>> +\n>>>> +\t\tLOG(Test, Info) << \"Successfully obtained format from source\";\n>>>> +\n>>>> +\t\tret = output_->setFormat(&format);\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\tLOG(Test, Info) << \"Successfully set format to output\";\n>>>> +\n>>>> +\t\tpool_.createBuffers(bufferCount);\n>>>> +\n>>>> +\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\tret = output_->importBuffers(&pool_);\n>>>> +\t\tif (ret) {\n>>>> +\t\t\tstd::cerr << \"Failed to import buffers\" << std::endl;\n>>>> +\t\t\treturn TestFail;\n>>>> +\t\t}\n>>>> +\n>>>> +\t\treturn 0;\n>>>> +\t}\n>>>> +\n>>>> +\tvoid receiveSourceBuffer(Buffer *buffer)\n>>>> +\t{\n>>>> +\t\tstd::cout << \"Received source buffer: \" << buffer->index()\n>>>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n>>>> +\n>>>> +\t\toutput_->queueBuffer(buffer);\n>>>> +\t\tframesCapture++;\n>>>> +\t}\n>>>> +\n>>>> +\tvoid receiveDestinationBuffer(Buffer *buffer)\n>>>> +\t{\n>>>> +\t\tstd::cout << \"Received destination buffer: \" << buffer->index()\n>>>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n>>>> +\n>>>> +\t\tdev_->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\tdev_->bufferReady.connect(this, &BufferSharingTest::receiveSourceBuffer);\n>>>> +\t\toutput_->bufferReady.connect(this, &BufferSharingTest::receiveDestinationBuffer);\n>>>> +\n>>>> +\t\t/* Queue all the buffers to the device. */\n>>>> +\t\tfor (Buffer &b : pool_.buffers()) {\n>>>> +\t\t\tif (dev_->queueBuffer(&b))\n>>>> +\t\t\t\treturn TestFail;\n>>>> +\t\t}\n>>>> +\n>>>> +\t\tret = dev_->streamOn();\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\tret = output_->streamOn();\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\ttimeout.start(5000);\n>>>> +\t\twhile (timeout.isRunning())\n>>>> +\t\t\tdispatcher->processEvents();\n>>>> +\n>>>> +\t\tif ((framesCapture < 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 ((framesCapture < 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\tstd::cout\n>>>> +\t\t\t<< \"Processed \" << framesCapture << \" capture frames\"\n>>>> +\t\t\t<< \" and \" << framesOutput << \" output frames\"\n>>>> +\t\t\t<< std::endl;\n>>>> +\n>>>> +\t\tret = dev_->streamOff();\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\tret = output_->streamOff();\n>>>> +\t\tif (ret)\n>>>> +\t\t\treturn TestFail;\n>>>> +\n>>>> +\t\treturn TestPass;\n>>>> +\t}\n>>>> +\n>>>> +\tvoid cleanup()\n>>>> +\t{\n>>>> +\t\tif (secondMedia_)\n>>>> +\t\t\tsecondMedia_->release();\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\n>","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 93F1060DBB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Feb 2019 10:47:49 +0100 (CET)","from [192.168.0.21]\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 03E1585;\n\tTue, 12 Feb 2019 10:47:48 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549964869;\n\tbh=IUo43UX4VCjTptP61TxXqovz/KhAblKFXTLIrBFvCNk=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=ENwI+89UNt+b2nG9ojvkbdFleHZnmD5Ovj07gTcXuzK3Zapyo+aw6VXFsvlp7aOk2\n\tr+wRrZ0MFs2KBWVGmftyReJadRB9Hv61E2Q8Il+wJz5f2bcqpqc3iuT304zkAYjbBv\n\ttxSOxi2zVIDYZWoptwa9UZKN4avRDbO2Clxn7A1g=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-4-kieran.bingham@ideasonboard.com>\n\t<20190208172826.GH4562@pendragon.ideasonboard.com>\n\t<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>\n\t<20190212092052.GC6279@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<3b145698-1f77-91ce-1eca-99c36f6e1cfd@ideasonboard.com>","Date":"Tue, 12 Feb 2019 09:47:45 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.4.0","MIME-Version":"1.0","In-Reply-To":"<20190212092052.GC6279@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 3/5] 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":"Tue, 12 Feb 2019 09:47:49 -0000"}},{"id":788,"web_url":"https://patchwork.libcamera.org/comment/788/","msgid":"<20190212111131.GG6279@pendragon.ideasonboard.com>","date":"2019-02-12T11:11:31","subject":"Re: [libcamera-devel] [PATCH 3/5] test: v4l2_device: Provide buffer\n\tsharing test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Tue, Feb 12, 2019 at 09:47:45AM +0000, Kieran Bingham wrote:\n> On 12/02/2019 09:20, Laurent Pinchart wrote:\n> > On Mon, Feb 11, 2019 at 11:52:35AM +0000, Kieran Bingham wrote:\n> >> On 08/02/2019 17:28, Laurent Pinchart wrote:\n> >>> On Thu, Feb 07, 2019 at 09:21:17PM +0000, Kieran Bingham wrote:\n> >>>> Obtain two V4L2Devices and use one to obtain a BufferPool.\n> >>>>\n> >>>> Propogate the formats from the first to the second device and then commence\n> >>>\n> >>> s/Propogate/Propagate/\n> >>\n> >> Ack.\n> >>\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 | 178 ++++++++++++++++++++++++++++\n> >>>>  test/v4l2_device/meson.build        |   1 +\n> >>>>  2 files changed, 179 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..0e96f7b894bd\n> >>>> --- /dev/null\n> >>>> +++ b/test/v4l2_device/buffer_sharing.cpp\n> >>>> @@ -0,0 +1,178 @@\n> >>>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> >>>> +/*\n> >>>> + * Copyright (C) 2019, Google Inc.\n> >>>> + *\n> >>>> + * libcamera V4L2 API tests\n> >>>\n> >>> Should this be updated ?\n> >>\n> >> It's part of the V4L2 API tests, no?\n> > \n> > Sure, but it wouldn't hurt to be a tad more specific :-)\n> > \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> >>>> +#include \"log.h\"\n> >>>> +\n> >>>> +LOG_DEFINE_CATEGORY(Test)\n> >>>\n> >>> The logger is internal to libcamera, let's not use it for tests. We\n> >>> should define a test-specific logging infrastructure instead, to suit\n> >>> the specific needs of tests.\n> >>\n> >> Ah yes - I should have dropped this - That part was just me playing\n> >> around with the code.\n> >>\n> >> It works in this instance because this code is an 'internal' test and\n> >> thus has access to all internals including the logging mechanism - but I\n> >> agree the Tests need their own.\n> >>\n> >> Care to write a TestLoggger sometime so we can actually fix all this up?\n> > \n> > I've added a task for that, let's see who can tackle it first :-)\n> > \n> >>>> +class BufferSharingTest : public V4L2DeviceTest\n> >>>> +{\n> >>>> +public:\n> >>>> +\tBufferSharingTest()\n> >>>> +\t\t: output_(nullptr), framesCapture(0), framesOutput(0){};\n> >>>> +\n> >>>> +private:\n> >>>> +\tconst unsigned int bufferCount = 4;\n> >>>> +\n> >>>> +\tV4L2Device *output_;\n> >>>> +\tstd::shared_ptr<MediaDevice> secondMedia_;\n> >>>> +\n> >>>> +\tunsigned int framesCapture;\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\tDeviceMatch uvcvideo(\"uvcvideo\");\n> >>>> +\t\tuvcvideo.add(\"Logitech BRIO\");\n> >>>\n> >>> This is *very* specific to your setup, we need a more generic solution.\n> >>> One option is to switch to vivid, as it has both a video capture and a\n> >>> video output device.\n> >>\n> >> Yes, of course it is - as was detailed in the cover letter.\n> >>\n> >> The main purpose of this posting is to support Jacopo in his continued\n> >> development on the IPU3 which needs buffer imports.\n> > \n> > Do you think it would be lots of work to move this to vivid ?\n> \n> You know my initial blocker was my inaccurate association of VIVID/VIMC.\n> and VIVID != VIMC which is not packaged by my distro :S\n>  (I should file a bug on Ubuntu)\n> \n> kbingham@Q:~/projects$ sudo modprobe vimc\n> modprobe: FATAL: Module vimc not found in directory\n\n:-/ A bug report is indeed needed.\n\n> /lib/modules/4.18.0-14-generic\n> kbingham@Q:~/projects$ sudo modprobe vivid\n> kbingham@Q:~/projects$ lsv4l2\n> video0: HP Wide Vision FHD Camera: HP W\n> video1: HP Wide Vision FHD Camera: HP W\n> video2: HP Wide Vision FHD Camera: HP I\n> video3: HP Wide Vision FHD Camera: HP I\n> video4: vivid-000-vid-cap\n> video5: vivid-000-vid-out\n> \n> \n> So I have vivid - but it does not provide a media device. So we can't\n> enumerate it with our current DeviceMatch...\n> \n> I hear rumours that Linux v4.20 now provides a media device for VIVID\n> ... should we restrict our tests to v4.20+ or add support for\n> non-media-controller devices?\n\nI think we shouldn't relax the media controller requirement. The\nvivid-based tests would then be restricted to v4.20+.\n\n> >>>> +\t\tsecondMedia_ = std::move(enumerator_->search(uvcvideo));\n> >>>> +\t\tif (!secondMedia_) {\n> >>>> +\t\t\tLOG(Test, Info) << \"No Brio found\";\n> >>>> +\t\t\treturn TestSkip;\n> >>>> +\t\t}\n> >>>> +\n> >>>> +\t\tsecondMedia_->acquire();\n> >>>> +\n> >>>> +\t\tMediaEntity *entity = secondMedia_->defaultEntity();\n> >>>> +\t\tif (!entity)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\toutput_ = new V4L2Device(entity);\n> >>>> +\t\tif (!output_)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\tret = output_->open();\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>\n> >>> How about adding an openDevice(const DeviceMatch &dm, ...) function to\n> >>> V4L2DeviceTest to do all this, and call it both from\n> >>> V4L2DeviceTest::init() and here ?\n> >>\n> >> This function certainly got long fast. A helper would be useful yes.\n> >>\n> >>>> +\t\tV4L2DeviceFormat format;\n> >>>> +\n> >>>> +\t\tret = dev_->getFormat(&format);\n> >>>> +\t\tif (ret) {\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\t\t}\n> >>>> +\n> >>>> +\t\tLOG(Test, Info) << \"Successfully obtained format from source\";\n> >>>> +\n> >>>> +\t\tret = output_->setFormat(&format);\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\tLOG(Test, Info) << \"Successfully set format to output\";\n> >>>> +\n> >>>> +\t\tpool_.createBuffers(bufferCount);\n> >>>> +\n> >>>> +\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\tret = output_->importBuffers(&pool_);\n> >>>> +\t\tif (ret) {\n> >>>> +\t\t\tstd::cerr << \"Failed to import buffers\" << std::endl;\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\t\t}\n> >>>> +\n> >>>> +\t\treturn 0;\n> >>>> +\t}\n> >>>> +\n> >>>> +\tvoid receiveSourceBuffer(Buffer *buffer)\n> >>>> +\t{\n> >>>> +\t\tstd::cout << \"Received source buffer: \" << buffer->index()\n> >>>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> >>>> +\n> >>>> +\t\toutput_->queueBuffer(buffer);\n> >>>> +\t\tframesCapture++;\n> >>>> +\t}\n> >>>> +\n> >>>> +\tvoid receiveDestinationBuffer(Buffer *buffer)\n> >>>> +\t{\n> >>>> +\t\tstd::cout << \"Received destination buffer: \" << buffer->index()\n> >>>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> >>>> +\n> >>>> +\t\tdev_->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\tdev_->bufferReady.connect(this, &BufferSharingTest::receiveSourceBuffer);\n> >>>> +\t\toutput_->bufferReady.connect(this, &BufferSharingTest::receiveDestinationBuffer);\n> >>>> +\n> >>>> +\t\t/* Queue all the buffers to the device. */\n> >>>> +\t\tfor (Buffer &b : pool_.buffers()) {\n> >>>> +\t\t\tif (dev_->queueBuffer(&b))\n> >>>> +\t\t\t\treturn TestFail;\n> >>>> +\t\t}\n> >>>> +\n> >>>> +\t\tret = dev_->streamOn();\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\tret = output_->streamOn();\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\ttimeout.start(5000);\n> >>>> +\t\twhile (timeout.isRunning())\n> >>>> +\t\t\tdispatcher->processEvents();\n> >>>> +\n> >>>> +\t\tif ((framesCapture < 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 ((framesCapture < 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\tstd::cout\n> >>>> +\t\t\t<< \"Processed \" << framesCapture << \" capture frames\"\n> >>>> +\t\t\t<< \" and \" << framesOutput << \" output frames\"\n> >>>> +\t\t\t<< std::endl;\n> >>>> +\n> >>>> +\t\tret = dev_->streamOff();\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\tret = output_->streamOff();\n> >>>> +\t\tif (ret)\n> >>>> +\t\t\treturn TestFail;\n> >>>> +\n> >>>> +\t\treturn TestPass;\n> >>>> +\t}\n> >>>> +\n> >>>> +\tvoid cleanup()\n> >>>> +\t{\n> >>>> +\t\tif (secondMedia_)\n> >>>> +\t\t\tsecondMedia_->release();\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 91D6260B0E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Feb 2019 12:11:35 +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 E071385;\n\tTue, 12 Feb 2019 12:11:34 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549969895;\n\tbh=ZDlhVdQwtjEVQn62XLjxPwuSn7CKvqfUzdsR4geuXmw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=PKWKWFbuTVjKyZ76KDpSZXw3bid3BZHAVoG+Y2Ed7mBqBwDLZIBxPJD0ijXifnrxM\n\tF+Ir1EhQIlKLQ4PH7v3lYb863JkLRlug4ABCU6LWMh/lnaJT5j8sfkmnRbpUNTcha5\n\tDeC+z7eUtdEZXWyqA5oFu2cQv0G3haa1uW2u25Iw=","Date":"Tue, 12 Feb 2019 13:11:31 +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":"<20190212111131.GG6279@pendragon.ideasonboard.com>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-4-kieran.bingham@ideasonboard.com>\n\t<20190208172826.GH4562@pendragon.ideasonboard.com>\n\t<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>\n\t<20190212092052.GC6279@pendragon.ideasonboard.com>\n\t<3b145698-1f77-91ce-1eca-99c36f6e1cfd@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<3b145698-1f77-91ce-1eca-99c36f6e1cfd@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/5] 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":"Tue, 12 Feb 2019 11:11:35 -0000"}},{"id":794,"web_url":"https://patchwork.libcamera.org/comment/794/","msgid":"<20190213101737.GJ31044@bigcity.dyn.berto.se>","date":"2019-02-13T10:17:37","subject":"Re: [libcamera-devel] [PATCH 3/5] test: v4l2_device: Provide buffer\n\tsharing test","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"On 2019-02-12 13:11:31 +0200, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> On Tue, Feb 12, 2019 at 09:47:45AM +0000, Kieran Bingham wrote:\n> > On 12/02/2019 09:20, Laurent Pinchart wrote:\n> > > On Mon, Feb 11, 2019 at 11:52:35AM +0000, Kieran Bingham wrote:\n> > >> On 08/02/2019 17:28, Laurent Pinchart wrote:\n> > >>> On Thu, Feb 07, 2019 at 09:21:17PM +0000, Kieran Bingham wrote:\n> > >>>> Obtain two V4L2Devices and use one to obtain a BufferPool.\n> > >>>>\n> > >>>> Propogate the formats from the first to the second device and then commence\n> > >>>\n> > >>> s/Propogate/Propagate/\n> > >>\n> > >> Ack.\n> > >>\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 | 178 ++++++++++++++++++++++++++++\n> > >>>>  test/v4l2_device/meson.build        |   1 +\n> > >>>>  2 files changed, 179 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..0e96f7b894bd\n> > >>>> --- /dev/null\n> > >>>> +++ b/test/v4l2_device/buffer_sharing.cpp\n> > >>>> @@ -0,0 +1,178 @@\n> > >>>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > >>>> +/*\n> > >>>> + * Copyright (C) 2019, Google Inc.\n> > >>>> + *\n> > >>>> + * libcamera V4L2 API tests\n> > >>>\n> > >>> Should this be updated ?\n> > >>\n> > >> It's part of the V4L2 API tests, no?\n> > > \n> > > Sure, but it wouldn't hurt to be a tad more specific :-)\n> > > \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> > >>>> +#include \"log.h\"\n> > >>>> +\n> > >>>> +LOG_DEFINE_CATEGORY(Test)\n> > >>>\n> > >>> The logger is internal to libcamera, let's not use it for tests. We\n> > >>> should define a test-specific logging infrastructure instead, to suit\n> > >>> the specific needs of tests.\n> > >>\n> > >> Ah yes - I should have dropped this - That part was just me playing\n> > >> around with the code.\n> > >>\n> > >> It works in this instance because this code is an 'internal' test and\n> > >> thus has access to all internals including the logging mechanism - but I\n> > >> agree the Tests need their own.\n> > >>\n> > >> Care to write a TestLoggger sometime so we can actually fix all this up?\n> > > \n> > > I've added a task for that, let's see who can tackle it first :-)\n> > > \n> > >>>> +class BufferSharingTest : public V4L2DeviceTest\n> > >>>> +{\n> > >>>> +public:\n> > >>>> +\tBufferSharingTest()\n> > >>>> +\t\t: output_(nullptr), framesCapture(0), framesOutput(0){};\n> > >>>> +\n> > >>>> +private:\n> > >>>> +\tconst unsigned int bufferCount = 4;\n> > >>>> +\n> > >>>> +\tV4L2Device *output_;\n> > >>>> +\tstd::shared_ptr<MediaDevice> secondMedia_;\n> > >>>> +\n> > >>>> +\tunsigned int framesCapture;\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\tDeviceMatch uvcvideo(\"uvcvideo\");\n> > >>>> +\t\tuvcvideo.add(\"Logitech BRIO\");\n> > >>>\n> > >>> This is *very* specific to your setup, we need a more generic solution.\n> > >>> One option is to switch to vivid, as it has both a video capture and a\n> > >>> video output device.\n> > >>\n> > >> Yes, of course it is - as was detailed in the cover letter.\n> > >>\n> > >> The main purpose of this posting is to support Jacopo in his continued\n> > >> development on the IPU3 which needs buffer imports.\n> > > \n> > > Do you think it would be lots of work to move this to vivid ?\n> > \n> > You know my initial blocker was my inaccurate association of VIVID/VIMC.\n> > and VIVID != VIMC which is not packaged by my distro :S\n> >  (I should file a bug on Ubuntu)\n> > \n> > kbingham@Q:~/projects$ sudo modprobe vimc\n> > modprobe: FATAL: Module vimc not found in directory\n> \n> :-/ A bug report is indeed needed.\n> \n> > /lib/modules/4.18.0-14-generic\n> > kbingham@Q:~/projects$ sudo modprobe vivid\n> > kbingham@Q:~/projects$ lsv4l2\n> > video0: HP Wide Vision FHD Camera: HP W\n> > video1: HP Wide Vision FHD Camera: HP W\n> > video2: HP Wide Vision FHD Camera: HP I\n> > video3: HP Wide Vision FHD Camera: HP I\n> > video4: vivid-000-vid-cap\n> > video5: vivid-000-vid-out\n> > \n> > \n> > So I have vivid - but it does not provide a media device. So we can't\n> > enumerate it with our current DeviceMatch...\n> > \n> > I hear rumours that Linux v4.20 now provides a media device for VIVID\n> > ... should we restrict our tests to v4.20+ or add support for\n> > non-media-controller devices?\n> \n> I think we shouldn't relax the media controller requirement. The\n> vivid-based tests would then be restricted to v4.20+.\n\nI agree, we should not relax the media controller requirement. That \nwould IMHO open a can of worms :-)\n\n> \n> > >>>> +\t\tsecondMedia_ = std::move(enumerator_->search(uvcvideo));\n> > >>>> +\t\tif (!secondMedia_) {\n> > >>>> +\t\t\tLOG(Test, Info) << \"No Brio found\";\n> > >>>> +\t\t\treturn TestSkip;\n> > >>>> +\t\t}\n> > >>>> +\n> > >>>> +\t\tsecondMedia_->acquire();\n> > >>>> +\n> > >>>> +\t\tMediaEntity *entity = secondMedia_->defaultEntity();\n> > >>>> +\t\tif (!entity)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\toutput_ = new V4L2Device(entity);\n> > >>>> +\t\tif (!output_)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\tret = output_->open();\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>\n> > >>> How about adding an openDevice(const DeviceMatch &dm, ...) function to\n> > >>> V4L2DeviceTest to do all this, and call it both from\n> > >>> V4L2DeviceTest::init() and here ?\n> > >>\n> > >> This function certainly got long fast. A helper would be useful yes.\n> > >>\n> > >>>> +\t\tV4L2DeviceFormat format;\n> > >>>> +\n> > >>>> +\t\tret = dev_->getFormat(&format);\n> > >>>> +\t\tif (ret) {\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\t\t}\n> > >>>> +\n> > >>>> +\t\tLOG(Test, Info) << \"Successfully obtained format from source\";\n> > >>>> +\n> > >>>> +\t\tret = output_->setFormat(&format);\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\tLOG(Test, Info) << \"Successfully set format to output\";\n> > >>>> +\n> > >>>> +\t\tpool_.createBuffers(bufferCount);\n> > >>>> +\n> > >>>> +\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\tret = output_->importBuffers(&pool_);\n> > >>>> +\t\tif (ret) {\n> > >>>> +\t\t\tstd::cerr << \"Failed to import buffers\" << std::endl;\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\t\t}\n> > >>>> +\n> > >>>> +\t\treturn 0;\n> > >>>> +\t}\n> > >>>> +\n> > >>>> +\tvoid receiveSourceBuffer(Buffer *buffer)\n> > >>>> +\t{\n> > >>>> +\t\tstd::cout << \"Received source buffer: \" << buffer->index()\n> > >>>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> > >>>> +\n> > >>>> +\t\toutput_->queueBuffer(buffer);\n> > >>>> +\t\tframesCapture++;\n> > >>>> +\t}\n> > >>>> +\n> > >>>> +\tvoid receiveDestinationBuffer(Buffer *buffer)\n> > >>>> +\t{\n> > >>>> +\t\tstd::cout << \"Received destination buffer: \" << buffer->index()\n> > >>>> +\t\t\t  << \" sequence \" << buffer->sequence() << std::endl;\n> > >>>> +\n> > >>>> +\t\tdev_->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\tdev_->bufferReady.connect(this, &BufferSharingTest::receiveSourceBuffer);\n> > >>>> +\t\toutput_->bufferReady.connect(this, &BufferSharingTest::receiveDestinationBuffer);\n> > >>>> +\n> > >>>> +\t\t/* Queue all the buffers to the device. */\n> > >>>> +\t\tfor (Buffer &b : pool_.buffers()) {\n> > >>>> +\t\t\tif (dev_->queueBuffer(&b))\n> > >>>> +\t\t\t\treturn TestFail;\n> > >>>> +\t\t}\n> > >>>> +\n> > >>>> +\t\tret = dev_->streamOn();\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\tret = output_->streamOn();\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\ttimeout.start(5000);\n> > >>>> +\t\twhile (timeout.isRunning())\n> > >>>> +\t\t\tdispatcher->processEvents();\n> > >>>> +\n> > >>>> +\t\tif ((framesCapture < 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 ((framesCapture < 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\tstd::cout\n> > >>>> +\t\t\t<< \"Processed \" << framesCapture << \" capture frames\"\n> > >>>> +\t\t\t<< \" and \" << framesOutput << \" output frames\"\n> > >>>> +\t\t\t<< std::endl;\n> > >>>> +\n> > >>>> +\t\tret = dev_->streamOff();\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\tret = output_->streamOff();\n> > >>>> +\t\tif (ret)\n> > >>>> +\t\t\treturn TestFail;\n> > >>>> +\n> > >>>> +\t\treturn TestPass;\n> > >>>> +\t}\n> > >>>> +\n> > >>>> +\tvoid cleanup()\n> > >>>> +\t{\n> > >>>> +\t\tif (secondMedia_)\n> > >>>> +\t\t\tsecondMedia_->release();\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\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com\n\t[IPv6:2a00:1450:4864:20::12a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 17DBF610B1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 11:17:40 +0100 (CET)","by mail-lf1-x12a.google.com with SMTP id f5so1302465lfc.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 02:17:40 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tr1sm3634945lfm.89.2019.02.13.02.17.37\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 13 Feb 2019 02:17:38 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=swrUm/Rx+iyTzbpHko1ML4L0+CdurFEfmMveC0tEr08=;\n\tb=1E70kGfVO4p7ECVbto/o+lXWqqYT3JlJSsNRdAzUpM3Zdom3jpqaw9QQo9/9tNTyvo\n\txWuUwDnNI8hBHhUhGaNmNKrXmwZQ6LDBpsVchy1bsZO5RqMMiCw5NnL517aS8gVerHX8\n\tVUDfL9dEW1ckSBcUOEk/EAPFTxOXuEBUjOcZ71N+5IfUL0ANDTetZSmSHBvgTzbITboN\n\tmgaFuTiwfsHTAe1/o6ChIprF+VGNSLN+jOE7zO2FdA8P/a6rFp8Eo+Zu0CgF9P2hbGj4\n\tJYhuM57QPj5tpC1z8HFKZ4CDXHF290CCGnYWvvL/Z+GLHx8XnzQZ8+SiDpIyIJUuazwB\n\tFOAQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=swrUm/Rx+iyTzbpHko1ML4L0+CdurFEfmMveC0tEr08=;\n\tb=lOT7JmbpszYVYa5sjbdBZVDsFKGv2Bcux07LJVRY55hhSz3w5FdzALCH/RF3rfNHRx\n\t0qz1ex09dmURbYaB7Avpr86xWu7fDhextriUKg3BEzUjPnUJfAcqz7H/QosnddgXLT15\n\t5H9cfaNboiIE+MKykesS4S/534YCfgBlPTcuUrdjiF50ZLVhKMgIYj2Q9vMlKlO7Oi5b\n\t6HjUb9O9RpVBM0rrAQxhxMrop6C1HsmGbpEhHoYu0cGbKuPW1SZcZaVVfhuPBdBOXqGA\n\twc5BF50/90q/vDRtzGcxuHB7w8vycCrVYoO0YWyxss7SI3baE9C0WRVc32VZ7Mn9CX6u\n\thj5A==","X-Gm-Message-State":"AHQUAuYs1zy/EmY5zmm93oaKmhS4NPqPryE//PeqWPP3ghaeI3r+LODq\n\t5rrZazxvf296t/oOLqD4vL9FLw==","X-Google-Smtp-Source":"AHgI3IYPu4JG3lFyjyQUxVFBgbRWJlBhao5d0h+qfEqvcVEuSvmflKi90MR8ZgmdSh77ZSDJ8MoZWA==","X-Received":"by 2002:ac2:43c3:: with SMTP id u3mr2182266lfl.114.1550053059007;\n\tWed, 13 Feb 2019 02:17:39 -0800 (PST)","Date":"Wed, 13 Feb 2019 11:17:37 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190213101737.GJ31044@bigcity.dyn.berto.se>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-4-kieran.bingham@ideasonboard.com>\n\t<20190208172826.GH4562@pendragon.ideasonboard.com>\n\t<81b2e5a6-8d47-7042-553f-3af545874616@ideasonboard.com>\n\t<20190212092052.GC6279@pendragon.ideasonboard.com>\n\t<3b145698-1f77-91ce-1eca-99c36f6e1cfd@ideasonboard.com>\n\t<20190212111131.GG6279@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190212111131.GG6279@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/5] 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 10:17:40 -0000"}}]