• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "v3_0/iaudio_capture.h"
22 #include "v3_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 
190     ASSERT_NE(capture_, nullptr);
191     EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyCapture(adapter_, captureId_));
192 
193     ASSERT_NE(manager_, nullptr);
194     EXPECT_EQ(HDF_SUCCESS, manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName));
195     ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
196 
197     IAudioManagerRelease(manager_, false);
198 }
199 
BENCHMARK_F(AudioCaptureBenchmarkTest,CaptureFrame)200 BENCHMARK_F(AudioCaptureBenchmarkTest, CaptureFrame)(benchmark::State &state)
201 {
202     ASSERT_NE(capture_, nullptr);
203     uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
204     uint64_t requestBytes = frameLen;
205 
206     int32_t ret = capture_->Start(capture_);
207     EXPECT_EQ(ret, HDF_SUCCESS);
208 
209     int8_t *frame = (int8_t *)calloc(1, frameLen);
210     EXPECT_NE(nullptr, frame);
211 
212     for (auto _ : state) {
213         ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
214         EXPECT_EQ(ret, HDF_SUCCESS);
215     }
216     capture_->Stop(capture_);
217 
218     if (frame != nullptr) {
219         free(frame);
220         frame = nullptr;
221     }
222 }
223 
224 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CaptureFrame)->
225     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
226 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetCapturePosition)227 BENCHMARK_F(AudioCaptureBenchmarkTest, GetCapturePosition)(benchmark::State &state)
228 {
229     ASSERT_NE(capture_, nullptr);
230     uint64_t frames;
231     struct AudioTimeStamp time;
232     uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
233     uint64_t requestBytes = frameLen;
234 
235     int32_t ret = capture_->Start(capture_);
236     EXPECT_EQ(ret, HDF_SUCCESS);
237 
238     int8_t *frame = (int8_t *)calloc(1, frameLen);
239     EXPECT_NE(nullptr, frame);
240 
241     ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
242     EXPECT_EQ(ret, HDF_SUCCESS);
243 
244     for (auto _ : state) {
245         ret = capture_->GetCapturePosition(capture_, &frames, &time);
246         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
247     }
248     capture_->Stop(capture_);
249 
250     if (frame != nullptr) {
251         free(frame);
252         frame = nullptr;
253     }
254 }
255 
256 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCapturePosition)->
257     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
258 
BENCHMARK_F(AudioCaptureBenchmarkTest,StartAndStop)259 BENCHMARK_F(AudioCaptureBenchmarkTest, StartAndStop)(benchmark::State &state)
260 {
261     ASSERT_NE(capture_, nullptr);
262     int32_t ret;
263     for (auto _ : state) {
264         ret = capture_->Start(capture_);
265         EXPECT_EQ(ret, HDF_SUCCESS);
266         ret = capture_->Stop(capture_);
267         EXPECT_EQ(ret, HDF_SUCCESS);
268     }
269 }
270 
271 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, StartAndStop)->
272     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
273 
BENCHMARK_F(AudioCaptureBenchmarkTest,Pause)274 BENCHMARK_F(AudioCaptureBenchmarkTest, Pause)(benchmark::State &state)
275 {
276     ASSERT_NE(capture_, nullptr);
277     int32_t ret = capture_->Start(capture_);
278     EXPECT_EQ(ret, HDF_SUCCESS);
279 
280     for (auto _ : state) {
281         ret = capture_->Pause(capture_);
282         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
283     }
284 
285     ret = capture_->Stop(capture_);
286     ASSERT_EQ(ret, HDF_SUCCESS);
287 }
288 
289 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Pause)->
290     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
291 
BENCHMARK_F(AudioCaptureBenchmarkTest,Resume)292 BENCHMARK_F(AudioCaptureBenchmarkTest, Resume)(benchmark::State &state)
293 {
294     ASSERT_NE(capture_, nullptr);
295     int32_t ret = capture_->Start(capture_);
296     EXPECT_EQ(ret, HDF_SUCCESS);
297 
298     ret = capture_->Pause(capture_);
299     ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
300 
301     for (auto _ : state) {
302         ret = capture_->Resume(capture_);
303         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
304     }
305 
306     ret = capture_->Stop(capture_);
307     ASSERT_EQ(ret, HDF_SUCCESS);
308 }
309 
310 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Resume)->
311     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
312 
BENCHMARK_F(AudioCaptureBenchmarkTest,Flush)313 BENCHMARK_F(AudioCaptureBenchmarkTest, Flush)(benchmark::State &state)
314 {
315     ASSERT_NE(capture_, nullptr);
316     int32_t ret;
317     for (auto _ : state) {
318         ret = capture_->Flush(capture_);
319         EXPECT_NE(ret, HDF_SUCCESS);
320     }
321 }
322 
323 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Flush)->
324     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
325 
BENCHMARK_F(AudioCaptureBenchmarkTest,TurnStandbyMode)326 BENCHMARK_F(AudioCaptureBenchmarkTest, TurnStandbyMode)(benchmark::State &state)
327 {
328     ASSERT_NE(capture_, nullptr);
329     int32_t ret;
330     for (auto _ : state) {
331         ret = capture_->Start(capture_);
332         EXPECT_EQ(ret, HDF_SUCCESS);
333         ret = capture_->TurnStandbyMode(capture_);
334         EXPECT_EQ(ret, HDF_SUCCESS);
335         capture_->Stop(capture_);
336     }
337 }
338 
339 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, TurnStandbyMode)->
340     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
341 
BENCHMARK_F(AudioCaptureBenchmarkTest,AudioDevDump)342 BENCHMARK_F(AudioCaptureBenchmarkTest, AudioDevDump)(benchmark::State &state)
343 {
344     ASSERT_NE(capture_, nullptr);
345     int32_t ret;
346     int32_t range = RANGE_VALUE;
347     char pathBuf[] = "/data/CaptureDump.log";
348 
349     FILE *file = fopen(pathBuf, "wb+");
350     ASSERT_NE(nullptr, file);
351     int fd = fileno(file);
352     if (fd == -1) {
353         fclose(file);
354         ASSERT_NE(fd, -1);
355     }
356 
357     for (auto _ : state) {
358         ret = capture_->AudioDevDump(capture_, range, fd);
359         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
360     }
361     fclose(file);
362 }
363 
364 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AudioDevDump)->
365     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
366 
BENCHMARK_F(AudioCaptureBenchmarkTest,SetMute)367 BENCHMARK_F(AudioCaptureBenchmarkTest, SetMute)(benchmark::State &state)
368 {
369     ASSERT_NE(capture_, nullptr);
370     int32_t ret;
371     bool isSupport = false;
372 
373     for (auto _ : state) {
374         ret = capture_->SetMute(capture_, isSupport);
375         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
376     }
377 }
378 
379 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetMute)->
380     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
381 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetMute)382 BENCHMARK_F(AudioCaptureBenchmarkTest, GetMute)(benchmark::State &state)
383 {
384     ASSERT_NE(capture_, nullptr);
385     int32_t ret;
386     bool isSupport = true;
387 
388     for (auto _ : state) {
389         ret = capture_->GetMute(capture_, &isSupport);
390         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
391     }
392 }
393 
394 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMute)->
395     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
396 
BENCHMARK_F(AudioCaptureBenchmarkTest,SetVolume)397 BENCHMARK_F(AudioCaptureBenchmarkTest, SetVolume)(benchmark::State &state)
398 {
399     ASSERT_NE(capture_, nullptr);
400     int32_t ret;
401     for (auto _ : state) {
402         ret = capture_->SetVolume(capture_, HALF_OF_MAX_VOLUME);
403         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
404     }
405 }
406 
407 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetVolume)->
408     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
409 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetVolume)410 BENCHMARK_F(AudioCaptureBenchmarkTest, GetVolume)(benchmark::State &state)
411 {
412     ASSERT_NE(capture_, nullptr);
413     int32_t ret;
414     float volume = 0.0;
415 
416     for (auto _ : state) {
417         ret = capture_->GetVolume(capture_, &volume);
418         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
419     }
420 }
421 
422 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetVolume)->
423     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
424 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetGainThreshold)425 BENCHMARK_F(AudioCaptureBenchmarkTest, GetGainThreshold)(benchmark::State &state)
426 {
427     ASSERT_NE(capture_, nullptr);
428     int32_t ret;
429     float bottom = 0.0;
430     float top = 0.0;
431 
432     for (auto _ : state) {
433         ret = capture_->GetGainThreshold(capture_, &bottom, &top);
434         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
435     }
436 }
437 
438 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGainThreshold)->
439     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
440 
BENCHMARK_F(AudioCaptureBenchmarkTest,SetSampleAttributes)441 BENCHMARK_F(AudioCaptureBenchmarkTest, SetSampleAttributes)(benchmark::State &state)
442 {
443     ASSERT_NE(capture_, nullptr);
444     int32_t ret;
445     struct AudioSampleAttributes attrs;
446     InitCaptureAttrs(attrs);
447 
448     for (auto _ : state) {
449         ret = capture_->SetSampleAttributes(capture_, &attrs);
450         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
451     }
452 }
453 
454 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetSampleAttributes)->
455     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
456 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetSampleAttributes)457 BENCHMARK_F(AudioCaptureBenchmarkTest, GetSampleAttributes)(benchmark::State &state)
458 {
459     ASSERT_NE(capture_, nullptr);
460     int32_t ret;
461     struct AudioSampleAttributes attrs = {};
462 
463     for (auto _ : state) {
464         ret = capture_->GetSampleAttributes(capture_, &attrs);
465         EXPECT_EQ(ret, HDF_SUCCESS);
466     }
467 }
468 
469 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetSampleAttributes)->
470     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
471 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetCurrentChannelId)472 BENCHMARK_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)(benchmark::State &state)
473 {
474     ASSERT_NE(capture_, nullptr);
475     int32_t ret;
476     uint32_t channelId = 0;
477 
478     for (auto _ : state) {
479         ret = capture_->GetCurrentChannelId(capture_, &channelId);
480         EXPECT_EQ(ret, HDF_SUCCESS);
481     }
482 }
483 
484 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)->
485     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
486 
BENCHMARK_F(AudioCaptureBenchmarkTest,SetExtraParams)487 BENCHMARK_F(AudioCaptureBenchmarkTest, SetExtraParams)(benchmark::State &state)
488 {
489     ASSERT_NE(capture_, nullptr);
490     int32_t ret;
491     char keyValueList[AUDIO_CAPTURE_BUF_TEST] =
492         "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
493 
494     for (auto _ : state) {
495         ret = capture_->SetExtraParams(capture_, keyValueList);
496         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
497     }
498 }
499 
500 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetExtraParams)->
501     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
502 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetExtraParams)503 BENCHMARK_F(AudioCaptureBenchmarkTest, GetExtraParams)(benchmark::State &state)
504 {
505     ASSERT_NE(capture_, nullptr);
506     int32_t ret;
507     char keyValueListReply[AUDIO_CAPTURE_BUF_TEST] = {};
508     uint32_t listLenth = AUDIO_CAPTURE_BUF_TEST;
509 
510     for (auto _ : state) {
511         ret = capture_->GetExtraParams(capture_, keyValueListReply, listLenth);
512         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
513     }
514 }
515 
516 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetExtraParams)->
517     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
518 
BENCHMARK_F(AudioCaptureBenchmarkTest,SelectScene)519 BENCHMARK_F(AudioCaptureBenchmarkTest, SelectScene)(benchmark::State &state)
520 {
521     ASSERT_NE(capture_, nullptr);
522     int32_t ret;
523     struct AudioSceneDescriptor scene;
524     scene.scene.id = AUDIO_IN_MEDIA;
525     scene.desc.pins = PIN_IN_MIC;
526     scene.desc.desc = const_cast<char*>("primary");
527 
528     for (auto _ : state) {
529         ret = capture_->SelectScene(capture_, &scene);
530         EXPECT_EQ(ret, HDF_SUCCESS);
531     }
532 }
533 
534 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SelectScene)->
535     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
536 
BENCHMARK_F(AudioCaptureBenchmarkTest,SetGain)537 BENCHMARK_F(AudioCaptureBenchmarkTest, SetGain)(benchmark::State &state)
538 {
539     ASSERT_NE(capture_, nullptr);
540     int32_t ret;
541     float gain = GAIN_VALUE;
542 
543     for (auto _ : state) {
544         ret = capture_->SetGain(capture_, gain);
545         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
546     }
547 }
548 
549 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetGain)->
550     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
551 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetGain)552 BENCHMARK_F(AudioCaptureBenchmarkTest, GetGain)(benchmark::State &state)
553 {
554     ASSERT_NE(capture_, nullptr);
555     int32_t ret;
556     float gain;
557 
558     for (auto _ : state) {
559         ret = capture_->GetGain(capture_, &gain);
560         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
561     }
562 }
563 
564 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGain)->
565     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
566 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetMmapPosition)567 BENCHMARK_F(AudioCaptureBenchmarkTest, GetMmapPosition)(benchmark::State &state)
568 {
569     ASSERT_NE(capture_, nullptr);
570     int32_t ret;
571     uint64_t frames = 0;
572     struct AudioTimeStamp time;
573     time.tvNSec = 0;
574     time.tvSec = 0;
575 
576     for (auto _ : state) {
577         ret = capture_->GetMmapPosition(capture_, &frames, &time);
578         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
579     }
580 }
581 
582 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMmapPosition)->
583     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
584 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetFrameSize)585 BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameSize)(benchmark::State &state)
586 {
587     ASSERT_NE(capture_, nullptr);
588     int32_t ret;
589     uint64_t frameSize = 0;
590 
591     for (auto _ : state) {
592         ret = capture_->GetFrameSize(capture_, &frameSize);
593         EXPECT_EQ(ret, HDF_SUCCESS);
594     }
595 }
596 
597 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameSize)->
598     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
599 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetFrameCount)600 BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameCount)(benchmark::State &state)
601 {
602     ASSERT_NE(capture_, nullptr);
603     int32_t ret;
604     uint64_t frameCount = 0;
605 
606     for (auto _ : state) {
607         ret = capture_->GetFrameCount(capture_, &frameCount);
608         EXPECT_EQ(ret, HDF_SUCCESS);
609     }
610 }
611 
612 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameCount)->
613     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
614 
BENCHMARK_F(AudioCaptureBenchmarkTest,CheckSceneCapability)615 BENCHMARK_F(AudioCaptureBenchmarkTest, CheckSceneCapability)(benchmark::State &state)
616 {
617     ASSERT_NE(capture_, nullptr);
618     int32_t ret;
619     struct AudioSceneDescriptor sceneDesc = {};
620     sceneDesc.desc.pins = PIN_IN_MIC;
621     sceneDesc.desc.desc = strdup("mic");
622     sceneDesc.scene.id = AUDIO_IN_COMMUNICATION;
623     bool isSupport = false;
624 
625     for (auto _ : state) {
626         ret = capture_->CheckSceneCapability(capture_, &sceneDesc, &isSupport);
627         EXPECT_EQ(ret, HDF_SUCCESS);
628     }
629     free(sceneDesc.desc.desc);
630     sceneDesc.desc.desc = nullptr;
631 }
632 
633 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CheckSceneCapability)->
634     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
635 
BENCHMARK_F(AudioCaptureBenchmarkTest,AddAndRemoveAudioEffect)636 BENCHMARK_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)(benchmark::State &state)
637 {
638     ASSERT_NE(capture_, nullptr);
639     int32_t ret;
640     uint64_t effectId = 0;
641 
642     for (auto _ : state) {
643         ret = capture_->AddAudioEffect(capture_, effectId);
644         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
645 
646         ret = capture_->RemoveAudioEffect(capture_, effectId);
647         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
648     }
649 }
650 
651 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)->
652     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
653 
BENCHMARK_F(AudioCaptureBenchmarkTest,GetFrameBufferSize)654 BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)(benchmark::State &state)
655 {
656     ASSERT_NE(capture_, nullptr);
657     int32_t ret;
658     uint64_t bufferSize = 0;
659 
660     for (auto _ : state) {
661         ret = capture_->GetFrameBufferSize(capture_, &bufferSize);
662         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
663     }
664 }
665 
666 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)->
667     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
668 
BENCHMARK_F(AudioCaptureBenchmarkTest,IsSupportsPauseAndResume)669 BENCHMARK_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)(benchmark::State &state)
670 {
671     ASSERT_NE(capture_, nullptr);
672     int32_t ret;
673     bool supportPause = false;
674     bool supportResume = false;
675 
676     for (auto _ : state) {
677         ret = capture_->IsSupportsPauseAndResume(capture_, &supportPause, &supportResume);
678         ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
679     }
680 }
681 
682 BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)->
683     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
684 }
685