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 #define LOG_TAG "APM::AudioPolicyEngine/Stream"
18 
19 #include "Stream.h"
20 #include <system/audio.h>
21 
22 using std::string;
23 
24 namespace android
25 {
26 namespace audio_policy
27 {
28 
setIdentifier(audio_stream_type_t identifier)29 status_t Element<audio_stream_type_t>::setIdentifier(audio_stream_type_t identifier)
30 {
31     if (identifier > AUDIO_STREAM_CNT) {
32         return BAD_VALUE;
33     }
34     mIdentifier = identifier;
35     ALOGD("%s: Stream %s identifier 0x%X", __FUNCTION__, getName().c_str(), identifier);
36     return NO_ERROR;
37 }
38 
39 /**
40 * Set the strategy to follow for this stream.
41 * It checks if the strategy is valid.
42 *
43 * @param[in] strategy to be followed.
44 *
45 * @return NO_ERROR if the strategy is set correctly, error code otherwise.
46 */
47 template <>
set(routing_strategy strategy)48 status_t Element<audio_stream_type_t>::set<routing_strategy>(routing_strategy strategy)
49 {
50     if (strategy >= NUM_STRATEGIES) {
51         return BAD_VALUE;
52     }
53     mApplicableStrategy = strategy;
54     ALOGD("%s: 0x%X for Stream %s", __FUNCTION__, strategy, getName().c_str());
55     return NO_ERROR;
56 }
57 
58 template <>
get() const59 routing_strategy Element<audio_stream_type_t>::get<routing_strategy>() const
60 {
61     ALOGV("%s: 0x%X for Stream %s", __FUNCTION__, mApplicableStrategy, getName().c_str());
62     return mApplicableStrategy;
63 }
64 
65 template <>
set(audio_stream_type_t volumeProfile)66 status_t Element<audio_stream_type_t>::set<audio_stream_type_t>(audio_stream_type_t volumeProfile)
67 {
68     if (volumeProfile >= AUDIO_STREAM_CNT) {
69         return BAD_VALUE;
70     }
71     mVolumeProfile = volumeProfile;
72     ALOGD("%s: 0x%X for Stream %s", __FUNCTION__, mVolumeProfile, getName().c_str());
73     return NO_ERROR;
74 }
75 
76 template <>
get() const77 audio_stream_type_t Element<audio_stream_type_t>::get<audio_stream_type_t>() const
78 {
79     ALOGV("%s: 0x%X for Stream %s", __FUNCTION__, mVolumeProfile, getName().c_str());
80     return mVolumeProfile;
81 }
82 
83 } // namespace audio_policy
84 } // namespace android
85 
86