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

Commit c78ac26e authored by Ruben Brunk's avatar Ruben Brunk
Browse files

Add experimental camera session prepare API.

Bug: 18949148
Change-Id: I8f73e68ea2e3acc60d98954106f364d13f439a82
parent a09f8cf8
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ enum {
    WAIT_UNTIL_IDLE,
    FLUSH,
    PREPARE,
    TEAR_DOWN
    TEAR_DOWN,
    PREPARE2
};

namespace {
@@ -366,6 +367,21 @@ public:
        return reply.readInt32();
    }

    virtual status_t prepare2(int maxCount, int streamId)
    {
        ALOGV("prepare2");
        Parcel data, reply;

        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
        data.writeInt32(maxCount);
        data.writeInt32(streamId);

        remote()->transact(PREPARE2, data, &reply);

        reply.readExceptionCode();
        return reply.readInt32();
    }

    virtual status_t tearDown(int streamId)
    {
        ALOGV("tearDown");
@@ -592,7 +608,14 @@ status_t BnCameraDeviceUser::onTransact(
            reply->writeInt32(tearDown(streamId));
            return NO_ERROR;
        } break;

        case PREPARE2: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int maxCount = data.readInt32();
            int streamId = data.readInt32();
            reply->writeNoException();
            reply->writeInt32(prepare2(maxCount, streamId));
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+5 −0
Original line number Diff line number Diff line
@@ -139,6 +139,11 @@ public:
     */
    virtual status_t        prepare(int streamId) = 0;

    /**
     * Preallocate up to maxCount buffers for a given output stream asynchronously.
     */
    virtual status_t        prepare2(int maxCount, int streamId) = 0;

    /**
     * Free all unused buffers for a given output stream.
     */
+37 −0
Original line number Diff line number Diff line
@@ -719,6 +719,43 @@ status_t CameraDeviceClient::prepare(int streamId) {
    return res;
}

status_t CameraDeviceClient::prepare2(int maxCount, int streamId) {
    ATRACE_CALL();
    ALOGV("%s", __FUNCTION__);

    status_t res = OK;
    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;

    Mutex::Autolock icl(mBinderSerializationLock);

    // Guard against trying to prepare non-created streams
    ssize_t index = NAME_NOT_FOUND;
    for (size_t i = 0; i < mStreamMap.size(); ++i) {
        if (streamId == mStreamMap.valueAt(i)) {
            index = i;
            break;
        }
    }

    if (index == NAME_NOT_FOUND) {
        ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream created yet",
                __FUNCTION__, mCameraId, streamId);
        return BAD_VALUE;
    }

    if (maxCount <= 0) {
        ALOGE("%s: Camera %d: Invalid maxCount (%d) specified, must be greater than 0.",
                __FUNCTION__, mCameraId, maxCount);
        return BAD_VALUE;
    }

    // Also returns BAD_VALUE if stream ID was not valid, or stream already
    // has been used
    res = mDevice->prepare(maxCount, streamId);

    return res;
}

status_t CameraDeviceClient::tearDown(int streamId) {
    ATRACE_CALL();
    ALOGV("%s", __FUNCTION__);
+3 −0
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ public:
    // Tear down stream resources by freeing its unused buffers
    virtual status_t      tearDown(int streamId);

    // Prepare stream by preallocating up to maxCount of its buffers
    virtual status_t      prepare2(int maxCount, int streamId);

    /**
     * Interface used by CameraService
     */
+6 −0
Original line number Diff line number Diff line
@@ -293,6 +293,12 @@ class CameraDeviceBase : public virtual RefBase {
     */
    virtual status_t tearDown(int streamId) = 0;

    /**
     * Prepare stream by preallocating up to maxCount buffers for it asynchronously.
     * Calls notifyPrepared() once allocation is complete.
     */
    virtual status_t prepare(int maxCount, int streamId) = 0;

    /**
     * Get the HAL device version.
     */
Loading