• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 #pragma once
18 
19 #include "IVolumeCurvesCollection.h"
20 #include <utils/KeyedVector.h>
21 #include <utils/StrongPointer.h>
22 #include <utils/SortedVector.h>
23 #include <hardware/audio.h>
24 
25 namespace android {
26 
27 // stream descriptor used for volume control
28 class StreamDescriptor
29 {
30 public:
31     StreamDescriptor();
32 
33     int getVolumeIndex(audio_devices_t device) const;
canBeMuted()34     bool canBeMuted() const { return mCanBeMuted; }
35     void clearCurrentVolumeIndex();
36     void addCurrentVolumeIndex(audio_devices_t device, int index);
getVolumeIndexMin()37     int getVolumeIndexMin() const { return mIndexMin; }
getVolumeIndexMax()38     int getVolumeIndexMax() const { return mIndexMax; }
39     void setVolumeIndexMin(int volIndexMin);
40     void setVolumeIndexMax(int volIndexMax);
hasVolumeIndexForDevice(audio_devices_t device)41     bool hasVolumeIndexForDevice(audio_devices_t device) const
42     {
43         device = Volume::getDeviceForVolume(device);
44         return mIndexCur.indexOfKey(device) >= 0;
45     }
46 
47     void dump(int fd) const;
48 
49     void setVolumeCurvePoint(device_category deviceCategory, const VolumeCurvePoint *point);
getVolumeCurvePoint(device_category deviceCategory)50     const VolumeCurvePoint *getVolumeCurvePoint(device_category deviceCategory) const
51     {
52         return mVolumeCurve[deviceCategory];
53     }
54 
55 private:
56     const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT];
57     KeyedVector<audio_devices_t, int> mIndexCur; /**< current volume index per device. */
58     int mIndexMin; /**< min volume index. */
59     int mIndexMax; /**< max volume index. */
60     bool mCanBeMuted; /**< true is the stream can be muted. */
61 };
62 
63 /**
64  * stream descriptors collection for volume control
65  */
66 class StreamDescriptorCollection : public DefaultKeyedVector<audio_stream_type_t, StreamDescriptor>,
67                                    public IVolumeCurvesCollection
68 {
69 public:
70     StreamDescriptorCollection();
71 
72     virtual void clearCurrentVolumeIndex(audio_stream_type_t stream);
73     virtual void addCurrentVolumeIndex(audio_stream_type_t stream, audio_devices_t device,
74                                        int index);
75     virtual bool canBeMuted(audio_stream_type_t stream);
getVolumeIndexMin(audio_stream_type_t stream)76     virtual int getVolumeIndexMin(audio_stream_type_t stream) const
77     {
78         return valueFor(stream).getVolumeIndexMin();
79     }
getVolumeIndex(audio_stream_type_t stream,audio_devices_t device)80     virtual int getVolumeIndex(audio_stream_type_t stream, audio_devices_t device)
81     {
82         return valueFor(stream).getVolumeIndex(device);
83     }
getVolumeIndexMax(audio_stream_type_t stream)84     virtual int getVolumeIndexMax(audio_stream_type_t stream) const
85     {
86         return valueFor(stream).getVolumeIndexMax();
87     }
88     virtual float volIndexToDb(audio_stream_type_t stream, device_category device,
89                                int indexInUi) const;
90     virtual status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
91     virtual void initializeVolumeCurves(bool isSpeakerDrcEnabled);
92     virtual void switchVolumeCurve(audio_stream_type_t streamSrc, audio_stream_type_t streamDst);
hasVolumeIndexForDevice(audio_stream_type_t stream,audio_devices_t device)93     virtual bool hasVolumeIndexForDevice(audio_stream_type_t stream,
94                                          audio_devices_t device) const
95     {
96         return valueFor(stream).hasVolumeIndexForDevice(device);
97     }
98 
99     virtual status_t dump(int fd) const;
100 
101 private:
102     void setVolumeCurvePoint(audio_stream_type_t stream, device_category deviceCategory,
103                              const VolumeCurvePoint *point);
104     const VolumeCurvePoint *getVolumeCurvePoint(audio_stream_type_t stream,
105                                                 device_category deviceCategory) const;
106     void setVolumeIndexMin(audio_stream_type_t stream,int volIndexMin);
107     void setVolumeIndexMax(audio_stream_type_t stream,int volIndexMax);
108 };
109 
110 }; // namespace android
111