赞
踩
手机本身有听筒和扬声器作为音频输出,手机本身可能有底部(双)Mic、顶部Mic、背部Mic作为音频输入。
手机可能连接有线耳机、多个蓝牙耳机、多个WiFi音频外设,或者车载设备、VR设备、投屏设备等。
AudioPolicy提供了一个音频输入、输出管理的中心,当然它还有一些其他的作用。
AudioStream在Audio Base.h中有定义,包含以下内容:
20typedef enum { 21 AUDIO_STREAM_DEFAULT = -1, // (-1) 22 AUDIO_STREAM_MIN = 0, 23 AUDIO_STREAM_VOICE_CALL = 0, 24 AUDIO_STREAM_SYSTEM = 1, 25 AUDIO_STREAM_RING = 2, 26 AUDIO_STREAM_MUSIC = 3, 27 AUDIO_STREAM_ALARM = 4, 28 AUDIO_STREAM_NOTIFICATION = 5, 29 AUDIO_STREAM_BLUETOOTH_SCO = 6, 30 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, 31 AUDIO_STREAM_DTMF = 8, 32 AUDIO_STREAM_TTS = 9, 33 AUDIO_STREAM_ACCESSIBILITY = 10, 34#ifndef AUDIO_NO_SYSTEM_DECLARATIONS 35 /** For dynamic policy output mixes. Only used by the audio policy */ 36 AUDIO_STREAM_REROUTING = 11, 37 /** For audio flinger tracks volume. Only used by the audioflinger */ 38 AUDIO_STREAM_PATCH = 12, 39#endif // AUDIO_NO_SYSTEM_DECLARATIONS 40} audio_stream_type_t;
AudioStrategy在Engine.cpp中有定义:
172routing_strategy Engine::getStrategyForStream(audio_stream_type_t stream) 173{ 174 // stream to strategy mapping 175 switch (stream) { 176 case AUDIO_STREAM_VOICE_CALL: 177 case AUDIO_STREAM_BLUETOOTH_SCO: 178 return STRATEGY_PHONE; 179 case AUDIO_STREAM_RING: 180 case AUDIO_STREAM_ALARM: 181 return STRATEGY_SONIFICATION; 182 case AUDIO_STREAM_NOTIFICATION: 183 return STRATEGY_SONIFICATION_RESPECTFUL; 184 case AUDIO_STREAM_DTMF: 185 return STRATEGY_DTMF; 186 default: 187 ALOGE("unknown stream type %d", stream); 188 case AUDIO_STREAM_SYSTEM: 189 // NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs 190 // while key clicks are played produces a poor result 191 case AUDIO_STREAM_MUSIC: 192 return STRATEGY_MEDIA; 193 case AUDIO_STREAM_ENFORCED_AUDIBLE: 194 return STRATEGY_ENFORCED_AUDIBLE; 195 case AUDIO_STREAM_TTS: 196 return STRATEGY_TRANSMITTED_THROUGH_SPEAKER; 197 case AUDIO_STREAM_ACCESSIBILITY: 198 return STRATEGY_ACCESSIBILITY; 199 case AUDIO_STREAM_REROUTING: 200 return STRATEGY_REROUTING; 201 } 202}
在之前的版本中,AudioStream对应AudioStrategy,AudioStrategy选择音频输出设备。
在现在的新版本中,AudioStream仅用来标识音频的音量,使用音频属性AudioAttributes和AudioStream共同决定AudioStrategy。
204routing_strategy Engine::getStrategyForUsage(audio_usage_t usage) 205{ 206 // usage to strategy mapping 207 switch (usage) { 208 case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: 209 return STRATEGY_ACCESSIBILITY; 210 211 case AUDIO_USAGE_MEDIA: 212 case AUDIO_USAGE_GAME: 213 case AUDIO_USAGE_ASSISTANT: 214 case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: 215 case AUDIO_USAGE_ASSISTANCE_SONIFICATION: 216 return STRATEGY_MEDIA; 217 218 case AUDIO_USAGE_VOICE_COMMUNICATION: 219 return STRATEGY_PHONE; 220 221 case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: 222 return STRATEGY_DTMF; 223 224 case AUDIO_USAGE_ALARM: 225 case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: 226 return STRATEGY_SONIFICATION; 227 228 case AUDIO_USAGE_NOTIFICATION: 229 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: 230 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: 231 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: 232 case AUDIO_USAGE_NOTIFICATION_EVENT: 233 return STRATEGY_SONIFICATION_RESPECTFUL; 234 235 case AUDIO_USAGE_UNKNOWN: 236 default: 237 return STRATEGY_MEDIA; 238 } 239}
见 https://blog.csdn.net/weixin_38663354/article/details/106817126
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。