François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 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/InputSource" |
| 18 | |
| 19 | #include "InputSource.h" |
| 20 | |
| 21 | using std::string; |
| 22 | |
François Gaffie | f19cf79 | 2018-05-30 17:22:17 +0200 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace audio_policy { |
| 25 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 26 | status_t Element<audio_source_t>::setIdentifier(audio_source_t identifier) |
| 27 | { |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 28 | if (identifier > AUDIO_SOURCE_MAX && identifier != AUDIO_SOURCE_HOTWORD |
| 29 | && identifier != AUDIO_SOURCE_FM_TUNER && identifier != AUDIO_SOURCE_ECHO_REFERENCE) { |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 30 | return BAD_VALUE; |
| 31 | } |
| 32 | mIdentifier = identifier; |
François Gaffie | 376740f | 2020-01-16 09:08:04 +0100 | [diff] [blame] | 33 | ALOGV("%s: InputSource %s identifier 0x%X", __FUNCTION__, getName().c_str(), identifier); |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 34 | return NO_ERROR; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Set the device associated to this source. |
François Gaffie | c7ce9a2 | 2016-05-09 11:07:52 +0200 | [diff] [blame] | 39 | * It checks if the input device is valid. |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 40 | * |
| 41 | * @param[in] devices selected for the given input source. |
| 42 | * @tparam audio_devices_t: Applicable input device for this input source. |
| 43 | * |
| 44 | * @return NO_ERROR if the device is either valid or none, error code otherwise. |
| 45 | */ |
| 46 | template <> |
| 47 | status_t Element<audio_source_t>::set(audio_devices_t devices) |
| 48 | { |
François Gaffie | 376740f | 2020-01-16 09:08:04 +0100 | [diff] [blame] | 49 | if (devices == AUDIO_DEVICE_NONE) { |
| 50 | // Reset |
| 51 | mApplicableDevices = devices; |
| 52 | return NO_ERROR; |
François Gaffie | c7ce9a2 | 2016-05-09 11:07:52 +0200 | [diff] [blame] | 53 | } |
François Gaffie | 376740f | 2020-01-16 09:08:04 +0100 | [diff] [blame] | 54 | devices |= AUDIO_DEVICE_BIT_IN; |
François Gaffie | c7ce9a2 | 2016-05-09 11:07:52 +0200 | [diff] [blame] | 55 | if (!audio_is_input_device(devices)) { |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 56 | ALOGE("%s: trying to set an invalid device 0x%X for input source %s", |
| 57 | __FUNCTION__, devices, getName().c_str()); |
| 58 | return BAD_VALUE; |
| 59 | } |
François Gaffie | 376740f | 2020-01-16 09:08:04 +0100 | [diff] [blame] | 60 | ALOGV("%s: 0x%X for input source %s", __FUNCTION__, devices, getName().c_str()); |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 61 | mApplicableDevices = devices; |
| 62 | return NO_ERROR; |
| 63 | } |
| 64 | |
| 65 | template <> |
| 66 | audio_devices_t Element<audio_source_t>::get<audio_devices_t>() const |
| 67 | { |
| 68 | ALOGV("%s: 0x%X for inputSource %s", __FUNCTION__, mApplicableDevices, getName().c_str()); |
| 69 | return mApplicableDevices; |
| 70 | } |
| 71 | } // namespace audio_policy |
| 72 | } // namespace android |
| 73 | |
| 74 | |