• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "napi/native_api.h"
17 #include <condition_variable>
18 #include <js_native_api_types.h>
19 #include <multimedia/player_framework/native_avcodec_videoencoder.h>
20 #include <multimedia/player_framework/native_avcapability.h>
21 #include <multimedia/player_framework/native_avcodec_base.h>
22 #include <multimedia/player_framework/native_avformat.h>
23 #include <pthread.h>
24 #include <iostream>
25 #include <fstream>
26 
27 #define FAIL (-1)
28 #define SUCCESS 0
29 #define PARAM_0 0
30 #define PARAM_1 1
31 #define PARAM_2 2
32 #define PARAM_3 3
33 #define PARAM_4 4
34 #define PARAM_5 5
35 #define PARAM_6 6
36 #define PARAM_7 7
37 using namespace std;
38 
39 constexpr uint32_t DEFAULT_WIDTH = 320;
40 
41 constexpr uint32_t DEFAULT_HEIGHT = 240;
42 
43 constexpr OH_AVPixelFormat DEFAULT_PIXELFORMAT = AV_PIXEL_FORMAT_YUVI420;
44 
OHVideoEncoderCreateByMime(napi_env env,napi_callback_info info)45 static napi_value OHVideoEncoderCreateByMime(napi_env env, napi_callback_info info)
46 {
47     int backParam = FAIL;
48     OH_AVCodec *checkParam = nullptr;
49     checkParam = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
50     if (checkParam != nullptr) {
51         backParam = SUCCESS;
52     }
53     napi_value result = nullptr;
54     OH_VideoEncoder_Destroy(checkParam);
55     napi_create_int32(env, backParam, &result);
56     return result;
57 }
58 
OHVideoEncoderCreateByMimeHEVC(napi_env env,napi_callback_info info)59 static napi_value OHVideoEncoderCreateByMimeHEVC(napi_env env, napi_callback_info info)
60 {
61     int backParam = FAIL;
62     OH_AVCodec *checkParam = nullptr;
63     checkParam = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
64     if (checkParam != nullptr) {
65         backParam = SUCCESS;
66     }
67     napi_value result = nullptr;
68     OH_VideoEncoder_Destroy(checkParam);
69     napi_create_int32(env, backParam, &result);
70     return result;
71 }
72 
OHVideoEncoderCreateByMimeAbnormal(napi_env env,napi_callback_info info)73 static napi_value OHVideoEncoderCreateByMimeAbnormal(napi_env env, napi_callback_info info)
74 {
75     int backParam = FAIL;
76     OH_AVCodec *checkParam = nullptr;
77     checkParam = OH_VideoEncoder_CreateByMime(nullptr);
78     if (checkParam == nullptr) {
79         backParam = SUCCESS;
80     }
81     napi_value result = nullptr;
82     napi_create_int32(env, backParam, &result);
83     return result;
84 }
85 
OHVideoEncoderCreateByName(napi_env env,napi_callback_info info)86 static napi_value OHVideoEncoderCreateByName(napi_env env, napi_callback_info info)
87 {
88     int backParam = FAIL;
89     OH_AVCodec *checkParam = nullptr;
90     OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true);
91     const char *codecName = OH_AVCapability_GetName(capability);
92     checkParam = OH_VideoEncoder_CreateByName(codecName);
93     if (checkParam != nullptr) {
94         backParam = SUCCESS;
95     }
96     napi_value result = nullptr;
97     OH_VideoEncoder_Destroy(checkParam);
98     napi_create_int32(env, backParam, &result);
99     return result;
100 }
101 
OHVideoEncoderCreateByNameHEVC(napi_env env,napi_callback_info info)102 static napi_value OHVideoEncoderCreateByNameHEVC(napi_env env, napi_callback_info info)
103 {
104     int backParam = FAIL;
105     OH_AVCodec *checkParam = nullptr;
106     OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, true);
107     const char *codecName = OH_AVCapability_GetName(capability);
108     checkParam = OH_VideoEncoder_CreateByName(codecName);
109     if (checkParam != nullptr) {
110         backParam = SUCCESS;
111     }
112     napi_value result = nullptr;
113     OH_VideoEncoder_Destroy(checkParam);
114     napi_create_int32(env, backParam, &result);
115     return result;
116 }
117 
OHVideoEncoderCreateByNameAbnormal(napi_env env,napi_callback_info info)118 static napi_value OHVideoEncoderCreateByNameAbnormal(napi_env env, napi_callback_info info)
119 {
120     int backParam = FAIL;
121     OH_AVCodec *checkParam = nullptr;
122     OH_AVCapability *capability = OH_AVCodec_GetCapability(nullptr, true);
123     const char *codecName = OH_AVCapability_GetName(capability);
124     checkParam = OH_VideoEncoder_CreateByName(codecName);
125     if (checkParam == nullptr) {
126         backParam = SUCCESS;
127     }
128     napi_value result = nullptr;
129     napi_create_int32(env, backParam, &result);
130     return result;
131 }
132 
OHVideoEncoderDestroy(napi_env env,napi_callback_info info)133 static napi_value OHVideoEncoderDestroy(napi_env env, napi_callback_info info)
134 {
135     int backParam = FAIL;
136     napi_value result = nullptr;
137     OH_AVCodec *videoEnc = nullptr;
138     OH_AVErrCode checkParam;
139     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
140     checkParam = OH_VideoEncoder_Destroy(videoEnc);
141     if (checkParam == AV_ERR_OK) {
142         backParam = SUCCESS;
143     }
144     videoEnc = nullptr;
145     napi_create_int32(env, backParam, &result);
146     return result;
147 }
148 
OHVideoEncoderDestroyHEVC(napi_env env,napi_callback_info info)149 static napi_value OHVideoEncoderDestroyHEVC(napi_env env, napi_callback_info info)
150 {
151     int backParam = FAIL;
152     napi_value result = nullptr;
153     OH_AVCodec *videoEnc = nullptr;
154     OH_AVErrCode checkParam;
155     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
156     checkParam = OH_VideoEncoder_Destroy(videoEnc);
157     if (checkParam == AV_ERR_OK) {
158         backParam = SUCCESS;
159     }
160     videoEnc = nullptr;
161     napi_create_int32(env, backParam, &result);
162     return result;
163 }
164 
OHVideoEncoderDestroyAbnormal(napi_env env,napi_callback_info info)165 static napi_value OHVideoEncoderDestroyAbnormal(napi_env env, napi_callback_info info)
166 {
167     int backParam = FAIL;
168     napi_value result = nullptr;
169     OH_AVCodec *videoEnc = nullptr;
170     OH_AVErrCode checkParam;
171     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
172     checkParam = OH_VideoEncoder_Destroy(videoEnc);
173     if (checkParam != AV_ERR_OK) {
174         backParam = SUCCESS;
175     }
176     videoEnc = nullptr;
177     napi_create_int32(env, backParam, &result);
178     return result;
179 }
180 
OnError(OH_AVCodec * codec,int32_t errorCode,void * userData)181 static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
182 {
183     (void)codec;
184     (void)errorCode;
185     (void)userData;
186 }
187 
OnStreamChanged(OH_AVCodec * codec,OH_AVFormat * format,void * userData)188 static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
189 {
190     (void)codec;
191     (void)format;
192     (void)userData;
193 }
194 
OnNeedInputData(OH_AVCodec * codec,uint32_t index,OH_AVMemory * mem,void * userData)195 static void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *mem, void *userData)
196 {
197     (void)userData;
198 }
199 
OnNeedOutputData(OH_AVCodec * codec,uint32_t index,OH_AVMemory * mem,OH_AVCodecBufferAttr * attr,void * userData)200 static void OnNeedOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *mem, OH_AVCodecBufferAttr *attr,
201     void *userData)
202 {
203     (void)userData;
204 }
205 
OnNeedInputBuffer(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * buffer,void * userData)206 static void OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData)
207 {
208     (void)userData;
209 }
210 
OnNeedOutputBuffer(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * buffer,void * userData)211 static void OnNeedOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData)
212 {
213     (void)userData;
214 }
215 
OHVideoEncoderSetCallback(napi_env env,napi_callback_info info)216 static napi_value OHVideoEncoderSetCallback(napi_env env, napi_callback_info info)
217 {
218     int backParam = FAIL;
219     napi_value result = nullptr;
220     OH_AVCodec *videoEnc = nullptr;
221     OH_AVErrCode checkParam;
222     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
223     OH_AVCodecAsyncCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputData, &OnNeedOutputData };
224     checkParam = OH_VideoEncoder_SetCallback(videoEnc, callback, nullptr);
225     if (checkParam == AV_ERR_OK) {
226         backParam = SUCCESS;
227     }
228     OH_VideoEncoder_Destroy(videoEnc);
229     napi_create_int32(env, backParam, &result);
230     return result;
231 }
232 
OHVideoEncoderSetCallbackHEVC(napi_env env,napi_callback_info info)233 static napi_value OHVideoEncoderSetCallbackHEVC(napi_env env, napi_callback_info info)
234 {
235     int backParam = FAIL;
236     napi_value result = nullptr;
237     OH_AVCodec *videoEnc = nullptr;
238     OH_AVErrCode checkParam;
239     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
240     OH_AVCodecAsyncCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputData, &OnNeedOutputData };
241     checkParam = OH_VideoEncoder_SetCallback(videoEnc, callback, nullptr);
242     if (checkParam == AV_ERR_OK) {
243         backParam = SUCCESS;
244     }
245     OH_VideoEncoder_Destroy(videoEnc);
246     napi_create_int32(env, backParam, &result);
247     return result;
248 }
249 
OHVideoEncoderSetCallbackAbnormal(napi_env env,napi_callback_info info)250 static napi_value OHVideoEncoderSetCallbackAbnormal(napi_env env, napi_callback_info info)
251 {
252     int backParam = FAIL;
253     napi_value result = nullptr;
254     OH_AVCodec *videoEnc = nullptr;
255     OH_AVErrCode checkParam;
256     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
257     OH_AVCodecAsyncCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputData, &OnNeedOutputData };
258     checkParam = OH_VideoEncoder_SetCallback(videoEnc, callback, nullptr);
259     if (checkParam != AV_ERR_OK) {
260         backParam = SUCCESS;
261     }
262     OH_VideoEncoder_Destroy(videoEnc);
263     napi_create_int32(env, backParam, &result);
264     return result;
265 }
266 
OHVideoEncoderRegisterCallback(napi_env env,napi_callback_info info)267 static napi_value OHVideoEncoderRegisterCallback(napi_env env, napi_callback_info info)
268 {
269     int backParam = FAIL;
270     napi_value result = nullptr;
271     OH_AVCodec *videoEnc = nullptr;
272     OH_AVErrCode checkParam;
273     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
274     OH_AVCodecCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputBuffer, &OnNeedOutputBuffer };
275     checkParam = OH_VideoEncoder_RegisterCallback(videoEnc, callback, nullptr);
276     if (checkParam == AV_ERR_OK) {
277         backParam = SUCCESS;
278     }
279     OH_VideoEncoder_Destroy(videoEnc);
280     napi_create_int32(env, backParam, &result);
281     return result;
282 }
283 
OHVideoEncoderRegisterCallbackHEVC(napi_env env,napi_callback_info info)284 static napi_value OHVideoEncoderRegisterCallbackHEVC(napi_env env, napi_callback_info info)
285 {
286     int backParam = FAIL;
287     napi_value result = nullptr;
288     OH_AVCodec *videoEnc = nullptr;
289     OH_AVErrCode checkParam;
290     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
291     OH_AVCodecCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputBuffer, &OnNeedOutputBuffer };
292     checkParam = OH_VideoEncoder_RegisterCallback(videoEnc, callback, nullptr);
293     if (checkParam == AV_ERR_OK) {
294         backParam = SUCCESS;
295     }
296     OH_VideoEncoder_Destroy(videoEnc);
297     napi_create_int32(env, backParam, &result);
298     return result;
299 }
300 
OHVideoEncoderRegisterCallbackAbnormal(napi_env env,napi_callback_info info)301 static napi_value OHVideoEncoderRegisterCallbackAbnormal(napi_env env, napi_callback_info info)
302 {
303     int backParam = FAIL;
304     napi_value result = nullptr;
305     OH_AVCodec *videoEnc = nullptr;
306     OH_AVErrCode checkParam;
307     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
308     OH_AVCodecCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputBuffer, &OnNeedOutputBuffer };
309     checkParam = OH_VideoEncoder_RegisterCallback(videoEnc, callback, nullptr);
310     if (checkParam != AV_ERR_OK) {
311         backParam = SUCCESS;
312     }
313     OH_VideoEncoder_Destroy(videoEnc);
314     napi_create_int32(env, backParam, &result);
315     return result;
316 }
317 
OHVideoEncoderConfigure(napi_env env,napi_callback_info info)318 static napi_value OHVideoEncoderConfigure(napi_env env, napi_callback_info info)
319 {
320     int backParam = FAIL;
321     napi_value result = nullptr;
322     OH_AVCodec *videoEnc = nullptr;
323     OH_AVErrCode checkParam;
324     OH_AVFormat *format = nullptr;
325     format = OH_AVFormat_Create();
326     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
327     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
328     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
329     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
330     checkParam = OH_VideoEncoder_Configure(videoEnc, format);
331     if (checkParam == AV_ERR_OK) {
332         backParam = SUCCESS;
333     }
334     OH_VideoEncoder_Destroy(videoEnc);
335     napi_create_int32(env, backParam, &result);
336     return result;
337 }
338 
OHVideoEncoderConfigureHEVC(napi_env env,napi_callback_info info)339 static napi_value OHVideoEncoderConfigureHEVC(napi_env env, napi_callback_info info)
340 {
341     int backParam = FAIL;
342     napi_value result = nullptr;
343     OH_AVCodec *videoEnc = nullptr;
344     OH_AVErrCode checkParam;
345     OH_AVFormat *format = nullptr;
346     format = OH_AVFormat_Create();
347     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
348     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
349     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
350     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
351     checkParam = OH_VideoEncoder_Configure(videoEnc, format);
352     if (checkParam == AV_ERR_OK) {
353         backParam = SUCCESS;
354     }
355     OH_VideoEncoder_Destroy(videoEnc);
356     napi_create_int32(env, backParam, &result);
357     return result;
358 }
359 
OHVideoEncoderConfigureAbnormal1(napi_env env,napi_callback_info info)360 static napi_value OHVideoEncoderConfigureAbnormal1(napi_env env, napi_callback_info info)
361 {
362     int backParam = FAIL;
363     napi_value result = nullptr;
364     OH_AVCodec *videoEnc = nullptr;
365     OH_AVErrCode checkParam;
366     OH_AVFormat *format = nullptr;
367     format = OH_AVFormat_Create();
368     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
369     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
370     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
371     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
372     checkParam = OH_VideoEncoder_Configure(videoEnc, nullptr);
373     if (checkParam != AV_ERR_OK) {
374         backParam = SUCCESS;
375     }
376     OH_VideoEncoder_Destroy(videoEnc);
377     napi_create_int32(env, backParam, &result);
378     return result;
379 }
380 
OHVideoEncoderConfigureAbnormal2(napi_env env,napi_callback_info info)381 static napi_value OHVideoEncoderConfigureAbnormal2(napi_env env, napi_callback_info info)
382 {
383     int backParam = FAIL;
384     napi_value result = nullptr;
385     OH_AVCodec *videoEnc = nullptr;
386     OH_AVErrCode checkParam;
387     OH_AVFormat *format = nullptr;
388     format = OH_AVFormat_Create();
389     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
390     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
391     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
392     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
393     checkParam = OH_VideoEncoder_Configure(nullptr, format);
394     if (checkParam != AV_ERR_OK) {
395         backParam = SUCCESS;
396     }
397     OH_VideoEncoder_Destroy(videoEnc);
398     napi_create_int32(env, backParam, &result);
399     return result;
400 }
401 
OHVideoEncoderConfigureAbnormal3(napi_env env,napi_callback_info info)402 static napi_value OHVideoEncoderConfigureAbnormal3(napi_env env, napi_callback_info info)
403 {
404     int backParam = FAIL;
405     napi_value result = nullptr;
406     OH_AVCodec *videoEnc = nullptr;
407     OH_AVErrCode checkParam;
408     OH_AVFormat *format = nullptr;
409     format = OH_AVFormat_Create();
410     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
411     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
412     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
413     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
414     checkParam = OH_VideoEncoder_Configure(nullptr, nullptr);
415     if (checkParam != AV_ERR_OK) {
416         backParam = SUCCESS;
417     }
418     OH_VideoEncoder_Destroy(videoEnc);
419     napi_create_int32(env, backParam, &result);
420     return result;
421 }
422 
OHVideoEncoderConfigureAbnormal4(napi_env env,napi_callback_info info)423 static napi_value OHVideoEncoderConfigureAbnormal4(napi_env env, napi_callback_info info)
424 {
425     int backParam = FAIL;
426     napi_value result = nullptr;
427     OH_AVCodec *videoEnc = nullptr;
428     OH_AVErrCode checkParam;
429     OH_AVFormat *format = nullptr;
430     format = OH_AVFormat_Create();
431     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
432     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
433     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
434     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
435     checkParam = OH_VideoEncoder_Configure(videoEnc, format);
436     if (checkParam != AV_ERR_OK) {
437         backParam = SUCCESS;
438     }
439     OH_VideoEncoder_Destroy(videoEnc);
440     napi_create_int32(env, backParam, &result);
441     return result;
442 }
443 
OHVideoEncoderConfigureAbnormal5(napi_env env,napi_callback_info info)444 static napi_value OHVideoEncoderConfigureAbnormal5(napi_env env, napi_callback_info info)
445 {
446     int backParam = FAIL;
447     napi_value result = nullptr;
448     OH_AVCodec *videoEnc = nullptr;
449     OH_AVErrCode checkParam;
450     OH_AVFormat *format = nullptr;
451     format = OH_AVFormat_Create();
452     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
453     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
454     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
455     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
456     checkParam = OH_VideoEncoder_Configure(videoEnc, nullptr);
457     if (checkParam != AV_ERR_OK) {
458         backParam = SUCCESS;
459     }
460     OH_VideoEncoder_Destroy(videoEnc);
461     napi_create_int32(env, backParam, &result);
462     return result;
463 }
464 
OHVideoEncoderConfigureAbnormal6(napi_env env,napi_callback_info info)465 static napi_value OHVideoEncoderConfigureAbnormal6(napi_env env, napi_callback_info info)
466 {
467     int backParam = FAIL;
468     napi_value result = nullptr;
469     OH_AVCodec *videoEnc = nullptr;
470     OH_AVErrCode checkParam;
471     OH_AVFormat *format = nullptr;
472     format = OH_AVFormat_Create();
473     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
474     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
475     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
476     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
477     checkParam = OH_VideoEncoder_Configure(nullptr, format);
478     if (checkParam != AV_ERR_OK) {
479         backParam = SUCCESS;
480     }
481     OH_VideoEncoder_Destroy(videoEnc);
482     napi_create_int32(env, backParam, &result);
483     return result;
484 }
485 
OHVideoEncoderConfigureAbnormal7(napi_env env,napi_callback_info info)486 static napi_value OHVideoEncoderConfigureAbnormal7(napi_env env, napi_callback_info info)
487 {
488     int backParam = FAIL;
489     napi_value result = nullptr;
490     OH_AVCodec *videoEnc = nullptr;
491     OH_AVErrCode checkParam;
492     OH_AVFormat *format = nullptr;
493     format = OH_AVFormat_Create();
494     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
495     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
496     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
497     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
498     checkParam = OH_VideoEncoder_Configure(nullptr, nullptr);
499     if (checkParam != AV_ERR_OK) {
500         backParam = SUCCESS;
501     }
502     OH_VideoEncoder_Destroy(videoEnc);
503     napi_create_int32(env, backParam, &result);
504     return result;
505 }
506 
OHVideoEncoderPrepare(napi_env env,napi_callback_info info)507 static napi_value OHVideoEncoderPrepare(napi_env env, napi_callback_info info)
508 {
509     int backParam = FAIL;
510     napi_value result = nullptr;
511     OH_AVCodec *videoEnc = nullptr;
512     OH_AVErrCode checkParam;
513     OH_AVFormat *format = nullptr;
514     format = OH_AVFormat_Create();
515     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
516     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
517     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
518     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
519     OH_VideoEncoder_Configure(videoEnc, format);
520     checkParam = OH_VideoEncoder_Prepare(videoEnc);
521     if (checkParam == AV_ERR_OK) {
522         backParam = SUCCESS;
523     }
524     OH_VideoEncoder_Destroy(videoEnc);
525     napi_create_int32(env, backParam, &result);
526     return result;
527 }
528 
OHVideoEncoderPrepareHEVC(napi_env env,napi_callback_info info)529 static napi_value OHVideoEncoderPrepareHEVC(napi_env env, napi_callback_info info)
530 {
531     int backParam = FAIL;
532     napi_value result = nullptr;
533     OH_AVCodec *videoEnc = nullptr;
534     OH_AVErrCode checkParam;
535     OH_AVFormat *format = nullptr;
536     format = OH_AVFormat_Create();
537     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
538     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
539     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
540     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
541     OH_VideoEncoder_Configure(videoEnc, format);
542     checkParam = OH_VideoEncoder_Prepare(videoEnc);
543     if (checkParam == AV_ERR_OK) {
544         backParam = SUCCESS;
545     }
546     OH_VideoEncoder_Destroy(videoEnc);
547     napi_create_int32(env, backParam, &result);
548     return result;
549 }
550 
OHVideoEncoderPrepareAbnormal1(napi_env env,napi_callback_info info)551 static napi_value OHVideoEncoderPrepareAbnormal1(napi_env env, napi_callback_info info)
552 {
553     int backParam = FAIL;
554     napi_value result = nullptr;
555     OH_AVCodec *videoEnc = nullptr;
556     OH_AVErrCode checkParam;
557     OH_AVFormat *format = nullptr;
558     format = OH_AVFormat_Create();
559     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
560     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
561     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
562     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
563     OH_VideoEncoder_Configure(videoEnc, format);
564     checkParam = OH_VideoEncoder_Prepare(nullptr);
565     if (checkParam != AV_ERR_OK) {
566         backParam = SUCCESS;
567     }
568     OH_VideoEncoder_Destroy(videoEnc);
569     napi_create_int32(env, backParam, &result);
570     return result;
571 }
572 
OHVideoEncoderPrepareAbnormal2(napi_env env,napi_callback_info info)573 static napi_value OHVideoEncoderPrepareAbnormal2(napi_env env, napi_callback_info info)
574 {
575     int backParam = FAIL;
576     napi_value result = nullptr;
577     OH_AVCodec *videoEnc = nullptr;
578     OH_AVErrCode checkParam;
579     OH_AVFormat *format = nullptr;
580     format = OH_AVFormat_Create();
581     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
582     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
583     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
584     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
585     OH_VideoEncoder_Configure(videoEnc, nullptr);
586     checkParam = OH_VideoEncoder_Prepare(videoEnc);
587     if (checkParam != AV_ERR_OK) {
588         backParam = SUCCESS;
589     }
590     OH_VideoEncoder_Destroy(videoEnc);
591     napi_create_int32(env, backParam, &result);
592     return result;
593 }
594 
OHVideoEncoderPrepareAbnormal3(napi_env env,napi_callback_info info)595 static napi_value OHVideoEncoderPrepareAbnormal3(napi_env env, napi_callback_info info)
596 {
597     int backParam = FAIL;
598     napi_value result = nullptr;
599     OH_AVCodec *videoEnc = nullptr;
600     OH_AVErrCode checkParam;
601     OH_AVFormat *format = nullptr;
602     format = OH_AVFormat_Create();
603     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
604     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
605     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
606     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
607     OH_VideoEncoder_Configure(videoEnc, nullptr);
608     checkParam = OH_VideoEncoder_Prepare(nullptr);
609     if (checkParam != AV_ERR_OK) {
610         backParam = SUCCESS;
611     }
612     OH_VideoEncoder_Destroy(videoEnc);
613     napi_create_int32(env, backParam, &result);
614     return result;
615 }
616 
OHVideoEncoderPrepareAbnormal4(napi_env env,napi_callback_info info)617 static napi_value OHVideoEncoderPrepareAbnormal4(napi_env env, napi_callback_info info)
618 {
619     int backParam = FAIL;
620     napi_value result = nullptr;
621     OH_AVCodec *videoEnc = nullptr;
622     OH_AVErrCode checkParam;
623     OH_AVFormat *format = nullptr;
624     format = OH_AVFormat_Create();
625     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
626     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
627     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
628     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
629     OH_VideoEncoder_Configure(nullptr, format);
630     checkParam = OH_VideoEncoder_Prepare(videoEnc);
631     if (checkParam == AV_ERR_OK) {
632         backParam = SUCCESS;
633     }
634     OH_VideoEncoder_Destroy(videoEnc);
635     napi_create_int32(env, backParam, &result);
636     return result;
637 }
638 
OHVideoEncoderPrepareAbnormal5(napi_env env,napi_callback_info info)639 static napi_value OHVideoEncoderPrepareAbnormal5(napi_env env, napi_callback_info info)
640 {
641     int backParam = FAIL;
642     napi_value result = nullptr;
643     OH_AVCodec *videoEnc = nullptr;
644     OH_AVErrCode checkParam;
645     OH_AVFormat *format = nullptr;
646     format = OH_AVFormat_Create();
647     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
648     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
649     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
650     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
651     OH_VideoEncoder_Configure(nullptr, format);
652     checkParam = OH_VideoEncoder_Prepare(nullptr);
653     if (checkParam != AV_ERR_OK) {
654         backParam = SUCCESS;
655     }
656     OH_VideoEncoder_Destroy(videoEnc);
657     napi_create_int32(env, backParam, &result);
658     return result;
659 }
660 
OHVideoEncoderPrepareAbnormal6(napi_env env,napi_callback_info info)661 static napi_value OHVideoEncoderPrepareAbnormal6(napi_env env, napi_callback_info info)
662 {
663     int backParam = FAIL;
664     napi_value result = nullptr;
665     OH_AVCodec *videoEnc = nullptr;
666     OH_AVErrCode checkParam;
667     OH_AVFormat *format = nullptr;
668     format = OH_AVFormat_Create();
669     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
670     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
671     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
672     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
673     OH_VideoEncoder_Configure(nullptr, nullptr);
674     checkParam = OH_VideoEncoder_Prepare(videoEnc);
675     if (checkParam == AV_ERR_OK) {
676         backParam = SUCCESS;
677     }
678     OH_VideoEncoder_Destroy(videoEnc);
679     napi_create_int32(env, backParam, &result);
680     return result;
681 }
682 
OHVideoEncoderPrepareAbnormal7(napi_env env,napi_callback_info info)683 static napi_value OHVideoEncoderPrepareAbnormal7(napi_env env, napi_callback_info info)
684 {
685     int backParam = FAIL;
686     napi_value result = nullptr;
687     OH_AVCodec *videoEnc = nullptr;
688     OH_AVErrCode checkParam;
689     OH_AVFormat *format = nullptr;
690     format = OH_AVFormat_Create();
691     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
692     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
693     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
694     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
695     OH_VideoEncoder_Configure(nullptr, nullptr);
696     checkParam = OH_VideoEncoder_Prepare(nullptr);
697     if (checkParam != AV_ERR_OK) {
698         backParam = SUCCESS;
699     }
700     OH_VideoEncoder_Destroy(videoEnc);
701     napi_create_int32(env, backParam, &result);
702     return result;
703 }
704 
OHVideoEncoderPrepareAbnormal8(napi_env env,napi_callback_info info)705 static napi_value OHVideoEncoderPrepareAbnormal8(napi_env env, napi_callback_info info)
706 {
707     int backParam = FAIL;
708     napi_value result = nullptr;
709     OH_AVCodec *videoEnc = nullptr;
710     OH_AVErrCode checkParam;
711     OH_AVFormat *format = nullptr;
712     format = OH_AVFormat_Create();
713     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
714     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
715     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
716     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
717     OH_VideoEncoder_Configure(videoEnc, format);
718     checkParam = OH_VideoEncoder_Prepare(videoEnc);
719     if (checkParam != AV_ERR_OK) {
720         backParam = SUCCESS;
721     }
722     OH_VideoEncoder_Destroy(videoEnc);
723     napi_create_int32(env, backParam, &result);
724     return result;
725 }
726 
OHVideoEncoderPrepareAbnormal9(napi_env env,napi_callback_info info)727 static napi_value OHVideoEncoderPrepareAbnormal9(napi_env env, napi_callback_info info)
728 {
729     int backParam = FAIL;
730     napi_value result = nullptr;
731     OH_AVCodec *videoEnc = nullptr;
732     OH_AVErrCode checkParam;
733     OH_AVFormat *format = nullptr;
734     format = OH_AVFormat_Create();
735     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
736     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
737     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
738     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
739     OH_VideoEncoder_Configure(videoEnc, format);
740     checkParam = OH_VideoEncoder_Prepare(nullptr);
741     if (checkParam != AV_ERR_OK) {
742         backParam = SUCCESS;
743     }
744     OH_VideoEncoder_Destroy(videoEnc);
745     napi_create_int32(env, backParam, &result);
746     return result;
747 }
748 
OHVideoEncoderPrepareAbnormal10(napi_env env,napi_callback_info info)749 static napi_value OHVideoEncoderPrepareAbnormal10(napi_env env, napi_callback_info info)
750 {
751     int backParam = FAIL;
752     napi_value result = nullptr;
753     OH_AVCodec *videoEnc = nullptr;
754     OH_AVErrCode checkParam;
755     OH_AVFormat *format = nullptr;
756     format = OH_AVFormat_Create();
757     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
758     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
759     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
760     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
761     OH_VideoEncoder_Configure(videoEnc, nullptr);
762     checkParam = OH_VideoEncoder_Prepare(videoEnc);
763     if (checkParam != AV_ERR_OK) {
764         backParam = SUCCESS;
765     }
766     OH_VideoEncoder_Destroy(videoEnc);
767     napi_create_int32(env, backParam, &result);
768     return result;
769 }
770 
OHVideoEncoderPrepareAbnormal11(napi_env env,napi_callback_info info)771 static napi_value OHVideoEncoderPrepareAbnormal11(napi_env env, napi_callback_info info)
772 {
773     int backParam = FAIL;
774     napi_value result = nullptr;
775     OH_AVCodec *videoEnc = nullptr;
776     OH_AVErrCode checkParam;
777     OH_AVFormat *format = nullptr;
778     format = OH_AVFormat_Create();
779     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
780     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
781     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
782     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
783     OH_VideoEncoder_Configure(videoEnc, nullptr);
784     checkParam = OH_VideoEncoder_Prepare(nullptr);
785     if (checkParam != AV_ERR_OK) {
786         backParam = SUCCESS;
787     }
788     OH_VideoEncoder_Destroy(videoEnc);
789     napi_create_int32(env, backParam, &result);
790     return result;
791 }
792 
OHVideoEncoderPrepareAbnormal12(napi_env env,napi_callback_info info)793 static napi_value OHVideoEncoderPrepareAbnormal12(napi_env env, napi_callback_info info)
794 {
795     int backParam = FAIL;
796     napi_value result = nullptr;
797     OH_AVCodec *videoEnc = nullptr;
798     OH_AVErrCode checkParam;
799     OH_AVFormat *format = nullptr;
800     format = OH_AVFormat_Create();
801     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
802     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
803     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
804     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
805     OH_VideoEncoder_Configure(nullptr, format);
806     checkParam = OH_VideoEncoder_Prepare(videoEnc);
807     if (checkParam != AV_ERR_OK) {
808         backParam = SUCCESS;
809     }
810     OH_VideoEncoder_Destroy(videoEnc);
811     napi_create_int32(env, backParam, &result);
812     return result;
813 }
814 
OHVideoEncoderPrepareAbnormal13(napi_env env,napi_callback_info info)815 static napi_value OHVideoEncoderPrepareAbnormal13(napi_env env, napi_callback_info info)
816 {
817     int backParam = FAIL;
818     napi_value result = nullptr;
819     OH_AVCodec *videoEnc = nullptr;
820     OH_AVErrCode checkParam;
821     OH_AVFormat *format = nullptr;
822     format = OH_AVFormat_Create();
823     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
824     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
825     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
826     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
827     OH_VideoEncoder_Configure(nullptr, format);
828     checkParam = OH_VideoEncoder_Prepare(nullptr);
829     if (checkParam != AV_ERR_OK) {
830         backParam = SUCCESS;
831     }
832     OH_VideoEncoder_Destroy(videoEnc);
833     napi_create_int32(env, backParam, &result);
834     return result;
835 }
836 
OHVideoEncoderPrepareAbnormal14(napi_env env,napi_callback_info info)837 static napi_value OHVideoEncoderPrepareAbnormal14(napi_env env, napi_callback_info info)
838 {
839     int backParam = FAIL;
840     napi_value result = nullptr;
841     OH_AVCodec *videoEnc = nullptr;
842     OH_AVErrCode checkParam;
843     OH_AVFormat *format = nullptr;
844     format = OH_AVFormat_Create();
845     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
846     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
847     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
848     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
849     OH_VideoEncoder_Configure(nullptr, nullptr);
850     checkParam = OH_VideoEncoder_Prepare(videoEnc);
851     if (checkParam != AV_ERR_OK) {
852         backParam = SUCCESS;
853     }
854     OH_VideoEncoder_Destroy(videoEnc);
855     napi_create_int32(env, backParam, &result);
856     return result;
857 }
858 
OHVideoEncoderPrepareAbnormal15(napi_env env,napi_callback_info info)859 static napi_value OHVideoEncoderPrepareAbnormal15(napi_env env, napi_callback_info info)
860 {
861     int backParam = FAIL;
862     napi_value result = nullptr;
863     OH_AVCodec *videoEnc = nullptr;
864     OH_AVErrCode checkParam;
865     OH_AVFormat *format = nullptr;
866     format = OH_AVFormat_Create();
867     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
868     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
869     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
870     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
871     OH_VideoEncoder_Configure(nullptr, nullptr);
872     checkParam = OH_VideoEncoder_Prepare(nullptr);
873     if (checkParam != AV_ERR_OK) {
874         backParam = SUCCESS;
875     }
876     OH_VideoEncoder_Destroy(videoEnc);
877     napi_create_int32(env, backParam, &result);
878     return result;
879 }
880 
OHVideoEncoderStart(napi_env env,napi_callback_info info)881 static napi_value OHVideoEncoderStart(napi_env env, napi_callback_info info)
882 {
883     size_t argc = PARAM_6;
884     napi_value args[PARAM_6] = {nullptr};
885     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
886     int firstParam;
887     int secondParam;
888     int thirdParam;
889     int fourthParam;
890     int fifthParam;
891     int sixthParam;
892     const char *mimeType = nullptr;
893     napi_get_value_int32(env, args[PARAM_0], &firstParam);
894     napi_get_value_int32(env, args[PARAM_1], &secondParam);
895     napi_get_value_int32(env, args[PARAM_2], &thirdParam);
896     napi_get_value_int32(env, args[PARAM_3], &fourthParam);
897     napi_get_value_int32(env, args[PARAM_4], &fifthParam);
898     napi_get_value_int32(env, args[PARAM_5], &sixthParam);
899 
900     int backParam = FAIL;
901     napi_value result = nullptr;
902     OH_AVCodec *videoEnc = nullptr;
903     OH_AVErrCode checkParam;
904     OH_AVFormat *format = nullptr;
905 
906     if (firstParam == PARAM_1) {
907         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC;
908     } else if (firstParam == PARAM_0) {
909         mimeType = nullptr;
910     } else if (firstParam == PARAM_2) {
911         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
912     }
913 
914     if (secondParam == PARAM_1) {
915         videoEnc = OH_VideoEncoder_CreateByMime(mimeType);
916     } else if (secondParam == PARAM_0) {
917         videoEnc = nullptr;
918     }
919 
920     if (thirdParam == PARAM_1) {
921         format = OH_AVFormat_Create();
922         OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
923         OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
924         OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
925     }
926 
927     OH_VideoEncoder_Configure(videoEnc, format);
928 
929     if (fourthParam == PARAM_1) {
930         OH_VideoEncoder_Prepare(videoEnc);
931     } else if (fourthParam == PARAM_0) {
932         OH_VideoEncoder_Prepare(nullptr);
933     }
934 
935     if (fifthParam == PARAM_1) {
936         checkParam = OH_VideoEncoder_Start(videoEnc);
937     } else if (fifthParam == PARAM_0) {
938         checkParam = OH_VideoEncoder_Start(nullptr);
939     }
940 
941     if (sixthParam == PARAM_1) {
942         if (checkParam == AV_ERR_OK) {
943             backParam = SUCCESS;
944         }
945     } else if (sixthParam == PARAM_0) {
946         if (checkParam != AV_ERR_OK) {
947             backParam = SUCCESS;
948         }
949     }
950 
951     OH_VideoEncoder_Destroy(videoEnc);
952     napi_create_int32(env, backParam, &result);
953     return result;
954 }
955 
OHVideoEncoderStop(napi_env env,napi_callback_info info)956 static napi_value OHVideoEncoderStop(napi_env env, napi_callback_info info)
957 {
958     size_t argc = PARAM_7;
959     napi_value args[PARAM_7] = {nullptr};
960     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
961     int firstParam;
962     int secondParam;
963     int thirdParam;
964     int fourthParam;
965     int fifthParam;
966     int sixthParam;
967     int seventhParam;
968     const char *mimeType = nullptr;
969     napi_get_value_int32(env, args[PARAM_0], &firstParam);
970     napi_get_value_int32(env, args[PARAM_1], &secondParam);
971     napi_get_value_int32(env, args[PARAM_2], &thirdParam);
972     napi_get_value_int32(env, args[PARAM_3], &fourthParam);
973     napi_get_value_int32(env, args[PARAM_4], &fifthParam);
974     napi_get_value_int32(env, args[PARAM_5], &sixthParam);
975     napi_get_value_int32(env, args[PARAM_6], &seventhParam);
976 
977     int backParam = FAIL;
978     napi_value result = nullptr;
979     OH_AVCodec *videoEnc = nullptr;
980     OH_AVErrCode checkParam;
981     OH_AVFormat *format = nullptr;
982 
983     if (firstParam == PARAM_1) {
984         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC;
985     } else if (firstParam == PARAM_0) {
986         mimeType = nullptr;
987     } else if (firstParam == PARAM_2) {
988         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
989     }
990 
991     if (secondParam == PARAM_1) {
992         videoEnc = OH_VideoEncoder_CreateByMime(mimeType);
993     } else if (secondParam == PARAM_0) {
994         videoEnc = nullptr;
995     }
996 
997     if (thirdParam == PARAM_1) {
998         format = OH_AVFormat_Create();
999         OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1000         OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1001         OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1002     }
1003 
1004     OH_VideoEncoder_Configure(videoEnc, format);
1005 
1006     if (fourthParam == PARAM_1) {
1007         OH_VideoEncoder_Prepare(videoEnc);
1008     } else if (fourthParam == PARAM_0) {
1009         OH_VideoEncoder_Prepare(nullptr);
1010     }
1011 
1012     if (fifthParam == PARAM_1) {
1013         OH_VideoEncoder_Start(videoEnc);
1014     } else if (fifthParam == PARAM_0) {
1015         OH_VideoEncoder_Start(nullptr);
1016     }
1017 
1018     if (sixthParam == PARAM_1) {
1019         checkParam = OH_VideoEncoder_Stop(videoEnc);
1020     } else if (sixthParam == PARAM_0) {
1021         checkParam = OH_VideoEncoder_Stop(nullptr);
1022     }
1023 
1024     if (seventhParam == PARAM_1) {
1025         if (checkParam == AV_ERR_OK) {
1026             backParam = SUCCESS;
1027         }
1028     } else if (seventhParam == PARAM_0) {
1029         if (checkParam != AV_ERR_OK) {
1030             backParam = SUCCESS;
1031         }
1032     }
1033     OH_VideoEncoder_Destroy(videoEnc);
1034     napi_create_int32(env, backParam, &result);
1035     return result;
1036 }
1037 
OHVideoEncoderFlush(napi_env env,napi_callback_info info)1038 static napi_value OHVideoEncoderFlush(napi_env env, napi_callback_info info)
1039 {
1040     size_t argc = PARAM_7;
1041     napi_value args[PARAM_7] = {nullptr};
1042     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1043     int firstParam;
1044     int secondParam;
1045     int thirdParam;
1046     int fourthParam;
1047     int fifthParam;
1048     int sixthParam;
1049     int seventhParam;
1050     const char *mimeType = nullptr;
1051     napi_get_value_int32(env, args[PARAM_0], &firstParam);
1052     napi_get_value_int32(env, args[PARAM_1], &secondParam);
1053     napi_get_value_int32(env, args[PARAM_2], &thirdParam);
1054     napi_get_value_int32(env, args[PARAM_3], &fourthParam);
1055     napi_get_value_int32(env, args[PARAM_4], &fifthParam);
1056     napi_get_value_int32(env, args[PARAM_5], &sixthParam);
1057     napi_get_value_int32(env, args[PARAM_6], &seventhParam);
1058 
1059     int backParam = FAIL;
1060     napi_value result = nullptr;
1061     OH_AVCodec *videoEnc = nullptr;
1062     OH_AVErrCode checkParam;
1063     OH_AVFormat *format = nullptr;
1064 
1065     if (firstParam == PARAM_1) {
1066         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC;
1067     } else if (firstParam == PARAM_0) {
1068         mimeType = nullptr;
1069     } else if (firstParam == PARAM_2) {
1070         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
1071     }
1072 
1073     if (secondParam == PARAM_1) {
1074         videoEnc = OH_VideoEncoder_CreateByMime(mimeType);
1075     } else if (secondParam == PARAM_0) {
1076         videoEnc = nullptr;
1077     }
1078 
1079     if (thirdParam == PARAM_1) {
1080         format = OH_AVFormat_Create();
1081         OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1082         OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1083         OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1084     }
1085 
1086     OH_VideoEncoder_Configure(videoEnc, format);
1087 
1088     if (fourthParam == PARAM_1) {
1089         OH_VideoEncoder_Prepare(videoEnc);
1090     } else if (fourthParam == PARAM_0) {
1091         OH_VideoEncoder_Prepare(nullptr);
1092     }
1093 
1094     if (fifthParam == PARAM_1) {
1095         OH_VideoEncoder_Start(videoEnc);
1096     } else if (fifthParam == PARAM_0) {
1097         OH_VideoEncoder_Start(nullptr);
1098     }
1099 
1100     if (sixthParam == PARAM_1) {
1101         checkParam = OH_VideoEncoder_Flush(videoEnc);
1102     } else if (sixthParam == PARAM_0) {
1103         checkParam = OH_VideoEncoder_Flush(nullptr);
1104     }
1105     if (seventhParam == PARAM_1) {
1106         if (checkParam == AV_ERR_OK) {
1107             backParam = SUCCESS;
1108         }
1109     } else if (seventhParam == PARAM_0) {
1110         if (checkParam != AV_ERR_OK) {
1111             backParam = SUCCESS;
1112         }
1113     }
1114     OH_VideoEncoder_Stop(videoEnc);
1115     OH_VideoEncoder_Destroy(videoEnc);
1116 
1117     napi_create_int32(env, backParam, &result);
1118     return result;
1119 }
1120 
OHVideoEncoderReset(napi_env env,napi_callback_info info)1121 static napi_value OHVideoEncoderReset(napi_env env, napi_callback_info info)
1122 {
1123     size_t argc = PARAM_7;
1124     napi_value args[PARAM_7] = {nullptr};
1125     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1126     int firstParam;
1127     int secondParam;
1128     int thirdParam;
1129     int fourthParam;
1130     int fifthParam;
1131     int sixthParam;
1132     int seventhParam;
1133     const char *mimeType = nullptr;
1134     napi_get_value_int32(env, args[PARAM_0], &firstParam);
1135     napi_get_value_int32(env, args[PARAM_1], &secondParam);
1136     napi_get_value_int32(env, args[PARAM_2], &thirdParam);
1137     napi_get_value_int32(env, args[PARAM_3], &fourthParam);
1138     napi_get_value_int32(env, args[PARAM_4], &fifthParam);
1139     napi_get_value_int32(env, args[PARAM_5], &sixthParam);
1140     napi_get_value_int32(env, args[PARAM_6], &seventhParam);
1141 
1142     int backParam = FAIL;
1143     napi_value result = nullptr;
1144     OH_AVCodec *videoEnc = nullptr;
1145     OH_AVErrCode checkParam;
1146     OH_AVFormat *format = nullptr;
1147 
1148     if (firstParam == PARAM_1) {
1149         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC;
1150     } else if (firstParam == PARAM_0) {
1151         mimeType = nullptr;
1152     } else if (firstParam == PARAM_2) {
1153         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
1154     }
1155 
1156     if (secondParam == PARAM_1) {
1157         videoEnc = OH_VideoEncoder_CreateByMime(mimeType);
1158     } else if (secondParam == PARAM_0) {
1159         videoEnc = nullptr;
1160     }
1161 
1162     if (thirdParam == PARAM_1) {
1163         format = OH_AVFormat_Create();
1164         OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1165         OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1166         OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1167     }
1168 
1169     OH_VideoEncoder_Configure(videoEnc, format);
1170 
1171     if (fourthParam == PARAM_1) {
1172         OH_VideoEncoder_Prepare(videoEnc);
1173     } else if (fourthParam == PARAM_0) {
1174         OH_VideoEncoder_Prepare(nullptr);
1175     }
1176 
1177     if (fifthParam == PARAM_1) {
1178         OH_VideoEncoder_Start(videoEnc);
1179     } else if (fifthParam == PARAM_0) {
1180         OH_VideoEncoder_Start(nullptr);
1181     }
1182 
1183     if (sixthParam == PARAM_1) {
1184         checkParam = OH_VideoEncoder_Reset(videoEnc);
1185     } else if (sixthParam == PARAM_0) {
1186         checkParam = OH_VideoEncoder_Reset(nullptr);
1187     }
1188     if (seventhParam == PARAM_1) {
1189         if (checkParam == AV_ERR_OK) {
1190             backParam = SUCCESS;
1191         }
1192     } else if (seventhParam == PARAM_0) {
1193         if (checkParam != AV_ERR_OK) {
1194             backParam = SUCCESS;
1195         }
1196     }
1197     OH_VideoEncoder_Destroy(videoEnc);
1198     napi_create_int32(env, backParam, &result);
1199     return result;
1200 }
1201 
OHVideoEncoderGetOutputDescription(napi_env env,napi_callback_info info)1202 static napi_value OHVideoEncoderGetOutputDescription(napi_env env, napi_callback_info info)
1203 {
1204     size_t argc = PARAM_7;
1205     napi_value args[PARAM_7] = {nullptr};
1206     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1207     int firstParam;
1208     int secondParam;
1209     int thirdParam;
1210     int fourthParam;
1211     int fifthParam;
1212     int sixthParam;
1213     int seventhParam;
1214     const char *mimeType = nullptr;
1215     napi_get_value_int32(env, args[PARAM_0], &firstParam);
1216     napi_get_value_int32(env, args[PARAM_1], &secondParam);
1217     napi_get_value_int32(env, args[PARAM_2], &thirdParam);
1218     napi_get_value_int32(env, args[PARAM_3], &fourthParam);
1219     napi_get_value_int32(env, args[PARAM_4], &fifthParam);
1220     napi_get_value_int32(env, args[PARAM_5], &sixthParam);
1221     napi_get_value_int32(env, args[PARAM_6], &seventhParam);
1222 
1223     int backParam = FAIL;
1224     napi_value result = nullptr;
1225     OH_AVCodec *videoEnc = nullptr;
1226     OH_AVFormat *checkParam = nullptr;
1227     OH_AVFormat *format = nullptr;
1228 
1229     if (firstParam == PARAM_1) {
1230         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC;
1231     } else if (firstParam == PARAM_0) {
1232         mimeType = nullptr;
1233     } else if (firstParam == PARAM_2) {
1234         mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC;
1235     }
1236 
1237     if (secondParam == PARAM_1) {
1238         videoEnc = OH_VideoEncoder_CreateByMime(mimeType);
1239     } else if (secondParam == PARAM_0) {
1240         videoEnc = nullptr;
1241     }
1242 
1243     if (thirdParam == PARAM_1) {
1244         format = OH_AVFormat_Create();
1245         OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1246         OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1247         OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1248     }
1249 
1250     OH_VideoEncoder_Configure(videoEnc, format);
1251 
1252     if (fourthParam == PARAM_1) {
1253         OH_VideoEncoder_Prepare(videoEnc);
1254     } else if (fourthParam == PARAM_0) {
1255         OH_VideoEncoder_Prepare(nullptr);
1256     }
1257 
1258     if (fifthParam == PARAM_1) {
1259         OH_VideoEncoder_Start(videoEnc);
1260     } else if (fifthParam == PARAM_0) {
1261         OH_VideoEncoder_Start(nullptr);
1262     }
1263 
1264     if (sixthParam == PARAM_1) {
1265         checkParam = OH_VideoEncoder_GetOutputDescription(videoEnc);
1266     } else if (sixthParam == PARAM_0) {
1267         checkParam = OH_VideoEncoder_GetOutputDescription(nullptr);
1268     }
1269     if (seventhParam == PARAM_1) {
1270         if (checkParam != nullptr) {
1271             backParam = SUCCESS;
1272         }
1273     } else if (seventhParam == PARAM_0) {
1274         if (checkParam == nullptr) {
1275             backParam = SUCCESS;
1276         }
1277     }
1278     OH_VideoEncoder_Destroy(videoEnc);
1279     napi_create_int32(env, backParam, &result);
1280     return result;
1281 }
1282 
OHVideoEncoderSetParameter(napi_env env,napi_callback_info info)1283 static napi_value OHVideoEncoderSetParameter(napi_env env, napi_callback_info info)
1284 {
1285     int backParam = FAIL;
1286     napi_value result = nullptr;
1287     OH_AVCodec *videoEnc = nullptr;
1288     OH_AVErrCode checkParam;
1289     OH_AVFormat *format = nullptr;
1290     format = OH_AVFormat_Create();
1291     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1292     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1293     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1294     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
1295     OH_VideoEncoder_Configure(videoEnc, format);
1296     OH_VideoEncoder_Prepare(videoEnc);
1297     checkParam = OH_VideoEncoder_Start(videoEnc);
1298     if (checkParam == AV_ERR_OK) {
1299         checkParam = OH_VideoEncoder_SetParameter(videoEnc, format);
1300         if (checkParam == AV_ERR_OK) {
1301             backParam = SUCCESS;
1302         }
1303     }
1304     OH_VideoEncoder_Destroy(videoEnc);
1305     napi_create_int32(env, backParam, &result);
1306     return result;
1307 }
1308 
OHVideoEncoderSetParameterHEVC(napi_env env,napi_callback_info info)1309 static napi_value OHVideoEncoderSetParameterHEVC(napi_env env, napi_callback_info info)
1310 {
1311     int backParam = FAIL;
1312     napi_value result = nullptr;
1313     OH_AVCodec *videoEnc = nullptr;
1314     OH_AVErrCode checkParam;
1315     OH_AVFormat *format = nullptr;
1316     format = OH_AVFormat_Create();
1317     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1318     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1319     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1320     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
1321     OH_VideoEncoder_Configure(videoEnc, format);
1322     OH_VideoEncoder_Prepare(videoEnc);
1323     checkParam = OH_VideoEncoder_Start(videoEnc);
1324     if (checkParam == AV_ERR_OK) {
1325         checkParam = OH_VideoEncoder_SetParameter(videoEnc, format);
1326         if (checkParam == AV_ERR_OK) {
1327             backParam = SUCCESS;
1328         }
1329     }
1330     OH_VideoEncoder_Destroy(videoEnc);
1331     napi_create_int32(env, backParam, &result);
1332     return result;
1333 }
1334 
OHVideoEncoderSetParameterAbnormal(napi_env env,napi_callback_info info)1335 static napi_value OHVideoEncoderSetParameterAbnormal(napi_env env, napi_callback_info info)
1336 {
1337     int backParam = FAIL;
1338     napi_value result = nullptr;
1339     OH_AVCodec *videoEnc = nullptr;
1340     OH_AVErrCode checkParam;
1341     OH_AVFormat *format = nullptr;
1342     format = OH_AVFormat_Create();
1343     OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
1344     OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1345     OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
1346     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
1347     OH_VideoEncoder_Configure(videoEnc, format);
1348     OH_VideoEncoder_Prepare(videoEnc);
1349     checkParam = OH_VideoEncoder_Start(videoEnc);
1350     if (checkParam != AV_ERR_OK) {
1351         checkParam = OH_VideoEncoder_SetParameter(videoEnc, format);
1352         if (checkParam != AV_ERR_OK) {
1353             backParam = SUCCESS;
1354         }
1355     }
1356     napi_create_int32(env, backParam, &result);
1357     return result;
1358 }
1359 
OHVideoEncoderGetInputDescription(napi_env env,napi_callback_info info)1360 static napi_value OHVideoEncoderGetInputDescription(napi_env env, napi_callback_info info)
1361 {
1362     int backParam = FAIL;
1363     napi_value result = nullptr;
1364     OH_AVCodec *videoEnc = nullptr;
1365     OH_AVFormat *checkParam = nullptr;
1366     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
1367     checkParam = OH_VideoEncoder_GetInputDescription(videoEnc);
1368     if (checkParam != nullptr) {
1369         backParam = SUCCESS;
1370         OH_VideoEncoder_Stop(videoEnc);
1371         OH_AVFormat_Destroy(checkParam);
1372         OH_VideoEncoder_Destroy(videoEnc);
1373     }
1374     napi_create_int32(env, backParam, &result);
1375     return result;
1376 }
1377 
OHVideoEncoderGetInputDescriptionHEVC(napi_env env,napi_callback_info info)1378 static napi_value OHVideoEncoderGetInputDescriptionHEVC(napi_env env, napi_callback_info info)
1379 {
1380     int backParam = FAIL;
1381     napi_value result = nullptr;
1382     OH_AVCodec *videoEnc = nullptr;
1383     OH_AVFormat *checkParam = nullptr;
1384     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
1385     checkParam = OH_VideoEncoder_GetInputDescription(videoEnc);
1386     if (checkParam != nullptr) {
1387         backParam = SUCCESS;
1388         OH_VideoEncoder_Stop(videoEnc);
1389         OH_AVFormat_Destroy(checkParam);
1390         OH_VideoEncoder_Destroy(videoEnc);
1391     }
1392     napi_create_int32(env, backParam, &result);
1393     return result;
1394 }
1395 
OHVideoEncoderGetInputDescriptionAbnormal(napi_env env,napi_callback_info info)1396 static napi_value OHVideoEncoderGetInputDescriptionAbnormal(napi_env env, napi_callback_info info)
1397 {
1398     int backParam = FAIL;
1399     napi_value result = nullptr;
1400     OH_AVCodec *videoEnc = nullptr;
1401     OH_AVFormat *checkParam = nullptr;
1402     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
1403     checkParam = OH_VideoEncoder_GetInputDescription(videoEnc);
1404     if (checkParam == nullptr) {
1405         backParam = SUCCESS;
1406         OH_VideoEncoder_Stop(videoEnc);
1407         OH_AVFormat_Destroy(checkParam);
1408     }
1409     napi_create_int32(env, backParam, &result);
1410     return result;
1411 }
1412 
OHVideoEncoderIsValid(napi_env env,napi_callback_info info)1413 static napi_value OHVideoEncoderIsValid(napi_env env, napi_callback_info info)
1414 {
1415     int backParam = FAIL;
1416     napi_value result = nullptr;
1417     OH_AVCodec *videoEnc = nullptr;
1418     OH_AVErrCode checkParam;
1419     bool status = true;
1420     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
1421     checkParam = OH_VideoEncoder_IsValid(videoEnc, &status);
1422     if (checkParam == AV_ERR_OK) {
1423         backParam = SUCCESS;
1424         OH_VideoEncoder_Stop(videoEnc);
1425     }
1426     OH_VideoEncoder_Destroy(videoEnc);
1427     napi_create_int32(env, backParam, &result);
1428     return result;
1429 }
1430 
OHVideoEncoderIsValidHEVC(napi_env env,napi_callback_info info)1431 static napi_value OHVideoEncoderIsValidHEVC(napi_env env, napi_callback_info info)
1432 {
1433     int backParam = FAIL;
1434     napi_value result = nullptr;
1435     OH_AVCodec *videoEnc = nullptr;
1436     OH_AVErrCode checkParam;
1437     bool status = true;
1438     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
1439     checkParam = OH_VideoEncoder_IsValid(videoEnc, &status);
1440     if (checkParam == AV_ERR_OK) {
1441         backParam = SUCCESS;
1442         OH_VideoEncoder_Stop(videoEnc);
1443     }
1444     OH_VideoEncoder_Destroy(videoEnc);
1445     napi_create_int32(env, backParam, &result);
1446     return result;
1447 }
1448 
OHVideoEncoderIsValidAbnormal(napi_env env,napi_callback_info info)1449 static napi_value OHVideoEncoderIsValidAbnormal(napi_env env, napi_callback_info info)
1450 {
1451     int backParam = FAIL;
1452     napi_value result = nullptr;
1453     OH_AVCodec *videoEnc = nullptr;
1454     OH_AVErrCode checkParam;
1455     bool status = true;
1456     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
1457     checkParam = OH_VideoEncoder_IsValid(videoEnc, &status);
1458     if (checkParam != AV_ERR_OK) {
1459         backParam = SUCCESS;
1460         OH_VideoEncoder_Stop(videoEnc);
1461     }
1462     OH_VideoEncoder_Destroy(videoEnc);
1463     napi_create_int32(env, backParam, &result);
1464     return result;
1465 }
1466 
OHVideoEncoderPushInputBuffer(napi_env env,napi_callback_info info)1467 static napi_value OHVideoEncoderPushInputBuffer(napi_env env, napi_callback_info info)
1468 {
1469     int backParam = FAIL;
1470     napi_value result = nullptr;
1471     OH_AVCodec *videoEnc = nullptr;
1472     OH_AVErrCode checkParam;
1473     uint32_t index = PARAM_1;
1474     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
1475     checkParam = OH_VideoEncoder_PushInputBuffer(videoEnc, index);
1476     if (checkParam != AV_ERR_OK) {
1477         backParam = SUCCESS;
1478     }
1479     OH_VideoEncoder_Destroy(videoEnc);
1480     napi_create_int32(env, backParam, &result);
1481     return result;
1482 }
1483 
OHVideoEncoderPushInputBufferHEVC(napi_env env,napi_callback_info info)1484 static napi_value OHVideoEncoderPushInputBufferHEVC(napi_env env, napi_callback_info info)
1485 {
1486     int backParam = FAIL;
1487     napi_value result = nullptr;
1488     OH_AVCodec *videoEnc = nullptr;
1489     OH_AVErrCode checkParam;
1490     uint32_t index = PARAM_1;
1491     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
1492     checkParam = OH_VideoEncoder_PushInputBuffer(videoEnc, index);
1493     if (checkParam != AV_ERR_OK) {
1494         backParam = SUCCESS;
1495     }
1496     OH_VideoEncoder_Destroy(videoEnc);
1497     napi_create_int32(env, backParam, &result);
1498     return result;
1499 }
1500 
OHVideoEncoderPushInputBufferAbnormal(napi_env env,napi_callback_info info)1501 static napi_value OHVideoEncoderPushInputBufferAbnormal(napi_env env, napi_callback_info info)
1502 {
1503     int backParam = FAIL;
1504     napi_value result = nullptr;
1505     OH_AVCodec *videoEnc = nullptr;
1506     OH_AVErrCode checkParam;
1507     uint32_t index = PARAM_1;
1508     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
1509     checkParam = OH_VideoEncoder_PushInputBuffer(videoEnc, index);
1510     if (checkParam != AV_ERR_OK) {
1511         backParam = SUCCESS;
1512     }
1513     OH_VideoEncoder_Destroy(videoEnc);
1514     napi_create_int32(env, backParam, &result);
1515     return result;
1516 }
1517 
OHVideoEncoderFreeOutputBuffer(napi_env env,napi_callback_info info)1518 static napi_value OHVideoEncoderFreeOutputBuffer(napi_env env, napi_callback_info info)
1519 {
1520     int backParam = FAIL;
1521     napi_value result = nullptr;
1522     OH_AVCodec *videoEnc = nullptr;
1523     OH_AVErrCode checkParam;
1524     uint32_t index = PARAM_1;
1525     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
1526     checkParam = OH_VideoEncoder_FreeOutputBuffer(videoEnc, 0);
1527     if (checkParam != AV_ERR_OK) {
1528         backParam = SUCCESS;
1529     }
1530     OH_VideoEncoder_Destroy(videoEnc);
1531     napi_create_int32(env, backParam, &result);
1532     return result;
1533 }
1534 
OHVideoEncoderFreeOutputBufferHEVC(napi_env env,napi_callback_info info)1535 static napi_value OHVideoEncoderFreeOutputBufferHEVC(napi_env env, napi_callback_info info)
1536 {
1537     int backParam = FAIL;
1538     napi_value result = nullptr;
1539     OH_AVCodec *videoEnc = nullptr;
1540     OH_AVErrCode checkParam;
1541     uint32_t index = PARAM_1;
1542     videoEnc = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);
1543     checkParam = OH_VideoEncoder_FreeOutputBuffer(videoEnc, 0);
1544     if (checkParam != AV_ERR_OK) {
1545         backParam = SUCCESS;
1546     }
1547     OH_VideoEncoder_Destroy(videoEnc);
1548     napi_create_int32(env, backParam, &result);
1549     return result;
1550 }
1551 
OHVideoEncoderFreeOutputBufferAbnormal(napi_env env,napi_callback_info info)1552 static napi_value OHVideoEncoderFreeOutputBufferAbnormal(napi_env env, napi_callback_info info)
1553 {
1554     int backParam = FAIL;
1555     napi_value result = nullptr;
1556     OH_AVCodec *videoEnc = nullptr;
1557     OH_AVErrCode checkParam;
1558     uint32_t index = PARAM_1;
1559     videoEnc = OH_VideoEncoder_CreateByMime(nullptr);
1560     checkParam = OH_VideoEncoder_FreeOutputBuffer(videoEnc, 0);
1561     if (checkParam != AV_ERR_OK) {
1562         backParam = SUCCESS;
1563     }
1564     OH_VideoEncoder_Destroy(videoEnc);
1565     napi_create_int32(env, backParam, &result);
1566     return result;
1567 }
1568 
1569 EXTERN_C_START
Init(napi_env env,napi_value exports)1570 static napi_value Init(napi_env env, napi_value exports)
1571 {
1572     napi_property_descriptor desc[] = {
1573         {"oHVideoEncoderCreateByMime", nullptr, OHVideoEncoderCreateByMime, nullptr, nullptr, nullptr, napi_default,
1574          nullptr},
1575         {"oHVideoEncoderCreateByMimeHEVC", nullptr, OHVideoEncoderCreateByMimeHEVC, nullptr, nullptr, nullptr,
1576          napi_default, nullptr},
1577         {"oHVideoEncoderCreateByMimeAbnormal", nullptr, OHVideoEncoderCreateByMimeAbnormal, nullptr, nullptr, nullptr,
1578          napi_default, nullptr},
1579         {"oHVideoEncoderCreateByName", nullptr, OHVideoEncoderCreateByName, nullptr, nullptr, nullptr, napi_default,
1580          nullptr},
1581         {"oHVideoEncoderCreateByNameHEVC", nullptr, OHVideoEncoderCreateByNameHEVC, nullptr, nullptr, nullptr,
1582          napi_default, nullptr},
1583         {"oHVideoEncoderCreateByNameAbnormal", nullptr, OHVideoEncoderCreateByNameAbnormal, nullptr, nullptr, nullptr,
1584          napi_default, nullptr},
1585         {"oHVideoEncoderDestroy", nullptr, OHVideoEncoderDestroy, nullptr, nullptr, nullptr, napi_default, nullptr},
1586         {"oHVideoEncoderDestroyHEVC", nullptr, OHVideoEncoderDestroyHEVC, nullptr, nullptr, nullptr, napi_default,
1587          nullptr},
1588         {"oHVideoEncoderDestroyAbnormal", nullptr, OHVideoEncoderDestroyAbnormal, nullptr, nullptr, nullptr,
1589          napi_default, nullptr},
1590         {"oHVideoEncoderSetCallback", nullptr, OHVideoEncoderSetCallback, nullptr, nullptr, nullptr, napi_default,
1591          nullptr},
1592         {"oHVideoEncoderSetCallbackHEVC", nullptr, OHVideoEncoderSetCallbackHEVC, nullptr, nullptr, nullptr,
1593          napi_default, nullptr},
1594         {"oHVideoEncoderSetCallbackAbnormal", nullptr, OHVideoEncoderSetCallbackAbnormal, nullptr, nullptr, nullptr,
1595          napi_default, nullptr},
1596         {"oHVideoEncoderConfigure", nullptr, OHVideoEncoderConfigure, nullptr, nullptr, nullptr, napi_default, nullptr},
1597         {"oHVideoEncoderConfigureHEVC", nullptr, OHVideoEncoderConfigureHEVC, nullptr, nullptr, nullptr, napi_default,
1598          nullptr},
1599         {"oHVideoEncoderConfigureAbnormal1", nullptr, OHVideoEncoderConfigureAbnormal1, nullptr, nullptr, nullptr,
1600          napi_default, nullptr},
1601         {"oHVideoEncoderConfigureAbnormal2", nullptr, OHVideoEncoderConfigureAbnormal2, nullptr, nullptr, nullptr,
1602          napi_default, nullptr},
1603         {"oHVideoEncoderConfigureAbnormal3", nullptr, OHVideoEncoderConfigureAbnormal3, nullptr, nullptr, nullptr,
1604          napi_default, nullptr},
1605         {"oHVideoEncoderConfigureAbnormal4", nullptr, OHVideoEncoderConfigureAbnormal4, nullptr, nullptr, nullptr,
1606          napi_default, nullptr},
1607         {"oHVideoEncoderConfigureAbnormal5", nullptr, OHVideoEncoderConfigureAbnormal5, nullptr, nullptr, nullptr,
1608          napi_default, nullptr},
1609         {"oHVideoEncoderConfigureAbnormal6", nullptr, OHVideoEncoderConfigureAbnormal6, nullptr, nullptr, nullptr,
1610          napi_default, nullptr},
1611         {"oHVideoEncoderConfigureAbnormal7", nullptr, OHVideoEncoderConfigureAbnormal7, nullptr, nullptr, nullptr,
1612          napi_default, nullptr},
1613         {"oHVideoEncoderPrepare", nullptr, OHVideoEncoderPrepare, nullptr, nullptr, nullptr, napi_default, nullptr},
1614         {"oHVideoEncoderPrepareHEVC", nullptr, OHVideoEncoderPrepareHEVC, nullptr, nullptr, nullptr, napi_default,
1615          nullptr},
1616         {"oHVideoEncoderPrepareAbnormal1", nullptr, OHVideoEncoderPrepareAbnormal1, nullptr, nullptr, nullptr,
1617          napi_default, nullptr},
1618         {"oHVideoEncoderPrepareAbnormal2", nullptr, OHVideoEncoderPrepareAbnormal2, nullptr, nullptr, nullptr,
1619          napi_default, nullptr},
1620         {"oHVideoEncoderPrepareAbnormal3", nullptr, OHVideoEncoderPrepareAbnormal3, nullptr, nullptr, nullptr,
1621          napi_default, nullptr},
1622         {"oHVideoEncoderPrepareAbnormal4", nullptr, OHVideoEncoderPrepareAbnormal4, nullptr, nullptr, nullptr,
1623          napi_default, nullptr},
1624         {"oHVideoEncoderPrepareAbnormal5", nullptr, OHVideoEncoderPrepareAbnormal5, nullptr, nullptr, nullptr,
1625          napi_default, nullptr},
1626         {"oHVideoEncoderPrepareAbnormal6", nullptr, OHVideoEncoderPrepareAbnormal6, nullptr, nullptr, nullptr,
1627          napi_default, nullptr},
1628         {"oHVideoEncoderPrepareAbnormal7", nullptr, OHVideoEncoderPrepareAbnormal7, nullptr, nullptr, nullptr,
1629          napi_default, nullptr},
1630         {"oHVideoEncoderPrepareAbnormal8", nullptr, OHVideoEncoderPrepareAbnormal8, nullptr, nullptr, nullptr,
1631          napi_default, nullptr},
1632         {"oHVideoEncoderPrepareAbnormal9", nullptr, OHVideoEncoderPrepareAbnormal9, nullptr, nullptr, nullptr,
1633          napi_default, nullptr},
1634         {"oHVideoEncoderPrepareAbnormal10", nullptr, OHVideoEncoderPrepareAbnormal10, nullptr, nullptr, nullptr,
1635          napi_default, nullptr},
1636         {"oHVideoEncoderPrepareAbnormal11", nullptr, OHVideoEncoderPrepareAbnormal11, nullptr, nullptr, nullptr,
1637          napi_default, nullptr},
1638         {"oHVideoEncoderPrepareAbnormal12", nullptr, OHVideoEncoderPrepareAbnormal12, nullptr, nullptr, nullptr,
1639          napi_default, nullptr},
1640         {"oHVideoEncoderPrepareAbnormal13", nullptr, OHVideoEncoderPrepareAbnormal13, nullptr, nullptr, nullptr,
1641          napi_default, nullptr},
1642         {"oHVideoEncoderPrepareAbnormal14", nullptr, OHVideoEncoderPrepareAbnormal14, nullptr, nullptr, nullptr,
1643          napi_default, nullptr},
1644         {"oHVideoEncoderPrepareAbnormal15", nullptr, OHVideoEncoderPrepareAbnormal15, nullptr, nullptr, nullptr,
1645          napi_default, nullptr},
1646         {"oHVideoEncoderStart", nullptr, OHVideoEncoderStart, nullptr, nullptr, nullptr, napi_default, nullptr},
1647         {"oHVideoEncoderStop", nullptr, OHVideoEncoderStop, nullptr, nullptr, nullptr, napi_default, nullptr},
1648         {"oHVideoEncoderFlush", nullptr, OHVideoEncoderFlush, nullptr, nullptr, nullptr, napi_default, nullptr},
1649         {"oHVideoEncoderReset", nullptr, OHVideoEncoderReset, nullptr, nullptr, nullptr, napi_default, nullptr},
1650         {"oHVideoEncoderGetOutputDescription", nullptr, OHVideoEncoderGetOutputDescription, nullptr, nullptr, nullptr,
1651          napi_default, nullptr},
1652         {"oHVideoEncoderSetParameter", nullptr, OHVideoEncoderSetParameter, nullptr, nullptr, nullptr, napi_default,
1653          nullptr},
1654         {"oHVideoEncoderSetParameterHEVC", nullptr, OHVideoEncoderSetParameterHEVC, nullptr, nullptr, nullptr,
1655          napi_default, nullptr},
1656         {"oHVideoEncoderSetParameterAbnormal", nullptr, OHVideoEncoderSetParameterAbnormal, nullptr, nullptr, nullptr,
1657          napi_default, nullptr},
1658         {"oHVideoEncoderGetInputDescription", nullptr, OHVideoEncoderGetInputDescription, nullptr, nullptr, nullptr,
1659          napi_default, nullptr},
1660         {"oHVideoEncoderGetInputDescriptionHEVC", nullptr, OHVideoEncoderGetInputDescriptionHEVC, nullptr, nullptr,
1661          nullptr, napi_default, nullptr},
1662         {"oHVideoEncoderGetInputDescriptionAbnormal", nullptr, OHVideoEncoderGetInputDescriptionAbnormal, nullptr,
1663          nullptr, nullptr, napi_default, nullptr},
1664         {"oHVideoEncoderIsValid", nullptr, OHVideoEncoderIsValid, nullptr, nullptr, nullptr, napi_default, nullptr},
1665         {"oHVideoEncoderIsValidHEVC", nullptr, OHVideoEncoderIsValidHEVC, nullptr, nullptr, nullptr, napi_default,
1666          nullptr},
1667         {"oHVideoEncoderIsValidAbnormal", nullptr, OHVideoEncoderIsValidAbnormal, nullptr, nullptr, nullptr,
1668          napi_default, nullptr},
1669         {"oHVideoEncoderRegisterCallback", nullptr, OHVideoEncoderRegisterCallback, nullptr, nullptr, nullptr,
1670          napi_default, nullptr},
1671         {"oHVideoEncoderRegisterCallbackHEVC", nullptr, OHVideoEncoderRegisterCallbackHEVC, nullptr, nullptr, nullptr,
1672          napi_default, nullptr},
1673         {"oHVideoEncoderRegisterCallbackAbnormal", nullptr, OHVideoEncoderRegisterCallbackAbnormal, nullptr, nullptr,
1674          nullptr, napi_default, nullptr},
1675         {"oHVideoEncoderPushInputBuffer", nullptr, OHVideoEncoderPushInputBuffer, nullptr, nullptr, nullptr,
1676          napi_default, nullptr},
1677         {"oHVideoEncoderPushInputBufferHEVC", nullptr, OHVideoEncoderPushInputBufferHEVC, nullptr, nullptr, nullptr,
1678          napi_default, nullptr},
1679         {"oHVideoEncoderPushInputBufferAbnormal", nullptr, OHVideoEncoderPushInputBufferAbnormal, nullptr, nullptr, nullptr,
1680          napi_default, nullptr},
1681         {"oHVideoEncoderFreeOutputBuffer", nullptr, OHVideoEncoderFreeOutputBuffer, nullptr, nullptr, nullptr,
1682          napi_default, nullptr},
1683         {"oHVideoEncoderFreeOutputBufferHEVC", nullptr, OHVideoEncoderFreeOutputBufferHEVC, nullptr, nullptr, nullptr,
1684          napi_default, nullptr},
1685         {"oHVideoEncoderFreeOutputBufferAbnormal", nullptr, OHVideoEncoderFreeOutputBufferAbnormal, nullptr, nullptr, nullptr,
1686          napi_default, nullptr},
1687     };
1688     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
1689     return exports;
1690 }
1691 EXTERN_C_END
1692 
1693 static napi_module demoModule = {
1694     .nm_version = 1,
1695     .nm_flags = 0,
1696     .nm_filename = nullptr,
1697     .nm_register_func = Init,
1698     .nm_modname = "libvideoencoderndk",
1699     .nm_priv = ((void *)0),
1700     .reserved = { 0 },
1701 };
1702 
RegisterModule(void)1703 extern "C" __attribute__((constructor)) void RegisterModule(void)
1704 {
1705     napi_module_register(&demoModule);
1706 }
1707