From patchwork Sun Oct 27 20:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2232 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8FDCD6017A for ; Sun, 27 Oct 2019 21:31:48 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 456EEC0005; Sun, 27 Oct 2019 20:31:48 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:30 +0100 Message-Id: <20191027203335.26888-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/6] libcamera: object: Define message invocation type X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Oct 2019 20:31:48 -0000 Define an enumeration of invocation types to be used to describe the delivery method of messages through the Object::invokeMethod operation. Signed-off-by: Jacopo Mondi --- include/libcamera/object.h | 7 +++++++ src/libcamera/object.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 3308330af857..017d3f8aa915 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -21,6 +21,13 @@ class Signal; class SignalBase; class Thread; +enum InvocationType { + InvocationTypeAuto, + InvocationTypeDirect, + InvocationTypeQueued, + InvocationTypeBlocking, +}; + class Object { public: diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index 98aa0af2f9b9..82df3893d052 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -25,6 +25,33 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Object) +/** + * \enum InvocationType + * \brief Method invocation type + * + * This enumeration describes the possible methods invocation types + * that can be used to invoke methods on an Object running in a different + * execution context. + * + * Method invocation is performed by appending an InvokeMessage message to the + * receiver's message queue. This enumeration defines how the caller behaves + * once the message has been delivered to the receiver's queue. + * + * \var InvocationType::InvocationTypeAuto + * \brief === I'm not sure how we would use this for method invocation === + * + * \var InvocationType::InvocationTypeDirect + * \brief === I'm not sure how we would use this for method invocation === + * + * \var InvocationType::InvocationTypeQueued + * \brief The method is invoked on the Object and the caller immediately returns + * as soon as the message is queued to the receiver's message queue + * + * \var InvocationType::InvocationTypeBlocking + * \brief The method is invoked on the Object and the caller is blocked until + * the called method is not executed + */ + /** * \class Object * \brief Base object to support automatic signal disconnection From patchwork Sun Oct 27 20:33:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2233 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 225886017C for ; Sun, 27 Oct 2019 21:31:49 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id B3F46C0002; Sun, 27 Oct 2019 20:31:48 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:31 +0100 Message-Id: <20191027203335.26888-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/6] libcamera: object: Invoke method with invokeType X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Oct 2019 20:31:49 -0000 Add the method invocation type to Object::invokeMethod() operation. The additional type parameter will be used when delivering InvokeMessages and decide if the caller should block waiting for reception or the message or return immediately. Signed-off-by: Jacopo Mondi --- include/libcamera/object.h | 6 +++--- src/android/camera_proxy.cpp | 3 ++- src/libcamera/event_notifier.cpp | 3 ++- src/libcamera/object.cpp | 5 +++-- src/libcamera/timer.cpp | 2 +- test/object-invoke.cpp | 5 +++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 017d3f8aa915..be07611c25c6 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -37,13 +37,13 @@ public: void postMessage(std::unique_ptr msg); template::value>::type * = nullptr> - void invokeMethod(void (T::*func)(Args...), Args... args) + void invokeMethod(void (T::*func)(Args...), InvocationType type, Args... args) { T *obj = static_cast(this); BoundMethodBase *method = new BoundMemberMethod(obj, this, func); void *pack = new typename BoundMemberMethod::PackType{ args... }; - invokeMethod(method, pack); + invokeMethod(method, type, pack); } Thread *thread() const { return thread_; } @@ -60,7 +60,7 @@ private: friend class BoundMethodBase; friend class Thread; - void invokeMethod(BoundMethodBase *method, void *pack); + void invokeMethod(BoundMethodBase *method, InvocationType type, void *pack); void notifyThreadMove(); diff --git a/src/android/camera_proxy.cpp b/src/android/camera_proxy.cpp index 4f5c0a024903..5f8428cfddfb 100644 --- a/src/android/camera_proxy.cpp +++ b/src/android/camera_proxy.cpp @@ -187,6 +187,7 @@ int CameraProxy::processCaptureRequest(camera3_capture_request_t *request) void CameraProxy::threadRpcCall(ThreadRpc &rpcRequest) { - cameraDevice_->invokeMethod(&CameraDevice::call, &rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::call, InvocationTypeQueued, + &rpcRequest); rpcRequest.waitDelivery(); } diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp index 687969b0a8d1..75456b4bb15e 100644 --- a/src/libcamera/event_notifier.cpp +++ b/src/libcamera/event_notifier.cpp @@ -128,7 +128,8 @@ void EventNotifier::message(Message *msg) if (msg->type() == Message::ThreadMoveMessage) { if (enabled_) { setEnabled(false); - invokeMethod(&EventNotifier::setEnabled, true); + invokeMethod(&EventNotifier::setEnabled, + InvocationTypeAuto, true); } } diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index 82df3893d052..d7c9ac970d1c 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -160,9 +160,10 @@ void Object::message(Message *msg) } /** - * \fn void Object::invokeMethod(void (T::*func)(Args...), Args... args) + * \fn void Object::invokeMethod(void (T::*func)(Args...), InvocationType type, Args... args) * \brief Invoke a method asynchronously on an Object instance * \param[in] func The object method to invoke + * \param[in] type The method invocation type * \param[in] args The method arguments * * This method invokes the member method \a func when control returns to the @@ -174,7 +175,7 @@ void Object::message(Message *msg) * remains valid until the method is invoked. */ -void Object::invokeMethod(BoundMethodBase *method, void *args) +void Object::invokeMethod(BoundMethodBase *method, InvocationType type, void *args) { std::unique_ptr msg = utils::make_unique(method, args, true); diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index ddb20954afa7..177fc24209ff 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -170,7 +170,7 @@ void Timer::message(Message *msg) if (msg->type() == Message::ThreadMoveMessage) { if (isRunning()) { unregisterTimer(); - invokeMethod(&Timer::registerTimer); + invokeMethod(&Timer::registerTimer, InvocationTypeAuto); } } diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 37a274402e6d..6e0e24b146f0 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -67,7 +67,7 @@ protected: * Test that method invocation in the same thread goes through * the event dispatcher. */ - object.invokeMethod(&InvokedObject::method, 42); + object.invokeMethod(&InvokedObject::method, InvocationTypeAuto, 42); if (object.status() != InvokedObject::NoCall) { cerr << "Method not invoked asynchronously" << endl; @@ -101,7 +101,8 @@ protected: thread_.start(); - object.invokeMethod(&InvokedObject::method, 42); + object.invokeMethod(&InvokedObject::method, + InvocationTypeAuto, 42); this_thread::sleep_for(chrono::milliseconds(100)); switch (object.status()) { From patchwork Sun Oct 27 20:33:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2234 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A17A61509 for ; Sun, 27 Oct 2019 21:31:49 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 3F71DC0006; Sun, 27 Oct 2019 20:31:49 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:32 +0100 Message-Id: <20191027203335.26888-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/6] libcamera: object: Add ObjectConditionVariable class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Oct 2019 20:31:50 -0000 Add ObjectConditionVariable class that implements an Object synchronization primitive used to synchronize message delivery between Object running in different execution contexts. Signed-off-by: Jacopo Mondi --- include/libcamera/object.h | 19 ++++++++++++++++ src/libcamera/object.cpp | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index be07611c25c6..c6477f18417d 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -7,8 +7,10 @@ #ifndef __LIBCAMERA_OBJECT_H__ #define __LIBCAMERA_OBJECT_H__ +#include #include #include +#include #include #include @@ -28,6 +30,23 @@ enum InvocationType { InvocationTypeBlocking, }; +class ObjectConditionVariable +{ +public: + ObjectConditionVariable() + : delivered_(false) + { + } + + void notifyReception(); + void waitDelivery(); + +private: + std::condition_variable cv_; + std::mutex mutex_; + bool delivered_; +}; + class Object { public: diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index d7c9ac970d1c..88054aba3454 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -52,6 +52,52 @@ LOG_DEFINE_CATEGORY(Object) * the called method is not executed */ +/** + * \class ObjectConditionVariable + * \brief Object synchronization primitive that wraps a std::condition_variable + * + * The ObjectConditionVariable class provides an object synchronization + * primitive to synchronize Object running in different execution context. + * + * It wraps an std::condition_variable that protects a shared variable. + * + * The class is used to implement blocking message delivery between Object + * instances running in different execution context. + */ + +/** + * \fn ObjectConditionVariable::ObjectConditionVariable() + * \brief Create an ObjectConditionVariable with the shared variable initialized + * to false + */ + +/** + * \brief Notify the ObjectConditionVariable to signal message reception + */ +void ObjectConditionVariable::notifyReception() +{ + { + MutexLocker locker(mutex_); + delivered_ = true; + } + cv_.notify_one(); +} + +/** + * \brief Wait for the ObjectConditionVariable to be signaled + * + * Wait for the ObjectConditionVariable to be signaled by suspending the Object + * on the wrapped std::condition_variable. If the shared condition + * variable has already been set to true by the Object that was meant to + * signal the ObjectConditionVariable before waitDelivery() is invoked, + * the operation returns immediately. + */ +void ObjectConditionVariable::waitDelivery() +{ + MutexLocker locker(mutex_); + cv_.wait(locker, [&] { return delivered_; }); +} + /** * \class Object * \brief Base object to support automatic signal disconnection From patchwork Sun Oct 27 20:33:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2235 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EC1F46017A for ; Sun, 27 Oct 2019 21:31:49 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id A4438C0002; Sun, 27 Oct 2019 20:31:49 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:33 +0100 Message-Id: <20191027203335.26888-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/6] libcamera: Support blocking method invocation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Oct 2019 20:31:51 -0000 Add support for blocking method invocation by providing a conditional variable to the InvokeMessage class operation and have the Object::invokeMethod() caller operation to wait on the conditional variable if the message invocationType is InvocationTypeBlocking. Signed-off-by: Jacopo Mondi --- src/libcamera/include/message.h | 5 +++++ src/libcamera/message.cpp | 11 +++++++++-- src/libcamera/object.cpp | 14 +++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h index 1cfde5669ede..cfb674adbccb 100644 --- a/src/libcamera/include/message.h +++ b/src/libcamera/include/message.h @@ -10,6 +10,7 @@ #include #include +#include namespace libcamera { @@ -48,14 +49,18 @@ class InvokeMessage : public Message { public: InvokeMessage(BoundMethodBase *method, void *pack, + ObjectConditionVariable *cond = nullptr, bool deleteMethod = false); ~InvokeMessage(); + ObjectConditionVariable *cond() const { return cond_; } + void invoke(); private: BoundMethodBase *method_; void *pack_; + ObjectConditionVariable *cond_; bool deleteMethod_; }; diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp index efafb655c17e..865404e81cfb 100644 --- a/src/libcamera/message.cpp +++ b/src/libcamera/message.cpp @@ -119,13 +119,14 @@ Message::Type Message::registerMessageType() * \brief Construct an InvokeMessage for method invocation on an Object * \param[in] method The bound method * \param[in] pack The packed method arguments + * \param[in] cond The condition variable used to signal reception of the message * \param[in] deleteMethod True to delete the \a method when the message is * destroyed */ InvokeMessage::InvokeMessage(BoundMethodBase *method, void *pack, - bool deleteMethod) + ObjectConditionVariable *cond, bool deleteMethod) : Message(Message::InvokeMessage), method_(method), pack_(pack), - deleteMethod_(deleteMethod) + cond_(cond), deleteMethod_(deleteMethod) { } @@ -135,6 +136,12 @@ InvokeMessage::~InvokeMessage() delete method_; } +/** + * \fn InvokeMessage::cond() + * \brief Retrieve the synchronization condition variable + * \return The ObjectConditionVariable + */ + /** * \brief Invoke the method bound to InvokeMessage::method_ with arguments * InvokeMessage::pack_ diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index 88054aba3454..ee6f5efc984c 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -196,7 +196,12 @@ void Object::message(Message *msg) switch (msg->type()) { case Message::InvokeMessage: { InvokeMessage *iMsg = static_cast(msg); + ObjectConditionVariable *cond = iMsg->cond(); iMsg->invoke(); + + if (cond) + cond->notifyReception(); + break; } @@ -223,9 +228,16 @@ void Object::message(Message *msg) void Object::invokeMethod(BoundMethodBase *method, InvocationType type, void *args) { + ObjectConditionVariable cond; + ObjectConditionVariable *c = type == InvocationTypeBlocking ? + &cond : nullptr; + std::unique_ptr msg = - utils::make_unique(method, args, true); + utils::make_unique(method, args, c, true); postMessage(std::move(msg)); + + if (c) + c->waitDelivery(); } /** From patchwork Sun Oct 27 20:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2236 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6D6F46017C for ; Sun, 27 Oct 2019 21:31:50 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 0DA00C0005; Sun, 27 Oct 2019 20:31:49 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:34 +0100 Message-Id: <20191027203335.26888-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/6] test: object-invoke: invoke method in blocking mode X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Oct 2019 20:31:51 -0000 Change the object-invoke test to perform the second method invocation operation in blocking mode. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- test/object-invoke.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 6e0e24b146f0..4ae8c91ab7f0 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -102,8 +102,7 @@ protected: thread_.start(); object.invokeMethod(&InvokedObject::method, - InvocationTypeAuto, 42); - this_thread::sleep_for(chrono::milliseconds(100)); + InvocationTypeBlocking, 42); switch (object.status()) { case InvokedObject::NoCall: From patchwork Sun Oct 27 20:33:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2237 Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D3AF16150A for ; Sun, 27 Oct 2019 21:31:50 +0100 (CET) X-Originating-IP: 93.2.121.143 Received: from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 84EB1C0007; Sun, 27 Oct 2019 20:31:50 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 27 Oct 2019 21:33:35 +0100 Message-Id: <20191027203335.26888-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203335.26888-1-jacopo@jmondi.org> References: <20191027203335.26888-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/6] android: Replace ThreadRPC with blocking method call X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Oct 2019 20:31:51 -0000 Use the newly introduced InvocationTypeBlocking message type to replace the blocking message delivery implemented with the ThreadRPC class in the Android camera HAL. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 34 ++++++------------------------ src/android/camera_device.h | 5 +---- src/android/camera_proxy.cpp | 21 ++++--------------- src/android/camera_proxy.h | 3 --- src/android/meson.build | 1 - src/android/thread_rpc.cpp | 26 ----------------------- src/android/thread_rpc.h | 39 ----------------------------------- 7 files changed, 11 insertions(+), 118 deletions(-) delete mode 100644 src/android/thread_rpc.cpp delete mode 100644 src/android/thread_rpc.h diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c7c9b3fd1724..897f545864a9 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -11,7 +11,6 @@ #include "utils.h" #include "camera_metadata.h" -#include "thread_rpc.h" using namespace libcamera; @@ -64,25 +63,6 @@ CameraDevice::~CameraDevice() delete it.second; } -/* - * Handle RPC request received from the associated proxy. - */ -void CameraDevice::call(ThreadRpc *rpc) -{ - switch (rpc->tag) { - case ThreadRpc::ProcessCaptureRequest: - processCaptureRequest(rpc->request); - break; - case ThreadRpc::Close: - close(); - break; - default: - LOG(HAL, Error) << "Unknown RPC operation: " << rpc->tag; - } - - rpc->notifyReception(); -} - int CameraDevice::open() { int ret = camera_->acquire(); @@ -698,7 +678,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) +void CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { StreamConfiguration *streamConfiguration = &config_->at(0); Stream *stream = streamConfiguration->stream(); @@ -706,7 +686,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques if (camera3Request->num_output_buffers != 1) { LOG(HAL, Error) << "Invalid number of output buffers: " << camera3Request->num_output_buffers; - return -EINVAL; + return; } /* Start the camera if that's the first request we handle. */ @@ -714,14 +694,14 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques int ret = camera_->allocateBuffers(); if (ret) { LOG(HAL, Error) << "Failed to allocate buffers"; - return ret; + return; } ret = camera_->start(); if (ret) { LOG(HAL, Error) << "Failed to start camera"; camera_->freeBuffers(); - return ret; + return; } running_ = true; @@ -769,7 +749,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; delete descriptor; - return -EINVAL; + return; } Request *request = @@ -782,13 +762,11 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques goto error; } - return 0; + return; error: delete request; delete descriptor; - - return ret; } void CameraDevice::requestComplete(Request *request, diff --git a/src/android/camera_device.h b/src/android/camera_device.h index d5d136a74f4a..2105b5b9a1e7 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -20,7 +20,6 @@ #include "message.h" class CameraMetadata; -class ThreadRpc; class CameraDevice : public libcamera::Object { @@ -28,15 +27,13 @@ public: CameraDevice(unsigned int id, const std::shared_ptr &camera); ~CameraDevice(); - void call(ThreadRpc *rpc); - int open(); void close(); void setCallbacks(const camera3_callback_ops_t *callbacks); camera_metadata_t *getStaticMetadata(); const camera_metadata_t *constructDefaultRequestSettings(int type); int configureStreams(camera3_stream_configuration_t *stream_list); - int processCaptureRequest(camera3_capture_request_t *request); + void processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request, const std::map &buffers); diff --git a/src/android/camera_proxy.cpp b/src/android/camera_proxy.cpp index 5f8428cfddfb..a48d8d265328 100644 --- a/src/android/camera_proxy.cpp +++ b/src/android/camera_proxy.cpp @@ -16,7 +16,6 @@ #include "utils.h" #include "camera_device.h" -#include "thread_rpc.h" using namespace libcamera; @@ -148,10 +147,8 @@ int CameraProxy::open(const hw_module_t *hardwareModule) void CameraProxy::close() { - ThreadRpc rpcRequest; - rpcRequest.tag = ThreadRpc::Close; - - threadRpcCall(rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::close, + InvocationTypeBlocking); } void CameraProxy::initialize(const camera3_callback_ops_t *callbacks) @@ -176,18 +173,8 @@ int CameraProxy::configureStreams(camera3_stream_configuration_t *stream_list) int CameraProxy::processCaptureRequest(camera3_capture_request_t *request) { - ThreadRpc rpcRequest; - rpcRequest.tag = ThreadRpc::ProcessCaptureRequest; - rpcRequest.request = request; - - threadRpcCall(rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::processCaptureRequest, + InvocationTypeBlocking, request); return 0; } - -void CameraProxy::threadRpcCall(ThreadRpc &rpcRequest) -{ - cameraDevice_->invokeMethod(&CameraDevice::call, InvocationTypeQueued, - &rpcRequest); - rpcRequest.waitDelivery(); -} diff --git a/src/android/camera_proxy.h b/src/android/camera_proxy.h index 7940eac4e376..e8cfbc9dd526 100644 --- a/src/android/camera_proxy.h +++ b/src/android/camera_proxy.h @@ -14,7 +14,6 @@ #include class CameraDevice; -class ThreadRpc; class CameraProxy { @@ -35,8 +34,6 @@ public: camera3_device_t *camera3Device() { return &camera3Device_; } private: - void threadRpcCall(ThreadRpc &rpcRequest); - unsigned int id_; CameraDevice *cameraDevice_; camera3_device_t camera3Device_; diff --git a/src/android/meson.build b/src/android/meson.build index b5e4eeeb73a8..70dfcc1df27a 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -4,7 +4,6 @@ android_hal_sources = files([ 'camera_device.cpp', 'camera_metadata.cpp', 'camera_proxy.cpp', - 'thread_rpc.cpp' ]) android_camera_metadata_sources = files([ diff --git a/src/android/thread_rpc.cpp b/src/android/thread_rpc.cpp deleted file mode 100644 index f57891ff56bf..000000000000 --- a/src/android/thread_rpc.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * thread_rpc.cpp - Inter-thread procedure call - */ - -#include "thread.h" -#include "thread_rpc.h" - -using namespace libcamera; - -void ThreadRpc::notifyReception() -{ - { - libcamera::MutexLocker locker(mutex_); - delivered_ = true; - } - cv_.notify_one(); -} - -void ThreadRpc::waitDelivery() -{ - libcamera::MutexLocker locker(mutex_); - cv_.wait(locker, [&] { return delivered_; }); -} diff --git a/src/android/thread_rpc.h b/src/android/thread_rpc.h deleted file mode 100644 index f577a5d9fb32..000000000000 --- a/src/android/thread_rpc.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * thread_rpc.h - Inter-thread procedure call - */ -#ifndef __ANDROID_THREAD_RPC_H__ -#define __ANDROID_THREAD_RPC_H__ - -#include -#include - -#include - -class ThreadRpc -{ -public: - enum RpcTag { - ProcessCaptureRequest, - Close, - }; - - ThreadRpc() - : delivered_(false) {} - - void notifyReception(); - void waitDelivery(); - - RpcTag tag; - - camera3_capture_request_t *request; - -private: - bool delivered_; - std::mutex mutex_; - std::condition_variable cv_; -}; - -#endif /* __ANDROID_THREAD_RPC_H__ */