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

Commit df7a856d authored by James Dong's avatar James Dong
Browse files

Fixed a race condition where some recording frames may not be released.

When startRecording() is called before setListener(), recording frames
are sent right after startRecording(), but there is no listener to
release the recording frames. This causes the hang in media server.

bug - 3166356

Change-Id: I19366ca682ef9f6b847590c190c30a15ed32b8e4
parent 64f11630
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -372,6 +372,9 @@ void Camera::dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<
    }
    if (listener != NULL) {
        listener->postDataTimestamp(timestamp, msgType, dataPtr);
    } else {
        LOGW("No listener was set. Drop a recording frame.");
        releaseRecordingFrame(dataPtr);
    }
}

+3 −20
Original line number Diff line number Diff line
@@ -495,26 +495,6 @@ status_t CameraSource::init(
        mIsMetaDataStoredInVideoBuffers = true;
    }

    /*
     * mCamera->startRecording() signals camera hal to make
     * available the video buffers (for instance, allocation
     * of the video buffers may be triggered when camera hal's
     * startRecording() method is called). Making available these
     * video buffers earlier (before calling start()) is critical,
     * if one wants to configure omx video encoders to use these
     * buffers for passing video frame data during video recording
     * without the need to memcpy the video frame data stored
     * in these buffers. Eliminating memcpy for video frame data
     * is crucial in performance for HD quality video recording
     * applications.
     *
     * Based on OMX IL spec, configuring the omx video encoders
     * must occur in loaded state. When start() is called, omx
     * video encoders are already in idle state, which is too
     * late. Thus, we must call mCamera->startRecording() earlier.
     */
    startCameraRecording();

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

    int64_t glitchDurationUs = (1000000LL / mVideoFrameRate);
@@ -565,8 +545,11 @@ status_t CameraSource::start(MetaData *meta) {
        mStartTimeUs = startTimeUs;
    }

    // Call setListener first before calling startCameraRecording()
    // to avoid recording frames being dropped.
    int64_t token = IPCThreadState::self()->clearCallingIdentity();
    mCamera->setListener(new CameraSourceListener(this));
    startCameraRecording();
    IPCThreadState::self()->restoreCallingIdentity(token);

    mStarted = true;