diff --git a/multimedia/player_framework/avtranscoder.h b/multimedia/player_framework/avtranscoder.h new file mode 100644 index 0000000000000000000000000000000000000000..612afa710639c3aace1976fae4963f04cb4c1a50 --- /dev/null +++ b/multimedia/player_framework/avtranscoder.h @@ -0,0 +1,308 @@ +/* + * 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. + */ + + + /** + * @addtogroup AVTranscoder + * @{ + * + * @brief Provides APIs of request capability for Transcoder. + * + * @syscap SystemCapability.Multimedia.Media.AVTranscoder + * @since 20 + * @} + */ + + /** + * @file avtranscoder.h + * + * @brief Defines the avtranscoder APIs. Uses the Native APIs provided by Media AVTranscoder + * to transcode a source video file to a new video file. + * + * @kit MediaKit + * @library libavtranscoder.so + * @syscap SystemCapability.Multimedia.Media.AVTranscoder + * @since 20 + */ + +#ifndef MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_H +#define MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_H + +#include +#include +#include "avtranscoder_base.h" +#include "native_avcodec_base.h" +#include "native_averrors.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a transcoder config + * @return Returns a pointer to an OH_AVTranscoder_Config instance for success, nullptr for failure + * @since 20 + */ +OH_AVTranscoder_Config *OH_AVTranscoderConfig_Create(); + +/** + * @brief release a transcoder config instance. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance. + * @return @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_Release(OH_AVTranscoder_Config* config); + +/** + * @brief Set Source file descriptor for transcoding. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance. + * @param {int32_t} srcFd Source file descriptor. + * @param {int64_t} srcOffset The offset into the file where the data to be read, in bytes. + * @param {int64_t} length The length in bytes of the data to be read + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or file related parameter error. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetSrcFD( + OH_AVTranscoder_Config *config, int32_t srcFd, int64_t srcOffset, int64_t length); + +/** + * @brief Set destination file descriptor for transcoding. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {int32_t} dstFd Destination file descriptor + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or dstFd is invalid. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstFD(OH_AVTranscoder_Config *config, int32_t dstFd); + +/** + * @brief Set destination video mime type. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {const char*} mimeType Destination video mime type. See native_avcodec_base.h + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or mimeType is unrecognized. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoType(OH_AVTranscoder_Config *config, const char *mimeType); + +/** + * @brief Set destination audio mime type. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {const char*} mimeType Destination audio mime type. See native_avcodec_base.h + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or mimeType is unrecognized. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioType(OH_AVTranscoder_Config *config, const char *mimeType); + +/** + * @brief Set destination file type. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {OH_AVOutputFormat} mimeType Destination file type. See native_avcodec_base.h + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or mimeType is invalid. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstFileType(OH_AVTranscoder_Config *config, OH_AVOutputFormat mimeType); + +/** + * @brief Set destination audio bitrate. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {int32_t} bitrate Destination audio bitrate. + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or bitrate value is invalid. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioBitrate(OH_AVTranscoder_Config *config, int32_t bitrate); + +/** + * @brief Set destination video bitrate. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {int32_t} bitrate Destination video bitrate. + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or bitrate value is invalid. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoBitrate(OH_AVTranscoder_Config *config, int32_t bitrate); + +/** + * @brief Set destination video resolution. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {int32_t} width Destination for video width. + * @param {int32_t} height Destination for video height. + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr or width/height value is invalid. +* @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoResolution(OH_AVTranscoder_Config *config, int32_t width, int32_t height); + +/** + * @brief Create a transcoder + * @return {OH_AVTranscoder*} Returns a pointer to an OH_AVTranscoder instance for success, nullptr for failure + * @since 20 + */ +OH_AVTranscoder *OH_AVTranscoder_Create(void); + +/** + * @brief Prepare for transcoding with a config. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance, + * see {@link OH_AVTranscoder_Config} + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder Prepare failed. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Prepare not allowed. + * {@link AV_ERR_IO} if Errors related to IO access + * {@link AV_ERR_SERVICE_DIED} if media service died. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if unsupported format. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_Prepare(OH_AVTranscoder *transcoder, OH_AVTranscoder_Config *config); + +/** + * @brief Start AVTranscoder. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder start failed. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. + * {@link AV_ERR_IO} if errors related to IO access. + * {@link AV_ERR_SERVICE_DIED} if media service died. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_Start(OH_AVTranscoder *transcoder); + +/** + * @brief Pause AVTranscoder. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder pause failed. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. + * {@link AV_ERR_IO} if errors related to IO access. + * {@link AV_ERR_SERVICE_DIED} if media service died. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_Pause(OH_AVTranscoder *transcoder); + +/** + * @brief Resume AVTranscoder. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder resume failed. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. + * {@link AV_ERR_IO} if errors related to IO access. + * {@link AV_ERR_SERVICE_DIED} if media service died. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_Resume(OH_AVTranscoder *transcoder); + +/** + * @brief Cancel AVTranscoder. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder stop failed. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. + * {@link AV_ERR_IO} if errors related to IO access. + * {@link AV_ERR_SERVICE_DIED} if media service died. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_Cancel(OH_AVTranscoder *transcoder); + +/** + * @brief Release AVTranscoder. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder release failed. + * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. + * {@link AV_ERR_IO} if errors related to IO access. + * {@link AV_ERR_SERVICE_DIED} if media service died. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_Release(OH_AVTranscoder *transcoder); + +/** + * @brief Set the state callback function so that your application can respond to the + * state change events generated by the avtranscoder. This interface must be called before Start is called. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @param {OH_AVTranscoder_OnStateChange} callback State callback function, see {@link OH_AVTranscoder_OnStateChange} + * @param {void*} userData Pointer to user specific data + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or input callback is nullptr. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_SetStateCallback( + OH_AVTranscoder *transcoder, OH_AVTranscoder_OnStateChange callback, void *userData); + +/** + * @brief Set the error callback function so that your application can respond to the + * error events generated by the avtranscoder. This interface must be called before Start is called. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @param {OH_AVTranscoder_OnError} callback Error callback function, see {@link OH_AVTranscoder_OnError} + * @param {void*} userData Pointer to user specific data + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or input callback is nullptr. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_SetErrorCallback( + OH_AVTranscoder *transcoder, OH_AVTranscoder_OnError callback, void *userData); + +/** + * @brief Set the progress updating callback function so that your application can respond to the + * progress updating events generated by the avtranscoder. This interface must be called before Start is called. + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance + * @param {OH_AVTranscoder_OnProgressUpdate} callback Uri callback function, + * see {@link OH_AVTranscoder_OnProgressUpdate} + * @param {void*} userData Pointer to user specific data + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or input callback is nullptr. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoder_SetProgressUpdateCallback( + OH_AVTranscoder *transcoder, OH_AVTranscoder_OnProgressUpdate callback, void *userData); + +/** + * @brief Enable B frame in destination video. + * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance + * @param {bool} enabled Whecher enable B Frame. If this function is not called, B Frame is disabled. + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input config is nullptr. + * @since 20 + */ +OH_AVErrCode OH_AVTranscoderConfig_EnableBFrame(OH_AVTranscoder_Config *config, bool enabled); + +#ifdef __cplusplus +} +#endif + +#endif // MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_H \ No newline at end of file diff --git a/multimedia/player_framework/avtranscoder/BUILD.gn b/multimedia/player_framework/avtranscoder/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..044f95901f9a75e227a50be7ea35ecceda204f0f --- /dev/null +++ b/multimedia/player_framework/avtranscoder/BUILD.gn @@ -0,0 +1,35 @@ +# 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("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +import("//foundation/multimedia/player_framework/config.gni") + +ohos_ndk_headers("avtranscoder_header") { + dest_dir = "$ndk_headers_out_dir/multimedia/player_framework" + sources = [ + "../avtranscoder.h", + "../avtranscoder_base.h", + ] +} + +ohos_ndk_library("libavtranscoder") { + ndk_description_file = "./libavtranscoder.ndk.json" + output_name = "avtranscoder" + output_extension = "so" + system_capability = "SystemCapability.Multimedia.Media.AVTranscoder" + system_capability_headers = [ + "multimedia/player_framework/avtranscoder.h", + "multimedia/player_framework/avtranscoder_base.h", + ] +} diff --git a/multimedia/player_framework/avtranscoder/libavtranscoder.ndk.json b/multimedia/player_framework/avtranscoder/libavtranscoder.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..ed2798acef8df285ee2a437dcacd66751fb6bdb9 --- /dev/null +++ b/multimedia/player_framework/avtranscoder/libavtranscoder.ndk.json @@ -0,0 +1,82 @@ +[ + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_Create" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_Release" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetSrcFD" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstFD" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstVideoType" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstAudioType" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstFileType" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstAudioBitrate" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstVideoBitrate" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoderConfig_SetDstVideoResolution" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Create" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Prepare" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Start" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Pause" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Resume" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Cancel" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_Release" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_SetStateCallback" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_SetErrorCallback" + }, + { + "first_introduced": "20", + "name": "OH_AVTranscoder_SetProgressUpdateCallback" + } +] \ No newline at end of file diff --git a/multimedia/player_framework/avtranscoder_base.h b/multimedia/player_framework/avtranscoder_base.h new file mode 100644 index 0000000000000000000000000000000000000000..5334a697e34c5de0b6d06f4311b460d046519570 --- /dev/null +++ b/multimedia/player_framework/avtranscoder_base.h @@ -0,0 +1,114 @@ +/* + * 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. + */ + +/** + * @addtogroup AVTranscoder + * @{ + * + * @brief Provides APIs of request capability for Transcoder. + * + * @syscap SystemCapability.Multimedia.Media.AVTranscoder + * @since 20 + * @} + */ + +/** + * @file avtranscoder_base.h + * + * @brief Defines the structure and enumeration for Media AVTranscoder. + * + * @kit MediaKit + * @library libavtranscoder.so + * @syscap SystemCapability.Multimedia.Media.AVTranscoder + * @since 20 + */ + +#ifndef MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_BASE_H +#define MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_BASE_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief definiton of avtranscoder + * @since 20 +*/ +typedef struct OH_AVTranscoder OH_AVTranscoder; + +/** + * @brief definiton of avtranscoder config + * @since 20 + */ +typedef struct OH_AVTranscoder_Config OH_AVTranscoder_Config; + +/** + * @brief Transcoder States + * @since 20 + */ +typedef enum OH_AVTranscoder_State { + /** prepared states */ + AVTRANSCODER_PREPARED = 1, + /** started states */ + AVTRANSCODER_STARTED = 2, + /** paused states */ + AVTRANSCODER_PAUSED = 3, + /** cancelled states */ + AVTRANSCODER_CANCELLED = 4, + /** completed states */ + AVTRANSCODER_COMPLETED = 5 +} OH_AVTranscoder_State; + +/** + * @brief Called when the state changed of current transcoding. + * @param {OH_AVTranscoder*} transcoder The pointer to an OH_AVTranscoder instance. + * @param {OH_AVTranscoder_State} state Indicates the transcoder state. For details, see {@link OH_AVTranscoder_State}. + * @param {void*} userData Pointer to user specific data. + * @since 20 + */ +typedef void (*OH_AVTranscoder_OnStateChange)(OH_AVTranscoder *transcoder, OH_AVTranscoder_State state, void *userData); + +/** + * @brief Called when an error occurred during transcoding + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance. + * @param {int32_t} errorCode Error code. + * {@link AV_ERR_NO_MEMORY} if memery is insufficient. + * {@link AV_ERR_IO} if IO access failed. + * {@link AV_ERR_INVALID_STATE} if The current state does not support this operation. + * {@link AV_ERR_UNSUPPORT} if unsurpport function. + * @param {const char*} errorMsg Error message. + * @param {void*} userData Pointer to user specific data. + * @since 20 + */ +typedef void (*OH_AVTranscoder_OnError)(OH_AVTranscoder *transcoder, int32_t errorCode, const char *errorMsg, + void *userData); + +/** + * @brief Progress indicator function definition, called when transcoding progress is updated + * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance. + * @param {int32_t} progress Transcoding progress. + * @param {void*} userData Pointer to user specific data. + * @since 20 + */ +typedef void (*OH_AVTranscoder_OnProgressUpdate)(OH_AVTranscoder *transcoder, int32_t progress, void *userData); + +#ifdef __cplusplus +} +#endif + +#endif // MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_BASE_H \ No newline at end of file diff --git a/ndk_targets.gni b/ndk_targets.gni index 6609db3e1dd5e597303453542e0ed6f6ca90a186..1881e5df40cde04c90d64ffc0b518d5ca18b23fa 100644 --- a/ndk_targets.gni +++ b/ndk_targets.gni @@ -146,6 +146,8 @@ _ndk_library_targets = [ "//interface/sdk_c/multimedia/player_framework/avmetadata_extractor:avmetadata_extractor_header", "//interface/sdk_c/multimedia/player_framework/avimage_generator:libavimage_generator", "//interface/sdk_c/multimedia/player_framework/avimage_generator:avimage_generator_header", + "//interface/sdk_c/multimedia/player_framework/avtranscoder:libavtranscoder", + "//interface/sdk_c/multimedia/player_framework/avtranscoder:avtranscoder_header", "//interface/sdk_c/multimedia/audio_framework:libohaudio_ndk", "//interface/sdk_c/multimedia/audio_framework:ohaudio_header", "//interface/sdk_c/multimedia/av_session:libohavsession_ndk",