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

Commit 164c75d4 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android (Google) Code Review
Browse files

Merge "Camera2: Add support for preview callbacks" into jb-mr1-dev

parents 6a8ea471 228a5380
Loading
Loading
Loading
Loading
+483 −149

File changed.

Preview size limit exceeded, changes collapsed.

+42 −8
Original line number Diff line number Diff line
@@ -93,8 +93,7 @@ private:
        RECORD,
        STILL_CAPTURE,
        VIDEO_SNAPSHOT
    } mState;

    };
    static const char *getStateName(State state);

    /** ICamera interface-related private members */
@@ -110,12 +109,13 @@ private:
    // up to the camera user
    mutable Mutex mICameraClientLock;

    class Parameters;

    status_t setPreviewWindowL(const sp<IBinder>& binder,
            sp<ANativeWindow> window);

    status_t startPreviewL(Parameters &params, bool restart);
    void     stopPreviewL();
    status_t startPreviewL();

    status_t startRecordingL(Parameters &params, bool restart);
    bool     recordingEnabledL();

    // Individual commands for sendCommand()
@@ -125,7 +125,7 @@ private:
    status_t commandEnableShutterSoundL(bool enable);
    status_t commandPlayRecordingSoundL();
    status_t commandStartFaceDetectionL(int type);
    status_t commandStopFaceDetectionL();
    status_t commandStopFaceDetectionL(Parameters &params);
    status_t commandEnableFocusMoveMsgL(bool enable);
    status_t commandPingL();
    status_t commandSetVideoBufferCountL(size_t count);
@@ -214,6 +214,12 @@ private:
        int afTriggerCounter;
        int currentAfTriggerId;
        bool afInMotion;

        uint32_t previewCallbackFlags;
        bool previewCallbackOneShot;

        // Overall camera state
        State state;
    };

    // This class encapsulates the Parameters class so that it can only be accessed
@@ -284,6 +290,7 @@ private:

    class Camera2Heap;

    void     setPreviewCallbackFlagL(Parameters &params, int flag);
    status_t updateRequests(const Parameters &params);

    // Number of zoom steps to simulate
@@ -305,6 +312,30 @@ private:
    status_t updatePreviewRequest(const Parameters &params);
    status_t updatePreviewStream(const Parameters &params);

    /** Preview callback related members */

    int mCallbackStreamId;
    static const size_t kCallbackHeapCount = 6;
    sp<CpuConsumer>    mCallbackConsumer;
    sp<ANativeWindow>  mCallbackWindow;
    // Simple listener that forwards frame available notifications from
    // a CPU consumer to the callback notification
    class CallbackWaiter: public CpuConsumer::FrameAvailableListener {
      public:
        CallbackWaiter(Camera2Client *parent) : mParent(parent) {}
        void onFrameAvailable() { mParent->onCallbackAvailable(); }
      private:
        Camera2Client *mParent;
    };
    sp<CallbackWaiter>  mCallbackWaiter;
    sp<Camera2Heap>     mCallbackHeap;
    int mCallbackHeapId;
    size_t mCallbackHeapHead, mCallbackHeapFree;
    // Handle callback image buffers
    void onCallbackAvailable();

    status_t updateCallbackStream(const Parameters &params);

    /* Still image capture related members */

    int mCaptureStreamId;
@@ -331,6 +362,7 @@ private:
    /* Recording related members */

    int mRecordingStreamId;
    int mRecordingFrameCount;
    sp<MediaConsumer>    mRecordingConsumer;
    sp<ANativeWindow>  mRecordingWindow;
    // Simple listener that forwards frame available notifications from
@@ -445,6 +477,8 @@ private:
    // Map from camera orientation + facing to gralloc transform enum
    static int degToTransform(int degrees, bool mirror);

    static size_t calculateBufferSize(int width, int height,
            int format, int stride);
};

}; // namespace android
+4 −3
Original line number Diff line number Diff line
@@ -1028,8 +1028,9 @@ int Camera2Device::StreamAdapter::enqueue_buffer(const camera2_stream_ops_t* w,
        buffer_handle_t* buffer) {
    StreamAdapter *stream =
            const_cast<StreamAdapter*>(static_cast<const StreamAdapter*>(w));
    ALOGVV("Stream %d enqueue: Buffer %p captured at %lld ns",
            stream->mId, (void*)(*buffer), timestamp);
    stream->mFrameCount++;
    ALOGVV("Stream %d enqueue: Frame %d (%p) captured at %lld ns",
            stream->mId, mFrameCount, (void*)(*buffer), timestamp);
    int state = stream->mState;
    if (state != ACTIVE) {
        ALOGE("%s: Called when in bad state: %d", __FUNCTION__, state);
@@ -1037,6 +1038,7 @@ int Camera2Device::StreamAdapter::enqueue_buffer(const camera2_stream_ops_t* w,
    }
    ANativeWindow *a = toANW(w);
    status_t err;

    err = native_window_set_buffers_timestamp(a, timestamp);
    if (err != OK) {
        ALOGE("%s: Error setting timestamp on native window: %s (%d)",
@@ -1052,7 +1054,6 @@ int Camera2Device::StreamAdapter::enqueue_buffer(const camera2_stream_ops_t* w,
    }

    stream->mActiveBuffers--;
    stream->mFrameCount++;
    stream->mLastTimestamp = timestamp;
    return OK;
}
+4 −2
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ status_t MediaConsumer::getNextBuffer(buffer_handle_t *buffer, nsecs_t *timestam

    if (!buffer) return BAD_VALUE;
    if (mCurrentLockedBuffers == mMaxLockedBuffers) {
        MC_LOGV("Too many buffers (max %d)", mCurrentLockedBuffers);
        return INVALID_OPERATION;
    }

@@ -91,6 +92,7 @@ status_t MediaConsumer::getNextBuffer(buffer_handle_t *buffer, nsecs_t *timestam
    err = mBufferQueue->acquireBuffer(&b);
    if (err != OK) {
        if (err == BufferQueue::NO_BUFFER_AVAILABLE) {
            MC_LOGV("No buffer available");
            return BAD_VALUE;
        } else {
            MC_LOGE("Error acquiring buffer: %s (%d)", strerror(err), err);
@@ -117,7 +119,7 @@ status_t MediaConsumer::getNextBuffer(buffer_handle_t *buffer, nsecs_t *timestam
    *timestamp = b.mTimestamp;

    mCurrentLockedBuffers++;

    MC_LOGV("getNextBuffer: %d buffers in use", mCurrentLockedBuffers);
    return OK;
}

@@ -143,8 +145,8 @@ status_t MediaConsumer::freeBuffer(buffer_handle_t buffer) {
                buf);
        return err;
    }

    mCurrentLockedBuffers--;
    MC_LOGV("freeBuffer: %d buffers in use", mCurrentLockedBuffers);

    return OK;
}