1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include "napi/native_api.h"
17f6603c60Sopenharmony_ci#include <condition_variable>
18f6603c60Sopenharmony_ci#include <js_native_api_types.h>
19f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcapability.h>
20f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcodec_audiodecoder.h>
21f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcodec_base.h>
22f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_averrors.h>
23f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avformat.h>
24f6603c60Sopenharmony_ci#include <pthread.h>
25f6603c60Sopenharmony_ci#include <queue>
26f6603c60Sopenharmony_ci#include <fstream>
27f6603c60Sopenharmony_ci#include <iostream>
28f6603c60Sopenharmony_ci
29f6603c60Sopenharmony_ci#define FAIL (-1)
30f6603c60Sopenharmony_ci#define SUCCESS 0
31f6603c60Sopenharmony_ci
32f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_SAMPLERATE = 44100;
33f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_BITRATE = 32000;
34f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_CHANNEL_COUNT = 2;
35f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_MAX_INPUT_SIZE = 1152;
36f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_AAC_TYPE = 1;
37f6603c60Sopenharmony_ciconstexpr uint8_t DEFAULT_VORBIS_TYPE = 10;
38f6603c60Sopenharmony_ciconstexpr uint8_t DEFAULT_VORBISTWO_TYPE = 20;
39f6603c60Sopenharmony_ciusing namespace std;
40f6603c60Sopenharmony_ci
41f6603c60Sopenharmony_cistatic napi_value TestInitPtr(napi_env env, OH_AVCodec *param)
42f6603c60Sopenharmony_ci{
43f6603c60Sopenharmony_ci    int backParam = FAIL;
44f6603c60Sopenharmony_ci    napi_value result = nullptr;
45f6603c60Sopenharmony_ci    OH_AVCodec *checkParam = param;
46f6603c60Sopenharmony_ci    if (checkParam != nullptr) {
47f6603c60Sopenharmony_ci        backParam = SUCCESS;
48f6603c60Sopenharmony_ci    }
49f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
50f6603c60Sopenharmony_ci    return result;
51f6603c60Sopenharmony_ci}
52f6603c60Sopenharmony_ci
53f6603c60Sopenharmony_cistatic napi_value TestInitAVErrCode(napi_env env, OH_AVErrCode param)
54f6603c60Sopenharmony_ci{
55f6603c60Sopenharmony_ci    int backParam = FAIL;
56f6603c60Sopenharmony_ci    napi_value result = nullptr;
57f6603c60Sopenharmony_ci    OH_AVErrCode checkParam = param;
58f6603c60Sopenharmony_ci    if (checkParam == AV_ERR_OK) {
59f6603c60Sopenharmony_ci        backParam = SUCCESS;
60f6603c60Sopenharmony_ci    }
61f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
62f6603c60Sopenharmony_ci    return result;
63f6603c60Sopenharmony_ci}
64f6603c60Sopenharmony_ci
65f6603c60Sopenharmony_cistatic napi_value AudioDecoderCreateByMimeAudioAac(napi_env env, napi_callback_info info)
66f6603c60Sopenharmony_ci{
67f6603c60Sopenharmony_ci    return TestInitPtr(env, OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC));
68f6603c60Sopenharmony_ci}
69f6603c60Sopenharmony_ci
70f6603c60Sopenharmony_cistatic napi_value AudioDecoderCreateByName(napi_env env, napi_callback_info info)
71f6603c60Sopenharmony_ci{
72f6603c60Sopenharmony_ci    OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS, false);
73f6603c60Sopenharmony_ci    const char *name = OH_AVCapability_GetName(capability);
74f6603c60Sopenharmony_ci    return TestInitPtr(env, OH_AudioDecoder_CreateByName(name));
75f6603c60Sopenharmony_ci}
76f6603c60Sopenharmony_ci
77f6603c60Sopenharmony_cistatic napi_value AudioDecoderDestroy(napi_env env, napi_callback_info info)
78f6603c60Sopenharmony_ci{
79f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
80f6603c60Sopenharmony_ci    return TestInitAVErrCode(env, OH_AudioDecoder_Destroy(audioDec));
81f6603c60Sopenharmony_ci}
82f6603c60Sopenharmony_ci
83f6603c60Sopenharmony_ciclass ADecSignal {
84f6603c60Sopenharmony_cipublic:
85f6603c60Sopenharmony_ci    pthread_mutex_t inMutex_;
86f6603c60Sopenharmony_ci    pthread_mutex_t outMutex_;
87f6603c60Sopenharmony_ci    pthread_mutex_t startMutex_;
88f6603c60Sopenharmony_ci    std::condition_variable inCond_;
89f6603c60Sopenharmony_ci    std::condition_variable outCond_;
90f6603c60Sopenharmony_ci    std::condition_variable startCond_;
91f6603c60Sopenharmony_ci    std::queue<uint32_t> inQueue_;
92f6603c60Sopenharmony_ci    std::queue<uint32_t> outQueue_;
93f6603c60Sopenharmony_ci    std::queue<OH_AVMemory *> inBufferQueue_;
94f6603c60Sopenharmony_ci    std::queue<OH_AVMemory *> outBufferQueue_;
95f6603c60Sopenharmony_ci    std::queue<OH_AVCodecBufferAttr> attrQueue_;
96f6603c60Sopenharmony_ci};
97f6603c60Sopenharmony_ciADecSignal *signal_;
98f6603c60Sopenharmony_cistatic void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
99f6603c60Sopenharmony_ci{
100f6603c60Sopenharmony_ci    (void)codec;
101f6603c60Sopenharmony_ci    (void)errorCode;
102f6603c60Sopenharmony_ci    (void)userData;
103f6603c60Sopenharmony_ci}
104f6603c60Sopenharmony_cistatic void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
105f6603c60Sopenharmony_ci{
106f6603c60Sopenharmony_ci    (void)codec;
107f6603c60Sopenharmony_ci    (void)format;
108f6603c60Sopenharmony_ci    (void)userData;
109f6603c60Sopenharmony_ci}
110f6603c60Sopenharmony_cistatic void onNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData)
111f6603c60Sopenharmony_ci{
112f6603c60Sopenharmony_ci    (void)codec;
113f6603c60Sopenharmony_ci    ADecSignal *signal = static_cast<ADecSignal *>(userData);
114f6603c60Sopenharmony_ci    pthread_mutex_lock(&signal->inMutex_);
115f6603c60Sopenharmony_ci    signal->inQueue_.push(index);
116f6603c60Sopenharmony_ci    signal->inBufferQueue_.push(data);
117f6603c60Sopenharmony_ci    signal->inCond_.notify_all();
118f6603c60Sopenharmony_ci}
119f6603c60Sopenharmony_cistatic void onNeedOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr,
120f6603c60Sopenharmony_ci    void *userData)
121f6603c60Sopenharmony_ci{
122f6603c60Sopenharmony_ci    (void)codec;
123f6603c60Sopenharmony_ci    ADecSignal *signal = static_cast<ADecSignal *>(userData);
124f6603c60Sopenharmony_ci    pthread_mutex_unlock(&signal->outMutex_);
125f6603c60Sopenharmony_ci    signal->outQueue_.push(index);
126f6603c60Sopenharmony_ci    signal->outBufferQueue_.push(data);
127f6603c60Sopenharmony_ci    if (attr) {
128f6603c60Sopenharmony_ci        signal->attrQueue_.push(*attr);
129f6603c60Sopenharmony_ci    }
130f6603c60Sopenharmony_ci    signal->outCond_.notify_all();
131f6603c60Sopenharmony_ci}
132f6603c60Sopenharmony_ci
133f6603c60Sopenharmony_cistatic napi_value AudioDecoderSetCallback(napi_env env, napi_callback_info info)
134f6603c60Sopenharmony_ci{
135f6603c60Sopenharmony_ci    napi_value result;
136f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
137f6603c60Sopenharmony_ci    signal_ = new ADecSignal();
138f6603c60Sopenharmony_ci    OH_AVCodecAsyncCallback callback = { &OnError, &OnStreamChanged, &onNeedInputData, &onNeedOutputData };
139f6603c60Sopenharmony_ci    result = TestInitAVErrCode(env, OH_AudioDecoder_SetCallback(audioDec, callback, signal_));
140f6603c60Sopenharmony_ci    OH_AudioDecoder_Destroy(audioDec);
141f6603c60Sopenharmony_ci    return result;
142f6603c60Sopenharmony_ci}
143f6603c60Sopenharmony_ci
144f6603c60Sopenharmony_cistatic napi_value AudioDecoderConfigure(napi_env env, napi_callback_info info)
145f6603c60Sopenharmony_ci{
146f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
147f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
148f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
149f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
150f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
151f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
152f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
153f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
154f6603c60Sopenharmony_ci    return TestInitAVErrCode(env, OH_AudioDecoder_Configure(audioDec, format));
155f6603c60Sopenharmony_ci}
156f6603c60Sopenharmony_ci
157f6603c60Sopenharmony_cistatic napi_value AudioDecoderPrepare(napi_env env, napi_callback_info info)
158f6603c60Sopenharmony_ci{
159f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
160f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
161f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
162f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
163f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
164f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
165f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
166f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
167f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
168f6603c60Sopenharmony_ci    return TestInitAVErrCode(env, OH_AudioDecoder_Prepare(audioDec));
169f6603c60Sopenharmony_ci}
170f6603c60Sopenharmony_ci
171f6603c60Sopenharmony_cistatic napi_value AudioDecoderStart(napi_env env, napi_callback_info info)
172f6603c60Sopenharmony_ci{
173f6603c60Sopenharmony_ci    int backParam = FAIL;
174f6603c60Sopenharmony_ci    napi_value result = nullptr;
175f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
176f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
177f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
178f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
179f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
180f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
181f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
182f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
183f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
184f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Configure(audioDec, format);
185f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Prepare(audioDec);
186f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Start(audioDec);
187f6603c60Sopenharmony_ci    if (checkParam == AV_ERR_OK) {
188f6603c60Sopenharmony_ci        backParam = SUCCESS;
189f6603c60Sopenharmony_ci    }
190f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
191f6603c60Sopenharmony_ci    return result;
192f6603c60Sopenharmony_ci}
193f6603c60Sopenharmony_ci
194f6603c60Sopenharmony_cistatic napi_value AudioDecoderStop(napi_env env, napi_callback_info info)
195f6603c60Sopenharmony_ci{
196f6603c60Sopenharmony_ci    int backParam = FAIL;
197f6603c60Sopenharmony_ci    napi_value result = nullptr;
198f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
199f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
200f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
201f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
202f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
203f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
204f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
205f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
206f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
207f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Configure(audioDec, format);
208f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Prepare(audioDec);
209f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
210f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Stop(audioDec);
211f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
212f6603c60Sopenharmony_ci            backParam = SUCCESS;
213f6603c60Sopenharmony_ci        }
214f6603c60Sopenharmony_ci    }
215f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
216f6603c60Sopenharmony_ci    return result;
217f6603c60Sopenharmony_ci}
218f6603c60Sopenharmony_ci
219f6603c60Sopenharmony_cistatic napi_value AudioDecoderFlush(napi_env env, napi_callback_info info)
220f6603c60Sopenharmony_ci{
221f6603c60Sopenharmony_ci    int backParam = FAIL;
222f6603c60Sopenharmony_ci    napi_value result = nullptr;
223f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
224f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
225f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
226f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
227f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
228f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
229f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
230f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
231f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
232f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
233f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
234f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
235f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
236f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
237f6603c60Sopenharmony_ci            backParam = SUCCESS;
238f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
239f6603c60Sopenharmony_ci        }
240f6603c60Sopenharmony_ci    }
241f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
242f6603c60Sopenharmony_ci    return result;
243f6603c60Sopenharmony_ci}
244f6603c60Sopenharmony_ci
245f6603c60Sopenharmony_cistatic napi_value AudioDecoderReset(napi_env env, napi_callback_info info)
246f6603c60Sopenharmony_ci{
247f6603c60Sopenharmony_ci    int backParam = FAIL;
248f6603c60Sopenharmony_ci    napi_value result = nullptr;
249f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
250f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
251f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
252f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
253f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
254f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
255f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
256f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
257f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
258f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
259f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
260f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
261f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Reset(audioDec);
262f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
263f6603c60Sopenharmony_ci            backParam = SUCCESS;
264f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
265f6603c60Sopenharmony_ci        }
266f6603c60Sopenharmony_ci    }
267f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
268f6603c60Sopenharmony_ci    return result;
269f6603c60Sopenharmony_ci}
270f6603c60Sopenharmony_ci
271f6603c60Sopenharmony_cistatic napi_value AudioDecoderGetOutputDescription(napi_env env, napi_callback_info info)
272f6603c60Sopenharmony_ci{
273f6603c60Sopenharmony_ci    int backParam = FAIL;
274f6603c60Sopenharmony_ci    napi_value result = nullptr;
275f6603c60Sopenharmony_ci    OH_AVFormat *checkParam = nullptr;
276f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
277f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
278f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
279f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
280f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
281f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
282f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
283f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
284f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
285f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
286f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
287f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_GetOutputDescription(audioDec);
288f6603c60Sopenharmony_ci        if (checkParam != nullptr) {
289f6603c60Sopenharmony_ci            backParam = SUCCESS;
290f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
291f6603c60Sopenharmony_ci            free(checkParam);
292f6603c60Sopenharmony_ci        }
293f6603c60Sopenharmony_ci    }
294f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
295f6603c60Sopenharmony_ci    return result;
296f6603c60Sopenharmony_ci}
297f6603c60Sopenharmony_ci
298f6603c60Sopenharmony_cistatic napi_value AudioDecoderSetParameter(napi_env env, napi_callback_info info)
299f6603c60Sopenharmony_ci{
300f6603c60Sopenharmony_ci    int backParam = FAIL;
301f6603c60Sopenharmony_ci    napi_value result = nullptr;
302f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
303f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
304f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
305f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
306f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
307f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
308f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
309f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
310f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
311f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Configure(audioDec, format);
312f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Prepare(audioDec);
313f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
314f6603c60Sopenharmony_ci        format = OH_AudioDecoder_GetOutputDescription(audioDec);
315f6603c60Sopenharmony_ci        if (format != nullptr) {
316f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_SetParameter(audioDec, format);
317f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
318f6603c60Sopenharmony_ci                backParam = SUCCESS;
319f6603c60Sopenharmony_ci                free(format);
320f6603c60Sopenharmony_ci            }
321f6603c60Sopenharmony_ci        }
322f6603c60Sopenharmony_ci    }
323f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
324f6603c60Sopenharmony_ci    return result;
325f6603c60Sopenharmony_ci}
326f6603c60Sopenharmony_ci
327f6603c60Sopenharmony_cistatic napi_value AudioDecoderIsValid(napi_env env, napi_callback_info info)
328f6603c60Sopenharmony_ci{
329f6603c60Sopenharmony_ci    int backParam = FAIL;
330f6603c60Sopenharmony_ci    napi_value result = nullptr;
331f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
332f6603c60Sopenharmony_ci    bool status = true;
333f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
334f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
335f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
336f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
337f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
338f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
339f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
340f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
341f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Configure(audioDec, format);
342f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Prepare(audioDec);
343f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
344f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
345f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
346f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_IsValid(audioDec, &status);
347f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
348f6603c60Sopenharmony_ci                backParam = SUCCESS;
349f6603c60Sopenharmony_ci                OH_AudioDecoder_Stop(audioDec);
350f6603c60Sopenharmony_ci            }
351f6603c60Sopenharmony_ci        }
352f6603c60Sopenharmony_ci    }
353f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
354f6603c60Sopenharmony_ci    return result;
355f6603c60Sopenharmony_ci}
356f6603c60Sopenharmony_ci
357f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderCreateByNameAnormal(napi_env env, napi_callback_info info)
358f6603c60Sopenharmony_ci{
359f6603c60Sopenharmony_ci    OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_AAC, false);
360f6603c60Sopenharmony_ci    const char *name = OH_AVCapability_GetName(capability);
361f6603c60Sopenharmony_ci    return TestInitPtr(env, OH_AudioDecoder_CreateByName(name));
362f6603c60Sopenharmony_ci}
363f6603c60Sopenharmony_ci
364f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderCreateByNameBnormal(napi_env env, napi_callback_info info)
365f6603c60Sopenharmony_ci{
366f6603c60Sopenharmony_ci    OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_MPEG, false);
367f6603c60Sopenharmony_ci    const char *name = OH_AVCapability_GetName(capability);
368f6603c60Sopenharmony_ci    return TestInitPtr(env, OH_AudioDecoder_CreateByName(name));
369f6603c60Sopenharmony_ci}
370f6603c60Sopenharmony_ci
371f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderCreateByNameCnormal(napi_env env, napi_callback_info info)
372f6603c60Sopenharmony_ci{
373f6603c60Sopenharmony_ci    OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_FLAC, false);
374f6603c60Sopenharmony_ci    const char *name = OH_AVCapability_GetName(capability);
375f6603c60Sopenharmony_ci    return TestInitPtr(env, OH_AudioDecoder_CreateByName(name));
376f6603c60Sopenharmony_ci}
377f6603c60Sopenharmony_ci
378f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderDestroyAnormal(napi_env env, napi_callback_info info)
379f6603c60Sopenharmony_ci{
380f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
381f6603c60Sopenharmony_ci    return TestInitAVErrCode(env, OH_AudioDecoder_Destroy(audioDec));
382f6603c60Sopenharmony_ci}
383f6603c60Sopenharmony_ci
384f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderDestroyBnormal(napi_env env, napi_callback_info info)
385f6603c60Sopenharmony_ci{
386f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
387f6603c60Sopenharmony_ci    return TestInitAVErrCode(env, OH_AudioDecoder_Destroy(audioDec));
388f6603c60Sopenharmony_ci}
389f6603c60Sopenharmony_ci
390f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderDestroyCnormal(napi_env env, napi_callback_info info)
391f6603c60Sopenharmony_ci{
392f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
393f6603c60Sopenharmony_ci    return TestInitAVErrCode(env, OH_AudioDecoder_Destroy(audioDec));
394f6603c60Sopenharmony_ci}
395f6603c60Sopenharmony_ci
396f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderStartAnormal(napi_env env, napi_callback_info info)
397f6603c60Sopenharmony_ci{
398f6603c60Sopenharmony_ci    int backParam = FAIL;
399f6603c60Sopenharmony_ci    napi_value result = nullptr;
400f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
401f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
402f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
403f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
404f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
405f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
406f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
407f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
408f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
409f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
410f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
411f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Start(audioDec);
412f6603c60Sopenharmony_ci    if (checkParam == AV_ERR_OK) {
413f6603c60Sopenharmony_ci        backParam = SUCCESS;
414f6603c60Sopenharmony_ci    }
415f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
416f6603c60Sopenharmony_ci    return result;
417f6603c60Sopenharmony_ci}
418f6603c60Sopenharmony_ci
419f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderStartBnormal(napi_env env, napi_callback_info info)
420f6603c60Sopenharmony_ci{
421f6603c60Sopenharmony_ci    int backParam = FAIL;
422f6603c60Sopenharmony_ci    napi_value result = nullptr;
423f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
424f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
425f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
426f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
427f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
428f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
429f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
430f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
431f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
432f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
433f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
434f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Start(audioDec);
435f6603c60Sopenharmony_ci    if (checkParam == AV_ERR_OK) {
436f6603c60Sopenharmony_ci        backParam = SUCCESS;
437f6603c60Sopenharmony_ci    }
438f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
439f6603c60Sopenharmony_ci    return result;
440f6603c60Sopenharmony_ci}
441f6603c60Sopenharmony_ci
442f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderStartCnormal(napi_env env, napi_callback_info info)
443f6603c60Sopenharmony_ci{
444f6603c60Sopenharmony_ci    int backParam = FAIL;
445f6603c60Sopenharmony_ci    napi_value result = nullptr;
446f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
447f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
448f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
449f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
450f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
451f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
452f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
453f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
454f6603c60Sopenharmony_ci    checkParam = OH_AudioDecoder_Start(audioDec);
455f6603c60Sopenharmony_ci    if (checkParam == AV_ERR_OK) {
456f6603c60Sopenharmony_ci        backParam = SUCCESS;
457f6603c60Sopenharmony_ci    }
458f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
459f6603c60Sopenharmony_ci    return result;
460f6603c60Sopenharmony_ci}
461f6603c60Sopenharmony_ci
462f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderStopAnormal(napi_env env, napi_callback_info info)
463f6603c60Sopenharmony_ci{
464f6603c60Sopenharmony_ci    int backParam = FAIL;
465f6603c60Sopenharmony_ci    napi_value result = nullptr;
466f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
467f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
468f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
469f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
470f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
471f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
472f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
473f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
474f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
475f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
476f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
477f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
478f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Stop(audioDec);
479f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
480f6603c60Sopenharmony_ci            backParam = SUCCESS;
481f6603c60Sopenharmony_ci        }
482f6603c60Sopenharmony_ci    }
483f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
484f6603c60Sopenharmony_ci    return result;
485f6603c60Sopenharmony_ci}
486f6603c60Sopenharmony_ci
487f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderStopBnormal(napi_env env, napi_callback_info info)
488f6603c60Sopenharmony_ci{
489f6603c60Sopenharmony_ci    int backParam = FAIL;
490f6603c60Sopenharmony_ci    napi_value result = nullptr;
491f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
492f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
493f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
494f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
495f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
496f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
497f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
498f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
499f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
500f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
501f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
502f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
503f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Stop(audioDec);
504f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
505f6603c60Sopenharmony_ci            backParam = SUCCESS;
506f6603c60Sopenharmony_ci        }
507f6603c60Sopenharmony_ci    }
508f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
509f6603c60Sopenharmony_ci    return result;
510f6603c60Sopenharmony_ci}
511f6603c60Sopenharmony_ci
512f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderStopCnormal(napi_env env, napi_callback_info info)
513f6603c60Sopenharmony_ci{
514f6603c60Sopenharmony_ci    int backParam = FAIL;
515f6603c60Sopenharmony_ci    napi_value result = nullptr;
516f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
517f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
518f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
519f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
520f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
521f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
522f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
523f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
524f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
525f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Stop(audioDec);
526f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
527f6603c60Sopenharmony_ci            backParam = SUCCESS;
528f6603c60Sopenharmony_ci        }
529f6603c60Sopenharmony_ci    }
530f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
531f6603c60Sopenharmony_ci    return result;
532f6603c60Sopenharmony_ci}
533f6603c60Sopenharmony_ci
534f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderFlushAnormal(napi_env env, napi_callback_info info)
535f6603c60Sopenharmony_ci{
536f6603c60Sopenharmony_ci    int backParam = FAIL;
537f6603c60Sopenharmony_ci    napi_value result = nullptr;
538f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
539f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
540f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
541f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
542f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
543f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
544f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
545f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
546f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
547f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
548f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
549f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
550f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
551f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
552f6603c60Sopenharmony_ci            backParam = SUCCESS;
553f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
554f6603c60Sopenharmony_ci        }
555f6603c60Sopenharmony_ci    }
556f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
557f6603c60Sopenharmony_ci    return result;
558f6603c60Sopenharmony_ci}
559f6603c60Sopenharmony_ci
560f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderFlushBnormal(napi_env env, napi_callback_info info)
561f6603c60Sopenharmony_ci{
562f6603c60Sopenharmony_ci    int backParam = FAIL;
563f6603c60Sopenharmony_ci    napi_value result = nullptr;
564f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
565f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
566f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
567f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
568f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
569f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
570f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
571f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
572f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
573f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
574f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
575f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
576f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
577f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
578f6603c60Sopenharmony_ci            backParam = SUCCESS;
579f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
580f6603c60Sopenharmony_ci        }
581f6603c60Sopenharmony_ci    }
582f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
583f6603c60Sopenharmony_ci    return result;
584f6603c60Sopenharmony_ci}
585f6603c60Sopenharmony_ci
586f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderFlushCnormal(napi_env env, napi_callback_info info)
587f6603c60Sopenharmony_ci{
588f6603c60Sopenharmony_ci    int backParam = FAIL;
589f6603c60Sopenharmony_ci    napi_value result = nullptr;
590f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
591f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
592f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
593f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
594f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
595f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
596f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
597f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
598f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
599f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
600f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
601f6603c60Sopenharmony_ci            backParam = SUCCESS;
602f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
603f6603c60Sopenharmony_ci        }
604f6603c60Sopenharmony_ci    }
605f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
606f6603c60Sopenharmony_ci    return result;
607f6603c60Sopenharmony_ci}
608f6603c60Sopenharmony_ci
609f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderResetAnormal(napi_env env, napi_callback_info info)
610f6603c60Sopenharmony_ci{
611f6603c60Sopenharmony_ci    int backParam = FAIL;
612f6603c60Sopenharmony_ci    napi_value result = nullptr;
613f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
614f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
615f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
616f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
617f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
618f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
619f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
620f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
621f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
622f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
623f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
624f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
625f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Reset(audioDec);
626f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
627f6603c60Sopenharmony_ci            backParam = SUCCESS;
628f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
629f6603c60Sopenharmony_ci        }
630f6603c60Sopenharmony_ci    }
631f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
632f6603c60Sopenharmony_ci    return result;
633f6603c60Sopenharmony_ci}
634f6603c60Sopenharmony_ci
635f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderResetBnormal(napi_env env, napi_callback_info info)
636f6603c60Sopenharmony_ci{
637f6603c60Sopenharmony_ci    int backParam = FAIL;
638f6603c60Sopenharmony_ci    napi_value result = nullptr;
639f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
640f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
641f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
642f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
643f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
644f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
645f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
646f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
647f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
648f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
649f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
650f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
651f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Reset(audioDec);
652f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
653f6603c60Sopenharmony_ci            backParam = SUCCESS;
654f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
655f6603c60Sopenharmony_ci        }
656f6603c60Sopenharmony_ci    }
657f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
658f6603c60Sopenharmony_ci    return result;
659f6603c60Sopenharmony_ci}
660f6603c60Sopenharmony_ci
661f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderResetCnormal(napi_env env, napi_callback_info info)
662f6603c60Sopenharmony_ci{
663f6603c60Sopenharmony_ci    int backParam = FAIL;
664f6603c60Sopenharmony_ci    napi_value result = nullptr;
665f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
666f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
667f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
668f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
669f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
670f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
671f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
672f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
673f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
674f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Reset(audioDec);
675f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
676f6603c60Sopenharmony_ci            backParam = SUCCESS;
677f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
678f6603c60Sopenharmony_ci        }
679f6603c60Sopenharmony_ci    }
680f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
681f6603c60Sopenharmony_ci    return result;
682f6603c60Sopenharmony_ci}
683f6603c60Sopenharmony_ci
684f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderGetOutputDescriptionAnormal(napi_env env, napi_callback_info info)
685f6603c60Sopenharmony_ci{
686f6603c60Sopenharmony_ci    int backParam = FAIL;
687f6603c60Sopenharmony_ci    napi_value result = nullptr;
688f6603c60Sopenharmony_ci    OH_AVFormat *checkParam = nullptr;
689f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
690f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
691f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
692f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
693f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
694f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
695f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
696f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
697f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
698f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
699f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
700f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_GetOutputDescription(audioDec);
701f6603c60Sopenharmony_ci        if (checkParam != nullptr) {
702f6603c60Sopenharmony_ci            backParam = SUCCESS;
703f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
704f6603c60Sopenharmony_ci            free(checkParam);
705f6603c60Sopenharmony_ci        }
706f6603c60Sopenharmony_ci    }
707f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
708f6603c60Sopenharmony_ci    return result;
709f6603c60Sopenharmony_ci}
710f6603c60Sopenharmony_ci
711f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderGetOutputDescriptionBnormal(napi_env env, napi_callback_info info)
712f6603c60Sopenharmony_ci{
713f6603c60Sopenharmony_ci    int backParam = FAIL;
714f6603c60Sopenharmony_ci    napi_value result = nullptr;
715f6603c60Sopenharmony_ci    OH_AVFormat *checkParam = nullptr;
716f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
717f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
718f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
719f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
720f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
721f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
722f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
723f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
724f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
725f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
726f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
727f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_GetOutputDescription(audioDec);
728f6603c60Sopenharmony_ci        if (checkParam != nullptr) {
729f6603c60Sopenharmony_ci            backParam = SUCCESS;
730f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
731f6603c60Sopenharmony_ci            free(checkParam);
732f6603c60Sopenharmony_ci        }
733f6603c60Sopenharmony_ci    }
734f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
735f6603c60Sopenharmony_ci    return result;
736f6603c60Sopenharmony_ci}
737f6603c60Sopenharmony_ci
738f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderGetOutputDescriptionCnormal(napi_env env, napi_callback_info info)
739f6603c60Sopenharmony_ci{
740f6603c60Sopenharmony_ci    int backParam = FAIL;
741f6603c60Sopenharmony_ci    napi_value result = nullptr;
742f6603c60Sopenharmony_ci    OH_AVFormat *checkParam = nullptr;
743f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
744f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
745f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
746f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
747f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
748f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
749f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
750f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
751f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_GetOutputDescription(audioDec);
752f6603c60Sopenharmony_ci        if (checkParam != nullptr) {
753f6603c60Sopenharmony_ci            backParam = SUCCESS;
754f6603c60Sopenharmony_ci            OH_AudioDecoder_Stop(audioDec);
755f6603c60Sopenharmony_ci            free(checkParam);
756f6603c60Sopenharmony_ci        }
757f6603c60Sopenharmony_ci    }
758f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
759f6603c60Sopenharmony_ci    return result;
760f6603c60Sopenharmony_ci}
761f6603c60Sopenharmony_ci
762f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderSetParameterAnormal(napi_env env, napi_callback_info info)
763f6603c60Sopenharmony_ci{
764f6603c60Sopenharmony_ci    int backParam = FAIL;
765f6603c60Sopenharmony_ci    napi_value result = nullptr;
766f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
767f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
768f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
769f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
770f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
771f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
772f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
773f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
774f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
775f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
776f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
777f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
778f6603c60Sopenharmony_ci        format = OH_AudioDecoder_GetOutputDescription(audioDec);
779f6603c60Sopenharmony_ci        if (format != nullptr) {
780f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_SetParameter(audioDec, format);
781f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
782f6603c60Sopenharmony_ci                backParam = SUCCESS;
783f6603c60Sopenharmony_ci                free(format);
784f6603c60Sopenharmony_ci            }
785f6603c60Sopenharmony_ci        }
786f6603c60Sopenharmony_ci    }
787f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
788f6603c60Sopenharmony_ci    return result;
789f6603c60Sopenharmony_ci}
790f6603c60Sopenharmony_ci
791f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderSetParameterBnormal(napi_env env, napi_callback_info info)
792f6603c60Sopenharmony_ci{
793f6603c60Sopenharmony_ci    int backParam = FAIL;
794f6603c60Sopenharmony_ci    napi_value result = nullptr;
795f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
796f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
797f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
798f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
799f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
800f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
801f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
802f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
803f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
804f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
805f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
806f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
807f6603c60Sopenharmony_ci        format = OH_AudioDecoder_GetOutputDescription(audioDec);
808f6603c60Sopenharmony_ci        if (format != nullptr) {
809f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_SetParameter(audioDec, format);
810f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
811f6603c60Sopenharmony_ci                backParam = SUCCESS;
812f6603c60Sopenharmony_ci                free(format);
813f6603c60Sopenharmony_ci            }
814f6603c60Sopenharmony_ci        }
815f6603c60Sopenharmony_ci    }
816f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
817f6603c60Sopenharmony_ci    return result;
818f6603c60Sopenharmony_ci}
819f6603c60Sopenharmony_ci
820f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderSetParameterCnormal(napi_env env, napi_callback_info info)
821f6603c60Sopenharmony_ci{
822f6603c60Sopenharmony_ci    int backParam = FAIL;
823f6603c60Sopenharmony_ci    napi_value result = nullptr;
824f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
825f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
826f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
827f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
828f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
829f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
830f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
831f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
832f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
833f6603c60Sopenharmony_ci        format = OH_AudioDecoder_GetOutputDescription(audioDec);
834f6603c60Sopenharmony_ci        if (format != nullptr) {
835f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_SetParameter(audioDec, format);
836f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
837f6603c60Sopenharmony_ci                backParam = SUCCESS;
838f6603c60Sopenharmony_ci                free(format);
839f6603c60Sopenharmony_ci            }
840f6603c60Sopenharmony_ci        }
841f6603c60Sopenharmony_ci    }
842f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
843f6603c60Sopenharmony_ci    return result;
844f6603c60Sopenharmony_ci}
845f6603c60Sopenharmony_ci
846f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderIsValidAnormal(napi_env env, napi_callback_info info)
847f6603c60Sopenharmony_ci{
848f6603c60Sopenharmony_ci    int backParam = FAIL;
849f6603c60Sopenharmony_ci    napi_value result = nullptr;
850f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
851f6603c60Sopenharmony_ci    bool status = true;
852f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
853f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
854f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
855f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
856f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
857f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
858f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
859f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
860f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
861f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
862f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
863f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
864f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
865f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_IsValid(audioDec, &status);
866f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
867f6603c60Sopenharmony_ci                backParam = SUCCESS;
868f6603c60Sopenharmony_ci                OH_AudioDecoder_Stop(audioDec);
869f6603c60Sopenharmony_ci            }
870f6603c60Sopenharmony_ci        }
871f6603c60Sopenharmony_ci    }
872f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
873f6603c60Sopenharmony_ci    return result;
874f6603c60Sopenharmony_ci}
875f6603c60Sopenharmony_ci
876f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderIsValidBnormal(napi_env env, napi_callback_info info)
877f6603c60Sopenharmony_ci{
878f6603c60Sopenharmony_ci    int backParam = FAIL;
879f6603c60Sopenharmony_ci    napi_value result = nullptr;
880f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
881f6603c60Sopenharmony_ci    bool status = true;
882f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
883f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
884f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE);
885f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE);
886f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT);
887f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
888f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
889f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC);
890f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
891f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
892f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
893f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
894f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
895f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_IsValid(audioDec, &status);
896f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
897f6603c60Sopenharmony_ci                backParam = SUCCESS;
898f6603c60Sopenharmony_ci                OH_AudioDecoder_Stop(audioDec);
899f6603c60Sopenharmony_ci            }
900f6603c60Sopenharmony_ci        }
901f6603c60Sopenharmony_ci    }
902f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
903f6603c60Sopenharmony_ci    return result;
904f6603c60Sopenharmony_ci}
905f6603c60Sopenharmony_ci
906f6603c60Sopenharmony_cistatic napi_value OHAudioDecoderIsValidCnormal(napi_env env, napi_callback_info info)
907f6603c60Sopenharmony_ci{
908f6603c60Sopenharmony_ci    int backParam = FAIL;
909f6603c60Sopenharmony_ci    napi_value result = nullptr;
910f6603c60Sopenharmony_ci    OH_AVErrCode checkParam;
911f6603c60Sopenharmony_ci    bool status = true;
912f6603c60Sopenharmony_ci    OH_AVFormat *format = nullptr;
913f6603c60Sopenharmony_ci    format = OH_AVFormat_Create();
914f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_IDENTIFICATION_HEADER, DEFAULT_VORBISTWO_TYPE);
915f6603c60Sopenharmony_ci    OH_AVFormat_SetIntValue(format, OH_MD_KEY_SETUP_HEADER, DEFAULT_VORBIS_TYPE);
916f6603c60Sopenharmony_ci    OH_AVCodec *audioDec = OH_AudioDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS);
917f6603c60Sopenharmony_ci    OH_AudioDecoder_Configure(audioDec, format);
918f6603c60Sopenharmony_ci    OH_AudioDecoder_Prepare(audioDec);
919f6603c60Sopenharmony_ci    if (OH_AudioDecoder_Start(audioDec) == AV_ERR_OK) {
920f6603c60Sopenharmony_ci        checkParam = OH_AudioDecoder_Flush(audioDec);
921f6603c60Sopenharmony_ci        if (checkParam == AV_ERR_OK) {
922f6603c60Sopenharmony_ci            checkParam = OH_AudioDecoder_IsValid(audioDec, &status);
923f6603c60Sopenharmony_ci            if (checkParam == AV_ERR_OK) {
924f6603c60Sopenharmony_ci                backParam = SUCCESS;
925f6603c60Sopenharmony_ci                OH_AudioDecoder_Stop(audioDec);
926f6603c60Sopenharmony_ci            }
927f6603c60Sopenharmony_ci        }
928f6603c60Sopenharmony_ci    }
929f6603c60Sopenharmony_ci    napi_create_int32(env, backParam, &result);
930f6603c60Sopenharmony_ci    return result;
931f6603c60Sopenharmony_ci}
932f6603c60Sopenharmony_ci
933f6603c60Sopenharmony_ciEXTERN_C_START
934f6603c60Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports)
935f6603c60Sopenharmony_ci{
936f6603c60Sopenharmony_ci    napi_property_descriptor desc[] = {
937f6603c60Sopenharmony_ci        {"OH_AudioDecoder_CreateByMime", nullptr, AudioDecoderCreateByMimeAudioAac, nullptr, nullptr, nullptr,
938f6603c60Sopenharmony_ci         napi_default, nullptr},
939f6603c60Sopenharmony_ci        {"OH_AudioDecoder_CreateByName", nullptr, AudioDecoderCreateByName, nullptr, nullptr, nullptr, napi_default,
940f6603c60Sopenharmony_ci         nullptr},
941f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Destroy", nullptr, AudioDecoderDestroy, nullptr, nullptr, nullptr, napi_default, nullptr},
942f6603c60Sopenharmony_ci        {"OH_AudioDecoder_SetCallback", nullptr, AudioDecoderSetCallback, nullptr, nullptr, nullptr, napi_default,
943f6603c60Sopenharmony_ci         nullptr},
944f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Configure", nullptr, AudioDecoderConfigure, nullptr, nullptr, nullptr, napi_default, nullptr},
945f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Prepare", nullptr, AudioDecoderPrepare, nullptr, nullptr, nullptr, napi_default, nullptr},
946f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Start", nullptr, AudioDecoderStart, nullptr, nullptr, nullptr, napi_default, nullptr},
947f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Stop", nullptr, AudioDecoderStop, nullptr, nullptr, nullptr, napi_default, nullptr},
948f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Flush", nullptr, AudioDecoderFlush, nullptr, nullptr, nullptr, napi_default, nullptr},
949f6603c60Sopenharmony_ci        {"OH_AudioDecoder_Reset", nullptr, AudioDecoderReset, nullptr, nullptr, nullptr, napi_default, nullptr},
950f6603c60Sopenharmony_ci        {"OH_AudioDecoder_GetOutputDescription", nullptr, AudioDecoderGetOutputDescription, nullptr, nullptr, nullptr,
951f6603c60Sopenharmony_ci         napi_default, nullptr},
952f6603c60Sopenharmony_ci        {"OH_AudioDecoder_SetParameter", nullptr, AudioDecoderSetParameter, nullptr, nullptr, nullptr, napi_default,
953f6603c60Sopenharmony_ci         nullptr},
954f6603c60Sopenharmony_ci        {"OH_AudioDecoder_IsValid", nullptr, AudioDecoderIsValid, nullptr, nullptr, nullptr, napi_default, nullptr},
955f6603c60Sopenharmony_ci        {"OHAudioDecoderCreateByNameAnormal", nullptr, OHAudioDecoderCreateByNameAnormal, nullptr, nullptr, nullptr,
956f6603c60Sopenharmony_ci         napi_default, nullptr},
957f6603c60Sopenharmony_ci        {"OHAudioDecoderCreateByNameBnormal", nullptr, OHAudioDecoderCreateByNameBnormal, nullptr, nullptr, nullptr,
958f6603c60Sopenharmony_ci         napi_default, nullptr},
959f6603c60Sopenharmony_ci        {"OHAudioDecoderCreateByNameCnormal", nullptr, OHAudioDecoderCreateByNameCnormal, nullptr, nullptr, nullptr,
960f6603c60Sopenharmony_ci         napi_default, nullptr},
961f6603c60Sopenharmony_ci        {"OHAudioDecoderDestroyAnormal", nullptr, OHAudioDecoderDestroyAnormal, nullptr, nullptr, nullptr, napi_default,
962f6603c60Sopenharmony_ci         nullptr},
963f6603c60Sopenharmony_ci        {"OHAudioDecoderDestroyBnormal", nullptr, OHAudioDecoderDestroyBnormal, nullptr, nullptr, nullptr, napi_default,
964f6603c60Sopenharmony_ci         nullptr},
965f6603c60Sopenharmony_ci        {"OHAudioDecoderDestroyCnormal", nullptr, OHAudioDecoderDestroyCnormal, nullptr, nullptr, nullptr, napi_default,
966f6603c60Sopenharmony_ci         nullptr},
967f6603c60Sopenharmony_ci        {"OHAudioDecoderStartAnormal", nullptr, OHAudioDecoderStartAnormal, nullptr, nullptr, nullptr, napi_default,
968f6603c60Sopenharmony_ci         nullptr},
969f6603c60Sopenharmony_ci        {"OHAudioDecoderStartBnormal", nullptr, OHAudioDecoderStartBnormal, nullptr, nullptr, nullptr, napi_default,
970f6603c60Sopenharmony_ci         nullptr},
971f6603c60Sopenharmony_ci        {"OHAudioDecoderStartCnormal", nullptr, OHAudioDecoderStartCnormal, nullptr, nullptr, nullptr, napi_default,
972f6603c60Sopenharmony_ci         nullptr},
973f6603c60Sopenharmony_ci        {"OHAudioDecoderStopAnormal", nullptr, OHAudioDecoderStopAnormal, nullptr, nullptr, nullptr, napi_default,
974f6603c60Sopenharmony_ci         nullptr},
975f6603c60Sopenharmony_ci        {"OHAudioDecoderStopBnormal", nullptr, OHAudioDecoderStopBnormal, nullptr, nullptr, nullptr, napi_default,
976f6603c60Sopenharmony_ci         nullptr},
977f6603c60Sopenharmony_ci        {"OHAudioDecoderStopCnormal", nullptr, OHAudioDecoderStopCnormal, nullptr, nullptr, nullptr, napi_default,
978f6603c60Sopenharmony_ci         nullptr},
979f6603c60Sopenharmony_ci        {"OHAudioDecoderFlushAnormal", nullptr, OHAudioDecoderFlushAnormal, nullptr, nullptr, nullptr, napi_default,
980f6603c60Sopenharmony_ci         nullptr},
981f6603c60Sopenharmony_ci        {"OHAudioDecoderFlushBnormal", nullptr, OHAudioDecoderFlushBnormal, nullptr, nullptr, nullptr, napi_default,
982f6603c60Sopenharmony_ci         nullptr},
983f6603c60Sopenharmony_ci        {"OHAudioDecoderFlushCnormal", nullptr, OHAudioDecoderFlushCnormal, nullptr, nullptr, nullptr, napi_default,
984f6603c60Sopenharmony_ci         nullptr},
985f6603c60Sopenharmony_ci        {"OHAudioDecoderResetAnormal", nullptr, OHAudioDecoderResetAnormal, nullptr, nullptr, nullptr, napi_default,
986f6603c60Sopenharmony_ci         nullptr},
987f6603c60Sopenharmony_ci        {"OHAudioDecoderResetBnormal", nullptr, OHAudioDecoderResetBnormal, nullptr, nullptr, nullptr, napi_default,
988f6603c60Sopenharmony_ci         nullptr},
989f6603c60Sopenharmony_ci        {"OHAudioDecoderResetCnormal", nullptr, OHAudioDecoderResetCnormal, nullptr, nullptr, nullptr, napi_default,
990f6603c60Sopenharmony_ci         nullptr},
991f6603c60Sopenharmony_ci        {"OHAudioDecoderGetOutputDescriptionAnormal", nullptr, OHAudioDecoderGetOutputDescriptionAnormal, nullptr,
992f6603c60Sopenharmony_ci         nullptr, nullptr, napi_default, nullptr},
993f6603c60Sopenharmony_ci        {"OHAudioDecoderGetOutputDescriptionBnormal", nullptr, OHAudioDecoderGetOutputDescriptionBnormal, nullptr,
994f6603c60Sopenharmony_ci         nullptr, nullptr, napi_default, nullptr},
995f6603c60Sopenharmony_ci        {"OHAudioDecoderGetOutputDescriptionCnormal", nullptr, OHAudioDecoderGetOutputDescriptionCnormal, nullptr,
996f6603c60Sopenharmony_ci         nullptr, nullptr, napi_default, nullptr},
997f6603c60Sopenharmony_ci        {"OHAudioDecoderSetParameterAnormal", nullptr, OHAudioDecoderSetParameterAnormal, nullptr, nullptr, nullptr,
998f6603c60Sopenharmony_ci         napi_default, nullptr},
999f6603c60Sopenharmony_ci        {"OHAudioDecoderSetParameterBnormal", nullptr, OHAudioDecoderSetParameterBnormal, nullptr, nullptr, nullptr,
1000f6603c60Sopenharmony_ci         napi_default, nullptr},
1001f6603c60Sopenharmony_ci        {"OHAudioDecoderSetParameterCnormal", nullptr, OHAudioDecoderSetParameterCnormal, nullptr, nullptr, nullptr,
1002f6603c60Sopenharmony_ci         napi_default, nullptr},
1003f6603c60Sopenharmony_ci        {"OHAudioDecoderIsValidAnormal", nullptr, OHAudioDecoderIsValidAnormal, nullptr, nullptr, nullptr, napi_default,
1004f6603c60Sopenharmony_ci         nullptr},
1005f6603c60Sopenharmony_ci        {"OHAudioDecoderIsValidBnormal", nullptr, OHAudioDecoderIsValidBnormal, nullptr, nullptr, nullptr, napi_default,
1006f6603c60Sopenharmony_ci         nullptr},
1007f6603c60Sopenharmony_ci        {"OHAudioDecoderIsValidCnormal", nullptr, OHAudioDecoderIsValidCnormal, nullptr, nullptr, nullptr, napi_default,
1008f6603c60Sopenharmony_ci         nullptr},
1009f6603c60Sopenharmony_ci    };
1010f6603c60Sopenharmony_ci    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
1011f6603c60Sopenharmony_ci    return exports;
1012f6603c60Sopenharmony_ci}
1013f6603c60Sopenharmony_ciEXTERN_C_END
1014f6603c60Sopenharmony_ci
1015f6603c60Sopenharmony_cistatic napi_module demoModule = {
1016f6603c60Sopenharmony_ci    .nm_version = 1,
1017f6603c60Sopenharmony_ci    .nm_flags = 0,
1018f6603c60Sopenharmony_ci    .nm_filename = nullptr,
1019f6603c60Sopenharmony_ci    .nm_register_func = Init,
1020f6603c60Sopenharmony_ci    .nm_modname = "libaudiodecoderxdlndk",
1021f6603c60Sopenharmony_ci    .nm_priv = ((void *)0),
1022f6603c60Sopenharmony_ci    .reserved = { 0 },
1023f6603c60Sopenharmony_ci};
1024f6603c60Sopenharmony_ci
1025f6603c60Sopenharmony_ciextern "C" __attribute__((constructor)) void RegisterModule(void)
1026f6603c60Sopenharmony_ci{
1027f6603c60Sopenharmony_ci    napi_module_register(&demoModule);
1028f6603c60Sopenharmony_ci}
1029