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

Commit 39d1f3e0 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

[AudioPolicy] fix volume regression



This CL fixes regression introduced in aosp/1213724

The regression happened when offloaded music is played, volume
is reduced, next song is requested then the volume is switching
to full scale.

It is linked to a "ghost volume source" without stream types that
is considered as a music stream before volume is set in AudioFlinger.
The music volume was overwritten by this volume source.

This CL fixes only the ghost volume source by preventing to add twice
the internal volumes sources linked to AUDIO_STREAM_PATCH and
AUDIO_STREAM_REROUTING.

The clean fix consists in aligning AudioFlinger on volume sources
rather than stream types.

Bug: 148588565
Test: plays offloaded music, reduce volume to min.
      Then press next song.
      No volume gap expected.

Change-Id: I0bb3b5ca1f13ba23351bcd658acf8d7f52555929
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 1602608c
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -107,6 +107,13 @@ product_strategy_t EngineBase::getProductStrategyByName(const std::string &name)
engineConfig::ParsingResult EngineBase::loadAudioPolicyEngineConfig()
{
    auto loadVolumeConfig = [](auto &volumeGroups, auto &volumeConfig) {
        // Ensure name unicity to prevent duplicate
        LOG_ALWAYS_FATAL_IF(std::any_of(std::begin(volumeGroups), std::end(volumeGroups),
                                     [&volumeConfig](const auto &volumeGroup) {
                return volumeConfig.name == volumeGroup.second->getName(); }),
                            "group name %s defined twice, review the configuration",
                            volumeConfig.name.c_str());

        sp<VolumeGroup> volumeGroup = new VolumeGroup(volumeConfig.name, volumeConfig.indexMin,
                                                      volumeConfig.indexMax);
        volumeGroups[volumeGroup->getId()] = volumeGroup;
@@ -131,6 +138,15 @@ engineConfig::ParsingResult EngineBase::loadAudioPolicyEngineConfig()
            volumeGroup->addSupportedAttributes(attr);
        }
    };
    auto checkStreamForGroups = [](auto streamType, const auto &volumeGroups) {
        const auto &iter = std::find_if(std::begin(volumeGroups), std::end(volumeGroups),
                                     [&streamType](const auto &volumeGroup) {
            const auto& streams = volumeGroup.second->getStreamTypes();
            return std::find(std::begin(streams), std::end(streams), streamType) !=
                    std::end(streams);
        });
        return iter != end(volumeGroups);
    };

    auto result = engineConfig::parse();
    if (result.parsedConfig == nullptr) {
@@ -139,15 +155,17 @@ engineConfig::ParsingResult EngineBase::loadAudioPolicyEngineConfig()
        android::status_t ret = engineConfig::parseLegacyVolumes(config.volumeGroups);
        result = {std::make_unique<engineConfig::Config>(config),
                  static_cast<size_t>(ret == NO_ERROR ? 0 : 1)};
    } else {
        // Append for internal use only volume groups (e.g. rerouting/patch)
        result.parsedConfig->volumeGroups.insert(
                    std::end(result.parsedConfig->volumeGroups),
                    std::begin(gSystemVolumeGroups), std::end(gSystemVolumeGroups));
    }
    // Append for internal use only strategies/volume groups (e.g. rerouting/patch)
    // Append for internal use only strategies (e.g. rerouting/patch)
    result.parsedConfig->productStrategies.insert(
                std::end(result.parsedConfig->productStrategies),
                std::begin(gOrderedSystemStrategies), std::end(gOrderedSystemStrategies));

    result.parsedConfig->volumeGroups.insert(
                std::end(result.parsedConfig->volumeGroups),
                std::begin(gSystemVolumeGroups), std::end(gSystemVolumeGroups));

    ALOGE_IF(result.nbSkippedElement != 0, "skipped %zu elements", result.nbSkippedElement);

@@ -177,6 +195,10 @@ engineConfig::ParsingResult EngineBase::loadAudioPolicyEngineConfig()
                volumeGroup = iter->second;
            }
            if (group.stream != AUDIO_STREAM_DEFAULT) {
                // A legacy stream can be assigned once to a volume group
                LOG_ALWAYS_FATAL_IF(checkStreamForGroups(group.stream, mVolumeGroups),
                                    "stream %s already assigned to a volume group, "
                                    "review the configuration", toString(group.stream).c_str());
                volumeGroup->addSupportedStream(group.stream);
            }
            addSupportedAttributesToGroup(group, volumeGroup, strategy);