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

Commit c6dd3da1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Camera: Flush all state transitions before reconfigureCamera" into main...

Merge "Camera: Flush all state transitions before reconfigureCamera" into main am: 90940c49 am: ced31c71 am: 5c25f15c am: 5a1692f3

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2742073



Change-Id: Ibecc5311ef4dcc8ce56a938d095bd62353bf0c1b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e2629f94 5a1692f3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2339,6 +2339,9 @@ bool Camera3Device::reconfigureCamera(const CameraMetadata& sessionParams, int c
    // deadlocks (http://b/143513518)
    nsecs_t maxExpectedDuration = getExpectedInFlightDuration();

    // Make sure status tracker is flushed
    mStatusTracker->flushPendingStates();

    Mutex::Autolock l(mLock);
    if (checkAbandonedStreamsLocked()) {
        ALOGW("%s: Abandoned stream detected, session parameters can't be applied correctly!",
+39 −9
Original line number Diff line number Diff line
@@ -34,7 +34,8 @@ StatusTracker::StatusTracker(wp<Camera3Device> parent) :
        mParent(parent),
        mNextComponentId(0),
        mIdleFence(new Fence()),
        mDeviceState(IDLE) {
        mDeviceState(IDLE),
        mFlushed(true) {
}

StatusTracker::~StatusTracker() {
@@ -111,6 +112,15 @@ void StatusTracker::markComponent(int id, ComponentState state,
        const sp<Fence>& componentFence) {
    ALOGV("%s: Component %d is now %s", __FUNCTION__, id,
            state == IDLE ? "idle" : "active");

    // If any component state changes, the status tracker is considered
    // not flushed.
    {
        Mutex::Autolock l(mFlushLock);
        mFlushed = false;
    }

    {
        Mutex::Autolock l(mPendingLock);

        StateChange newState = {
@@ -122,12 +132,21 @@ void StatusTracker::markComponent(int id, ComponentState state,
        mPendingChangeQueue.add(newState);
        mPendingChangeSignal.signal();
    }
}

void StatusTracker::flushPendingStates()  {
    Mutex::Autolock l(mFlushLock);
    while (!mFlushed && isRunning()) {
        mFlushCondition.waitRelative(mFlushLock, kWaitDuration);
    }
}

void StatusTracker::requestExit() {
    // First mark thread dead
    Thread::requestExit();
    // Then exit any waits
    mPendingChangeSignal.signal();
    mFlushCondition.signal();
}

StatusTracker::ComponentState StatusTracker::getDeviceStateLocked() {
@@ -231,6 +250,17 @@ bool StatusTracker::threadLoop() {
    }
    mStateTransitions.clear();

    // After all pending changes are cleared and notified, mark the tracker
    // as flushed.
    {
        Mutex::Autolock fl(mFlushLock);
        Mutex::Autolock pl(mPendingLock);
        if (mPendingChangeQueue.size() == 0) {
            mFlushed = true;
            mFlushCondition.signal();
        }
    }

    if (waitForIdleFence) {
        auto ret = mIdleFence->wait(kWaitDuration);
        if (ret == NO_ERROR) {
+9 −0
Original line number Diff line number Diff line
@@ -70,6 +70,10 @@ class StatusTracker: public Thread {

    void dumpActiveComponents();

    // Flush all pending states inflight in the tracker, and return upon
    // completion.
    void flushPendingStates();

    virtual void requestExit();
  protected:

@@ -113,6 +117,11 @@ class StatusTracker: public Thread {
    // Current overall device state
    ComponentState mDeviceState;

    // For flushing all pending states transitions
    bool mFlushed;
    Mutex mFlushLock;
    Condition mFlushCondition;

    // Private to threadLoop

    // Determine current overall device state