1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <benchmark/benchmark.h>
17 #include <climits>
18 #include <gtest/gtest.h>
19 #include "hdf_base.h"
20 #include "osal_mem.h"
21 #include "v1_0/iaudio_capture.h"
22 #include "v1_0/iaudio_manager.h"
23
24 using namespace std;
25 using namespace testing::ext;
26 namespace {
27 static const uint32_t MAX_AUDIO_ADAPTER_NUM = 5;
28 const int32_t AUDIO_CAPTURE_BUF_TEST = 1024;
29 const int BUFFER_LENTH = 1024 * 16;
30 const int DEEP_BUFFER_CAPTURE_PERIOD_SIZE = 4 * 1024;
31 const int DEFAULT_BUFFER_SIZE = 16384;
32 const float HALF_OF_MAX_VOLUME = 0.5;
33 const int MOVE_LEFT_NUM = 8;
34 const int TEST_SAMPLE_RATE_MASK_48000 = 48000;
35 const int TEST_CHANNEL_COUNT = 2;
36 const int32_t ITERATION_FREQUENCY = 100;
37 const int32_t REPETITION_FREQUENCY = 3;
38 const int32_t RANGE_VALUE = 4;
39 const float GAIN_VALUE = 1.0;
40
41 class AudioCaptureBenchmarkTest : public benchmark::Fixture {
42 public:
43 struct IAudioManager *manager_ = nullptr;;
44 struct IAudioAdapter *adapter_ = nullptr;
45 struct IAudioCapture *capture_ = nullptr;
46 uint32_t captureId_ = 0;
47 char *devDescriptorName_ = nullptr;
48 struct AudioAdapterDescriptor *adapterDescs_ = nullptr;
49 virtual void SetUp(const ::benchmark::State &state);
50 virtual void TearDown(const ::benchmark::State &state);
51 uint64_t GetCaptureBufferSize();
52 void InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc);
53 void InitCaptureAttrs(struct AudioSampleAttributes &attrs);
54 void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
55 void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
56 };
57
GetCaptureBufferSize()58 uint64_t AudioCaptureBenchmarkTest::GetCaptureBufferSize()
59 {
60 int32_t ret = HDF_SUCCESS;
61 uint64_t frameSize = 0;
62 uint64_t frameCount = 0;
63 uint64_t bufferSize = 0;
64
65 if (capture_ == nullptr) {
66 return DEFAULT_BUFFER_SIZE;
67 }
68
69 ret = capture_->GetFrameSize(capture_, &frameSize);
70 if (ret != HDF_SUCCESS) {
71 return DEFAULT_BUFFER_SIZE;
72 }
73
74 ret = capture_->GetFrameCount(capture_, &frameCount);
75 if (ret != HDF_SUCCESS) {
76 return DEFAULT_BUFFER_SIZE;
77 }
78
79 bufferSize = frameCount * frameSize;
80 if (bufferSize == 0) {
81 bufferSize = DEFAULT_BUFFER_SIZE;
82 }
83
84 return bufferSize;
85 }
86
InitCaptureDevDesc(struct AudioDeviceDescriptor & devDesc)87 void AudioCaptureBenchmarkTest::InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc)
88 {
89 devDesc.pins = (enum AudioPortPin)PIN_IN_MIC;
90 devDescriptorName_ = strdup("cardname");
91 devDesc.desc = devDescriptorName_;
92
93 ASSERT_NE(adapterDescs_, nullptr);
94 ASSERT_NE(adapterDescs_->ports, nullptr);
95 for (uint32_t index = 0; index < adapterDescs_->portsLen; index++) {
96 if (adapterDescs_->ports[index].dir == PORT_IN) {
97 devDesc.portId = adapterDescs_->ports[index].portId;
98 return;
99 }
100 }
101 }
102
InitCaptureAttrs(struct AudioSampleAttributes & attrs)103 void AudioCaptureBenchmarkTest::InitCaptureAttrs(struct AudioSampleAttributes &attrs)
104 {
105 attrs.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
106 attrs.channelCount = TEST_CHANNEL_COUNT;
107 attrs.sampleRate = TEST_SAMPLE_RATE_MASK_48000;
108 attrs.interleaved = 0;
109 attrs.type = AUDIO_IN_MEDIA;
110 attrs.period = DEEP_BUFFER_CAPTURE_PERIOD_SIZE;
111 attrs.frameSize = AUDIO_FORMAT_TYPE_PCM_16_BIT * TEST_CHANNEL_COUNT / MOVE_LEFT_NUM;
112 attrs.isBigEndian = false;
113 attrs.isSignedData = true;
114 attrs.startThreshold = DEEP_BUFFER_CAPTURE_PERIOD_SIZE / (attrs.format * attrs.channelCount / MOVE_LEFT_NUM);
115 attrs.stopThreshold = INT_MAX;
116 attrs.silenceThreshold = BUFFER_LENTH;
117 }
118
FreeAdapterElements(struct AudioAdapterDescriptor * dataBlock,bool freeSelf)119 void AudioCaptureBenchmarkTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
120 {
121 if (dataBlock == nullptr) {
122 return;
123 }
124
125 if (dataBlock->adapterName != nullptr) {
126 OsalMemFree(dataBlock->adapterName);
127 dataBlock->adapterName = nullptr;
128 }
129
130 if (dataBlock->ports != nullptr) {
131 OsalMemFree(dataBlock->ports);
132 }
133
134 if (freeSelf) {
135 OsalMemFree(dataBlock);
136 }
137 }
138
ReleaseAllAdapterDescs(struct AudioAdapterDescriptor * descs,uint32_t descsLen)139 void AudioCaptureBenchmarkTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
140 {
141 if (descs == nullptr || descsLen == 0) {
142 return;
143 }
144
145 for (uint32_t i = 0; i < descsLen; i++) {
146 FreeAdapterElements(&descs[i], false);
147 }
148 }
149
SetUp(const::benchmark::State & state)150 void AudioCaptureBenchmarkTest::SetUp(const ::benchmark::State &state)
151 {
152 uint32_t size = MAX_AUDIO_ADAPTER_NUM;
153 struct AudioDeviceDescriptor devDesc = {};
154 struct AudioSampleAttributes attrs = {};
155
156 manager_ = IAudioManagerGet(false);
157 ASSERT_NE(manager_, nullptr);
158
159 adapterDescs_ = (struct AudioAdapterDescriptor *)OsalMemCalloc(
160 sizeof(struct AudioAdapterDescriptor) * (MAX_AUDIO_ADAPTER_NUM));
161 ASSERT_NE(adapterDescs_, nullptr);
162
163 EXPECT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
164 if (size > MAX_AUDIO_ADAPTER_NUM) {
165 ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
166 ASSERT_LT(size, MAX_AUDIO_ADAPTER_NUM);
167 }
168
169 EXPECT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_));
170 if (adapter_ == nullptr) {
171 ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
172 EXPECT_NE(adapter_, nullptr);
173 }
174
175 InitCaptureDevDesc(devDesc);
176 InitCaptureAttrs(attrs);
177 EXPECT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devDesc, &attrs, &capture_, &captureId_));
178 if (capture_ == nullptr) {
179 (void)manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
180 ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
181 }
182 ASSERT_NE(capture_, nullptr);
183 }
184
TearDown(const::benchmark::State & state)185 void AudioCaptureBenchmarkTest::TearDown(const ::benchmark::State &state)
186 {
187 ASSERT_NE(devDescriptorName_, nullptr);
188 free(devDescriptorName_);
189 devDescriptorName_ = nullptr;
190
191 ASSERT_NE(capture_, nullptr);
192 EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyCapture(adapter_, captureId_));
193
194 ASSERT_NE(manager_, nullptr);
195 EXPECT_EQ(HDF_SUCCESS, manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName));
196 ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
197
198 IAudioManagerRelease(manager_, false);
199 }
200
BENCHMARK_F(AudioCaptureBenchmarkTest,CaptureFrame)201 BENCHMARK_F(AudioCaptureBenchmarkTest, CaptureFrame)(benchmark::State &state)
202 {
203 ASSERT_NE(capture_, nullptr);
204 uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
205 uint64_t requestBytes = frameLen;
206
207 int32_t ret = capture_->Start(capture_);
208 EXPECT_EQ(ret, HDF_SUCCESS);
209
210 int8_t *frame = (int8_t *)calloc(1, frameLen);
211 EXPECT_NE(nullptr, frame);
212
213 for (auto _ : state) {
214 ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
215 EXPECT_EQ(ret, HDF_SUCCESS);
216 }
217 capture_->Stop(capture_);
218
219 if (frame != nullptr) {
220 free(frame);
221 frame = nullptr;
222 }
223 }
224
225 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CaptureFrame)->
226 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
227
BENCHMARK_F(AudioCaptureBenchmarkTest,GetCapturePosition)228 BENCHMARK_F(AudioCaptureBenchmarkTest, GetCapturePosition)(benchmark::State &state)
229 {
230 ASSERT_NE(capture_, nullptr);
231 uint64_t frames;
232 struct AudioTimeStamp time;
233 uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
234 uint64_t requestBytes = frameLen;
235
236 int32_t ret = capture_->Start(capture_);
237 EXPECT_EQ(ret, HDF_SUCCESS);
238
239 int8_t *frame = (int8_t *)calloc(1, frameLen);
240 EXPECT_NE(nullptr, frame);
241
242 ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
243 EXPECT_EQ(ret, HDF_SUCCESS);
244
245 for (auto _ : state) {
246 ret = capture_->GetCapturePosition(capture_, &frames, &time);
247 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
248 }
249 capture_->Stop(capture_);
250
251 if (frame != nullptr) {
252 free(frame);
253 frame = nullptr;
254 }
255 }
256
257 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCapturePosition)->
258 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
259
BENCHMARK_F(AudioCaptureBenchmarkTest,StartAndStop)260 BENCHMARK_F(AudioCaptureBenchmarkTest, StartAndStop)(benchmark::State &state)
261 {
262 ASSERT_NE(capture_, nullptr);
263 int32_t ret;
264 for (auto _ : state) {
265 ret = capture_->Start(capture_);
266 EXPECT_EQ(ret, HDF_SUCCESS);
267 ret = capture_->Stop(capture_);
268 EXPECT_EQ(ret, HDF_SUCCESS);
269 }
270 }
271
272 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, StartAndStop)->
273 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
274
BENCHMARK_F(AudioCaptureBenchmarkTest,Pause)275 BENCHMARK_F(AudioCaptureBenchmarkTest, Pause)(benchmark::State &state)
276 {
277 ASSERT_NE(capture_, nullptr);
278 int32_t ret = capture_->Start(capture_);
279 EXPECT_EQ(ret, HDF_SUCCESS);
280
281 for (auto _ : state) {
282 ret = capture_->Pause(capture_);
283 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
284 }
285
286 ret = capture_->Stop(capture_);
287 ASSERT_EQ(ret, HDF_SUCCESS);
288 }
289
290 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Pause)->
291 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
292
BENCHMARK_F(AudioCaptureBenchmarkTest,Resume)293 BENCHMARK_F(AudioCaptureBenchmarkTest, Resume)(benchmark::State &state)
294 {
295 ASSERT_NE(capture_, nullptr);
296 int32_t ret = capture_->Start(capture_);
297 EXPECT_EQ(ret, HDF_SUCCESS);
298
299 ret = capture_->Pause(capture_);
300 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
301
302 for (auto _ : state) {
303 ret = capture_->Resume(capture_);
304 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
305 }
306
307 ret = capture_->Stop(capture_);
308 ASSERT_EQ(ret, HDF_SUCCESS);
309 }
310
311 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Resume)->
312 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
313
BENCHMARK_F(AudioCaptureBenchmarkTest,Flush)314 BENCHMARK_F(AudioCaptureBenchmarkTest, Flush)(benchmark::State &state)
315 {
316 ASSERT_NE(capture_, nullptr);
317 int32_t ret;
318 for (auto _ : state) {
319 ret = capture_->Flush(capture_);
320 EXPECT_NE(ret, HDF_SUCCESS);
321 }
322 }
323
324 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Flush)->
325 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
326
BENCHMARK_F(AudioCaptureBenchmarkTest,TurnStandbyMode)327 BENCHMARK_F(AudioCaptureBenchmarkTest, TurnStandbyMode)(benchmark::State &state)
328 {
329 ASSERT_NE(capture_, nullptr);
330 int32_t ret;
331 for (auto _ : state) {
332 ret = capture_->Start(capture_);
333 EXPECT_EQ(ret, HDF_SUCCESS);
334 ret = capture_->TurnStandbyMode(capture_);
335 EXPECT_EQ(ret, HDF_SUCCESS);
336 capture_->Stop(capture_);
337 }
338 }
339
340 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, TurnStandbyMode)->
341 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
342
BENCHMARK_F(AudioCaptureBenchmarkTest,AudioDevDump)343 BENCHMARK_F(AudioCaptureBenchmarkTest, AudioDevDump)(benchmark::State &state)
344 {
345 ASSERT_NE(capture_, nullptr);
346 int32_t ret;
347 int32_t range = RANGE_VALUE;
348 char pathBuf[] = "/data/CaptureDump.log";
349
350 FILE *file = fopen(pathBuf, "wb+");
351 ASSERT_NE(nullptr, file);
352 int fd = fileno(file);
353 if (fd == -1) {
354 fclose(file);
355 ASSERT_NE(fd, -1);
356 }
357
358 for (auto _ : state) {
359 ret = capture_->AudioDevDump(capture_, range, fd);
360 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
361 }
362 fclose(file);
363 }
364
365 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AudioDevDump)->
366 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
367
BENCHMARK_F(AudioCaptureBenchmarkTest,SetMute)368 BENCHMARK_F(AudioCaptureBenchmarkTest, SetMute)(benchmark::State &state)
369 {
370 ASSERT_NE(capture_, nullptr);
371 int32_t ret;
372 bool isSupport = false;
373
374 for (auto _ : state) {
375 ret = capture_->SetMute(capture_, isSupport);
376 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
377 }
378 }
379
380 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetMute)->
381 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
382
BENCHMARK_F(AudioCaptureBenchmarkTest,GetMute)383 BENCHMARK_F(AudioCaptureBenchmarkTest, GetMute)(benchmark::State &state)
384 {
385 ASSERT_NE(capture_, nullptr);
386 int32_t ret;
387 bool isSupport = true;
388
389 for (auto _ : state) {
390 ret = capture_->GetMute(capture_, &isSupport);
391 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
392 }
393 }
394
395 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMute)->
396 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
397
BENCHMARK_F(AudioCaptureBenchmarkTest,SetVolume)398 BENCHMARK_F(AudioCaptureBenchmarkTest, SetVolume)(benchmark::State &state)
399 {
400 ASSERT_NE(capture_, nullptr);
401 int32_t ret;
402 for (auto _ : state) {
403 ret = capture_->SetVolume(capture_, HALF_OF_MAX_VOLUME);
404 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
405 }
406 }
407
408 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetVolume)->
409 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
410
BENCHMARK_F(AudioCaptureBenchmarkTest,GetVolume)411 BENCHMARK_F(AudioCaptureBenchmarkTest, GetVolume)(benchmark::State &state)
412 {
413 ASSERT_NE(capture_, nullptr);
414 int32_t ret;
415 float volume = 0.0;
416
417 for (auto _ : state) {
418 ret = capture_->GetVolume(capture_, &volume);
419 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
420 }
421 }
422
423 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetVolume)->
424 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
425
BENCHMARK_F(AudioCaptureBenchmarkTest,GetGainThreshold)426 BENCHMARK_F(AudioCaptureBenchmarkTest, GetGainThreshold)(benchmark::State &state)
427 {
428 ASSERT_NE(capture_, nullptr);
429 int32_t ret;
430 float bottom = 0.0;
431 float top = 0.0;
432
433 for (auto _ : state) {
434 ret = capture_->GetGainThreshold(capture_, &bottom, &top);
435 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
436 }
437 }
438
439 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGainThreshold)->
440 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
441
BENCHMARK_F(AudioCaptureBenchmarkTest,SetSampleAttributes)442 BENCHMARK_F(AudioCaptureBenchmarkTest, SetSampleAttributes)(benchmark::State &state)
443 {
444 ASSERT_NE(capture_, nullptr);
445 int32_t ret;
446 struct AudioSampleAttributes attrs;
447 InitCaptureAttrs(attrs);
448
449 for (auto _ : state) {
450 ret = capture_->SetSampleAttributes(capture_, &attrs);
451 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
452 }
453 }
454
455 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetSampleAttributes)->
456 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
457
BENCHMARK_F(AudioCaptureBenchmarkTest,GetSampleAttributes)458 BENCHMARK_F(AudioCaptureBenchmarkTest, GetSampleAttributes)(benchmark::State &state)
459 {
460 ASSERT_NE(capture_, nullptr);
461 int32_t ret;
462 struct AudioSampleAttributes attrs = {};
463
464 for (auto _ : state) {
465 ret = capture_->GetSampleAttributes(capture_, &attrs);
466 EXPECT_EQ(ret, HDF_SUCCESS);
467 }
468 }
469
470 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetSampleAttributes)->
471 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
472
BENCHMARK_F(AudioCaptureBenchmarkTest,GetCurrentChannelId)473 BENCHMARK_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)(benchmark::State &state)
474 {
475 ASSERT_NE(capture_, nullptr);
476 int32_t ret;
477 uint32_t channelId = 0;
478
479 for (auto _ : state) {
480 ret = capture_->GetCurrentChannelId(capture_, &channelId);
481 EXPECT_EQ(ret, HDF_SUCCESS);
482 }
483 }
484
485 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)->
486 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
487
BENCHMARK_F(AudioCaptureBenchmarkTest,SetExtraParams)488 BENCHMARK_F(AudioCaptureBenchmarkTest, SetExtraParams)(benchmark::State &state)
489 {
490 ASSERT_NE(capture_, nullptr);
491 int32_t ret;
492 char keyValueList[AUDIO_CAPTURE_BUF_TEST] =
493 "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
494
495 for (auto _ : state) {
496 ret = capture_->SetExtraParams(capture_, keyValueList);
497 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
498 }
499 }
500
501 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetExtraParams)->
502 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
503
BENCHMARK_F(AudioCaptureBenchmarkTest,GetExtraParams)504 BENCHMARK_F(AudioCaptureBenchmarkTest, GetExtraParams)(benchmark::State &state)
505 {
506 ASSERT_NE(capture_, nullptr);
507 int32_t ret;
508 char keyValueListReply[AUDIO_CAPTURE_BUF_TEST] = {};
509 uint32_t listLenth = AUDIO_CAPTURE_BUF_TEST;
510
511 for (auto _ : state) {
512 ret = capture_->GetExtraParams(capture_, keyValueListReply, listLenth);
513 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
514 }
515 }
516
517 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetExtraParams)->
518 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
519
BENCHMARK_F(AudioCaptureBenchmarkTest,SelectScene)520 BENCHMARK_F(AudioCaptureBenchmarkTest, SelectScene)(benchmark::State &state)
521 {
522 ASSERT_NE(capture_, nullptr);
523 int32_t ret;
524 struct AudioSceneDescriptor scene;
525 scene.scene.id = AUDIO_IN_MEDIA;
526 scene.desc.pins = PIN_IN_MIC;
527 scene.desc.desc = const_cast<char*>("primary");
528
529 for (auto _ : state) {
530 ret = capture_->SelectScene(capture_, &scene);
531 EXPECT_EQ(ret, HDF_SUCCESS);
532 }
533 }
534
535 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SelectScene)->
536 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
537
BENCHMARK_F(AudioCaptureBenchmarkTest,SetGain)538 BENCHMARK_F(AudioCaptureBenchmarkTest, SetGain)(benchmark::State &state)
539 {
540 ASSERT_NE(capture_, nullptr);
541 int32_t ret;
542 float gain = GAIN_VALUE;
543
544 for (auto _ : state) {
545 ret = capture_->SetGain(capture_, gain);
546 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
547 }
548 }
549
550 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetGain)->
551 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
552
BENCHMARK_F(AudioCaptureBenchmarkTest,GetGain)553 BENCHMARK_F(AudioCaptureBenchmarkTest, GetGain)(benchmark::State &state)
554 {
555 ASSERT_NE(capture_, nullptr);
556 int32_t ret;
557 float gain;
558
559 for (auto _ : state) {
560 ret = capture_->GetGain(capture_, &gain);
561 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
562 }
563 }
564
565 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGain)->
566 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
567
BENCHMARK_F(AudioCaptureBenchmarkTest,GetMmapPosition)568 BENCHMARK_F(AudioCaptureBenchmarkTest, GetMmapPosition)(benchmark::State &state)
569 {
570 ASSERT_NE(capture_, nullptr);
571 int32_t ret;
572 uint64_t frames = 0;
573 struct AudioTimeStamp time;
574 time.tvNSec = 0;
575 time.tvSec = 0;
576
577 for (auto _ : state) {
578 ret = capture_->GetMmapPosition(capture_, &frames, &time);
579 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
580 }
581 }
582
583 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMmapPosition)->
584 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
585
BENCHMARK_F(AudioCaptureBenchmarkTest,GetFrameSize)586 BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameSize)(benchmark::State &state)
587 {
588 ASSERT_NE(capture_, nullptr);
589 int32_t ret;
590 uint64_t frameSize = 0;
591
592 for (auto _ : state) {
593 ret = capture_->GetFrameSize(capture_, &frameSize);
594 EXPECT_EQ(ret, HDF_SUCCESS);
595 }
596 }
597
598 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameSize)->
599 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
600
BENCHMARK_F(AudioCaptureBenchmarkTest,GetFrameCount)601 BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameCount)(benchmark::State &state)
602 {
603 ASSERT_NE(capture_, nullptr);
604 int32_t ret;
605 uint64_t frameCount = 0;
606
607 for (auto _ : state) {
608 ret = capture_->GetFrameCount(capture_, &frameCount);
609 EXPECT_EQ(ret, HDF_SUCCESS);
610 }
611 }
612
613 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameCount)->
614 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
615
BENCHMARK_F(AudioCaptureBenchmarkTest,CheckSceneCapability)616 BENCHMARK_F(AudioCaptureBenchmarkTest, CheckSceneCapability)(benchmark::State &state)
617 {
618 ASSERT_NE(capture_, nullptr);
619 int32_t ret;
620 struct AudioSceneDescriptor sceneDesc = {};
621 sceneDesc.desc.pins = PIN_IN_MIC;
622 sceneDesc.desc.desc = strdup("mic");
623 sceneDesc.scene.id = AUDIO_IN_COMMUNICATION;
624 bool isSupport = false;
625
626 for (auto _ : state) {
627 ret = capture_->CheckSceneCapability(capture_, &sceneDesc, &isSupport);
628 EXPECT_EQ(ret, HDF_SUCCESS);
629 }
630 free(sceneDesc.desc.desc);
631 sceneDesc.desc.desc = nullptr;
632 }
633
634 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CheckSceneCapability)->
635 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
636
BENCHMARK_F(AudioCaptureBenchmarkTest,AddAndRemoveAudioEffect)637 BENCHMARK_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)(benchmark::State &state)
638 {
639 ASSERT_NE(capture_, nullptr);
640 int32_t ret;
641 uint64_t effectId = 0;
642
643 for (auto _ : state) {
644 ret = capture_->AddAudioEffect(capture_, effectId);
645 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
646
647 ret = capture_->RemoveAudioEffect(capture_, effectId);
648 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
649 }
650 }
651
652 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)->
653 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
654
BENCHMARK_F(AudioCaptureBenchmarkTest,GetFrameBufferSize)655 BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)(benchmark::State &state)
656 {
657 ASSERT_NE(capture_, nullptr);
658 int32_t ret;
659 uint64_t bufferSize = 0;
660
661 for (auto _ : state) {
662 ret = capture_->GetFrameBufferSize(capture_, &bufferSize);
663 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
664 }
665 }
666
667 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)->
668 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
669
BENCHMARK_F(AudioCaptureBenchmarkTest,IsSupportsPauseAndResume)670 BENCHMARK_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)(benchmark::State &state)
671 {
672 ASSERT_NE(capture_, nullptr);
673 int32_t ret;
674 bool supportPause = false;
675 bool supportResume = false;
676
677 for (auto _ : state) {
678 ret = capture_->IsSupportsPauseAndResume(capture_, &supportPause, &supportResume);
679 ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
680 }
681 }
682
683 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)->
684 Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
685 }
686