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

Commit 5a4af294 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh Committed by android-build-merger
Browse files

Camera: use wp for NotificationListener am: e1c80635 am: ece9e363

am: 04a0551e

Change-Id: I2b2afca9cc6ff3bdbd98c1d2c325bdfa0b47627f
parents fe0082c1 04a0551e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -104,7 +104,8 @@ status_t Camera2ClientBase<TClientBase>::initialize(CameraModule *module) {
        return res;
    }

    res = mDevice->setNotifyCallback(this);
    wp<CameraDeviceBase::NotificationListener> weakThis(this);
    res = mDevice->setNotifyCallback(weakThis);

    return OK;
}
+2 −2
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ class CameraDeviceBase : public virtual RefBase {
    /**
     * Abstract class for HAL notification listeners
     */
    class NotificationListener {
    class NotificationListener : public virtual RefBase {
      public:
        // The set of notifications is a merge of the notifications required for
        // API1 and API2.
@@ -219,7 +219,7 @@ class CameraDeviceBase : public virtual RefBase {
     * Connect HAL notifications to a listener. Overwrites previous
     * listener. Set to NULL to stop receiving notifications.
     */
    virtual status_t setNotifyCallback(NotificationListener *listener) = 0;
    virtual status_t setNotifyCallback(wp<NotificationListener> listener) = 0;

    /**
     * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
+37 −33
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ status_t Camera3Device::disconnect() {
    ATRACE_CALL();
    Mutex::Autolock il(mInterfaceLock);

    ALOGV("%s: E", __FUNCTION__);
    ALOGI("%s: E", __FUNCTION__);

    status_t res = OK;

@@ -336,7 +336,7 @@ status_t Camera3Device::disconnect() {
        internalUpdateStatusLocked(STATUS_UNINITIALIZED);
    }

    ALOGV("%s: X", __FUNCTION__);
    ALOGI("%s: X", __FUNCTION__);
    return res;
}

@@ -1482,7 +1482,7 @@ status_t Camera3Device::waitUntilStateThenRelock(bool active, nsecs_t timeout) {
}


status_t Camera3Device::setNotifyCallback(NotificationListener *listener) {
status_t Camera3Device::setNotifyCallback(wp<NotificationListener> listener) {
    ATRACE_CALL();
    Mutex::Autolock l(mOutputLock);

@@ -1615,15 +1615,9 @@ status_t Camera3Device::flush(int64_t *frameNumber) {
    ALOGV("%s: Camera %d: Flushing all requests", __FUNCTION__, mId);
    Mutex::Autolock il(mInterfaceLock);

    NotificationListener* listener;
    {
        Mutex::Autolock l(mOutputLock);
        listener = mListener;
    }

    {
        Mutex::Autolock l(mLock);
        mRequestThread->clear(listener, /*out*/frameNumber);
        mRequestThread->clear(/*out*/frameNumber);
    }

    status_t res;
@@ -1749,10 +1743,11 @@ void Camera3Device::notifyStatus(bool idle) {
        // state changes
        if (mPauseStateNotify) return;
    }
    NotificationListener *listener;

    sp<NotificationListener> listener;
    {
        Mutex::Autolock l(mOutputLock);
        listener = mListener;
        listener = mListener.promote();
    }
    if (idle && listener != NULL) {
        listener->notifyIdle();
@@ -2172,8 +2167,9 @@ void Camera3Device::setErrorStateLockedV(const char *fmt, va_list args) {
    internalUpdateStatusLocked(STATUS_ERROR);

    // Notify upstream about a device error
    if (mListener != NULL) {
        mListener->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
    sp<NotificationListener> listener = mListener.promote();
    if (listener != NULL) {
        listener->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
                CaptureResultExtras());
    }

@@ -2575,10 +2571,10 @@ void Camera3Device::processCaptureResult(const camera3_capture_result *result) {

void Camera3Device::notify(const camera3_notify_msg *msg) {
    ATRACE_CALL();
    NotificationListener *listener;
    sp<NotificationListener> listener;
    {
        Mutex::Autolock l(mOutputLock);
        listener = mListener;
        listener = mListener.promote();
    }

    if (msg == NULL) {
@@ -2602,7 +2598,7 @@ void Camera3Device::notify(const camera3_notify_msg *msg) {
}

void Camera3Device::notifyError(const camera3_error_msg_t &msg,
        NotificationListener *listener) {
        sp<NotificationListener> listener) {

    // Map camera HAL error codes to ICameraDeviceCallback error codes
    // Index into this with the HAL error code
@@ -2673,7 +2669,7 @@ void Camera3Device::notifyError(const camera3_error_msg_t &msg,
}

void Camera3Device::notifyShutter(const camera3_shutter_msg_t &msg,
        NotificationListener *listener) {
        sp<NotificationListener> listener) {
    ssize_t idx;

    // Set timestamp for the request in the in-flight tracking
@@ -2782,7 +2778,7 @@ Camera3Device::RequestThread::RequestThread(wp<Camera3Device> parent,
}

void Camera3Device::RequestThread::setNotificationListener(
        NotificationListener *listener) {
        wp<NotificationListener> listener) {
    Mutex::Autolock l(mRequestLock);
    mListener = listener;
}
@@ -2917,7 +2913,6 @@ status_t Camera3Device::RequestThread::clearRepeatingRequestsLocked(/*out*/int64
}

status_t Camera3Device::RequestThread::clear(
        NotificationListener *listener,
        /*out*/int64_t *lastFrameNumber) {
    Mutex::Autolock l(mRequestLock);
    ALOGV("RequestThread::%s:", __FUNCTION__);
@@ -2926,6 +2921,7 @@ status_t Camera3Device::RequestThread::clear(

    // Send errors for all requests pending in the request queue, including
    // pending repeating requests
    sp<NotificationListener> listener = mListener.promote();
    if (listener != NULL) {
        for (RequestList::iterator it = mRequestQueue.begin();
                 it != mRequestQueue.end(); ++it) {
@@ -3065,6 +3061,7 @@ void Camera3Device::overrideResultForPrecaptureCancel(
void Camera3Device::RequestThread::checkAndStopRepeatingRequest() {
    bool surfaceAbandoned = false;
    int64_t lastFrameNumber = 0;
    sp<NotificationListener> listener;
    {
        Mutex::Autolock l(mRequestLock);
        // Check all streams needed by repeating requests are still valid. Otherwise, stop
@@ -3081,9 +3078,11 @@ void Camera3Device::RequestThread::checkAndStopRepeatingRequest() {
                break;
            }
        }
        listener = mListener.promote();
    }
    if (surfaceAbandoned) {
        mListener->notifyRepeatingRequestError(lastFrameNumber);

    if (listener != NULL && surfaceAbandoned) {
        listener->notifyRepeatingRequestError(lastFrameNumber);
    }
}

@@ -3426,8 +3425,9 @@ void Camera3Device::RequestThread::cleanUpFailedRequests(bool sendRequestError)

        if (sendRequestError) {
            Mutex::Autolock l(mRequestLock);
            if (mListener != NULL) {
                mListener->notifyError(
            sp<NotificationListener> listener = mListener.promote();
            if (listener != NULL) {
                listener->notifyError(
                        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
                        captureRequest->mResultExtras);
            }
@@ -3566,8 +3566,10 @@ sp<Camera3Device::CaptureRequest>
                // error
                ALOGE("%s: Can't get input buffer, skipping request:"
                        " %s (%d)", __FUNCTION__, strerror(-res), res);
                if (mListener != NULL) {
                    mListener->notifyError(

                sp<NotificationListener> listener = mListener.promote();
                if (listener != NULL) {
                    listener->notifyError(
                            hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
                            nextRequest->mResultExtras);
                }
@@ -3847,13 +3849,14 @@ status_t Camera3Device::PreparerThread::prepare(int maxCount, sp<Camera3StreamIn
    status_t res;

    Mutex::Autolock l(mLock);
    sp<NotificationListener> listener = mListener.promote();

    res = stream->startPrepare(maxCount);
    if (res == OK) {
        // No preparation needed, fire listener right off
        ALOGV("%s: Stream %d already prepared", __FUNCTION__, stream->getId());
        if (mListener) {
            mListener->notifyPrepared(stream->getId());
        if (listener != NULL) {
            listener->notifyPrepared(stream->getId());
        }
        return OK;
    } else if (res != NOT_ENOUGH_DATA) {
@@ -3868,8 +3871,8 @@ status_t Camera3Device::PreparerThread::prepare(int maxCount, sp<Camera3StreamIn
        res = Thread::run("C3PrepThread", PRIORITY_BACKGROUND);
        if (res != OK) {
            ALOGE("%s: Unable to start preparer stream: %d (%s)", __FUNCTION__, res, strerror(-res));
            if (mListener) {
                mListener->notifyPrepared(stream->getId());
            if (listener != NULL) {
                listener->notifyPrepared(stream->getId());
            }
            return res;
        }
@@ -3897,7 +3900,7 @@ status_t Camera3Device::PreparerThread::clear() {
    return OK;
}

void Camera3Device::PreparerThread::setNotificationListener(NotificationListener *listener) {
void Camera3Device::PreparerThread::setNotificationListener(wp<NotificationListener> listener) {
    Mutex::Autolock l(mLock);
    mListener = listener;
}
@@ -3944,10 +3947,11 @@ bool Camera3Device::PreparerThread::threadLoop() {

    // This stream has finished, notify listener
    Mutex::Autolock l(mLock);
    if (mListener) {
    sp<NotificationListener> listener = mListener.promote();
    if (listener != NULL) {
        ALOGV("%s: Stream %d prepare done, signaling listener", __FUNCTION__,
                mCurrentStream->getId());
        mListener->notifyPrepared(mCurrentStream->getId());
        listener->notifyPrepared(mCurrentStream->getId());
    }

    ATRACE_ASYNC_END("stream prepare", mCurrentStream->getId());
+9 −11
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ class Camera3Device :
    // Transitions to the idle state on success
    virtual status_t waitUntilDrained();

    virtual status_t setNotifyCallback(NotificationListener *listener);
    virtual status_t setNotifyCallback(wp<NotificationListener> listener);
    virtual bool     willNotify3A();
    virtual status_t waitForNextFrame(nsecs_t timeout);
    virtual status_t getNextResult(CaptureResult *frame);
@@ -460,7 +460,7 @@ class Camera3Device :
                camera3_device_t *hal3Device,
                bool aeLockAvailable);

        void     setNotificationListener(NotificationListener *listener);
        void     setNotificationListener(wp<NotificationListener> listener);

        /**
         * Call after stream (re)-configuration is completed.
@@ -485,9 +485,7 @@ class Camera3Device :
        /**
         * Remove all queued and repeating requests, and pending triggers
         */
        status_t clear(NotificationListener *listener,
                       /*out*/
                       int64_t *lastFrameNumber = NULL);
        status_t clear(/*out*/int64_t *lastFrameNumber = NULL);

        /**
         * Flush all pending requests in HAL.
@@ -603,7 +601,7 @@ class Camera3Device :
        wp<camera3::StatusTracker>  mStatusTracker;
        camera3_device_t  *mHal3Device;

        NotificationListener *mListener;
        wp<NotificationListener> mListener;

        const int          mId;       // The camera ID
        int                mStatusId; // The RequestThread's component ID for
@@ -760,7 +758,7 @@ class Camera3Device :
        PreparerThread();
        ~PreparerThread();

        void setNotificationListener(NotificationListener *listener);
        void setNotificationListener(wp<NotificationListener> listener);

        /**
         * Queue up a stream to be prepared. Streams are processed by a background thread in FIFO
@@ -781,7 +779,7 @@ class Camera3Device :

        // Guarded by mLock

        NotificationListener *mListener;
        wp<NotificationListener> mListener;
        List<sp<camera3::Camera3StreamInterface> > mPendingStreams;
        bool mActive;
        bool mCancelNow;
@@ -810,7 +808,7 @@ class Camera3Device :
    uint32_t               mNextReprocessShutterFrameNumber;
    List<CaptureResult>   mResultQueue;
    Condition              mResultSignal;
    NotificationListener  *mListener;
    wp<NotificationListener>  mListener;

    /**** End scope for mOutputLock ****/

@@ -823,9 +821,9 @@ class Camera3Device :

    // Specific notify handlers
    void notifyError(const camera3_error_msg_t &msg,
            NotificationListener *listener);
            sp<NotificationListener> listener);
    void notifyShutter(const camera3_shutter_msg_t &msg,
            NotificationListener *listener);
            sp<NotificationListener> listener);

    // helper function to return the output buffers to the streams.
    void returnOutputBuffers(const camera3_stream_buffer_t *outputBuffers,