Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AudioPolicyClientImpl" |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 20 | #include <utils/Log.h> |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 21 | #include "AudioPolicyService.h" |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 25 | /* implementation of the client interface from the policy manager */ |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 26 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 27 | audio_module_handle_t AudioPolicyService::AudioPolicyClient::loadHwModule(const char *name) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 28 | { |
| 29 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 30 | if (af == 0) { |
| 31 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | return af->loadHwModule(name); |
| 36 | } |
| 37 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 38 | audio_io_handle_t AudioPolicyService::AudioPolicyClient::openOutput(audio_module_handle_t module, |
| 39 | audio_devices_t *pDevices, |
| 40 | uint32_t *pSamplingRate, |
| 41 | audio_format_t *pFormat, |
| 42 | audio_channel_mask_t *pChannelMask, |
| 43 | uint32_t *pLatencyMs, |
| 44 | audio_output_flags_t flags, |
| 45 | const audio_offload_info_t *offloadInfo) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 46 | { |
| 47 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 48 | if (af == 0) { |
| 49 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 50 | return 0; |
| 51 | } |
| 52 | return af->openOutput(module, pDevices, pSamplingRate, pFormat, pChannelMask, |
| 53 | pLatencyMs, flags, offloadInfo); |
| 54 | } |
| 55 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 56 | audio_io_handle_t AudioPolicyService::AudioPolicyClient::openDuplicateOutput( |
| 57 | audio_io_handle_t output1, |
| 58 | audio_io_handle_t output2) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 59 | { |
| 60 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 61 | if (af == 0) { |
| 62 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 63 | return 0; |
| 64 | } |
| 65 | return af->openDuplicateOutput(output1, output2); |
| 66 | } |
| 67 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 68 | status_t AudioPolicyService::AudioPolicyClient::closeOutput(audio_io_handle_t output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 69 | { |
| 70 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 71 | if (af == 0) { |
| 72 | return PERMISSION_DENIED; |
| 73 | } |
| 74 | |
| 75 | return af->closeOutput(output); |
| 76 | } |
| 77 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 78 | status_t AudioPolicyService::AudioPolicyClient::suspendOutput(audio_io_handle_t output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 79 | { |
| 80 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 81 | if (af == 0) { |
| 82 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 83 | return PERMISSION_DENIED; |
| 84 | } |
| 85 | |
| 86 | return af->suspendOutput(output); |
| 87 | } |
| 88 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 89 | status_t AudioPolicyService::AudioPolicyClient::restoreOutput(audio_io_handle_t output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 90 | { |
| 91 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 92 | if (af == 0) { |
| 93 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 94 | return PERMISSION_DENIED; |
| 95 | } |
| 96 | |
| 97 | return af->restoreOutput(output); |
| 98 | } |
| 99 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 100 | audio_io_handle_t AudioPolicyService::AudioPolicyClient::openInput(audio_module_handle_t module, |
| 101 | audio_devices_t *pDevices, |
| 102 | uint32_t *pSamplingRate, |
| 103 | audio_format_t *pFormat, |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame^] | 104 | audio_channel_mask_t *pChannelMask, |
| 105 | audio_input_flags_t flags) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 106 | { |
| 107 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 108 | if (af == 0) { |
| 109 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 110 | return 0; |
| 111 | } |
| 112 | |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame^] | 113 | return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask, flags); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 116 | status_t AudioPolicyService::AudioPolicyClient::closeInput(audio_io_handle_t input) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 117 | { |
| 118 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 119 | if (af == 0) { |
| 120 | return PERMISSION_DENIED; |
| 121 | } |
| 122 | |
| 123 | return af->closeInput(input); |
| 124 | } |
| 125 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 126 | status_t AudioPolicyService::AudioPolicyClient::setStreamVolume(audio_stream_type_t stream, |
| 127 | float volume, audio_io_handle_t output, |
| 128 | int delay_ms) |
| 129 | { |
| 130 | return mAudioPolicyService->setStreamVolume(stream, volume, output, |
| 131 | delay_ms); |
| 132 | } |
| 133 | |
| 134 | status_t AudioPolicyService::AudioPolicyClient::invalidateStream(audio_stream_type_t stream) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 135 | { |
| 136 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 137 | if (af == 0) { |
| 138 | return PERMISSION_DENIED; |
| 139 | } |
| 140 | |
| 141 | return af->invalidateStream(stream); |
| 142 | } |
| 143 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 144 | void AudioPolicyService::AudioPolicyClient::setParameters(audio_io_handle_t io_handle, |
| 145 | const String8& keyValuePairs, |
| 146 | int delay_ms) |
| 147 | { |
| 148 | mAudioPolicyService->setParameters(io_handle, keyValuePairs.string(), delay_ms); |
| 149 | } |
| 150 | |
| 151 | String8 AudioPolicyService::AudioPolicyClient::getParameters(audio_io_handle_t io_handle, |
| 152 | const String8& keys) |
| 153 | { |
| 154 | String8 result = AudioSystem::getParameters(io_handle, keys); |
| 155 | return result; |
| 156 | } |
| 157 | |
| 158 | status_t AudioPolicyService::AudioPolicyClient::startTone(audio_policy_tone_t tone, |
| 159 | audio_stream_type_t stream) |
| 160 | { |
| 161 | return mAudioPolicyService->startTone(tone, stream); |
| 162 | } |
| 163 | |
| 164 | status_t AudioPolicyService::AudioPolicyClient::stopTone() |
| 165 | { |
| 166 | return mAudioPolicyService->stopTone(); |
| 167 | } |
| 168 | |
| 169 | status_t AudioPolicyService::AudioPolicyClient::setVoiceVolume(float volume, int delay_ms) |
| 170 | { |
| 171 | return mAudioPolicyService->setVoiceVolume(volume, delay_ms); |
| 172 | } |
| 173 | |
| 174 | status_t AudioPolicyService::AudioPolicyClient::moveEffects(int session, |
| 175 | audio_io_handle_t src_output, |
| 176 | audio_io_handle_t dst_output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 177 | { |
| 178 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 179 | if (af == 0) { |
| 180 | return PERMISSION_DENIED; |
| 181 | } |
| 182 | |
| 183 | return af->moveEffects(session, src_output, dst_output); |
| 184 | } |
| 185 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 186 | status_t AudioPolicyService::AudioPolicyClient::createAudioPatch(const struct audio_patch *patch, |
| 187 | audio_patch_handle_t *handle, |
| 188 | int delayMs) |
| 189 | { |
| 190 | return mAudioPolicyService->clientCreateAudioPatch(patch, handle, delayMs); |
| 191 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 192 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 193 | status_t AudioPolicyService::AudioPolicyClient::releaseAudioPatch(audio_patch_handle_t handle, |
| 194 | int delayMs) |
| 195 | { |
| 196 | return mAudioPolicyService->clientReleaseAudioPatch(handle, delayMs); |
| 197 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 198 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 199 | status_t AudioPolicyService::AudioPolicyClient::setAudioPortConfig( |
| 200 | const struct audio_port_config *config, |
| 201 | int delayMs) |
| 202 | { |
| 203 | return mAudioPolicyService->clientSetAudioPortConfig(config, delayMs); |
| 204 | } |
| 205 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 206 | void AudioPolicyService::AudioPolicyClient::onAudioPortListUpdate() |
| 207 | { |
| 208 | mAudioPolicyService->onAudioPortListUpdate(); |
| 209 | } |
| 210 | |
| 211 | void AudioPolicyService::AudioPolicyClient::onAudioPatchListUpdate() |
| 212 | { |
| 213 | mAudioPolicyService->onAudioPatchListUpdate(); |
| 214 | } |
| 215 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 216 | }; // namespace android |