1 /* 2 * Copyright (C) 2024 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 encoder of the audio to transcoder. 72 * 73 * If this function is not called, the output file does not contain the audio track. 74 * This function must be called after {@link SetAudioSource} but before {@link Prepare}. 75 * 76 * @param encoder Indicates the audio encoder to set. 77 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 78 * in {@link media_errors.h} otherwise. 79 * @since 1.0 80 * @version 1.0 81 */ 82 virtual int32_t SetAudioEncoder(AudioCodecFormat encoder) = 0; 83 84 /** 85 * @brief Sets the encoding bit rate of the audio to transcoder. 86 * 87 * This function must be called after {@link SetAudioSource} but before {@link Prepare}. 88 * 89 * @param bitRate Indicates the audio encoding bit rate, in bit/s. 90 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 91 * in {@link media_errors.h} otherwise. 92 * @since 1.0 93 * @version 1.0 94 */ 95 virtual int32_t SetAudioEncodingBitRate(int32_t bitRate) = 0; 96 97 /** 98 * @brief Sets the output file format. 99 * 100 * This function must be called before {@link Prepare}. 101 * 102 * @param format Indicates the output file format. For details, see {@link OutputFormatType}. 103 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 104 * in {@link media_errors.h} otherwise. 105 * @since 1.0 106 * @version 1.0 107 */ 108 virtual int32_t SetOutputFormat(OutputFormatType format) = 0; 109 110 /** 111 * @brief Sets the file descriptor (FD) of the input file. 112 * 113 * This function must be called before {@link Prepare}. 114 * 115 * @param fd Indicates the FD of the file. 116 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 117 * in {@link media_errors.h} otherwise. 118 * @since 1.0 119 * @version 1.0 120 */ 121 virtual int32_t SetInputFile(int32_t fd, int64_t offset, int64_t size) = 0; 122 123 /** 124 * @brief Sets the file descriptor (FD) of the output file. 125 * 126 * This function must be called before {@link Prepare}. 127 * 128 * @param fd Indicates the FD of the file. 129 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 130 * in {@link media_errors.h} otherwise. 131 * @since 1.0 132 * @version 1.0 133 */ 134 virtual int32_t SetOutputFile(int32_t fd) = 0; 135 136 /** 137 * @brief Registers a transcodering listener. 138 * 139 * This function must be called before {@link Prepare}. 140 * 141 * @param callback Indicates the transcodering listener to register. For details, see {@link TransCoderCallback}. 142 * @return Returns {@link SUCCESS} if the listener is registered; returns an error code defined 143 * in {@link media_errors.h} otherwise. 144 * @since 1.0 145 * @version 1.0 146 */ 147 virtual int32_t SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback) = 0; 148 149 /** 150 * @brief Prepares for transcodering. 151 * 152 * This function must be called before {@link Start}. 153 * 154 * @return Returns {@link SUCCESS} if the preparation 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 Prepare() = 0; 160 161 /** 162 * @brief Starts transcodering. 163 * 164 * This function must be called after {@link Prepare}. 165 * 166 * @return Returns {@link SUCCESS} if the transcodering is started; returns an error code defined 167 * in {@link media_errors.h} otherwise. 168 * @since 1.0 169 * @version 1.0 170 */ 171 virtual int32_t Start() = 0; 172 173 /** 174 * @brief Pauses transcodering. 175 * 176 * After {@link Start} is called, you can call this function to pause transcodering. 177 * 178 * @return Returns {@link SUCCESS} if the transcodering is paused; returns an error code defined 179 * in {@link media_errors.h} otherwise. 180 * @since 1.0 181 * @version 1.0 182 */ 183 virtual int32_t Pause() = 0; 184 185 /** 186 * @brief Resumes transcodering. 187 * 188 * You can call this function to resume transcodering after {@link Pause} is called. 189 * 190 * @return Returns {@link SUCCESS} if the transcodering is resumed; returns an error code defined 191 * in {@link media_errors.h} otherwise. 192 * @since 1.0 193 * @version 1.0 194 */ 195 virtual int32_t Resume() = 0; 196 197 /** 198 * @brief Cancels the transcodering. 199 * 200 * After the function is called, add a transcodering is cancelled. 201 * 202 * @return Returns {@link SUCCESS} if the transcodering is cancel; returns an error code defined 203 * in {@link media_errors.h} otherwise. 204 * @since 1.0 205 * @version 1.0 206 */ 207 virtual int32_t Cancel() = 0; 208 209 /** 210 * @brief Releases transcodering resources. 211 * 212 * @return Returns {@link SUCCESS} if transcodering resources are released; returns an error code defined 213 * in {@link media_errors.h} otherwise. 214 * @since 1.0 215 * @version 1.0 216 */ 217 virtual int32_t Release() = 0; 218 }; 219 } // namespace Media 220 } // namespace OHOS 221 #endif // I_TRANSCODER_SERVICE_H 222