[{"id":4033,"web_url":"https://patchwork.libcamera.org/comment/4033/","msgid":"<20200316155000.GI2260535@oden.dyn.berto.se>","date":"2020-03-16T15:50:00","subject":"Re: [libcamera-devel] [PATCH 9/9] libcamera: framebuffer_allocator:\n\tLift camera restrictions on allocator","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for this nice cleanup.\n\nOn 2020-03-15 01:57:28 +0200, Laurent Pinchart wrote:\n> The Camera class currently requires the allocator to have no allocated\n> buffer before the camera is reconfigured, and the allocator to be\n> destroyed before the camera is released. There's no basis for these\n> restrictions anymore, remove them.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  include/libcamera/camera.h                |  2 --\n>  include/libcamera/framebuffer_allocator.h |  5 +----\n>  src/cam/capture.cpp                       |  2 +-\n>  src/gstreamer/gstlibcameraallocator.cpp   |  2 +-\n>  src/libcamera/camera.cpp                  | 18 +---------------\n>  src/libcamera/framebuffer_allocator.cpp   | 25 -----------------------\n>  src/qcam/main_window.cpp                  |  2 +-\n>  src/v4l2/v4l2_camera.cpp                  |  2 +-\n>  test/camera/capture.cpp                   |  2 +-\n>  test/camera/statemachine.cpp              |  2 +-\n>  10 files changed, 8 insertions(+), 54 deletions(-)\n> \n> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\n> index a5e2b49f0f25..9c0e58f7864b 100644\n> --- a/include/libcamera/camera.h\n> +++ b/include/libcamera/camera.h\n> @@ -113,8 +113,6 @@ private:\n>  \tfriend class FrameBufferAllocator;\n>  \tint exportFrameBuffers(Stream *stream,\n>  \t\t\t       std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n> -\t/* \\todo Remove allocator_ from the exposed API */\n> -\tFrameBufferAllocator *allocator_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h\n> index 42812253ada9..78f1353964eb 100644\n> --- a/include/libcamera/framebuffer_allocator.h\n> +++ b/include/libcamera/framebuffer_allocator.h\n> @@ -20,8 +20,7 @@ class Stream;\n>  class FrameBufferAllocator\n>  {\n>  public:\n> -\tstatic FrameBufferAllocator *create(std::shared_ptr<Camera> camera);\n> -\n> +\tFrameBufferAllocator(std::shared_ptr<Camera> camera);\n>  \tFrameBufferAllocator(const Camera &) = delete;\n>  \tFrameBufferAllocator &operator=(const Camera &) = delete;\n>  \n> @@ -34,8 +33,6 @@ public:\n>  \tconst std::vector<std::unique_ptr<FrameBuffer>> &buffers(Stream *stream) const;\n>  \n>  private:\n> -\tFrameBufferAllocator(std::shared_ptr<Camera> camera);\n> -\n>  \tstd::shared_ptr<Camera> camera_;\n>  \tstd::map<Stream *, std::vector<std::unique_ptr<FrameBuffer>>> buffers_;\n>  };\n> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\n> index 7d970f991d3a..b62a9b24b216 100644\n> --- a/src/cam/capture.cpp\n> +++ b/src/cam/capture.cpp\n> @@ -52,7 +52,7 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)\n>  \t}\n>  \n>  \n> -\tFrameBufferAllocator *allocator = FrameBufferAllocator::create(camera_);\n> +\tFrameBufferAllocator *allocator = new FrameBufferAllocator(camera_);\n>  \n>  \tret = capture(loop, allocator);\n>  \n> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> index d0b90ecaa873..1d5959c076cb 100644\n> --- a/src/gstreamer/gstlibcameraallocator.cpp\n> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> @@ -188,7 +188,7 @@ gst_libcamera_allocator_new(std::shared_ptr<Camera> camera)\n>  \tauto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n>  \t\t\t\t\t\t\t  nullptr));\n>  \n> -\tself->fb_allocator = FrameBufferAllocator::create(camera);\n> +\tself->fb_allocator = new FrameBufferAllocator(camera);\n>  \tfor (Stream *stream : camera->streams()) {\n>  \t\tgint ret;\n>  \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 5593c1b317a0..8c3bb2c2a01f 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -508,7 +508,7 @@ const std::string &Camera::name() const\n>  \n>  Camera::Camera(PipelineHandler *pipe, const std::string &name,\n>  \t       const std::set<Stream *> &streams)\n> -\t: p_(new Private(pipe, name, streams)), allocator_(nullptr)\n> +\t: p_(new Private(pipe, name, streams))\n>  {\n>  }\n>  \n> @@ -620,16 +620,6 @@ int Camera::release()\n>  \tif (ret < 0)\n>  \t\treturn ret == -EACCES ? -EBUSY : ret;\n>  \n> -\tif (allocator_) {\n> -\t\t/*\n> -\t\t * \\todo Try to find a better API that would make this error\n> -\t\t * impossible.\n> -\t\t */\n> -\t\tLOG(Camera, Error)\n> -\t\t\t<< \"Buffers must be freed before the camera can be reconfigured\";\n> -\t\treturn -EBUSY;\n> -\t}\n> -\n>  \tp_->pipe_->unlock();\n>  \n>  \tp_->setState(Private::CameraAvailable);\n> @@ -763,12 +753,6 @@ int Camera::configure(CameraConfiguration *config)\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> -\tif (allocator_ && allocator_->allocated()) {\n> -\t\tLOG(Camera, Error)\n> -\t\t\t<< \"Allocator must be deleted before camera can be reconfigured\";\n> -\t\treturn -EBUSY;\n> -\t}\n> -\n>  \tif (config->validate() != CameraConfiguration::Valid) {\n>  \t\tLOG(Camera, Error)\n>  \t\t\t<< \"Can't configure camera with invalid configuration\";\n> diff --git a/src/libcamera/framebuffer_allocator.cpp b/src/libcamera/framebuffer_allocator.cpp\n> index 6f7a2e90b08a..a37b564c6701 100644\n> --- a/src/libcamera/framebuffer_allocator.cpp\n> +++ b/src/libcamera/framebuffer_allocator.cpp\n> @@ -53,29 +53,6 @@ LOG_DEFINE_CATEGORY(Allocator)\n>   * are provided externally applications shall not use this class.\n>   */\n>  \n> -/**\n> - * \\brief Create a FrameBuffer allocator\n> - * \\param[in] camera The camera the allocator serves\n> - *\n> - * A single allocator may be created for a Camera instance.\n> - *\n> - * The caller is responsible for deleting the allocator before the camera is\n> - * released.\n> - *\n> - * \\return A pointer to the newly created allocator object or nullptr on error\n> - */\n> -FrameBufferAllocator *\n> -FrameBufferAllocator::create(std::shared_ptr<Camera> camera)\n> -{\n> -\tif (camera->allocator_) {\n> -\t\tLOG(Allocator, Error) << \"Camera already has an allocator\";\n> -\t\treturn nullptr;\n> -\t}\n> -\n> -\tcamera->allocator_ = new FrameBufferAllocator(camera);\n> -\treturn camera->allocator_;\n> -}\n> -\n>  /**\n>   * \\brief Construct a FrameBufferAllocator serving a camera\n>   * \\param[in] camera The camera\n> @@ -88,8 +65,6 @@ FrameBufferAllocator::FrameBufferAllocator(std::shared_ptr<Camera> camera)\n>  FrameBufferAllocator::~FrameBufferAllocator()\n>  {\n>  \tbuffers_.clear();\n> -\n> -\tcamera_->allocator_ = nullptr;\n>  }\n>  \n>  /**\n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index ae1760dfd647..47d37c3e62ce 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -240,7 +240,7 @@ int MainWindow::startCapture()\n>  \n>  \tadjustSize();\n>  \n> -\tallocator_ = FrameBufferAllocator::create(camera_);\n> +\tallocator_ = new FrameBufferAllocator(camera_);\n>  \tret = allocator_->allocate(stream);\n>  \tif (ret < 0) {\n>  \t\tstd::cerr << \"Failed to allocate capture buffers\" << std::endl;\n> diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp\n> index e7018b566475..f0b9f1804c94 100644\n> --- a/src/v4l2/v4l2_camera.cpp\n> +++ b/src/v4l2/v4l2_camera.cpp\n> @@ -40,7 +40,7 @@ int V4L2Camera::open()\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> -\tbufferAllocator_ = FrameBufferAllocator::create(camera_);\n> +\tbufferAllocator_ = new FrameBufferAllocator(camera_);\n>  \n>  \treturn 0;\n>  }\n> diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp\n> index b304d59c1c2a..f6b2f348bda5 100644\n> --- a/test/camera/capture.cpp\n> +++ b/test/camera/capture.cpp\n> @@ -63,7 +63,7 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> -\t\tallocator_ = FrameBufferAllocator::create(camera_);\n> +\t\tallocator_ = new FrameBufferAllocator(camera_);\n>  \n>  \t\treturn TestPass;\n>  \t}\n> diff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp\n> index 20541b3e4752..325b4674bcc9 100644\n> --- a/test/camera/statemachine.cpp\n> +++ b/test/camera/statemachine.cpp\n> @@ -117,7 +117,7 @@ protected:\n>  \t\t\treturn TestFail;\n>  \n>  \t\t/* Use internally allocated buffers. */\n> -\t\tallocator_ = FrameBufferAllocator::create(camera_);\n> +\t\tallocator_ = new FrameBufferAllocator(camera_);\n>  \t\tStream *stream = *camera_->streams().begin();\n>  \t\tif (allocator_->allocate(stream) < 0)\n>  \t\t\treturn TestFail;\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \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-x12b.google.com (mail-lf1-x12b.google.com\n\t[IPv6:2a00:1450:4864:20::12b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E098F6041A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 16:50:01 +0100 (CET)","by mail-lf1-x12b.google.com with SMTP id s1so14488863lfd.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 08:50:01 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\t203sm122704ljf.65.2020.03.16.08.50.00\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 16 Mar 2020 08:50:00 -0700 (PDT)"],"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\tbh=eR7unUOEKdoQEnHeGJmh+LldDlKXuU9vHzEU0FcHSJA=;\n\tb=H5NI3gyiiVv06+wdZbJ76AkCKcOkgOtEcFy5VqofBahxEwKWJ6SogkDSIXVqglhBpY\n\trUwBI2Nqo+5c++yNJkMiXXvQeU/8HAxZBsSq0Av6mOV7pQ4uYLtEYXl1UaJvWUYjtbvJ\n\t1GlQlJW5jjQ/8e4W2I670c8sUuwd81FNUpSILNqJwadrLzZG3++zmCaQVyqa0PMyWnU1\n\t4ElbcDw4oOXdhrnO38aiGo4tydmlZavfIkjj9sG04EtHWHG6vUjsfuNDCRn0bzEO6ziY\n\tXtevgNpCF/v4/ba6v9qm2A3PetqS+1LMIbl1ZENwpZYEQvOox2X2N991caSFB5IBGTzV\n\tDQRQ==","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;\n\tbh=eR7unUOEKdoQEnHeGJmh+LldDlKXuU9vHzEU0FcHSJA=;\n\tb=MJyTquWNUXGmteiUKXYdUoJgERwLVVMtysyV67ff92HeQBaPykgpETJfFtGnQ+UlWt\n\t789buGJxDtXQPbMqdqDbYDCwR+6LPOdDKH9rAyCIf54Ho4J12tkMFEXhok+RgEv+evIv\n\tSvL7GH2UN9xHHJxbMixMzOqh0spcrM7Hi3PN/2yfXs7DVEEGohksXZ2nyLlrCtNQeFLf\n\tlnOS0OEQU+1czpG3fnN59aBxsQQ8J3IXzWTlaC+ZgDpWp48obLcA/oeSegv9ajr1B4kW\n\tWherUozW5jsiWLx0O29o64lgm8zBCKDr0qL+t0ErgX5YEqe4s3Cxjgmm9IiRcNnMFjmv\n\tgH0Q==","X-Gm-Message-State":"ANhLgQ1h4NbX0UgRu3KSITnv7IXdlgcg9QjRapGlQYurBZpN0kSczZnj\n\tUcR+QF5hF93ztjWfLmRcPqdQtg==","X-Google-Smtp-Source":"ADFU+vv4DeyoswB0nVNTv95NBjhowzrXC+GlM1bJPvWFvAsQFyu3AXbfIQBRoVwWv31TVW0V0IUunA==","X-Received":"by 2002:a05:6512:3044:: with SMTP id\n\tb4mr55077lfb.10.1584373801154; \n\tMon, 16 Mar 2020 08:50:01 -0700 (PDT)","Date":"Mon, 16 Mar 2020 16:50:00 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200316155000.GI2260535@oden.dyn.berto.se>","References":"<20200314235728.15495-1-laurent.pinchart@ideasonboard.com>\n\t<20200314235728.15495-10-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200314235728.15495-10-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 9/9] libcamera: framebuffer_allocator:\n\tLift camera restrictions on allocator","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>","X-List-Received-Date":"Mon, 16 Mar 2020 15:50:02 -0000"}}]