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 <Volume.h>
20#include <utils/KeyedVector.h>
21#include <utils/StrongPointer.h>
22#include <utils/SortedVector.h>
23#include <hardware/audio.h>
24
25namespace android {
26
27// stream descriptor used for volume control
28class StreamDescriptor
29{
30public:
31    StreamDescriptor();
32
33    int getVolumeIndex(audio_devices_t device) const;
34    bool canBeMuted() const { return mCanBeMuted; }
35    void clearCurrentVolumeIndex();
36    void addCurrentVolumeIndex(audio_devices_t device, int index);
37    int getVolumeIndexMin() const { return mIndexMin; }
38    int getVolumeIndexMax() const { return mIndexMax; }
39    void setVolumeIndexMin(int volIndexMin);
40    void setVolumeIndexMax(int volIndexMax);
41
42    void dump(int fd) const;
43
44    void setVolumeCurvePoint(Volume::device_category deviceCategory, const VolumeCurvePoint *point);
45    const VolumeCurvePoint *getVolumeCurvePoint(Volume::device_category deviceCategory) const
46    {
47        return mVolumeCurve[deviceCategory];
48    }
49
50private:
51    const VolumeCurvePoint *mVolumeCurve[Volume::DEVICE_CATEGORY_CNT];
52    KeyedVector<audio_devices_t, int> mIndexCur; /**< current volume index per device. */
53    int mIndexMin; /**< min volume index. */
54    int mIndexMax; /**< max volume index. */
55    bool mCanBeMuted; /**< true is the stream can be muted. */
56};
57
58/**
59 * stream descriptors collection for volume control
60 */
61class StreamDescriptorCollection : public DefaultKeyedVector<audio_stream_type_t, StreamDescriptor>
62{
63public:
64    StreamDescriptorCollection();
65
66    void clearCurrentVolumeIndex(audio_stream_type_t stream);
67    void addCurrentVolumeIndex(audio_stream_type_t stream, audio_devices_t device, int index);
68
69    bool canBeMuted(audio_stream_type_t stream);
70
71    status_t dump(int fd) const;
72
73    void setVolumeCurvePoint(audio_stream_type_t stream,
74                             Volume::device_category deviceCategory,
75                             const VolumeCurvePoint *point);
76
77    const VolumeCurvePoint *getVolumeCurvePoint(audio_stream_type_t stream,
78                                                Volume::device_category deviceCategory) const;
79
80    void setVolumeIndexMin(audio_stream_type_t stream,int volIndexMin);
81    void setVolumeIndexMax(audio_stream_type_t stream,int volIndexMax);
82
83};
84
85}; // namespace android
86