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 #ifndef NATIVE_AVMUXER_H 17 #define NATIVE_AVMUXER_H 18 19 #include <stdint.h> 20 #include <stdio.h> 21 #include "native_avcodec_base.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct OH_AVMuxer OH_AVMuxer; 28 29 /** 30 * @brief Create an OH_AVMuxer instance by output file description and format. 31 * @syscap SystemCapability.Multimedia.Media.Muxer 32 * @param fd Must be opened with read and write permission. Caller is responsible for closing fd. 33 * @param format The output format is {@link OH_AVOutputFormat} . 34 * @return Returns a pointer to an OH_AVMuxer instance, needs to be freed by OH_AVMuxer_Destroy. 35 * @since 10 36 */ 37 OH_AVMuxer *OH_AVMuxer_Create(int32_t fd, OH_AVOutputFormat format); 38 39 /** 40 * @brief Set the rotation for output video playback. 41 * Note: This interface can only be called before OH_AVMuxer_Start. 42 * @syscap SystemCapability.Multimedia.Media.Muxer 43 * @param muxer Pointer to an OH_AVMuxer instance. 44 * @param rotation The supported angles are 0, 90, 180, and 270 degrees. 45 * @return Returns AV_ERR_OK if the execution is successful, 46 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 47 * @since 10 48 */ 49 OH_AVErrCode OH_AVMuxer_SetRotation(OH_AVMuxer *muxer, int32_t rotation); 50 51 /** 52 * @brief Add track format to the muxer. 53 * Note: This interface can only be called before OH_AVMuxer_Start. 54 * @syscap SystemCapability.Multimedia.Media.Muxer 55 * @param muxer Pointer to an OH_AVMuxer instance 56 * @param trackIndex The int32_t handle pointer used to get the track index for this newly added track, 57 * and it should be used in the OH_AVMuxer_WriteSample. The track index is greater than or equal to 0, 58 * others is error index. 59 * @param trackFormat OH_AVFormat handle pointer contain track format 60 * @return Returns AV_ERR_OK if the execution is successful, 61 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 62 * @since 10 63 */ 64 OH_AVErrCode OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat); 65 66 /** 67 * @brief Start the muxer. 68 * Note: This interface is called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSample. 69 * @syscap SystemCapability.Multimedia.Media.Muxer 70 * @param muxer Pointer to an OH_AVMuxer instance 71 * @return Returns AV_ERR_OK if the execution is successful, 72 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 73 * @since 10 74 */ 75 OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer); 76 77 /** 78 * @brief Write an encoded sample to the muxer. 79 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 80 * make sure that the samples are written to the right tacks. Also, it needs to make sure the samples for each track are 81 * written in chronological order. 82 * @syscap SystemCapability.Multimedia.Media.Muxer 83 * @param muxer Pointer to an OH_AVMuxer instance 84 * @param trackIndex The track index for this sample 85 * @param sample The encoded or demuxer sample 86 * @param info The buffer information related to this sample {@link OH_AVCodecBufferAttr} 87 * @return Returns AV_ERR_OK if the execution is successful, 88 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 89 * @deprecated since 11 90 * @useinstead OH_AVMuxer_WriteSampleBuffer 91 * @since 10 92 */ 93 OH_AVErrCode OH_AVMuxer_WriteSample(OH_AVMuxer *muxer, uint32_t trackIndex, 94 OH_AVMemory *sample, OH_AVCodecBufferAttr info); 95 96 /** 97 * @brief Write an encoded sample to the muxer. 98 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 99 * make sure that the samples are written to the right tracks. Also, it needs to make sure the samples for each track 100 * are written in chronological order. 101 * @syscap SystemCapability.Multimedia.Media.Muxer 102 * @param muxer Pointer to an OH_AVMuxer instance 103 * @param trackIndex The track index for this sample 104 * @param sample The encoded or demuxer sample, which including data and buffer information 105 * @return Returns AV_ERR_OK if the execution is successful, 106 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 107 * @since 11 108 */ 109 OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, 110 const OH_AVBuffer *sample); 111 112 /** 113 * @brief Stop the muxer. 114 * Note: Once the muxer stops, it can not be restarted. 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 * @since 10 120 */ 121 OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer); 122 123 /** 124 * @brief Clear the internal resources of the muxer and destroy the muxer instance 125 * @syscap SystemCapability.Multimedia.Media.Muxer 126 * @param muxer Pointer to an OH_AVMuxer instance 127 * @return Returns AV_ERR_OK if the execution is successful, 128 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 129 * @since 10 130 */ 131 OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer); 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif // NATIVE_AVMUXER_H