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