• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024-2025 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 I_TRANSCODER_SERVICE_H
17 #define I_TRANSCODER_SERVICE_H
18 
19 #include <string>
20 #include "transcoder.h"
21 #include "refbase.h"
22 
23 namespace OHOS {
24 namespace Media {
25 class ITransCoderService {
26 public:
27     virtual ~ITransCoderService() = default;
28 
29     /**
30      * @brief Sets the encoder of the video to transcoder.
31      *
32      * If this function is not called, the output file does not contain the video track.
33      * This function must be called after {@link SetVideoSource} but before {@link Prepare}.
34      *
35      * @param encoder Indicates the video encoder to set.
36      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
37      * in {@link media_errors.h} otherwise.
38      * @since 1.0
39      * @version 1.0
40      */
41     virtual int32_t SetVideoEncoder(VideoCodecFormat encoder) = 0;
42 
43     /**
44      * @brief Sets the encoding video size of the video to transcoder.
45      *
46      * This function must be called after {@link SetVideoSource} but before {@link Prepare}.
47      *
48      * @param width Indicates the video width to set.
49      * @param height Indicates the video height to set.
50      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
51      * in {@link media_errors.h} otherwise.
52      * @since 1.0
53      * @version 1.0
54      */
55     virtual int32_t SetVideoSize(int32_t width, int32_t height) = 0;
56 
57     /**
58      * @brief Sets the encoding bit rate of the video to transcoder.
59      *
60      * This function must be called after {@link SetVideoSource} but before {@link Prepare}.
61      *
62      * @param rate Indicates the encoding bit rate to set.
63      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
64      * in {@link media_errors.h} otherwise.
65      * @since 1.0
66      * @version 1.0
67      */
68     virtual int32_t SetVideoEncodingBitRate(int32_t rate) = 0;
69 
70     /**
71      * @brief Sets the colorspace of the video to transcoder.
72      *
73      * This function must be called after {@link SetAudioSource} but before {@link Prepare}.
74      *
75      * @param colorSpaceFormat Indicates the color space format of the video to set.
76      * @return Returns {@link MSERR_Ok} if the setting is successful; returns an error code otherwise.
77      * @since 1.0
78      * @version 1.0
79      */
80     virtual int32_t SetColorSpace(TranscoderColorSpace colorSpaceFormat) = 0;
81 
82     /**
83      * @brief Sets the B frame encoding to transcoder
84      *
85      * This function must be called after {@link SetOutputFormat} but before {@link Prepare}.
86      *
87      * @param enableBFrame Indicates whether to enable B frame encoding for reduce file size.
88      * The default value is false, which means B frame encoding cannot be enabled.
89      * @return Returns {@link MSERR_OK} if the setting is successful; returns an error code otherwise.
90      * @since 1.0
91      * @version 1.0
92      */
93     virtual int32_t SetEnableBFrame(bool enableBFrame) = 0;
94 
95     /**
96      * @brief Sets the encoder of the audio to transcoder.
97      *
98      * If this function is not called, the output file does not contain the audio track.
99      * This function must be called after {@link SetAudioSource} but before {@link Prepare}.
100      *
101      * @param encoder Indicates the audio encoder to set.
102      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
103      * in {@link media_errors.h} otherwise.
104      * @since 1.0
105      * @version 1.0
106      */
107     virtual int32_t SetAudioEncoder(AudioCodecFormat encoder) = 0;
108 
109     /**
110      * @brief Sets the encoding bit rate of the audio to transcoder.
111      *
112      * This function must be called after {@link SetAudioSource} but before {@link Prepare}.
113      *
114      * @param bitRate Indicates the audio encoding bit rate, in bit/s.
115      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
116      * in {@link media_errors.h} otherwise.
117      * @since 1.0
118      * @version 1.0
119      */
120     virtual int32_t SetAudioEncodingBitRate(int32_t bitRate) = 0;
121 
122     /**
123      * @brief Sets the output file format.
124      *
125      * This function must be called before {@link Prepare}.
126      *
127      * @param format Indicates the output file format. For details, see {@link OutputFormatType}.
128      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
129      * in {@link media_errors.h} otherwise.
130      * @since 1.0
131      * @version 1.0
132      */
133     virtual int32_t SetOutputFormat(OutputFormatType format) = 0;
134 
135     /**
136      * @brief Sets the file descriptor (FD) of the input file.
137      *
138      * This function must be called before {@link Prepare}.
139      *
140      * @param fd Indicates the FD of the file.
141      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
142      * in {@link media_errors.h} otherwise.
143      * @since 1.0
144      * @version 1.0
145      */
146     virtual int32_t SetInputFile(int32_t fd, int64_t offset, int64_t size) = 0;
147 
148     /**
149      * @brief Sets the file descriptor (FD) of the output file.
150      *
151      * This function must be called before {@link Prepare}.
152      *
153      * @param fd Indicates the FD of the file.
154      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
155      * in {@link media_errors.h} otherwise.
156      * @since 1.0
157      * @version 1.0
158      */
159     virtual int32_t SetOutputFile(int32_t fd) = 0;
160 
161     /**
162      * @brief Registers a transcodering listener.
163      *
164      * This function must be called before {@link Prepare}.
165      *
166      * @param callback Indicates the transcodering listener to register. For details, see {@link TransCoderCallback}.
167      * @return Returns {@link SUCCESS} if the listener is registered; returns an error code defined
168      * in {@link media_errors.h} otherwise.
169      * @since 1.0
170      * @version 1.0
171      */
172     virtual int32_t SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback) = 0;
173 
174     /**
175      * @brief Prepares for transcodering.
176      *
177      * This function must be called before {@link Start}.
178      *
179      * @return Returns {@link SUCCESS} if the preparation is successful; returns an error code defined
180      * in {@link media_errors.h} otherwise.
181      * @since 1.0
182      * @version 1.0
183      */
184     virtual int32_t Prepare() = 0;
185 
186     /**
187      * @brief Starts transcodering.
188      *
189      * This function must be called after {@link Prepare}.
190      *
191      * @return Returns {@link SUCCESS} if the transcodering is started; returns an error code defined
192      * in {@link media_errors.h} otherwise.
193      * @since 1.0
194      * @version 1.0
195      */
196     virtual int32_t Start() = 0;
197 
198     /**
199      * @brief Pauses transcodering.
200      *
201      * After {@link Start} is called, you can call this function to pause transcodering.
202      *
203      * @return Returns {@link SUCCESS} if the transcodering is paused; returns an error code defined
204      * in {@link media_errors.h} otherwise.
205      * @since 1.0
206      * @version 1.0
207      */
208     virtual int32_t Pause() = 0;
209 
210     /**
211     * @brief Resumes transcodering.
212     *
213     * You can call this function to resume transcodering after {@link Pause} is called.
214      *
215      * @return Returns {@link SUCCESS} if the transcodering is resumed; returns an error code defined
216      * in {@link media_errors.h} otherwise.
217      * @since 1.0
218      * @version 1.0
219      */
220     virtual int32_t Resume() = 0;
221 
222     /**
223      * @brief Cancels the transcodering.
224      *
225      * After the function is called, add a transcodering is cancelled.
226      *
227      * @return Returns {@link SUCCESS} if the transcodering is cancel; returns an error code defined
228      * in {@link media_errors.h} otherwise.
229      * @since 1.0
230      * @version 1.0
231      */
232     virtual int32_t Cancel() = 0;
233 
234     /**
235      * @brief Releases transcodering resources.
236      *
237      * @return Returns {@link SUCCESS} if transcodering resources are released; returns an error code defined
238      * in {@link media_errors.h} otherwise.
239      * @since 1.0
240      * @version 1.0
241      */
242     virtual int32_t Release() = 0;
243 };
244 } // namespace Media
245 } // namespace OHOS
246 #endif // I_TRANSCODER_SERVICE_H
247