Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 17 | #include <map> |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 18 | #include <memory> |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 19 | #include <string> |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 20 | #include <sys/wait.h> |
| 21 | #include <unistd.h> |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 22 | |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 23 | #include <gtest/gtest.h> |
| 24 | |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 25 | #define LOG_TAG "APM_Test" |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 26 | #include <Serializer.h> |
| 27 | #include <android-base/file.h> |
| 28 | #include <media/AudioPolicy.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 29 | #include <media/PatchBuilder.h> |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 30 | #include <media/RecordingActivityTracker.h> |
| 31 | #include <utils/Log.h> |
| 32 | #include <utils/Vector.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 33 | |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 34 | #include "AudioPolicyInterface.h" |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 35 | #include "AudioPolicyTestClient.h" |
| 36 | #include "AudioPolicyTestManager.h" |
| 37 | |
| 38 | using namespace android; |
| 39 | |
Mikhail Naganov | e13c679 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 40 | TEST(AudioPolicyManagerTestInit, EngineFailure) { |
| 41 | AudioPolicyTestClient client; |
| 42 | AudioPolicyTestManager manager(&client); |
| 43 | manager.getConfig().setDefault(); |
| 44 | manager.getConfig().setEngineLibraryNameSuffix("non-existent"); |
| 45 | ASSERT_EQ(NO_INIT, manager.initialize()); |
| 46 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 47 | } |
| 48 | |
| 49 | TEST(AudioPolicyManagerTestInit, ClientFailure) { |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 50 | AudioPolicyTestClient client; |
| 51 | AudioPolicyTestManager manager(&client); |
| 52 | manager.getConfig().setDefault(); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 53 | // Since the default client fails to open anything, |
| 54 | // APM should indicate that the initialization didn't succeed. |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 55 | ASSERT_EQ(NO_INIT, manager.initialize()); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 56 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 57 | } |
| 58 | |
| 59 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 60 | class AudioPolicyManagerTestClient : public AudioPolicyTestClient { |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 61 | public: |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 62 | // AudioPolicyClientInterface implementation |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 63 | audio_module_handle_t loadHwModule(const char* /*name*/) override { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 64 | return mNextModuleHandle++; |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 65 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 66 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 67 | status_t openOutput(audio_module_handle_t module, |
| 68 | audio_io_handle_t* output, |
| 69 | audio_config_t* /*config*/, |
| 70 | audio_devices_t* /*devices*/, |
| 71 | const String8& /*address*/, |
| 72 | uint32_t* /*latencyMs*/, |
| 73 | audio_output_flags_t /*flags*/) override { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 74 | if (module >= mNextModuleHandle) { |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 75 | ALOGE("%s: Module handle %d has not been allocated yet (next is %d)", |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 76 | __func__, module, mNextModuleHandle); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 77 | return BAD_VALUE; |
| 78 | } |
| 79 | *output = mNextIoHandle++; |
| 80 | return NO_ERROR; |
| 81 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 82 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 83 | status_t openInput(audio_module_handle_t module, |
| 84 | audio_io_handle_t* input, |
| 85 | audio_config_t* /*config*/, |
| 86 | audio_devices_t* /*device*/, |
| 87 | const String8& /*address*/, |
| 88 | audio_source_t /*source*/, |
| 89 | audio_input_flags_t /*flags*/) override { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 90 | if (module >= mNextModuleHandle) { |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 91 | ALOGE("%s: Module handle %d has not been allocated yet (next is %d)", |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 92 | __func__, module, mNextModuleHandle); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 93 | return BAD_VALUE; |
| 94 | } |
| 95 | *input = mNextIoHandle++; |
| 96 | return NO_ERROR; |
| 97 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 98 | |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 99 | status_t createAudioPatch(const struct audio_patch* patch, |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 100 | audio_patch_handle_t* handle, |
| 101 | int /*delayMs*/) override { |
| 102 | *handle = mNextPatchHandle++; |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 103 | mActivePatches.insert(std::make_pair(*handle, *patch)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 104 | return NO_ERROR; |
| 105 | } |
| 106 | |
| 107 | status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 108 | int /*delayMs*/) override { |
| 109 | if (mActivePatches.erase(handle) != 1) { |
| 110 | if (handle >= mNextPatchHandle) { |
| 111 | ALOGE("%s: Patch handle %d has not been allocated yet (next is %d)", |
| 112 | __func__, handle, mNextPatchHandle); |
| 113 | } else { |
| 114 | ALOGE("%s: Attempt to release patch %d twice", __func__, handle); |
| 115 | } |
| 116 | return BAD_VALUE; |
| 117 | } |
| 118 | return NO_ERROR; |
| 119 | } |
| 120 | |
| 121 | // Helper methods for tests |
| 122 | size_t getActivePatchesCount() const { return mActivePatches.size(); } |
| 123 | |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 124 | const struct audio_patch* getLastAddedPatch() const { |
| 125 | if (mActivePatches.empty()) { |
| 126 | return nullptr; |
| 127 | } |
| 128 | auto it = --mActivePatches.end(); |
| 129 | return &it->second; |
| 130 | }; |
| 131 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 132 | private: |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 133 | audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1; |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 134 | audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1; |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 135 | audio_patch_handle_t mNextPatchHandle = AUDIO_PATCH_HANDLE_NONE + 1; |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 136 | std::map<audio_patch_handle_t, struct audio_patch> mActivePatches; |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 137 | }; |
| 138 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 139 | class PatchCountCheck { |
| 140 | public: |
| 141 | explicit PatchCountCheck(AudioPolicyManagerTestClient *client) |
| 142 | : mClient{client}, |
| 143 | mInitialCount{mClient->getActivePatchesCount()} {} |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 144 | int deltaFromSnapshot() const { |
| 145 | size_t currentCount = mClient->getActivePatchesCount(); |
| 146 | if (mInitialCount <= currentCount) { |
| 147 | return currentCount - mInitialCount; |
| 148 | } else { |
| 149 | return -(static_cast<int>(mInitialCount - currentCount)); |
| 150 | } |
| 151 | } |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 152 | private: |
| 153 | const AudioPolicyManagerTestClient *mClient; |
| 154 | const size_t mInitialCount; |
| 155 | }; |
| 156 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 157 | class AudioPolicyManagerTest : public testing::Test { |
| 158 | protected: |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 159 | void SetUp() override; |
| 160 | void TearDown() override; |
| 161 | virtual void SetUpConfig(AudioPolicyConfig *config) { (void)config; } |
| 162 | |
| 163 | void dumpToLog(); |
| 164 | void getOutputForAttr( |
| 165 | audio_port_handle_t *selectedDeviceId, |
| 166 | audio_format_t format, |
| 167 | int channelMask, |
| 168 | int sampleRate, |
| 169 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 170 | audio_port_handle_t *portId = nullptr, |
| 171 | audio_attributes_t attr = {}); |
| 172 | void getInputForAttr( |
| 173 | const audio_attributes_t &attr, |
| 174 | audio_unique_id_t riid, |
| 175 | audio_port_handle_t *selectedDeviceId, |
| 176 | audio_format_t format, |
| 177 | int channelMask, |
| 178 | int sampleRate, |
| 179 | audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 180 | audio_port_handle_t *portId = nullptr); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 181 | PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 182 | |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 183 | void findDevicePort(audio_port_role_t role, audio_devices_t deviceType, |
| 184 | const std::string &address, audio_port &foundPort); |
| 185 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 186 | std::unique_ptr<AudioPolicyManagerTestClient> mClient; |
| 187 | std::unique_ptr<AudioPolicyTestManager> mManager; |
| 188 | }; |
| 189 | |
| 190 | void AudioPolicyManagerTest::SetUp() { |
| 191 | mClient.reset(new AudioPolicyManagerTestClient); |
| 192 | mManager.reset(new AudioPolicyTestManager(mClient.get())); |
| 193 | mManager->getConfig().setDefault(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 194 | SetUpConfig(&mManager->getConfig()); // Subclasses may want to customize the config. |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 195 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 196 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 197 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 198 | |
| 199 | void AudioPolicyManagerTest::TearDown() { |
| 200 | mManager.reset(); |
| 201 | mClient.reset(); |
| 202 | } |
| 203 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 204 | void AudioPolicyManagerTest::dumpToLog() { |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 205 | int pipefd[2]; |
| 206 | ASSERT_NE(-1, pipe(pipefd)); |
| 207 | pid_t cpid = fork(); |
| 208 | ASSERT_NE(-1, cpid); |
| 209 | if (cpid == 0) { |
| 210 | // Child process reads from the pipe and logs. |
| 211 | close(pipefd[1]); |
| 212 | std::string line; |
| 213 | char buf; |
| 214 | while (read(pipefd[0], &buf, sizeof(buf)) > 0) { |
| 215 | if (buf != '\n') { |
| 216 | line += buf; |
| 217 | } else { |
| 218 | ALOGI("%s", line.c_str()); |
| 219 | line = ""; |
| 220 | } |
| 221 | } |
| 222 | if (!line.empty()) ALOGI("%s", line.c_str()); |
| 223 | close(pipefd[0]); |
| 224 | _exit(EXIT_SUCCESS); |
| 225 | } else { |
| 226 | // Parent does the dump and checks the status code. |
| 227 | close(pipefd[0]); |
| 228 | ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); |
| 229 | close(pipefd[1]); |
| 230 | wait(NULL); // Wait for the child to exit. |
| 231 | } |
| 232 | } |
| 233 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 234 | void AudioPolicyManagerTest::getOutputForAttr( |
| 235 | audio_port_handle_t *selectedDeviceId, |
| 236 | audio_format_t format, |
| 237 | int channelMask, |
| 238 | int sampleRate, |
| 239 | audio_output_flags_t flags, |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 240 | audio_port_handle_t *portId, |
| 241 | audio_attributes_t attr) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 242 | audio_io_handle_t output = AUDIO_PORT_HANDLE_NONE; |
| 243 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 244 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 245 | config.sample_rate = sampleRate; |
| 246 | config.channel_mask = channelMask; |
| 247 | config.format = format; |
| 248 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 249 | audio_port_handle_t localPortId; |
| 250 | if (!portId) portId = &localPortId; |
| 251 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 252 | ASSERT_EQ(OK, mManager->getOutputForAttr( |
| 253 | &attr, &output, AUDIO_SESSION_NONE, &stream, 0 /*uid*/, &config, &flags, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 254 | selectedDeviceId, portId, {})); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 255 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 256 | } |
| 257 | |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 258 | void AudioPolicyManagerTest::getInputForAttr( |
| 259 | const audio_attributes_t &attr, |
| 260 | audio_unique_id_t riid, |
| 261 | audio_port_handle_t *selectedDeviceId, |
| 262 | audio_format_t format, |
| 263 | int channelMask, |
| 264 | int sampleRate, |
| 265 | audio_input_flags_t flags, |
| 266 | audio_port_handle_t *portId) { |
| 267 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 268 | audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER; |
| 269 | config.sample_rate = sampleRate; |
| 270 | config.channel_mask = channelMask; |
| 271 | config.format = format; |
| 272 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 273 | audio_port_handle_t localPortId; |
| 274 | if (!portId) portId = &localPortId; |
| 275 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 276 | AudioPolicyInterface::input_type_t inputType; |
| 277 | ASSERT_EQ(OK, mManager->getInputForAttr( |
| 278 | &attr, &input, riid, AUDIO_SESSION_NONE, 0 /*uid*/, &config, flags, |
| 279 | selectedDeviceId, &inputType, portId)); |
| 280 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 281 | } |
| 282 | |
| 283 | void AudioPolicyManagerTest::findDevicePort(audio_port_role_t role, |
| 284 | audio_devices_t deviceType, const std::string &address, audio_port &foundPort) { |
| 285 | uint32_t numPorts = 0; |
| 286 | uint32_t generation1; |
| 287 | status_t ret; |
| 288 | |
| 289 | ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, nullptr, &generation1); |
| 290 | ASSERT_EQ(NO_ERROR, ret); |
| 291 | |
| 292 | uint32_t generation2; |
| 293 | struct audio_port ports[numPorts]; |
| 294 | ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, ports, &generation2); |
| 295 | ASSERT_EQ(NO_ERROR, ret); |
| 296 | ASSERT_EQ(generation1, generation2); |
| 297 | |
| 298 | for (const auto &port : ports) { |
| 299 | if (port.role == role && port.ext.device.type == deviceType && |
| 300 | (strncmp(port.ext.device.address, address.c_str(), |
| 301 | AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0)) { |
| 302 | foundPort = port; |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | GTEST_FAIL(); |
| 307 | } |
| 308 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 309 | |
| 310 | TEST_F(AudioPolicyManagerTest, InitSuccess) { |
| 311 | // SetUp must finish with no assertions. |
| 312 | } |
| 313 | |
| 314 | TEST_F(AudioPolicyManagerTest, Dump) { |
| 315 | dumpToLog(); |
| 316 | } |
| 317 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 318 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { |
| 319 | audio_patch patch{}; |
| 320 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 321 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 322 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(nullptr, &handle, 0)); |
| 323 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, nullptr, 0)); |
| 324 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 325 | patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1; |
| 326 | patch.num_sinks = 1; |
| 327 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 328 | patch.num_sources = 1; |
| 329 | patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1; |
| 330 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 331 | patch.num_sources = 2; |
| 332 | patch.num_sinks = 1; |
| 333 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 334 | patch = {}; |
| 335 | patch.num_sources = 1; |
| 336 | patch.sources[0].role = AUDIO_PORT_ROLE_SINK; |
| 337 | patch.num_sinks = 1; |
| 338 | patch.sinks[0].role = AUDIO_PORT_ROLE_SINK; |
| 339 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 340 | patch = {}; |
| 341 | patch.num_sources = 1; |
| 342 | patch.sources[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 343 | patch.num_sinks = 1; |
| 344 | patch.sinks[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 345 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 346 | // Verify that the handle is left unchanged. |
| 347 | ASSERT_EQ(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 348 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFromMix) { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 352 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 353 | uid_t uid = 42; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 354 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 355 | ASSERT_FALSE(mManager->getConfig().getAvailableInputDevices().isEmpty()); |
| 356 | PatchBuilder patchBuilder; |
| 357 | patchBuilder.addSource(mManager->getConfig().getAvailableInputDevices()[0]). |
| 358 | addSink(mManager->getConfig().getDefaultOutputDevice()); |
| 359 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 360 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 361 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | // TODO: Add patch creation tests that involve already existing patch |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 365 | |
| 366 | class AudioPolicyManagerTestMsd : public AudioPolicyManagerTest { |
| 367 | protected: |
| 368 | void SetUpConfig(AudioPolicyConfig *config) override; |
| 369 | void TearDown() override; |
| 370 | |
| 371 | sp<DeviceDescriptor> mMsdOutputDevice; |
| 372 | sp<DeviceDescriptor> mMsdInputDevice; |
| 373 | }; |
| 374 | |
| 375 | void AudioPolicyManagerTestMsd::SetUpConfig(AudioPolicyConfig *config) { |
| 376 | // TODO: Consider using Serializer to load part of the config from a string. |
| 377 | mMsdOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_BUS); |
| 378 | sp<AudioProfile> pcmOutputProfile = new AudioProfile( |
| 379 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 380 | sp<AudioProfile> ac3OutputProfile = new AudioProfile( |
| 381 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
| 382 | mMsdOutputDevice->addAudioProfile(pcmOutputProfile); |
| 383 | mMsdOutputDevice->addAudioProfile(ac3OutputProfile); |
| 384 | mMsdInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUS); |
| 385 | // Match output profile from AudioPolicyConfig::setDefault. |
| 386 | sp<AudioProfile> pcmInputProfile = new AudioProfile( |
| 387 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, 44100); |
| 388 | mMsdInputDevice->addAudioProfile(pcmInputProfile); |
| 389 | config->addAvailableDevice(mMsdOutputDevice); |
| 390 | config->addAvailableDevice(mMsdInputDevice); |
| 391 | |
| 392 | sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 2 /*halVersionMajor*/); |
| 393 | HwModuleCollection modules = config->getHwModules(); |
| 394 | modules.add(msdModule); |
| 395 | config->setHwModules(modules); |
| 396 | mMsdOutputDevice->attach(msdModule); |
| 397 | mMsdInputDevice->attach(msdModule); |
| 398 | |
| 399 | sp<OutputProfile> msdOutputProfile = new OutputProfile(String8("msd input")); |
| 400 | msdOutputProfile->addAudioProfile(pcmOutputProfile); |
| 401 | msdOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 402 | msdModule->addOutputProfile(msdOutputProfile); |
| 403 | sp<OutputProfile> msdCompressedOutputProfile = |
| 404 | new OutputProfile(String8("msd compressed input")); |
| 405 | msdCompressedOutputProfile->addAudioProfile(ac3OutputProfile); |
| 406 | msdCompressedOutputProfile->setFlags( |
| 407 | AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | |
| 408 | AUDIO_OUTPUT_FLAG_NON_BLOCKING); |
| 409 | msdCompressedOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 410 | msdModule->addOutputProfile(msdCompressedOutputProfile); |
| 411 | |
| 412 | sp<InputProfile> msdInputProfile = new InputProfile(String8("msd output")); |
| 413 | msdInputProfile->addAudioProfile(pcmInputProfile); |
| 414 | msdInputProfile->addSupportedDevice(mMsdInputDevice); |
| 415 | msdModule->addInputProfile(msdInputProfile); |
| 416 | |
| 417 | // Add a profile with another encoding to the default device to test routing |
| 418 | // of streams that are not supported by MSD. |
| 419 | sp<AudioProfile> dtsOutputProfile = new AudioProfile( |
| 420 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
| 421 | config->getDefaultOutputDevice()->addAudioProfile(dtsOutputProfile); |
| 422 | sp<OutputProfile> primaryEncodedOutputProfile = new OutputProfile(String8("encoded")); |
| 423 | primaryEncodedOutputProfile->addAudioProfile(dtsOutputProfile); |
| 424 | primaryEncodedOutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
| 425 | primaryEncodedOutputProfile->addSupportedDevice(config->getDefaultOutputDevice()); |
| 426 | config->getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
| 427 | addOutputProfile(primaryEncodedOutputProfile); |
| 428 | } |
| 429 | |
| 430 | void AudioPolicyManagerTestMsd::TearDown() { |
| 431 | mMsdOutputDevice.clear(); |
| 432 | mMsdInputDevice.clear(); |
| 433 | AudioPolicyManagerTest::TearDown(); |
| 434 | } |
| 435 | |
| 436 | TEST_F(AudioPolicyManagerTestMsd, InitSuccess) { |
| 437 | ASSERT_TRUE(mMsdOutputDevice); |
| 438 | ASSERT_TRUE(mMsdInputDevice); |
| 439 | } |
| 440 | |
| 441 | TEST_F(AudioPolicyManagerTestMsd, Dump) { |
| 442 | dumpToLog(); |
| 443 | } |
| 444 | |
| 445 | TEST_F(AudioPolicyManagerTestMsd, PatchCreationOnSetForceUse) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 446 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 447 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, |
| 448 | AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 449 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 453 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 454 | audio_port_handle_t selectedDeviceId; |
| 455 | getOutputForAttr(&selectedDeviceId, |
| 456 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 457 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 458 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 462 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 463 | audio_port_handle_t selectedDeviceId; |
| 464 | getOutputForAttr(&selectedDeviceId, |
| 465 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 466 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 467 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedPlusPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 471 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 472 | audio_port_handle_t selectedDeviceId; |
| 473 | getOutputForAttr(&selectedDeviceId, |
| 474 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 475 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 476 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 477 | getOutputForAttr(&selectedDeviceId, |
| 478 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 479 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 480 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrUnsupportedFormatBypassesMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 484 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 485 | audio_port_handle_t selectedDeviceId; |
| 486 | getOutputForAttr(&selectedDeviceId, |
| 487 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 488 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 489 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrFormatSwitching) { |
| 493 | // Switch between formats that are supported and not supported by MSD. |
| 494 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 495 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 496 | audio_port_handle_t selectedDeviceId, portId; |
| 497 | getOutputForAttr(&selectedDeviceId, |
| 498 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
| 499 | &portId); |
| 500 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 501 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 502 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 503 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 504 | } |
| 505 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 506 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 507 | audio_port_handle_t selectedDeviceId, portId; |
| 508 | getOutputForAttr(&selectedDeviceId, |
| 509 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
| 510 | &portId); |
| 511 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 512 | ASSERT_EQ(-1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 513 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 514 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 515 | } |
| 516 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 517 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 518 | audio_port_handle_t selectedDeviceId; |
| 519 | getOutputForAttr(&selectedDeviceId, |
| 520 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 521 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 522 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 523 | } |
| 524 | } |
jiabin | 723ed13 | 2019-08-28 15:31:47 -0700 | [diff] [blame^] | 525 | |
| 526 | using PolicyMixTuple = std::tuple<audio_usage_t, audio_source_t, uint32_t>; |
| 527 | |
| 528 | class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTest { |
| 529 | protected: |
| 530 | void SetUp() override; |
| 531 | void TearDown() override; |
| 532 | |
| 533 | status_t addPolicyMix(int mixType, int mixFlag, audio_devices_t deviceType, |
| 534 | std::string mixAddress, const audio_config_t& audioConfig, |
| 535 | const std::vector<PolicyMixTuple>& rules); |
| 536 | void clearPolicyMix(); |
| 537 | void resetManager(const std::string& configFileName); |
| 538 | audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch* patch); |
| 539 | |
| 540 | Vector<AudioMix> mAudioMixes; |
| 541 | const std::string mExecutableDir = base::GetExecutableDirectory(); |
| 542 | const std::string mConfig = mExecutableDir + "/test_audio_policy_configuration.xml"; |
| 543 | const std::string mPrimaryOnlyConfig = mExecutableDir + |
| 544 | "/test_audio_policy_primary_only_configuration.xml"; |
| 545 | const std::string mMixAddress = "remote_submix_media"; |
| 546 | }; |
| 547 | |
| 548 | void AudioPolicyManagerTestDynamicPolicy::SetUp() { |
| 549 | // Override Setup function to use configuration file to do initialization. |
| 550 | mClient.reset(new AudioPolicyManagerTestClient); |
| 551 | resetManager(mConfig); |
| 552 | } |
| 553 | |
| 554 | void AudioPolicyManagerTestDynamicPolicy::TearDown() { |
| 555 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 556 | AudioPolicyManagerTest::TearDown(); |
| 557 | } |
| 558 | |
| 559 | status_t AudioPolicyManagerTestDynamicPolicy::addPolicyMix(int mixType, int mixFlag, |
| 560 | audio_devices_t deviceType, std::string mixAddress, const audio_config_t& audioConfig, |
| 561 | const std::vector<PolicyMixTuple>& rules) { |
| 562 | Vector<AudioMixMatchCriterion> myMixMatchCriteria; |
| 563 | |
| 564 | for(const auto &rule: rules) { |
| 565 | myMixMatchCriteria.add(AudioMixMatchCriterion( |
| 566 | std::get<0>(rule), std::get<1>(rule), std::get<2>(rule))); |
| 567 | } |
| 568 | |
| 569 | AudioMix myAudioMix(myMixMatchCriteria, mixType, audioConfig, mixFlag, |
| 570 | String8(mixAddress.c_str()), 0); |
| 571 | myAudioMix.mDeviceType = deviceType; |
| 572 | // Clear mAudioMix before add new one to make sure we don't add already exist mixes. |
| 573 | mAudioMixes.clear(); |
| 574 | mAudioMixes.add(myAudioMix); |
| 575 | |
| 576 | // As the policy mixes registration may fail at some case, |
| 577 | // caller need to check the returned status. |
| 578 | status_t ret = mManager->registerPolicyMixes(mAudioMixes); |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | void AudioPolicyManagerTestDynamicPolicy::clearPolicyMix() { |
| 583 | if (mManager != nullptr) { |
| 584 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 585 | } |
| 586 | mAudioMixes.clear(); |
| 587 | } |
| 588 | |
| 589 | void AudioPolicyManagerTestDynamicPolicy::resetManager(const std::string& configFileName) { |
| 590 | clearPolicyMix(); |
| 591 | mManager.reset(new AudioPolicyTestManager(mClient.get())); |
| 592 | status_t status = deserializeAudioPolicyFile(configFileName.c_str(), &mManager->getConfig()); |
| 593 | ASSERT_EQ(NO_ERROR, status); |
| 594 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 595 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
| 596 | } |
| 597 | |
| 598 | audio_port_handle_t AudioPolicyManagerTestDynamicPolicy::getDeviceIdFromPatch( |
| 599 | const struct audio_patch* patch) { |
| 600 | // The logic here is the same as the one in AudioIoDescriptor. |
| 601 | // Note this function is aim to get routed device id for test. |
| 602 | // In that case, device to device patch is not expected here. |
| 603 | if (patch->num_sources != 0 && patch->num_sinks != 0) { |
| 604 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
| 605 | return patch->sinks[0].id; |
| 606 | } else { |
| 607 | return patch->sources[0].id; |
| 608 | } |
| 609 | } |
| 610 | return AUDIO_PORT_HANDLE_NONE; |
| 611 | } |
| 612 | |
| 613 | TEST_F(AudioPolicyManagerTestDynamicPolicy, InitSuccess) { |
| 614 | // SetUp must finish with no assertions. |
| 615 | } |
| 616 | |
| 617 | TEST_F(AudioPolicyManagerTestDynamicPolicy, Dump) { |
| 618 | dumpToLog(); |
| 619 | } |
| 620 | |
| 621 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyMixes) { |
| 622 | status_t ret; |
| 623 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 624 | |
| 625 | // Only capture of playback is allowed in LOOP_BACK &RENDER mode |
| 626 | ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER, |
| 627 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 628 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 629 | |
| 630 | // Fail due to the device is already connected. |
| 631 | clearPolicyMix(); |
| 632 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 633 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 634 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 635 | |
| 636 | // The first time to register policy mixes with valid parameter should succeed. |
| 637 | clearPolicyMix(); |
| 638 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 639 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 640 | audioConfig.sample_rate = 48000; |
| 641 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 642 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 643 | std::vector<PolicyMixTuple>()); |
| 644 | ASSERT_EQ(NO_ERROR, ret); |
| 645 | // Registering the same policy mixes should fail. |
| 646 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 647 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 648 | |
| 649 | // Registration should fail due to not module for remote submix found. |
| 650 | resetManager(mPrimaryOnlyConfig); |
| 651 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 652 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 653 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 654 | |
| 655 | // Registration should fail due to device not found. |
| 656 | // Note that earpiece is not present in the test configuration file. |
| 657 | // This will need to be updated if earpiece is added in the test configuration file. |
| 658 | resetManager(mConfig); |
| 659 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 660 | AUDIO_DEVICE_OUT_EARPIECE, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 661 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 662 | |
| 663 | // Registration should fail due to output not found. |
| 664 | clearPolicyMix(); |
| 665 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 666 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 667 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 668 | |
| 669 | // The first time to register valid policy mixes should succeed. |
| 670 | clearPolicyMix(); |
| 671 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 672 | AUDIO_DEVICE_OUT_SPEAKER, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 673 | ASSERT_EQ(NO_ERROR, ret); |
| 674 | // Registering the same policy mixes should fail. |
| 675 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 676 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 677 | } |
| 678 | |
| 679 | TEST_F(AudioPolicyManagerTestDynamicPolicy, UnregisterPolicyMixes) { |
| 680 | status_t ret; |
| 681 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 682 | |
| 683 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 684 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 685 | audioConfig.sample_rate = 48000; |
| 686 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 687 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 688 | std::vector<PolicyMixTuple>()); |
| 689 | ASSERT_EQ(NO_ERROR, ret); |
| 690 | |
| 691 | // After successfully registering policy mixes, it should be able to unregister. |
| 692 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 693 | ASSERT_EQ(NO_ERROR, ret); |
| 694 | |
| 695 | // After unregistering policy mixes successfully, it should fail unregistering |
| 696 | // the same policy mixes as they are not registered. |
| 697 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 698 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 699 | |
| 700 | resetManager(mPrimaryOnlyConfig); |
| 701 | // Create a fake policy mixes, the unregistration should fail due to no remote |
| 702 | // submix module found. |
| 703 | mAudioMixes.add(AudioMix(Vector<AudioMixMatchCriterion>(), MIX_TYPE_PLAYERS, |
| 704 | audioConfig, MIX_ROUTE_FLAG_LOOP_BACK, String8(mMixAddress.c_str()), 0)); |
| 705 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 706 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 707 | } |
| 708 | |
| 709 | class AudioPolicyManagerTestDPPlaybackReRouting : public AudioPolicyManagerTestDynamicPolicy, |
| 710 | public testing::WithParamInterface<audio_attributes_t> { |
| 711 | protected: |
| 712 | void SetUp() override; |
| 713 | void TearDown() override; |
| 714 | |
| 715 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 716 | |
| 717 | std::vector<PolicyMixTuple> mUsageRules = { |
| 718 | {AUDIO_USAGE_MEDIA, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE}, |
| 719 | {AUDIO_USAGE_ALARM, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE} |
| 720 | }; |
| 721 | |
| 722 | struct audio_port mInjectionPort; |
| 723 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 724 | }; |
| 725 | |
| 726 | void AudioPolicyManagerTestDPPlaybackReRouting::SetUp() { |
| 727 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 728 | |
| 729 | mTracker.reset(new RecordingActivityTracker()); |
| 730 | |
| 731 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 732 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 733 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 734 | audioConfig.sample_rate = 48000; |
| 735 | status_t ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 736 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, mUsageRules); |
| 737 | ASSERT_EQ(NO_ERROR, ret); |
| 738 | |
| 739 | struct audio_port extractionPort; |
| 740 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 741 | mMixAddress, extractionPort); |
| 742 | |
| 743 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 744 | audio_source_t source = AUDIO_SOURCE_REMOTE_SUBMIX; |
| 745 | audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, 0, ""}; |
| 746 | std::string tags = "addr=" + mMixAddress; |
| 747 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 748 | getInputForAttr(attr, mTracker->getRiid(), &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 749 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &mPortId); |
| 750 | ASSERT_EQ(NO_ERROR, mManager->startInput(mPortId)); |
| 751 | ASSERT_EQ(extractionPort.id, selectedDeviceId); |
| 752 | |
| 753 | findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 754 | mMixAddress, mInjectionPort); |
| 755 | } |
| 756 | |
| 757 | void AudioPolicyManagerTestDPPlaybackReRouting::TearDown() { |
| 758 | mManager->stopInput(mPortId); |
| 759 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 760 | } |
| 761 | |
| 762 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, InitSuccess) { |
| 763 | // SetUp must finish with no assertions |
| 764 | } |
| 765 | |
| 766 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, Dump) { |
| 767 | dumpToLog(); |
| 768 | } |
| 769 | |
| 770 | TEST_P(AudioPolicyManagerTestDPPlaybackReRouting, PlaybackReRouting) { |
| 771 | const audio_attributes_t attr = GetParam(); |
| 772 | const audio_usage_t usage = attr.usage; |
| 773 | |
| 774 | audio_port_handle_t playbackRoutedPortId; |
| 775 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 776 | getOutputForAttr(&playbackRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 777 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, &portId, attr); |
| 778 | if (std::find_if(begin(mUsageRules), end(mUsageRules), [&usage](const auto &usageRule) { |
| 779 | return (std::get<0>(usageRule) == usage) && |
| 780 | (std::get<2>(usageRule) == RULE_MATCH_ATTRIBUTE_USAGE);}) != end(mUsageRules) || |
| 781 | (strncmp(attr.tags, "addr=", strlen("addr=")) == 0 && |
| 782 | strncmp(attr.tags + strlen("addr="), mMixAddress.c_str(), |
| 783 | AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - strlen("addr=") - 1) == 0)) { |
| 784 | EXPECT_EQ(mInjectionPort.id, playbackRoutedPortId); |
| 785 | } else { |
| 786 | EXPECT_NE(mInjectionPort.id, playbackRoutedPortId); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | INSTANTIATE_TEST_CASE_P( |
| 791 | PlaybackReroutingUsageMatch, |
| 792 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 793 | testing::Values( |
| 794 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
| 795 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 796 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
| 797 | AUDIO_SOURCE_DEFAULT, 0, ""} |
| 798 | ) |
| 799 | ); |
| 800 | |
| 801 | INSTANTIATE_TEST_CASE_P( |
| 802 | PlaybackReroutingAddressPriorityMatch, |
| 803 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 804 | testing::Values( |
| 805 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
| 806 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 807 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
| 808 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 809 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 810 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 811 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 812 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
| 813 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 814 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
| 815 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 816 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 817 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
| 818 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 819 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 820 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
| 821 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 822 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 823 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
| 824 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 825 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 826 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
| 827 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 828 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
| 829 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 830 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 831 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
| 832 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 833 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 834 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 835 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 836 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 837 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
| 838 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 839 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
| 840 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 841 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VIRTUAL_SOURCE, |
| 842 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 843 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
| 844 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"} |
| 845 | ) |
| 846 | ); |
| 847 | |
| 848 | INSTANTIATE_TEST_CASE_P( |
| 849 | PlaybackReroutingUnHandledUsages, |
| 850 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 851 | testing::Values( |
| 852 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
| 853 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 854 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 855 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 856 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 857 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
| 858 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 859 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 860 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
| 861 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 862 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 863 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
| 864 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 865 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 866 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
| 867 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 868 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 869 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
| 870 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 871 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
| 872 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 873 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 874 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
| 875 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 876 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 877 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 878 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 879 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 880 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
| 881 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 882 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
| 883 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 884 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
| 885 | AUDIO_SOURCE_DEFAULT, 0, ""} |
| 886 | ) |
| 887 | ); |
| 888 | |
| 889 | class AudioPolicyManagerTestDPMixRecordInjection : public AudioPolicyManagerTestDynamicPolicy, |
| 890 | public testing::WithParamInterface<audio_attributes_t> { |
| 891 | protected: |
| 892 | void SetUp() override; |
| 893 | void TearDown() override; |
| 894 | |
| 895 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 896 | |
| 897 | std::vector<PolicyMixTuple> mSourceRules = { |
| 898 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_CAMCORDER, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 899 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_MIC, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 900 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_VOICE_COMMUNICATION, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET} |
| 901 | }; |
| 902 | |
| 903 | struct audio_port mExtractionPort; |
| 904 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 905 | }; |
| 906 | |
| 907 | void AudioPolicyManagerTestDPMixRecordInjection::SetUp() { |
| 908 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 909 | |
| 910 | mTracker.reset(new RecordingActivityTracker()); |
| 911 | |
| 912 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 913 | audioConfig.channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 914 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 915 | audioConfig.sample_rate = 48000; |
| 916 | status_t ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 917 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, mMixAddress, audioConfig, mSourceRules); |
| 918 | ASSERT_EQ(NO_ERROR, ret); |
| 919 | |
| 920 | struct audio_port injectionPort; |
| 921 | findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 922 | mMixAddress, injectionPort); |
| 923 | |
| 924 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 925 | audio_usage_t usage = AUDIO_USAGE_VIRTUAL_SOURCE; |
| 926 | audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, 0, ""}; |
| 927 | std::string tags = std::string("addr=") + mMixAddress; |
| 928 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 929 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 930 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, &mPortId, attr); |
| 931 | ASSERT_EQ(NO_ERROR, mManager->startOutput(mPortId)); |
| 932 | ASSERT_EQ(injectionPort.id, getDeviceIdFromPatch(mClient->getLastAddedPatch())); |
| 933 | |
| 934 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 935 | mMixAddress, mExtractionPort); |
| 936 | } |
| 937 | |
| 938 | void AudioPolicyManagerTestDPMixRecordInjection::TearDown() { |
| 939 | mManager->stopOutput(mPortId); |
| 940 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 941 | } |
| 942 | |
| 943 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, InitSuccess) { |
| 944 | // SetUp mush finish with no assertions. |
| 945 | } |
| 946 | |
| 947 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, Dump) { |
| 948 | dumpToLog(); |
| 949 | } |
| 950 | |
| 951 | TEST_P(AudioPolicyManagerTestDPMixRecordInjection, RecordingInjection) { |
| 952 | const audio_attributes_t attr = GetParam(); |
| 953 | const audio_source_t source = attr.source; |
| 954 | |
| 955 | audio_port_handle_t captureRoutedPortId; |
| 956 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 957 | getInputForAttr(attr, mTracker->getRiid(), &captureRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, |
| 958 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &portId); |
| 959 | if (std::find_if(begin(mSourceRules), end(mSourceRules), [&source](const auto &sourceRule) { |
| 960 | return (std::get<1>(sourceRule) == source) && |
| 961 | (std::get<2>(sourceRule) == RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET);}) |
| 962 | != end(mSourceRules)) { |
| 963 | EXPECT_EQ(mExtractionPort.id, captureRoutedPortId); |
| 964 | } else { |
| 965 | EXPECT_NE(mExtractionPort.id, captureRoutedPortId); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | // No address priority rule for remote recording, address is a "don't care" |
| 970 | INSTANTIATE_TEST_CASE_P( |
| 971 | RecordInjectionSourceMatch, |
| 972 | AudioPolicyManagerTestDPMixRecordInjection, |
| 973 | testing::Values( |
| 974 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 975 | AUDIO_SOURCE_CAMCORDER, 0, ""}, |
| 976 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 977 | AUDIO_SOURCE_CAMCORDER, 0, "addr=remote_submix_media"}, |
| 978 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 979 | AUDIO_SOURCE_MIC, 0, "addr=remote_submix_media"}, |
| 980 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 981 | AUDIO_SOURCE_MIC, 0, ""}, |
| 982 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 983 | AUDIO_SOURCE_VOICE_COMMUNICATION, 0, ""}, |
| 984 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 985 | AUDIO_SOURCE_VOICE_COMMUNICATION, 0, |
| 986 | "addr=remote_submix_media"} |
| 987 | ) |
| 988 | ); |
| 989 | |
| 990 | // No address priority rule for remote recording |
| 991 | INSTANTIATE_TEST_CASE_P( |
| 992 | RecordInjectionSourceNotMatch, |
| 993 | AudioPolicyManagerTestDPMixRecordInjection, |
| 994 | testing::Values( |
| 995 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 996 | AUDIO_SOURCE_VOICE_RECOGNITION, 0, ""}, |
| 997 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 998 | AUDIO_SOURCE_HOTWORD, 0, ""}, |
| 999 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 1000 | AUDIO_SOURCE_VOICE_RECOGNITION, 0, |
| 1001 | "addr=remote_submix_media"}, |
| 1002 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 1003 | AUDIO_SOURCE_HOTWORD, 0, "addr=remote_submix_media"} |
| 1004 | ) |
| 1005 | ); |