AudioPolicyClientImplLegacy.cpp revision ec40d284218466d8f0e832e7eb88e6ea6c479c88
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 17#define LOG_TAG "AudioPolicyService" 18//#define LOG_NDEBUG 0 19 20#include "Configuration.h" 21#undef __STRICT_ANSI__ 22#define __STDINT_LIMITS 23#define __STDC_LIMIT_MACROS 24#include <stdint.h> 25 26#include <sys/time.h> 27#include <binder/IServiceManager.h> 28#include <utils/Log.h> 29#include <cutils/properties.h> 30#include <binder/IPCThreadState.h> 31#include <utils/String16.h> 32#include <utils/threads.h> 33#include "AudioPolicyService.h" 34#include "ServiceUtilities.h" 35#include <hardware_legacy/power.h> 36#include <media/AudioEffect.h> 37#include <media/EffectsFactoryApi.h> 38//#include <media/IAudioFlinger.h> 39 40#include <hardware/hardware.h> 41#include <system/audio.h> 42#include <system/audio_policy.h> 43#include <hardware/audio_policy.h> 44#include <audio_effects/audio_effects_conf.h> 45#include <media/AudioParameter.h> 46 47 48namespace android { 49 50/* implementation of the interface to the policy manager */ 51extern "C" { 52 53audio_module_handle_t aps_load_hw_module(void *service __unused, 54 const char *name) 55{ 56 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 57 if (af == 0) { 58 ALOGW("%s: could not get AudioFlinger", __func__); 59 return 0; 60 } 61 62 return af->loadHwModule(name); 63} 64 65// deprecated: replaced by aps_open_output_on_module() 66audio_io_handle_t aps_open_output(void *service __unused, 67 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 AUDIO_INPUT_FLAG_FAST /*FIXME*/); 163} 164 165audio_io_handle_t aps_open_input_on_module(void *service __unused, 166 audio_module_handle_t module, 167 audio_devices_t *pDevices, 168 uint32_t *pSamplingRate, 169 audio_format_t *pFormat, 170 audio_channel_mask_t *pChannelMask) 171{ 172 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 173 if (af == 0) { 174 ALOGW("%s: could not get AudioFlinger", __func__); 175 return 0; 176 } 177 178 return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask, 179 AUDIO_INPUT_FLAG_FAST /*FIXME*/); 180} 181 182int aps_close_input(void *service __unused, audio_io_handle_t input) 183{ 184 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 185 if (af == 0) { 186 return PERMISSION_DENIED; 187 } 188 189 return af->closeInput(input); 190} 191 192int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream) 193{ 194 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 195 if (af == 0) { 196 return PERMISSION_DENIED; 197 } 198 199 return af->invalidateStream(stream); 200} 201 202int aps_move_effects(void *service __unused, int session, 203 audio_io_handle_t src_output, 204 audio_io_handle_t dst_output) 205{ 206 sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 207 if (af == 0) { 208 return PERMISSION_DENIED; 209 } 210 211 return af->moveEffects(session, src_output, dst_output); 212} 213 214char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle, 215 const char *keys) 216{ 217 String8 result = AudioSystem::getParameters(io_handle, String8(keys)); 218 return strdup(result.string()); 219} 220 221void aps_set_parameters(void *service, audio_io_handle_t io_handle, 222 const char *kv_pairs, int delay_ms) 223{ 224 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 225 226 audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms); 227} 228 229int aps_set_stream_volume(void *service, audio_stream_type_t stream, 230 float volume, audio_io_handle_t output, 231 int delay_ms) 232{ 233 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 234 235 return audioPolicyService->setStreamVolume(stream, volume, output, 236 delay_ms); 237} 238 239int aps_start_tone(void *service, audio_policy_tone_t tone, 240 audio_stream_type_t stream) 241{ 242 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 243 244 return audioPolicyService->startTone(tone, stream); 245} 246 247int aps_stop_tone(void *service) 248{ 249 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 250 251 return audioPolicyService->stopTone(); 252} 253 254int aps_set_voice_volume(void *service, float volume, int delay_ms) 255{ 256 AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 257 258 return audioPolicyService->setVoiceVolume(volume, delay_ms); 259} 260 261}; // extern "C" 262 263}; // namespace android 264