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

Commit 029e33e5 authored by Eric Laurent's avatar Eric Laurent Committed by Mikhail Naganov
Browse files

audio flinger: report actual sink device for MSD playback threads

When a playback thread is routed to an MSD module, make sure that the
actual sink device selected by the software patch at the output of the
MSD module is reported to AudioTrack clients.

Bug: 139894721
Test: atest AudioTrackTest
Test: atest RoutingTest
Change-Id: Ie52ebe198e9ebdfe5f2a38dcd44c551c705a7931
Merged-In: Ie52ebe198e9ebdfe5f2a38dcd44c551c705a7931
parent 2610b34b
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -1462,6 +1462,20 @@ void AudioFlinger::forwardParametersToDownstreamPatches_l(
    }
}

// Update downstream patches for all playback threads attached to an MSD module
void AudioFlinger::updateDownStreamPatches_l(const struct audio_patch *patch,
                                             const std::set<audio_io_handle_t> streams)
{
    for (const audio_io_handle_t stream : streams) {
        PlaybackThread *playbackThread = checkPlaybackThread_l(stream);
        if (playbackThread == nullptr || !playbackThread->isMsdDevice()) {
            continue;
        }
        playbackThread->setDownStreamPatch(patch);
        playbackThread->sendIoConfigEvent(AUDIO_OUTPUT_CONFIG_CHANGED);
    }
}

// Filter reserved keys from setParameters() before forwarding to audio HAL or acting upon.
// Some keys are used for audio routing and audio path configuration and should be reserved for use
// by audio policy and audio flinger for functional, privacy and security reasons.
@@ -2534,7 +2548,11 @@ sp<AudioFlinger::ThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t mo
                      *output, thread.get());
            }
            mPlaybackThreads.add(*output, thread);
            mPatchPanel.notifyStreamOpened(outHwDev, *output);
            struct audio_patch patch;
            mPatchPanel.notifyStreamOpened(outHwDev, *output, &patch);
            if (thread->isMsdDevice()) {
                thread->setDownStreamPatch(&patch);
            }
            return thread;
        }
    }
+3 −0
Original line number Diff line number Diff line
@@ -320,6 +320,9 @@ public:
    status_t removeEffectFromHal(audio_port_handle_t deviceId,
            audio_module_handle_t hwModuleId, sp<EffectHalInterface> effect);

    void updateDownStreamPatches_l(const struct audio_patch *patch,
                                   const std::set<audio_io_handle_t> streams);

private:
    // FIXME The 400 is temporarily too high until a leak of writers in media.log is fixed.
    static const size_t kLogMemorySize = 400 * 1024;
+17 −3
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ exit:
        mAudioFlinger.mDeviceEffectManager.createAudioPatch(*handle, newPatch);
        mPatches.insert(std::make_pair(*handle, std::move(newPatch)));
        if (insertedModule != AUDIO_MODULE_HANDLE_NONE) {
            addSoftwarePatchToInsertedModules(insertedModule, *handle);
            addSoftwarePatchToInsertedModules(insertedModule, *handle, &newPatch.mAudioPatch);
        }
    } else {
        newPatch.clearConnections(this);
@@ -781,10 +781,20 @@ status_t AudioFlinger::PatchPanel::getDownstreamSoftwarePatches(
}

void AudioFlinger::PatchPanel::notifyStreamOpened(
        AudioHwDevice *audioHwDevice, audio_io_handle_t stream)
        AudioHwDevice *audioHwDevice, audio_io_handle_t stream, struct audio_patch *patch)
{
    if (audioHwDevice->isInsert()) {
        mInsertedModules[audioHwDevice->handle()].streams.insert(stream);
        if (patch != nullptr) {
            std::vector <SoftwarePatch> swPatches;
            getDownstreamSoftwarePatches(stream, &swPatches);
            if (swPatches.size() > 0) {
                auto iter = mPatches.find(swPatches[0].getPatchHandle());
                if (iter != mPatches.end()) {
                    *patch = iter->second.mAudioPatch;
                }
            }
        }
    }
}

@@ -813,9 +823,13 @@ sp<DeviceHalInterface> AudioFlinger::PatchPanel::findHwDeviceByModule(audio_modu
}

void AudioFlinger::PatchPanel::addSoftwarePatchToInsertedModules(
        audio_module_handle_t module, audio_patch_handle_t handle)
        audio_module_handle_t module, audio_patch_handle_t handle,
        const struct audio_patch *patch)
{
    mInsertedModules[module].sw_patches.insert(handle);
    if (!mInsertedModules[module].streams.empty()) {
        mAudioFlinger.updateDownStreamPatches_l(patch, mInsertedModules[module].streams);
    }
}

void AudioFlinger::PatchPanel::removeSoftwarePatchFromInsertedModules(
+4 −2
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ public:
            std::vector<SoftwarePatch> *patches) const;

    // Notifies patch panel about all opened and closed streams.
    void notifyStreamOpened(AudioHwDevice *audioHwDevice, audio_io_handle_t stream);
    void notifyStreamOpened(AudioHwDevice *audioHwDevice, audio_io_handle_t stream,
                            struct audio_patch *patch);
    void notifyStreamClosed(audio_io_handle_t stream);

    void dump(int fd) const;
@@ -226,7 +227,8 @@ private:
    AudioHwDevice* findAudioHwDeviceByModule(audio_module_handle_t module);
    sp<DeviceHalInterface> findHwDeviceByModule(audio_module_handle_t module);
    void addSoftwarePatchToInsertedModules(
            audio_module_handle_t module, audio_patch_handle_t handle);
            audio_module_handle_t module, audio_patch_handle_t handle,
            const struct audio_patch *patch);
    void removeSoftwarePatchFromInsertedModules(audio_patch_handle_t handle);
    void erasePatch(audio_patch_handle_t handle);

+8 −3
Original line number Diff line number Diff line
@@ -1864,7 +1864,8 @@ AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinge
        // index 0 is reserved for normal mixer's submix
        mFastTrackAvailMask(((1 << FastMixerState::sMaxFastTracks) - 1) & ~1),
        mHwSupportsPause(false), mHwPaused(false), mFlushPending(false),
        mLeftVolFloat(-1.0), mRightVolFloat(-1.0)
        mLeftVolFloat(-1.0), mRightVolFloat(-1.0),
        mDownStreamPatch{}
{
    snprintf(mThreadName, kThreadNameLength, "AudioOut_%X", id);
    mNBLogWriter = audioFlinger->newWriter_l(kLogSize, mThreadName);
@@ -2632,12 +2633,16 @@ void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event,
    ALOGV("PlaybackThread::ioConfigChanged, thread %p, event %d", this, event);

    desc->mIoHandle = mId;
    struct audio_patch patch = mPatch;
    if (isMsdDevice()) {
        patch = mDownStreamPatch;
    }

    switch (event) {
    case AUDIO_OUTPUT_OPENED:
    case AUDIO_OUTPUT_REGISTERED:
    case AUDIO_OUTPUT_CONFIG_CHANGED:
        desc->mPatch = mPatch;
        desc->mPatch = patch;
        desc->mChannelMask = mChannelMask;
        desc->mSamplingRate = mSampleRate;
        desc->mFormat = mFormat;
@@ -2647,7 +2652,7 @@ void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event,
        desc->mLatency = latency_l();
        break;
    case AUDIO_CLIENT_STARTED:
        desc->mPatch = mPatch;
        desc->mPatch = patch;
        desc->mPortId = portId;
        break;
    case AUDIO_OUTPUT_CLOSED:
Loading