• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "APM::AudioPolicyEngine/VolumeGroup"
18 //#define LOG_NDEBUG 0
19 
20 #include "VolumeGroup.h"
21 #include <media/TypeConverter.h>
22 #include <utils/String8.h>
23 #include <cstdint>
24 #include <string>
25 
26 #include <log/log.h>
27 
28 
29 namespace android {
30 
31 //
32 // VolumeGroup implementation
33 //
VolumeGroup(const std::string & name,int indexMin,int indexMax)34 VolumeGroup::VolumeGroup(const std::string &name, int indexMin, int indexMax) :
35     mName(name), mId(static_cast<volume_group_t>(HandleGenerator<uint32_t>::getNextHandle())),
36     mGroupVolumeCurves(VolumeCurves(indexMin, indexMax))
37 {
38 }
39 
40 // Used for introspection, e.g. JAVA
getSupportedAttributes() const41 AttributesVector VolumeGroup::getSupportedAttributes() const
42 {
43     AttributesVector supportedAttributes = {};
44     for (auto &aa : mGroupVolumeCurves.getAttributes()) {
45         aa.source = AUDIO_SOURCE_INVALID;
46         supportedAttributes.push_back(aa);
47     }
48     return supportedAttributes;
49 }
50 
dump(String8 * dst,int spaces) const51 void VolumeGroup::dump(String8 *dst, int spaces) const
52 {
53     dst->appendFormat("\n%*s-%s (id: %d)\n", spaces, "", mName.c_str(), mId);
54     mGroupVolumeCurves.dump(dst, spaces + 2, true);
55     mGroupVolumeCurves.dump(dst, spaces + 2, false);
56     dst->appendFormat("\n");
57 }
58 
add(const sp<VolumeCurve> & curve)59 void VolumeGroup::add(const sp<VolumeCurve> &curve)
60 {
61     mGroupVolumeCurves.add(curve);
62 }
63 
addSupportedAttributes(const audio_attributes_t & attr)64 void VolumeGroup::addSupportedAttributes(const audio_attributes_t &attr)
65 {
66     mGroupVolumeCurves.addAttributes(attr);
67 }
68 
addSupportedStream(audio_stream_type_t stream)69 void VolumeGroup::addSupportedStream(audio_stream_type_t stream)
70 {
71     mGroupVolumeCurves.addStreamType(stream);
72 }
73 
74 //
75 // VolumeGroupMap implementation
76 //
dump(String8 * dst,int spaces) const77 void VolumeGroupMap::dump(String8 *dst, int spaces) const
78 {
79     dst->appendFormat("\n%*sVolume Groups dump:", spaces, "");
80     for (const auto &iter : *this) {
81         iter.second->dump(dst, spaces + 2);
82     }
83 }
84 
85 } // namespace android
86 
87