Home | History | Annotate | Download | only in audio

Lines Matching full:device

31 status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_devices device,
36 LOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
38 // connect/disconnect only 1 device at a time
39 if (AudioSystem::popCount(device) != 1) return BAD_VALUE;
47 if (AudioSystem::isOutputDevice(device)) {
50 if (AudioSystem::isA2dpDevice(device)) {
51 LOGE("setDeviceConnectionState() invalid device: %x", device);
58 // handle output device connection
60 if (mAvailableOutputDevices & device) {
61 LOGW("setDeviceConnectionState() device already connected: %x", device);
64 LOGV("setDeviceConnectionState() connecting device %x", device);
66 // register new device as available
67 mAvailableOutputDevices |= device;
70 // handle A2DP device connection
71 if (AudioSystem::isA2dpDevice(device)) {
72 status_t status = handleA2dpConnection(device, device_address);
74 mAvailableOutputDevices &= ~device;
80 if (AudioSystem::isBluetoothScoDevice(device)) {
81 LOGV("setDeviceConnectionState() BT SCO device, address %s", device_address);
82 // keep track of SCO device address
87 // handle output device disconnection
89 if (!(mAvailableOutputDevices & device)) {
90 LOGW("setDeviceConnectionState() device not connected: %x", device);
95 LOGV("setDeviceConnectionState() disconnecting device %x", device);
96 // remove device from available output devices
97 mAvailableOutputDevices &= ~device;
100 // handle A2DP device disconnection
101 if (AudioSystem::isA2dpDevice(device)) {
102 status_t status = handleA2dpDisconnection(device, device_address);
104 mAvailableOutputDevices |= device;
110 if (AudioSystem::isBluetoothScoDevice(device)) {
127 if (state == AudioSystem::DEVICE_STATE_UNAVAILABLE && AudioSystem::isA2dpDevice(device)) {
134 if (device == AudioSystem::DEVICE_OUT_WIRED_HEADSET) {
135 device = AudioSystem::DEVICE_IN_WIRED_HEADSET;
136 } else if (device == AudioSystem::DEVICE_OUT_BLUETOOTH_SCO ||
137 device == AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET ||
138 device == AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT) {
139 device = AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET;
145 if (AudioSystem::isInputDevice(device)) {
149 // handle input device connection
151 if (mAvailableInputDevices & device) {
152 LOGW("setDeviceConnectionState() device already connected: %d", device);
155 mAvailableInputDevices |= device;
159 // handle input device disconnection
161 if (!(mAvailableInputDevices & device)) {
162 LOGW("setDeviceConnectionState() device not connected: %d", device);
165 mAvailableInputDevices &= ~device;
178 LOGV("setDeviceConnectionState() changing device from %x to %x for input %d",
190 LOGW("setDeviceConnectionState() invalid device: %x", device);
194 AudioSystem::device_connection_state AudioPolicyManagerBase::getDeviceConnectionState(AudioSystem::audio_devices device,
199 if (AudioSystem::isOutputDevice(device)) {
200 if (device & mAvailableOutputDevices) {
202 if (AudioSystem::isA2dpDevice(device) &&
207 if (AudioSystem::isBluetoothScoDevice(device) &&
213 } else if (AudioSystem::isInputDevice(device)) {
214 if (device & mAvailableInputDevices) {
254 // even if no device change is needed
259 // even if no device change is needed
264 // even if no device change is needed
268 // check for device and output changes triggered by new phone state
279 // even if no device change is needed
281 newDevice = hwOutputDesc->device();
289 // delay the device change command by twice the output latency to have some margin
304 // setting output device above
378 // check for device and output changes triggered by new phone state
395 LOGV("setForceUse() changing device from %x to %x for input %d",
434 uint32_t device = getDeviceForStrategy(strategy);
470 if (needsDirectOuput(stream, samplingRate, format, channels, flags, device)) {
472 LOGV("getOutput() opening direct output device %x", device);
474 outputDesc->mDevice = device;
514 uint32_t a2dpDevice = device & AudioSystem::DEVICE_OUT_ALL_A2DP;
515 if (AudioSystem::popCount((AudioSystem::audio_devices)device) == 2) {
520 LOGW_IF((mA2dpOutput == 0), "getOutput() A2DP device in multiple %x selected but A2DP output not opened", device);
528 LOGV("getOutput() using output %d for 2 devices %x", output, device);
532 // if playing on A2DP device, use a2dp output
533 LOGW_IF((mA2dpOutput == 0), "getOutput() A2DP device %x selected but A2DP output not opened", device);
538 // if playing on not A2DP device, use hardware output
584 // apply volume rules for current stream and device if necessary
585 checkAndSetVolume(stream, mStreams[stream].mIndexCur, output, outputDesc->device());
680 uint32_t device = getDeviceForInputSource(inputSource);
684 if (device == 0) {
706 inputDesc->mDevice = device;
830 // compute and apply stream volume on all outputs according to connected device
833 status_t volStatus = checkAndSetVolume(stream, index, mOutputs.keyAt(i), mOutputs.valueAt(i)->device());
990 snprintf(buffer, SIZE, " A2DP device address: %s\n", mA2dpDeviceAddress.string());
993 snprintf(buffer, SIZE, " SCO device address: %s\n", mScoDeviceAddress.string());
1311 status_t AudioPolicyManagerBase::handleA2dpConnection(AudioSystem::audio_devices device,
1314 // when an A2DP device is connected, open an A2DP and a duplicated output
1315 LOGV("opening A2DP output for device %s", device_address);
1317 outputDesc->mDevice = device;
1330 // set initial stream volume for A2DP device
1331 applyStreamVolumes(mA2dpOutput, device);
1337 // If both A2DP and duplicated outputs are open, send device address to A2DP hardware
1354 applyStreamVolumes(mDuplicatedOutput, device);
1366 LOGW("setDeviceConnectionState() could not open A2DP output for device %x", device);
1386 status_t AudioPolicyManagerBase::handleA2dpDisconnection(AudioSystem::audio_devices device,
1517 // ((SCO device is connected &&
1523 // ((SCO device is NOT connected ||
1559 uint32_t device = 0;
1564 // use device for strategy enforced audible
1566 // use device for strategy phone
1568 // use device for strategy sonification
1570 // use device for strategy media
1572 // use device for strategy DTMF
1574 device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
1577 device = getDeviceForStrategy(STRATEGY_PHONE, fromCache);
1579 device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
1581 device = getDeviceForStrategy(STRATEGY_MEDIA, fromCache);
1583 device = getDeviceForStrategy(STRATEGY_DTMF, fromCache);
1586 LOGV("getNewDevice() selected device %x", device);
1587 return device;
1636 uint32_t device = 0;
1639 LOGV("getDeviceForStrategy() from cache strategy %d, device %x", strategy, mDeviceForStrategy[strategy]);
1647 device = getDeviceForStrategy(STRATEGY_MEDIA, false);
1659 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
1660 if (device) break;
1662 device
1663 if (device) break;
1664 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO;
1665 if (device) break;
1666 // if SCO device is requested but no SCO device is available, fall back to default case
1670 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE;
1671 if (device) break;
1672 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
1673 if (device) break;
1677 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP;
1678 if (device) break;
1679 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
1680 if (device) break;
1683 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
1684 if (device) break;
1685 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
1686 if (device) break;
1687 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET;
1688 if (device) break;
1689 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_EARPIECE;
1690 if (device == 0) {
1691 LOGE("getDeviceForStrategy() earpiece device not found");
1700 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
1701 if (device) break;
1704 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
1705 if (device) break;
1706 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
1707 if (device) break;
1708 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET;
1709 if (device) break;
1710 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
1711 if (device == 0) {
1712 LOGE("getDeviceForStrategy() speaker device not found");
1720 // If incall, just select the STRATEGY_PHONE device: The rest of the behavior is handled by
1723 device = getDeviceForStrategy(STRATEGY_PHONE, false);
1732 device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
1733 if (device == 0) {
1734 LOGE("getDeviceForStrategy() speaker device not found");
1736 // The second device used for sonification is the same as the device used by media strategy
1771 // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or
1773 device |= device2;
1774 if (device == 0) {
1775 LOGE("getDeviceForStrategy() speaker device not found");
1784 LOGV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
1785 return device;
1795 void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t device, bool force, int delayMs)
1797 LOGV("setOutputDevice() output %d device %x delayMs %d", output, device, delayMs);
1802 setOutputDevice(outputDesc->mOutput1->mId, device, force, delayMs);
1803 setOutputDevice(outputDesc->mOutput2->mId, device, force, delayMs);
1809 device &= AudioSystem::DEVICE_OUT_ALL_A2DP;
1811 device &= ~AudioSystem::DEVICE_OUT_ALL_A2DP;
1815 uint32_t prevDevice = (uint32_t)outputDesc->device();
1817 // - the requestede device is 0
1818 // - the requested device is the same as current device and force is not specified.
1820 if ((device == 0 || device == prevDevice) && !force) {
1821 LOGV("setOutputDevice() setting same device %x or null device for output %d", device, output);
1825 outputDesc->mDevice = device;
1827 if (output == mHardwareOutput && AudioSystem::popCount(device) == 2) {
1837 param.addInt(String8(AudioParameter::keyRouting), (int)device);
1839 // update stream volumes according to new device
1840 applyStreamVolumes(output, device, delayMs);
1850 uint32_t device;
1859 device = AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET;
1861 device = AudioSystem::DEVICE_IN_WIRED_HEADSET;
1863 device = AudioSystem::DEVICE_IN_BUILTIN_MIC;
1868 device = AudioSystem::DEVICE_IN_BACK_MIC;
1870 device = AudioSystem::DEVICE_IN_BUILTIN_MIC;
1876 device = AudioSystem::DEVICE_IN_VOICE_CALL;
1880 device = 0;
1883 LOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
1884 return device;
1898 AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategory(uint32_t device)
1900 if (device == 0) {
1906 if (AudioSystem::popCount(device) > 1) {
1907 // Multiple device selection is either:
1908 // - speaker + one other device: give priority to speaker in this case.
1909 // - one A2DP device + another device: happens with duplicated output. In this case
1910 // retain the device on the A2DP output as the other must not correspond to an active
1912 if (device & AUDIO_DEVICE_OUT_SPEAKER)
1915 device &= AUDIO_DEVICE_OUT_ALL_A2DP;
1918 LOGW_IF(AudioSystem::popCount(device) != 1,
1919 "getDeviceCategory() invalid device combination: %08x",
1920 device);
1922 switch(device) {
1940 float AudioPolicyManagerBase::volIndexToAmpl(uint32_t device, const StreamDescriptor& streamDesc,
1943 device_category deviceCategory = getDeviceCategory(device);
2048 float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device)
2054 if (device == 0) {
2055 device = outputDesc->device();
2061 (device == AudioSystem::DEVICE_OUT_AUX_DIGITAL ||
2062 device == AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) {
2066 volume = volIndexToAmpl(device, streamDesc, index);
2073 if ((device &
2086 float musicVol = computeVolume(AudioSystem::MUSIC, mStreams[AudioSystem::MUSIC].mIndexCur, output, device);
2098 status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs, bool force)
2115 float volume = computeVolume(stream, index, output, device);
2158 void AudioPolicyManagerBase::applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs, bool force)
2160 LOGV("applyStreamVolumes() for output %d and device %x", output, device);
2163 checkAndSetVolume(stream, mStreams[stream].mIndexCur, output, device, delayMs, force);
2187 checkAndSetVolume(stream, 0, output, outputDesc->device(), delayMs);
2198 checkAndSetVolume(stream, streamDesc.mIndexCur, output, outputDesc->device(), delayMs);
2207 // in the device used for phone strategy and play the tone if the selected device does not
2208 // interfere with the device used for phone strategy
2214 LOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
2228 if (outputDesc->device() & getDeviceForStrategy(STRATEGY_PHONE)) {
2259 uint32_t device)
2290 uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::device()
2292 uint32_t device = 0;
2294 device = mOutput1->mDevice | mOutput2->mDevice;
2296 device = mDevice;
2298 return device;
2353 snprintf(buffer, SIZE, " Devices %08x\n", device());