概述
目录
1 stream_type—流类型
2 routing_strategy—策略
3 audio_devices--输入输出设备定义
4 stream_type、device、strategy三者间的关系
5 getStrategy--流类型与策略之间的映射关系函数
6 audio_mode—模式
1 stream_type—流类型
enum stream_type {
DEFAULT =-1,
VOICE_CALL = 0, //电话
SYSTEM = 1, //系统声音
RING = 2, //铃声
MUSIC = 3, //音乐声
ALARM = 4, //警告
NOTIFICATION = 5, //通知
BLUETOOTH_SCO = 6, //蓝牙耳机接通
ENFORCED_AUDIBLE = 7, //不能被静音必须路由到喇叭播放的声音
DTMF = 8, //双音多频
TTS = 9, //从文本到语音的合成技术
NUM_STREAM_TYPES
};
2 routing_strategy—策略
enum routing_strategy {
STRATEGY_MEDIA,
STRATEGY_PHONE,
STRATEGY_SONIFICATION,
STRATEGY_DTMF,
NUM_STRATEGIES
};
3 audio_devices--输入输出设备定义
enum audio_devices {
// output devices
DEVICE_OUT_EARPIECE = 0x1,
DEVICE_OUT_SPEAKER = 0x2,
DEVICE_OUT_WIRED_HEADSET = 0x4,
DEVICE_OUT_WIRED_HEADPHONE = 0x8,
DEVICE_OUT_BLUETOOTH_SCO = 0x10,
DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
DEVICE_OUT_AUX_DIGITAL = 0x400,
DEVICE_OUT_FM_HEADPHONE = 0x800,
DEVICE_OUT_FM_SPEAKER = 0x1000,
DEVICE_OUT_TTY = 0x2000,
DEVICE_OUT_DEFAULT = 0x8000,
DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_FM_HEADPHONE | DEVICE_OUT_FM_SPEAKER | DEVICE_OUT_TTY | DEVICE_OUT_DEFAULT),
DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
// input devices
DEVICE_IN_COMMUNICATION = 0x10000,
DEVICE_IN_AMBIENT = 0x20000,
DEVICE_IN_BUILTIN_MIC = 0x40000,
DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
DEVICE_IN_WIRED_HEADSET = 0x100000,
DEVICE_IN_AUX_DIGITAL = 0x200000,
DEVICE_IN_VOICE_CALL = 0x400000,
DEVICE_IN_BACK_MIC = 0x800000,
DEVICE_IN_DEFAULT = 0x80000000,
DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
};
4 stream_type、device、strategy三者间的关系
首先要搞清楚stream_type,device,strategy三者之间的关系:
·AudioSystem::stream_type 音频流的类型,一共有10种类型,在应用层上,就会根据不同场景把stream_type定义好,然后再传到JAVA层或者JNI层。
·AudioSystem::audio_devices 音频输入输出设备
·AudioPolicyManager::routing_strategy 音频路由策略,可以有4种策略
三者的关系如图所示:
5 getStrategy--流类型与策略之间的映射关系函数
getStrategy(stream_type)根据stream type,返回对应的routing strategy值,getDeviceForStrategy()则是根据routing strategy,返回可用的device。Android把10种stream type归纳为4种路由策略,然后根据路由策略决定具体的输出设备。
AudioPolicyManagerBase::routing_strategy AudioPolicyManagerBase::getStrategy(
AudioSystem::stream_type stream) {
switch (stream) {
case AudioSystem::VOICE_CALL: // 电话来了
case AudioSystem::BLUETOOTH_SCO: // 蓝牙耳机接通了
return STRATEGY_PHONE;
case AudioSystem::RING: // 铃声响了
case AudioSystem::NOTIFICATION: // 通知,例如界面中最上面一栏中有消息了
case AudioSystem::ALARM: // 警告,电池没电时的警告?
case AudioSystem::ENFORCED_AUDIBLE:
return STRATEGY_SONIFICATION;
case AudioSystem::DTMF:
return STRATEGY_DTMF;
default:
LOGE("unknown stream type");
case AudioSystem::SYSTEM: // 系统声音,播放音乐的时候按键音,
/*mute 掉音乐,并切换 output 的话,将导致 很差的用户体验。
其中可以得到以下信息:
1、按键声音属于 system stream type 。
2、策略的改变将会导致 output 的切换
3、优先级高的策略 start 时会 mute 掉优先级低的策略*/
case AudioSystem::TTS: // TTS 就是 Text To Speech
case AudioSystem::MUSIC:
return STRATEGY_MEDIA;
}
}
6 audio_mode—模式
enum audio_mode {
MODE_INVALID = -2,
MODE_CURRENT = -1,
MODE_NORMAL = 0,
MODE_RINGTONE,
MODE_IN_CALL,
MODE_IN_COMMUNICATION,
NUM_MODES // not a valid entry, denotes end-of-list
};
最后
以上就是鲤鱼战斗机为你收集整理的音频流分析 五 策略与流类型1 stream_type—流类型2 routing_strategy—策略3 audio_devices--输入输出设备定义4 stream_type、device、strategy三者间的关系5 getStrategy--流类型与策略之间的映射关系函数 6 audio_mode—模式的全部内容,希望文章能够帮你解决音频流分析 五 策略与流类型1 stream_type—流类型2 routing_strategy—策略3 audio_devices--输入输出设备定义4 stream_type、device、strategy三者间的关系5 getStrategy--流类型与策略之间的映射关系函数 6 audio_mode—模式所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复