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 24extern "C" { 25#endif 26 27typedef 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 */ 37OH_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 * {@link AV_ERR_INVALID_VAL}, the muxer or rotation invalid. 48 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 49 * @since 10 50 */ 51OH_AVErrCode OH_AVMuxer_SetRotation(OH_AVMuxer *muxer, int32_t rotation); 52 53/** 54 * @brief Add track format to the muxer. 55 * Note: This interface can only be called before OH_AVMuxer_Start. 56 * @syscap SystemCapability.Multimedia.Media.Muxer 57 * @param muxer Pointer to an OH_AVMuxer instance 58 * @param trackIndex The int32_t handle pointer used to get the track index for this newly added track, 59 * and it should be used in the OH_AVMuxer_WriteSample. The track index is greater than or equal to 0, 60 * others is error index. 61 * @param trackFormat OH_AVFormat handle pointer contain track format 62 * @return Returns AV_ERR_OK if the execution is successful, 63 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 64 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or trackFormat invalid. 65 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 66 * {@link AV_ERR_UNSUPPORT}, the mime type is not supported. 67 * {@link AV_ERR_NO_MEMORY}, failed to malloc memory. 68 * {@link AV_ERR_UNKNOWN}, unknown error. 69 * @since 10 70 */ 71OH_AVErrCode OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat); 72 73/** 74 * @brief Start the muxer. 75 * Note: This interface is called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSample. 76 * @syscap SystemCapability.Multimedia.Media.Muxer 77 * @param muxer Pointer to an OH_AVMuxer instance 78 * @return Returns AV_ERR_OK if the execution is successful, 79 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 80 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 81 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 82 * {@link AV_ERR_UNKNOWN}, unknown error. 83 * @since 10 84 */ 85OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer); 86 87/** 88 * @brief Write an encoded sample to the muxer. 89 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 90 * make sure that the samples are written to the right tacks. Also, it needs to make sure the samples for each track are 91 * written in chronological order. 92 * @syscap SystemCapability.Multimedia.Media.Muxer 93 * @param muxer Pointer to an OH_AVMuxer instance 94 * @param trackIndex The track index for this sample 95 * @param sample The encoded or demuxer sample 96 * @param info The buffer information related to this sample {@link OH_AVCodecBufferAttr} 97 * @return Returns AV_ERR_OK if the execution is successful, 98 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 99 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or sample or info invalid. 100 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 101 * {@link AV_ERR_NO_MEMORY}, failed to request memory. 102 * {@link AV_ERR_UNKNOWN}, unknown error. 103 * @deprecated since 11 104 * @useinstead OH_AVMuxer_WriteSampleBuffer 105 * @since 10 106 */ 107OH_AVErrCode OH_AVMuxer_WriteSample(OH_AVMuxer *muxer, uint32_t trackIndex, 108 OH_AVMemory *sample, OH_AVCodecBufferAttr info); 109 110/** 111 * @brief Write an encoded sample to the muxer. 112 * Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to 113 * make sure that the samples are written to the right tracks. Also, it needs to make sure the samples for each track 114 * are written in chronological order. 115 * @syscap SystemCapability.Multimedia.Media.Muxer 116 * @param muxer Pointer to an OH_AVMuxer instance 117 * @param trackIndex The track index for this sample 118 * @param sample The encoded or demuxer sample, which including data and buffer information 119 * @return Returns AV_ERR_OK if the execution is successful, 120 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 121 * {@link AV_ERR_INVALID_VAL}, the muxer or trackIndex or sample invalid. 122 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 123 * {@link AV_ERR_NO_MEMORY}, failed to request memory. 124 * {@link AV_ERR_UNKNOWN}, unknown error. 125 * @since 11 126 */ 127OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, 128 const OH_AVBuffer *sample); 129 130/** 131 * @brief Stop the muxer. 132 * Note: Once the muxer stops, it can not be restarted. 133 * @syscap SystemCapability.Multimedia.Media.Muxer 134 * @param muxer Pointer to an OH_AVMuxer instance 135 * @return Returns AV_ERR_OK if the execution is successful, 136 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 137 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 138 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface, it was called in invalid state. 139 * @since 10 140 */ 141OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer); 142 143/** 144 * @brief Clear the internal resources of the muxer and destroy the muxer instance 145 * @syscap SystemCapability.Multimedia.Media.Muxer 146 * @param muxer Pointer to an OH_AVMuxer instance 147 * @return Returns AV_ERR_OK if the execution is successful, 148 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 149 * {@link AV_ERR_INVALID_VAL}, the muxer invalid. 150 * @since 10 151 */ 152OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer); 153 154#ifdef __cplusplus 155} 156#endif 157 158#endif // NATIVE_AVMUXER_H