1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#include <benchmark/benchmark.h>
17094332d3Sopenharmony_ci#include <climits>
18094332d3Sopenharmony_ci#include <gtest/gtest.h>
19094332d3Sopenharmony_ci#include "hdf_base.h"
20094332d3Sopenharmony_ci#include "osal_mem.h"
21094332d3Sopenharmony_ci#include "v4_0/iaudio_capture.h"
22094332d3Sopenharmony_ci#include "v4_0/iaudio_manager.h"
23094332d3Sopenharmony_ci
24094332d3Sopenharmony_ciusing namespace std;
25094332d3Sopenharmony_ciusing namespace testing::ext;
26094332d3Sopenharmony_cinamespace {
27094332d3Sopenharmony_cistatic const uint32_t MAX_AUDIO_ADAPTER_NUM = 5;
28094332d3Sopenharmony_ciconst int32_t AUDIO_CAPTURE_BUF_TEST = 1024;
29094332d3Sopenharmony_ciconst int BUFFER_LENTH = 1024 * 16;
30094332d3Sopenharmony_ciconst int DEEP_BUFFER_CAPTURE_PERIOD_SIZE = 4 * 1024;
31094332d3Sopenharmony_ciconst int DEFAULT_BUFFER_SIZE = 16384;
32094332d3Sopenharmony_ciconst float HALF_OF_MAX_VOLUME = 0.5;
33094332d3Sopenharmony_ciconst int MOVE_LEFT_NUM = 8;
34094332d3Sopenharmony_ciconst int TEST_SAMPLE_RATE_MASK_48000 = 48000;
35094332d3Sopenharmony_ciconst int TEST_CHANNEL_COUNT = 2;
36094332d3Sopenharmony_ciconst int32_t ITERATION_FREQUENCY = 100;
37094332d3Sopenharmony_ciconst int32_t REPETITION_FREQUENCY = 3;
38094332d3Sopenharmony_ciconst int32_t RANGE_VALUE = 4;
39094332d3Sopenharmony_ciconst float GAIN_VALUE = 1.0;
40094332d3Sopenharmony_ci
41094332d3Sopenharmony_ciclass AudioCaptureBenchmarkTest : public benchmark::Fixture {
42094332d3Sopenharmony_cipublic:
43094332d3Sopenharmony_ci    struct IAudioManager *manager_ = nullptr;;
44094332d3Sopenharmony_ci    struct IAudioAdapter *adapter_ = nullptr;
45094332d3Sopenharmony_ci    struct IAudioCapture *capture_ = nullptr;
46094332d3Sopenharmony_ci    uint32_t captureId_ = 0;
47094332d3Sopenharmony_ci    char *devDescriptorName_ = nullptr;
48094332d3Sopenharmony_ci    struct AudioAdapterDescriptor *adapterDescs_ = nullptr;
49094332d3Sopenharmony_ci    virtual void SetUp(const ::benchmark::State &state);
50094332d3Sopenharmony_ci    virtual void TearDown(const ::benchmark::State &state);
51094332d3Sopenharmony_ci    uint64_t GetCaptureBufferSize();
52094332d3Sopenharmony_ci    void InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc);
53094332d3Sopenharmony_ci    void InitCaptureAttrs(struct AudioSampleAttributes &attrs);
54094332d3Sopenharmony_ci    void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
55094332d3Sopenharmony_ci    void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
56094332d3Sopenharmony_ci};
57094332d3Sopenharmony_ci
58094332d3Sopenharmony_ciuint64_t AudioCaptureBenchmarkTest::GetCaptureBufferSize()
59094332d3Sopenharmony_ci{
60094332d3Sopenharmony_ci    int32_t ret = HDF_SUCCESS;
61094332d3Sopenharmony_ci    uint64_t frameSize = 0;
62094332d3Sopenharmony_ci    uint64_t frameCount = 0;
63094332d3Sopenharmony_ci    uint64_t bufferSize = 0;
64094332d3Sopenharmony_ci
65094332d3Sopenharmony_ci    if (capture_ == nullptr) {
66094332d3Sopenharmony_ci        return DEFAULT_BUFFER_SIZE;
67094332d3Sopenharmony_ci    }
68094332d3Sopenharmony_ci
69094332d3Sopenharmony_ci    ret = capture_->GetFrameSize(capture_, &frameSize);
70094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
71094332d3Sopenharmony_ci        return DEFAULT_BUFFER_SIZE;
72094332d3Sopenharmony_ci    }
73094332d3Sopenharmony_ci
74094332d3Sopenharmony_ci    ret = capture_->GetFrameCount(capture_, &frameCount);
75094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
76094332d3Sopenharmony_ci        return DEFAULT_BUFFER_SIZE;
77094332d3Sopenharmony_ci    }
78094332d3Sopenharmony_ci
79094332d3Sopenharmony_ci    bufferSize = frameCount * frameSize;
80094332d3Sopenharmony_ci    if (bufferSize == 0) {
81094332d3Sopenharmony_ci        bufferSize = DEFAULT_BUFFER_SIZE;
82094332d3Sopenharmony_ci    }
83094332d3Sopenharmony_ci
84094332d3Sopenharmony_ci    return bufferSize;
85094332d3Sopenharmony_ci}
86094332d3Sopenharmony_ci
87094332d3Sopenharmony_civoid AudioCaptureBenchmarkTest::InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc)
88094332d3Sopenharmony_ci{
89094332d3Sopenharmony_ci    devDesc.pins = (enum AudioPortPin)PIN_IN_MIC;
90094332d3Sopenharmony_ci    devDescriptorName_ = strdup("cardname");
91094332d3Sopenharmony_ci    devDesc.desc = devDescriptorName_;
92094332d3Sopenharmony_ci
93094332d3Sopenharmony_ci    ASSERT_NE(adapterDescs_, nullptr);
94094332d3Sopenharmony_ci    ASSERT_NE(adapterDescs_->ports, nullptr);
95094332d3Sopenharmony_ci    for (uint32_t index = 0; index < adapterDescs_->portsLen; index++) {
96094332d3Sopenharmony_ci        if (adapterDescs_->ports[index].dir == PORT_IN) {
97094332d3Sopenharmony_ci            devDesc.portId = adapterDescs_->ports[index].portId;
98094332d3Sopenharmony_ci            return;
99094332d3Sopenharmony_ci        }
100094332d3Sopenharmony_ci    }
101094332d3Sopenharmony_ci}
102094332d3Sopenharmony_ci
103094332d3Sopenharmony_civoid AudioCaptureBenchmarkTest::InitCaptureAttrs(struct AudioSampleAttributes &attrs)
104094332d3Sopenharmony_ci{
105094332d3Sopenharmony_ci    attrs.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
106094332d3Sopenharmony_ci    attrs.channelCount = TEST_CHANNEL_COUNT;
107094332d3Sopenharmony_ci    attrs.sampleRate = TEST_SAMPLE_RATE_MASK_48000;
108094332d3Sopenharmony_ci    attrs.interleaved = 0;
109094332d3Sopenharmony_ci    attrs.type = AUDIO_IN_MEDIA;
110094332d3Sopenharmony_ci    attrs.period = DEEP_BUFFER_CAPTURE_PERIOD_SIZE;
111094332d3Sopenharmony_ci    attrs.frameSize = AUDIO_FORMAT_TYPE_PCM_16_BIT * TEST_CHANNEL_COUNT / MOVE_LEFT_NUM;
112094332d3Sopenharmony_ci    attrs.isBigEndian = false;
113094332d3Sopenharmony_ci    attrs.isSignedData = true;
114094332d3Sopenharmony_ci    attrs.startThreshold = DEEP_BUFFER_CAPTURE_PERIOD_SIZE / (attrs.format * attrs.channelCount / MOVE_LEFT_NUM);
115094332d3Sopenharmony_ci    attrs.stopThreshold = INT_MAX;
116094332d3Sopenharmony_ci    attrs.silenceThreshold = BUFFER_LENTH;
117094332d3Sopenharmony_ci}
118094332d3Sopenharmony_ci
119094332d3Sopenharmony_civoid AudioCaptureBenchmarkTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
120094332d3Sopenharmony_ci{
121094332d3Sopenharmony_ci    if (dataBlock == nullptr) {
122094332d3Sopenharmony_ci        return;
123094332d3Sopenharmony_ci    }
124094332d3Sopenharmony_ci
125094332d3Sopenharmony_ci    if (dataBlock->adapterName != nullptr) {
126094332d3Sopenharmony_ci        OsalMemFree(dataBlock->adapterName);
127094332d3Sopenharmony_ci        dataBlock->adapterName = nullptr;
128094332d3Sopenharmony_ci    }
129094332d3Sopenharmony_ci
130094332d3Sopenharmony_ci    if (dataBlock->ports != nullptr) {
131094332d3Sopenharmony_ci        OsalMemFree(dataBlock->ports);
132094332d3Sopenharmony_ci    }
133094332d3Sopenharmony_ci
134094332d3Sopenharmony_ci    if (freeSelf) {
135094332d3Sopenharmony_ci        OsalMemFree(dataBlock);
136094332d3Sopenharmony_ci    }
137094332d3Sopenharmony_ci}
138094332d3Sopenharmony_ci
139094332d3Sopenharmony_civoid AudioCaptureBenchmarkTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
140094332d3Sopenharmony_ci{
141094332d3Sopenharmony_ci    if (descs == nullptr || descsLen == 0) {
142094332d3Sopenharmony_ci        return;
143094332d3Sopenharmony_ci    }
144094332d3Sopenharmony_ci
145094332d3Sopenharmony_ci    for (uint32_t i = 0; i < descsLen; i++) {
146094332d3Sopenharmony_ci        FreeAdapterElements(&descs[i], false);
147094332d3Sopenharmony_ci    }
148094332d3Sopenharmony_ci}
149094332d3Sopenharmony_ci
150094332d3Sopenharmony_civoid AudioCaptureBenchmarkTest::SetUp(const ::benchmark::State &state)
151094332d3Sopenharmony_ci{
152094332d3Sopenharmony_ci    uint32_t size = MAX_AUDIO_ADAPTER_NUM;
153094332d3Sopenharmony_ci    struct AudioDeviceDescriptor devDesc = {};
154094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs = {};
155094332d3Sopenharmony_ci
156094332d3Sopenharmony_ci    manager_ = IAudioManagerGet(false);
157094332d3Sopenharmony_ci    ASSERT_NE(manager_, nullptr);
158094332d3Sopenharmony_ci
159094332d3Sopenharmony_ci    adapterDescs_ = (struct AudioAdapterDescriptor *)OsalMemCalloc(
160094332d3Sopenharmony_ci        sizeof(struct AudioAdapterDescriptor) * (MAX_AUDIO_ADAPTER_NUM));
161094332d3Sopenharmony_ci    ASSERT_NE(adapterDescs_, nullptr);
162094332d3Sopenharmony_ci
163094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
164094332d3Sopenharmony_ci    if (size > MAX_AUDIO_ADAPTER_NUM) {
165094332d3Sopenharmony_ci        ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
166094332d3Sopenharmony_ci        ASSERT_LT(size, MAX_AUDIO_ADAPTER_NUM);
167094332d3Sopenharmony_ci    }
168094332d3Sopenharmony_ci
169094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_));
170094332d3Sopenharmony_ci    if (adapter_ == nullptr) {
171094332d3Sopenharmony_ci        ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
172094332d3Sopenharmony_ci        EXPECT_NE(adapter_, nullptr);
173094332d3Sopenharmony_ci    }
174094332d3Sopenharmony_ci
175094332d3Sopenharmony_ci    InitCaptureDevDesc(devDesc);
176094332d3Sopenharmony_ci    InitCaptureAttrs(attrs);
177094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devDesc, &attrs, &capture_, &captureId_));
178094332d3Sopenharmony_ci    if (capture_ == nullptr) {
179094332d3Sopenharmony_ci        (void)manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
180094332d3Sopenharmony_ci        ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
181094332d3Sopenharmony_ci    }
182094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
183094332d3Sopenharmony_ci}
184094332d3Sopenharmony_ci
185094332d3Sopenharmony_civoid AudioCaptureBenchmarkTest::TearDown(const ::benchmark::State &state)
186094332d3Sopenharmony_ci{
187094332d3Sopenharmony_ci    ASSERT_NE(devDescriptorName_, nullptr);
188094332d3Sopenharmony_ci    free(devDescriptorName_);
189094332d3Sopenharmony_ci
190094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
191094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, adapter_->DestroyCapture(adapter_, captureId_));
192094332d3Sopenharmony_ci
193094332d3Sopenharmony_ci    ASSERT_NE(manager_, nullptr);
194094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName));
195094332d3Sopenharmony_ci    ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
196094332d3Sopenharmony_ci
197094332d3Sopenharmony_ci    IAudioManagerRelease(manager_, false);
198094332d3Sopenharmony_ci}
199094332d3Sopenharmony_ci
200094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, CaptureFrame)(benchmark::State &state)
201094332d3Sopenharmony_ci{
202094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
203094332d3Sopenharmony_ci    uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
204094332d3Sopenharmony_ci    uint64_t requestBytes = frameLen;
205094332d3Sopenharmony_ci
206094332d3Sopenharmony_ci    int32_t ret = capture_->Start(capture_);
207094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
208094332d3Sopenharmony_ci
209094332d3Sopenharmony_ci    int8_t *frame = (int8_t *)calloc(1, frameLen);
210094332d3Sopenharmony_ci    EXPECT_NE(nullptr, frame);
211094332d3Sopenharmony_ci
212094332d3Sopenharmony_ci    for (auto _ : state) {
213094332d3Sopenharmony_ci        ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
214094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
215094332d3Sopenharmony_ci    }
216094332d3Sopenharmony_ci    capture_->Stop(capture_);
217094332d3Sopenharmony_ci
218094332d3Sopenharmony_ci    if (frame != nullptr) {
219094332d3Sopenharmony_ci        free(frame);
220094332d3Sopenharmony_ci        frame = nullptr;
221094332d3Sopenharmony_ci    }
222094332d3Sopenharmony_ci}
223094332d3Sopenharmony_ci
224094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CaptureFrame)->
225094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
226094332d3Sopenharmony_ci
227094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetCapturePosition)(benchmark::State &state)
228094332d3Sopenharmony_ci{
229094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
230094332d3Sopenharmony_ci    uint64_t frames;
231094332d3Sopenharmony_ci    struct AudioTimeStamp time;
232094332d3Sopenharmony_ci    uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
233094332d3Sopenharmony_ci    uint64_t requestBytes = frameLen;
234094332d3Sopenharmony_ci
235094332d3Sopenharmony_ci    int32_t ret = capture_->Start(capture_);
236094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
237094332d3Sopenharmony_ci
238094332d3Sopenharmony_ci    int8_t *frame = (int8_t *)calloc(1, frameLen);
239094332d3Sopenharmony_ci    EXPECT_NE(nullptr, frame);
240094332d3Sopenharmony_ci
241094332d3Sopenharmony_ci    ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
242094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
243094332d3Sopenharmony_ci
244094332d3Sopenharmony_ci    for (auto _ : state) {
245094332d3Sopenharmony_ci        ret = capture_->GetCapturePosition(capture_, &frames, &time);
246094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
247094332d3Sopenharmony_ci    }
248094332d3Sopenharmony_ci    capture_->Stop(capture_);
249094332d3Sopenharmony_ci
250094332d3Sopenharmony_ci    if (frame != nullptr) {
251094332d3Sopenharmony_ci        free(frame);
252094332d3Sopenharmony_ci        frame = nullptr;
253094332d3Sopenharmony_ci    }
254094332d3Sopenharmony_ci}
255094332d3Sopenharmony_ci
256094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCapturePosition)->
257094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
258094332d3Sopenharmony_ci
259094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, StartAndStop)(benchmark::State &state)
260094332d3Sopenharmony_ci{
261094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
262094332d3Sopenharmony_ci    int32_t ret;
263094332d3Sopenharmony_ci    for (auto _ : state) {
264094332d3Sopenharmony_ci        ret = capture_->Start(capture_);
265094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
266094332d3Sopenharmony_ci        ret = capture_->Stop(capture_);
267094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
268094332d3Sopenharmony_ci    }
269094332d3Sopenharmony_ci}
270094332d3Sopenharmony_ci
271094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, StartAndStop)->
272094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
273094332d3Sopenharmony_ci
274094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, Pause)(benchmark::State &state)
275094332d3Sopenharmony_ci{
276094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
277094332d3Sopenharmony_ci    int32_t ret = capture_->Start(capture_);
278094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
279094332d3Sopenharmony_ci
280094332d3Sopenharmony_ci    for (auto _ : state) {
281094332d3Sopenharmony_ci        ret = capture_->Pause(capture_);
282094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
283094332d3Sopenharmony_ci    }
284094332d3Sopenharmony_ci
285094332d3Sopenharmony_ci    ret = capture_->Stop(capture_);
286094332d3Sopenharmony_ci    ASSERT_EQ(ret, HDF_SUCCESS);
287094332d3Sopenharmony_ci}
288094332d3Sopenharmony_ci
289094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Pause)->
290094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
291094332d3Sopenharmony_ci
292094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, Resume)(benchmark::State &state)
293094332d3Sopenharmony_ci{
294094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
295094332d3Sopenharmony_ci    int32_t ret = capture_->Start(capture_);
296094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
297094332d3Sopenharmony_ci
298094332d3Sopenharmony_ci    ret = capture_->Pause(capture_);
299094332d3Sopenharmony_ci    ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
300094332d3Sopenharmony_ci
301094332d3Sopenharmony_ci    for (auto _ : state) {
302094332d3Sopenharmony_ci        ret = capture_->Resume(capture_);
303094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
304094332d3Sopenharmony_ci    }
305094332d3Sopenharmony_ci
306094332d3Sopenharmony_ci    ret = capture_->Stop(capture_);
307094332d3Sopenharmony_ci    ASSERT_EQ(ret, HDF_SUCCESS);
308094332d3Sopenharmony_ci}
309094332d3Sopenharmony_ci
310094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Resume)->
311094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
312094332d3Sopenharmony_ci
313094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, Flush)(benchmark::State &state)
314094332d3Sopenharmony_ci{
315094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
316094332d3Sopenharmony_ci    int32_t ret;
317094332d3Sopenharmony_ci    for (auto _ : state) {
318094332d3Sopenharmony_ci        ret = capture_->Flush(capture_);
319094332d3Sopenharmony_ci        EXPECT_NE(ret, HDF_SUCCESS);
320094332d3Sopenharmony_ci    }
321094332d3Sopenharmony_ci}
322094332d3Sopenharmony_ci
323094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Flush)->
324094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
325094332d3Sopenharmony_ci
326094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, TurnStandbyMode)(benchmark::State &state)
327094332d3Sopenharmony_ci{
328094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
329094332d3Sopenharmony_ci    int32_t ret;
330094332d3Sopenharmony_ci    for (auto _ : state) {
331094332d3Sopenharmony_ci        ret = capture_->Start(capture_);
332094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
333094332d3Sopenharmony_ci        ret = capture_->TurnStandbyMode(capture_);
334094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
335094332d3Sopenharmony_ci        capture_->Stop(capture_);
336094332d3Sopenharmony_ci    }
337094332d3Sopenharmony_ci}
338094332d3Sopenharmony_ci
339094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, TurnStandbyMode)->
340094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
341094332d3Sopenharmony_ci
342094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, AudioDevDump)(benchmark::State &state)
343094332d3Sopenharmony_ci{
344094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
345094332d3Sopenharmony_ci    int32_t ret;
346094332d3Sopenharmony_ci    int32_t range = RANGE_VALUE;
347094332d3Sopenharmony_ci    char pathBuf[] = "/data/CaptureDump.log";
348094332d3Sopenharmony_ci
349094332d3Sopenharmony_ci    FILE *file = fopen(pathBuf, "wb+");
350094332d3Sopenharmony_ci    ASSERT_NE(nullptr, file);
351094332d3Sopenharmony_ci    int fd = fileno(file);
352094332d3Sopenharmony_ci    if (fd == -1) {
353094332d3Sopenharmony_ci        fclose(file);
354094332d3Sopenharmony_ci        ASSERT_NE(fd, -1);
355094332d3Sopenharmony_ci    }
356094332d3Sopenharmony_ci
357094332d3Sopenharmony_ci    for (auto _ : state) {
358094332d3Sopenharmony_ci        ret = capture_->AudioDevDump(capture_, range, fd);
359094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
360094332d3Sopenharmony_ci    }
361094332d3Sopenharmony_ci    fclose(file);
362094332d3Sopenharmony_ci}
363094332d3Sopenharmony_ci
364094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AudioDevDump)->
365094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
366094332d3Sopenharmony_ci
367094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, SetMute)(benchmark::State &state)
368094332d3Sopenharmony_ci{
369094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
370094332d3Sopenharmony_ci    int32_t ret;
371094332d3Sopenharmony_ci    bool isSupport = false;
372094332d3Sopenharmony_ci
373094332d3Sopenharmony_ci    for (auto _ : state) {
374094332d3Sopenharmony_ci        ret = capture_->SetMute(capture_, isSupport);
375094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
376094332d3Sopenharmony_ci    }
377094332d3Sopenharmony_ci}
378094332d3Sopenharmony_ci
379094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetMute)->
380094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
381094332d3Sopenharmony_ci
382094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetMute)(benchmark::State &state)
383094332d3Sopenharmony_ci{
384094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
385094332d3Sopenharmony_ci    int32_t ret;
386094332d3Sopenharmony_ci    bool isSupport = true;
387094332d3Sopenharmony_ci
388094332d3Sopenharmony_ci    for (auto _ : state) {
389094332d3Sopenharmony_ci        ret = capture_->GetMute(capture_, &isSupport);
390094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
391094332d3Sopenharmony_ci    }
392094332d3Sopenharmony_ci}
393094332d3Sopenharmony_ci
394094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMute)->
395094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
396094332d3Sopenharmony_ci
397094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, SetVolume)(benchmark::State &state)
398094332d3Sopenharmony_ci{
399094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
400094332d3Sopenharmony_ci    int32_t ret;
401094332d3Sopenharmony_ci    for (auto _ : state) {
402094332d3Sopenharmony_ci        ret = capture_->SetVolume(capture_, HALF_OF_MAX_VOLUME);
403094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
404094332d3Sopenharmony_ci    }
405094332d3Sopenharmony_ci}
406094332d3Sopenharmony_ci
407094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetVolume)->
408094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
409094332d3Sopenharmony_ci
410094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetVolume)(benchmark::State &state)
411094332d3Sopenharmony_ci{
412094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
413094332d3Sopenharmony_ci    int32_t ret;
414094332d3Sopenharmony_ci    float volume = 0.0;
415094332d3Sopenharmony_ci
416094332d3Sopenharmony_ci    for (auto _ : state) {
417094332d3Sopenharmony_ci        ret = capture_->GetVolume(capture_, &volume);
418094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
419094332d3Sopenharmony_ci    }
420094332d3Sopenharmony_ci}
421094332d3Sopenharmony_ci
422094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetVolume)->
423094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
424094332d3Sopenharmony_ci
425094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetGainThreshold)(benchmark::State &state)
426094332d3Sopenharmony_ci{
427094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
428094332d3Sopenharmony_ci    int32_t ret;
429094332d3Sopenharmony_ci    float bottom = 0.0;
430094332d3Sopenharmony_ci    float top = 0.0;
431094332d3Sopenharmony_ci
432094332d3Sopenharmony_ci    for (auto _ : state) {
433094332d3Sopenharmony_ci        ret = capture_->GetGainThreshold(capture_, &bottom, &top);
434094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
435094332d3Sopenharmony_ci    }
436094332d3Sopenharmony_ci}
437094332d3Sopenharmony_ci
438094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGainThreshold)->
439094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
440094332d3Sopenharmony_ci
441094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, SetSampleAttributes)(benchmark::State &state)
442094332d3Sopenharmony_ci{
443094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
444094332d3Sopenharmony_ci    int32_t ret;
445094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs;
446094332d3Sopenharmony_ci    InitCaptureAttrs(attrs);
447094332d3Sopenharmony_ci
448094332d3Sopenharmony_ci    for (auto _ : state) {
449094332d3Sopenharmony_ci        ret = capture_->SetSampleAttributes(capture_, &attrs);
450094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
451094332d3Sopenharmony_ci    }
452094332d3Sopenharmony_ci}
453094332d3Sopenharmony_ci
454094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetSampleAttributes)->
455094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
456094332d3Sopenharmony_ci
457094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetSampleAttributes)(benchmark::State &state)
458094332d3Sopenharmony_ci{
459094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
460094332d3Sopenharmony_ci    int32_t ret;
461094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs = {};
462094332d3Sopenharmony_ci
463094332d3Sopenharmony_ci    for (auto _ : state) {
464094332d3Sopenharmony_ci        ret = capture_->GetSampleAttributes(capture_, &attrs);
465094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
466094332d3Sopenharmony_ci    }
467094332d3Sopenharmony_ci}
468094332d3Sopenharmony_ci
469094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetSampleAttributes)->
470094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
471094332d3Sopenharmony_ci
472094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)(benchmark::State &state)
473094332d3Sopenharmony_ci{
474094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
475094332d3Sopenharmony_ci    int32_t ret;
476094332d3Sopenharmony_ci    uint32_t channelId = 0;
477094332d3Sopenharmony_ci
478094332d3Sopenharmony_ci    for (auto _ : state) {
479094332d3Sopenharmony_ci        ret = capture_->GetCurrentChannelId(capture_, &channelId);
480094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
481094332d3Sopenharmony_ci    }
482094332d3Sopenharmony_ci}
483094332d3Sopenharmony_ci
484094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)->
485094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
486094332d3Sopenharmony_ci
487094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, SetExtraParams)(benchmark::State &state)
488094332d3Sopenharmony_ci{
489094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
490094332d3Sopenharmony_ci    int32_t ret;
491094332d3Sopenharmony_ci    char keyValueList[AUDIO_CAPTURE_BUF_TEST] =
492094332d3Sopenharmony_ci        "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
493094332d3Sopenharmony_ci
494094332d3Sopenharmony_ci    for (auto _ : state) {
495094332d3Sopenharmony_ci        ret = capture_->SetExtraParams(capture_, keyValueList);
496094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
497094332d3Sopenharmony_ci    }
498094332d3Sopenharmony_ci}
499094332d3Sopenharmony_ci
500094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetExtraParams)->
501094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
502094332d3Sopenharmony_ci
503094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetExtraParams)(benchmark::State &state)
504094332d3Sopenharmony_ci{
505094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
506094332d3Sopenharmony_ci    int32_t ret;
507094332d3Sopenharmony_ci    char keyValueListReply[AUDIO_CAPTURE_BUF_TEST] = {};
508094332d3Sopenharmony_ci    uint32_t listLenth = AUDIO_CAPTURE_BUF_TEST;
509094332d3Sopenharmony_ci
510094332d3Sopenharmony_ci    for (auto _ : state) {
511094332d3Sopenharmony_ci        ret = capture_->GetExtraParams(capture_, keyValueListReply, listLenth);
512094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
513094332d3Sopenharmony_ci    }
514094332d3Sopenharmony_ci}
515094332d3Sopenharmony_ci
516094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetExtraParams)->
517094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
518094332d3Sopenharmony_ci
519094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, SelectScene)(benchmark::State &state)
520094332d3Sopenharmony_ci{
521094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
522094332d3Sopenharmony_ci    int32_t ret;
523094332d3Sopenharmony_ci    struct AudioSceneDescriptor scene;
524094332d3Sopenharmony_ci    scene.scene.id = AUDIO_IN_MEDIA;
525094332d3Sopenharmony_ci    scene.desc.pins = PIN_IN_MIC;
526094332d3Sopenharmony_ci    scene.desc.desc = const_cast<char*>("primary");
527094332d3Sopenharmony_ci
528094332d3Sopenharmony_ci    for (auto _ : state) {
529094332d3Sopenharmony_ci        ret = capture_->SelectScene(capture_, &scene);
530094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
531094332d3Sopenharmony_ci    }
532094332d3Sopenharmony_ci}
533094332d3Sopenharmony_ci
534094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SelectScene)->
535094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
536094332d3Sopenharmony_ci
537094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, SetGain)(benchmark::State &state)
538094332d3Sopenharmony_ci{
539094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
540094332d3Sopenharmony_ci    int32_t ret;
541094332d3Sopenharmony_ci    float gain = GAIN_VALUE;
542094332d3Sopenharmony_ci
543094332d3Sopenharmony_ci    for (auto _ : state) {
544094332d3Sopenharmony_ci        ret = capture_->SetGain(capture_, gain);
545094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
546094332d3Sopenharmony_ci    }
547094332d3Sopenharmony_ci}
548094332d3Sopenharmony_ci
549094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetGain)->
550094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
551094332d3Sopenharmony_ci
552094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetGain)(benchmark::State &state)
553094332d3Sopenharmony_ci{
554094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
555094332d3Sopenharmony_ci    int32_t ret;
556094332d3Sopenharmony_ci    float gain;
557094332d3Sopenharmony_ci
558094332d3Sopenharmony_ci    for (auto _ : state) {
559094332d3Sopenharmony_ci        ret = capture_->GetGain(capture_, &gain);
560094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
561094332d3Sopenharmony_ci    }
562094332d3Sopenharmony_ci}
563094332d3Sopenharmony_ci
564094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGain)->
565094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
566094332d3Sopenharmony_ci
567094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetMmapPosition)(benchmark::State &state)
568094332d3Sopenharmony_ci{
569094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
570094332d3Sopenharmony_ci    int32_t ret;
571094332d3Sopenharmony_ci    uint64_t frames = 0;
572094332d3Sopenharmony_ci    struct AudioTimeStamp time;
573094332d3Sopenharmony_ci    time.tvNSec = 0;
574094332d3Sopenharmony_ci    time.tvSec = 0;
575094332d3Sopenharmony_ci
576094332d3Sopenharmony_ci    for (auto _ : state) {
577094332d3Sopenharmony_ci        ret = capture_->GetMmapPosition(capture_, &frames, &time);
578094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
579094332d3Sopenharmony_ci    }
580094332d3Sopenharmony_ci}
581094332d3Sopenharmony_ci
582094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMmapPosition)->
583094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
584094332d3Sopenharmony_ci
585094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameSize)(benchmark::State &state)
586094332d3Sopenharmony_ci{
587094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
588094332d3Sopenharmony_ci    int32_t ret;
589094332d3Sopenharmony_ci    uint64_t frameSize = 0;
590094332d3Sopenharmony_ci
591094332d3Sopenharmony_ci    for (auto _ : state) {
592094332d3Sopenharmony_ci        ret = capture_->GetFrameSize(capture_, &frameSize);
593094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
594094332d3Sopenharmony_ci    }
595094332d3Sopenharmony_ci}
596094332d3Sopenharmony_ci
597094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameSize)->
598094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
599094332d3Sopenharmony_ci
600094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameCount)(benchmark::State &state)
601094332d3Sopenharmony_ci{
602094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
603094332d3Sopenharmony_ci    int32_t ret;
604094332d3Sopenharmony_ci    uint64_t frameCount = 0;
605094332d3Sopenharmony_ci
606094332d3Sopenharmony_ci    for (auto _ : state) {
607094332d3Sopenharmony_ci        ret = capture_->GetFrameCount(capture_, &frameCount);
608094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
609094332d3Sopenharmony_ci    }
610094332d3Sopenharmony_ci}
611094332d3Sopenharmony_ci
612094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameCount)->
613094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
614094332d3Sopenharmony_ci
615094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, CheckSceneCapability)(benchmark::State &state)
616094332d3Sopenharmony_ci{
617094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
618094332d3Sopenharmony_ci    int32_t ret;
619094332d3Sopenharmony_ci    struct AudioSceneDescriptor sceneDesc = {};
620094332d3Sopenharmony_ci    sceneDesc.desc.pins = PIN_IN_MIC;
621094332d3Sopenharmony_ci    sceneDesc.desc.desc = strdup("mic");
622094332d3Sopenharmony_ci    sceneDesc.scene.id = AUDIO_IN_COMMUNICATION;
623094332d3Sopenharmony_ci    bool isSupport = false;
624094332d3Sopenharmony_ci
625094332d3Sopenharmony_ci    for (auto _ : state) {
626094332d3Sopenharmony_ci        ret = capture_->CheckSceneCapability(capture_, &sceneDesc, &isSupport);
627094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
628094332d3Sopenharmony_ci    }
629094332d3Sopenharmony_ci    free(sceneDesc.desc.desc);
630094332d3Sopenharmony_ci    sceneDesc.desc.desc = nullptr;
631094332d3Sopenharmony_ci}
632094332d3Sopenharmony_ci
633094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CheckSceneCapability)->
634094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
635094332d3Sopenharmony_ci
636094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)(benchmark::State &state)
637094332d3Sopenharmony_ci{
638094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
639094332d3Sopenharmony_ci    int32_t ret;
640094332d3Sopenharmony_ci    uint64_t effectId = 0;
641094332d3Sopenharmony_ci
642094332d3Sopenharmony_ci    for (auto _ : state) {
643094332d3Sopenharmony_ci        ret = capture_->AddAudioEffect(capture_, effectId);
644094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
645094332d3Sopenharmony_ci
646094332d3Sopenharmony_ci        ret = capture_->RemoveAudioEffect(capture_, effectId);
647094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
648094332d3Sopenharmony_ci    }
649094332d3Sopenharmony_ci}
650094332d3Sopenharmony_ci
651094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)->
652094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
653094332d3Sopenharmony_ci
654094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)(benchmark::State &state)
655094332d3Sopenharmony_ci{
656094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
657094332d3Sopenharmony_ci    int32_t ret;
658094332d3Sopenharmony_ci    uint64_t bufferSize = 0;
659094332d3Sopenharmony_ci
660094332d3Sopenharmony_ci    for (auto _ : state) {
661094332d3Sopenharmony_ci        ret = capture_->GetFrameBufferSize(capture_, &bufferSize);
662094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
663094332d3Sopenharmony_ci    }
664094332d3Sopenharmony_ci}
665094332d3Sopenharmony_ci
666094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)->
667094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
668094332d3Sopenharmony_ci
669094332d3Sopenharmony_ciBENCHMARK_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)(benchmark::State &state)
670094332d3Sopenharmony_ci{
671094332d3Sopenharmony_ci    ASSERT_NE(capture_, nullptr);
672094332d3Sopenharmony_ci    int32_t ret;
673094332d3Sopenharmony_ci    bool supportPause = false;
674094332d3Sopenharmony_ci    bool supportResume = false;
675094332d3Sopenharmony_ci
676094332d3Sopenharmony_ci    for (auto _ : state) {
677094332d3Sopenharmony_ci        ret = capture_->IsSupportsPauseAndResume(capture_, &supportPause, &supportResume);
678094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
679094332d3Sopenharmony_ci    }
680094332d3Sopenharmony_ci}
681094332d3Sopenharmony_ci
682094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)->
683094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
684094332d3Sopenharmony_ci}
685