blob: 9ff1538b7d24cb30d8da153ade986c856b3b5a3b [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#define LOG_TAG "APM::AudioPolicyEngine/InputSource"
18
19#include "InputSource.h"
20
21using std::string;
22
23namespace android
24{
25namespace audio_policy
26{
27status_t Element<audio_source_t>::setIdentifier(audio_source_t identifier)
28{
29 if (identifier > AUDIO_SOURCE_MAX && identifier != AUDIO_SOURCE_HOTWORD) {
30 return BAD_VALUE;
31 }
32 mIdentifier = identifier;
33 ALOGD("%s: InputSource %s identifier 0x%X", __FUNCTION__, getName().c_str(), identifier);
34 return NO_ERROR;
35}
36
37/**
38* Set the device associated to this source.
39* It checks if the input device is valid but allows to set a NONE device
40* (i.e. only the IN BIT is set).
41*
42* @param[in] devices selected for the given input source.
43* @tparam audio_devices_t: Applicable input device for this input source.
44*
45* @return NO_ERROR if the device is either valid or none, error code otherwise.
46*/
47template <>
48status_t Element<audio_source_t>::set(audio_devices_t devices)
49{
50 if (!audio_is_input_device(devices) && devices != AUDIO_DEVICE_BIT_IN) {
51 ALOGE("%s: trying to set an invalid device 0x%X for input source %s",
52 __FUNCTION__, devices, getName().c_str());
53 return BAD_VALUE;
54 }
55 ALOGD("%s: 0x%X for input source %s", __FUNCTION__, devices, getName().c_str());
56 mApplicableDevices = devices;
57 return NO_ERROR;
58}
59
60template <>
61audio_devices_t Element<audio_source_t>::get<audio_devices_t>() const
62{
63 ALOGV("%s: 0x%X for inputSource %s", __FUNCTION__, mApplicableDevices, getName().c_str());
64 return mApplicableDevices;
65}
66} // namespace audio_policy
67} // namespace android
68
69