Loading media/libaudiofoundation/AudioContainers.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,13 @@ const DeviceTypeSet& getAudioDeviceOutAllScoSet() { return audioDeviceOutAllScoSet; } const DeviceTypeSet& getAudioDeviceOutAllUsbSet() { static const DeviceTypeSet audioDeviceOutAllUsbSet = DeviceTypeSet( std::begin(AUDIO_DEVICE_OUT_ALL_USB_ARRAY), std::end(AUDIO_DEVICE_OUT_ALL_USB_ARRAY)); return audioDeviceOutAllUsbSet; } const DeviceTypeSet& getAudioDeviceInAllSet() { static const DeviceTypeSet audioDeviceInAllSet = DeviceTypeSet( std::begin(AUDIO_DEVICE_IN_ALL_ARRAY), Loading @@ -49,6 +56,13 @@ const DeviceTypeSet& getAudioDeviceInAllSet() { return audioDeviceInAllSet; } const DeviceTypeSet& getAudioDeviceInAllUsbSet() { static const DeviceTypeSet audioDeviceInAllUsbSet = DeviceTypeSet( std::begin(AUDIO_DEVICE_IN_ALL_USB_ARRAY), std::end(AUDIO_DEVICE_IN_ALL_USB_ARRAY)); return audioDeviceInAllUsbSet; } bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) { if (deviceTypes.empty()) { str = "Empty device types"; Loading media/libaudiofoundation/include/media/AudioContainers.h +2 −0 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ using FormatVector = std::vector<audio_format_t>; const DeviceTypeSet& getAudioDeviceOutAllSet(); const DeviceTypeSet& getAudioDeviceOutAllA2dpSet(); const DeviceTypeSet& getAudioDeviceOutAllScoSet(); const DeviceTypeSet& getAudioDeviceOutAllUsbSet(); const DeviceTypeSet& getAudioDeviceInAllSet(); const DeviceTypeSet& getAudioDeviceInAllUsbSet(); template<typename T> static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) { Loading media/libaudiohal/impl/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ cc_defaults { "android.hardware.audio.common-util", "android.hidl.allocator@1.0", "android.hidl.memory@1.0", "libaudiofoundation", "libaudiohal_deathhandler", "libaudioutils", "libbase", Loading media/libaudiohal/impl/ConversionHelperHidl.cpp +9 −12 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <string.h> #define LOG_TAG "HalHidl" #include <media/AudioContainers.h> #include <media/AudioParameter.h> #include <utils/Log.h> Loading Loading @@ -109,26 +110,22 @@ static std::string deviceAddressToHal(const DeviceAddress& address) { char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN]; memset(halAddress, 0, sizeof(halAddress)); audio_devices_t halDevice = static_cast<audio_devices_t>(address.device); const bool isInput = (halDevice & AUDIO_DEVICE_BIT_IN) != 0; if (isInput) halDevice &= ~AUDIO_DEVICE_BIT_IN; if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) { if (getAudioDeviceOutAllA2dpSet().count(halDevice) > 0 || halDevice == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) { snprintf(halAddress, sizeof(halAddress), "%02X:%02X:%02X:%02X:%02X:%02X", address.address.mac[0], address.address.mac[1], address.address.mac[2], address.address.mac[3], address.address.mac[4], address.address.mac[5]); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_IP) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_IP) != 0)) { } else if (halDevice == AUDIO_DEVICE_OUT_IP || halDevice == AUDIO_DEVICE_IN_IP) { snprintf(halAddress, sizeof(halAddress), "%d.%d.%d.%d", address.address.ipv4[0], address.address.ipv4[1], address.address.ipv4[2], address.address.ipv4[3]); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0)) { } else if (getAudioDeviceOutAllUsbSet().count(halDevice) > 0 || getAudioDeviceInAllUsbSet().count(halDevice) > 0) { snprintf(halAddress, sizeof(halAddress), "card=%d;device=%d", address.address.alsa.card, address.address.alsa.device); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_BUS) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_BUS) != 0)) { } else if (halDevice == AUDIO_DEVICE_OUT_BUS || halDevice == AUDIO_DEVICE_IN_BUS) { snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str()); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0 || (isInput && (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) { } else if (halDevice == AUDIO_DEVICE_OUT_REMOTE_SUBMIX || halDevice == AUDIO_DEVICE_IN_REMOTE_SUBMIX) { snprintf(halAddress, sizeof(halAddress), "%s", address.rSubmixAddress.c_str()); } else { snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str()); Loading media/libaudiohal/impl/DeviceHalHidl.cpp +13 −22 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) #include <cutils/native_handle.h> #include <hwbinder/IPCThreadState.h> #include <media/AudioContainers.h> #include <utils/Log.h> #include <common/all-versions/VersionUtils.h> Loading Loading @@ -51,43 +52,33 @@ status_t deviceAddressFromHal( if (halAddress == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) { return OK; } const bool isInput = (device & AUDIO_DEVICE_BIT_IN) != 0; if (isInput) device &= ~AUDIO_DEVICE_BIT_IN; if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_A2DP) != 0) || (isInput && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) { if (getAudioDeviceOutAllA2dpSet().count(device) > 0 || device == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) { int status = sscanf(halAddress, "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX", &address->address.mac[0], &address->address.mac[1], &address->address.mac[2], &address->address.mac[3], &address->address.mac[4], &address->address.mac[5]); return status == 6 ? OK : BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_IP) != 0) || (isInput && (device & AUDIO_DEVICE_IN_IP) != 0)) { } else if (device == AUDIO_DEVICE_OUT_IP || device == AUDIO_DEVICE_IN_IP) { int status = sscanf(halAddress, "%hhu.%hhu.%hhu.%hhu", &address->address.ipv4[0], &address->address.ipv4[1], &address->address.ipv4[2], &address->address.ipv4[3]); return status == 4 ? OK : BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_USB)) != 0 || (isInput && (device & AUDIO_DEVICE_IN_ALL_USB)) != 0) { } else if (getAudioDeviceOutAllUsbSet().count(device) > 0 || getAudioDeviceInAllUsbSet().count(device) > 0) { int status = sscanf(halAddress, "card=%d;device=%d", &address->address.alsa.card, &address->address.alsa.device); return status == 2 ? OK : BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_BUS) != 0) || (isInput && (device & AUDIO_DEVICE_IN_BUS) != 0)) { if (halAddress != NULL) { } else if (device == AUDIO_DEVICE_OUT_BUS || device == AUDIO_DEVICE_IN_BUS) { address->busAddress = halAddress; return OK; } return BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0 || (isInput && (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) { if (halAddress != NULL) { } else if (device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX || device == AUDIO_DEVICE_IN_REMOTE_SUBMIX) { address->rSubmixAddress = halAddress; return OK; } return BAD_VALUE; } return OK; } Loading Loading
media/libaudiofoundation/AudioContainers.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,13 @@ const DeviceTypeSet& getAudioDeviceOutAllScoSet() { return audioDeviceOutAllScoSet; } const DeviceTypeSet& getAudioDeviceOutAllUsbSet() { static const DeviceTypeSet audioDeviceOutAllUsbSet = DeviceTypeSet( std::begin(AUDIO_DEVICE_OUT_ALL_USB_ARRAY), std::end(AUDIO_DEVICE_OUT_ALL_USB_ARRAY)); return audioDeviceOutAllUsbSet; } const DeviceTypeSet& getAudioDeviceInAllSet() { static const DeviceTypeSet audioDeviceInAllSet = DeviceTypeSet( std::begin(AUDIO_DEVICE_IN_ALL_ARRAY), Loading @@ -49,6 +56,13 @@ const DeviceTypeSet& getAudioDeviceInAllSet() { return audioDeviceInAllSet; } const DeviceTypeSet& getAudioDeviceInAllUsbSet() { static const DeviceTypeSet audioDeviceInAllUsbSet = DeviceTypeSet( std::begin(AUDIO_DEVICE_IN_ALL_USB_ARRAY), std::end(AUDIO_DEVICE_IN_ALL_USB_ARRAY)); return audioDeviceInAllUsbSet; } bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) { if (deviceTypes.empty()) { str = "Empty device types"; Loading
media/libaudiofoundation/include/media/AudioContainers.h +2 −0 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ using FormatVector = std::vector<audio_format_t>; const DeviceTypeSet& getAudioDeviceOutAllSet(); const DeviceTypeSet& getAudioDeviceOutAllA2dpSet(); const DeviceTypeSet& getAudioDeviceOutAllScoSet(); const DeviceTypeSet& getAudioDeviceOutAllUsbSet(); const DeviceTypeSet& getAudioDeviceInAllSet(); const DeviceTypeSet& getAudioDeviceInAllUsbSet(); template<typename T> static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) { Loading
media/libaudiohal/impl/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ cc_defaults { "android.hardware.audio.common-util", "android.hidl.allocator@1.0", "android.hidl.memory@1.0", "libaudiofoundation", "libaudiohal_deathhandler", "libaudioutils", "libbase", Loading
media/libaudiohal/impl/ConversionHelperHidl.cpp +9 −12 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <string.h> #define LOG_TAG "HalHidl" #include <media/AudioContainers.h> #include <media/AudioParameter.h> #include <utils/Log.h> Loading Loading @@ -109,26 +110,22 @@ static std::string deviceAddressToHal(const DeviceAddress& address) { char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN]; memset(halAddress, 0, sizeof(halAddress)); audio_devices_t halDevice = static_cast<audio_devices_t>(address.device); const bool isInput = (halDevice & AUDIO_DEVICE_BIT_IN) != 0; if (isInput) halDevice &= ~AUDIO_DEVICE_BIT_IN; if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) { if (getAudioDeviceOutAllA2dpSet().count(halDevice) > 0 || halDevice == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) { snprintf(halAddress, sizeof(halAddress), "%02X:%02X:%02X:%02X:%02X:%02X", address.address.mac[0], address.address.mac[1], address.address.mac[2], address.address.mac[3], address.address.mac[4], address.address.mac[5]); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_IP) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_IP) != 0)) { } else if (halDevice == AUDIO_DEVICE_OUT_IP || halDevice == AUDIO_DEVICE_IN_IP) { snprintf(halAddress, sizeof(halAddress), "%d.%d.%d.%d", address.address.ipv4[0], address.address.ipv4[1], address.address.ipv4[2], address.address.ipv4[3]); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0)) { } else if (getAudioDeviceOutAllUsbSet().count(halDevice) > 0 || getAudioDeviceInAllUsbSet().count(halDevice) > 0) { snprintf(halAddress, sizeof(halAddress), "card=%d;device=%d", address.address.alsa.card, address.address.alsa.device); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_BUS) != 0) || (isInput && (halDevice & AUDIO_DEVICE_IN_BUS) != 0)) { } else if (halDevice == AUDIO_DEVICE_OUT_BUS || halDevice == AUDIO_DEVICE_IN_BUS) { snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str()); } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0 || (isInput && (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) { } else if (halDevice == AUDIO_DEVICE_OUT_REMOTE_SUBMIX || halDevice == AUDIO_DEVICE_IN_REMOTE_SUBMIX) { snprintf(halAddress, sizeof(halAddress), "%s", address.rSubmixAddress.c_str()); } else { snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str()); Loading
media/libaudiohal/impl/DeviceHalHidl.cpp +13 −22 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) #include <cutils/native_handle.h> #include <hwbinder/IPCThreadState.h> #include <media/AudioContainers.h> #include <utils/Log.h> #include <common/all-versions/VersionUtils.h> Loading Loading @@ -51,43 +52,33 @@ status_t deviceAddressFromHal( if (halAddress == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) { return OK; } const bool isInput = (device & AUDIO_DEVICE_BIT_IN) != 0; if (isInput) device &= ~AUDIO_DEVICE_BIT_IN; if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_A2DP) != 0) || (isInput && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) { if (getAudioDeviceOutAllA2dpSet().count(device) > 0 || device == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) { int status = sscanf(halAddress, "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX", &address->address.mac[0], &address->address.mac[1], &address->address.mac[2], &address->address.mac[3], &address->address.mac[4], &address->address.mac[5]); return status == 6 ? OK : BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_IP) != 0) || (isInput && (device & AUDIO_DEVICE_IN_IP) != 0)) { } else if (device == AUDIO_DEVICE_OUT_IP || device == AUDIO_DEVICE_IN_IP) { int status = sscanf(halAddress, "%hhu.%hhu.%hhu.%hhu", &address->address.ipv4[0], &address->address.ipv4[1], &address->address.ipv4[2], &address->address.ipv4[3]); return status == 4 ? OK : BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_USB)) != 0 || (isInput && (device & AUDIO_DEVICE_IN_ALL_USB)) != 0) { } else if (getAudioDeviceOutAllUsbSet().count(device) > 0 || getAudioDeviceInAllUsbSet().count(device) > 0) { int status = sscanf(halAddress, "card=%d;device=%d", &address->address.alsa.card, &address->address.alsa.device); return status == 2 ? OK : BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_BUS) != 0) || (isInput && (device & AUDIO_DEVICE_IN_BUS) != 0)) { if (halAddress != NULL) { } else if (device == AUDIO_DEVICE_OUT_BUS || device == AUDIO_DEVICE_IN_BUS) { address->busAddress = halAddress; return OK; } return BAD_VALUE; } else if ((!isInput && (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0 || (isInput && (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) { if (halAddress != NULL) { } else if (device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX || device == AUDIO_DEVICE_IN_REMOTE_SUBMIX) { address->rSubmixAddress = halAddress; return OK; } return BAD_VALUE; } return OK; } Loading