Show a patch.

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

{
    "id": 10658,
    "url": "https://patchwork.libcamera.org/api/patches/10658/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10658/",
    "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": "<20201212185116.29611-4-laurent.pinchart@ideasonboard.com>",
    "date": "2020-12-12T18:51:16",
    "name": "[libcamera-devel,3/3] libcamera: pipeline: Manage resources with std::unique_ptr<>",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b1d1eb3d92f669b52908de0744cb06bffcac3994",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": {
        "id": 14,
        "url": "https://patchwork.libcamera.org/api/users/14/?format=api",
        "username": "pinchartl",
        "first_name": "Laurent",
        "last_name": "Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/10658/mbox/",
    "series": [
        {
            "id": 1531,
            "url": "https://patchwork.libcamera.org/api/series/1531/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1531",
            "date": "2020-12-12T18:51:14",
            "name": "libcamera: Fix leaks and simplify object management with std::unique_ptr<>",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1531/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10658/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10658/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8C627BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 12 Dec 2020 18:51:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DC1E76034C;\n\tSat, 12 Dec 2020 19:51:30 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CAC56032B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 12 Dec 2020 19:51:28 +0100 (CET)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 75A4F4FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 12 Dec 2020 19:51:27 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Pqv5M8mI\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1607799087;\n\tbh=93iiYLrUABDfk9S9z7sBULHXCAtBFZ/vE4HvXpG+J9c=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Pqv5M8mIBQtAGc+VsYyJAnqkvbAsCntxQFdbk8e8N5njc5+fL+pK+v1Vm8RQzgGT6\n\t7HVQIfCOXgloET4TeIJtIVbagE8Za9W8DawM0DvT4GyZS646TW3EJSiPt9Gc4Z7lhu\n\t6QMZD8JmBgQnSWGNux27L6xhGmCGYh94gcJ3Btqw=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 12 Dec 2020 20:51:16 +0200",
        "Message-Id": "<20201212185116.29611-4-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20201212185116.29611-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20201212185116.29611-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH 3/3] libcamera: pipeline: Manage resources\n\twith std::unique_ptr<>",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Replace manual resource destruction with std::unique_ptr<> where\napplicable. This removes the need for several destructors.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/ipu3/cio2.cpp         | 11 ++---------\n src/libcamera/pipeline/ipu3/cio2.h           |  9 ++++-----\n src/libcamera/pipeline/rkisp1/rkisp1.cpp     | 19 +++++++------------\n src/libcamera/pipeline/simple/converter.cpp  |  8 +-------\n src/libcamera/pipeline/simple/converter.h    |  3 +--\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 12 ++++--------\n src/libcamera/pipeline/vimc/vimc.cpp         | 11 +++--------\n 7 files changed, 22 insertions(+), 51 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp\nindex 821715e325b4..bd5260d5b288 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.cpp\n+++ b/src/libcamera/pipeline/ipu3/cio2.cpp\n@@ -33,16 +33,9 @@ const std::map<uint32_t, PixelFormat> mbusCodesToPixelFormat = {\n } /* namespace */\n \n CIO2Device::CIO2Device()\n-\t: sensor_(nullptr), csi2_(nullptr)\n {\n }\n \n-CIO2Device::~CIO2Device()\n-{\n-\tdelete csi2_;\n-\tdelete sensor_;\n-}\n-\n /**\n  * \\brief Retrieve the list of supported PixelFormats\n  *\n@@ -117,7 +110,7 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \n \tMediaLink *link = links[0];\n \tMediaEntity *sensorEntity = link->source()->entity();\n-\tsensor_ = new CameraSensor(sensorEntity);\n+\tsensor_ = std::make_unique<CameraSensor>(sensorEntity);\n \tret = sensor_->init();\n \tif (ret)\n \t\treturn ret;\n@@ -148,7 +141,7 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \t * might impact on power consumption.\n \t */\n \n-\tcsi2_ = new V4L2Subdevice(csi2Entity);\n+\tcsi2_ = std::make_unique<V4L2Subdevice>(csi2Entity);\n \tret = csi2_->open();\n \tif (ret)\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h\nindex 0dca9673ca07..236ad287354a 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.h\n+++ b/src/libcamera/pipeline/ipu3/cio2.h\n@@ -33,7 +33,6 @@ public:\n \tstatic constexpr unsigned int CIO2_BUFFER_COUNT = 4;\n \n \tCIO2Device();\n-\t~CIO2Device();\n \n \tstd::vector<PixelFormat> formats() const;\n \tstd::vector<SizeRange> sizes() const;\n@@ -49,8 +48,8 @@ public:\n \tint start();\n \tint stop();\n \n-\tCameraSensor *sensor() { return sensor_; }\n-\tconst CameraSensor *sensor() const { return sensor_; }\n+\tCameraSensor *sensor() { return sensor_.get(); }\n+\tconst CameraSensor *sensor() const { return sensor_.get(); }\n \n \tint queueBuffer(Request *request, FrameBuffer *rawBuffer);\n \tvoid tryReturnBuffer(FrameBuffer *buffer);\n@@ -61,8 +60,8 @@ private:\n \n \tvoid cio2BufferReady(FrameBuffer *buffer);\n \n-\tCameraSensor *sensor_;\n-\tV4L2Subdevice *csi2_;\n+\tstd::unique_ptr<CameraSensor> sensor_;\n+\tstd::unique_ptr<V4L2Subdevice> csi2_;\n \tstd::unique_ptr<V4L2VideoDevice> output_;\n \n \tstd::vector<std::unique_ptr<FrameBuffer>> buffers_;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 4d98c9027f42..021d0ffe3ffb 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -121,21 +121,16 @@ class RkISP1CameraData : public CameraData\n public:\n \tRkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath,\n \t\t\t RkISP1SelfPath *selfPath)\n-\t\t: CameraData(pipe), sensor_(nullptr), frame_(0),\n-\t\t  frameInfo_(pipe), mainPath_(mainPath), selfPath_(selfPath)\n+\t\t: CameraData(pipe), frame_(0), frameInfo_(pipe),\n+\t\t  mainPath_(mainPath), selfPath_(selfPath)\n \t{\n \t}\n \n-\t~RkISP1CameraData()\n-\t{\n-\t\tdelete sensor_;\n-\t}\n-\n \tint loadIPA();\n \n \tStream mainPathStream_;\n \tStream selfPathStream_;\n-\tCameraSensor *sensor_;\n+\tstd::unique_ptr<CameraSensor> sensor_;\n \tunsigned int frame_;\n \tstd::vector<IPABuffer> ipaBuffers_;\n \tRkISP1Frames frameInfo_;\n@@ -430,7 +425,7 @@ void RkISP1CameraData::queueFrameAction(unsigned int frame,\n \tcase RKISP1_IPA_ACTION_V4L2_SET: {\n \t\tconst ControlList &controls = action.controls[0];\n \t\ttimeline_.scheduleAction(std::make_unique<RkISP1ActionSetSensor>(frame,\n-\t\t\t\t\t\t\t\t\t\t sensor_,\n+\t\t\t\t\t\t\t\t\t\t sensor_.get(),\n \t\t\t\t\t\t\t\t\t\t controls));\n \t\tbreak;\n \t}\n@@ -489,7 +484,7 @@ bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg)\n \n CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n {\n-\tconst CameraSensor *sensor = data_->sensor_;\n+\tconst CameraSensor *sensor = data_->sensor_.get();\n \tStatus status = Valid;\n \n \tif (config_.empty())\n@@ -660,7 +655,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \tRkISP1CameraConfiguration *config =\n \t\tstatic_cast<RkISP1CameraConfiguration *>(c);\n \tRkISP1CameraData *data = cameraData(camera);\n-\tCameraSensor *sensor = data->sensor_;\n+\tCameraSensor *sensor = data->sensor_.get();\n \tint ret;\n \n \tret = initLinks(camera, sensor, *config);\n@@ -1035,7 +1030,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n \n \tdata->controlInfo_ = std::move(ctrls);\n \n-\tdata->sensor_ = new CameraSensor(sensor);\n+\tdata->sensor_ = std::make_unique<CameraSensor>(sensor);\n \tret = data->sensor_->init();\n \tif (ret)\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp\nindex 67e6e864aa0a..a6a8e139cb3e 100644\n--- a/src/libcamera/pipeline/simple/converter.cpp\n+++ b/src/libcamera/pipeline/simple/converter.cpp\n@@ -24,7 +24,6 @@ namespace libcamera {\n LOG_DECLARE_CATEGORY(SimplePipeline)\n \n SimpleConverter::SimpleConverter(MediaDevice *media)\n-\t: m2m_(nullptr)\n {\n \t/*\n \t * Locate the video node. There's no need to validate the pipeline\n@@ -38,17 +37,12 @@ SimpleConverter::SimpleConverter(MediaDevice *media)\n \tif (it == entities.end())\n \t\treturn;\n \n-\tm2m_ = new V4L2M2MDevice((*it)->deviceNode());\n+\tm2m_ = std::make_unique<V4L2M2MDevice>((*it)->deviceNode());\n \n \tm2m_->output()->bufferReady.connect(this, &SimpleConverter::outputBufferReady);\n \tm2m_->capture()->bufferReady.connect(this, &SimpleConverter::captureBufferReady);\n }\n \n-SimpleConverter::~SimpleConverter()\n-{\n-\tdelete m2m_;\n-}\n-\n int SimpleConverter::open()\n {\n \tif (!m2m_)\ndiff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h\nindex 78296680aa14..a3c4d899cfc8 100644\n--- a/src/libcamera/pipeline/simple/converter.h\n+++ b/src/libcamera/pipeline/simple/converter.h\n@@ -29,7 +29,6 @@ class SimpleConverter\n {\n public:\n \tSimpleConverter(MediaDevice *media);\n-\t~SimpleConverter();\n \n \tint open();\n \tvoid close();\n@@ -56,7 +55,7 @@ private:\n \tvoid captureBufferReady(FrameBuffer *buffer);\n \tvoid outputBufferReady(FrameBuffer *buffer);\n \n-\tV4L2M2MDevice *m2m_;\n+\tstd::unique_ptr<V4L2M2MDevice> m2m_;\n \n \tstd::queue<FrameBuffer *> captureDoneQueue_;\n \tstd::queue<FrameBuffer *> outputDoneQueue_;\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 87b0f03d143a..e54f45bb8825 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -9,6 +9,7 @@\n #include <fstream>\n #include <iomanip>\n #include <math.h>\n+#include <memory>\n #include <tuple>\n \n #include <libcamera/camera.h>\n@@ -35,21 +36,16 @@ class UVCCameraData : public CameraData\n {\n public:\n \tUVCCameraData(PipelineHandler *pipe)\n-\t\t: CameraData(pipe), video_(nullptr)\n+\t\t: CameraData(pipe)\n \t{\n \t}\n \n-\t~UVCCameraData()\n-\t{\n-\t\tdelete video_;\n-\t}\n-\n \tint init(MediaDevice *media);\n \tvoid addControl(uint32_t cid, const ControlInfo &v4l2info,\n \t\t\tControlInfoMap::Map *ctrls);\n \tvoid bufferReady(FrameBuffer *buffer);\n \n-\tV4L2VideoDevice *video_;\n+\tstd::unique_ptr<V4L2VideoDevice> video_;\n \tStream stream_;\n };\n \n@@ -499,7 +495,7 @@ int UVCCameraData::init(MediaDevice *media)\n \t}\n \n \t/* Create and open the video device. */\n-\tvideo_ = new V4L2VideoDevice(*entity);\n+\tvideo_ = std::make_unique<V4L2VideoDevice>(*entity);\n \tret = video_->open();\n \tif (ret)\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 72256f5b4190..8bda746f3136 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -42,20 +42,15 @@ class VimcCameraData : public CameraData\n {\n public:\n \tVimcCameraData(PipelineHandler *pipe, MediaDevice *media)\n-\t\t: CameraData(pipe), media_(media), sensor_(nullptr)\n+\t\t: CameraData(pipe), media_(media)\n \t{\n \t}\n \n-\t~VimcCameraData()\n-\t{\n-\t\tdelete sensor_;\n-\t}\n-\n \tint init();\n \tvoid bufferReady(FrameBuffer *buffer);\n \n \tMediaDevice *media_;\n-\tCameraSensor *sensor_;\n+\tstd::unique_ptr<CameraSensor> sensor_;\n \tstd::unique_ptr<V4L2Subdevice> debayer_;\n \tstd::unique_ptr<V4L2Subdevice> scaler_;\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n@@ -461,7 +456,7 @@ int VimcCameraData::init()\n \t\treturn ret;\n \n \t/* Create and open the camera sensor, debayer, scaler and video device. */\n-\tsensor_ = new CameraSensor(media_->getEntityByName(\"Sensor B\"));\n+\tsensor_ = std::make_unique<CameraSensor>(media_->getEntityByName(\"Sensor B\"));\n \tret = sensor_->init();\n \tif (ret)\n \t\treturn ret;\n",
    "prefixes": [
        "libcamera-devel",
        "3/3"
    ]
}