AudioPolicyManagerALSA.cpp
status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device,
AudioSystem::device_connection_state state,
const char *device_address)
audio_devices_t :要连接的设备号 常见 AUDIO_DEVICE_OUT_SPEAKER = 0x2 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8
AudioSystem::device_connection_state:
enum device_connection_state {
DEVICE_STATE_UNAVAILABLE,
DEVICE_STATE_AVAILABLE,
NUM_DEVICE_STATES
};
DEVICE_STATE_UNAVAILABLE = 0;
DEVICE_STATE_AVAILABLE = 1
const char *device_address:usb 蓝牙 使用
--->dev->set_parameters(dev, keyValuePairs.string());
疑问会调用两次,但是第二次没有调用AudioHardwareALSA::setParameters
--->alsa_sound/audio_hw_hal.cpp" : static int adev_set_parameters
---->AudioHardwareALSA::setParameters 设置 mDevSettingsFlag |= WIRED_ACCESSORY_HEADPHONE;
mDevSettingsFlag 标志在ALSADevice.cpp中会判断这个标志。
一共有两个设备:
2433 I( 269: 269) loadHwModule() Loaded primary audio interface from QCOM Audio HW HAL (audio) handle 1
3015 I( 269: 269) loadHwModule() Loaded r_submix audio interface from Wifi Display audio HAL (audio) handle 4
这个两设备有不同的set_parameters实现。主要是自己还是没有理解代码的用意,很容易跑偏。
hardware/libhardware/modules/audio_remote_submix/audio_hw.cpp
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
{
return -ENOSYS;
}
r_submix什么都没有做。
功能是策略对应的output是否有变化。本例中没有变化。
------>mDeviceForStrategy[i] = getDeviceForStrategy((routing_strategy)i, false /*fromCache*/);
-----> AudioPolicyManager::getDeviceForStrategy() 根据策略,选择设备
------> alsa_sound/ALSADevice.cpp void ALSADevice::switchDevice