1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "napi/native_api.h" 17#include <condition_variable> 18#include <js_native_api_types.h> 19#include <multimedia/native_audio_channel_layout.h> 20#include <multimedia/player_framework/native_avcodec_audiocodec.h> 21#include <multimedia/player_framework/native_avcapability.h> 22#include <multimedia/player_framework/native_avcodec_base.h> 23#include <multimedia/player_framework/native_averrors.h> 24#include <multimedia/player_framework/native_avformat.h> 25#include <pthread.h> 26#include <queue> 27#include <iostream> 28#include <fstream> 29 30#define FAIL (-1) 31#define SUCCESS 0 32#define WIDTH 1920 33#define HEIGHT 1080 34#define FRAMERATETHIRTY 30 35constexpr uint32_t DEFAULT_SAMPLERATE = 44100; 36constexpr uint64_t DEFAULT_BITRATE = 32000; 37constexpr uint32_t DEFAULT_CHANNEL_COUNT = 2; 38constexpr uint32_t AUDIO_32BITS_PRE_SAMPLE = 3; 39constexpr uint32_t AUDIO_LEVEL_0 = 0; 40constexpr OH_AudioChannelLayout CHANNEL_LAYOUT = OH_AudioChannelLayout::CH_LAYOUT_STEREO; 41constexpr OH_BitsPerSample SAMPLE_FORMAT = OH_BitsPerSample::SAMPLE_F32LE; 42constexpr OH_BitsPerSample SAMPLE_FORMAT_S32 = OH_BitsPerSample::SAMPLE_S32LE; 43constexpr int32_t COMPLIANCE_LEVEL = 0; 44constexpr OH_BitsPerSample BITS_PER_CODED_SAMPLE = OH_BitsPerSample::SAMPLE_S24LE; 45constexpr uint32_t DEFAULT_MAX_INPUT_SIZE = 1024*DEFAULT_CHANNEL_COUNT *sizeof(float); 46using namespace std; 47 48static napi_value AudioEncoderCreateByMime(napi_env env, napi_callback_info info) 49{ 50 int backParam = FAIL; 51 OH_AVCodec *checkParam = nullptr; 52 checkParam = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 53 if (checkParam != nullptr) { 54 backParam = SUCCESS; 55 } 56 napi_value result = nullptr; 57 napi_create_int32(env, backParam, &result); 58 return result; 59} 60 61static napi_value AudioEncoderCreateByName(napi_env env, napi_callback_info info) 62{ 63 int backParam = FAIL; 64 OH_AVCodec *checkParam = nullptr; 65 OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_FLAC, true); 66 const char *name = OH_AVCapability_GetName(capability); 67 checkParam = OH_AudioCodec_CreateByName(name); 68 if (checkParam != nullptr) { 69 backParam = SUCCESS; 70 } 71 napi_value result = nullptr; 72 napi_create_int32(env, backParam, &result); 73 return result; 74} 75 76static napi_value AudioEncoderDestroy(napi_env env, napi_callback_info info) 77{ 78 int backParam = FAIL; 79 napi_value result = nullptr; 80 OH_AVCodec *audioEnc = nullptr; 81 OH_AVErrCode checkParam; 82 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 83 checkParam = OH_AudioCodec_Destroy(audioEnc); 84 if (checkParam == AV_ERR_OK) { 85 backParam = SUCCESS; 86 } 87 napi_create_int32(env, backParam, &result); 88 return result; 89} 90 91class AEncSignal { 92public: 93 mutex inMutex_; 94 mutex outMutex_; 95 mutex startMutex_; 96 condition_variable inCond_; 97 condition_variable outCond_; 98 condition_variable startCond_; 99 queue<uint32_t> inQueue_; 100 queue<uint32_t> outQueue_; 101 queue<OH_AVBuffer *> inBufferQueue_; 102 queue<OH_AVBuffer *> outBufferQueue_; 103}; 104AEncSignal *signal_ = new AEncSignal(); 105static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData) 106{ 107 (void)codec; 108 (void)errorCode; 109 (void)userData; 110} 111static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData) 112{ 113 (void)codec; 114 (void)format; 115 (void)userData; 116} 117static void OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) 118{ 119 (void)codec; 120 AEncSignal *signal = static_cast<AEncSignal *>(userData); 121 unique_lock<mutex> lock(signal->inMutex_); 122 signal->inQueue_.push(index); 123 signal->inBufferQueue_.push(buffer); 124 signal->inCond_.notify_all(); 125} 126static void OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) 127{ 128 (void)codec; 129 AEncSignal *signal = static_cast<AEncSignal *>(userData); 130 unique_lock<mutex> lock(signal->outMutex_); 131 signal->outQueue_.push(index); 132 signal->outBufferQueue_.push(buffer); 133} 134 135static napi_value AudioEncoderRegisterCallback(napi_env env, napi_callback_info info) 136{ 137 int backParam = FAIL; 138 napi_value result = nullptr; 139 OH_AVCodec *audioEnc = nullptr; 140 OH_AVErrCode checkParam; 141 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 142 signal_ = new AEncSignal(); 143 OH_AVCodecCallback callback = {&OnError, &OnStreamChanged, &OnNeedInputBuffer, &OnNewOutputBuffer}; 144 checkParam = OH_AudioCodec_RegisterCallback(audioEnc, callback, signal_); 145 if (checkParam == AV_ERR_OK) { 146 backParam = SUCCESS; 147 } 148 OH_AudioCodec_Destroy(audioEnc); 149 napi_create_int32(env, backParam, &result); 150 return result; 151} 152 153static napi_value AudioEncoderConfigure(napi_env env, napi_callback_info info) 154{ 155 int backParam = FAIL; 156 napi_value result = nullptr; 157 OH_AVCodec *audioEnc = nullptr; 158 OH_AVErrCode checkParam; 159 OH_AVFormat *format = nullptr; 160 format = OH_AVFormat_Create(); 161 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 162 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 163 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 164 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, BITS_PER_CODED_SAMPLE); 165 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 166 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 167 OH_AVFormat_SetLongValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, COMPLIANCE_LEVEL); 168 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 169 checkParam = OH_AudioCodec_Configure(audioEnc, format); 170 if (checkParam == AV_ERR_OK) { 171 backParam = SUCCESS; 172 } 173 napi_create_int32(env, backParam, &result); 174 return result; 175} 176 177static napi_value AudioEncoderPrepare(napi_env env, napi_callback_info info) 178{ 179 int backParam = FAIL; 180 napi_value result = nullptr; 181 OH_AVCodec *audioEnc = nullptr; 182 OH_AVErrCode checkParam; 183 OH_AVFormat *format = nullptr; 184 format = OH_AVFormat_Create(); 185 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 186 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 187 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 188 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 189 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 190 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 191 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 192 OH_AudioCodec_Configure(audioEnc, format); 193 checkParam = OH_AudioCodec_Prepare(audioEnc); 194 if (checkParam == AV_ERR_OK) { 195 backParam = SUCCESS; 196 } 197 napi_create_int32(env, backParam, &result); 198 return result; 199} 200 201static napi_value AudioEncoderStart(napi_env env, napi_callback_info info) 202{ 203 int backParam = FAIL; 204 napi_value result = nullptr; 205 OH_AVCodec *audioEnc = nullptr; 206 OH_AVErrCode checkParam; 207 OH_AVFormat *format = nullptr; 208 format = OH_AVFormat_Create(); 209 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 210 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 211 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 212 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 213 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 214 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 215 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 216 OH_AudioCodec_Configure(audioEnc, format); 217 OH_AudioCodec_Prepare(audioEnc); 218 checkParam = OH_AudioCodec_Start(audioEnc); 219 if (checkParam == AV_ERR_OK) { 220 backParam = SUCCESS; 221 } 222 napi_create_int32(env, backParam, &result); 223 return result; 224} 225 226static napi_value AudioEncoderStop(napi_env env, napi_callback_info info) 227{ 228 int backParam = FAIL; 229 napi_value result = nullptr; 230 OH_AVCodec *audioEnc = nullptr; 231 OH_AVErrCode checkParam; 232 OH_AVFormat *format = nullptr; 233 format = OH_AVFormat_Create(); 234 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 235 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 236 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 237 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 238 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 239 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 240 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 241 OH_AudioCodec_Configure(audioEnc, format); 242 OH_AudioCodec_Prepare(audioEnc); 243 if (OH_AudioCodec_Start(audioEnc) == AV_ERR_OK) { 244 checkParam = OH_AudioCodec_Stop(audioEnc); 245 if(checkParam == AV_ERR_OK){ 246 backParam = SUCCESS; 247 } 248 } 249 napi_create_int32(env, backParam, &result); 250 return result; 251} 252 253static napi_value AudioEncoderFlush(napi_env env, napi_callback_info info) 254{ 255 int backParam = FAIL; 256 napi_value result = nullptr; 257 OH_AVCodec *audioEnc = nullptr; 258 OH_AVErrCode checkParam; 259 OH_AVFormat *format = nullptr; 260 format = OH_AVFormat_Create(); 261 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 262 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 263 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 264 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 265 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 266 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 267 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 268 OH_AudioCodec_Configure(audioEnc, format); 269 OH_AudioCodec_Prepare(audioEnc); 270 if (OH_AudioCodec_Start(audioEnc) == AV_ERR_OK) { 271 checkParam = OH_AudioCodec_Flush(audioEnc); 272 if(checkParam == AV_ERR_OK){ 273 backParam = SUCCESS; 274 OH_AudioCodec_Stop(audioEnc); 275 } 276 } 277 napi_create_int32(env, backParam, &result); 278 return result; 279} 280 281static napi_value AudioEncoderReset(napi_env env, napi_callback_info info) 282{ 283 int backParam = FAIL; 284 napi_value result = nullptr; 285 OH_AVCodec *audioEnc = nullptr; 286 OH_AVErrCode checkParam; 287 OH_AVFormat *format = nullptr; 288 format = OH_AVFormat_Create(); 289 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 290 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 291 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 292 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 293 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 294 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 295 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 296 OH_AudioCodec_Configure(audioEnc, format); 297 OH_AudioCodec_Prepare(audioEnc); 298 if (OH_AudioCodec_Start(audioEnc) == AV_ERR_OK) { 299 checkParam = OH_AudioCodec_Reset(audioEnc); 300 if(checkParam == AV_ERR_OK){ 301 backParam = SUCCESS; 302 } 303 } 304 napi_create_int32(env, backParam, &result); 305 return result; 306} 307 308static napi_value AudioEncoderGetOutputDescription(napi_env env, napi_callback_info info) 309{ 310 int backParam = FAIL; 311 napi_value result = nullptr; 312 OH_AVCodec *audioEnc = nullptr; 313 OH_AVFormat *checkParam = nullptr; 314 OH_AVFormat *format = nullptr; 315 format = OH_AVFormat_Create(); 316 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 317 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 318 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 319 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 320 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 321 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 322 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 323 OH_AudioCodec_Configure(audioEnc, format); 324 OH_AudioCodec_Prepare(audioEnc); 325 if (OH_AudioCodec_Start(audioEnc) == AV_ERR_OK) { 326 checkParam = OH_AudioCodec_GetOutputDescription(audioEnc); 327 if(checkParam != nullptr){ 328 backParam = SUCCESS; 329 free(checkParam); 330 } 331 } 332 napi_create_int32(env, backParam, &result); 333 return result; 334} 335 336static napi_value AudioEncoderSetParameter(napi_env env, napi_callback_info info) 337{ 338 int backParam = FAIL; 339 napi_value result = nullptr; 340 OH_AVCodec *audioEnc = nullptr; 341 OH_AVErrCode checkParam; 342 OH_AVFormat *format = nullptr; 343 format = OH_AVFormat_Create(); 344 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 345 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 346 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 347 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT_S32); 348 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 349 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_COMPRESSION_LEVEL, AUDIO_LEVEL_0); 350 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, AUDIO_32BITS_PRE_SAMPLE); 351 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC, true); 352 OH_AudioCodec_Configure(audioEnc, format); 353 OH_AudioCodec_Prepare(audioEnc); 354 if (OH_AudioCodec_Start(audioEnc) == AV_ERR_OK) { 355 format = OH_AudioCodec_GetOutputDescription(audioEnc); 356 if(format != nullptr){ 357 checkParam = OH_AudioCodec_SetParameter(audioEnc, format); 358 if(checkParam == AV_ERR_OK){ 359 backParam = SUCCESS; 360 free(format); 361 } 362 } 363 } 364 napi_create_int32(env, backParam, &result); 365 return result; 366} 367 368static napi_value AudioEncoderIsValid(napi_env env, napi_callback_info info) 369{ 370 int backParam = FAIL; 371 napi_value result = nullptr; 372 OH_AVCodec *audioEnc = nullptr; 373 OH_AVErrCode checkParam; 374 bool status = true; 375 OH_AVFormat *format = nullptr; 376 format = OH_AVFormat_Create(); 377 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNEL_COUNT); 378 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLERATE); 379 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, DEFAULT_BITRATE); 380 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT); 381 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT); 382 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE); 383 audioEnc = OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true); 384 OH_AudioCodec_Configure(audioEnc, format); 385 OH_AudioCodec_Prepare(audioEnc); 386 if (OH_AudioCodec_Start(audioEnc) == AV_ERR_OK) { 387 checkParam = OH_AudioCodec_Flush(audioEnc); 388 if (checkParam == AV_ERR_OK) { 389 checkParam = OH_AudioCodec_IsValid(audioEnc, &status); 390 if (checkParam == AV_ERR_OK) { 391 backParam = SUCCESS; 392 OH_AudioCodec_Stop(audioEnc); 393 } 394 } 395 } 396 napi_create_int32(env, backParam, &result); 397 return result; 398} 399 400EXTERN_C_START 401static napi_value Init(napi_env env, napi_value exports) { 402 napi_property_descriptor desc[] = { 403 {"OH_AudioCodec_CreateByMime", nullptr, AudioEncoderCreateByMime, nullptr, nullptr, nullptr, napi_default, 404 nullptr}, 405 {"OH_AudioCodec_CreateByName", nullptr, AudioEncoderCreateByName, nullptr, nullptr, nullptr, napi_default, 406 nullptr}, 407 {"OH_AudioCodec_Destroy", nullptr, AudioEncoderDestroy, nullptr, nullptr, nullptr, napi_default, nullptr}, 408 {"OH_AudioCodec_RegisterCallback", nullptr, AudioEncoderRegisterCallback, nullptr, nullptr, nullptr, napi_default, 409 nullptr}, 410 {"OH_AudioCodec_Configure", nullptr, AudioEncoderConfigure, nullptr, nullptr, nullptr, napi_default, nullptr}, 411 {"OH_AudioCodec_Prepare", nullptr, AudioEncoderPrepare, nullptr, nullptr, nullptr, napi_default, nullptr}, 412 {"OH_AudioCodec_Start", nullptr, AudioEncoderStart, nullptr, nullptr, nullptr, napi_default, nullptr}, 413 {"OH_AudioCodec_Stop", nullptr, AudioEncoderStop, nullptr, nullptr, nullptr, napi_default, nullptr}, 414 {"OH_AudioCodec_Flush", nullptr, AudioEncoderFlush, nullptr, nullptr, nullptr, napi_default, nullptr}, 415 {"OH_AudioCodec_Reset", nullptr, AudioEncoderReset, nullptr, nullptr, nullptr, napi_default, nullptr}, 416 {"OH_AudioCodec_GetOutputDescription", nullptr, AudioEncoderGetOutputDescription, nullptr, nullptr, nullptr, 417 napi_default, nullptr}, 418 {"OH_AudioCodec_SetParameter", nullptr, AudioEncoderSetParameter, nullptr, nullptr, nullptr, napi_default, 419 nullptr}, 420 {"OH_AudioCodec_IsValid", nullptr, AudioEncoderIsValid, nullptr, nullptr, nullptr, napi_default, nullptr}, 421 }; 422 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); 423 return exports; 424} 425EXTERN_C_END 426 427static napi_module demoModule = { 428 .nm_version = 1, 429 .nm_flags = 0, 430 .nm_filename = nullptr, 431 .nm_register_func = Init, 432 .nm_modname = "libaudioEncoderAvBuffer", 433 .nm_priv = ((void *)0), 434 .reserved = {0}, 435}; 436 437extern "C" __attribute__((constructor)) void RegisterModule(void) { 438 napi_module_register(&demoModule); 439} 440