[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
Merged-In: I0bb3b5ca1f13ba23351bcd658acf8d7f52555929
Signed-off-by: François Gaffie <francois.gaffie@renault.com>
gugelfrei
François Gaffie 4 years ago committed by Eric Laurent
parent d7227cc108
commit de82404ca5

@ -107,6 +107,14 @@ 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
const auto &iter = std::find_if(std::begin(volumeGroups), std::end(volumeGroups),
[&volumeConfig](const auto &volumeGroup) {
return volumeConfig.name == volumeGroup.second->getName(); });
LOG_ALWAYS_FATAL_IF(iter != std::end(volumeGroups),
"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 +139,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 +156,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 +196,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);

Loading…
Cancel
Save