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

Commit cc2e2089 authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

Merge "[BUG] AudioFlinger: Patch Panel: Fix SwBridge Patch leak" am:...

Merge "[BUG] AudioFlinger: Patch Panel: Fix SwBridge Patch leak" am: 8dd7969b am: e3a5e4ca am: 05fa72ae

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

Change-Id: I87c04c5e991cc1d9298b3625c3732c8de60dd1c8
parents 3b169aab 05fa72ae
Loading
Loading
Loading
Loading
+16 −8
Original line number Original line Diff line number Diff line
@@ -133,7 +133,8 @@ status_t AudioFlinger::PatchPanel::getAudioPort(struct audio_port_v7 *port)


/* Connect a patch between several source and sink ports */
/* Connect a patch between several source and sink ports */
status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch,
status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch,
                                   audio_patch_handle_t *handle)
                                   audio_patch_handle_t *handle,
                                   bool endpointPatch)
{
{
    if (handle == NULL || patch == NULL) {
    if (handle == NULL || patch == NULL) {
        return BAD_VALUE;
        return BAD_VALUE;
@@ -196,7 +197,7 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa
        }
        }
    }
    }


    Patch newPatch{*patch};
    Patch newPatch{*patch, endpointPatch};
    audio_module_handle_t insertedModule = AUDIO_MODULE_HANDLE_NONE;
    audio_module_handle_t insertedModule = AUDIO_MODULE_HANDLE_NONE;


    switch (patch->sources[0].type) {
    switch (patch->sources[0].type) {
@@ -418,12 +419,17 @@ status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *pa
            }
            }


            // remove stale audio patch with same output as source if any
            // remove stale audio patch with same output as source if any
            // Prevent to remove endpoint patches (involved in a SwBridge)
            // Prevent to remove AudioPatch used to route an output involved in an endpoint.
            if (!endpointPatch) {
                for (auto& iter : mPatches) {
                for (auto& iter : mPatches) {
                if (iter.second.mAudioPatch.sources[0].ext.mix.handle == thread->id()) {
                    if (iter.second.mAudioPatch.sources[0].ext.mix.handle == thread->id() &&
                            !iter.second.mIsEndpointPatch) {
                        erasePatch(iter.first);
                        erasePatch(iter.first);
                        break;
                        break;
                    }
                    }
                }
                }
            }
        } break;
        } break;
        default:
        default:
            status = BAD_VALUE;
            status = BAD_VALUE;
@@ -457,7 +463,8 @@ status_t AudioFlinger::PatchPanel::Patch::createConnections(PatchPanel *panel)
    status_t status = panel->createAudioPatch(
    status_t status = panel->createAudioPatch(
            PatchBuilder().addSource(mAudioPatch.sources[0]).
            PatchBuilder().addSource(mAudioPatch.sources[0]).
                addSink(mRecord.thread(), { .source = AUDIO_SOURCE_MIC }).patch(),
                addSink(mRecord.thread(), { .source = AUDIO_SOURCE_MIC }).patch(),
            mRecord.handlePtr());
            mRecord.handlePtr(),
            true /*endpointPatch*/);
    if (status != NO_ERROR) {
    if (status != NO_ERROR) {
        *mRecord.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
        *mRecord.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
        return status;
        return status;
@@ -467,7 +474,8 @@ status_t AudioFlinger::PatchPanel::Patch::createConnections(PatchPanel *panel)
    if (mAudioPatch.num_sinks != 0) {
    if (mAudioPatch.num_sinks != 0) {
        status = panel->createAudioPatch(
        status = panel->createAudioPatch(
                PatchBuilder().addSource(mPlayback.thread()).addSink(mAudioPatch.sinks[0]).patch(),
                PatchBuilder().addSource(mPlayback.thread()).addSink(mAudioPatch.sinks[0]).patch(),
                mPlayback.handlePtr());
                mPlayback.handlePtr(),
                true /*endpointPatch*/);
        if (status != NO_ERROR) {
        if (status != NO_ERROR) {
            *mPlayback.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
            *mPlayback.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
            return status;
            return status;
+7 −2
Original line number Original line Diff line number Diff line
@@ -56,7 +56,8 @@ public:


    /* Create a patch between several source and sink ports */
    /* Create a patch between several source and sink ports */
    status_t createAudioPatch(const struct audio_patch *patch,
    status_t createAudioPatch(const struct audio_patch *patch,
                                       audio_patch_handle_t *handle);
                              audio_patch_handle_t *handle,
                              bool endpointPatch = false);


    /* Release a patch */
    /* Release a patch */
    status_t releaseAudioPatch(audio_patch_handle_t handle);
    status_t releaseAudioPatch(audio_patch_handle_t handle);
@@ -161,7 +162,8 @@ public:


    class Patch final {
    class Patch final {
    public:
    public:
        explicit Patch(const struct audio_patch &patch) : mAudioPatch(patch) {}
        Patch(const struct audio_patch &patch, bool endpointPatch) :
            mAudioPatch(patch), mIsEndpointPatch(endpointPatch) {}
        Patch() = default;
        Patch() = default;
        ~Patch();
        ~Patch();
        Patch(const Patch& other) noexcept {
        Patch(const Patch& other) noexcept {
@@ -170,6 +172,7 @@ public:
            mPlayback = other.mPlayback;
            mPlayback = other.mPlayback;
            mRecord = other.mRecord;
            mRecord = other.mRecord;
            mThread = other.mThread;
            mThread = other.mThread;
            mIsEndpointPatch = other.mIsEndpointPatch;
        }
        }
        Patch(Patch&& other) noexcept { swap(other); }
        Patch(Patch&& other) noexcept { swap(other); }
        Patch& operator=(Patch&& other) noexcept {
        Patch& operator=(Patch&& other) noexcept {
@@ -184,6 +187,7 @@ public:
            swap(mPlayback, other.mPlayback);
            swap(mPlayback, other.mPlayback);
            swap(mRecord, other.mRecord);
            swap(mRecord, other.mRecord);
            swap(mThread, other.mThread);
            swap(mThread, other.mThread);
            swap(mIsEndpointPatch, other.mIsEndpointPatch);
        }
        }


        friend void swap(Patch &a, Patch &b) noexcept {
        friend void swap(Patch &a, Patch &b) noexcept {
@@ -218,6 +222,7 @@ public:
        Endpoint<RecordThread, RecordThread::PatchRecord> mRecord;
        Endpoint<RecordThread, RecordThread::PatchRecord> mRecord;


        wp<ThreadBase> mThread;
        wp<ThreadBase> mThread;
        bool mIsEndpointPatch;
    };
    };


    // Call with AudioFlinger mLock held
    // Call with AudioFlinger mLock held