AudioPolicyClientImplLegacy.cpp revision dce54a1492c410ad0d93253b341fb33305337505
1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* 2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Copyright (C) 2009 The Android Open Source Project 3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Licensed under the Apache License, Version 2.0 (the "License"); 5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * you may not use this file except in compliance with the License. 6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * You may obtain a copy of the License at 7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * http://www.apache.org/licenses/LICENSE-2.0 9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Unless required by applicable law or agreed to in writing, software 11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * distributed under the License is distributed on an "AS IS" BASIS, 12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * See the License for the specific language governing permissions and 14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * limitations under the License. 15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#define LOG_TAG "AudioPolicyService" 18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//#define LOG_NDEBUG 0 19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "Configuration.h" 21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#undef __STRICT_ANSI__ 22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#define __STDINT_LIMITS 23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#define __STDC_LIMIT_MACROS 24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <stdint.h> 25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <sys/time.h> 27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <binder/IServiceManager.h> 28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <utils/Log.h> 29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <cutils/properties.h> 30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <binder/IPCThreadState.h> 31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <utils/String16.h> 32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <utils/threads.h> 33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "AudioPolicyService.h" 34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "ServiceUtilities.h" 35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <hardware_legacy/power.h> 36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <media/AudioEffect.h> 37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <media/EffectsFactoryApi.h> 38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//#include <media/IAudioFlinger.h> 39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <hardware/hardware.h> 41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <system/audio.h> 42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <system/audio_policy.h> 43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <hardware/audio_policy.h> 44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <audio_effects/audio_effects_conf.h> 45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <media/AudioParameter.h> 46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollnamespace android { 49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* implementation of the interface to the policy manager */ 51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollextern "C" { 52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollaudio_module_handle_t aps_load_hw_module(void *service __unused, 54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll const char *name) 55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll{ 56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll if (af == 0) { 58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll ALOGW("%s: could not get AudioFlinger", __func__); 59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll return 0; 60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll return af->loadHwModule(name); 63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// deprecated: replaced by aps_open_output_on_module() 66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollaudio_io_handle_t aps_open_output(void *service __unused, 67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll audio_devices_t *pDevices, 68 uint32_t *pSamplingRate, 69 audio_format_t *pFormat, 70 audio_channel_mask_t *pChannelMask, 71 uint32_t *pLatencyMs, 72 audio_output_flags_t flags) 73{ 74 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 75 if (af == 0) { 76 ALOGW("%s: could not get AudioFlinger", __func__); 77 return 0; 78 } 79 80 return af->openOutput((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask, 81 pLatencyMs, flags); 82} 83 84audio_io_handle_t aps_open_output_on_module(void *service __unused, 85 audio_module_handle_t module, 86 audio_devices_t *pDevices, 87 uint32_t *pSamplingRate, 88 audio_format_t *pFormat, 89 audio_channel_mask_t *pChannelMask, 90 uint32_t *pLatencyMs, 91 audio_output_flags_t flags, 92 const audio_offload_info_t *offloadInfo) 93{ 94 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 95 if (af == 0) { 96 ALOGW("%s: could not get AudioFlinger", __func__); 97 return 0; 98 } 99 return af->openOutput(module, pDevices, pSamplingRate, pFormat, pChannelMask, 100 pLatencyMs, flags, offloadInfo); 101} 102 103audio_io_handle_t aps_open_dup_output(void *service __unused, 104 audio_io_handle_t output1, 105 audio_io_handle_t output2) 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 return af->openDuplicateOutput(output1, output2); 113} 114 115int aps_close_output(void *service __unused, audio_io_handle_t output) 116{ 117 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 118 if (af == 0) { 119 return PERMISSION_DENIED; 120 } 121 122 return af->closeOutput(output); 123} 124 125int aps_suspend_output(void *service __unused, audio_io_handle_t output) 126{ 127 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 128 if (af == 0) { 129 ALOGW("%s: could not get AudioFlinger", __func__); 130 return PERMISSION_DENIED; 131 } 132 133 return af->suspendOutput(output); 134} 135 136int aps_restore_output(void *service __unused, audio_io_handle_t output) 137{ 138 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 139 if (af == 0) { 140 ALOGW("%s: could not get AudioFlinger", __func__); 141 return PERMISSION_DENIED; 142 } 143 144 return af->restoreOutput(output); 145} 146 147// deprecated: replaced by aps_open_input_on_module(), and acoustics parameter is ignored 148audio_io_handle_t aps_open_input(void *service __unused, 149 audio_devices_t *pDevices, 150 uint32_t *pSamplingRate, 151 audio_format_t *pFormat, 152 audio_channel_mask_t *pChannelMask, 153 audio_in_acoustics_t acoustics __unused) 154{ 155 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 156 if (af == 0) { 157 ALOGW("%s: could not get AudioFlinger", __func__); 158 return 0; 159 } 160 161 return af->openInput((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask); 162} 163 164audio_io_handle_t aps_open_input_on_module(void *service __unused, 165 audio_module_handle_t module, 166 audio_devices_t *pDevices, 167 uint32_t *pSamplingRate, 168 audio_format_t *pFormat, 169 audio_channel_mask_t *pChannelMask) 170{ 171 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 172 if (af == 0) { 173 ALOGW("%s: could not get AudioFlinger", __func__); 174 return 0; 175 } 176 177 return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask); 178} 179 180int aps_close_input(void *service __unused, audio_io_handle_t input) 181{ 182 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 183 if (af == 0) { 184 return PERMISSION_DENIED; 185 } 186 187 return af->closeInput(input); 188} 189 190int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream) 191{ 192 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 193 if (af == 0) { 194 return PERMISSION_DENIED; 195 } 196 197 return af->invalidateStream(stream); 198} 199 200int aps_move_effects(void *service __unused, int session, 201 audio_io_handle_t src_output, 202 audio_io_handle_t dst_output) 203{ 204 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 205 if (af == 0) { 206 return PERMISSION_DENIED; 207 } 208 209 return af->moveEffects(session, src_output, dst_output); 210} 211 212char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle, 213 const char *keys) 214{ 215 String8 result = AudioSystem::getParameters(io_handle, String8(keys)); 216 return strdup(result.string()); 217} 218 219void aps_set_parameters(void *service, audio_io_handle_t io_handle, 220 const char *kv_pairs, int delay_ms) 221{ 222 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 223 224 audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms); 225} 226 227int aps_set_stream_volume(void *service, audio_stream_type_t stream, 228 float volume, audio_io_handle_t output, 229 int delay_ms) 230{ 231 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 232 233 return audioPolicyService->setStreamVolume(stream, volume, output, 234 delay_ms); 235} 236 237int aps_start_tone(void *service, audio_policy_tone_t tone, 238 audio_stream_type_t stream) 239{ 240 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 241 242 return audioPolicyService->startTone(tone, stream); 243} 244 245int aps_stop_tone(void *service) 246{ 247 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 248 249 return audioPolicyService->stopTone(); 250} 251 252int aps_set_voice_volume(void *service, float volume, int delay_ms) 253{ 254 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 255 256 return audioPolicyService->setVoiceVolume(volume, delay_ms); 257} 258 259}; // extern "C" 260 261}; // namespace android 262