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

Commit 528b084b authored by Wu-cheng Li's avatar Wu-cheng Li
Browse files

Unlock the camera if media recorder fails to start recording.

bug:4965716

Change-Id: Icb1f7f18e9ea6c4f0427ade2ed338e7d56be5e01
parent b0b713f2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -720,8 +720,9 @@ public class MediaRecorder
     *
     * <p>Since API level 13, if applications set a camera via
     * {@link #setCamera(Camera)}, the apps can use the camera after this method
     * call. The apps do not need to lock the camera again. The apps should not
     * start another recording session during recording.
     * call. The apps do not need to lock the camera again. However, if this
     * method fails, the apps should still lock the camera back. The apps should
     * not start another recording session during recording.
     *
     * @throws IllegalStateException if it is called before
     * prepare().
+17 −12
Original line number Diff line number Diff line
@@ -158,9 +158,12 @@ CameraSource::CameraSource(
    mVideoSize.width  = -1;
    mVideoSize.height = -1;

    int64_t token = IPCThreadState::self()->clearCallingIdentity();
    mInitCheck = init(camera, proxy, cameraId,
                    videoSize, frameRate,
                    storeMetaDataInVideoBuffers);
    if (mInitCheck != OK) releaseCamera();
    IPCThreadState::self()->restoreCallingIdentity(token);
}

status_t CameraSource::initCheck() const {
@@ -295,7 +298,6 @@ status_t CameraSource::configureCamera(
    if (width != -1 && height != -1) {
        if (!isVideoSizeSupported(width, height, sizes)) {
            LOGE("Video dimension (%dx%d) is unsupported", width, height);
            releaseCamera();
            return BAD_VALUE;
        }
        if (isSetVideoSizeSupportedByCamera) {
@@ -309,7 +311,6 @@ status_t CameraSource::configureCamera(
        // If one and only one of the width and height is -1
        // we reject such a request.
        LOGE("Requested video size (%dx%d) is not supported", width, height);
        releaseCamera();
        return BAD_VALUE;
    } else {  // width == -1 && height == -1
        // Do not configure the camera.
@@ -327,7 +328,6 @@ status_t CameraSource::configureCamera(
        if (strstr(supportedFrameRates, buf) == NULL) {
            LOGE("Requested frame rate (%d) is not supported: %s",
                frameRate, supportedFrameRates);
            releaseCamera();
            return BAD_VALUE;
        }

@@ -463,7 +463,6 @@ status_t CameraSource::init(
        bool storeMetaDataInVideoBuffers) {

    status_t err = OK;
    int64_t token = IPCThreadState::self()->clearCallingIdentity();

    if ((err = isCameraAvailable(camera, proxy, cameraId)) != OK) {
        LOGE("Camera connection could not be established.");
@@ -505,8 +504,6 @@ status_t CameraSource::init(
        }
    }

    IPCThreadState::self()->restoreCallingIdentity(token);

    int64_t glitchDurationUs = (1000000LL / mVideoFrameRate);
    if (glitchDurationUs > mGlitchDurationThresholdUs) {
        mGlitchDurationThresholdUs = glitchDurationUs;
@@ -573,13 +570,21 @@ void CameraSource::stopCameraRecording() {

void CameraSource::releaseCamera() {
    LOGV("releaseCamera");
    if (mCamera != 0) {
        if ((mCameraFlags & FLAGS_HOT_CAMERA) == 0) {
            LOGV("Camera was cold when we started, stopping preview");
            mCamera->stopPreview();
            mCamera->disconnect();
        } else {
            // Unlock the camera so the application can lock it back.
            mCamera->unlock();
        }
        mCamera.clear();
    }
    if (mCameraRecordingProxy != 0) {
        mCameraRecordingProxy->asBinder()->unlinkToDeath(mDeathNotifier);
        mCameraRecordingProxy.clear();
    }
    mCameraFlags = 0;
}