{"id":547,"url":"https://patchwork.libcamera.org/api/1.1/patches/547/?format=json","web_url":"https://patchwork.libcamera.org/patch/547/","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":"<20190207212119.30299-5-kieran.bingham@ideasonboard.com>","date":"2019-02-07T21:21:18","name":"[libcamera-devel,4/5] libcamera: v4l2_device: Simplify exportBuffers()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"4008f86e7e994db67aecb9f834bb0bb34cc3d6ca","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/547/mbox/","series":[{"id":171,"url":"https://patchwork.libcamera.org/api/1.1/series/171/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=171","date":"2019-02-07T21:21:14","name":"libcamera: Buffer Sharing","version":1,"mbox":"https://patchwork.libcamera.org/series/171/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/547/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/547/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 F0C7E610B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 Feb 2019 22:21:32 +0100 (CET)","from localhost.localdomain (unknown [149.254.234.206])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 909D1F9;\n\tThu,  7 Feb 2019 22:21:30 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549574492;\n\tbh=n2ZfEbMbZsPjWwZOX5Vw16iOoWiFMo9ApdnPsIvxsY0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=TxUQcG6npLyq1bDbGzuwN4T3f9skko27XSrcjzz+OzJkvemTYDuCJFFxT7p0J4pa3\n\tRmx+eAfVDLc84hj28xTYOjMcwzaUVJerBMsbiYJpydBHipgHM5QXZQJSH3tmMiFcre\n\tOPtDyGj4V6GjyxFb+RnjSD/S76K8mYzMp0Ike6Dw=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Thu,  7 Feb 2019 21:21:18 +0000","Message-Id":"<20190207212119.30299-5-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.19.1","In-Reply-To":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 4/5] libcamera: v4l2_device: Simplify\n\texportBuffers()","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":"Thu, 07 Feb 2019 21:21:33 -0000"},"content":"exportBuffers() can only operate on an existing BufferPool allocation. The\npool identifies its size through its .count() method.\n\nPassing a count in to the exportBuffers() call is redundant and can be\nincorrect if the value is not the same as the BufferPool size.\n\nSimplify the function and remove the unnecessary argument, correcting all uses\nthroughout the code base.\n\nWhile we're here, remove the createBuffers() helper from the V4L2DeviceTest\nwhich only served to obfuscate which pool the buffers were being allocated for.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/v4l2_device.h  |  2 +-\n src/libcamera/pipeline/ipu3/ipu3.cpp |  3 +--\n src/libcamera/pipeline/uvcvideo.cpp  |  2 +-\n src/libcamera/pipeline/vimc.cpp      |  2 +-\n src/libcamera/v4l2_device.cpp        | 15 ++++++---------\n test/v4l2_device/buffer_sharing.cpp  |  2 +-\n test/v4l2_device/capture_async.cpp   |  4 ++--\n test/v4l2_device/request_buffers.cpp |  4 ++--\n test/v4l2_device/stream_on_off.cpp   |  4 ++--\n test/v4l2_device/v4l2_device_test.h  |  2 --\n 10 files changed, 17 insertions(+), 23 deletions(-)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 3acb5e466d64..98fa2110efb5 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -97,7 +97,7 @@ public:\n \tint getFormat(V4L2DeviceFormat *format);\n \tint setFormat(V4L2DeviceFormat *format);\n \n-\tint exportBuffers(unsigned int count, BufferPool *pool);\n+\tint exportBuffers(BufferPool *pool);\n \tint importBuffers(BufferPool *pool);\n \tint releaseBuffers();\n \ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 34b03995ae31..677e127dd738 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -191,8 +191,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream)\n \tif (!cfg.bufferCount)\n \t\treturn -EINVAL;\n \n-\tint ret = data->cio2_->exportBuffers(cfg.bufferCount,\n-\t\t\t\t\t     &stream->bufferPool());\n+\tint ret = data->cio2_->exportBuffers(&stream->bufferPool());\n \tif (ret) {\n \t\tLOG(IPU3, Error) << \"Failed to request memory\";\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex ed8228bb2fc6..1a0dcb582670 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -102,7 +102,7 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera, Stream *stream)\n \n \tLOG(UVC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n \n-\treturn video_->exportBuffers(cfg.bufferCount, &stream->bufferPool());\n+\treturn video_->exportBuffers(&stream->bufferPool());\n }\n \n int PipelineHandlerUVC::freeBuffers(Camera *camera, Stream *stream)\ndiff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 0e9ad7b59ee5..06627b1cb847 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -101,7 +101,7 @@ int PipeHandlerVimc::allocateBuffers(Camera *camera, Stream *stream)\n \n \tLOG(VIMC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n \n-\treturn video_->exportBuffers(cfg.bufferCount, &stream->bufferPool());\n+\treturn video_->exportBuffers(&stream->bufferPool());\n }\n \n int PipeHandlerVimc::freeBuffers(Camera *camera, Stream *stream)\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex c654e6dd7b8d..c2e4d0ea8db2 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -526,13 +526,12 @@ int V4L2Device::requestBuffers(unsigned int count)\n }\n \n /**\n- * \\brief Request \\a count buffers to be allocated from the device and stored in\n- * the buffer pool provided.\n- * \\param[in] count Number of buffers to allocate\n+ * \\brief Request buffers to be allocated from the device and stored in the\n+ *  buffer pool provided.\n  * \\param[out] pool BufferPool to populate with buffers\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Device::exportBuffers(unsigned int count, BufferPool *pool)\n+int V4L2Device::exportBuffers(BufferPool *pool)\n {\n \tunsigned int allocatedBuffers;\n \tunsigned int i;\n@@ -540,21 +539,19 @@ int V4L2Device::exportBuffers(unsigned int count, BufferPool *pool)\n \n \tmemoryType_ = V4L2_MEMORY_MMAP;\n \n-\tret = requestBuffers(count);\n+\tret = requestBuffers(pool->count());\n \tif (ret < 0)\n \t\treturn ret;\n \n \tallocatedBuffers = ret;\n-\tif (allocatedBuffers < count) {\n+\tif (allocatedBuffers < pool->count()) {\n \t\tLOG(V4L2, Error) << \"Not enough buffers provided by V4L2Device\";\n \t\trequestBuffers(0);\n \t\treturn -ENOMEM;\n \t}\n \n-\tcount = ret;\n-\n \t/* Map the buffers. */\n-\tfor (i = 0; i < count; ++i) {\n+\tfor (i = 0; i < pool->count(); ++i) {\n \t\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n \t\tstruct v4l2_buffer buf = {};\n \t\tstruct Buffer &buffer = pool->buffers()[i];\ndiff --git a/test/v4l2_device/buffer_sharing.cpp b/test/v4l2_device/buffer_sharing.cpp\nindex 0e96f7b894bd..ca086f2728f1 100644\n--- a/test/v4l2_device/buffer_sharing.cpp\n+++ b/test/v4l2_device/buffer_sharing.cpp\n@@ -80,7 +80,7 @@ protected:\n \n \t\tpool_.createBuffers(bufferCount);\n \n-\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n+\t\tret = dev_->exportBuffers(&pool_);\n \t\tif (ret)\n \t\t\treturn TestFail;\n \ndiff --git a/test/v4l2_device/capture_async.cpp b/test/v4l2_device/capture_async.cpp\nindex 7a0735f65535..d3e20ed86b98 100644\n--- a/test/v4l2_device/capture_async.cpp\n+++ b/test/v4l2_device/capture_async.cpp\n@@ -38,9 +38,9 @@ protected:\n \t\tTimer timeout;\n \t\tint ret;\n \n-\t\tcreateBuffers(bufferCount);\n+\t\tpool_.createBuffers(bufferCount);\n \n-\t\tret = dev_->exportBuffers(bufferCount, &pool_);\n+\t\tret = dev_->exportBuffers(&pool_);\n \t\tif (ret)\n \t\t\treturn TestFail;\n \ndiff --git a/test/v4l2_device/request_buffers.cpp b/test/v4l2_device/request_buffers.cpp\nindex bc6ff2c18a57..26d7d9528982 100644\n--- a/test/v4l2_device/request_buffers.cpp\n+++ b/test/v4l2_device/request_buffers.cpp\n@@ -19,9 +19,9 @@ protected:\n \t\t */\n \t\tconst unsigned int bufferCount = 8;\n \n-\t\tcreateBuffers(bufferCount);\n+\t\tpool_.createBuffers(bufferCount);\n \n-\t\tint ret = dev_->exportBuffers(bufferCount, &pool_);\n+\t\tint ret = dev_->exportBuffers(&pool_);\n \t\tif (ret)\n \t\t\treturn TestFail;\n \ndiff --git a/test/v4l2_device/stream_on_off.cpp b/test/v4l2_device/stream_on_off.cpp\nindex b564d2a2ab67..861d8d695813 100644\n--- a/test/v4l2_device/stream_on_off.cpp\n+++ b/test/v4l2_device/stream_on_off.cpp\n@@ -14,9 +14,9 @@ protected:\n \t{\n \t\tconst unsigned int bufferCount = 8;\n \n-\t\tcreateBuffers(bufferCount);\n+\t\tpool_.createBuffers(bufferCount);\n \n-\t\tint ret = dev_->exportBuffers(bufferCount, &pool_);\n+\t\tint ret = dev_->exportBuffers(&pool_);\n \t\tif (ret)\n \t\t\treturn TestFail;\n \ndiff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_device/v4l2_device_test.h\nindex f22f0bb555d8..43539655f85b 100644\n--- a/test/v4l2_device/v4l2_device_test.h\n+++ b/test/v4l2_device/v4l2_device_test.h\n@@ -24,8 +24,6 @@ class V4L2DeviceTest : public Test\n public:\n \tV4L2DeviceTest() : dev_(nullptr){};\n \n-\tvoid createBuffers(unsigned int qty) { pool_.createBuffers(qty); }\n-\n protected:\n \tint init();\n \tvoid cleanup();\n","prefixes":["libcamera-devel","4/5"]}