1049e185fSopenharmony_ci/*
2049e185fSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
3049e185fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4049e185fSopenharmony_ci * you may not use this file except in compliance with the License.
5049e185fSopenharmony_ci * You may obtain a copy of the License at
6049e185fSopenharmony_ci *
7049e185fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8049e185fSopenharmony_ci *
9049e185fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10049e185fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11049e185fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12049e185fSopenharmony_ci * See the License for the specific language governing permissions and
13049e185fSopenharmony_ci * limitations under the License.
14049e185fSopenharmony_ci */
15049e185fSopenharmony_ci
16049e185fSopenharmony_ci#ifndef I_TRANSCODER_SERVICE_H
17049e185fSopenharmony_ci#define I_TRANSCODER_SERVICE_H
18049e185fSopenharmony_ci
19049e185fSopenharmony_ci#include <string>
20049e185fSopenharmony_ci#include "transcoder.h"
21049e185fSopenharmony_ci#include "refbase.h"
22049e185fSopenharmony_ci
23049e185fSopenharmony_cinamespace OHOS {
24049e185fSopenharmony_cinamespace Media {
25049e185fSopenharmony_ciclass ITransCoderService {
26049e185fSopenharmony_cipublic:
27049e185fSopenharmony_ci    virtual ~ITransCoderService() = default;
28049e185fSopenharmony_ci
29049e185fSopenharmony_ci    /**
30049e185fSopenharmony_ci     * @brief Sets the encoder of the video to transcoder.
31049e185fSopenharmony_ci     *
32049e185fSopenharmony_ci     * If this function is not called, the output file does not contain the video track.
33049e185fSopenharmony_ci     * This function must be called after {@link SetVideoSource} but before {@link Prepare}.
34049e185fSopenharmony_ci     *
35049e185fSopenharmony_ci     * @param encoder Indicates the video encoder to set.
36049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
37049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
38049e185fSopenharmony_ci     * @since 1.0
39049e185fSopenharmony_ci     * @version 1.0
40049e185fSopenharmony_ci     */
41049e185fSopenharmony_ci    virtual int32_t SetVideoEncoder(VideoCodecFormat encoder) = 0;
42049e185fSopenharmony_ci
43049e185fSopenharmony_ci    /**
44049e185fSopenharmony_ci     * @brief Sets the encoding video size of the video to transcoder.
45049e185fSopenharmony_ci     *
46049e185fSopenharmony_ci     * This function must be called after {@link SetVideoSource} but before {@link Prepare}.
47049e185fSopenharmony_ci     *
48049e185fSopenharmony_ci     * @param width Indicates the video width to set.
49049e185fSopenharmony_ci     * @param height Indicates the video height to set.
50049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
51049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
52049e185fSopenharmony_ci     * @since 1.0
53049e185fSopenharmony_ci     * @version 1.0
54049e185fSopenharmony_ci     */
55049e185fSopenharmony_ci    virtual int32_t SetVideoSize(int32_t width, int32_t height) = 0;
56049e185fSopenharmony_ci
57049e185fSopenharmony_ci    /**
58049e185fSopenharmony_ci     * @brief Sets the encoding bit rate of the video to transcoder.
59049e185fSopenharmony_ci     *
60049e185fSopenharmony_ci     * This function must be called after {@link SetVideoSource} but before {@link Prepare}.
61049e185fSopenharmony_ci     *
62049e185fSopenharmony_ci     * @param rate Indicates the encoding bit rate to set.
63049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
64049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
65049e185fSopenharmony_ci     * @since 1.0
66049e185fSopenharmony_ci     * @version 1.0
67049e185fSopenharmony_ci     */
68049e185fSopenharmony_ci    virtual int32_t SetVideoEncodingBitRate(int32_t rate) = 0;
69049e185fSopenharmony_ci
70049e185fSopenharmony_ci    /**
71049e185fSopenharmony_ci     * @brief Sets the encoder of the audio to transcoder.
72049e185fSopenharmony_ci     *
73049e185fSopenharmony_ci     * If this function is not called, the output file does not contain the audio track.
74049e185fSopenharmony_ci     * This function must be called after {@link SetAudioSource} but before {@link Prepare}.
75049e185fSopenharmony_ci     *
76049e185fSopenharmony_ci     * @param encoder Indicates the audio encoder to set.
77049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
78049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
79049e185fSopenharmony_ci     * @since 1.0
80049e185fSopenharmony_ci     * @version 1.0
81049e185fSopenharmony_ci     */
82049e185fSopenharmony_ci    virtual int32_t SetAudioEncoder(AudioCodecFormat encoder) = 0;
83049e185fSopenharmony_ci
84049e185fSopenharmony_ci    /**
85049e185fSopenharmony_ci     * @brief Sets the encoding bit rate of the audio to transcoder.
86049e185fSopenharmony_ci     *
87049e185fSopenharmony_ci     * This function must be called after {@link SetAudioSource} but before {@link Prepare}.
88049e185fSopenharmony_ci     *
89049e185fSopenharmony_ci     * @param bitRate Indicates the audio encoding bit rate, in bit/s.
90049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
91049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
92049e185fSopenharmony_ci     * @since 1.0
93049e185fSopenharmony_ci     * @version 1.0
94049e185fSopenharmony_ci     */
95049e185fSopenharmony_ci    virtual int32_t SetAudioEncodingBitRate(int32_t bitRate) = 0;
96049e185fSopenharmony_ci
97049e185fSopenharmony_ci    /**
98049e185fSopenharmony_ci     * @brief Sets the output file format.
99049e185fSopenharmony_ci     *
100049e185fSopenharmony_ci     * This function must be called before {@link Prepare}.
101049e185fSopenharmony_ci     *
102049e185fSopenharmony_ci     * @param format Indicates the output file format. For details, see {@link OutputFormatType}.
103049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
104049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
105049e185fSopenharmony_ci     * @since 1.0
106049e185fSopenharmony_ci     * @version 1.0
107049e185fSopenharmony_ci     */
108049e185fSopenharmony_ci    virtual int32_t SetOutputFormat(OutputFormatType format) = 0;
109049e185fSopenharmony_ci
110049e185fSopenharmony_ci    /**
111049e185fSopenharmony_ci     * @brief Sets the file descriptor (FD) of the input file.
112049e185fSopenharmony_ci     *
113049e185fSopenharmony_ci     * This function must be called before {@link Prepare}.
114049e185fSopenharmony_ci     *
115049e185fSopenharmony_ci     * @param fd Indicates the FD of the file.
116049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
117049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
118049e185fSopenharmony_ci     * @since 1.0
119049e185fSopenharmony_ci     * @version 1.0
120049e185fSopenharmony_ci     */
121049e185fSopenharmony_ci    virtual int32_t SetInputFile(int32_t fd, int64_t offset, int64_t size) = 0;
122049e185fSopenharmony_ci
123049e185fSopenharmony_ci    /**
124049e185fSopenharmony_ci     * @brief Sets the file descriptor (FD) of the output file.
125049e185fSopenharmony_ci     *
126049e185fSopenharmony_ci     * This function must be called before {@link Prepare}.
127049e185fSopenharmony_ci     *
128049e185fSopenharmony_ci     * @param fd Indicates the FD of the file.
129049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
130049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
131049e185fSopenharmony_ci     * @since 1.0
132049e185fSopenharmony_ci     * @version 1.0
133049e185fSopenharmony_ci     */
134049e185fSopenharmony_ci    virtual int32_t SetOutputFile(int32_t fd) = 0;
135049e185fSopenharmony_ci
136049e185fSopenharmony_ci    /**
137049e185fSopenharmony_ci     * @brief Registers a transcodering listener.
138049e185fSopenharmony_ci     *
139049e185fSopenharmony_ci     * This function must be called before {@link Prepare}.
140049e185fSopenharmony_ci     *
141049e185fSopenharmony_ci     * @param callback Indicates the transcodering listener to register. For details, see {@link TransCoderCallback}.
142049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the listener is registered; returns an error code defined
143049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
144049e185fSopenharmony_ci     * @since 1.0
145049e185fSopenharmony_ci     * @version 1.0
146049e185fSopenharmony_ci     */
147049e185fSopenharmony_ci    virtual int32_t SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback) = 0;
148049e185fSopenharmony_ci
149049e185fSopenharmony_ci    /**
150049e185fSopenharmony_ci     * @brief Prepares for transcodering.
151049e185fSopenharmony_ci     *
152049e185fSopenharmony_ci     * This function must be called before {@link Start}.
153049e185fSopenharmony_ci     *
154049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the preparation is successful; returns an error code defined
155049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
156049e185fSopenharmony_ci     * @since 1.0
157049e185fSopenharmony_ci     * @version 1.0
158049e185fSopenharmony_ci     */
159049e185fSopenharmony_ci    virtual int32_t Prepare() = 0;
160049e185fSopenharmony_ci
161049e185fSopenharmony_ci    /**
162049e185fSopenharmony_ci     * @brief Starts transcodering.
163049e185fSopenharmony_ci     *
164049e185fSopenharmony_ci     * This function must be called after {@link Prepare}.
165049e185fSopenharmony_ci     *
166049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the transcodering is started; returns an error code defined
167049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
168049e185fSopenharmony_ci     * @since 1.0
169049e185fSopenharmony_ci     * @version 1.0
170049e185fSopenharmony_ci     */
171049e185fSopenharmony_ci    virtual int32_t Start() = 0;
172049e185fSopenharmony_ci
173049e185fSopenharmony_ci    /**
174049e185fSopenharmony_ci     * @brief Pauses transcodering.
175049e185fSopenharmony_ci     *
176049e185fSopenharmony_ci     * After {@link Start} is called, you can call this function to pause transcodering.
177049e185fSopenharmony_ci     *
178049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the transcodering is paused; returns an error code defined
179049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
180049e185fSopenharmony_ci     * @since 1.0
181049e185fSopenharmony_ci     * @version 1.0
182049e185fSopenharmony_ci     */
183049e185fSopenharmony_ci    virtual int32_t Pause() = 0;
184049e185fSopenharmony_ci
185049e185fSopenharmony_ci    /**
186049e185fSopenharmony_ci    * @brief Resumes transcodering.
187049e185fSopenharmony_ci    *
188049e185fSopenharmony_ci    * You can call this function to resume transcodering after {@link Pause} is called.
189049e185fSopenharmony_ci     *
190049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the transcodering is resumed; returns an error code defined
191049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
192049e185fSopenharmony_ci     * @since 1.0
193049e185fSopenharmony_ci     * @version 1.0
194049e185fSopenharmony_ci     */
195049e185fSopenharmony_ci    virtual int32_t Resume() = 0;
196049e185fSopenharmony_ci
197049e185fSopenharmony_ci    /**
198049e185fSopenharmony_ci     * @brief Cancels the transcodering.
199049e185fSopenharmony_ci     *
200049e185fSopenharmony_ci     * After the function is called, add a transcodering is cancelled.
201049e185fSopenharmony_ci     *
202049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if the transcodering is cancel; returns an error code defined
203049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
204049e185fSopenharmony_ci     * @since 1.0
205049e185fSopenharmony_ci     * @version 1.0
206049e185fSopenharmony_ci     */
207049e185fSopenharmony_ci    virtual int32_t Cancel() = 0;
208049e185fSopenharmony_ci
209049e185fSopenharmony_ci    /**
210049e185fSopenharmony_ci     * @brief Releases transcodering resources.
211049e185fSopenharmony_ci     *
212049e185fSopenharmony_ci     * @return Returns {@link SUCCESS} if transcodering resources are released; returns an error code defined
213049e185fSopenharmony_ci     * in {@link media_errors.h} otherwise.
214049e185fSopenharmony_ci     * @since 1.0
215049e185fSopenharmony_ci     * @version 1.0
216049e185fSopenharmony_ci     */
217049e185fSopenharmony_ci    virtual int32_t Release() = 0;
218049e185fSopenharmony_ci};
219049e185fSopenharmony_ci} // namespace Media
220049e185fSopenharmony_ci} // namespace OHOS
221049e185fSopenharmony_ci#endif // I_TRANSCODER_SERVICE_H
222