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

Commit 459dbf3b authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

Merge "audioflinger: Move async callback setting to onFirstRef" am: 0852c962...

Merge "audioflinger: Move async callback setting to onFirstRef" am: 0852c962 am: e6cda358 am: e04f6a9d am: 0e5a56f6

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2452165



Change-Id: I582ee910943a8d8c72486e45e17bfb6c68a93a05
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 74eb107d 0e5a56f6
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -2165,9 +2165,19 @@ void AudioFlinger::PlaybackThread::onFirstRef()
    if (!isStreamInitialized()) {
        ALOGE("The stream is not open yet"); // This should not happen.
    } else {
        // setEventCallback will need a strong pointer as a parameter. Calling it
        // here instead of constructor of PlaybackThread so that the onFirstRef
        // callback would not be made on an incompletely constructed object.
        // Callbacks take strong or weak pointers as a parameter.
        // Since PlaybackThread passes itself as a callback handler, it can only
        // be done outside of the constructor. Creating weak and especially strong
        // pointers to a refcounted object in its own constructor is strongly
        // discouraged, see comments in system/core/libutils/include/utils/RefBase.h.
        // Even if a function takes a weak pointer, it is possible that it will
        // need to convert it to a strong pointer down the line.
        if (mOutput->flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING &&
                mOutput->stream->setCallback(this) == OK) {
            mUseAsyncWrite = true;
            mCallbackThread = new AudioFlinger::AsyncCallbackThread(this);
        }

        if (mOutput->stream->setEventCallback(this) != OK) {
            ALOGD("Failed to add event callback");
        }
@@ -3068,13 +3078,6 @@ void AudioFlinger::PlaybackThread::readOutputParameters_l()
                mFrameCount);
    }

    if (mOutput->flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING) {
        if (mOutput->stream->setCallback(this) == OK) {
            mUseAsyncWrite = true;
            mCallbackThread = new AudioFlinger::AsyncCallbackThread(this);
        }
    }

    mHwSupportsPause = false;
    if (mOutput->flags & AUDIO_OUTPUT_FLAG_DIRECT) {
        bool supportsPause = false, supportsResume = false;