This CL adds the concept of Volume Group to the engine. It generalizes the volume management today controled by stream types and hard coded into AOSP. The goal is to control the volume per attributes, being able to define a group of attributes that follow the same volume curves. It intends to replace the concept of aliases in AudioService. Bug: 124767636 Test: build Change-Id: Icd079374cc1680d074b01836eca0bceb0b0c5247 Signed-off-by: François Gaffie <francois.gaffie@renault.com>gugelfrei
parent
a666d61efb
commit
251c7f0a9d
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <VolumeCurve.h>
|
||||
#include <map>
|
||||
|
||||
namespace android {
|
||||
|
||||
class StreamVolumeCurves
|
||||
{
|
||||
public:
|
||||
StreamVolumeCurves() = default;
|
||||
|
||||
/**
|
||||
* @brief switchVolumeCurve control API for Engine, allows to switch the volume curves
|
||||
* from one stream type to another.
|
||||
* @param src source stream type
|
||||
* @param dst destination stream type
|
||||
*/
|
||||
status_t switchVolumeCurve(audio_stream_type_t streamSrc, audio_stream_type_t streamDst)
|
||||
{
|
||||
if (!hasCurvesFor(streamSrc) || !hasCurvesFor(streamDst)) {
|
||||
ALOGE("%s: No curves defined for streams %d %d", __FUNCTION__, streamSrc, streamDst);
|
||||
return NO_INIT;
|
||||
}
|
||||
const VolumeCurves &sourceCurves = getCurvesFor(streamSrc);
|
||||
VolumeCurves &dstCurves = editCurvesFor(streamDst);
|
||||
return dstCurves.switchCurvesFrom(sourceCurves);
|
||||
}
|
||||
void dump(String8 *dst, int spaces = 0) const;
|
||||
|
||||
void add(const VolumeCurves &curves, audio_stream_type_t streamType)
|
||||
{
|
||||
mCurves.emplace(streamType, curves);
|
||||
}
|
||||
|
||||
bool hasCurvesFor(audio_stream_type_t stream)
|
||||
{
|
||||
return mCurves.find(stream) != end(mCurves);
|
||||
}
|
||||
|
||||
VolumeCurves &editCurvesFor(audio_stream_type_t stream)
|
||||
{
|
||||
ALOG_ASSERT(mCurves.find(stream) != end(mCurves), "Invalid stream type for Volume Curve");
|
||||
return mCurves[stream];
|
||||
}
|
||||
const VolumeCurves &getCurvesFor(audio_stream_type_t stream) const
|
||||
{
|
||||
ALOG_ASSERT(mCurves.find(stream) != end(mCurves), "Invalid stream type for Volume Curve");
|
||||
return mCurves.at(stream);
|
||||
}
|
||||
/**
|
||||
* @brief getVolumeCurvesForStream
|
||||
* @param stream type for which the volume curves interface is requested
|
||||
* @return the VolumeCurves for a given stream type.
|
||||
*/
|
||||
VolumeCurves &getVolumeCurvesForStream(audio_stream_type_t stream)
|
||||
{
|
||||
ALOG_ASSERT(mCurves.find(stream) != end(mCurves), "Invalid stream type for Volume Curve");
|
||||
return mCurves[stream];
|
||||
}
|
||||
/**
|
||||
* @brief restoreOriginVolumeCurve helper control API for engine to restore the original volume
|
||||
* curves for a given stream type
|
||||
* @param stream for which the volume curves will be restored.
|
||||
*/
|
||||
status_t restoreOriginVolumeCurve(audio_stream_type_t stream)
|
||||
{
|
||||
if (!hasCurvesFor(stream)) {
|
||||
ALOGE("%s: No curves defined for streams", __FUNCTION__);
|
||||
return NO_INIT;
|
||||
}
|
||||
return switchVolumeCurve(stream, stream);
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<audio_stream_type_t, VolumeCurves> mCurves;
|
||||
};
|
||||
|
||||
} // namespace android
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AudioPolicyManagerInterface.h>
|
||||
#include <VolumeCurve.h>
|
||||
#include <system/audio.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <HandleGenerator.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class VolumeGroup : public virtual RefBase, private HandleGenerator<uint32_t>
|
||||
{
|
||||
public:
|
||||
VolumeGroup(const std::string &name, int indexMin, int indexMax);
|
||||
std::string getName() const { return mName; }
|
||||
volume_group_t getId() const { return mId; }
|
||||
|
||||
void add(const sp<VolumeCurve> &curve);
|
||||
|
||||
VolumeCurves *getVolumeCurves() { return &mGroupVolumeCurves; }
|
||||
|
||||
void addSupportedAttributes(const audio_attributes_t &attr);
|
||||
AttributesVector getSupportedAttributes() const { return mGroupVolumeCurves.getAttributes(); }
|
||||
|
||||
void addSupportedStream(audio_stream_type_t stream);
|
||||
StreamTypeVector getStreamTypes() const { return mGroupVolumeCurves.getStreamTypes(); }
|
||||
|
||||
void dump(String8 *dst, int spaces = 0) const;
|
||||
|
||||
private:
|
||||
const std::string mName;
|
||||
const volume_group_t mId;
|
||||
VolumeCurves mGroupVolumeCurves;
|
||||
};
|
||||
|
||||
class VolumeGroupMap : public std::map<volume_group_t, sp<VolumeGroup> >
|
||||
{
|
||||
public:
|
||||
void dump(String8 *dst, int spaces = 0) const;
|
||||
};
|
||||
|
||||
} // namespace android
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "APM::Engine::StreamVolumeCurves"
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include "StreamVolumeCurves.h"
|
||||
#include <TypeConverter.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
void StreamVolumeCurves::dump(String8 *dst, int spaces) const
|
||||
{
|
||||
if (mCurves.empty()) {
|
||||
return;
|
||||
}
|
||||
dst->appendFormat("\n%*sStreams dump:\n", spaces, "");
|
||||
dst->appendFormat(
|
||||
"%*sStream Can be muted Index Min Index Max Index Cur [device : index]...\n", spaces + 2, "");
|
||||
for (const auto &streamCurve : mCurves) {
|
||||
streamCurve.second.dump(dst, spaces + 2, false);
|
||||
}
|
||||
dst->appendFormat("\n%*sVolume Curves for Use Cases (aka Stream types) dump:\n", spaces, "");
|
||||
for (const auto &streamCurve : mCurves) {
|
||||
std::string streamTypeLiteral;
|
||||
StreamTypeConverter::toString(streamCurve.first, streamTypeLiteral);
|
||||
dst->appendFormat(
|
||||
" %s (%02d): Curve points for device category (index, attenuation in millibel)\n",
|
||||
streamTypeLiteral.c_str(), streamCurve.first);
|
||||
streamCurve.second.dump(dst, spaces + 2, true);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "APM::AudioPolicyEngine/VolumeGroup"
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include "VolumeGroup.h"
|
||||
#include <media/TypeConverter.h>
|
||||
#include <utils/String8.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <log/log.h>
|
||||
|
||||
|
||||
namespace android {
|
||||
|
||||
//
|
||||
// VolumeGroup implementation
|
||||
//
|
||||
VolumeGroup::VolumeGroup(const std::string &name, int indexMin, int indexMax) :
|
||||
mName(name), mId(static_cast<volume_group_t>(HandleGenerator<uint32_t>::getNextHandle())),
|
||||
mGroupVolumeCurves(VolumeCurves(indexMin, indexMax))
|
||||
{
|
||||
}
|
||||
|
||||
void VolumeGroup::dump(String8 *dst, int spaces) const
|
||||
{
|
||||
dst->appendFormat("\n%*s-%s (id: %d)\n", spaces, "", mName.c_str(), mId);
|
||||
mGroupVolumeCurves.dump(dst, spaces + 2, true);
|
||||
mGroupVolumeCurves.dump(dst, spaces + 2, false);
|
||||
dst->appendFormat("\n");
|
||||
}
|
||||
|
||||
void VolumeGroup::add(const sp<VolumeCurve> &curve)
|
||||
{
|
||||
mGroupVolumeCurves.add(curve);
|
||||
}
|
||||
|
||||
void VolumeGroup::addSupportedAttributes(const audio_attributes_t &attr)
|
||||
{
|
||||
mGroupVolumeCurves.addAttributes(attr);
|
||||
}
|
||||
|
||||
void VolumeGroup::addSupportedStream(audio_stream_type_t stream)
|
||||
{
|
||||
mGroupVolumeCurves.addStreamType(stream);
|
||||
}
|
||||
|
||||
//
|
||||
// VolumeGroupMap implementation
|
||||
//
|
||||
void VolumeGroupMap::dump(String8 *dst, int spaces) const
|
||||
{
|
||||
dst->appendFormat("\n%*sVolume Groups dump:", spaces, "");
|
||||
for (const auto &iter : *this) {
|
||||
iter.second->dump(dst, spaces + 2);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
@ -0,0 +1,192 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Copyright (C) 2018 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!-- Volume Groups Tables included by Audio Policy Configuration file -->
|
||||
<!-- Note:
|
||||
It is VALID to have a group without attributes if a product strategy is following
|
||||
this group for all attributes.
|
||||
Otherwise, attributes must be specified
|
||||
-->
|
||||
|
||||
<volumeGroups>
|
||||
<volumeGroup>
|
||||
<name>oem_traffic_anouncement</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_HEADSET">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_EARPIECE">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_EXT_MEDIA">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<!-- OEM ADAS is a volume group that has a single port gain (this is the reason why it is a group
|
||||
but may host different streams.
|
||||
A priority must be given among them (either they are multualy excluisve, so the volume
|
||||
will be the one of the currently acitve stream, otherwise a priority must be given by
|
||||
any mean. -->
|
||||
<volumeGroup>
|
||||
<name>oem_adas_2</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_HEADSET">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
<volumeGroup>
|
||||
<name>oem_adas_3</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-2400</point>
|
||||
<point>33,-1600</point>
|
||||
<point>66,-800</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_EARPIECE">
|
||||
<point>0,-2400</point>
|
||||
<point>33,-1600</point>
|
||||
<point>66,-800</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<!-- MEDIA is a volume group that has a single port gain (this is the reason why it is a group
|
||||
but may host different streams.
|
||||
A priority must be given among them (either they are multualy exclusive, so the volume
|
||||
will be the one of the active stream with highest priority (ORDER MATTERS) unless the curves
|
||||
followed will the the curves for the requested attributes.-->
|
||||
<volumeGroup>
|
||||
<name>media_car_audio_type_3</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
<volumeGroup>
|
||||
<name>media_car_audio_type_7</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-2400</point>
|
||||
<point>33,-1600</point>
|
||||
<point>66,-800</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
<volumeGroup>
|
||||
<name>media</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-2400</point>
|
||||
<point>33,-1600</point>
|
||||
<point>66,-800</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<volumeGroup>
|
||||
<name>speech</name>
|
||||
<indexMin>1</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<volumeGroup>
|
||||
<name>system</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<volumeGroup>
|
||||
<name>phone</name>
|
||||
<indexMin>1</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<volumeGroup>
|
||||
<name>ring</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>40</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-4200</point>
|
||||
<point>33,-2800</point>
|
||||
<point>66,-1400</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
|
||||
<volumeGroup>
|
||||
<name>tts</name>
|
||||
<indexMin>0</indexMin>
|
||||
<indexMax>15</indexMax>
|
||||
<volume deviceCategory="DEVICE_CATEGORY_SPEAKER">
|
||||
<point>0,-0</point>
|
||||
<point>100,0</point>
|
||||
</volume>
|
||||
</volumeGroup>
|
||||
</volumeGroups>
|
||||
|
Loading…
Reference in new issue