diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/.gitignore b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/app.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..be1a0f439ff9844418447f6fc90be35d9611628b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + { + "app": { + "bundleName": "com.samples.avtranscoderndk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3887d20d5a745fdc056cb1d7bb93431c3752d481 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVTranscoderNDK" + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/README.md b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a2b88f48607a714bd4007c636abb629c57173744 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/README.md @@ -0,0 +1,69 @@ +# AVTranscoderNDK + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->使用AVTranscoder实现视频转码(C/C++)的配套示例工程。 + +本示例以“开始转码-暂停转码-恢复转码-转码完成”的一次流程为示例,展示AVTranscoder视频转码相关功能。 + +## 效果预览 + +| 预览 | +| ------------------------------------------------------------ | +| | + +## 使用说明 +1. 安装编译生成的hap包,并打开应用; +2. 点击启动转码按钮,之后可从设置的沙箱路径导出生成的转码视频; + +## 工程目录 + +``` +AVTranscoderNDK +entry/src/main/ets/ +└── pages + └── Index.ets (转码界面) +entry/src/main/ +├── cpp +│ ├── types +│ │ └── libentry +│ │ └── Index.d.ts (NDK函数对应的js映射) +│ ├── CMakeLists.txt (CMake脚本) +│ └── napi_init.cpp (NDK函数) +└── resources + ├── base + │ ├── element + │ │ ├── color.json + │ │ ├── float.json + │ │ └── string.json + └── rawfile + └── src.mp4 (视频资源) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.3.900,构建 2024年10月8日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/build-profile.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5791c644097643ca98cf578197a7b9b33c043e27 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/.gitignore b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/build-profile.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cfc804ca1fe8c314b8cb45e6990c4b8032944af1 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "x86_64", "armeabi-v7a"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/hvigorfile.ts b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..75d2e499a804dc9c4875b133326ee877cc980c65 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0819d23bd94b2332532735469c1e40d4aea424e9 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(AVTranscoderNDK) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libavtranscoder.so) \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18c6e45d0257bd3a79ef72163d23d8f8bc4f0dff --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "napi/native_api.h" +#include +#include +#include +#include "multimedia/player_framework/avtranscoder.h" +#include "multimedia/player_framework/avtranscoder_base.h" +#include +#include +#include +#include +#include +#include +#define FAIL (-1) +#define SUCCESS 0 +#define PARAM_0 0 +#define PARAM_1 1 +#define PARAM_2 2 +#define PARAM_3 3 +#define PARAM_4 4 +#define LOG_MSG_TAG "AVTransCoderNdk" +#define LOG(format, ...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, 0xFF00, LOG_MSG_TAG, format, ##__VA_ARGS__)) +#define LOGE(format, ...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, LOG_MSG_TAG, format, ##__VA_ARGS__)) +#define LOGD(format, ...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, 0xFF00, LOG_MSG_TAG, format, ##__VA_ARGS__)) +const std::string CREATEAVTRANSCODER_EVENT = "create"; +const std::string PREPAREAVTRANSCODER_EVENT = "prepare"; +const std::string STARTAVTRANSCODER_EVENT = "setVideoType"; +const std::string PAUSEAVTRANSCODER_EVENT = "pause"; +const std::string RESUMEAVTRANSCODER_EVENT = "resume"; +const std::string CANCELAVTRANSCODER_EVENT = "cancel"; +const std::string RELEASEAVTRANSCODER_EVENT = "release"; +const std::string ERROR_EVENT = "error"; +const std::string END_EVENT = "end"; +const std::int32_t AUDIO_BITRATE = 200000; +const std::int32_t VIDEO_BITRATE = 3000000; + +typedef struct NdkAVTransCoderUser { + using StateChangeFunc = std::function; + NdkAVTransCoderUser(); + NdkAVTransCoderUser(const NdkAVTransCoderUser &other) = delete; + NdkAVTransCoderUser &operator=(const NdkAVTransCoderUser &other) = delete; + ~NdkAVTransCoderUser(); + + void OnStateChangeCb(OH_AVTranscoder *transcoder, OH_AVTranscoder_State state); + void OnErrorCb(OH_AVTranscoder *transcoder, int32_t errorCode, const char *errorMsg); + void OnProgressUpdateCb(OH_AVTranscoder *transcoder, int progress); + std::map stateChangeFuncs_; + + OH_AVTranscoder *transcoder = nullptr; + int32_t errorCode = AV_ERR_OK; + OH_AVTranscoder_State transCoderState = AVTRANSCODER_PREPARED; + int avTranscoderProgress = 0; + int inStartStateCount = 0; +} NdkAVTransCoderUser; +NdkAVTransCoderUser::NdkAVTransCoderUser() {} +NdkAVTransCoderUser::~NdkAVTransCoderUser() {} + +typedef struct NdkAVTransCoderContext { + NdkAVTransCoderUser *transcoderUser = nullptr; + OH_AVTranscoder *transcoder = nullptr; + OH_AVTranscoder_Config *config = nullptr; + OH_AVTranscoder_State transCoderState = AVTRANSCODER_PREPARED; +} NdkAVTransCoderContext; +static NdkAVTransCoderContext g_ctx; + +void NdkAVTransCoderUser::OnProgressUpdateCb(OH_AVTranscoder *transcoder, int progress) +{ + LOG("NdkAVTransCoderUser OnProgressUpdateCb progress: %{public}d", progress); + this->avTranscoderProgress = progress; +} + +void NdkAVTransCoderUser::OnErrorCb(OH_AVTranscoder *transcoder, int32_t errorCode, const char *errorMsg) +{ + LOG("NdkAVTransCoderUser OnErrorCb errorCode: %{public}d ,errorMsg: %{public}s", errorCode, + errorMsg == nullptr ? "unknown" : errorMsg); + this->errorCode = errorCode; +} + +void NdkAVTransCoderUser::OnStateChangeCb(OH_AVTranscoder *transcoder, OH_AVTranscoder_State state) +{ + this->transCoderState = state; + if (transcoder == nullptr) { + return; + } + int32_t ret = -1; + switch (state) { + case AVTRANSCODER_PREPARED: { + this->transCoderState = AVTRANSCODER_PREPARED; + if (this->stateChangeFuncs_.count(AVTRANSCODER_PREPARED) > 0) { + this->stateChangeFuncs_[AVTRANSCODER_PREPARED](); + } + break; + } + case AVTRANSCODER_STARTED: { + this->transCoderState = AVTRANSCODER_STARTED; + if (this->stateChangeFuncs_.count(AVTRANSCODER_STARTED) > 0) { + this->stateChangeFuncs_[AVTRANSCODER_STARTED](); + } + break; + } + case AVTRANSCODER_PAUSED: { + this->transCoderState = AVTRANSCODER_PAUSED; + if (this->stateChangeFuncs_.count(AVTRANSCODER_PAUSED) > 0) { + this->stateChangeFuncs_[AVTRANSCODER_PAUSED](); + } + break; + } + case AVTRANSCODER_CANCELLED: { + this->transCoderState = AVTRANSCODER_CANCELLED; + if (this->stateChangeFuncs_.count(AVTRANSCODER_CANCELLED) > 0) { + this->stateChangeFuncs_[AVTRANSCODER_CANCELLED](); + } + break; + } + case AVTRANSCODER_COMPLETED: { + this->transCoderState = AVTRANSCODER_COMPLETED; + if (this->stateChangeFuncs_.count(AVTRANSCODER_COMPLETED) > 0) { + this->stateChangeFuncs_[AVTRANSCODER_COMPLETED](); + } + break; + } + default: + break; + } +} + +static void AvTranscoderStateChangeCbImpl(OH_AVTranscoder *transcoder, OH_AVTranscoder_State state, void *userData) +{ + LOG("AvTranscoderStateChangeCbImpl state: %{public}d", state); + NdkAVTransCoderUser *ndkAVTransCoderUser = reinterpret_cast(userData); + if (ndkAVTransCoderUser == nullptr || transcoder == nullptr) { + LOGE("AvTranscoderStateChangeCbImpl ndkAVTransCoderUser or transcoder is nullptr"); + return; + } + ndkAVTransCoderUser->OnStateChangeCb(transcoder, state); +} + +static void AvTranscoderErrorCbImpl(OH_AVTranscoder *transcoder, int32_t errorCode, const char *errorMsg, + void *userData) +{ + LOG("AvTranscoderErrorCbImpl errorCode: %{public}d, errorMsg: %{public}s", errorCode, + errorMsg == nullptr ? "unknown" : errorMsg); + NdkAVTransCoderUser *ndkAVTransCoderUser = reinterpret_cast(userData); + if (ndkAVTransCoderUser == nullptr || transcoder == nullptr) { + LOGE("AvTranscoderErrorCbImpl ndkAVTransCoderUser or transcoder is nullptr"); + return; + } + ndkAVTransCoderUser->OnErrorCb(transcoder, errorCode, errorMsg); +} + +static void AvTranscoderProgressUpdateCbImpl(OH_AVTranscoder *transcoder, int progress, void *userData) +{ + LOG("AvTranscoderProgressUpdateCbImpl progress: %{public}d", progress); + NdkAVTransCoderUser *ndkAVTransCoderUser = reinterpret_cast(userData); + if (ndkAVTransCoderUser == nullptr || transcoder == nullptr) { + LOGE("AvTranscoderProgressUpdateCbImpl ndkAVTransCoderUser or transcoder is nullptr"); + return; + } + ndkAVTransCoderUser->OnProgressUpdateCb(transcoder, progress); +} + +static OH_AVTranscoder_Config *createDefaultTransCoderConfig(int32_t dstFd) +{ + OH_AVTranscoder_Config *config = OH_AVTranscoderConfig_Create(); + OH_AVTranscoderConfig_SetDstFD(config, dstFd); // 设置转码的目标文件属dstFd。 + OH_AVTranscoderConfig_SetDstFileType(config, AV_OUTPUT_FORMAT_MPEG_4); // 封装格式。 + OH_AVTranscoderConfig_SetDstVideoType(config, "video/avc"); // 视频编码格式,可选。 + OH_AVTranscoderConfig_SetDstAudioType(config, "audio/mp4a-latm"); // 音频编码格式,可选。 + OH_AVTranscoderConfig_SetDstAudioBitrate(config, AUDIO_BITRATE); // 音频比特率,可选。 + OH_AVTranscoderConfig_SetDstVideoBitrate(config, VIDEO_BITRATE); // 视频比特率,可选。 + return config; +} +static napi_value OHAvTranscoderNdkPlay(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + int backParam = FAIL; + size_t argc = PARAM_4; + napi_value args[PARAM_4] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + int32_t srcFd = PARAM_0; + napi_get_value_int32(env, args[PARAM_0], &srcFd); + int64_t srcOffset = PARAM_0; + napi_get_value_int64(env, args[PARAM_1], &srcOffset); + int64_t length = PARAM_0; + napi_get_value_int64(env, args[PARAM_2], &length); + int32_t dstFd = PARAM_0; + napi_get_value_int32(env, args[PARAM_3], &dstFd); + + OH_AVTranscoder *transcoder = OH_AVTranscoder_Create(); + NdkAVTransCoderUser *transcoderUser = nullptr; + transcoderUser = new NdkAVTransCoderUser(); + transcoderUser->transcoder = transcoder; + g_ctx.transcoder = transcoder; + g_ctx.config = createDefaultTransCoderConfig(dstFd); + + OH_AVTranscoderConfig_SetSrcFD(g_ctx.config, srcFd, srcOffset, length); // 设置转码源视频FD + OH_AVTranscoder_SetStateCallback(transcoder, AvTranscoderStateChangeCbImpl, transcoderUser); // 设置状态回调 + OH_AVTranscoder_SetErrorCallback(transcoder, AvTranscoderErrorCbImpl, transcoderUser); // 设置错误码回调 + OH_AVTranscoder_SetProgressUpdateCallback(transcoder, AvTranscoderProgressUpdateCbImpl, transcoderUser); // 设置进度值回调 + g_ctx.transcoderUser = transcoderUser; + transcoderUser->stateChangeFuncs_ = {{AVTRANSCODER_PREPARED, [transcoderUser]() { + // 状态为AVTRANSCODER_PREPARED时开始转码 + OH_AVErrCode errCode = OH_AVTranscoder_Start(transcoderUser->transcoder); + transcoderUser->errorCode = errCode; + LOG("OH_AVTranscoder_Start errCode:%{public}d", errCode); + }}}; + OH_AVErrCode errCode = AV_ERR_OK; + if (errCode == AV_ERR_OK) { + errCode = OH_AVTranscoder_Prepare(transcoder, g_ctx.config); + } else { + backParam = errCode; + } + LOG("Transcoder OHAvTranscoderConfigSetDstVideoType ret %{public}d", backParam); + napi_create_int32(env, backParam, &result); + return result; +} + +static napi_value OHAvTranscoderNdkPause(napi_env env, napi_callback_info info) +{ + int ret = 100; + ret = OH_AVTranscoder_Pause(g_ctx.transcoder); // 暂停转码 + LOG("OH_AVTranscoder_Pause ret:%{public}d", ret); + napi_value value; + napi_create_int32(env, ret, &value); + return value; +} + +static napi_value OHAvTranscoderNdkResume(napi_env env, napi_callback_info info) +{ + int ret = 100; + ret = OH_AVTranscoder_Resume(g_ctx.transcoder); // 恢复转码 + LOG("OH_AVTranscoder_Resume ret:%{public}d", ret); + napi_value value; + napi_create_int32(env, ret, &value); + return value; +} + +static napi_value OHAvTranscoderNdkCancel(napi_env env, napi_callback_info info) +{ + int ret = 100; + ret = OH_AVTranscoder_Cancel(g_ctx.transcoder); // 取消转码 + LOG("OH_AVTranscoder_Cancel ret:%{public}d", ret); + napi_value value; + napi_create_int32(env, ret, &value); + return value; +} + +static napi_value OHAvTranscoderNdkRelease(napi_env env, napi_callback_info info) +{ + int ret = 100; + LOG("OH_AVTranscoder_Release ret:%{public}d", ret); + if (g_ctx.transcoder != nullptr) { + ret = OH_AVTranscoder_Release(g_ctx.transcoder); // 释放转码实例 + LOG("OH_AVTranscoder_Release ret:%{public}d", ret); + g_ctx.transcoder = nullptr; + } + if (g_ctx.config != nullptr) { + ret = OH_AVTranscoderConfig_Release(g_ctx.config); // 释放转码配置实例 + LOG("OH_AVTranscoderConfig_Release ret:%{public}d", ret); + g_ctx.config = nullptr; + } + napi_value value; + napi_create_int32(env, ret, &value); + return value; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"AvTranscoderNdkPlay", nullptr, OHAvTranscoderNdkPlay, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"AvTranscoderNdkPause", nullptr, OHAvTranscoderNdkPause, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"AvTranscoderNdkResume", nullptr, OHAvTranscoderNdkResume, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"AvTranscoderNdkCancel", nullptr, OHAvTranscoderNdkCancel, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"AvTranscoderNdkRelease", nullptr, OHAvTranscoderNdkRelease, nullptr, nullptr, nullptr, napi_default, + nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..0389b1c397e6129321ae44bdc3632249101f1952 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const AvTranscoderNdkPlay: (srcFd: number, srcOffset: number,length: number, dstFd: number) => number; +export const AvTranscoderNdkPause: () => number; +export const AvTranscoderNdkResume: () => number; +export const AvTranscoderNdkCancel: () => number; +export const AvTranscoderNdkRelease: () => number; diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c69ca2198f11d3288b2ac61227a583604b647c78 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..815478a2d52cf36f2ec6056948d18c9deec58522 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5fcdbb5f2d104864e59a8099c489b14c938652ff --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1e5ee41ed8de583a7f8bc98786f07dbf52fdfbb --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import testNapi from 'libentry.so'; +import fs from '@ohos.file.fs'; +import { BusinessError } from '@kit.BasicServicesKit'; +import resourceManager from '@ohos.resourceManager'; + +@Entry +@Component +struct Index { + @State message: string = '启动转码'; + @State progress: number = 0; + private context: Context | undefined = this.getUIContext().getHostContext(); + private src: resourceManager.RawFileDescriptor | undefined = undefined; + private dst: fs.File | undefined = undefined; + + getFileFd(fileName: string) { + let pathName = getContext().filesDir + '/' + fileName; + console.log('pathName is ' + pathName) + let file: fs.File = fs.openSync(pathName, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + return file; + } + + async start() { + if (!this.context) { + console.log('context is null') + return; + } + this.src = this.context.resourceManager.getRawFdSync('src.mp4'); + this.dst = this.getFileFd('out.mp4'); + try { + let errCode = testNapi.AvTranscoderNdkPlay(this.src.fd, this.src.offset, this.src.length, this.dst.fd) + console.log('AvTranscoderNdkPlay success: ' + JSON.stringify(errCode)); + } catch (err) { + let error = err as BusinessError; + console.log('AvTranscoderNdkPlay err:' + error); + return; + } + } + + aboutToDisappear(): void { + testNapi.AvTranscoderNdkRelease(); // 释放转码实例。 + if (this.src) { + fs.closeSync(this.src.fd); + } + if (this.dst) { + fs.closeSync(this.dst.fd); + } + } + + build() { + Row() { + Column({ space: 12 }) { + Button($r('app.string.AVTranscoder_start')) + .id('AVTranscoderStart') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.start(); // 开始转码。 + }) + Button($r('app.string.AVTranscoder_pause')) + .id('AVTranscoderPause') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + testNapi.AvTranscoderNdkPause(); //暂停转码。 + }) + Button($r('app.string.AVTranscoder_resume')) + .id('AVTranscoderResume') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + testNapi.AvTranscoderNdkResume(); // 恢复转码。 + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/module.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..78a72362efdf4ef6d9c8400b25527133d926dd45 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c8e2de9d5cd9528164b461bd80502c3cac1ac4dd --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "视频转码C++示例" + }, + { + "name": "AVTranscoder_start", + "value": "启动转码" + }, + { + "name": "AVTranscoder_pause", + "value": "暂停转码" + }, + { + "name": "AVTranscoder_resume", + "value": "恢复转码" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..67b655257d016546a4d2b29ad0440aaadb2f213c --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "AVTranscoder_start", + "value": "start" + }, + { + "name": "AVTranscoder_pause", + "value": "pause" + }, + { + "name": "AVTranscoder_resume", + "value": "resume" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/rawfile/src.mp4 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/rawfile/src.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..69ae5c519a3f27f952590a12af7db6a3483b5e96 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/rawfile/src.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5a813a7a2d33548cf1c76bc33f914c98cd5ada05984a0bb5c8508546f999422 +size 1849540 diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..597ecf95e61d7e30367c22fe2f8638008361b044 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/mock/Libentry.mock.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..bbcd4ffee2dc23d8783fd8a1ac5e5325bc2b5240 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const nativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default nativeMock; \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98b0ae79f0090e1fc381d54c959fb32c9f7563f4 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/mock/mock-config.json5 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..08da22bf79409a6e76ab943762b6364d94ec8e7a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AVTranscoderNDK]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /** + * 启动转码、暂停转码、恢复转码 + */ + it('AVTranscoderTest_001', 0, async (done: Function) => { + console.info(TAG, 'AVTranscoderTest_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button1 = await driver.findComponent(ON.id('AVTranscoderStart')); + await button1.click(); + await driver.delayMs(3000); + const button2 = await driver.findComponent(ON.id('AVTranscoderPause')); + await button2.click(); + await driver.delayMs(3000); + const button3 = await driver.findComponent(ON.id('AVTranscoderResume')); + await button3.click(); + await driver.delayMs(3000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AVTranscoderTest_001 end'); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..15985f07ded51de709b7c68483df86e9071ade0b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/test/List.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e9fe9c6f2d69036c01eee02ac0ac90f0dcd5f5d --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/hvigorfile.ts b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..23fe442f06ed23dedd3c9afdcdc91bcf66bb5d37 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/ohosTest.md b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..b0c031f1fceb9dfe7ea3f7e065eaece56df63a38 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/ohosTest.md @@ -0,0 +1,7 @@ +# AVTranscoderNDK测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并转码 | 设备正常运行 | | 转码成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/screenshots/AVTranscoderNDK.jpeg b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/screenshots/AVTranscoderNDK.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..187f6f87c17ed5e81c2d9b2d30b52fb86bebc252 Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderNDK/screenshots/AVTranscoderNDK.jpeg differ