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 typedef struct OH_AVMuxer OH_AVMuxer; 49 50 /** 51 * @brief Create an OH_AVMuxer instance by output file description and format. 52 * @syscap SystemCapability.Multimedia.Media.Muxer 53 * @param fd Must be opened with read and write permission. Caller is responsible for closing fd. 54 * @param format The output format is {@link OH_AVOutputFormat} . 55 * @return Returns a pointer to an OH_AVMuxer instance, needs to be freed by OH_AVMuxer_Destroy. 56 * @since 10 57 */ 58 OH_AVMuxer *OH_AVMuxer_Create(int32_t fd, OH_AVOutputFormat format); 59 60 /** 61 * @brief Set the rotation for output video playback. 62 * Note: This interface can only be called before OH_AVMuxer_Start. 63 * @syscap SystemCapability.Multimedia.Media.Muxer 64 * @param muxer Pointer to an OH_AVMuxer instance. 65 * @param rotation The supported angles are 0, 90, 180, and 270 degrees. 66 * @return Returns AV_ERR_OK if the execution is successful, 67 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 68 * {@link AV_ERR_INVALID_VAL}, the muxer or rotation invalid. 69 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 70 * @since 10 71 */ 72 OH_AVErrCode OH_AVMuxer_SetRotation(OH_AVMuxer *muxer, int32_t rotation); 73 74 /** 75 * @brief Set format to the muxer. 76 * 77 * @syscap SystemCapability.Multimedia.Media.Muxer 78 * @param muxer Pointer to an OH_AVMuxer instance 79 * @param format OH_AVFormat handle pointer contain format 80 * @return Returns AV_ERR_OK if the execution is successful 81 * {@link AV_ERR_INVALID_VAL}, the muxer or format is invalid 82 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state 83 * @since 14 84 */ 85 OH_AVErrCode OH_AVMuxer_SetFormat(OH_AVMuxer *muxer, OH_AVFormat *format); 86 87 /** 88 * @brief Add track format to the muxer. 89 * Note: This interface can only be called before OH_AVMuxer_Start. 90 * @syscap SystemCapability.Multimedia.Media.Muxer 91 * @param muxer Pointer to an OH_AVMuxer instance 92 * @param trackIndex The int32_t handle pointer used to get the track index for this newly added track, 93 * and it should be used in the OH_AVMuxer_WriteSample. The track index is greater than or equal to 0, 94 * others is error index. 95 * @param trackFormat OH_AVFormat handle pointer contain track format 96 * @return Returns AV_ERR_OK if the execution is successful, 97 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 98 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or trackFormat invalid. 99 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 100 * {@link AV_ERR_UNSUPPORT}, the mime type is not supported. 101 * {@link AV_ERR_NO_MEMORY}, failed to malloc memory. 102 * {@link AV_ERR_UNKNOWN}, unknown error. 103 * @since 10 104 */ 105 OH_AVErrCode OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat); 106 107 /** 108 * @brief Start the muxer. 109 * Note: This interface is called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSample. 110 * @syscap SystemCapability.Multimedia.Media.Muxer 111 * @param muxer Pointer to an OH_AVMuxer instance 112 * @return Returns AV_ERR_OK if the execution is successful, 113 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 114 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 115 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 116 * {@link AV_ERR_UNKNOWN}, unknown error. 117 * @since 10 118 */ 119 OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer); 120 121 /** 122 * @brief Write an encoded sample to the muxer. 123 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 124 * make sure that the samples are written to the right tacks. Also, it needs to make sure the samples for each track are 125 * written in chronological order. 126 * @syscap SystemCapability.Multimedia.Media.Muxer 127 * @param muxer Pointer to an OH_AVMuxer instance 128 * @param trackIndex The track index for this sample 129 * @param sample The encoded or demuxer sample 130 * @param info The buffer information related to this sample {@link OH_AVCodecBufferAttr} 131 * @return Returns AV_ERR_OK if the execution is successful, 132 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 133 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or sample or info invalid. 134 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 135 * {@link AV_ERR_NO_MEMORY}, failed to request memory. 136 * {@link AV_ERR_UNKNOWN}, unknown error. 137 * @deprecated since 11 138 * @useinstead OH_AVMuxer_WriteSampleBuffer 139 * @since 10 140 */ 141 OH_AVErrCode OH_AVMuxer_WriteSample(OH_AVMuxer *muxer, uint32_t trackIndex, 142 OH_AVMemory *sample, OH_AVCodecBufferAttr info); 143 144 /** 145 * @brief Write an encoded sample to the muxer. 146 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 147 * make sure that the samples are written to the right tracks. Also, it needs to make sure the samples for each track 148 * are written in chronological order. 149 * @syscap SystemCapability.Multimedia.Media.Muxer 150 * @param muxer Pointer to an OH_AVMuxer instance 151 * @param trackIndex The track index for this sample 152 * @param sample The encoded or demuxer sample, which including data and buffer information 153 * @return Returns AV_ERR_OK if the execution is successful, 154 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 155 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or sample invalid. 156 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 157 * {@link AV_ERR_NO_MEMORY}, failed to request memory. 158 * {@link AV_ERR_UNKNOWN}, unknown error. 159 * @since 11 160 */ 161 OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, 162 const OH_AVBuffer *sample); 163 164 /** 165 * @brief Stop the muxer. 166 * Note: Once the muxer stops, it can not be restarted. 167 * @syscap SystemCapability.Multimedia.Media.Muxer 168 * @param muxer Pointer to an OH_AVMuxer instance 169 * @return Returns AV_ERR_OK if the execution is successful, 170 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 171 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 172 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 173 * @since 10 174 */ 175 OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer); 176 177 /** 178 * @brief Clear the internal resources of the muxer and destroy the muxer instance 179 * @syscap SystemCapability.Multimedia.Media.Muxer 180 * @param muxer Pointer to an OH_AVMuxer instance 181 * @return Returns AV_ERR_OK if the execution is successful, 182 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 183 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 184 * @since 10 185 */ 186 OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer); 187 188 #ifdef __cplusplus 189 } 190 #endif 191 192 #endif // NATIVE_AVMUXER_H 193 /** @} */