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

Commit 36cdfb18 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Camera2: Break out individual commands

- List all commands that need implementing in sendCommand
- Write skeleton methods for each one
- Implements playRecordingSound command
- Partially implements enableShutterSound command

Bug: 6243944
Change-Id: I7866df75adca09483f407d3a4f630e847dbc7721
parent 983cf231
Loading
Loading
Loading
Loading
+135 −52
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ void Camera2Client::disconnect() {

    if (mDevice == 0) return;

    stopPreviewLocked();
    stopPreviewL();

    mDevice->waitUntilDrained();

@@ -453,7 +453,7 @@ status_t Camera2Client::setPreviewDisplay(
        window = surface;
    }

    return setPreviewWindowLocked(binder,window);
    return setPreviewWindowL(binder,window);
}

status_t Camera2Client::setPreviewTexture(
@@ -470,10 +470,10 @@ status_t Camera2Client::setPreviewTexture(
        binder = surfaceTexture->asBinder();
        window = new SurfaceTextureClient(surfaceTexture);
    }
    return setPreviewWindowLocked(binder, window);
    return setPreviewWindowL(binder, window);
}

status_t Camera2Client::setPreviewWindowLocked(const sp<IBinder>& binder,
status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder,
        sp<ANativeWindow> window) {
    ATRACE_CALL();
    status_t res;
@@ -525,7 +525,7 @@ status_t Camera2Client::setPreviewWindowLocked(const sp<IBinder>& binder,
    mPreviewWindow = window;

    if (mState == WAITING_FOR_PREVIEW_WINDOW) {
        return startPreviewLocked();
        return startPreviewL();
    }

    return OK;
@@ -544,10 +544,10 @@ status_t Camera2Client::startPreview() {
    Mutex::Autolock icl(mICameraLock);
    status_t res;
    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
    return startPreviewLocked();
    return startPreviewL();
}

status_t Camera2Client::startPreviewLocked() {
status_t Camera2Client::startPreviewL() {
    ATRACE_CALL();
    status_t res;
    if (mState >= PREVIEW) {
@@ -613,10 +613,10 @@ void Camera2Client::stopPreview() {
    Mutex::Autolock icl(mICameraLock);
    status_t res;
    if ( (res = checkPid(__FUNCTION__) ) != OK) return;
    stopPreviewLocked();
    stopPreviewL();
}

void Camera2Client::stopPreviewLocked() {
void Camera2Client::stopPreviewL() {
    ATRACE_CALL();
    switch (mState) {
        case DISCONNECTED:
@@ -684,7 +684,7 @@ status_t Camera2Client::startRecording() {

    switch (mState) {
        case STOPPED:
            res = startPreviewLocked();
            res = startPreviewL();
            if (res != OK) return res;
            break;
        case PREVIEW:
@@ -1523,13 +1523,51 @@ status_t Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
    ALOGV("%s: Camera %d: Command %d (%d, %d)", __FUNCTION__, mCameraId,
            cmd, arg1, arg2);

    if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
    switch (cmd) {
        case CAMERA_CMD_START_SMOOTH_ZOOM:
            return commandStartSmoothZoomL();
        case CAMERA_CMD_STOP_SMOOTH_ZOOM:
            return commandStopSmoothZoomL();
        case CAMERA_CMD_SET_DISPLAY_ORIENTATION:
            return commandSetDisplayOrientationL(arg1);
        case CAMERA_CMD_ENABLE_SHUTTER_SOUND:
            return commandEnableShutterSoundL(arg1 == 1);
        case CAMERA_CMD_PLAY_RECORDING_SOUND:
            return commandPlayRecordingSoundL();
        case CAMERA_CMD_START_FACE_DETECTION:
            return commandStartFaceDetectionL(arg1);
        case CAMERA_CMD_STOP_FACE_DETECTION:
            return commandStopFaceDetectionL();
        case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG:
            return commandEnableFocusMoveMsgL(arg1 == 1);
        case CAMERA_CMD_PING:
            return commandPingL();
        case CAMERA_CMD_SET_VIDEO_BUFFER_COUNT:
            return commandSetVideoBufferCountL(arg1);
        default:
            ALOGE("%s: Unknown command %d (arguments %d, %d)",
                    __FUNCTION__, cmd, arg1, arg2);
            return BAD_VALUE;
    }
}

status_t Camera2Client::commandStartSmoothZoomL() {
    ALOGE("%s: Unimplemented!", __FUNCTION__);
    return OK;
}

status_t Camera2Client::commandStopSmoothZoomL() {
    ALOGE("%s: Unimplemented!", __FUNCTION__);
    return OK;
}

status_t Camera2Client::commandSetDisplayOrientationL(int degrees) {
    LockedParameters::Key k(mParameters);
        int transform = degToTransform(arg1,
    int transform = degToTransform(degrees,
            mCameraFacing == CAMERA_FACING_FRONT);
    if (transform == -1) {
        ALOGE("%s: Camera %d: Error setting %d as display orientation value",
                    __FUNCTION__, mCameraId, arg1);
                __FUNCTION__, mCameraId, degrees);
        return BAD_VALUE;
    }
    if (transform != k.mParameters.previewTransform &&
@@ -1538,14 +1576,63 @@ status_t Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
    }
    k.mParameters.previewTransform = transform;
    return OK;
    } else if (cmd == CAMERA_CMD_PING) {
}

status_t Camera2Client::commandEnableShutterSoundL(bool enable) {
    LockedParameters::Key k(mParameters);
    if (enable) {
        k.mParameters.playShutterSound = true;
        return OK;
    }

    // Disabling shutter sound may not be allowed. In that case only
    // allow the mediaserver process to disable the sound.
    char value[PROPERTY_VALUE_MAX];
    property_get("ro.camera.sound.forced", value, "0");
    if (strncmp(value, "0", 2) != 0) {
        // Disabling shutter sound is not allowed. Deny if the current
        // process is not mediaserver.
        if (getCallingPid() != getpid()) {
            ALOGE("Failed to disable shutter sound. Permission denied (pid %d)",
                    getCallingPid());
            return PERMISSION_DENIED;
        }
    }

    k.mParameters.playShutterSound = false;
    return OK;
}

status_t Camera2Client::commandPlayRecordingSoundL() {
    mCameraService->playSound(CameraService::SOUND_RECORDING);
    return OK;
}

status_t Camera2Client::commandStartFaceDetectionL(int type) {
    ALOGE("%s: Unimplemented!", __FUNCTION__);
    return OK;
}

status_t Camera2Client::commandStopFaceDetectionL() {
    ALOGE("%s: Unimplemented!", __FUNCTION__);
    return OK;
}

status_t Camera2Client::commandEnableFocusMoveMsgL(bool enable) {
    ALOGE("%s: Unimplemented!", __FUNCTION__);
    return OK;
}

status_t Camera2Client::commandPingL() {
    // Always ping back if access is proper and device is alive
    if (mState != DISCONNECTED) {
        return OK;
    } else {
        return NO_INIT;
    }
    } else if (cmd == CAMERA_CMD_SET_VIDEO_BUFFER_COUNT) {
}

status_t Camera2Client::commandSetVideoBufferCountL(size_t count) {
    if (recordingEnabled()) {
        ALOGE("%s: Camera %d: Error setting video buffer count after "
                "recording was started", __FUNCTION__, mCameraId);
@@ -1553,30 +1640,24 @@ status_t Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
    }

    // 32 is the current upper limit on the video buffer count for BufferQueue
        if (arg1 <= 0 || arg1 > 32) {
    if (count > 32) {
        ALOGE("%s: Camera %d: Error setting %d as video buffer count value",
                    __FUNCTION__, mCameraId, arg1);
                __FUNCTION__, mCameraId, count);
        return BAD_VALUE;
    }

    // Need to reallocate memory for heap
        if (mRecordingHeapCount != arg1) {
    if (mRecordingHeapCount != count) {
        if  (mRecordingHeap != 0) {
            mRecordingHeap.clear();
            mRecordingHeap = NULL;
        }
            mRecordingHeapCount = arg1;
        mRecordingHeapCount = count;
    }

    return OK;
}

    ALOGE("%s: Camera %d: Unimplemented command %d (%d, %d)", __FUNCTION__,
            mCameraId, cmd, arg1, arg2);

    return OK;
}

/** Device-related methods */

void Camera2Client::onCaptureAvailable() {
@@ -2458,8 +2539,10 @@ status_t Camera2Client::buildDefaultParameters() {
                CameraParameters::FALSE);
    }

    // Always use metadata mode for recording
    // Set up initial state for non-Camera.Parameters state variables

    k.mParameters.storeMetadataInBuffers = true;
    k.mParameters.playShutterSound = true;

    k.mParameters.paramsFlattened = params.flatten();

+23 −8
Original line number Diff line number Diff line
@@ -86,16 +86,28 @@ private:
    /** ICamera interface-related private members */

    // Mutex that must be locked by methods implementing the ICamera interface.
    // Ensures serialization between incoming ICamera calls
    // Ensures serialization between incoming ICamera calls. All methods below
    // that append 'L' to the name assume that mICameraLock is locked when
    // they're called
    mutable Mutex mICameraLock;

    // The following must be called with mICameraLock already locked

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

    void stopPreviewLocked();
    status_t startPreviewLocked();
    void stopPreviewL();
    status_t startPreviewL();

    // Individual commands for sendCommand()
    status_t commandStartSmoothZoomL();
    status_t commandStopSmoothZoomL();
    status_t commandSetDisplayOrientationL(int degrees);
    status_t commandEnableShutterSoundL(bool enable);
    status_t commandPlayRecordingSoundL();
    status_t commandStartFaceDetectionL(int type);
    status_t commandStopFaceDetectionL();
    status_t commandEnableFocusMoveMsgL(bool enable);
    status_t commandPingL();
    status_t commandSetVideoBufferCountL(size_t count);

    // Current camera state; this is the contents of the CameraParameters object
    // in a more-efficient format. The enum values are mostly based off the
@@ -169,9 +181,12 @@ private:
        bool recordingHint;
        bool videoStabilization;

        bool storeMetadataInBuffers;

        String8 paramsFlattened;

        // These parameters are also part of the camera API-visible state, but not directly
        // listed in Camera.Parameters
        bool storeMetadataInBuffers;
        bool playShutterSound;
    };

    class LockedParameters {