blob: 8c39dc6480bc0e84ad4587c8cfc2b63332267921 [file] [log] [blame]
François Gaffie20f06f92015-03-24 09:01:14 +01001/*
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 "Element.h"
20#include "EngineDefinition.h"
21#include <Volume.h>
22#include <RoutingStrategy.h>
23#include <map>
24
25namespace android
26{
27namespace audio_policy
28{
29/**
30 * @tparam routing_strategy: Applicable strategy for this stream.
31 */
32template <>
33class Element<audio_stream_type_t>
34{
35private:
36 typedef std::map<Volume::device_category, VolumeCurvePoints> VolumeProfiles;
37 typedef VolumeProfiles::iterator VolumeProfileIterator;
38 typedef VolumeProfiles::const_iterator VolumeProfileConstIterator;
39
40public:
41 Element(const std::string &name)
42 : mName(name),
43 mApplicableStrategy(STRATEGY_MEDIA),
44 mIndexMin(0),
45 mIndexMax(1)
46 {}
47 ~Element() {}
48
49 /**
50 * Returns identifier of this policy element
51 *
52 * @returns string representing the name of this policy element
53 */
54 const std::string &getName() const { return mName; }
55
56 /**
57 * Set the unique identifier for this policy element.
58 *
59 * @tparam Key type of the unique identifier.
60 * @param[in] identifier to be set.
61 *
62 * @return NO_ERROR if the identifier is valid and set correctly, error code otherwise.
63 */
64 status_t setIdentifier(audio_stream_type_t identifier);
65
66 /**
67 * @return the unique identifier of this policy element.
68 */
69 audio_stream_type_t getIdentifier() const { return mIdentifier; }
70
71 /**
72 * A Policy element may implement getter/setter function for a given property.
73 * Property may be routing_strategy, audio_stream_type_t, audio_usage_t, audio_source_t
74 * or a string.
75 */
76 template <typename Property>
77 Property get() const;
78
79 template <typename Property>
80 status_t set(Property property);
81
82 status_t setVolumeProfile(Volume::device_category category, const VolumeCurvePoints &points);
83
84 float volIndexToDb(Volume::device_category deviceCategory, int indexInUi);
85
86 status_t initVolume(int indexMin, int indexMax);
87
88private:
89 /* Copy facilities are put private to disable copy. */
90 Element(const Element &object);
91 Element &operator=(const Element &object);
92
93 std::string mName; /**< Unique literal Identifier of a policy base element*/
94 audio_stream_type_t mIdentifier; /**< Unique numerical Identifier of a policy base element*/
95
96 routing_strategy mApplicableStrategy; /**< Applicable strategy for this stream. */
97
98 /**
99 * Collection of volume profiles indexed by the stream type.
100 * Volume is the only reason why the stream profile was not removed from policy when introducing
101 * attributes.
102 */
103 VolumeProfiles mVolumeProfiles;
104
105 int mIndexMin;
106
107 int mIndexMax;
108};
109
110typedef Element<audio_stream_type_t> Stream;
111
112} // namespace audio_policy
113} // namespace android
114
115