Show a patch.

GET /api/patches/575/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 575,
    "url": "https://patchwork.libcamera.org/api/patches/575/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/575/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20190213151027.6376-7-kieran.bingham@ideasonboard.com>",
    "date": "2019-02-13T15:10:25",
    "name": "[libcamera-devel,v2,6/8] libcamera: v4l2_device: Simplify exportBuffers()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "cab9d0babca7951cb196a414ba00bd7b85ed38e9",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/575/mbox/",
    "series": [
        {
            "id": 181,
            "url": "https://patchwork.libcamera.org/api/series/181/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=181",
            "date": "2019-02-13T15:10:19",
            "name": "libcamera: v4l2_device buffer sharing",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/181/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/575/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/575/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 21601610C3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 16:10:34 +0100 (CET)",
            "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B6378304;\n\tWed, 13 Feb 2019 16:10:33 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550070633;\n\tbh=MhhgKgQyLFk+ylf1yHADPMsHipUjGgQGNCN/vzjWACQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=wFRAh4Vvx7OmybCIhOiCclrGIIZXulhHx5E4RbLytZwvkuHUYDoYDdWbHA6Vp5W93\n\tmqW9WwpJ0BYvHjRIwJ0psnSMZRDGyQq/lrXt2OF3J08fStdGJXX8coc1+7AkHYKgRX\n\tyyh2iW1UEErwMC2kG/YtfIJWEfZlouWcA14mYlq4=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Wed, 13 Feb 2019 15:10:25 +0000",
        "Message-Id": "<20190213151027.6376-7-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.19.1",
        "In-Reply-To": "<20190213151027.6376-1-kieran.bingham@ideasonboard.com>",
        "References": "<20190213151027.6376-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 6/8] 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": "Wed, 13 Feb 2019 15:10:35 -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\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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/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 9 files changed, 16 insertions(+), 22 deletions(-)",
    "diff": "diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 983b9d900aea..5a536393a5b5 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -99,7 +99,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 releaseBuffers();\n \n \tint queueBuffer(Buffer *buffer);\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 fc31c52c0ecd..b6a98657b609 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 46840a4f4104..543ff212d010 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -101,7 +101,7 @@ int PipelineHandlerVimc::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 PipelineHandlerVimc::freeBuffers(Camera *camera, Stream *stream)\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex d690be9823f5..152bd9930a70 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -538,13 +538,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@@ -552,21 +551,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/capture_async.cpp b/test/v4l2_device/capture_async.cpp\nindex ba37c9731831..511368d6b53d 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",
        "v2",
        "6/8"
    ]
}