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