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

Commit d667e38b authored by Shuzhen Wang's avatar Shuzhen Wang Committed by Android (Google) Code Review
Browse files

Merge "Camera: Flush all state transitions before reconfigureCamera" into udc-qpr-dev

parents ee345caa 2b407e5b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2336,6 +2336,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() {
@@ -227,6 +246,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();
        }
    }

    return true;
}

+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