1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup AVMuxer 18 * @{ 19 * 20 * @brief The AVMuxer module provides functions for audio and video muxer. 21 * 22 * @syscap SystemCapability.Multimedia.Media.Muxer 23 * @since 10 24 */ 25 26 /** 27 * @file native_avmuxer.h 28 * 29 * @brief Declare the Native API used for audio and video muxer. 30 * 31 * @kit AVCodecKit 32 * @library libnative_media_avmuxer.so 33 * @syscap SystemCapability.Multimedia.Media.Muxer 34 * @since 10 35 */ 36 37 #ifndef NATIVE_AVMUXER_H 38 #define NATIVE_AVMUXER_H 39 40 #include <stdint.h> 41 #include <stdio.h> 42 #include "native_avcodec_base.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /** 49 * @brief Forward declaration of OH_AVMuxer. 50 * 51 * @since 10 52 */ 53 typedef struct OH_AVMuxer OH_AVMuxer; 54 55 /** 56 * @brief Create an OH_AVMuxer instance by output file description and format. 57 * @syscap SystemCapability.Multimedia.Media.Muxer 58 * @param fd Must be opened with read and write permission. Caller is responsible for closing fd. 59 * @param format The output format is {@link OH_AVOutputFormat} . 60 * @return Returns a pointer to an OH_AVMuxer instance, needs to be freed by OH_AVMuxer_Destroy. 61 * @since 10 62 */ 63 OH_AVMuxer *OH_AVMuxer_Create(int32_t fd, OH_AVOutputFormat format); 64 65 /** 66 * @brief Set the rotation for output video playback. 67 * Note: This interface can only be called before OH_AVMuxer_Start. 68 * @syscap SystemCapability.Multimedia.Media.Muxer 69 * @param muxer Pointer to an OH_AVMuxer instance. 70 * @param rotation The supported angles are 0, 90, 180, and 270 degrees. 71 * @return Returns AV_ERR_OK if the execution is successful, 72 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 73 * {@link AV_ERR_INVALID_VAL}, the muxer or rotation invalid. 74 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 75 * @since 10 76 */ 77 OH_AVErrCode OH_AVMuxer_SetRotation(OH_AVMuxer *muxer, int32_t rotation); 78 79 /** 80 * @brief Set format to the muxer. 81 * 82 * @syscap SystemCapability.Multimedia.Media.Muxer 83 * @param muxer Pointer to an OH_AVMuxer instance 84 * @param format OH_AVFormat handle pointer contain format 85 * @return Returns AV_ERR_OK if the execution is successful 86 * {@link AV_ERR_INVALID_VAL}, the muxer or format is invalid 87 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state 88 * @since 14 89 */ 90 OH_AVErrCode OH_AVMuxer_SetFormat(OH_AVMuxer *muxer, OH_AVFormat *format); 91 92 /** 93 * @brief Add track format to the muxer. 94 * Note: This interface can only be called before OH_AVMuxer_Start. 95 * @syscap SystemCapability.Multimedia.Media.Muxer 96 * @param muxer Pointer to an OH_AVMuxer instance 97 * @param trackIndex The int32_t handle pointer used to get the track index for this newly added track, 98 * and it should be used in the OH_AVMuxer_WriteSample. The track index is greater than or equal to 0, 99 * others is error index. 100 * @param trackFormat OH_AVFormat handle pointer contain track format 101 * @return Returns AV_ERR_OK if the execution is successful, 102 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 103 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or trackFormat invalid. 104 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 105 * {@link AV_ERR_UNSUPPORT}, the mime type is not supported. 106 * {@link AV_ERR_NO_MEMORY}, failed to malloc memory. 107 * {@link AV_ERR_UNKNOWN}, unknown error. 108 * @since 10 109 */ 110 OH_AVErrCode OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat); 111 112 /** 113 * @brief Start the muxer. 114 * Note: This interface is called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSample. 115 * @syscap SystemCapability.Multimedia.Media.Muxer 116 * @param muxer Pointer to an OH_AVMuxer instance 117 * @return Returns AV_ERR_OK if the execution is successful, 118 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 119 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 120 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 121 * {@link AV_ERR_UNKNOWN}, unknown error. 122 * @since 10 123 */ 124 OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer); 125 126 /** 127 * @brief Write an encoded sample to the muxer. 128 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 129 * make sure that the samples are written to the right tacks. Also, it needs to make sure the samples for each track are 130 * written in chronological order. 131 * @syscap SystemCapability.Multimedia.Media.Muxer 132 * @param muxer Pointer to an OH_AVMuxer instance 133 * @param trackIndex The track index for this sample 134 * @param sample The encoded or demuxer sample 135 * @param info The buffer information related to this sample {@link OH_AVCodecBufferAttr} 136 * @return Returns AV_ERR_OK if the execution is successful, 137 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 138 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or sample or info invalid. 139 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 140 * {@link AV_ERR_NO_MEMORY}, failed to request memory. 141 * {@link AV_ERR_UNKNOWN}, unknown error. 142 * @deprecated since 11 143 * @useinstead OH_AVMuxer_WriteSampleBuffer 144 * @since 10 145 */ 146 OH_AVErrCode OH_AVMuxer_WriteSample(OH_AVMuxer *muxer, uint32_t trackIndex, 147 OH_AVMemory *sample, OH_AVCodecBufferAttr info); 148 149 /** 150 * @brief Write an encoded sample to the muxer. 151 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 152 * make sure that the samples are written to the right tracks. Also, it needs to make sure the samples for each track 153 * are written in chronological order. 154 * @syscap SystemCapability.Multimedia.Media.Muxer 155 * @param muxer Pointer to an OH_AVMuxer instance 156 * @param trackIndex The track index for this sample 157 * @param sample The encoded or demuxer sample, which including data and buffer information 158 * @return Returns AV_ERR_OK if the execution is successful, 159 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 160 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or sample invalid. 161 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 162 * {@link AV_ERR_NO_MEMORY}, failed to request memory. 163 * {@link AV_ERR_UNKNOWN}, unknown error. 164 * @since 11 165 */ 166 OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, 167 const OH_AVBuffer *sample); 168 169 /** 170 * @brief Stop the muxer. 171 * Note: Once the muxer stops, it can not be restarted. 172 * @syscap SystemCapability.Multimedia.Media.Muxer 173 * @param muxer Pointer to an OH_AVMuxer instance 174 * @return Returns AV_ERR_OK if the execution is successful, 175 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 176 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 177 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 178 * @since 10 179 */ 180 OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer); 181 182 /** 183 * @brief Clear the internal resources of the muxer and destroy the muxer instance 184 * @syscap SystemCapability.Multimedia.Media.Muxer 185 * @param muxer Pointer to an OH_AVMuxer instance 186 * @return Returns AV_ERR_OK if the execution is successful, 187 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 188 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 189 * @since 10 190 */ 191 OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer); 192 193 #ifdef __cplusplus 194 } 195 #endif 196 197 #endif // NATIVE_AVMUXER_H 198 /** @} */ 199