blob: ed87f78288bf498319307ad8c4280fbb7c82e7ec [file] [log] [blame]
Sham Rathod40f55bd2022-11-14 14:24:49 +05301/*
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 Naganov872d4a62023-03-09 18:19:01 -080017#define LOG_TAG "VtsHalDownmixTargetTest"
18#include <android-base/logging.h>
19
Sneha Patilf533b502023-10-25 12:39:55 +053020#include <audio_utils/ChannelMix.h>
Sham Rathod40f55bd2022-11-14 14:24:49 +053021#include "EffectHelper.h"
22
23using namespace android;
24
Sneha Patilf533b502023-10-25 12:39:55 +053025using aidl::android::hardware::audio::common::getChannelCount;
Sham Rathod40f55bd2022-11-14 14:24:49 +053026using aidl::android::hardware::audio::effect::Descriptor;
27using aidl::android::hardware::audio::effect::Downmix;
Shunkai Yaof8be1ac2023-03-06 18:41:27 +000028using aidl::android::hardware::audio::effect::getEffectTypeUuidDownmix;
Sham Rathod40f55bd2022-11-14 14:24:49 +053029using aidl::android::hardware::audio::effect::IEffect;
30using aidl::android::hardware::audio::effect::IFactory;
Sham Rathod40f55bd2022-11-14 14:24:49 +053031using aidl::android::hardware::audio::effect::Parameter;
Sneha Patilf533b502023-10-25 12:39:55 +053032using android::audio_utils::channels::ChannelMix;
Jaideep Sharma74498412023-09-13 15:25:25 +053033using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Sham Rathod40f55bd2022-11-14 14:24:49 +053034
Shunkai Yao6b7784e2024-01-03 18:27:45 +000035// minimal HAL interface version to run downmix data path test
36constexpr int32_t kMinDataTestHalVersion = 2;
37
Sham Rathod40f55bd2022-11-14 14:24:49 +053038// Testing for enum values
Sneha Patilf533b502023-10-25 12:39:55 +053039static const std::vector<Downmix::Type> kTypeValues = {ndk::enum_range<Downmix::Type>().begin(),
40 ndk::enum_range<Downmix::Type>().end()};
Sham Rathod40f55bd2022-11-14 14:24:49 +053041
Sneha Patilf533b502023-10-25 12:39:55 +053042// Testing for supported layouts from AudioChannelLayout.h
43static 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,
Andy Hung69f8d2e2024-12-19 16:37:59 -080055 AudioChannelLayout::LAYOUT_9POINT1POINT6, AudioChannelLayout::LAYOUT_13POINT0,
Sneha Patilf533b502023-10-25 12:39:55 +053056 AudioChannelLayout::LAYOUT_22POINT2};
57
58static 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
87class DownmixEffectHelper : public EffectHelper {
Sham Rathod40f55bd2022-11-14 14:24:49 +053088 public:
Aayush Sonifbb5cd32024-11-21 10:51:46 +000089 void SetUpDownmix(int32_t inputBufferLayout = kDefaultChannelLayout) {
Sham Rathod40f55bd2022-11-14 14:24:49 +053090 ASSERT_NE(nullptr, mFactory);
91 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
92
Sneha Patilf533b502023-10-25 12:39:55 +053093 AudioChannelLayout inputChannelLayout =
94 AudioChannelLayout::make<AudioChannelLayout::layoutMask>(inputBufferLayout);
95
Sham Rathod40f55bd2022-11-14 14:24:49 +053096 Parameter::Specific specific = getDefaultParamSpecific();
97 Parameter::Common common = EffectHelper::createParamCommon(
98 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
Sneha Patil807c9522024-06-06 09:44:54 +000099 kFrameCount /* iFrameCount */, kFrameCount /* oFrameCount */, inputChannelLayout,
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000100 AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
101 AudioChannelLayout::LAYOUT_STEREO));
Sneha Patilf533b502023-10-25 12:39:55 +0530102 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &mOpenEffectReturn, EX_NONE));
Sham Rathod40f55bd2022-11-14 14:24:49 +0530103 ASSERT_NE(nullptr, mEffect);
104 }
105
Sneha Patilf533b502023-10-25 12:39:55 +0530106 void TearDownDownmix() {
Sham Rathod40f55bd2022-11-14 14:24:49 +0530107 ASSERT_NO_FATAL_FAILURE(close(mEffect));
108 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Sneha Patilf533b502023-10-25 12:39:55 +0530109 mOpenEffectReturn = IEffect::OpenEffectReturn{};
Sham Rathod40f55bd2022-11-14 14:24:49 +0530110 }
111
Sneha Patilf533b502023-10-25 12:39:55 +0530112 Parameter createDownmixParam(Downmix::Type type) {
113 return Parameter::make<Parameter::specific>(
114 Parameter::Specific::make<Parameter::Specific::downmix>(
115 Downmix::make<Downmix::type>(type)));
116 }
117 void setParameters(Downmix::Type type) {
118 // set parameter
119 auto param = createDownmixParam(type);
120 EXPECT_STATUS(EX_NONE, mEffect->setParameter(param)) << param.toString();
Sham Rathod40f55bd2022-11-14 14:24:49 +0530121 }
122
Sneha Patilf533b502023-10-25 12:39:55 +0530123 void validateParameters(Downmix::Type type) {
124 auto leId = Downmix::Id::make<Downmix::Id::commonTag>(Downmix::Tag(Downmix::type));
125 auto id = Parameter::Id::make<Parameter::Id::downmixTag>(leId);
126 // get parameter
127 Parameter getParam;
128 EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
129 auto expectedParam = createDownmixParam(type);
130 EXPECT_EQ(expectedParam, getParam) << "\nexpectedParam:" << expectedParam.toString()
131 << "\ngetParam:" << getParam.toString();
Sham Rathod40f55bd2022-11-14 14:24:49 +0530132 }
133
134 Parameter::Specific getDefaultParamSpecific() {
135 Downmix dm = Downmix::make<Downmix::type>(Downmix::Type::STRIP);
136 Parameter::Specific specific = Parameter::Specific::make<Parameter::Specific::downmix>(dm);
137 return specific;
138 }
139
Sneha Patilf533b502023-10-25 12:39:55 +0530140 void setDataTestParams(int32_t layoutType) {
Sneha Patilf533b502023-10-25 12:39:55 +0530141 // Get the number of channels used
142 mInputChannelCount = getChannelCount(
143 AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layoutType));
Sneha Patil807c9522024-06-06 09:44:54 +0000144 mInputBufferSize = kFrameCount * mInputChannelCount;
145 mInputBuffer.resize(mInputBufferSize);
Sneha Patilf533b502023-10-25 12:39:55 +0530146
147 // In case of downmix, output is always configured to stereo layout.
Sneha Patil807c9522024-06-06 09:44:54 +0000148 mOutputBufferSize = kFrameCount * kOutputChannelCount;
Shunkai Yao1319e982024-01-11 00:39:13 +0000149 mOutputBuffer.resize(mOutputBufferSize);
Sneha Patilf533b502023-10-25 12:39:55 +0530150 }
151
Sneha Patilf533b502023-10-25 12:39:55 +0530152 bool isLayoutValid(int32_t inputLayout) {
153 if (inputLayout & kMaxChannelMask) {
154 return false;
155 }
156 return true;
157 }
158
Sneha Patil807c9522024-06-06 09:44:54 +0000159 static const long kFrameCount = 256;
160 static constexpr float kMaxDownmixSample = 1;
161 static constexpr int kOutputChannelCount = 2;
162 // Mask for layouts greater than MAX_INPUT_CHANNELS_SUPPORTED
163 static constexpr int32_t kMaxChannelMask =
164 ~((1 << ChannelMix<AUDIO_CHANNEL_OUT_STEREO>::MAX_INPUT_CHANNELS_SUPPORTED) - 1);
Sneha Patilf533b502023-10-25 12:39:55 +0530165 std::shared_ptr<IFactory> mFactory;
166 Descriptor mDescriptor;
167 std::shared_ptr<IEffect> mEffect;
168 IEffect::OpenEffectReturn mOpenEffectReturn;
169
170 std::vector<float> mInputBuffer;
171 std::vector<float> mOutputBuffer;
172 size_t mInputChannelCount;
173 size_t mOutputBufferSize;
Sneha Patil807c9522024-06-06 09:44:54 +0000174 size_t mInputBufferSize;
Sneha Patilf533b502023-10-25 12:39:55 +0530175};
176
177/**
178 * Here we focus on specific parameter checking, general IEffect interfaces testing performed in
179 * VtsAudioEffectTargetTest.
180 */
181enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE };
182
183using DownmixParamTestParam =
184 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>;
185
186class DownmixParamTest : public ::testing::TestWithParam<DownmixParamTestParam>,
187 public DownmixEffectHelper {
188 public:
189 DownmixParamTest() : mParamType(std::get<PARAM_TYPE>(GetParam())) {
190 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
191 }
192
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000193 void SetUp() override { ASSERT_NO_FATAL_FAILURE(SetUpDownmix()); }
Sneha Patilf533b502023-10-25 12:39:55 +0530194
195 void TearDown() override { TearDownDownmix(); }
196
197 const Downmix::Type mParamType;
Sham Rathod40f55bd2022-11-14 14:24:49 +0530198};
199
200TEST_P(DownmixParamTest, SetAndGetType) {
Sneha Patilf533b502023-10-25 12:39:55 +0530201 ASSERT_NO_FATAL_FAILURE(setParameters(mParamType));
202 ASSERT_NO_FATAL_FAILURE(validateParameters(mParamType));
203}
204
205enum FoldParamName { FOLD_INSTANCE_NAME, FOLD_INPUT_LAYOUT, FOLD_TEST_CHANNEL };
206
207using DownmixDataTestParamFold =
208 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t>;
209
210class DownmixFoldDataTest : public ::testing::TestWithParam<DownmixDataTestParamFold>,
211 public DownmixEffectHelper {
212 public:
213 DownmixFoldDataTest() : mInputChannelLayout(std::get<FOLD_INPUT_LAYOUT>(GetParam())) {
214 std::tie(mFactory, mDescriptor) = std::get<FOLD_INSTANCE_NAME>(GetParam());
215 }
216
217 void SetUp() override {
Shunkai Yao50e478b2024-03-14 01:54:58 +0000218 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000219 ASSERT_NO_FATAL_FAILURE(SetUpDownmix(mInputChannelLayout));
Shunkai Yao8016a0d2025-03-26 16:39:55 +0000220 SKIP_TEST_IF_VERSION_UNSUPPORTED(mEffect, kMinDataTestHalVersion);
Sneha Patilf533b502023-10-25 12:39:55 +0530221 if (!isLayoutValid(mInputChannelLayout)) {
222 GTEST_SKIP() << "Layout not supported \n";
223 }
224 setDataTestParams(mInputChannelLayout);
225 }
226
Shunkai Yao50e478b2024-03-14 01:54:58 +0000227 void TearDown() override {
228 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
229 TearDownDownmix();
230 }
Sneha Patilf533b502023-10-25 12:39:55 +0530231
232 void checkAtLeft(int32_t position) {
233 for (size_t i = 0, j = position; i < mOutputBufferSize;
234 i += kOutputChannelCount, j += mInputChannelCount) {
235 // Validate Left channel has audio
236 if (mInputBuffer[j] != 0) {
237 ASSERT_NE(mOutputBuffer[i], 0);
238 } else {
239 // No change in output when input is 0
240 ASSERT_EQ(mOutputBuffer[i], mInputBuffer[j]);
241 }
242 // Validate Right channel has no audio
243 ASSERT_EQ(mOutputBuffer[i + 1], 0);
244 }
245 }
246
247 void checkAtRight(int32_t position) {
248 for (size_t i = 0, j = position; i < mOutputBufferSize;
249 i += kOutputChannelCount, j += mInputChannelCount) {
250 // Validate Left channel has no audio
Shunkai Yao1319e982024-01-11 00:39:13 +0000251 ASSERT_EQ(mOutputBuffer[i], 0) << " at " << i;
Sneha Patilf533b502023-10-25 12:39:55 +0530252 // Validate Right channel has audio
253 if (mInputBuffer[j] != 0) {
Shunkai Yao1319e982024-01-11 00:39:13 +0000254 ASSERT_NE(mOutputBuffer[i + 1], 0) << " at " << i;
Sneha Patilf533b502023-10-25 12:39:55 +0530255 } else {
256 // No change in output when input is 0
Shunkai Yao1319e982024-01-11 00:39:13 +0000257 ASSERT_EQ(mOutputBuffer[i + 1], mInputBuffer[j]) << " at " << i;
Sneha Patilf533b502023-10-25 12:39:55 +0530258 }
259 }
260 }
261
262 void checkAtCenter(size_t position) {
263 for (size_t i = 0, j = position; i < mOutputBufferSize;
264 i += kOutputChannelCount, j += mInputChannelCount) {
265 // Validate both channels have audio
266 if (mInputBuffer[j] != 0) {
267 ASSERT_NE(mOutputBuffer[i], 0);
268 ASSERT_NE(mOutputBuffer[i + 1], 0);
269
270 } else {
271 // No change in output when input is 0
272 ASSERT_EQ(mOutputBuffer[i], mInputBuffer[j]);
273 ASSERT_EQ(mOutputBuffer[i + 1], mInputBuffer[j]);
274 }
275 }
276 }
277
278 void validateOutput(int32_t channel, size_t position) {
279 switch (channel) {
280 case AudioChannelLayout::CHANNEL_FRONT_LEFT:
281 case AudioChannelLayout::CHANNEL_BACK_LEFT:
282 case AudioChannelLayout::CHANNEL_SIDE_LEFT:
283 case AudioChannelLayout::CHANNEL_TOP_FRONT_LEFT:
284 case AudioChannelLayout::CHANNEL_BOTTOM_FRONT_LEFT:
285 case AudioChannelLayout::CHANNEL_TOP_BACK_LEFT:
286 case AudioChannelLayout::CHANNEL_FRONT_WIDE_LEFT:
287 case AudioChannelLayout::CHANNEL_TOP_SIDE_LEFT:
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000288 ASSERT_NO_FATAL_FAILURE(checkAtLeft(position));
Sneha Patilf533b502023-10-25 12:39:55 +0530289 break;
290
291 case AudioChannelLayout::CHANNEL_FRONT_RIGHT:
292 case AudioChannelLayout::CHANNEL_BACK_RIGHT:
293 case AudioChannelLayout::CHANNEL_SIDE_RIGHT:
294 case AudioChannelLayout::CHANNEL_TOP_FRONT_RIGHT:
295 case AudioChannelLayout::CHANNEL_BOTTOM_FRONT_RIGHT:
296 case AudioChannelLayout::CHANNEL_TOP_BACK_RIGHT:
297 case AudioChannelLayout::CHANNEL_FRONT_WIDE_RIGHT:
298 case AudioChannelLayout::CHANNEL_TOP_SIDE_RIGHT:
299 case AudioChannelLayout::CHANNEL_LOW_FREQUENCY_2:
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000300 ASSERT_NO_FATAL_FAILURE(checkAtRight(position));
Sneha Patilf533b502023-10-25 12:39:55 +0530301 break;
302
303 case AudioChannelLayout::CHANNEL_FRONT_CENTER:
304 case AudioChannelLayout::CHANNEL_BACK_CENTER:
305 case AudioChannelLayout::CHANNEL_TOP_FRONT_CENTER:
306 case AudioChannelLayout::CHANNEL_BOTTOM_FRONT_CENTER:
307 case AudioChannelLayout::CHANNEL_FRONT_LEFT_OF_CENTER:
308 case AudioChannelLayout::CHANNEL_FRONT_RIGHT_OF_CENTER:
309 case AudioChannelLayout::CHANNEL_TOP_CENTER:
310 case AudioChannelLayout::CHANNEL_TOP_BACK_CENTER:
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000311 ASSERT_NO_FATAL_FAILURE(checkAtCenter(position));
Sneha Patilf533b502023-10-25 12:39:55 +0530312 break;
313
314 case AudioChannelLayout::CHANNEL_LOW_FREQUENCY:
315 // If CHANNEL_LOW_FREQUENCY_2 is supported
316 if (mInputChannelLayout & AudioChannelLayout::CHANNEL_LOW_FREQUENCY_2) {
317 // Validate that only Left channel has audio
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000318 ASSERT_NO_FATAL_FAILURE(checkAtLeft(position));
Sneha Patilf533b502023-10-25 12:39:55 +0530319 } else {
320 // Validate that both channels have audio
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000321 ASSERT_NO_FATAL_FAILURE(checkAtCenter(position));
Sneha Patilf533b502023-10-25 12:39:55 +0530322 }
323 break;
324 }
325 }
326
327 std::set<int32_t> getInputChannelLayouts() {
328 std::set<int32_t> supportedChannels;
329 for (int32_t channel : kChannels) {
330 if ((mInputChannelLayout & channel) == channel) {
331 supportedChannels.insert(channel);
332 }
333 }
334 return supportedChannels;
335 }
336
337 int32_t mInputChannelLayout;
338};
339
340TEST_P(DownmixFoldDataTest, DownmixProcessData) {
341 // Set FOLD type parameter
342 ASSERT_NO_FATAL_FAILURE(setParameters(Downmix::Type::FOLD));
343
344 // Get all the channels from input layout
345 std::set<int32_t> supportedChannels = getInputChannelLayouts();
346
347 for (int32_t channel : supportedChannels) {
348 size_t position = std::distance(supportedChannels.begin(), supportedChannels.find(channel));
Aayush Sonibb001fb2024-09-11 13:51:14 +0000349 generateInputBuffer(mInputBuffer, position, false /*isStripe*/,
350 mInputChannelCount /*channelCount*/, kMaxDownmixSample);
Sneha Patilf533b502023-10-25 12:39:55 +0530351 ASSERT_NO_FATAL_FAILURE(
352 processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect, &mOpenEffectReturn));
353 validateOutput(channel, position);
354 std::fill(mInputBuffer.begin(), mInputBuffer.end(), 0);
355 }
356}
357
358enum StripParamName { STRIP_INSTANCE_NAME, STRIP_INPUT_LAYOUT };
359
360using DownmixStripDataTestParam =
361 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t>;
362
363class DownmixStripDataTest : public ::testing::TestWithParam<DownmixStripDataTestParam>,
364 public DownmixEffectHelper {
365 public:
366 DownmixStripDataTest() : mInputChannelLayout(std::get<STRIP_INPUT_LAYOUT>(GetParam())) {
367 std::tie(mFactory, mDescriptor) = std::get<STRIP_INSTANCE_NAME>(GetParam());
368 }
369
370 void SetUp() override {
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000371 ASSERT_NO_FATAL_FAILURE(SetUpDownmix(mInputChannelLayout));
Shunkai Yao8016a0d2025-03-26 16:39:55 +0000372 SKIP_TEST_IF_VERSION_UNSUPPORTED(mEffect, kMinDataTestHalVersion);
Sneha Patilf533b502023-10-25 12:39:55 +0530373 if (!isLayoutValid(mInputChannelLayout)) {
374 GTEST_SKIP() << "Layout not supported \n";
375 }
376 setDataTestParams(mInputChannelLayout);
377 }
378
379 void TearDown() override { TearDownDownmix(); }
380
381 void validateOutput() {
Sneha Patil807c9522024-06-06 09:44:54 +0000382 ASSERT_EQ(mInputBufferSize, mInputBuffer.size());
383 ASSERT_GE(mInputBufferSize, mOutputBufferSize);
384 for (size_t i = 0, j = 0; i < mInputBufferSize && j < mOutputBufferSize;
Sneha Patilf533b502023-10-25 12:39:55 +0530385 i += mInputChannelCount, j += kOutputChannelCount) {
386 ASSERT_EQ(mOutputBuffer[j], mInputBuffer[i]);
387 ASSERT_EQ(mOutputBuffer[j + 1], mInputBuffer[i + 1]);
388 }
Sneha Patilf533b502023-10-25 12:39:55 +0530389 }
390
391 int32_t mInputChannelLayout;
392};
393
394TEST_P(DownmixStripDataTest, DownmixProcessData) {
395 // Set STRIP type parameter
396 ASSERT_NO_FATAL_FAILURE(setParameters(Downmix::Type::STRIP));
397
398 // Generate input buffer, call process and compare outputs
Aayush Sonibb001fb2024-09-11 13:51:14 +0000399 generateInputBuffer(mInputBuffer, 0 /*position*/, true /*isStripe*/,
400 mInputChannelCount /*channelCount*/, kMaxDownmixSample);
Sneha Patilf533b502023-10-25 12:39:55 +0530401 ASSERT_NO_FATAL_FAILURE(
402 processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect, &mOpenEffectReturn));
Aayush Soni63d6e2a2025-03-04 13:37:28 +0000403 ASSERT_NO_FATAL_FAILURE(validateOutput());
Sham Rathod40f55bd2022-11-14 14:24:49 +0530404}
405
406INSTANTIATE_TEST_SUITE_P(
407 DownmixTest, DownmixParamTest,
408 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000409 IFactory::descriptor, getEffectTypeUuidDownmix())),
Sham Rathod40f55bd2022-11-14 14:24:49 +0530410 testing::ValuesIn(kTypeValues)),
411 [](const testing::TestParamInfo<DownmixParamTest::ParamType>& info) {
412 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
413 std::string type = std::to_string(static_cast<int>(std::get<PARAM_TYPE>(info.param)));
Shunkai Yao6b7784e2024-01-03 18:27:45 +0000414 std::string name = getPrefix(descriptor) + "_type_" + type;
Sham Rathod40f55bd2022-11-14 14:24:49 +0530415 std::replace_if(
416 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
417 return name;
418 });
419
420GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest);
421
Sneha Patilf533b502023-10-25 12:39:55 +0530422INSTANTIATE_TEST_SUITE_P(
423 DownmixTest, DownmixFoldDataTest,
424 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
425 IFactory::descriptor, getEffectTypeUuidDownmix())),
426 testing::ValuesIn(kLayoutValues)),
427 [](const testing::TestParamInfo<DownmixFoldDataTest::ParamType>& info) {
428 auto descriptor = std::get<FOLD_INSTANCE_NAME>(info.param).second;
429 std::string layout = std::to_string(std::get<FOLD_INPUT_LAYOUT>(info.param));
Shunkai Yao6b7784e2024-01-03 18:27:45 +0000430 std::string name = getPrefix(descriptor) + "_fold_layout_" + layout;
Sneha Patilf533b502023-10-25 12:39:55 +0530431 std::replace_if(
432 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
433 return name;
434 });
435
436GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixFoldDataTest);
437
438INSTANTIATE_TEST_SUITE_P(
439 DownmixTest, DownmixStripDataTest,
440 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
441 IFactory::descriptor, getEffectTypeUuidDownmix())),
442 testing::ValuesIn(kLayoutValues)),
443 [](const testing::TestParamInfo<DownmixStripDataTest::ParamType>& info) {
444 auto descriptor = std::get<STRIP_INSTANCE_NAME>(info.param).second;
445 std::string layout =
446 std::to_string(static_cast<int>(std::get<STRIP_INPUT_LAYOUT>(info.param)));
Shunkai Yao6b7784e2024-01-03 18:27:45 +0000447 std::string name = getPrefix(descriptor) + "_strip_layout_" + layout;
Sneha Patilf533b502023-10-25 12:39:55 +0530448 std::replace_if(
449 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
450 return name;
451 });
452
453GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixStripDataTest);
454
Sham Rathod40f55bd2022-11-14 14:24:49 +0530455int main(int argc, char** argv) {
456 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +0530457 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Sham Rathod40f55bd2022-11-14 14:24:49 +0530458 ABinderProcess_setThreadPoolMaxThreadCount(1);
459 ABinderProcess_startThreadPool();
460 return RUN_ALL_TESTS();
461}