Show a patch.

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

{
    "id": 1130,
    "url": "https://patchwork.libcamera.org/api/patches/1130/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1130/",
    "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": "<20190429191729.29697-3-niklas.soderlund@ragnatech.se>",
    "date": "2019-04-29T19:17:20",
    "name": "[libcamera-devel,02/11] libcamera: media_device: Open and close media device inside populate()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2b481cc40166540c1d058f857bee4ada7052a11a",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1130/mbox/",
    "series": [
        {
            "id": 284,
            "url": "https://patchwork.libcamera.org/api/series/284/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=284",
            "date": "2019-04-29T19:17:18",
            "name": "libcamerea: Add support for exclusive access to cameras between processes",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/284/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1130/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1130/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<niklas.soderlund@ragnatech.se>",
        "Received": [
            "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33FE160E5A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Apr 2019 21:17:47 +0200 (CEST)",
            "from wyvern.station (unknown [37.182.44.227])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 7811e05c-6ab3-11e9-8e2c-005056917f90;\n\tMon, 29 Apr 2019 21:17:46 +0200 (CEST)"
        ],
        "X-Halon-ID": "7811e05c-6ab3-11e9-8e2c-005056917f90",
        "Authorized-sender": "niklas@soderlund.pp.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 29 Apr 2019 21:17:20 +0200",
        "Message-Id": "<20190429191729.29697-3-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190429191729.29697-1-niklas.soderlund@ragnatech.se>",
        "References": "<20190429191729.29697-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 02/11] libcamera: media_device: Open and\n\tclose media device inside populate()",
        "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, 29 Apr 2019 19:17:47 -0000"
    },
    "content": "Remove the need for the caller to open and close the media device when\npopulating the MediaDevice. This is done as an effort to make the usage\nof the MediaDevice less error prone and the interface stricter.\n\nThe rework also revealed and fixes a potential memory leak in\nMediaDevice::populate() where if the second (or later) call to\nMEDIA_IOC_G_TOPOLOGY would fail.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/device_enumerator.cpp           |  8 +------\n src/libcamera/media_device.cpp                | 12 +++++++++--\n test/media_device/media_device_print_test.cpp |  6 ------\n test/pipeline/ipu3/ipu3_pipeline_test.cpp     |  5 -----\n test/v4l2_device/v4l2_device_test.cpp         |  5 -----\n test/v4l2_subdevice/v4l2_subdevice_test.cpp   | 21 +------------------\n 6 files changed, 12 insertions(+), 45 deletions(-)",
    "diff": "diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex f6878b3d58b3f966..caf91dcff6efd564 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -205,11 +205,7 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode)\n {\n \tstd::shared_ptr<MediaDevice> media = std::make_shared<MediaDevice>(deviceNode);\n \n-\tint ret = media->open();\n-\tif (ret < 0)\n-\t\treturn ret;\n-\n-\tret = media->populate();\n+\tint ret = media->populate();\n \tif (ret < 0) {\n \t\tLOG(DeviceEnumerator, Info)\n \t\t\t<< \"Unable to populate media device \" << deviceNode\n@@ -236,8 +232,6 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode)\n \t\t\treturn ret;\n \t}\n \n-\tmedia->close();\n-\n \tLOG(DeviceEnumerator, Debug)\n \t\t<< \"Added device \" << deviceNode << \": \" << media->driver();\n \ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 449571fb4b78fb94..4b3b8f1fa3e6aaad 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -221,6 +221,10 @@ int MediaDevice::populate()\n \n \tclear();\n \n+\tret = open();\n+\tif (ret)\n+\t\treturn ret;\n+\n \t/*\n \t * Keep calling G_TOPOLOGY until the version number stays stable.\n \t */\n@@ -237,8 +241,9 @@ int MediaDevice::populate()\n \t\t\tLOG(MediaDevice, Error)\n \t\t\t\t<< \"Failed to enumerate topology: \"\n \t\t\t\t<< strerror(-ret);\n-\t\t\treturn ret;\n+\t\t\tgoto done;\n \t\t}\n+\t\tret = 0;\n \n \t\tif (version == topology.topology_version)\n \t\t\tbreak;\n@@ -262,6 +267,9 @@ int MediaDevice::populate()\n \t    populateLinks(topology))\n \t\tvalid_ = true;\n \n+done:\n+\tclose();\n+\n \tdelete[] ents;\n \tdelete[] interfaces;\n \tdelete[] pads;\n@@ -272,7 +280,7 @@ int MediaDevice::populate()\n \t\treturn -EINVAL;\n \t}\n \n-\treturn 0;\n+\treturn ret;\n }\n \n /**\ndiff --git a/test/media_device/media_device_print_test.cpp b/test/media_device/media_device_print_test.cpp\nindex 3eef973939201b27..ceffd538e13fca73 100644\n--- a/test/media_device/media_device_print_test.cpp\n+++ b/test/media_device/media_device_print_test.cpp\n@@ -124,10 +124,6 @@ int MediaDevicePrintTest::testMediaDevice(const string deviceNode)\n \n \tdev.close();\n \n-\tret = dev.open();\n-\tif (ret)\n-\t\treturn ret;\n-\n \tret = dev.populate();\n \tif (ret)\n \t\treturn ret;\n@@ -135,8 +131,6 @@ int MediaDevicePrintTest::testMediaDevice(const string deviceNode)\n \t/* Print out the media graph. */\n \tprintMediaGraph(dev, cerr);\n \n-\tdev.close();\n-\n \treturn 0;\n }\n \ndiff --git a/test/pipeline/ipu3/ipu3_pipeline_test.cpp b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\nindex 953f0233cde485cb..1d4cc4d4950b8391 100644\n--- a/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n+++ b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n@@ -71,11 +71,6 @@ int IPU3PipelineTest::init()\n \t\treturn TestSkip;\n \t}\n \n-\tif (cio2->open()) {\n-\t\tcerr << \"Failed to open media device \" << cio2->deviceNode() << endl;\n-\t\treturn TestFail;\n-\t}\n-\n \t/*\n \t * Camera sensor are connected to the CIO2 unit.\n \t * Count how many sensors are connected in the system\ndiff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\nindex 90e5f7a3ee0c0f2f..833038d56ea4631d 100644\n--- a/test/v4l2_device/v4l2_device_test.cpp\n+++ b/test/v4l2_device/v4l2_device_test.cpp\n@@ -46,9 +46,6 @@ int V4L2DeviceTest::init()\n \tif (!media_)\n \t\treturn TestSkip;\n \n-\tif (!media_->acquire())\n-\t\treturn TestSkip;\n-\n \tMediaEntity *entity = media_->getEntityByName(\"vivid-000-vid-cap\");\n \tif (!entity)\n \t\treturn TestSkip;\n@@ -62,8 +59,6 @@ int V4L2DeviceTest::init()\n \n void V4L2DeviceTest::cleanup()\n {\n-\tmedia_->release();\n-\n \tcapture_->streamOff();\n \tcapture_->releaseBuffers();\n \tcapture_->close();\ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\nindex 4e16ab6cf3e5f874..562a638cb28ebfb2 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n+++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n@@ -45,33 +45,16 @@ int V4L2SubdeviceTest::init()\n \t\treturn TestSkip;\n \t}\n \n-\tif (!media_->acquire()) {\n-\t\tcerr << \"Unable to acquire media device \"\n-\t\t     << media_->deviceNode() << endl;\n-\t\treturn TestSkip;\n-\t}\n-\n-\tint ret = media_->open();\n-\tif (ret) {\n-\t\tcerr << \"Unable to open media device: \" << media_->deviceNode()\n-\t\t     << \": \" << strerror(ret) << endl;\n-\t\tmedia_->release();\n-\t\treturn TestSkip;\n-\t}\n-\n \tMediaEntity *videoEntity = media_->getEntityByName(\"Scaler\");\n \tif (!videoEntity) {\n \t\tcerr << \"Unable to find media entity 'Scaler'\" << endl;\n-\t\tmedia_->release();\n \t\treturn TestFail;\n \t}\n \n \tscaler_ = new V4L2Subdevice(videoEntity);\n-\tret = scaler_->open();\n-\tif (ret) {\n+\tif (scaler_->open()) {\n \t\tcerr << \"Unable to open video subdevice \"\n \t\t     << scaler_->entity()->deviceNode() << endl;\n-\t\tmedia_->release();\n \t\treturn TestSkip;\n \t}\n \n@@ -80,7 +63,5 @@ int V4L2SubdeviceTest::init()\n \n void V4L2SubdeviceTest::cleanup()\n {\n-\tmedia_->release();\n-\n \tdelete scaler_;\n }\n",
    "prefixes": [
        "libcamera-devel",
        "02/11"
    ]
}