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/audio_types.h"
22094332d3Sopenharmony_ci#include "v4_0/iaudio_manager.h"
23094332d3Sopenharmony_ci#include "v4_0/iaudio_render.h"
24094332d3Sopenharmony_ci
25094332d3Sopenharmony_ciusing namespace std;
26094332d3Sopenharmony_ciusing namespace testing::ext;
27094332d3Sopenharmony_ci
28094332d3Sopenharmony_cinamespace {
29094332d3Sopenharmony_ciconst float MAX_GAINTHRESHOLD = 15.0;
30094332d3Sopenharmony_ciconst float MIN_GAINTHRESHOLD = 0.0;
31094332d3Sopenharmony_ciconst int BUFFER_LENTH = 1024 * 16;
32094332d3Sopenharmony_ciconst int DEEP_BUFFER_RENDER_PERIOD_SIZE = 4 * 1024;
33094332d3Sopenharmony_ciconst int MOVE_LEFT_NUM = 8;
34094332d3Sopenharmony_ciconst int32_t AUDIO_RENDER_BUF_TEST = 1024;
35094332d3Sopenharmony_ciconst int32_t AUDIO_RENDER_CHANNELCOUNT = 2;
36094332d3Sopenharmony_ciconst int32_t AUDIO_SAMPLE_RATE_48K = 48000;
37094332d3Sopenharmony_ciconst int32_t MAX_AUDIO_ADAPTER_DESC = 5;
38094332d3Sopenharmony_ciconst uint64_t DEFAULT_BUFFER_SIZE = 16384;
39094332d3Sopenharmony_ciconst int32_t ITERATION_FREQUENCY = 100;
40094332d3Sopenharmony_ciconst int32_t REPETITION_FREQUENCY = 3;
41094332d3Sopenharmony_ciconst int32_t RANGE_VALUE = 4;
42094332d3Sopenharmony_ciconst float GAIN_VALUE = 1.0;
43094332d3Sopenharmony_ciconst float SPEED_VALUE = 2.0;
44094332d3Sopenharmony_ciconst float VOLUNE_VALUE = 0.2;
45094332d3Sopenharmony_ci
46094332d3Sopenharmony_ciclass AudioRenderBenchmarkTest : public benchmark::Fixture {
47094332d3Sopenharmony_cipublic:
48094332d3Sopenharmony_ci    struct IAudioManager *manager_ = nullptr;
49094332d3Sopenharmony_ci    struct AudioAdapterDescriptor descs_[MAX_AUDIO_ADAPTER_DESC];
50094332d3Sopenharmony_ci    struct AudioAdapterDescriptor *desc_;
51094332d3Sopenharmony_ci    struct IAudioAdapter *adapter_ = nullptr;
52094332d3Sopenharmony_ci    struct IAudioRender *render_ = nullptr;
53094332d3Sopenharmony_ci    struct AudioDeviceDescriptor devDescRender_ = {};
54094332d3Sopenharmony_ci    struct AudioSampleAttributes attrsRender_ = {};
55094332d3Sopenharmony_ci    uint32_t renderId_ = 0;
56094332d3Sopenharmony_ci    char *devDescriptorName_ = nullptr;
57094332d3Sopenharmony_ci    uint32_t size_ = MAX_AUDIO_ADAPTER_DESC;
58094332d3Sopenharmony_ci    virtual void SetUp(const ::benchmark::State &state);
59094332d3Sopenharmony_ci    virtual void TearDown(const ::benchmark::State &state);
60094332d3Sopenharmony_ci    uint64_t GetRenderBufferSize();
61094332d3Sopenharmony_ci    void InitRenderAttrs(struct AudioSampleAttributes &attrs);
62094332d3Sopenharmony_ci    void InitRenderDevDesc(struct AudioDeviceDescriptor &devDesc);
63094332d3Sopenharmony_ci    void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
64094332d3Sopenharmony_ci    void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
65094332d3Sopenharmony_ci};
66094332d3Sopenharmony_ci
67094332d3Sopenharmony_ciuint64_t AudioRenderBenchmarkTest::GetRenderBufferSize()
68094332d3Sopenharmony_ci{
69094332d3Sopenharmony_ci    int32_t ret = HDF_SUCCESS;
70094332d3Sopenharmony_ci    uint64_t frameSize = 0;
71094332d3Sopenharmony_ci    uint64_t frameCount = 0;
72094332d3Sopenharmony_ci    uint64_t bufferSize = 0;
73094332d3Sopenharmony_ci
74094332d3Sopenharmony_ci    if (render_ == nullptr) {
75094332d3Sopenharmony_ci        return DEFAULT_BUFFER_SIZE;
76094332d3Sopenharmony_ci    }
77094332d3Sopenharmony_ci
78094332d3Sopenharmony_ci    ret = render_->GetFrameSize(render_, &frameSize);
79094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
80094332d3Sopenharmony_ci        return DEFAULT_BUFFER_SIZE;
81094332d3Sopenharmony_ci    }
82094332d3Sopenharmony_ci
83094332d3Sopenharmony_ci    ret = render_->GetFrameCount(render_, &frameCount);
84094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
85094332d3Sopenharmony_ci        return DEFAULT_BUFFER_SIZE;
86094332d3Sopenharmony_ci    }
87094332d3Sopenharmony_ci
88094332d3Sopenharmony_ci    bufferSize = frameCount * frameSize;
89094332d3Sopenharmony_ci    if (bufferSize == 0) {
90094332d3Sopenharmony_ci        bufferSize = DEFAULT_BUFFER_SIZE;
91094332d3Sopenharmony_ci    }
92094332d3Sopenharmony_ci
93094332d3Sopenharmony_ci    return bufferSize;
94094332d3Sopenharmony_ci}
95094332d3Sopenharmony_ci
96094332d3Sopenharmony_civoid AudioRenderBenchmarkTest::InitRenderAttrs(struct AudioSampleAttributes &attrs)
97094332d3Sopenharmony_ci{
98094332d3Sopenharmony_ci    attrs.channelCount = AUDIO_RENDER_CHANNELCOUNT;
99094332d3Sopenharmony_ci    attrs.sampleRate = AUDIO_SAMPLE_RATE_48K;
100094332d3Sopenharmony_ci    attrs.interleaved = 0;
101094332d3Sopenharmony_ci    attrs.type = AUDIO_IN_MEDIA;
102094332d3Sopenharmony_ci    attrs.period = DEEP_BUFFER_RENDER_PERIOD_SIZE;
103094332d3Sopenharmony_ci    attrs.frameSize = AUDIO_FORMAT_TYPE_PCM_16_BIT * AUDIO_RENDER_CHANNELCOUNT / MOVE_LEFT_NUM;
104094332d3Sopenharmony_ci    attrs.isBigEndian = false;
105094332d3Sopenharmony_ci    attrs.isSignedData = true;
106094332d3Sopenharmony_ci    attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (attrs.format * attrs.channelCount / MOVE_LEFT_NUM);
107094332d3Sopenharmony_ci    attrs.stopThreshold = INT_MAX;
108094332d3Sopenharmony_ci    attrs.silenceThreshold = BUFFER_LENTH;
109094332d3Sopenharmony_ci}
110094332d3Sopenharmony_ci
111094332d3Sopenharmony_civoid AudioRenderBenchmarkTest::InitRenderDevDesc(struct AudioDeviceDescriptor &devDesc)
112094332d3Sopenharmony_ci{
113094332d3Sopenharmony_ci    devDesc.pins = PIN_OUT_SPEAKER;
114094332d3Sopenharmony_ci    devDescriptorName_ = strdup("cardname");
115094332d3Sopenharmony_ci    devDesc.desc = devDescriptorName_;
116094332d3Sopenharmony_ci
117094332d3Sopenharmony_ci    ASSERT_NE(desc_, nullptr);
118094332d3Sopenharmony_ci    ASSERT_NE(desc_->ports, nullptr);
119094332d3Sopenharmony_ci    for (uint32_t index = 0; index < desc_->portsLen; index++) {
120094332d3Sopenharmony_ci        if (desc_->ports[index].dir == PORT_OUT) {
121094332d3Sopenharmony_ci            devDesc.portId = desc_->ports[index].portId;
122094332d3Sopenharmony_ci            return;
123094332d3Sopenharmony_ci        }
124094332d3Sopenharmony_ci    }
125094332d3Sopenharmony_ci}
126094332d3Sopenharmony_ci
127094332d3Sopenharmony_civoid AudioRenderBenchmarkTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
128094332d3Sopenharmony_ci{
129094332d3Sopenharmony_ci    if (dataBlock == nullptr) {
130094332d3Sopenharmony_ci        return;
131094332d3Sopenharmony_ci    }
132094332d3Sopenharmony_ci
133094332d3Sopenharmony_ci    OsalMemFree(dataBlock->adapterName);
134094332d3Sopenharmony_ci
135094332d3Sopenharmony_ci    OsalMemFree(dataBlock->ports);
136094332d3Sopenharmony_ci
137094332d3Sopenharmony_ci    if (freeSelf) {
138094332d3Sopenharmony_ci        OsalMemFree(dataBlock);
139094332d3Sopenharmony_ci    }
140094332d3Sopenharmony_ci}
141094332d3Sopenharmony_ci
142094332d3Sopenharmony_civoid AudioRenderBenchmarkTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
143094332d3Sopenharmony_ci{
144094332d3Sopenharmony_ci    if (descs == nullptr || descsLen == 0) {
145094332d3Sopenharmony_ci        return;
146094332d3Sopenharmony_ci    }
147094332d3Sopenharmony_ci
148094332d3Sopenharmony_ci    for (uint32_t i = 0; i < descsLen; i++) {
149094332d3Sopenharmony_ci        FreeAdapterElements(&descs[i], false);
150094332d3Sopenharmony_ci    }
151094332d3Sopenharmony_ci}
152094332d3Sopenharmony_ci
153094332d3Sopenharmony_civoid AudioRenderBenchmarkTest::SetUp(const ::benchmark::State &state)
154094332d3Sopenharmony_ci{
155094332d3Sopenharmony_ci    manager_ = IAudioManagerGet(false);
156094332d3Sopenharmony_ci    ASSERT_NE(manager_, nullptr);
157094332d3Sopenharmony_ci
158094332d3Sopenharmony_ci    ASSERT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, descs_, &size_));
159094332d3Sopenharmony_ci    ASSERT_NE(descs_, nullptr);
160094332d3Sopenharmony_ci    EXPECT_GE(MAX_AUDIO_ADAPTER_DESC, size_);
161094332d3Sopenharmony_ci    desc_ = &descs_[0];
162094332d3Sopenharmony_ci    ASSERT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, desc_, &adapter_));
163094332d3Sopenharmony_ci    ASSERT_NE(adapter_, nullptr);
164094332d3Sopenharmony_ci    InitRenderDevDesc(devDescRender_);
165094332d3Sopenharmony_ci    InitRenderAttrs(attrsRender_);
166094332d3Sopenharmony_ci
167094332d3Sopenharmony_ci    attrsRender_.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
168094332d3Sopenharmony_ci    int32_t ret = adapter_->CreateRender(adapter_, &devDescRender_, &attrsRender_, &render_, &renderId_);
169094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
170094332d3Sopenharmony_ci        attrsRender_.format = AUDIO_FORMAT_TYPE_PCM_32_BIT;
171094332d3Sopenharmony_ci        ASSERT_EQ(HDF_SUCCESS, adapter_->CreateRender(adapter_, &devDescRender_, &attrsRender_, &render_, &renderId_));
172094332d3Sopenharmony_ci    }
173094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
174094332d3Sopenharmony_ci}
175094332d3Sopenharmony_ci
176094332d3Sopenharmony_civoid AudioRenderBenchmarkTest::TearDown(const ::benchmark::State &state)
177094332d3Sopenharmony_ci{
178094332d3Sopenharmony_ci    ASSERT_NE(devDescriptorName_, nullptr);
179094332d3Sopenharmony_ci    free(devDescriptorName_);
180094332d3Sopenharmony_ci
181094332d3Sopenharmony_ci    if (adapter_ != nullptr) {
182094332d3Sopenharmony_ci        adapter_->DestroyRender(adapter_, renderId_);
183094332d3Sopenharmony_ci        render_ = nullptr;
184094332d3Sopenharmony_ci    }
185094332d3Sopenharmony_ci    if (manager_ != nullptr) {
186094332d3Sopenharmony_ci        manager_->UnloadAdapter(manager_, desc_->adapterName);
187094332d3Sopenharmony_ci        adapter_ = nullptr;
188094332d3Sopenharmony_ci        ReleaseAllAdapterDescs(descs_, size_);
189094332d3Sopenharmony_ci
190094332d3Sopenharmony_ci        IAudioManagerRelease(manager_, false);
191094332d3Sopenharmony_ci    }
192094332d3Sopenharmony_ci}
193094332d3Sopenharmony_ci
194094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, StartAndStop)(benchmark::State &state)
195094332d3Sopenharmony_ci{
196094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
197094332d3Sopenharmony_ci    int32_t ret;
198094332d3Sopenharmony_ci    for (auto _ : state) {
199094332d3Sopenharmony_ci        ret = render_->Start(render_);
200094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
201094332d3Sopenharmony_ci        ret = render_->Stop(render_);
202094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
203094332d3Sopenharmony_ci    }
204094332d3Sopenharmony_ci}
205094332d3Sopenharmony_ci
206094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, StartAndStop)->
207094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
208094332d3Sopenharmony_ci
209094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, Pause)(benchmark::State &state)
210094332d3Sopenharmony_ci{
211094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
212094332d3Sopenharmony_ci    int32_t ret = render_->Start(render_);
213094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
214094332d3Sopenharmony_ci
215094332d3Sopenharmony_ci    for (auto _ : state) {
216094332d3Sopenharmony_ci        ret = render_->Pause(render_);
217094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
218094332d3Sopenharmony_ci    }
219094332d3Sopenharmony_ci
220094332d3Sopenharmony_ci    ret = render_->Stop(render_);
221094332d3Sopenharmony_ci    ASSERT_EQ(ret, HDF_SUCCESS);
222094332d3Sopenharmony_ci}
223094332d3Sopenharmony_ci
224094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Pause)->
225094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
226094332d3Sopenharmony_ci
227094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, Resume)(benchmark::State &state)
228094332d3Sopenharmony_ci{
229094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
230094332d3Sopenharmony_ci    int32_t ret = render_->Start(render_);
231094332d3Sopenharmony_ci    EXPECT_EQ(ret, HDF_SUCCESS);
232094332d3Sopenharmony_ci
233094332d3Sopenharmony_ci    ret = render_->Pause(render_);
234094332d3Sopenharmony_ci    ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
235094332d3Sopenharmony_ci
236094332d3Sopenharmony_ci    for (auto _ : state) {
237094332d3Sopenharmony_ci        ret = render_->Resume(render_);
238094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
239094332d3Sopenharmony_ci    }
240094332d3Sopenharmony_ci
241094332d3Sopenharmony_ci    ret = render_->Stop(render_);
242094332d3Sopenharmony_ci    ASSERT_EQ(ret, HDF_SUCCESS);
243094332d3Sopenharmony_ci}
244094332d3Sopenharmony_ci
245094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Resume)->
246094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
247094332d3Sopenharmony_ci
248094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, Flush)(benchmark::State &state)
249094332d3Sopenharmony_ci{
250094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
251094332d3Sopenharmony_ci    int32_t ret;
252094332d3Sopenharmony_ci    for (auto _ : state) {
253094332d3Sopenharmony_ci        ret = render_->Flush(render_);
254094332d3Sopenharmony_ci        EXPECT_NE(ret, HDF_SUCCESS);
255094332d3Sopenharmony_ci    }
256094332d3Sopenharmony_ci}
257094332d3Sopenharmony_ci
258094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Flush)->
259094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
260094332d3Sopenharmony_ci
261094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, TurnStandbyMode)(benchmark::State &state)
262094332d3Sopenharmony_ci{
263094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
264094332d3Sopenharmony_ci    int32_t ret;
265094332d3Sopenharmony_ci    for (auto _ : state) {
266094332d3Sopenharmony_ci        ret = render_->Start(render_);
267094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
268094332d3Sopenharmony_ci        ret = render_->TurnStandbyMode(render_);
269094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
270094332d3Sopenharmony_ci        render_->Stop(render_);
271094332d3Sopenharmony_ci    }
272094332d3Sopenharmony_ci}
273094332d3Sopenharmony_ci
274094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, TurnStandbyMode)->
275094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
276094332d3Sopenharmony_ci
277094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, AudioDevDump)(benchmark::State &state)
278094332d3Sopenharmony_ci{
279094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
280094332d3Sopenharmony_ci    int32_t ret;
281094332d3Sopenharmony_ci    int32_t range = RANGE_VALUE;
282094332d3Sopenharmony_ci    char pathBuf[] = "/data/RenderDump.log";
283094332d3Sopenharmony_ci
284094332d3Sopenharmony_ci    FILE *file = fopen(pathBuf, "wb+");
285094332d3Sopenharmony_ci    ASSERT_NE(nullptr, file);
286094332d3Sopenharmony_ci    int fd = fileno(file);
287094332d3Sopenharmony_ci    if (fd == -1) {
288094332d3Sopenharmony_ci        fclose(file);
289094332d3Sopenharmony_ci        ASSERT_NE(fd, -1);
290094332d3Sopenharmony_ci    }
291094332d3Sopenharmony_ci
292094332d3Sopenharmony_ci    for (auto _ : state) {
293094332d3Sopenharmony_ci        ret = render_->AudioDevDump(render_, range, fd);
294094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
295094332d3Sopenharmony_ci    }
296094332d3Sopenharmony_ci    fclose(file);
297094332d3Sopenharmony_ci}
298094332d3Sopenharmony_ci
299094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, AudioDevDump)->
300094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
301094332d3Sopenharmony_ci
302094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetFrameSize)(benchmark::State &state)
303094332d3Sopenharmony_ci{
304094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
305094332d3Sopenharmony_ci    int32_t ret;
306094332d3Sopenharmony_ci    uint64_t frameSize = 0;
307094332d3Sopenharmony_ci
308094332d3Sopenharmony_ci    for (auto _ : state) {
309094332d3Sopenharmony_ci        ret = render_->GetFrameSize(render_, &frameSize);
310094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
311094332d3Sopenharmony_ci    }
312094332d3Sopenharmony_ci}
313094332d3Sopenharmony_ci
314094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameSize)->
315094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
316094332d3Sopenharmony_ci
317094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetFrameCount)(benchmark::State &state)
318094332d3Sopenharmony_ci{
319094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
320094332d3Sopenharmony_ci    int32_t ret;
321094332d3Sopenharmony_ci    uint64_t frameCount = 0;
322094332d3Sopenharmony_ci
323094332d3Sopenharmony_ci    for (auto _ : state) {
324094332d3Sopenharmony_ci        ret = render_->GetFrameCount(render_, &frameCount);
325094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
326094332d3Sopenharmony_ci    }
327094332d3Sopenharmony_ci}
328094332d3Sopenharmony_ci
329094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameCount)->
330094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
331094332d3Sopenharmony_ci
332094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetSampleAttributes)(benchmark::State &state)
333094332d3Sopenharmony_ci{
334094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
335094332d3Sopenharmony_ci    int32_t ret;
336094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs = attrsRender_;
337094332d3Sopenharmony_ci    for (auto _ : state) {
338094332d3Sopenharmony_ci        ret = render_->SetSampleAttributes(render_, &attrs);
339094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
340094332d3Sopenharmony_ci    }
341094332d3Sopenharmony_ci}
342094332d3Sopenharmony_ci
343094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetSampleAttributes)->
344094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
345094332d3Sopenharmony_ci
346094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetSampleAttributes)(benchmark::State &state)
347094332d3Sopenharmony_ci{
348094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
349094332d3Sopenharmony_ci    int32_t ret;
350094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs = {};
351094332d3Sopenharmony_ci
352094332d3Sopenharmony_ci    for (auto _ : state) {
353094332d3Sopenharmony_ci        ret = render_->GetSampleAttributes(render_, &attrs);
354094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
355094332d3Sopenharmony_ci    }
356094332d3Sopenharmony_ci}
357094332d3Sopenharmony_ci
358094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetSampleAttributes)->
359094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
360094332d3Sopenharmony_ci
361094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetCurrentChannelId)(benchmark::State &state)
362094332d3Sopenharmony_ci{
363094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
364094332d3Sopenharmony_ci    int32_t ret;
365094332d3Sopenharmony_ci    uint32_t channelId = 0;
366094332d3Sopenharmony_ci
367094332d3Sopenharmony_ci    for (auto _ : state) {
368094332d3Sopenharmony_ci        ret = render_->GetCurrentChannelId(render_, &channelId);
369094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
370094332d3Sopenharmony_ci    }
371094332d3Sopenharmony_ci}
372094332d3Sopenharmony_ci
373094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetCurrentChannelId)->
374094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
375094332d3Sopenharmony_ci
376094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SelectScene)(benchmark::State &state)
377094332d3Sopenharmony_ci{
378094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
379094332d3Sopenharmony_ci    int32_t ret;
380094332d3Sopenharmony_ci    struct AudioSceneDescriptor scene;
381094332d3Sopenharmony_ci    scene.scene.id = AUDIO_IN_MEDIA;
382094332d3Sopenharmony_ci    scene.desc.pins = PIN_OUT_SPEAKER;
383094332d3Sopenharmony_ci    scene.desc.desc = const_cast<char*>("primary");
384094332d3Sopenharmony_ci
385094332d3Sopenharmony_ci    for (auto _ : state) {
386094332d3Sopenharmony_ci        ret = render_->SelectScene(render_, &scene);
387094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
388094332d3Sopenharmony_ci    }
389094332d3Sopenharmony_ci}
390094332d3Sopenharmony_ci
391094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SelectScene)->
392094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
393094332d3Sopenharmony_ci
394094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetLatency)(benchmark::State &state)
395094332d3Sopenharmony_ci{
396094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
397094332d3Sopenharmony_ci    int32_t ret;
398094332d3Sopenharmony_ci    uint32_t ms = 0;
399094332d3Sopenharmony_ci
400094332d3Sopenharmony_ci    for (auto _ : state) {
401094332d3Sopenharmony_ci        ret = render_->GetLatency(render_, &ms);
402094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
403094332d3Sopenharmony_ci    }
404094332d3Sopenharmony_ci}
405094332d3Sopenharmony_ci
406094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetLatency)->
407094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
408094332d3Sopenharmony_ci
409094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetRenderPosition)(benchmark::State &state)
410094332d3Sopenharmony_ci{
411094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
412094332d3Sopenharmony_ci    int32_t ret;
413094332d3Sopenharmony_ci    uint64_t frames = 0;
414094332d3Sopenharmony_ci    struct AudioTimeStamp time;
415094332d3Sopenharmony_ci
416094332d3Sopenharmony_ci    for (auto _ : state) {
417094332d3Sopenharmony_ci        ret = render_->GetRenderPosition(render_, &frames, &time);
418094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
419094332d3Sopenharmony_ci    }
420094332d3Sopenharmony_ci}
421094332d3Sopenharmony_ci
422094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetRenderPosition)->
423094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
424094332d3Sopenharmony_ci
425094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetExtraParams)(benchmark::State &state)
426094332d3Sopenharmony_ci{
427094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
428094332d3Sopenharmony_ci    int32_t ret;
429094332d3Sopenharmony_ci    char keyValueList[AUDIO_RENDER_BUF_TEST] =
430094332d3Sopenharmony_ci        "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
431094332d3Sopenharmony_ci
432094332d3Sopenharmony_ci    for (auto _ : state) {
433094332d3Sopenharmony_ci        ret = render_->SetExtraParams(render_, keyValueList);
434094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
435094332d3Sopenharmony_ci    }
436094332d3Sopenharmony_ci}
437094332d3Sopenharmony_ci
438094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetExtraParams)->
439094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
440094332d3Sopenharmony_ci
441094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetExtraParams)(benchmark::State &state)
442094332d3Sopenharmony_ci{
443094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
444094332d3Sopenharmony_ci    int32_t ret;
445094332d3Sopenharmony_ci    char keyValueList[AUDIO_RENDER_BUF_TEST] = {};
446094332d3Sopenharmony_ci    uint32_t keyValueListLen = 0;
447094332d3Sopenharmony_ci
448094332d3Sopenharmony_ci    for (auto _ : state) {
449094332d3Sopenharmony_ci        ret = render_->GetExtraParams(render_, keyValueList, keyValueListLen);
450094332d3Sopenharmony_ci        EXPECT_NE(ret, HDF_SUCCESS);
451094332d3Sopenharmony_ci    }
452094332d3Sopenharmony_ci}
453094332d3Sopenharmony_ci
454094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetExtraParams)->
455094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
456094332d3Sopenharmony_ci
457094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetGain)(benchmark::State &state)
458094332d3Sopenharmony_ci{
459094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
460094332d3Sopenharmony_ci    int32_t ret;
461094332d3Sopenharmony_ci    float gain = GAIN_VALUE;
462094332d3Sopenharmony_ci
463094332d3Sopenharmony_ci    for (auto _ : state) {
464094332d3Sopenharmony_ci        ret = render_->SetGain(render_, gain);
465094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
466094332d3Sopenharmony_ci    }
467094332d3Sopenharmony_ci}
468094332d3Sopenharmony_ci
469094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetGain)->
470094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
471094332d3Sopenharmony_ci
472094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetGain)(benchmark::State &state)
473094332d3Sopenharmony_ci{
474094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
475094332d3Sopenharmony_ci    int32_t ret;
476094332d3Sopenharmony_ci    float gain;
477094332d3Sopenharmony_ci
478094332d3Sopenharmony_ci    for (auto _ : state) {
479094332d3Sopenharmony_ci        ret = render_->GetGain(render_, &gain);
480094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
481094332d3Sopenharmony_ci    }
482094332d3Sopenharmony_ci}
483094332d3Sopenharmony_ci
484094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetGain)->
485094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
486094332d3Sopenharmony_ci
487094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetGainThreshold)(benchmark::State &state)
488094332d3Sopenharmony_ci{
489094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
490094332d3Sopenharmony_ci    int32_t ret;
491094332d3Sopenharmony_ci    float min = 0.0;
492094332d3Sopenharmony_ci    float max = GAIN_VALUE;
493094332d3Sopenharmony_ci
494094332d3Sopenharmony_ci    for (auto _ : state) {
495094332d3Sopenharmony_ci        ret = render_->GetGainThreshold(render_, &min, &max);
496094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
497094332d3Sopenharmony_ci    }
498094332d3Sopenharmony_ci    EXPECT_GE(min, MIN_GAINTHRESHOLD);
499094332d3Sopenharmony_ci    EXPECT_LE(max, MAX_GAINTHRESHOLD);
500094332d3Sopenharmony_ci}
501094332d3Sopenharmony_ci
502094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetGainThreshold)->
503094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
504094332d3Sopenharmony_ci
505094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetMmapPosition)(benchmark::State &state)
506094332d3Sopenharmony_ci{
507094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
508094332d3Sopenharmony_ci    int32_t ret;
509094332d3Sopenharmony_ci    uint64_t frames = 0;
510094332d3Sopenharmony_ci    struct AudioTimeStamp time;
511094332d3Sopenharmony_ci    time.tvNSec = 0;
512094332d3Sopenharmony_ci    time.tvSec = 0;
513094332d3Sopenharmony_ci
514094332d3Sopenharmony_ci    for (auto _ : state) {
515094332d3Sopenharmony_ci        ret = render_->GetMmapPosition(render_, &frames, &time);
516094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
517094332d3Sopenharmony_ci    }
518094332d3Sopenharmony_ci}
519094332d3Sopenharmony_ci
520094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetMmapPosition)->
521094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
522094332d3Sopenharmony_ci
523094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetMute)(benchmark::State &state)
524094332d3Sopenharmony_ci{
525094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
526094332d3Sopenharmony_ci    int32_t ret;
527094332d3Sopenharmony_ci    bool mute = false;
528094332d3Sopenharmony_ci
529094332d3Sopenharmony_ci    for (auto _ : state) {
530094332d3Sopenharmony_ci        ret = render_->SetMute(render_, mute);
531094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
532094332d3Sopenharmony_ci    }
533094332d3Sopenharmony_ci}
534094332d3Sopenharmony_ci
535094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetMute)->
536094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
537094332d3Sopenharmony_ci
538094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetMute)(benchmark::State &state)
539094332d3Sopenharmony_ci{
540094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
541094332d3Sopenharmony_ci    int32_t ret;
542094332d3Sopenharmony_ci    bool isMute = false;
543094332d3Sopenharmony_ci
544094332d3Sopenharmony_ci    for (auto _ : state) {
545094332d3Sopenharmony_ci        ret = render_->GetMute(render_, &isMute);
546094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
547094332d3Sopenharmony_ci    }
548094332d3Sopenharmony_ci}
549094332d3Sopenharmony_ci
550094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetMute)->
551094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
552094332d3Sopenharmony_ci
553094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetVolume)(benchmark::State &state)
554094332d3Sopenharmony_ci{
555094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
556094332d3Sopenharmony_ci    int32_t ret;
557094332d3Sopenharmony_ci    float volume = VOLUNE_VALUE;
558094332d3Sopenharmony_ci
559094332d3Sopenharmony_ci    for (auto _ : state) {
560094332d3Sopenharmony_ci        ret = render_->SetVolume(render_, volume);
561094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
562094332d3Sopenharmony_ci    }
563094332d3Sopenharmony_ci}
564094332d3Sopenharmony_ci
565094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetVolume)->
566094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
567094332d3Sopenharmony_ci
568094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetVolume)(benchmark::State &state)
569094332d3Sopenharmony_ci{
570094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
571094332d3Sopenharmony_ci    int32_t ret;
572094332d3Sopenharmony_ci    float val = 0.0;
573094332d3Sopenharmony_ci
574094332d3Sopenharmony_ci    for (auto _ : state) {
575094332d3Sopenharmony_ci        ret = render_->GetVolume(render_, &val);
576094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
577094332d3Sopenharmony_ci    }
578094332d3Sopenharmony_ci}
579094332d3Sopenharmony_ci
580094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetVolume)->
581094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
582094332d3Sopenharmony_ci
583094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, RenderFrame)(benchmark::State &state)
584094332d3Sopenharmony_ci{
585094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
586094332d3Sopenharmony_ci    int32_t ret;
587094332d3Sopenharmony_ci    uint32_t frameLen = (uint64_t)GetRenderBufferSize();
588094332d3Sopenharmony_ci    uint64_t requestBytes = frameLen;
589094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, render_->Start(render_));
590094332d3Sopenharmony_ci
591094332d3Sopenharmony_ci    int8_t *frame = (int8_t *)calloc(1, frameLen);
592094332d3Sopenharmony_ci    ASSERT_NE(nullptr, frame);
593094332d3Sopenharmony_ci
594094332d3Sopenharmony_ci    for (auto _ : state) {
595094332d3Sopenharmony_ci        ret = render_->RenderFrame(render_, frame, frameLen, &requestBytes);
596094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
597094332d3Sopenharmony_ci    }
598094332d3Sopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, render_->Stop(render_));
599094332d3Sopenharmony_ci
600094332d3Sopenharmony_ci    if (frame != nullptr) {
601094332d3Sopenharmony_ci        free(frame);
602094332d3Sopenharmony_ci        frame = nullptr;
603094332d3Sopenharmony_ci    }
604094332d3Sopenharmony_ci}
605094332d3Sopenharmony_ci
606094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, RenderFrame)->
607094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
608094332d3Sopenharmony_ci
609094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetChannelMode)(benchmark::State &state)
610094332d3Sopenharmony_ci{
611094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
612094332d3Sopenharmony_ci    int32_t ret;
613094332d3Sopenharmony_ci    AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
614094332d3Sopenharmony_ci
615094332d3Sopenharmony_ci    for (auto _ : state) {
616094332d3Sopenharmony_ci        ret = render_->SetChannelMode(render_, mode);
617094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
618094332d3Sopenharmony_ci    }
619094332d3Sopenharmony_ci}
620094332d3Sopenharmony_ci
621094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetChannelMode)->
622094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
623094332d3Sopenharmony_ci
624094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, SetRenderSpeed)(benchmark::State &state)
625094332d3Sopenharmony_ci{
626094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
627094332d3Sopenharmony_ci    int32_t ret;
628094332d3Sopenharmony_ci    float speed = SPEED_VALUE;
629094332d3Sopenharmony_ci
630094332d3Sopenharmony_ci    for (auto _ : state) {
631094332d3Sopenharmony_ci        ret = render_->SetRenderSpeed(render_, speed);
632094332d3Sopenharmony_ci        EXPECT_NE(ret, HDF_SUCCESS);
633094332d3Sopenharmony_ci    }
634094332d3Sopenharmony_ci}
635094332d3Sopenharmony_ci
636094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetRenderSpeed)->
637094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
638094332d3Sopenharmony_ci
639094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetRenderSpeed)(benchmark::State &state)
640094332d3Sopenharmony_ci{
641094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
642094332d3Sopenharmony_ci    int32_t ret;
643094332d3Sopenharmony_ci    float speed = 0.0;
644094332d3Sopenharmony_ci
645094332d3Sopenharmony_ci    ASSERT_EQ(HDF_SUCCESS, render_->Start(render_));
646094332d3Sopenharmony_ci    for (auto _ : state) {
647094332d3Sopenharmony_ci        ret = render_->GetRenderSpeed(render_, &speed);
648094332d3Sopenharmony_ci        EXPECT_NE(ret, HDF_SUCCESS);
649094332d3Sopenharmony_ci    }
650094332d3Sopenharmony_ci    ASSERT_EQ(HDF_SUCCESS, render_->Stop(render_));
651094332d3Sopenharmony_ci}
652094332d3Sopenharmony_ci
653094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetRenderSpeed)->
654094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
655094332d3Sopenharmony_ci
656094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetChannelMode)(benchmark::State &state)
657094332d3Sopenharmony_ci{
658094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
659094332d3Sopenharmony_ci    int32_t ret;
660094332d3Sopenharmony_ci    enum AudioChannelMode channelMode = AUDIO_CHANNEL_NORMAL;
661094332d3Sopenharmony_ci
662094332d3Sopenharmony_ci    for (auto _ : state) {
663094332d3Sopenharmony_ci        ret = render_->GetChannelMode(render_, &channelMode);
664094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
665094332d3Sopenharmony_ci    }
666094332d3Sopenharmony_ci}
667094332d3Sopenharmony_ci
668094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetChannelMode)->
669094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
670094332d3Sopenharmony_ci
671094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, RegCallback)(benchmark::State &state)
672094332d3Sopenharmony_ci{
673094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
674094332d3Sopenharmony_ci    int32_t ret;
675094332d3Sopenharmony_ci    int8_t cookie = 0;
676094332d3Sopenharmony_ci    struct IAudioCallback *audioCallback = nullptr;
677094332d3Sopenharmony_ci
678094332d3Sopenharmony_ci    for (auto _ : state) {
679094332d3Sopenharmony_ci        ret = render_->RegCallback(render_, audioCallback, cookie);
680094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
681094332d3Sopenharmony_ci    }
682094332d3Sopenharmony_ci}
683094332d3Sopenharmony_ci
684094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, RegCallback)->
685094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
686094332d3Sopenharmony_ci
687094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, DrainBuffer)(benchmark::State &state)
688094332d3Sopenharmony_ci{
689094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
690094332d3Sopenharmony_ci    int32_t ret;
691094332d3Sopenharmony_ci    enum AudioDrainNotifyType type = AUDIO_DRAIN_NORMAL_MODE;
692094332d3Sopenharmony_ci
693094332d3Sopenharmony_ci    for (auto _ : state) {
694094332d3Sopenharmony_ci        ret = render_->DrainBuffer(render_, &type);
695094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_ERR_NOT_SUPPORT);
696094332d3Sopenharmony_ci    }
697094332d3Sopenharmony_ci}
698094332d3Sopenharmony_ci
699094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, DrainBuffer)->
700094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
701094332d3Sopenharmony_ci
702094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, IsSupportsDrain)(benchmark::State &state)
703094332d3Sopenharmony_ci{
704094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
705094332d3Sopenharmony_ci    int32_t ret;
706094332d3Sopenharmony_ci    bool support = false;
707094332d3Sopenharmony_ci
708094332d3Sopenharmony_ci    for (auto _ : state) {
709094332d3Sopenharmony_ci        ret = render_->IsSupportsDrain(render_, &support);
710094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
711094332d3Sopenharmony_ci    }
712094332d3Sopenharmony_ci}
713094332d3Sopenharmony_ci
714094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, IsSupportsDrain)->
715094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
716094332d3Sopenharmony_ci
717094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, CheckSceneCapability)(benchmark::State &state)
718094332d3Sopenharmony_ci{
719094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
720094332d3Sopenharmony_ci    int32_t ret;
721094332d3Sopenharmony_ci    struct AudioSceneDescriptor scene;
722094332d3Sopenharmony_ci    bool supported = false;
723094332d3Sopenharmony_ci    scene.scene.id = AUDIO_IN_MEDIA;
724094332d3Sopenharmony_ci    scene.desc = devDescRender_;
725094332d3Sopenharmony_ci
726094332d3Sopenharmony_ci    for (auto _ : state) {
727094332d3Sopenharmony_ci        ret = render_->CheckSceneCapability(render_, &scene, &supported);
728094332d3Sopenharmony_ci        EXPECT_EQ(ret, HDF_SUCCESS);
729094332d3Sopenharmony_ci    }
730094332d3Sopenharmony_ci}
731094332d3Sopenharmony_ci
732094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, CheckSceneCapability)->
733094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
734094332d3Sopenharmony_ci
735094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, AddAndRemoveAudioEffect)(benchmark::State &state)
736094332d3Sopenharmony_ci{
737094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
738094332d3Sopenharmony_ci    int32_t ret;
739094332d3Sopenharmony_ci    uint64_t effectId = 0;
740094332d3Sopenharmony_ci
741094332d3Sopenharmony_ci    for (auto _ : state) {
742094332d3Sopenharmony_ci        ret = render_->AddAudioEffect(render_, effectId);
743094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
744094332d3Sopenharmony_ci
745094332d3Sopenharmony_ci        ret = render_->RemoveAudioEffect(render_, effectId);
746094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
747094332d3Sopenharmony_ci    }
748094332d3Sopenharmony_ci}
749094332d3Sopenharmony_ci
750094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, AddAndRemoveAudioEffect)->
751094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
752094332d3Sopenharmony_ci
753094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, GetFrameBufferSize)(benchmark::State &state)
754094332d3Sopenharmony_ci{
755094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
756094332d3Sopenharmony_ci    int32_t ret;
757094332d3Sopenharmony_ci    uint64_t bufferSize = BUFFER_LENTH;
758094332d3Sopenharmony_ci
759094332d3Sopenharmony_ci    for (auto _ : state) {
760094332d3Sopenharmony_ci        ret = render_->GetFrameBufferSize(render_, &bufferSize);
761094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
762094332d3Sopenharmony_ci    }
763094332d3Sopenharmony_ci}
764094332d3Sopenharmony_ci
765094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameBufferSize)->
766094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
767094332d3Sopenharmony_ci
768094332d3Sopenharmony_ciBENCHMARK_F(AudioRenderBenchmarkTest, IsSupportsPauseAndResume)(benchmark::State &state)
769094332d3Sopenharmony_ci{
770094332d3Sopenharmony_ci    ASSERT_NE(render_, nullptr);
771094332d3Sopenharmony_ci    int32_t ret;
772094332d3Sopenharmony_ci    bool supportPause = false;
773094332d3Sopenharmony_ci    bool supportResume = false;
774094332d3Sopenharmony_ci
775094332d3Sopenharmony_ci    for (auto _ : state) {
776094332d3Sopenharmony_ci        ret = render_->IsSupportsPauseAndResume(render_, &supportPause, &supportResume);
777094332d3Sopenharmony_ci        ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
778094332d3Sopenharmony_ci    }
779094332d3Sopenharmony_ci}
780094332d3Sopenharmony_ci
781094332d3Sopenharmony_ciBENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, IsSupportsPauseAndResume)->
782094332d3Sopenharmony_ci    Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
783094332d3Sopenharmony_ci}
784