1 // Copyright 2016 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 16 // Internal helpers for BAudioDeviceInfo. 17 18 #include "brillo_audio_device_info_internal.h" 19 20 #include <base/logging.h> 21 22 #include "brillo_audio_device_info_def.h" 23 24 namespace brillo { 25 BAudioDeviceInfoInternal(int device_id)26BAudioDeviceInfoInternal::BAudioDeviceInfoInternal(int device_id) { 27 device_id_ = device_id; 28 } 29 GetDeviceId()30int BAudioDeviceInfoInternal::GetDeviceId() { 31 return device_id_; 32 } 33 GetConfig()34audio_policy_forced_cfg_t BAudioDeviceInfoInternal::GetConfig() { 35 switch (device_id_) { 36 case TYPE_BUILTIN_SPEAKER: 37 return AUDIO_POLICY_FORCE_SPEAKER; 38 case TYPE_WIRED_HEADSET: 39 return AUDIO_POLICY_FORCE_HEADPHONES; 40 case TYPE_WIRED_HEADSET_MIC: 41 return AUDIO_POLICY_FORCE_HEADPHONES; 42 case TYPE_WIRED_HEADPHONES: 43 return AUDIO_POLICY_FORCE_HEADPHONES; 44 case TYPE_BUILTIN_MIC: 45 return AUDIO_POLICY_FORCE_NONE; 46 default: 47 return AUDIO_POLICY_FORCE_NONE; 48 } 49 } 50 GetAudioDevicesT()51audio_devices_t BAudioDeviceInfoInternal::GetAudioDevicesT() { 52 switch (device_id_) { 53 case TYPE_BUILTIN_SPEAKER: 54 return AUDIO_DEVICE_OUT_SPEAKER; 55 case TYPE_WIRED_HEADSET: 56 return AUDIO_DEVICE_OUT_WIRED_HEADSET; 57 case TYPE_WIRED_HEADSET_MIC: 58 return AUDIO_DEVICE_IN_WIRED_HEADSET; 59 case TYPE_WIRED_HEADPHONES: 60 return AUDIO_DEVICE_OUT_WIRED_HEADPHONE; 61 case TYPE_BUILTIN_MIC: 62 return AUDIO_DEVICE_IN_BUILTIN_MIC; 63 default: 64 return AUDIO_DEVICE_NONE; 65 } 66 } 67 CreateFromAudioDevicesT(unsigned int device)68BAudioDeviceInfoInternal* BAudioDeviceInfoInternal::CreateFromAudioDevicesT( 69 unsigned int device) { 70 int device_id = TYPE_UNKNOWN; 71 switch (device) { 72 case AUDIO_DEVICE_OUT_WIRED_HEADSET: 73 device_id = TYPE_WIRED_HEADSET; 74 break; 75 case AUDIO_DEVICE_OUT_WIRED_HEADPHONE: 76 device_id = TYPE_WIRED_HEADPHONES; 77 break; 78 case AUDIO_DEVICE_IN_WIRED_HEADSET: 79 device_id = TYPE_WIRED_HEADSET_MIC; 80 break; 81 } 82 if (device_id == TYPE_UNKNOWN) { 83 LOG(ERROR) << "Unsupported device."; 84 return nullptr; 85 } 86 return new BAudioDeviceInfoInternal(device_id); 87 } 88 89 } // namespace brillo 90