Loading services/audiopolicy/common/managerdefinitions/include/AudioPolicyConfig.h +18 −14 Original line number Diff line number Diff line Loading @@ -38,12 +38,12 @@ public: AudioPolicyConfig(HwModuleCollection &hwModules, DeviceVector &availableOutputDevices, DeviceVector &availableInputDevices, sp<DeviceDescriptor> &defaultOutputDevices, sp<DeviceDescriptor> &defaultOutputDevice, VolumeCurvesCollection *volumes = nullptr) : mHwModules(hwModules), mAvailableOutputDevices(availableOutputDevices), mAvailableInputDevices(availableInputDevices), mDefaultOutputDevices(defaultOutputDevices), mDefaultOutputDevice(defaultOutputDevice), mVolumeCurves(volumes), mIsSpeakerDrcEnabled(false) {} Loading Loading @@ -108,40 +108,44 @@ public: void setDefaultOutputDevice(const sp<DeviceDescriptor> &defaultDevice) { mDefaultOutputDevices = defaultDevice; mDefaultOutputDevice = defaultDevice; } const sp<DeviceDescriptor> &getDefaultOutputDevice() const { return mDefaultOutputDevices; } const sp<DeviceDescriptor> &getDefaultOutputDevice() const { return mDefaultOutputDevice; } void setDefault(void) { mSource = "AudioPolicyConfig::setDefault"; mDefaultOutputDevices = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER); sp<HwModule> module; mDefaultOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER); mDefaultOutputDevice->addAudioProfile(AudioProfile::createFullDynamic()); sp<DeviceDescriptor> defaultInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUILTIN_MIC); mAvailableOutputDevices.add(mDefaultOutputDevices); defaultInputDevice->addAudioProfile(AudioProfile::createFullDynamic()); sp<AudioProfile> micProfile = new AudioProfile( AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000); defaultInputDevice->addAudioProfile(micProfile); mAvailableOutputDevices.add(mDefaultOutputDevice); mAvailableInputDevices.add(defaultInputDevice); module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY); sp<HwModule> module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY, 2 /*halVersionMajor*/); mHwModules.add(module); mDefaultOutputDevice->attach(module); defaultInputDevice->attach(module); sp<OutputProfile> outProfile; outProfile = new OutputProfile(String8("primary")); outProfile->attach(module); outProfile->addAudioProfile( new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 44100)); outProfile->addSupportedDevice(mDefaultOutputDevices); outProfile->addSupportedDevice(mDefaultOutputDevice); outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY); module->addOutputProfile(outProfile); sp<InputProfile> inProfile; inProfile = new InputProfile(String8("primary")); inProfile->attach(module); inProfile->addAudioProfile( new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000)); inProfile->addAudioProfile(micProfile); inProfile->addSupportedDevice(defaultInputDevice); module->addInputProfile(inProfile); mHwModules.add(module); } private: Loading @@ -149,7 +153,7 @@ private: HwModuleCollection &mHwModules; /**< Collection of Module, with Profiles, i.e. Mix Ports. */ DeviceVector &mAvailableOutputDevices; DeviceVector &mAvailableInputDevices; sp<DeviceDescriptor> &mDefaultOutputDevices; sp<DeviceDescriptor> &mDefaultOutputDevice; VolumeCurvesCollection *mVolumeCurves; // TODO: remove when legacy conf file is removed. true on devices that use DRC on the // DEVICE_CATEGORY_SPEAKER path to boost soft sounds, used to adjust volume curves accordingly. Loading services/audiopolicy/common/managerdefinitions/include/AudioProfile.h +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ bool operator == (const SortedVector<T> &left, const SortedVector<T> &right); class AudioProfile : public virtual RefBase { public: static sp<AudioProfile> createFullDynamic(); AudioProfile(audio_format_t format, audio_channel_mask_t channelMasks, uint32_t samplingRate) : Loading services/audiopolicy/common/managerdefinitions/src/AudioProfile.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,23 @@ namespace android { static AudioProfile* createFullDynamicImpl() { AudioProfile* dynamicProfile = new AudioProfile(gDynamicFormat, ChannelsVector(), SampleRateVector()); dynamicProfile->setDynamicFormat(true); dynamicProfile->setDynamicChannels(true); dynamicProfile->setDynamicRate(true); return dynamicProfile; } // static sp<AudioProfile> AudioProfile::createFullDynamic() { static sp<AudioProfile> dynamicProfile = createFullDynamicImpl(); return dynamicProfile; } status_t AudioProfile::checkExact(uint32_t samplingRate, audio_channel_mask_t channelMask, audio_format_t format) const { Loading services/audiopolicy/common/managerdefinitions/src/Serializer.cpp +2 −12 Original line number Diff line number Diff line Loading @@ -242,12 +242,7 @@ status_t MixPortTraits::deserialize(_xmlDoc *doc, const _xmlNode *child, PtrElem AudioProfileTraits::Collection profiles; deserializeCollection<AudioProfileTraits>(doc, child, profiles, NULL); if (profiles.isEmpty()) { sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat, ChannelsVector(), SampleRateVector()); dynamicProfile->setDynamicFormat(true); dynamicProfile->setDynamicChannels(true); dynamicProfile->setDynamicRate(true); profiles.add(dynamicProfile); profiles.add(AudioProfile::createFullDynamic()); } mixPort->setAudioProfiles(profiles); Loading Loading @@ -328,12 +323,7 @@ status_t DevicePortTraits::deserialize(_xmlDoc *doc, const _xmlNode *root, PtrEl AudioProfileTraits::Collection profiles; deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL); if (profiles.isEmpty()) { sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat, ChannelsVector(), SampleRateVector()); dynamicProfile->setDynamicFormat(true); dynamicProfile->setDynamicChannels(true); dynamicProfile->setDynamicRate(true); profiles.add(dynamicProfile); profiles.add(AudioProfile::createFullDynamic()); } deviceDesc->setAudioProfiles(profiles); Loading services/audiopolicy/tests/audiopolicymanager_tests.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,13 @@ #include <memory> #include <set> #include <sys/wait.h> #include <unistd.h> #include <gtest/gtest.h> #define LOG_TAG "APM_Test" #include <log/log.h> #include <media/PatchBuilder.h> #include "AudioPolicyTestClient.h" Loading Loading @@ -134,6 +138,36 @@ TEST_F(AudioPolicyManagerTest, InitSuccess) { // SetUp must finish with no assertions. } TEST_F(AudioPolicyManagerTest, Dump) { int pipefd[2]; ASSERT_NE(-1, pipe(pipefd)); pid_t cpid = fork(); ASSERT_NE(-1, cpid); if (cpid == 0) { // Child process reads from the pipe and logs. close(pipefd[1]); std::string line; char buf; while (read(pipefd[0], &buf, sizeof(buf)) > 0) { if (buf != '\n') { line += buf; } else { ALOGI("%s", line.c_str()); line = ""; } } if (!line.empty()) ALOGI("%s", line.c_str()); close(pipefd[0]); _exit(EXIT_SUCCESS); } else { // Parent does the dump and checks the status code. close(pipefd[0]); ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); close(pipefd[1]); wait(NULL); // Wait for the child to exit. } } TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { audio_patch patch{}; audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; Loading Loading
services/audiopolicy/common/managerdefinitions/include/AudioPolicyConfig.h +18 −14 Original line number Diff line number Diff line Loading @@ -38,12 +38,12 @@ public: AudioPolicyConfig(HwModuleCollection &hwModules, DeviceVector &availableOutputDevices, DeviceVector &availableInputDevices, sp<DeviceDescriptor> &defaultOutputDevices, sp<DeviceDescriptor> &defaultOutputDevice, VolumeCurvesCollection *volumes = nullptr) : mHwModules(hwModules), mAvailableOutputDevices(availableOutputDevices), mAvailableInputDevices(availableInputDevices), mDefaultOutputDevices(defaultOutputDevices), mDefaultOutputDevice(defaultOutputDevice), mVolumeCurves(volumes), mIsSpeakerDrcEnabled(false) {} Loading Loading @@ -108,40 +108,44 @@ public: void setDefaultOutputDevice(const sp<DeviceDescriptor> &defaultDevice) { mDefaultOutputDevices = defaultDevice; mDefaultOutputDevice = defaultDevice; } const sp<DeviceDescriptor> &getDefaultOutputDevice() const { return mDefaultOutputDevices; } const sp<DeviceDescriptor> &getDefaultOutputDevice() const { return mDefaultOutputDevice; } void setDefault(void) { mSource = "AudioPolicyConfig::setDefault"; mDefaultOutputDevices = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER); sp<HwModule> module; mDefaultOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER); mDefaultOutputDevice->addAudioProfile(AudioProfile::createFullDynamic()); sp<DeviceDescriptor> defaultInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUILTIN_MIC); mAvailableOutputDevices.add(mDefaultOutputDevices); defaultInputDevice->addAudioProfile(AudioProfile::createFullDynamic()); sp<AudioProfile> micProfile = new AudioProfile( AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000); defaultInputDevice->addAudioProfile(micProfile); mAvailableOutputDevices.add(mDefaultOutputDevice); mAvailableInputDevices.add(defaultInputDevice); module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY); sp<HwModule> module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY, 2 /*halVersionMajor*/); mHwModules.add(module); mDefaultOutputDevice->attach(module); defaultInputDevice->attach(module); sp<OutputProfile> outProfile; outProfile = new OutputProfile(String8("primary")); outProfile->attach(module); outProfile->addAudioProfile( new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 44100)); outProfile->addSupportedDevice(mDefaultOutputDevices); outProfile->addSupportedDevice(mDefaultOutputDevice); outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY); module->addOutputProfile(outProfile); sp<InputProfile> inProfile; inProfile = new InputProfile(String8("primary")); inProfile->attach(module); inProfile->addAudioProfile( new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000)); inProfile->addAudioProfile(micProfile); inProfile->addSupportedDevice(defaultInputDevice); module->addInputProfile(inProfile); mHwModules.add(module); } private: Loading @@ -149,7 +153,7 @@ private: HwModuleCollection &mHwModules; /**< Collection of Module, with Profiles, i.e. Mix Ports. */ DeviceVector &mAvailableOutputDevices; DeviceVector &mAvailableInputDevices; sp<DeviceDescriptor> &mDefaultOutputDevices; sp<DeviceDescriptor> &mDefaultOutputDevice; VolumeCurvesCollection *mVolumeCurves; // TODO: remove when legacy conf file is removed. true on devices that use DRC on the // DEVICE_CATEGORY_SPEAKER path to boost soft sounds, used to adjust volume curves accordingly. Loading
services/audiopolicy/common/managerdefinitions/include/AudioProfile.h +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ bool operator == (const SortedVector<T> &left, const SortedVector<T> &right); class AudioProfile : public virtual RefBase { public: static sp<AudioProfile> createFullDynamic(); AudioProfile(audio_format_t format, audio_channel_mask_t channelMasks, uint32_t samplingRate) : Loading
services/audiopolicy/common/managerdefinitions/src/AudioProfile.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,23 @@ namespace android { static AudioProfile* createFullDynamicImpl() { AudioProfile* dynamicProfile = new AudioProfile(gDynamicFormat, ChannelsVector(), SampleRateVector()); dynamicProfile->setDynamicFormat(true); dynamicProfile->setDynamicChannels(true); dynamicProfile->setDynamicRate(true); return dynamicProfile; } // static sp<AudioProfile> AudioProfile::createFullDynamic() { static sp<AudioProfile> dynamicProfile = createFullDynamicImpl(); return dynamicProfile; } status_t AudioProfile::checkExact(uint32_t samplingRate, audio_channel_mask_t channelMask, audio_format_t format) const { Loading
services/audiopolicy/common/managerdefinitions/src/Serializer.cpp +2 −12 Original line number Diff line number Diff line Loading @@ -242,12 +242,7 @@ status_t MixPortTraits::deserialize(_xmlDoc *doc, const _xmlNode *child, PtrElem AudioProfileTraits::Collection profiles; deserializeCollection<AudioProfileTraits>(doc, child, profiles, NULL); if (profiles.isEmpty()) { sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat, ChannelsVector(), SampleRateVector()); dynamicProfile->setDynamicFormat(true); dynamicProfile->setDynamicChannels(true); dynamicProfile->setDynamicRate(true); profiles.add(dynamicProfile); profiles.add(AudioProfile::createFullDynamic()); } mixPort->setAudioProfiles(profiles); Loading Loading @@ -328,12 +323,7 @@ status_t DevicePortTraits::deserialize(_xmlDoc *doc, const _xmlNode *root, PtrEl AudioProfileTraits::Collection profiles; deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL); if (profiles.isEmpty()) { sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat, ChannelsVector(), SampleRateVector()); dynamicProfile->setDynamicFormat(true); dynamicProfile->setDynamicChannels(true); dynamicProfile->setDynamicRate(true); profiles.add(dynamicProfile); profiles.add(AudioProfile::createFullDynamic()); } deviceDesc->setAudioProfiles(profiles); Loading
services/audiopolicy/tests/audiopolicymanager_tests.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,13 @@ #include <memory> #include <set> #include <sys/wait.h> #include <unistd.h> #include <gtest/gtest.h> #define LOG_TAG "APM_Test" #include <log/log.h> #include <media/PatchBuilder.h> #include "AudioPolicyTestClient.h" Loading Loading @@ -134,6 +138,36 @@ TEST_F(AudioPolicyManagerTest, InitSuccess) { // SetUp must finish with no assertions. } TEST_F(AudioPolicyManagerTest, Dump) { int pipefd[2]; ASSERT_NE(-1, pipe(pipefd)); pid_t cpid = fork(); ASSERT_NE(-1, cpid); if (cpid == 0) { // Child process reads from the pipe and logs. close(pipefd[1]); std::string line; char buf; while (read(pipefd[0], &buf, sizeof(buf)) > 0) { if (buf != '\n') { line += buf; } else { ALOGI("%s", line.c_str()); line = ""; } } if (!line.empty()) ALOGI("%s", line.c_str()); close(pipefd[0]); _exit(EXIT_SUCCESS); } else { // Parent does the dump and checks the status code. close(pipefd[0]); ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); close(pipefd[1]); wait(NULL); // Wait for the child to exit. } } TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { audio_patch patch{}; audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; Loading