[{"id":27433,"web_url":"https://patchwork.libcamera.org/comment/27433/","msgid":"<f35443b33e730a5772ac1cd2b002638be62a6876.camel@ndufresne.ca>","date":"2023-06-28T14:29:01","subject":"Re: [libcamera-devel] [PATCH] gstreamer: Drop libcamera_private\n\tdependency","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/people/30/","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"content":"Hi,\n\nLe mardi 27 juin 2023 à 13:52 +0200, Umang Jain a écrit :\n> Drop libcamera_private dependency entirely as to avoid libcamerasrc\n> getting more dependent on it. In order to achieve that, one of the\n> mutex locks in GstLibcameraSrcState needs to be replaced with GMutex.\n> \n> However doing so, this won't let us to use the clang's thread annotation\n> macros in libcamera (which should be fine as libcamerasrc would move\n> out of libcamera repo once matured).\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\n> ---\n>  src/gstreamer/gstlibcamerasrc.cpp | 23 +++++++++++------------\n>  src/gstreamer/meson.build         |  2 +-\n>  2 files changed, 12 insertions(+), 13 deletions(-)\n> \n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index 11f15068..b5c6e9ab 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -32,8 +32,6 @@\n>  #include <queue>\n>  #include <vector>\n>  \n> -#include <libcamera/base/mutex.h>\n> -\n>  #include <libcamera/camera.h>\n>  #include <libcamera/camera_manager.h>\n>  #include <libcamera/control_ids.h>\n> @@ -125,11 +123,9 @@ struct GstLibcameraSrcState {\n>  \t * be held while calling into other graph elements (e.g. when calling\n>  \t * gst_pad_query()).\n>  \t */\n> -\tMutex lock_;\n> -\tstd::queue<std::unique_ptr<RequestWrap>> queuedRequests_\n> -\t\tLIBCAMERA_TSA_GUARDED_BY(lock_);\n> -\tstd::queue<std::unique_ptr<RequestWrap>> completedRequests_\n> -\t\tLIBCAMERA_TSA_GUARDED_BY(lock_);\n> +\tGMutex lock_;\n> +\tstd::queue<std::unique_ptr<RequestWrap>> queuedRequests_;\n> +\tstd::queue<std::unique_ptr<RequestWrap>> completedRequests_;\n>  \n>  \tControlList initControls_;\n>  \tguint group_id_;\n> @@ -208,7 +204,7 @@ int GstLibcameraSrcState::queueRequest()\n>  \tcam_->queueRequest(wrap->request_.get());\n>  \n>  \t{\n> -\t\tMutexLocker locker(lock_);\n> +\t\tGLibLocker locker(&lock_);\n>  \t\tqueuedRequests_.push(std::move(wrap));\n>  \t}\n>  \n> @@ -224,7 +220,7 @@ GstLibcameraSrcState::requestCompleted(Request *request)\n>  \tstd::unique_ptr<RequestWrap> wrap;\n>  \n>  \t{\n> -\t\tMutexLocker locker(lock_);\n> +\t\tGLibLocker locker(&lock_);\n>  \t\twrap = std::move(queuedRequests_.front());\n>  \t\tqueuedRequests_.pop();\n>  \t}\n> @@ -251,7 +247,7 @@ GstLibcameraSrcState::requestCompleted(Request *request)\n>  \t}\n>  \n>  \t{\n> -\t\tMutexLocker locker(lock_);\n> +\t\tGLibLocker locker(&lock_);\n>  \t\tcompletedRequests_.push(std::move(wrap));\n>  \t}\n>  \n> @@ -265,7 +261,7 @@ int GstLibcameraSrcState::processRequest()\n>  \tint err = 0;\n>  \n>  \t{\n> -\t\tMutexLocker locker(lock_);\n> +\t\tGLibLocker locker(&lock_);\n>  \n>  \t\tif (!completedRequests_.empty()) {\n>  \t\t\twrap = std::move(completedRequests_.front());\n> @@ -639,7 +635,7 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task,\n>  \tstate->cam_->stop();\n>  \n>  \t{\n> -\t\tMutexLocker locker(state->lock_);\n> +\t\tGLibLocker locker(&state->lock_);\n>  \t\tstate->completedRequests_ = {};\n>  \t}\n>  \n> @@ -776,6 +772,7 @@ gst_libcamera_src_finalize(GObject *object)\n>  \n>  \tg_rec_mutex_clear(&self->stream_lock);\n>  \tg_clear_object(&self->task);\n> +\tg_mutex_clear(&self->state->lock_);\n>  \tg_free(self->camera_name);\n>  \tdelete self->controls;\n>  \tdelete self->state;\n> @@ -795,6 +792,8 @@ gst_libcamera_src_init(GstLibcameraSrc *self)\n>  \tgst_task_set_leave_callback(self->task, gst_libcamera_src_task_leave, self, nullptr);\n>  \tgst_task_set_lock(self->task, &self->stream_lock);\n>  \n> +\tg_mutex_init(&state->lock_);\n> +\n>  \tstate->srcpads_.push_back(gst_pad_new_from_template(templ, \"src\"));\n>  \tgst_element_add_pad(GST_ELEMENT(self), state->srcpads_.back());\n>  \n> diff --git a/src/gstreamer/meson.build b/src/gstreamer/meson.build\n> index eda246d7..77c79140 100644\n> --- a/src/gstreamer/meson.build\n> +++ b/src/gstreamer/meson.build\n> @@ -42,7 +42,7 @@ endif\n>  libcamera_gst = shared_library('gstlibcamera',\n>      libcamera_gst_sources,\n>      cpp_args : libcamera_gst_cpp_args,\n> -    dependencies : [libcamera_private, gstvideo_dep, gstallocator_dep],\n> +    dependencies : [libcamera_public, gstvideo_dep, gstallocator_dep],\n>      install: true,\n>      install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')),\n>  )","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 EBC10BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jun 2023 14:29:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3A435628C1;\n\tWed, 28 Jun 2023 16:29:05 +0200 (CEST)","from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com\n\t[IPv6:2607:f8b0:4864:20::22b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CD207628BC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jun 2023 16:29:03 +0200 (CEST)","by mail-oi1-x22b.google.com with SMTP id\n\t5614622812f47-3a04e5baffcso5126997b6e.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jun 2023 07:29:03 -0700 (PDT)","from nicolas-tpx395.localdomain ([2606:6d00:15:c623::7a9])\n\tby smtp.gmail.com with ESMTPSA id\n\tev14-20020a0562140a8e00b00631fea4d5c2sm5806245qvb.98.2023.06.28.07.29.01\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 28 Jun 2023 07:29:02 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687962545;\n\tbh=TsZ3e4cxnBffNLhdFv+jJznMjeacmqZRfBc+NOEYwwY=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=ZnEW6/cdMbLN03tD/TQXitoxaUSLUKnti5SKQ1r//V4SXtVqQosdipESDRn/kgy7J\n\tq4y76nMvYb9uXz5uJzBkYBpXJ3yO1Gzg/zeXSiqHTTASCxtSKyX3MFCINGqVLdMocp\n\t0vNN6YiOPx4V/JxP1EJ1UZb841+Y09B2q9e88L58xwa5kMrxCGHBIiLp18cIhzPQ0E\n\t4/5hTnjgq4F0feOVnmJC+xzPQ1NmmXXThh2If0Ba9mmy7ck9pHXPEsDA+y6QYi8UXU\n\tFr47olhBqOu9Q1rrZrA7hnoUEt42p8Nhnd8I7rjndaDxCEtJ9jm64AqCVGDg6kXZ7G\n\tPwc8Pt5Q+881w==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ndufresne-ca.20221208.gappssmtp.com; s=20221208; t=1687962542;\n\tx=1690554542; \n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=PB435IFffHe60xWXwsO3JbgvxOYohgIWkfj3RnJk4Fc=;\n\tb=LgHXa1OaOkm6E0H0hlxNvcjrxySxOLVjgngbnlrbEuN2OXb/+CBIP8DyUvc7c/a3AC\n\tIr9jwBhzncUB1SASI4CktyuZeYE8H/0PXk6l3/qvunrPKYE3YUCgY4ziR54IlhhRB93z\n\tRjeZmXayuA9BLZGbTXQQGKohXHKn2z0tla5+w9Oq0a14aNsS310hQe0w3eIsHEiOirbW\n\tgW8/d/7HbGTBcqf6Rq0ShbmX9oRs4kwDYIDarJkAPTKdJ/LVKsGIzuzHU3TcYWtZYDtb\n\tSA3Iqf1JOkO3P1bl6SBQXuduKBtytHKitvBdprH9WL2xGOS1tTHOPTuxNKAsATWBAUuy\n\tUftQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ndufresne-ca.20221208.gappssmtp.com\n\theader.i=@ndufresne-ca.20221208.gappssmtp.com header.b=\"LgHXa1Oa\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1687962542; x=1690554542;\n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=PB435IFffHe60xWXwsO3JbgvxOYohgIWkfj3RnJk4Fc=;\n\tb=MfTDAbiJnSLUgUgm1pMZ1ZKzI2ntyCbcXzbqJSQFYcwvzsdmzB2AUM3kXYnTatphEL\n\toCdQgHgfvF90+NL85KDYKjnyPdxBWvkc/g+buP0Qv3KnQNxlRaSyak5G8WIVj0plK1IX\n\tu5YyS7raNfjf8EYTRCjNO4j/gpq+Sk7oGt2KvLNDvHWP2BDsYgXdRZ4bVb1kaOn4HjvT\n\tGJTqGF5IcW55WTTsZ/A080iRbQWZkn0G2EFsfWc8Nuj4TiKNlUUIVcPLh/16MSmFhgM3\n\twAa9AbJp9Zn8WlIaEWOHhdtSsriPIvZm5xAqOQzfIYiwXuXo66EVPrLQVDSbv6cGmufi\n\t/M6g==","X-Gm-Message-State":"AC+VfDzBrsztscANQDVdxE1rL14w4CCM2VRh9zQjoagUKoX/lXcKMCll\n\tsXPrCrVeT+hlkhl8np42hdKL5A==","X-Google-Smtp-Source":"ACHHUZ6NMslSaru5Utj/2TyB6K5MbOSoXlgE+onmO9wNQOoPjx8SKfP1r0/2wWFYUzwXXcDkgiaQYQ==","X-Received":"by 2002:a05:6808:494:b0:3a1:f237:ec62 with SMTP id\n\tz20-20020a056808049400b003a1f237ec62mr5832897oid.48.1687962542563; \n\tWed, 28 Jun 2023 07:29:02 -0700 (PDT)","Message-ID":"<f35443b33e730a5772ac1cd2b002638be62a6876.camel@ndufresne.ca>","To":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 28 Jun 2023 10:29:01 -0400","In-Reply-To":"<20230627115221.121279-1-umang.jain@ideasonboard.com>","References":"<20230627115221.121279-1-umang.jain@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.48.3 (3.48.3-1.fc38) ","MIME-Version":"1.0","Subject":"Re: [libcamera-devel] [PATCH] gstreamer: Drop libcamera_private\n\tdependency","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>","From":"Nicolas Dufresne via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]