Loading services/audiopolicy/managerdefault/AudioPolicyManager.cpp +27 −6 Original line number Diff line number Diff line Loading @@ -206,6 +206,9 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript // Reset active device codec device->setEncodedFormat(AUDIO_FORMAT_DEFAULT); // remove device from mReportedFormatsMap cache mReportedFormatsMap.erase(device); } break; default: Loading Loading @@ -334,6 +337,9 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript mAvailableInputDevices.remove(device); checkInputsForDevice(device, state); // remove device from mReportedFormatsMap cache mReportedFormatsMap.erase(device); } break; default: Loading Loading @@ -4332,14 +4338,28 @@ status_t AudioPolicyManager::getSurroundFormats(unsigned int *numSurroundFormats // checkOutputsForDevice(). for (size_t i = 0; i < mAvailableOutputDevices.size(); i++) { sp<DeviceDescriptor> device = mAvailableOutputDevices[i]; FormatVector supportedFormats = device->getAudioPort()->getAudioProfiles().getSupportedFormats(); for (size_t j = 0; j < supportedFormats.size(); j++) { if (mConfig.getSurroundFormats().count(supportedFormats[j]) != 0) { formats.insert(supportedFormats[j]); audio_devices_t deviceType = device->type(); // Enabling/disabling formats are applied to only HDMI devices. So, this function // returns formats reported by HDMI devices. if (deviceType != AUDIO_DEVICE_OUT_HDMI) { continue; } // Formats reported by sink devices std::unordered_set<audio_format_t> formatset; if (auto it = mReportedFormatsMap.find(device); it != mReportedFormatsMap.end()) { formatset.insert(it->second.begin(), it->second.end()); } // Formats hard-coded in the in policy configuration file (if any). FormatVector encodedFormats = device->encodedFormats(); formatset.insert(encodedFormats.begin(), encodedFormats.end()); // Filter the formats which are supported by the vendor hardware. for (auto it = formatset.begin(); it != formatset.end(); ++it) { if (mConfig.getSurroundFormats().count(*it) != 0) { formats.insert(*it); } else { for (const auto& pair : mConfig.getSurroundFormats()) { if (pair.second.count(supportedFormats[j]) != 0) { if (pair.second.count(*it) != 0) { formats.insert(pair.first); break; } Loading Loading @@ -6538,6 +6558,7 @@ void AudioPolicyManager::updateAudioProfiles(const sp<DeviceDescriptor>& devDesc return; } FormatVector formats = formatsFromString(reply.string()); mReportedFormatsMap[devDesc] = formats; if (device == AUDIO_DEVICE_OUT_HDMI || isDeviceOfModule(devDesc, AUDIO_HARDWARE_MODULE_ID_MSD)) { modifySurroundFormats(devDesc, &formats); Loading services/audiopolicy/managerdefault/AudioPolicyManager.h +3 −0 Original line number Diff line number Diff line Loading @@ -813,6 +813,9 @@ protected: std::unordered_set<audio_format_t> mManualSurroundFormats; std::unordered_map<uid_t, audio_flags_mask_t> mAllowedCapturePolicies; // The map of device descriptor and formats reported by the device. std::map<wp<DeviceDescriptor>, FormatVector> mReportedFormatsMap; private: void onNewAudioModulesAvailableInt(DeviceVector *newDevices); Loading services/audiopolicy/tests/AudioPolicyManagerTestClient.h +2 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,8 @@ public: size_t getAudioPortListUpdateCount() const { return mAudioPortListUpdateCount; } virtual void addSupportedFormat(audio_format_t /* format */) {} private: audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1; audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1; Loading services/audiopolicy/tests/AudioPolicyManagerTestClientForHdmi.h 0 → 100644 +46 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <map> #include <set> #include <system/audio.h> #include <utils/Log.h> #include <utils/String8.h> #include "AudioPolicyTestClient.h" namespace android { class AudioPolicyManagerTestClientForHdmi : public AudioPolicyManagerTestClient { public: String8 getParameters(audio_io_handle_t /* ioHandle */, const String8& /* keys*/ ) override { return mAudioParameters.toString(); } void addSupportedFormat(audio_format_t format) override { mAudioParameters.add( String8(AudioParameter::keyStreamSupportedFormats), String8(audio_format_to_string(format))); mAudioParameters.addInt(String8(AudioParameter::keyStreamSupportedSamplingRates), 48000); mAudioParameters.add(String8(AudioParameter::keyStreamSupportedChannels), String8("")); } private: AudioParameter mAudioParameters; }; } // namespace android No newline at end of file services/audiopolicy/tests/AudioPolicyTestManager.h +1 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ class AudioPolicyTestManager : public AudioPolicyManager { using AudioPolicyManager::getOutputs; using AudioPolicyManager::getAvailableOutputDevices; using AudioPolicyManager::getAvailableInputDevices; using AudioPolicyManager::setSurroundFormatEnabled; uint32_t getAudioPortGeneration() const { return mAudioPortGeneration; } }; Loading Loading
services/audiopolicy/managerdefault/AudioPolicyManager.cpp +27 −6 Original line number Diff line number Diff line Loading @@ -206,6 +206,9 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript // Reset active device codec device->setEncodedFormat(AUDIO_FORMAT_DEFAULT); // remove device from mReportedFormatsMap cache mReportedFormatsMap.erase(device); } break; default: Loading Loading @@ -334,6 +337,9 @@ status_t AudioPolicyManager::setDeviceConnectionStateInt(const sp<DeviceDescript mAvailableInputDevices.remove(device); checkInputsForDevice(device, state); // remove device from mReportedFormatsMap cache mReportedFormatsMap.erase(device); } break; default: Loading Loading @@ -4332,14 +4338,28 @@ status_t AudioPolicyManager::getSurroundFormats(unsigned int *numSurroundFormats // checkOutputsForDevice(). for (size_t i = 0; i < mAvailableOutputDevices.size(); i++) { sp<DeviceDescriptor> device = mAvailableOutputDevices[i]; FormatVector supportedFormats = device->getAudioPort()->getAudioProfiles().getSupportedFormats(); for (size_t j = 0; j < supportedFormats.size(); j++) { if (mConfig.getSurroundFormats().count(supportedFormats[j]) != 0) { formats.insert(supportedFormats[j]); audio_devices_t deviceType = device->type(); // Enabling/disabling formats are applied to only HDMI devices. So, this function // returns formats reported by HDMI devices. if (deviceType != AUDIO_DEVICE_OUT_HDMI) { continue; } // Formats reported by sink devices std::unordered_set<audio_format_t> formatset; if (auto it = mReportedFormatsMap.find(device); it != mReportedFormatsMap.end()) { formatset.insert(it->second.begin(), it->second.end()); } // Formats hard-coded in the in policy configuration file (if any). FormatVector encodedFormats = device->encodedFormats(); formatset.insert(encodedFormats.begin(), encodedFormats.end()); // Filter the formats which are supported by the vendor hardware. for (auto it = formatset.begin(); it != formatset.end(); ++it) { if (mConfig.getSurroundFormats().count(*it) != 0) { formats.insert(*it); } else { for (const auto& pair : mConfig.getSurroundFormats()) { if (pair.second.count(supportedFormats[j]) != 0) { if (pair.second.count(*it) != 0) { formats.insert(pair.first); break; } Loading Loading @@ -6538,6 +6558,7 @@ void AudioPolicyManager::updateAudioProfiles(const sp<DeviceDescriptor>& devDesc return; } FormatVector formats = formatsFromString(reply.string()); mReportedFormatsMap[devDesc] = formats; if (device == AUDIO_DEVICE_OUT_HDMI || isDeviceOfModule(devDesc, AUDIO_HARDWARE_MODULE_ID_MSD)) { modifySurroundFormats(devDesc, &formats); Loading
services/audiopolicy/managerdefault/AudioPolicyManager.h +3 −0 Original line number Diff line number Diff line Loading @@ -813,6 +813,9 @@ protected: std::unordered_set<audio_format_t> mManualSurroundFormats; std::unordered_map<uid_t, audio_flags_mask_t> mAllowedCapturePolicies; // The map of device descriptor and formats reported by the device. std::map<wp<DeviceDescriptor>, FormatVector> mReportedFormatsMap; private: void onNewAudioModulesAvailableInt(DeviceVector *newDevices); Loading
services/audiopolicy/tests/AudioPolicyManagerTestClient.h +2 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,8 @@ public: size_t getAudioPortListUpdateCount() const { return mAudioPortListUpdateCount; } virtual void addSupportedFormat(audio_format_t /* format */) {} private: audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1; audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1; Loading
services/audiopolicy/tests/AudioPolicyManagerTestClientForHdmi.h 0 → 100644 +46 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <map> #include <set> #include <system/audio.h> #include <utils/Log.h> #include <utils/String8.h> #include "AudioPolicyTestClient.h" namespace android { class AudioPolicyManagerTestClientForHdmi : public AudioPolicyManagerTestClient { public: String8 getParameters(audio_io_handle_t /* ioHandle */, const String8& /* keys*/ ) override { return mAudioParameters.toString(); } void addSupportedFormat(audio_format_t format) override { mAudioParameters.add( String8(AudioParameter::keyStreamSupportedFormats), String8(audio_format_to_string(format))); mAudioParameters.addInt(String8(AudioParameter::keyStreamSupportedSamplingRates), 48000); mAudioParameters.add(String8(AudioParameter::keyStreamSupportedChannels), String8("")); } private: AudioParameter mAudioParameters; }; } // namespace android No newline at end of file
services/audiopolicy/tests/AudioPolicyTestManager.h +1 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ class AudioPolicyTestManager : public AudioPolicyManager { using AudioPolicyManager::getOutputs; using AudioPolicyManager::getAvailableOutputDevices; using AudioPolicyManager::getAvailableInputDevices; using AudioPolicyManager::setSurroundFormatEnabled; uint32_t getAudioPortGeneration() const { return mAudioPortGeneration; } }; Loading