Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6540509f authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

Camera: wait for remote camera provider

Before we attempt to get passthrough implementation.

Test: run binderized camera HAL mode with Camera2 CTS.
Bug: 34250977
Change-Id: I5ef81429c85e7761e60541d1a8764b4e6d58b24a
parent 067428c5
Loading
Loading
Loading
Loading
+38 −19
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include "CameraProviderManager.h"

#include <chrono>
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <hidl/ServiceManagement.h>

@@ -46,6 +47,8 @@ CameraProviderManager::~CameraProviderManager() {

status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListener> listener,
        ServiceInteractionProxy* proxy) {
    int numProviders = 0;
    {
        std::lock_guard<std::mutex> lock(mInterfaceMutex);
        if (proxy == nullptr) {
            ALOGE("%s: No valid service interaction proxy provided", __FUNCTION__);
@@ -63,9 +66,23 @@ status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListe
                    "about camera providers", __FUNCTION__);
            return INVALID_OPERATION;
        }
        numProviders = mProviders.size();
    }

    // Also see if there's a passthrough HAL, but let's not complain if there's not
    if (numProviders == 0) {
        // Remote provider might have not been initialized
        // Wait for a bit and see if we get one registered
        std::mutex mtx;
        std::unique_lock<std::mutex> lock(mtx);
        mProviderRegistered.wait_for(lock, std::chrono::seconds(15));
        if (mProviders.size() == 0) {
            ALOGI("%s: Unable to get one registered provider within timeout!",
                    __FUNCTION__);
            std::lock_guard<std::mutex> lock(mInterfaceMutex);
            // See if there's a passthrough HAL, but let's not complain if there's not
            addProvider(kLegacyProviderName, /*expected*/ false);
        }
    }

    return OK;
}
@@ -277,6 +294,7 @@ hardware::Return<void> CameraProviderManager::onRegistration(
    std::lock_guard<std::mutex> lock(mInterfaceMutex);

    addProvider(name);
    mProviderRegistered.notify_one();
    return hardware::Return<void>();
}

@@ -370,7 +388,8 @@ status_t CameraProviderManager::ProviderInfo::initialize() {
        ALOGE("%s: Invalid provider name, ignoring", __FUNCTION__);
        return BAD_VALUE;
    }
    ALOGI("Connecting to new camera provider: %s", mProviderName.c_str());
    ALOGI("Connecting to new camera provider: %s, isRemote? %d",
            mProviderName.c_str(), mInterface->isRemote());
    Status status = mInterface->setCallback(this);
    if (status != Status::OK) {
        ALOGE("%s: Unable to register callbacks with camera provider '%s'",
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <vector>
#include <string>
#include <mutex>
#include <condition_variable>

#include <camera/CameraParameters2.h>
#include <camera/CameraMetadata.h>
@@ -219,6 +220,8 @@ private:
    // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
    mutable std::mutex mInterfaceMutex;

    std::condition_variable mProviderRegistered;

    // the status listener update callbacks will lock mStatusMutex
    mutable std::mutex mStatusListenerMutex;
    wp<StatusListener> mListener;