Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Mikhail Naganov | 872d4a6 | 2023-03-09 18:19:01 -0800 | [diff] [blame] | 17 | #define LOG_TAG "VtsHalDownmixTargetTest" |
| 18 | #include <android-base/logging.h> |
| 19 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 20 | #include <audio_utils/ChannelMix.h> |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 21 | #include "EffectHelper.h" |
| 22 | |
| 23 | using namespace android; |
| 24 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 25 | using aidl::android::hardware::audio::common::getChannelCount; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 26 | using aidl::android::hardware::audio::effect::Descriptor; |
| 27 | using aidl::android::hardware::audio::effect::Downmix; |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 28 | using aidl::android::hardware::audio::effect::getEffectTypeUuidDownmix; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 29 | using aidl::android::hardware::audio::effect::IEffect; |
| 30 | using aidl::android::hardware::audio::effect::IFactory; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 31 | using aidl::android::hardware::audio::effect::Parameter; |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 32 | using android::audio_utils::channels::ChannelMix; |
Jaideep Sharma | 7449841 | 2023-09-13 15:25:25 +0530 | [diff] [blame] | 33 | using android::hardware::audio::common::testing::detail::TestExecutionTracer; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 34 | |
Shunkai Yao | 6b7784e | 2024-01-03 18:27:45 +0000 | [diff] [blame] | 35 | // minimal HAL interface version to run downmix data path test |
| 36 | constexpr int32_t kMinDataTestHalVersion = 2; |
| 37 | |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 38 | // Testing for enum values |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 39 | static const std::vector<Downmix::Type> kTypeValues = {ndk::enum_range<Downmix::Type>().begin(), |
| 40 | ndk::enum_range<Downmix::Type>().end()}; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 41 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 42 | // Testing for supported layouts from AudioChannelLayout.h |
| 43 | static const std::vector<int32_t> kLayoutValues = { |
| 44 | AudioChannelLayout::LAYOUT_STEREO, AudioChannelLayout::LAYOUT_2POINT1, |
| 45 | AudioChannelLayout::LAYOUT_TRI, AudioChannelLayout::LAYOUT_TRI_BACK, |
| 46 | AudioChannelLayout::LAYOUT_3POINT1, AudioChannelLayout::LAYOUT_2POINT0POINT2, |
| 47 | AudioChannelLayout::LAYOUT_2POINT1POINT2, AudioChannelLayout::LAYOUT_3POINT0POINT2, |
| 48 | AudioChannelLayout::LAYOUT_3POINT1POINT2, AudioChannelLayout::LAYOUT_QUAD, |
| 49 | AudioChannelLayout::LAYOUT_QUAD_SIDE, AudioChannelLayout::LAYOUT_SURROUND, |
| 50 | AudioChannelLayout::LAYOUT_PENTA, AudioChannelLayout::LAYOUT_5POINT1, |
| 51 | AudioChannelLayout::LAYOUT_5POINT1_SIDE, AudioChannelLayout::LAYOUT_5POINT1POINT2, |
| 52 | AudioChannelLayout::LAYOUT_5POINT1POINT4, AudioChannelLayout::LAYOUT_6POINT1, |
| 53 | AudioChannelLayout::LAYOUT_7POINT1, AudioChannelLayout::LAYOUT_7POINT1POINT2, |
| 54 | AudioChannelLayout::LAYOUT_7POINT1POINT4, AudioChannelLayout::LAYOUT_9POINT1POINT4, |
| 55 | AudioChannelLayout::LAYOUT_9POINT1POINT6, AudioChannelLayout::LAYOUT_13POINT_360RA, |
| 56 | AudioChannelLayout::LAYOUT_22POINT2}; |
| 57 | |
| 58 | static const std::vector<int32_t> kChannels = { |
| 59 | AudioChannelLayout::CHANNEL_FRONT_LEFT, |
| 60 | AudioChannelLayout::CHANNEL_FRONT_RIGHT, |
| 61 | AudioChannelLayout::CHANNEL_FRONT_CENTER, |
| 62 | AudioChannelLayout::CHANNEL_LOW_FREQUENCY, |
| 63 | AudioChannelLayout::CHANNEL_BACK_LEFT, |
| 64 | AudioChannelLayout::CHANNEL_BACK_RIGHT, |
| 65 | AudioChannelLayout::CHANNEL_BACK_CENTER, |
| 66 | AudioChannelLayout::CHANNEL_SIDE_LEFT, |
| 67 | AudioChannelLayout::CHANNEL_SIDE_RIGHT, |
| 68 | AudioChannelLayout::CHANNEL_FRONT_LEFT_OF_CENTER, |
| 69 | AudioChannelLayout::CHANNEL_FRONT_RIGHT_OF_CENTER, |
| 70 | AudioChannelLayout::CHANNEL_TOP_CENTER, |
| 71 | AudioChannelLayout::CHANNEL_TOP_FRONT_LEFT, |
| 72 | AudioChannelLayout::CHANNEL_TOP_FRONT_CENTER, |
| 73 | AudioChannelLayout::CHANNEL_TOP_FRONT_RIGHT, |
| 74 | AudioChannelLayout::CHANNEL_TOP_BACK_LEFT, |
| 75 | AudioChannelLayout::CHANNEL_TOP_BACK_CENTER, |
| 76 | AudioChannelLayout::CHANNEL_TOP_BACK_RIGHT, |
| 77 | AudioChannelLayout::CHANNEL_TOP_SIDE_LEFT, |
| 78 | AudioChannelLayout::CHANNEL_TOP_SIDE_RIGHT, |
| 79 | AudioChannelLayout::CHANNEL_BOTTOM_FRONT_LEFT, |
| 80 | AudioChannelLayout::CHANNEL_BOTTOM_FRONT_CENTER, |
| 81 | AudioChannelLayout::CHANNEL_BOTTOM_FRONT_RIGHT, |
| 82 | AudioChannelLayout::CHANNEL_LOW_FREQUENCY_2, |
| 83 | AudioChannelLayout::CHANNEL_FRONT_WIDE_LEFT, |
| 84 | AudioChannelLayout::CHANNEL_FRONT_WIDE_RIGHT, |
| 85 | }; |
| 86 | |
| 87 | class DownmixEffectHelper : public EffectHelper { |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 88 | public: |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 89 | void SetUpDownmix(int32_t inputBufferLayout = AudioChannelLayout::LAYOUT_STEREO) { |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 90 | ASSERT_NE(nullptr, mFactory); |
| 91 | ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); |
| 92 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 93 | AudioChannelLayout inputChannelLayout = |
| 94 | AudioChannelLayout::make<AudioChannelLayout::layoutMask>(inputBufferLayout); |
| 95 | |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 96 | Parameter::Specific specific = getDefaultParamSpecific(); |
| 97 | Parameter::Common common = EffectHelper::createParamCommon( |
| 98 | 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */, |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 99 | kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */, |
| 100 | inputChannelLayout); |
| 101 | ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &mOpenEffectReturn, EX_NONE)); |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 102 | ASSERT_NE(nullptr, mEffect); |
| 103 | } |
| 104 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 105 | void TearDownDownmix() { |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 106 | ASSERT_NO_FATAL_FAILURE(close(mEffect)); |
| 107 | ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 108 | mOpenEffectReturn = IEffect::OpenEffectReturn{}; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 109 | } |
| 110 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 111 | Parameter createDownmixParam(Downmix::Type type) { |
| 112 | return Parameter::make<Parameter::specific>( |
| 113 | Parameter::Specific::make<Parameter::Specific::downmix>( |
| 114 | Downmix::make<Downmix::type>(type))); |
| 115 | } |
| 116 | void setParameters(Downmix::Type type) { |
| 117 | // set parameter |
| 118 | auto param = createDownmixParam(type); |
| 119 | EXPECT_STATUS(EX_NONE, mEffect->setParameter(param)) << param.toString(); |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 120 | } |
| 121 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 122 | void validateParameters(Downmix::Type type) { |
| 123 | auto leId = Downmix::Id::make<Downmix::Id::commonTag>(Downmix::Tag(Downmix::type)); |
| 124 | auto id = Parameter::Id::make<Parameter::Id::downmixTag>(leId); |
| 125 | // get parameter |
| 126 | Parameter getParam; |
| 127 | EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam)); |
| 128 | auto expectedParam = createDownmixParam(type); |
| 129 | EXPECT_EQ(expectedParam, getParam) << "\nexpectedParam:" << expectedParam.toString() |
| 130 | << "\ngetParam:" << getParam.toString(); |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | Parameter::Specific getDefaultParamSpecific() { |
| 134 | Downmix dm = Downmix::make<Downmix::type>(Downmix::Type::STRIP); |
| 135 | Parameter::Specific specific = Parameter::Specific::make<Parameter::Specific::downmix>(dm); |
| 136 | return specific; |
| 137 | } |
| 138 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 139 | void setDataTestParams(int32_t layoutType) { |
| 140 | mInputBuffer.resize(kBufferSize); |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 141 | |
| 142 | // Get the number of channels used |
| 143 | mInputChannelCount = getChannelCount( |
| 144 | AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layoutType)); |
| 145 | |
| 146 | // In case of downmix, output is always configured to stereo layout. |
| 147 | mOutputBufferSize = (mInputBuffer.size() / mInputChannelCount) * kOutputChannelCount; |
Shunkai Yao | 1319e98 | 2024-01-11 00:39:13 +0000 | [diff] [blame] | 148 | mOutputBuffer.resize(mOutputBufferSize); |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // Generate mInputBuffer values between -kMaxDownmixSample to kMaxDownmixSample |
| 152 | void generateInputBuffer(size_t position, bool isStrip) { |
| 153 | size_t increment; |
| 154 | if (isStrip) |
| 155 | // Fill input at all the channels |
| 156 | increment = 1; |
| 157 | else |
| 158 | // Fill input at only one channel |
| 159 | increment = mInputChannelCount; |
| 160 | |
| 161 | for (size_t i = position; i < mInputBuffer.size(); i += increment) { |
| 162 | mInputBuffer[i] = |
| 163 | ((static_cast<float>(std::rand()) / RAND_MAX) * 2 - 1) * kMaxDownmixSample; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | bool isLayoutValid(int32_t inputLayout) { |
| 168 | if (inputLayout & kMaxChannelMask) { |
| 169 | return false; |
| 170 | } |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | static constexpr long kInputFrameCount = 100, kOutputFrameCount = 100; |
| 175 | std::shared_ptr<IFactory> mFactory; |
| 176 | Descriptor mDescriptor; |
| 177 | std::shared_ptr<IEffect> mEffect; |
| 178 | IEffect::OpenEffectReturn mOpenEffectReturn; |
| 179 | |
| 180 | std::vector<float> mInputBuffer; |
| 181 | std::vector<float> mOutputBuffer; |
| 182 | size_t mInputChannelCount; |
| 183 | size_t mOutputBufferSize; |
| 184 | static constexpr size_t kBufferSize = 128; |
| 185 | static constexpr float kMaxDownmixSample = 1; |
| 186 | static constexpr int kOutputChannelCount = 2; |
| 187 | // Mask for layouts greater than MAX_INPUT_CHANNELS_SUPPORTED |
| 188 | static constexpr int32_t kMaxChannelMask = |
| 189 | ~((1 << ChannelMix<AUDIO_CHANNEL_OUT_STEREO>::MAX_INPUT_CHANNELS_SUPPORTED) - 1); |
| 190 | }; |
| 191 | |
| 192 | /** |
| 193 | * Here we focus on specific parameter checking, general IEffect interfaces testing performed in |
| 194 | * VtsAudioEffectTargetTest. |
| 195 | */ |
| 196 | enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE }; |
| 197 | |
| 198 | using DownmixParamTestParam = |
| 199 | std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>; |
| 200 | |
| 201 | class DownmixParamTest : public ::testing::TestWithParam<DownmixParamTestParam>, |
| 202 | public DownmixEffectHelper { |
| 203 | public: |
| 204 | DownmixParamTest() : mParamType(std::get<PARAM_TYPE>(GetParam())) { |
| 205 | std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam()); |
| 206 | } |
| 207 | |
| 208 | void SetUp() override { SetUpDownmix(); } |
| 209 | |
| 210 | void TearDown() override { TearDownDownmix(); } |
| 211 | |
| 212 | const Downmix::Type mParamType; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | TEST_P(DownmixParamTest, SetAndGetType) { |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 216 | ASSERT_NO_FATAL_FAILURE(setParameters(mParamType)); |
| 217 | ASSERT_NO_FATAL_FAILURE(validateParameters(mParamType)); |
| 218 | } |
| 219 | |
| 220 | enum FoldParamName { FOLD_INSTANCE_NAME, FOLD_INPUT_LAYOUT, FOLD_TEST_CHANNEL }; |
| 221 | |
| 222 | using DownmixDataTestParamFold = |
| 223 | std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t>; |
| 224 | |
| 225 | class DownmixFoldDataTest : public ::testing::TestWithParam<DownmixDataTestParamFold>, |
| 226 | public DownmixEffectHelper { |
| 227 | public: |
| 228 | DownmixFoldDataTest() : mInputChannelLayout(std::get<FOLD_INPUT_LAYOUT>(GetParam())) { |
| 229 | std::tie(mFactory, mDescriptor) = std::get<FOLD_INSTANCE_NAME>(GetParam()); |
| 230 | } |
| 231 | |
| 232 | void SetUp() override { |
| 233 | SetUpDownmix(mInputChannelLayout); |
Shunkai Yao | 6b7784e | 2024-01-03 18:27:45 +0000 | [diff] [blame] | 234 | if (int32_t version; |
| 235 | mEffect->getInterfaceVersion(&version).isOk() && version < kMinDataTestHalVersion) { |
| 236 | GTEST_SKIP() << "Skipping the data test for version: " << version << "\n"; |
| 237 | } |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 238 | if (!isLayoutValid(mInputChannelLayout)) { |
| 239 | GTEST_SKIP() << "Layout not supported \n"; |
| 240 | } |
| 241 | setDataTestParams(mInputChannelLayout); |
| 242 | } |
| 243 | |
| 244 | void TearDown() override { TearDownDownmix(); } |
| 245 | |
| 246 | void checkAtLeft(int32_t position) { |
| 247 | for (size_t i = 0, j = position; i < mOutputBufferSize; |
| 248 | i += kOutputChannelCount, j += mInputChannelCount) { |
| 249 | // Validate Left channel has audio |
| 250 | if (mInputBuffer[j] != 0) { |
| 251 | ASSERT_NE(mOutputBuffer[i], 0); |
| 252 | } else { |
| 253 | // No change in output when input is 0 |
| 254 | ASSERT_EQ(mOutputBuffer[i], mInputBuffer[j]); |
| 255 | } |
| 256 | // Validate Right channel has no audio |
| 257 | ASSERT_EQ(mOutputBuffer[i + 1], 0); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void checkAtRight(int32_t position) { |
| 262 | for (size_t i = 0, j = position; i < mOutputBufferSize; |
| 263 | i += kOutputChannelCount, j += mInputChannelCount) { |
| 264 | // Validate Left channel has no audio |
Shunkai Yao | 1319e98 | 2024-01-11 00:39:13 +0000 | [diff] [blame] | 265 | ASSERT_EQ(mOutputBuffer[i], 0) << " at " << i; |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 266 | // Validate Right channel has audio |
| 267 | if (mInputBuffer[j] != 0) { |
Shunkai Yao | 1319e98 | 2024-01-11 00:39:13 +0000 | [diff] [blame] | 268 | ASSERT_NE(mOutputBuffer[i + 1], 0) << " at " << i; |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 269 | } else { |
| 270 | // No change in output when input is 0 |
Shunkai Yao | 1319e98 | 2024-01-11 00:39:13 +0000 | [diff] [blame] | 271 | ASSERT_EQ(mOutputBuffer[i + 1], mInputBuffer[j]) << " at " << i; |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | void checkAtCenter(size_t position) { |
| 277 | for (size_t i = 0, j = position; i < mOutputBufferSize; |
| 278 | i += kOutputChannelCount, j += mInputChannelCount) { |
| 279 | // Validate both channels have audio |
| 280 | if (mInputBuffer[j] != 0) { |
| 281 | ASSERT_NE(mOutputBuffer[i], 0); |
| 282 | ASSERT_NE(mOutputBuffer[i + 1], 0); |
| 283 | |
| 284 | } else { |
| 285 | // No change in output when input is 0 |
| 286 | ASSERT_EQ(mOutputBuffer[i], mInputBuffer[j]); |
| 287 | ASSERT_EQ(mOutputBuffer[i + 1], mInputBuffer[j]); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | void validateOutput(int32_t channel, size_t position) { |
| 293 | switch (channel) { |
| 294 | case AudioChannelLayout::CHANNEL_FRONT_LEFT: |
| 295 | case AudioChannelLayout::CHANNEL_BACK_LEFT: |
| 296 | case AudioChannelLayout::CHANNEL_SIDE_LEFT: |
| 297 | case AudioChannelLayout::CHANNEL_TOP_FRONT_LEFT: |
| 298 | case AudioChannelLayout::CHANNEL_BOTTOM_FRONT_LEFT: |
| 299 | case AudioChannelLayout::CHANNEL_TOP_BACK_LEFT: |
| 300 | case AudioChannelLayout::CHANNEL_FRONT_WIDE_LEFT: |
| 301 | case AudioChannelLayout::CHANNEL_TOP_SIDE_LEFT: |
| 302 | checkAtLeft(position); |
| 303 | break; |
| 304 | |
| 305 | case AudioChannelLayout::CHANNEL_FRONT_RIGHT: |
| 306 | case AudioChannelLayout::CHANNEL_BACK_RIGHT: |
| 307 | case AudioChannelLayout::CHANNEL_SIDE_RIGHT: |
| 308 | case AudioChannelLayout::CHANNEL_TOP_FRONT_RIGHT: |
| 309 | case AudioChannelLayout::CHANNEL_BOTTOM_FRONT_RIGHT: |
| 310 | case AudioChannelLayout::CHANNEL_TOP_BACK_RIGHT: |
| 311 | case AudioChannelLayout::CHANNEL_FRONT_WIDE_RIGHT: |
| 312 | case AudioChannelLayout::CHANNEL_TOP_SIDE_RIGHT: |
| 313 | case AudioChannelLayout::CHANNEL_LOW_FREQUENCY_2: |
| 314 | checkAtRight(position); |
| 315 | break; |
| 316 | |
| 317 | case AudioChannelLayout::CHANNEL_FRONT_CENTER: |
| 318 | case AudioChannelLayout::CHANNEL_BACK_CENTER: |
| 319 | case AudioChannelLayout::CHANNEL_TOP_FRONT_CENTER: |
| 320 | case AudioChannelLayout::CHANNEL_BOTTOM_FRONT_CENTER: |
| 321 | case AudioChannelLayout::CHANNEL_FRONT_LEFT_OF_CENTER: |
| 322 | case AudioChannelLayout::CHANNEL_FRONT_RIGHT_OF_CENTER: |
| 323 | case AudioChannelLayout::CHANNEL_TOP_CENTER: |
| 324 | case AudioChannelLayout::CHANNEL_TOP_BACK_CENTER: |
| 325 | checkAtCenter(position); |
| 326 | break; |
| 327 | |
| 328 | case AudioChannelLayout::CHANNEL_LOW_FREQUENCY: |
| 329 | // If CHANNEL_LOW_FREQUENCY_2 is supported |
| 330 | if (mInputChannelLayout & AudioChannelLayout::CHANNEL_LOW_FREQUENCY_2) { |
| 331 | // Validate that only Left channel has audio |
| 332 | checkAtLeft(position); |
| 333 | } else { |
| 334 | // Validate that both channels have audio |
| 335 | checkAtCenter(position); |
| 336 | } |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | std::set<int32_t> getInputChannelLayouts() { |
| 342 | std::set<int32_t> supportedChannels; |
| 343 | for (int32_t channel : kChannels) { |
| 344 | if ((mInputChannelLayout & channel) == channel) { |
| 345 | supportedChannels.insert(channel); |
| 346 | } |
| 347 | } |
| 348 | return supportedChannels; |
| 349 | } |
| 350 | |
| 351 | int32_t mInputChannelLayout; |
| 352 | }; |
| 353 | |
| 354 | TEST_P(DownmixFoldDataTest, DownmixProcessData) { |
| 355 | // Set FOLD type parameter |
| 356 | ASSERT_NO_FATAL_FAILURE(setParameters(Downmix::Type::FOLD)); |
| 357 | |
| 358 | // Get all the channels from input layout |
| 359 | std::set<int32_t> supportedChannels = getInputChannelLayouts(); |
| 360 | |
| 361 | for (int32_t channel : supportedChannels) { |
| 362 | size_t position = std::distance(supportedChannels.begin(), supportedChannels.find(channel)); |
| 363 | generateInputBuffer(position, false /*isStripe*/); |
| 364 | ASSERT_NO_FATAL_FAILURE( |
| 365 | processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect, &mOpenEffectReturn)); |
| 366 | validateOutput(channel, position); |
| 367 | std::fill(mInputBuffer.begin(), mInputBuffer.end(), 0); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | enum StripParamName { STRIP_INSTANCE_NAME, STRIP_INPUT_LAYOUT }; |
| 372 | |
| 373 | using DownmixStripDataTestParam = |
| 374 | std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t>; |
| 375 | |
| 376 | class DownmixStripDataTest : public ::testing::TestWithParam<DownmixStripDataTestParam>, |
| 377 | public DownmixEffectHelper { |
| 378 | public: |
| 379 | DownmixStripDataTest() : mInputChannelLayout(std::get<STRIP_INPUT_LAYOUT>(GetParam())) { |
| 380 | std::tie(mFactory, mDescriptor) = std::get<STRIP_INSTANCE_NAME>(GetParam()); |
| 381 | } |
| 382 | |
| 383 | void SetUp() override { |
| 384 | SetUpDownmix(mInputChannelLayout); |
Shunkai Yao | 6b7784e | 2024-01-03 18:27:45 +0000 | [diff] [blame] | 385 | if (int32_t version; |
| 386 | mEffect->getInterfaceVersion(&version).isOk() && version < kMinDataTestHalVersion) { |
| 387 | GTEST_SKIP() << "Skipping the data test for version: " << version << "\n"; |
| 388 | } |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 389 | if (!isLayoutValid(mInputChannelLayout)) { |
| 390 | GTEST_SKIP() << "Layout not supported \n"; |
| 391 | } |
| 392 | setDataTestParams(mInputChannelLayout); |
| 393 | } |
| 394 | |
| 395 | void TearDown() override { TearDownDownmix(); } |
| 396 | |
| 397 | void validateOutput() { |
| 398 | ASSERT_EQ(kBufferSize, mInputBuffer.size()); |
| 399 | ASSERT_GE(kBufferSize, mOutputBufferSize); |
| 400 | for (size_t i = 0, j = 0; i < kBufferSize && j < mOutputBufferSize; |
| 401 | i += mInputChannelCount, j += kOutputChannelCount) { |
| 402 | ASSERT_EQ(mOutputBuffer[j], mInputBuffer[i]); |
| 403 | ASSERT_EQ(mOutputBuffer[j + 1], mInputBuffer[i + 1]); |
| 404 | } |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | int32_t mInputChannelLayout; |
| 408 | }; |
| 409 | |
| 410 | TEST_P(DownmixStripDataTest, DownmixProcessData) { |
| 411 | // Set STRIP type parameter |
| 412 | ASSERT_NO_FATAL_FAILURE(setParameters(Downmix::Type::STRIP)); |
| 413 | |
| 414 | // Generate input buffer, call process and compare outputs |
| 415 | generateInputBuffer(0 /*position*/, true /*isStripe*/); |
| 416 | ASSERT_NO_FATAL_FAILURE( |
| 417 | processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect, &mOpenEffectReturn)); |
| 418 | validateOutput(); |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | INSTANTIATE_TEST_SUITE_P( |
| 422 | DownmixTest, DownmixParamTest, |
| 423 | ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors( |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 424 | IFactory::descriptor, getEffectTypeUuidDownmix())), |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 425 | testing::ValuesIn(kTypeValues)), |
| 426 | [](const testing::TestParamInfo<DownmixParamTest::ParamType>& info) { |
| 427 | auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second; |
| 428 | std::string type = std::to_string(static_cast<int>(std::get<PARAM_TYPE>(info.param))); |
Shunkai Yao | 6b7784e | 2024-01-03 18:27:45 +0000 | [diff] [blame] | 429 | std::string name = getPrefix(descriptor) + "_type_" + type; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 430 | std::replace_if( |
| 431 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 432 | return name; |
| 433 | }); |
| 434 | |
| 435 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest); |
| 436 | |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 437 | INSTANTIATE_TEST_SUITE_P( |
| 438 | DownmixTest, DownmixFoldDataTest, |
| 439 | ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors( |
| 440 | IFactory::descriptor, getEffectTypeUuidDownmix())), |
| 441 | testing::ValuesIn(kLayoutValues)), |
| 442 | [](const testing::TestParamInfo<DownmixFoldDataTest::ParamType>& info) { |
| 443 | auto descriptor = std::get<FOLD_INSTANCE_NAME>(info.param).second; |
| 444 | std::string layout = std::to_string(std::get<FOLD_INPUT_LAYOUT>(info.param)); |
Shunkai Yao | 6b7784e | 2024-01-03 18:27:45 +0000 | [diff] [blame] | 445 | std::string name = getPrefix(descriptor) + "_fold_layout_" + layout; |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 446 | std::replace_if( |
| 447 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 448 | return name; |
| 449 | }); |
| 450 | |
| 451 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixFoldDataTest); |
| 452 | |
| 453 | INSTANTIATE_TEST_SUITE_P( |
| 454 | DownmixTest, DownmixStripDataTest, |
| 455 | ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors( |
| 456 | IFactory::descriptor, getEffectTypeUuidDownmix())), |
| 457 | testing::ValuesIn(kLayoutValues)), |
| 458 | [](const testing::TestParamInfo<DownmixStripDataTest::ParamType>& info) { |
| 459 | auto descriptor = std::get<STRIP_INSTANCE_NAME>(info.param).second; |
| 460 | std::string layout = |
| 461 | std::to_string(static_cast<int>(std::get<STRIP_INPUT_LAYOUT>(info.param))); |
Shunkai Yao | 6b7784e | 2024-01-03 18:27:45 +0000 | [diff] [blame] | 462 | std::string name = getPrefix(descriptor) + "_strip_layout_" + layout; |
Sneha Patil | f533b50 | 2023-10-25 12:39:55 +0530 | [diff] [blame] | 463 | std::replace_if( |
| 464 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 465 | return name; |
| 466 | }); |
| 467 | |
| 468 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixStripDataTest); |
| 469 | |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 470 | int main(int argc, char** argv) { |
| 471 | ::testing::InitGoogleTest(&argc, argv); |
Jaideep Sharma | 7449841 | 2023-09-13 15:25:25 +0530 | [diff] [blame] | 472 | ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer()); |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 473 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 474 | ABinderProcess_startThreadPool(); |
| 475 | return RUN_ALL_TESTS(); |
| 476 | } |