1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "napi/native_api.h" 17f6603c60Sopenharmony_ci#include <condition_variable> 18f6603c60Sopenharmony_ci#include <js_native_api_types.h> 19f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcodec_videodecoder.h> 20f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcapability.h> 21f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcodec_base.h> 22f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avformat.h> 23f6603c60Sopenharmony_ci#include <pthread.h> 24f6603c60Sopenharmony_ci#include <iostream> 25f6603c60Sopenharmony_ci#include <fstream> 26f6603c60Sopenharmony_ci#include <queue> 27f6603c60Sopenharmony_ci 28f6603c60Sopenharmony_ci#define FAIL (-1) 29f6603c60Sopenharmony_ci#define SUCCESS 0 30f6603c60Sopenharmony_ci#define PARAM_0 0 31f6603c60Sopenharmony_ci#define PARAM_1 1 32f6603c60Sopenharmony_ci#define PARAM_2 2 33f6603c60Sopenharmony_ci#define PARAM_3 3 34f6603c60Sopenharmony_ci#define PARAM_4 4 35f6603c60Sopenharmony_ci#define PARAM_5 5 36f6603c60Sopenharmony_ci#define PARAM_6 6 37f6603c60Sopenharmony_ci#define PARAM_7 7 38f6603c60Sopenharmony_ciusing namespace std; 39f6603c60Sopenharmony_ci 40f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_WIDTH = 320; 41f6603c60Sopenharmony_ci 42f6603c60Sopenharmony_ciconstexpr uint32_t DEFAULT_HEIGHT = 240; 43f6603c60Sopenharmony_ci 44f6603c60Sopenharmony_ciconstexpr OH_AVPixelFormat DEFAULT_PIXELFORMAT = AV_PIXEL_FORMAT_NV12; 45f6603c60Sopenharmony_ci 46f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderCreateByMime(napi_env env, napi_callback_info info) 47f6603c60Sopenharmony_ci{ 48f6603c60Sopenharmony_ci int backParam = FAIL; 49f6603c60Sopenharmony_ci OH_AVCodec *checkParam = nullptr; 50f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC); 51f6603c60Sopenharmony_ci if (checkParam != nullptr) { 52f6603c60Sopenharmony_ci backParam = SUCCESS; 53f6603c60Sopenharmony_ci } 54f6603c60Sopenharmony_ci napi_value result = nullptr; 55f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(checkParam); 56f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 57f6603c60Sopenharmony_ci return result; 58f6603c60Sopenharmony_ci} 59f6603c60Sopenharmony_ci 60f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderCreateByName(napi_env env, napi_callback_info info) 61f6603c60Sopenharmony_ci{ 62f6603c60Sopenharmony_ci int backParam = FAIL; 63f6603c60Sopenharmony_ci OH_AVCodec *checkParam = nullptr; 64f6603c60Sopenharmony_ci OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false); 65f6603c60Sopenharmony_ci const char *codecName = OH_AVCapability_GetName(capability); 66f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_CreateByName(codecName); 67f6603c60Sopenharmony_ci if (checkParam != nullptr) { 68f6603c60Sopenharmony_ci backParam = SUCCESS; 69f6603c60Sopenharmony_ci } 70f6603c60Sopenharmony_ci napi_value result = nullptr; 71f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(checkParam); 72f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 73f6603c60Sopenharmony_ci return result; 74f6603c60Sopenharmony_ci} 75f6603c60Sopenharmony_ci 76f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderDestroy(napi_env env, napi_callback_info info) 77f6603c60Sopenharmony_ci{ 78f6603c60Sopenharmony_ci int backParam = FAIL; 79f6603c60Sopenharmony_ci napi_value result = nullptr; 80f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 81f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 82f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 83f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Destroy(videoDec); 84f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 85f6603c60Sopenharmony_ci backParam = SUCCESS; 86f6603c60Sopenharmony_ci } 87f6603c60Sopenharmony_ci videoDec = nullptr; 88f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 89f6603c60Sopenharmony_ci return result; 90f6603c60Sopenharmony_ci} 91f6603c60Sopenharmony_ci 92f6603c60Sopenharmony_ciclass VDecSignal { 93f6603c60Sopenharmony_cipublic: 94f6603c60Sopenharmony_ci std::mutex inMutex_; 95f6603c60Sopenharmony_ci std::mutex outMutex_; 96f6603c60Sopenharmony_ci std::condition_variable inCond_; 97f6603c60Sopenharmony_ci std::condition_variable outCond_; 98f6603c60Sopenharmony_ci std::queue<uint32_t> inQueue_; 99f6603c60Sopenharmony_ci std::queue<uint32_t> outQueue_; 100f6603c60Sopenharmony_ci std::queue<OH_AVMemory *> inBufferQueue_; 101f6603c60Sopenharmony_ci std::queue<OH_AVMemory *> outBufferQueue_; 102f6603c60Sopenharmony_ci std::queue<OH_AVCodecBufferAttr> attrQueue_; 103f6603c60Sopenharmony_ci}; 104f6603c60Sopenharmony_cistatic void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData) 105f6603c60Sopenharmony_ci{ 106f6603c60Sopenharmony_ci (void)codec; 107f6603c60Sopenharmony_ci (void)errorCode; 108f6603c60Sopenharmony_ci (void)userData; 109f6603c60Sopenharmony_ci} 110f6603c60Sopenharmony_ci 111f6603c60Sopenharmony_cistatic void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData) 112f6603c60Sopenharmony_ci{ 113f6603c60Sopenharmony_ci (void)codec; 114f6603c60Sopenharmony_ci (void)format; 115f6603c60Sopenharmony_ci (void)userData; 116f6603c60Sopenharmony_ci} 117f6603c60Sopenharmony_ci 118f6603c60Sopenharmony_cistatic void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *mem, void *userData) 119f6603c60Sopenharmony_ci{ 120f6603c60Sopenharmony_ci (void)userData; 121f6603c60Sopenharmony_ci} 122f6603c60Sopenharmony_ci 123f6603c60Sopenharmony_cistatic void OnNeedOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *mem, OH_AVCodecBufferAttr *attr, 124f6603c60Sopenharmony_ci void *userData) 125f6603c60Sopenharmony_ci{ 126f6603c60Sopenharmony_ci (void)userData; 127f6603c60Sopenharmony_ci} 128f6603c60Sopenharmony_ci 129f6603c60Sopenharmony_cistatic void OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) 130f6603c60Sopenharmony_ci{ 131f6603c60Sopenharmony_ci (void)userData; 132f6603c60Sopenharmony_ci} 133f6603c60Sopenharmony_ci 134f6603c60Sopenharmony_cistatic void OnNeedOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) 135f6603c60Sopenharmony_ci{ 136f6603c60Sopenharmony_ci (void)userData; 137f6603c60Sopenharmony_ci} 138f6603c60Sopenharmony_ci 139f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderSetCallback(napi_env env, napi_callback_info info) 140f6603c60Sopenharmony_ci{ 141f6603c60Sopenharmony_ci int backParam = FAIL; 142f6603c60Sopenharmony_ci napi_value result = nullptr; 143f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 144f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 145f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 146f6603c60Sopenharmony_ci OH_AVCodecAsyncCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputData, &OnNeedOutputData }; 147f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_SetCallback(videoDec, callback, nullptr); 148f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 149f6603c60Sopenharmony_ci backParam = SUCCESS; 150f6603c60Sopenharmony_ci } 151f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 152f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 153f6603c60Sopenharmony_ci return result; 154f6603c60Sopenharmony_ci} 155f6603c60Sopenharmony_ci 156f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderRegisterCallback(napi_env env, napi_callback_info info) 157f6603c60Sopenharmony_ci{ 158f6603c60Sopenharmony_ci int backParam = FAIL; 159f6603c60Sopenharmony_ci napi_value result = nullptr; 160f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 161f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 162f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 163f6603c60Sopenharmony_ci OH_AVCodecCallback callback = { &OnError, &OnStreamChanged, &OnNeedInputBuffer, &OnNeedOutputBuffer }; 164f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_RegisterCallback(videoDec, callback, nullptr); 165f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 166f6603c60Sopenharmony_ci backParam = SUCCESS; 167f6603c60Sopenharmony_ci } 168f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 169f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 170f6603c60Sopenharmony_ci return result; 171f6603c60Sopenharmony_ci} 172f6603c60Sopenharmony_ci 173f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderConfigure(napi_env env, napi_callback_info info) 174f6603c60Sopenharmony_ci{ 175f6603c60Sopenharmony_ci int backParam = FAIL; 176f6603c60Sopenharmony_ci napi_value result = nullptr; 177f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 178f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 179f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 180f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 181f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 182f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 183f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 184f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 185f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Configure(videoDec, format); 186f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 187f6603c60Sopenharmony_ci backParam = SUCCESS; 188f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 189f6603c60Sopenharmony_ci } 190f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 191f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 192f6603c60Sopenharmony_ci return result; 193f6603c60Sopenharmony_ci} 194f6603c60Sopenharmony_ci 195f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderPrepare(napi_env env, napi_callback_info info) 196f6603c60Sopenharmony_ci{ 197f6603c60Sopenharmony_ci int backParam = FAIL; 198f6603c60Sopenharmony_ci napi_value result = nullptr; 199f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 200f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 201f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 202f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 203f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 204f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 205f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 206f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 207f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 208f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Prepare(videoDec); 209f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 210f6603c60Sopenharmony_ci backParam = SUCCESS; 211f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 212f6603c60Sopenharmony_ci } 213f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 214f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 215f6603c60Sopenharmony_ci return result; 216f6603c60Sopenharmony_ci} 217f6603c60Sopenharmony_ci 218f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderStart(napi_env env, napi_callback_info info) 219f6603c60Sopenharmony_ci{ 220f6603c60Sopenharmony_ci size_t argc = PARAM_6; 221f6603c60Sopenharmony_ci napi_value args[PARAM_6] = {nullptr}; 222f6603c60Sopenharmony_ci napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); 223f6603c60Sopenharmony_ci int firstParam; 224f6603c60Sopenharmony_ci int secondParam; 225f6603c60Sopenharmony_ci int thirdParam; 226f6603c60Sopenharmony_ci int fourthParam; 227f6603c60Sopenharmony_ci int fifthParam; 228f6603c60Sopenharmony_ci int sixthParam; 229f6603c60Sopenharmony_ci const char *mimeType = nullptr; 230f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_0], &firstParam); 231f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_1], &secondParam); 232f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_2], &thirdParam); 233f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_3], &fourthParam); 234f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_4], &fifthParam); 235f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_5], &sixthParam); 236f6603c60Sopenharmony_ci 237f6603c60Sopenharmony_ci int backParam = FAIL; 238f6603c60Sopenharmony_ci napi_value result = nullptr; 239f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 240f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 241f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 242f6603c60Sopenharmony_ci 243f6603c60Sopenharmony_ci if (firstParam == PARAM_1) { 244f6603c60Sopenharmony_ci mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC; 245f6603c60Sopenharmony_ci } else if (firstParam == PARAM_0) { 246f6603c60Sopenharmony_ci mimeType = nullptr; 247f6603c60Sopenharmony_ci } else if (firstParam == PARAM_2) { 248f6603c60Sopenharmony_ci mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC; 249f6603c60Sopenharmony_ci } 250f6603c60Sopenharmony_ci 251f6603c60Sopenharmony_ci if (secondParam == PARAM_1) { 252f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(mimeType); 253f6603c60Sopenharmony_ci } else if (secondParam == PARAM_0) { 254f6603c60Sopenharmony_ci videoDec = nullptr; 255f6603c60Sopenharmony_ci } 256f6603c60Sopenharmony_ci 257f6603c60Sopenharmony_ci if (thirdParam == PARAM_1) { 258f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 259f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 260f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 261f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 262f6603c60Sopenharmony_ci } 263f6603c60Sopenharmony_ci 264f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 265f6603c60Sopenharmony_ci 266f6603c60Sopenharmony_ci if (fourthParam == PARAM_1) { 267f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(videoDec); 268f6603c60Sopenharmony_ci } else if (fourthParam == PARAM_0) { 269f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(nullptr); 270f6603c60Sopenharmony_ci } 271f6603c60Sopenharmony_ci 272f6603c60Sopenharmony_ci if (fifthParam == PARAM_1) { 273f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Start(videoDec); 274f6603c60Sopenharmony_ci } else if (fifthParam == PARAM_0) { 275f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Start(nullptr); 276f6603c60Sopenharmony_ci } 277f6603c60Sopenharmony_ci 278f6603c60Sopenharmony_ci if (sixthParam == PARAM_1) { 279f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 280f6603c60Sopenharmony_ci backParam = SUCCESS; 281f6603c60Sopenharmony_ci } 282f6603c60Sopenharmony_ci } else if (sixthParam == PARAM_0) { 283f6603c60Sopenharmony_ci if (checkParam != AV_ERR_OK) { 284f6603c60Sopenharmony_ci backParam = SUCCESS; 285f6603c60Sopenharmony_ci } 286f6603c60Sopenharmony_ci } 287f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 288f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 289f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 290f6603c60Sopenharmony_ci return result; 291f6603c60Sopenharmony_ci} 292f6603c60Sopenharmony_ci 293f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderStop(napi_env env, napi_callback_info info) 294f6603c60Sopenharmony_ci{ 295f6603c60Sopenharmony_ci size_t argc = PARAM_7; 296f6603c60Sopenharmony_ci napi_value args[PARAM_7] = {nullptr}; 297f6603c60Sopenharmony_ci napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); 298f6603c60Sopenharmony_ci int firstParam; 299f6603c60Sopenharmony_ci int secondParam; 300f6603c60Sopenharmony_ci int thirdParam; 301f6603c60Sopenharmony_ci int fourthParam; 302f6603c60Sopenharmony_ci int fifthParam; 303f6603c60Sopenharmony_ci int sixthParam; 304f6603c60Sopenharmony_ci int seventhParam; 305f6603c60Sopenharmony_ci const char *mimeType = nullptr; 306f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_0], &firstParam); 307f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_1], &secondParam); 308f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_2], &thirdParam); 309f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_3], &fourthParam); 310f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_4], &fifthParam); 311f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_5], &sixthParam); 312f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_6], &seventhParam); 313f6603c60Sopenharmony_ci 314f6603c60Sopenharmony_ci int backParam = FAIL; 315f6603c60Sopenharmony_ci napi_value result = nullptr; 316f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 317f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 318f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 319f6603c60Sopenharmony_ci 320f6603c60Sopenharmony_ci if (firstParam == PARAM_1) { 321f6603c60Sopenharmony_ci mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC; 322f6603c60Sopenharmony_ci } else if (firstParam == PARAM_0) { 323f6603c60Sopenharmony_ci mimeType = nullptr; 324f6603c60Sopenharmony_ci } else if (firstParam == PARAM_2) { 325f6603c60Sopenharmony_ci mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC; 326f6603c60Sopenharmony_ci } 327f6603c60Sopenharmony_ci 328f6603c60Sopenharmony_ci if (secondParam == PARAM_1) { 329f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(mimeType); 330f6603c60Sopenharmony_ci } else if (secondParam == PARAM_0) { 331f6603c60Sopenharmony_ci videoDec = nullptr; 332f6603c60Sopenharmony_ci } 333f6603c60Sopenharmony_ci 334f6603c60Sopenharmony_ci if (thirdParam == PARAM_1) { 335f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 336f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 337f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 338f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 339f6603c60Sopenharmony_ci } 340f6603c60Sopenharmony_ci 341f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 342f6603c60Sopenharmony_ci 343f6603c60Sopenharmony_ci if (fourthParam == PARAM_1) { 344f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(videoDec); 345f6603c60Sopenharmony_ci } else if (fourthParam == PARAM_0) { 346f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(nullptr); 347f6603c60Sopenharmony_ci } 348f6603c60Sopenharmony_ci 349f6603c60Sopenharmony_ci if (fifthParam == PARAM_1) { 350f6603c60Sopenharmony_ci OH_VideoDecoder_Start(videoDec); 351f6603c60Sopenharmony_ci } else if (fifthParam == PARAM_0) { 352f6603c60Sopenharmony_ci OH_VideoDecoder_Start(nullptr); 353f6603c60Sopenharmony_ci } 354f6603c60Sopenharmony_ci 355f6603c60Sopenharmony_ci if (sixthParam == PARAM_1) { 356f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Stop(videoDec); 357f6603c60Sopenharmony_ci } else if (sixthParam == PARAM_0) { 358f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Stop(nullptr); 359f6603c60Sopenharmony_ci } 360f6603c60Sopenharmony_ci 361f6603c60Sopenharmony_ci if (seventhParam == PARAM_1) { 362f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 363f6603c60Sopenharmony_ci backParam = SUCCESS; 364f6603c60Sopenharmony_ci } 365f6603c60Sopenharmony_ci } else if (seventhParam == PARAM_0) { 366f6603c60Sopenharmony_ci if (checkParam != AV_ERR_OK) { 367f6603c60Sopenharmony_ci backParam = SUCCESS; 368f6603c60Sopenharmony_ci } 369f6603c60Sopenharmony_ci } 370f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 371f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 372f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 373f6603c60Sopenharmony_ci return result; 374f6603c60Sopenharmony_ci} 375f6603c60Sopenharmony_ci 376f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderFlush(napi_env env, napi_callback_info info) 377f6603c60Sopenharmony_ci{ 378f6603c60Sopenharmony_ci size_t argc = PARAM_7; 379f6603c60Sopenharmony_ci napi_value args[PARAM_7] = {nullptr}; 380f6603c60Sopenharmony_ci napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); 381f6603c60Sopenharmony_ci int firstParam; 382f6603c60Sopenharmony_ci int secondParam; 383f6603c60Sopenharmony_ci int thirdParam; 384f6603c60Sopenharmony_ci int fourthParam; 385f6603c60Sopenharmony_ci int fifthParam; 386f6603c60Sopenharmony_ci int sixthParam; 387f6603c60Sopenharmony_ci int seventhParam; 388f6603c60Sopenharmony_ci const char *mimeType = nullptr; 389f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_0], &firstParam); 390f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_1], &secondParam); 391f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_2], &thirdParam); 392f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_3], &fourthParam); 393f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_4], &fifthParam); 394f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_5], &sixthParam); 395f6603c60Sopenharmony_ci napi_get_value_int32(env, args[PARAM_6], &seventhParam); 396f6603c60Sopenharmony_ci 397f6603c60Sopenharmony_ci int backParam = FAIL; 398f6603c60Sopenharmony_ci napi_value result = nullptr; 399f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 400f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 401f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 402f6603c60Sopenharmony_ci 403f6603c60Sopenharmony_ci if (firstParam == PARAM_1) { 404f6603c60Sopenharmony_ci mimeType = OH_AVCODEC_MIMETYPE_VIDEO_AVC; 405f6603c60Sopenharmony_ci } else if (firstParam == PARAM_0) { 406f6603c60Sopenharmony_ci mimeType = nullptr; 407f6603c60Sopenharmony_ci } else if (firstParam == PARAM_2) { 408f6603c60Sopenharmony_ci mimeType = OH_AVCODEC_MIMETYPE_VIDEO_HEVC; 409f6603c60Sopenharmony_ci } 410f6603c60Sopenharmony_ci 411f6603c60Sopenharmony_ci if (secondParam == PARAM_1) { 412f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(mimeType); 413f6603c60Sopenharmony_ci } else if (secondParam == PARAM_0) { 414f6603c60Sopenharmony_ci videoDec = nullptr; 415f6603c60Sopenharmony_ci } 416f6603c60Sopenharmony_ci 417f6603c60Sopenharmony_ci if (thirdParam == PARAM_1) { 418f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 419f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 420f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 421f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 422f6603c60Sopenharmony_ci } 423f6603c60Sopenharmony_ci 424f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 425f6603c60Sopenharmony_ci 426f6603c60Sopenharmony_ci if (fourthParam == PARAM_1) { 427f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(videoDec); 428f6603c60Sopenharmony_ci } else if (fourthParam == PARAM_0) { 429f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(nullptr); 430f6603c60Sopenharmony_ci } 431f6603c60Sopenharmony_ci 432f6603c60Sopenharmony_ci if (fifthParam == PARAM_1) { 433f6603c60Sopenharmony_ci OH_VideoDecoder_Start(videoDec); 434f6603c60Sopenharmony_ci } else if (fifthParam == PARAM_0) { 435f6603c60Sopenharmony_ci OH_VideoDecoder_Start(nullptr); 436f6603c60Sopenharmony_ci } 437f6603c60Sopenharmony_ci 438f6603c60Sopenharmony_ci if (sixthParam == PARAM_1) { 439f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Flush(videoDec); 440f6603c60Sopenharmony_ci } else if (sixthParam == PARAM_0) { 441f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Flush(nullptr); 442f6603c60Sopenharmony_ci } 443f6603c60Sopenharmony_ci 444f6603c60Sopenharmony_ci if (seventhParam == PARAM_1) { 445f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 446f6603c60Sopenharmony_ci backParam = SUCCESS; 447f6603c60Sopenharmony_ci } 448f6603c60Sopenharmony_ci } else if (seventhParam == PARAM_0) { 449f6603c60Sopenharmony_ci if (checkParam != AV_ERR_OK) { 450f6603c60Sopenharmony_ci backParam = SUCCESS; 451f6603c60Sopenharmony_ci } 452f6603c60Sopenharmony_ci } 453f6603c60Sopenharmony_ci OH_VideoDecoder_Stop(videoDec); 454f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 455f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 456f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 457f6603c60Sopenharmony_ci return result; 458f6603c60Sopenharmony_ci} 459f6603c60Sopenharmony_ci 460f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderReset(napi_env env, napi_callback_info info) 461f6603c60Sopenharmony_ci{ 462f6603c60Sopenharmony_ci int backParam = FAIL; 463f6603c60Sopenharmony_ci napi_value result = nullptr; 464f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 465f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 466f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 467f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 468f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 469f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 470f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 471f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 472f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 473f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(videoDec); 474f6603c60Sopenharmony_ci if (OH_VideoDecoder_Start(videoDec) == AV_ERR_OK) { 475f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Reset(videoDec); 476f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 477f6603c60Sopenharmony_ci backParam = SUCCESS; 478f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 479f6603c60Sopenharmony_ci } 480f6603c60Sopenharmony_ci } 481f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 482f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 483f6603c60Sopenharmony_ci return result; 484f6603c60Sopenharmony_ci} 485f6603c60Sopenharmony_ci 486f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderGetOutputDescription(napi_env env, napi_callback_info info) 487f6603c60Sopenharmony_ci{ 488f6603c60Sopenharmony_ci int backParam = FAIL; 489f6603c60Sopenharmony_ci napi_value result = nullptr; 490f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 491f6603c60Sopenharmony_ci OH_AVFormat *checkParam = nullptr; 492f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 493f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 494f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 495f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 496f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 497f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 498f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 499f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(videoDec); 500f6603c60Sopenharmony_ci if (OH_VideoDecoder_Start(videoDec) == AV_ERR_OK) { 501f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_GetOutputDescription(videoDec); 502f6603c60Sopenharmony_ci if (checkParam != nullptr) { 503f6603c60Sopenharmony_ci backParam = SUCCESS; 504f6603c60Sopenharmony_ci OH_VideoDecoder_Stop(videoDec); 505f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 506f6603c60Sopenharmony_ci } 507f6603c60Sopenharmony_ci } 508f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 509f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 510f6603c60Sopenharmony_ci return result; 511f6603c60Sopenharmony_ci} 512f6603c60Sopenharmony_ci 513f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderSetParameter(napi_env env, napi_callback_info info) 514f6603c60Sopenharmony_ci{ 515f6603c60Sopenharmony_ci int backParam = FAIL; 516f6603c60Sopenharmony_ci napi_value result = nullptr; 517f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 518f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 519f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 520f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 521f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 522f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 523f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 524f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 525f6603c60Sopenharmony_ci OH_VideoDecoder_Configure(videoDec, format); 526f6603c60Sopenharmony_ci OH_VideoDecoder_Prepare(videoDec); 527f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_Start(videoDec); 528f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 529f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_SetParameter(videoDec, format); 530f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 531f6603c60Sopenharmony_ci backParam = SUCCESS; 532f6603c60Sopenharmony_ci OH_VideoDecoder_Stop(videoDec); 533f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 534f6603c60Sopenharmony_ci } 535f6603c60Sopenharmony_ci } 536f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 537f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 538f6603c60Sopenharmony_ci return result; 539f6603c60Sopenharmony_ci} 540f6603c60Sopenharmony_ci 541f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderPushInputData(napi_env env, napi_callback_info info) 542f6603c60Sopenharmony_ci{ 543f6603c60Sopenharmony_ci int backParam = FAIL; 544f6603c60Sopenharmony_ci napi_value result = nullptr; 545f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 546f6603c60Sopenharmony_ci uint32_t index = PARAM_1; 547f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 548f6603c60Sopenharmony_ci OH_AVFormat *format = nullptr; 549f6603c60Sopenharmony_ci format = OH_AVFormat_Create(); 550f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH); 551f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT); 552f6603c60Sopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT); 553f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 554f6603c60Sopenharmony_ci OH_AVCodecBufferAttr info_; 555f6603c60Sopenharmony_ci info_.offset = 0; 556f6603c60Sopenharmony_ci info_.flags = AVCODEC_BUFFER_FLAGS_NONE; 557f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_PushInputData(videoDec, index, info_); 558f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 559f6603c60Sopenharmony_ci backParam = SUCCESS; 560f6603c60Sopenharmony_ci } 561f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 562f6603c60Sopenharmony_ci OH_AVFormat_Destroy(format); 563f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 564f6603c60Sopenharmony_ci return result; 565f6603c60Sopenharmony_ci} 566f6603c60Sopenharmony_ci 567f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderPushInputBuffer(napi_env env, napi_callback_info info) 568f6603c60Sopenharmony_ci{ 569f6603c60Sopenharmony_ci int backParam = FAIL; 570f6603c60Sopenharmony_ci napi_value result = nullptr; 571f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 572f6603c60Sopenharmony_ci uint32_t index = PARAM_1; 573f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 574f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 575f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_PushInputBuffer(videoDec, index); 576f6603c60Sopenharmony_ci if (checkParam != AV_ERR_OK) { 577f6603c60Sopenharmony_ci backParam = SUCCESS; 578f6603c60Sopenharmony_ci } 579f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 580f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 581f6603c60Sopenharmony_ci return result; 582f6603c60Sopenharmony_ci} 583f6603c60Sopenharmony_ci 584f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderFreeOutputBuffer(napi_env env, napi_callback_info info) 585f6603c60Sopenharmony_ci{ 586f6603c60Sopenharmony_ci int backParam = FAIL; 587f6603c60Sopenharmony_ci napi_value result = nullptr; 588f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 589f6603c60Sopenharmony_ci uint32_t index = PARAM_1; 590f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 591f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 592f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_FreeOutputBuffer(videoDec, index); 593f6603c60Sopenharmony_ci if (checkParam != AV_ERR_OK) { 594f6603c60Sopenharmony_ci backParam = SUCCESS; 595f6603c60Sopenharmony_ci } 596f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 597f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 598f6603c60Sopenharmony_ci return result; 599f6603c60Sopenharmony_ci} 600f6603c60Sopenharmony_ci 601f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderRenderOutputData(napi_env env, napi_callback_info info) 602f6603c60Sopenharmony_ci{ 603f6603c60Sopenharmony_ci int backParam = FAIL; 604f6603c60Sopenharmony_ci napi_value result = nullptr; 605f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 606f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 607f6603c60Sopenharmony_ci uint32_t index = PARAM_1; 608f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 609f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_RenderOutputData(videoDec, index); 610f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 611f6603c60Sopenharmony_ci backParam = SUCCESS; 612f6603c60Sopenharmony_ci OH_VideoDecoder_Stop(videoDec); 613f6603c60Sopenharmony_ci } 614f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 615f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 616f6603c60Sopenharmony_ci return result; 617f6603c60Sopenharmony_ci} 618f6603c60Sopenharmony_ci 619f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderRenderOutputBuffer(napi_env env, napi_callback_info info) 620f6603c60Sopenharmony_ci{ 621f6603c60Sopenharmony_ci int backParam = FAIL; 622f6603c60Sopenharmony_ci napi_value result = nullptr; 623f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 624f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 625f6603c60Sopenharmony_ci uint32_t index = PARAM_1; 626f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 627f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_RenderOutputBuffer(videoDec, index); 628f6603c60Sopenharmony_ci if (checkParam != AV_ERR_OK) { 629f6603c60Sopenharmony_ci backParam = SUCCESS; 630f6603c60Sopenharmony_ci OH_VideoDecoder_Stop(videoDec); 631f6603c60Sopenharmony_ci } 632f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 633f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 634f6603c60Sopenharmony_ci return result; 635f6603c60Sopenharmony_ci} 636f6603c60Sopenharmony_ci 637f6603c60Sopenharmony_cistatic napi_value OHVideoDecoderIsValid(napi_env env, napi_callback_info info) 638f6603c60Sopenharmony_ci{ 639f6603c60Sopenharmony_ci int backParam = FAIL; 640f6603c60Sopenharmony_ci napi_value result = nullptr; 641f6603c60Sopenharmony_ci OH_AVCodec *videoDec = nullptr; 642f6603c60Sopenharmony_ci OH_AVErrCode checkParam; 643f6603c60Sopenharmony_ci bool status = true; 644f6603c60Sopenharmony_ci videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); 645f6603c60Sopenharmony_ci checkParam = OH_VideoDecoder_IsValid(videoDec, &status); 646f6603c60Sopenharmony_ci if (checkParam == AV_ERR_OK) { 647f6603c60Sopenharmony_ci backParam = SUCCESS; 648f6603c60Sopenharmony_ci OH_VideoDecoder_Stop(videoDec); 649f6603c60Sopenharmony_ci } 650f6603c60Sopenharmony_ci OH_VideoDecoder_Destroy(videoDec); 651f6603c60Sopenharmony_ci napi_create_int32(env, backParam, &result); 652f6603c60Sopenharmony_ci return result; 653f6603c60Sopenharmony_ci} 654f6603c60Sopenharmony_ci 655f6603c60Sopenharmony_ciEXTERN_C_START 656f6603c60Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports) 657f6603c60Sopenharmony_ci{ 658f6603c60Sopenharmony_ci napi_property_descriptor desc[] = { 659f6603c60Sopenharmony_ci {"oHVideoDecoderCreateByMime", nullptr, OHVideoDecoderCreateByMime, nullptr, nullptr, nullptr, napi_default, 660f6603c60Sopenharmony_ci nullptr}, 661f6603c60Sopenharmony_ci {"oHVideoDecoderCreateByName", nullptr, OHVideoDecoderCreateByName, nullptr, nullptr, nullptr, napi_default, 662f6603c60Sopenharmony_ci nullptr}, 663f6603c60Sopenharmony_ci {"oHVideoDecoderDestroy", nullptr, OHVideoDecoderDestroy, nullptr, nullptr, nullptr, napi_default, nullptr}, 664f6603c60Sopenharmony_ci {"oHVideoDecoderConfigure", nullptr, OHVideoDecoderConfigure, nullptr, nullptr, nullptr, napi_default, nullptr}, 665f6603c60Sopenharmony_ci {"oHVideoDecoderPrepare", nullptr, OHVideoDecoderPrepare, nullptr, nullptr, nullptr, napi_default, nullptr}, 666f6603c60Sopenharmony_ci {"oHVideoDecoderStart", nullptr, OHVideoDecoderStart, nullptr, nullptr, nullptr, napi_default, nullptr}, 667f6603c60Sopenharmony_ci {"oHVideoDecoderStop", nullptr, OHVideoDecoderStop, nullptr, nullptr, nullptr, napi_default, nullptr}, 668f6603c60Sopenharmony_ci {"oHVideoDecoderFlush", nullptr, OHVideoDecoderFlush, nullptr, nullptr, nullptr, napi_default, nullptr}, 669f6603c60Sopenharmony_ci {"oHVideoDecoderReset", nullptr, OHVideoDecoderReset, nullptr, nullptr, nullptr, napi_default, nullptr}, 670f6603c60Sopenharmony_ci {"oHVideoDecoderGetOutputDescription", nullptr, OHVideoDecoderGetOutputDescription, nullptr, nullptr, nullptr, 671f6603c60Sopenharmony_ci napi_default, nullptr}, 672f6603c60Sopenharmony_ci {"oHVideoDecoderSetParameter", nullptr, OHVideoDecoderSetParameter, nullptr, nullptr, nullptr, napi_default, 673f6603c60Sopenharmony_ci nullptr}, 674f6603c60Sopenharmony_ci {"oHVideoDecoderPushInputData", nullptr, OHVideoDecoderPushInputData, nullptr, nullptr, nullptr, napi_default, 675f6603c60Sopenharmony_ci nullptr}, 676f6603c60Sopenharmony_ci {"oHVideoDecoderRenderOutputData", nullptr, OHVideoDecoderRenderOutputData, nullptr, nullptr, nullptr, 677f6603c60Sopenharmony_ci napi_default, nullptr}, 678f6603c60Sopenharmony_ci {"oHVideoDecoderIsValid", nullptr, OHVideoDecoderIsValid, nullptr, nullptr, nullptr, napi_default, nullptr}, 679f6603c60Sopenharmony_ci {"oHVideoDecoderSetCallback", nullptr, OHVideoDecoderSetCallback, nullptr, nullptr, nullptr, napi_default, 680f6603c60Sopenharmony_ci nullptr}, 681f6603c60Sopenharmony_ci {"oHVideoDecoderRegisterCallback", nullptr, OHVideoDecoderRegisterCallback, nullptr, nullptr, nullptr, napi_default, 682f6603c60Sopenharmony_ci nullptr}, 683f6603c60Sopenharmony_ci {"oHVideoDecoderPushInputBuffer", nullptr, OHVideoDecoderPushInputBuffer, nullptr, nullptr, nullptr, napi_default, 684f6603c60Sopenharmony_ci nullptr}, 685f6603c60Sopenharmony_ci {"oHVideoDecoderFreeOutputBuffer", nullptr, OHVideoDecoderFreeOutputBuffer, nullptr, nullptr, nullptr, napi_default, 686f6603c60Sopenharmony_ci nullptr}, 687f6603c60Sopenharmony_ci {"oHVideoDecoderRenderOutputBuffer", nullptr, OHVideoDecoderRenderOutputBuffer, nullptr, nullptr, nullptr, 688f6603c60Sopenharmony_ci napi_default, nullptr}, 689f6603c60Sopenharmony_ci }; 690f6603c60Sopenharmony_ci napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); 691f6603c60Sopenharmony_ci return exports; 692f6603c60Sopenharmony_ci} 693f6603c60Sopenharmony_ciEXTERN_C_END 694f6603c60Sopenharmony_ci 695f6603c60Sopenharmony_cistatic napi_module demoModule = { 696f6603c60Sopenharmony_ci .nm_version = 1, 697f6603c60Sopenharmony_ci .nm_flags = 0, 698f6603c60Sopenharmony_ci .nm_filename = nullptr, 699f6603c60Sopenharmony_ci .nm_register_func = Init, 700f6603c60Sopenharmony_ci .nm_modname = "libvideodecoderndk", 701f6603c60Sopenharmony_ci .nm_priv = ((void *)0), 702f6603c60Sopenharmony_ci .reserved = { 0 }, 703f6603c60Sopenharmony_ci}; 704f6603c60Sopenharmony_ci 705f6603c60Sopenharmony_ciextern "C" __attribute__((constructor)) void RegisterModule(void) 706f6603c60Sopenharmony_ci{ 707f6603c60Sopenharmony_ci napi_module_register(&demoModule); 708f6603c60Sopenharmony_ci} 709