1 /* 2 * Copyright (C) 2021 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_GST_CODEC_H 17 #define I_GST_CODEC_H 18 19 #include <memory> 20 #include <gst/gst.h> 21 #include <vector> 22 #include "nocopyable.h" 23 #include "i_codec_params_mgr.h" 24 #include "i_codec_buffer_mgr.h" 25 #include "i_codec_common.h" 26 27 namespace OHOS { 28 namespace Media { 29 class IGstCodec { 30 public: 31 virtual ~IGstCodec() = default; 32 /** 33 * @brief Init codec. 34 * 35 * This function must be called immediately after creation 36 * 37 * @return Returns GST_CODEC_OK if successful; 38 * @since 1.0 39 * @version 1.0 40 */ 41 virtual int32_t Init() = 0; 42 43 /** 44 * @brief Set a ICodecBufferMgr for the codec interface. 45 * 46 * Every codec need a special Inbuffermgr which must set. 47 * 48 * @since 1.0 49 * @version 1.0 50 */ SetInBufferMgr(std::shared_ptr<ICodecBufferMgr> bufferMgr)51 virtual void SetInBufferMgr(std::shared_ptr<ICodecBufferMgr> bufferMgr) 52 { 53 (void)bufferMgr; 54 return; 55 }; 56 57 /** 58 * @brief Set a ICodecBufferMgr for the codec interface. 59 * 60 * Every codec need a special Outbuffermgr which must set. 61 * 62 * @since 1.0 63 * @version 1.0 64 */ SetOutBufferMgr(std::shared_ptr<ICodecBufferMgr> bufferMgr)65 virtual void SetOutBufferMgr(std::shared_ptr<ICodecBufferMgr> bufferMgr) 66 { 67 (void)bufferMgr; 68 return; 69 }; 70 71 /** 72 * @brief Set a ICodecParamsMgr for the codec interface. 73 * 74 * Every codec need a special ICodecParamsMgr which must set. 75 * 76 * @since 1.0 77 * @version 1.0 78 */ SetParamsMgr(std::shared_ptr<ICodecParamsMgr> paramsMgr)79 virtual void SetParamsMgr(std::shared_ptr<ICodecParamsMgr> paramsMgr) 80 { 81 (void)paramsMgr; 82 return; 83 }; 84 85 /** 86 * @brief Set param with key, and value is in element. 87 * 88 * Every codec need to set param before start. 89 * 90 * @return Returns GST_CODEC_OK successful; 91 * @since 1.0 92 * @version 1.0 93 */ 94 virtual int32_t SetParameter(GstCodecParamKey key, GstElement *element) = 0; 95 96 /** 97 * @brief Update the value in element with key. 98 * 99 * Get parameter before set. 100 * 101 * @return Returns GST_CODEC_OK successful; 102 * @since 1.0 103 * @version 1.0 104 */ 105 virtual int32_t GetParameter(GstCodecParamKey key, GstElement *element) = 0; 106 107 /** 108 * @brief Start codec, must have allocated or used buffers. 109 * 110 * @return Returns GST_CODEC_OK successful; 111 * @since 1.0 112 * @version 1.0 113 */ 114 virtual int32_t Start() = 0; 115 116 /** 117 * @brief Stop codec and then must have free buffers. 118 * 119 * @return Returns GST_CODEC_OK successful; 120 * @since 1.0 121 * @version 1.0 122 */ 123 virtual int32_t Stop() = 0; 124 125 /** 126 * @brief Use input Buffer which can be null, and the real buffer in the push. 127 * 128 * @return Returns GST_CODEC_OK successful; 129 * @since 1.0 130 * @version 1.0 131 */ 132 virtual int32_t UseInputBuffers(std::vector<GstBuffer*> buffers) = 0; 133 134 /** 135 * @brief Send the input buffer filled with data to the codec. 136 * 137 * Codec will empty this buffer. 138 * 139 * @return Returns GST_CODEC_OK successful; 140 * @since 1.0 141 * @version 1.0 142 */ 143 virtual int32_t PushInputBuffer(GstBuffer *buffer) = 0; 144 145 /** 146 * @brief Free Buffers free after stop. 147 * 148 * @return Returns GST_CODEC_OK successful; 149 * @since 1.0 150 * @version 1.0 151 */ 152 virtual int32_t FreeInputBuffers() = 0; 153 154 /** 155 * @brief Use out Buffers allocate by surface or avshmem. 156 * 157 * @return Returns GST_CODEC_OK successful; 158 * @since 1.0 159 * @version 1.0 160 */ 161 virtual int32_t UseOutputBuffers(std::vector<GstBuffer*> buffers) = 0; 162 163 /** 164 * @brief Send the out buffer which is empty to the codec, Codec will fill this buffer. 165 * 166 * Push ouput buffer which is empty. 167 * 168 * @return Returns GST_CODEC_OK successful; 169 * @since 1.0 170 * @version 1.0 171 */ 172 virtual int32_t PushOutputBuffer(GstBuffer *buffer) = 0; 173 174 /** 175 * @brief Get the buffer which memory is full. 176 * 177 * Get ouput buffer which filled by codec. 178 * 179 * @return Returns GST_CODEC_OK successful; 180 * @since 1.0 181 * @version 1.0 182 */ 183 virtual int32_t PullOutputBuffer(GstBuffer **buffer) = 0; 184 185 /** 186 * @brief Free Buffers free after stop. 187 * 188 * @return Returns GST_CODEC_OK successful; 189 * @since 1.0 190 * @version 1.0 191 */ 192 virtual int32_t FreeOutputBuffers() = 0; 193 194 /** 195 * @brief Flush buffers. 196 * 197 * When we seek we need flush. 198 * 199 * @return Returns GST_CODEC_OK successful; 200 * @since 1.0 201 * @version 1.0 202 */ 203 virtual int32_t Flush(GstCodecDirect direct) = 0; 204 205 /** 206 * @brief Active or deactive port. 207 * 208 * When reconfig we need to deactive and then active. 209 * 210 * @return Returns GST_CODEC_OK successful; 211 * @since 1.0 212 * @version 1.0 213 */ 214 virtual int32_t ActiveBufferMgr(GstCodecDirect direct, bool active) = 0; 215 216 /** 217 * @brief Init codec. 218 * 219 * This function must be called immediately before destroy 220 * 221 * @since 1.0 222 * @version 1.0 223 */ 224 virtual void Deinit() = 0; 225 226 /** 227 * @brief Callback when codec process dies. 228 * 229 * @since 1.0 230 * @version 1.0 231 */ 232 virtual void OnCodecDied() = 0; 233 234 /** 235 * @brief Set surface pool for callback mode. 236 * 237 * @since 1.0 238 * @version 1.0 239 */ 240 virtual void SetOutputPool(GstBufferPool *pool) = 0; 241 242 /** 243 * @brief Format Changed. 244 * 245 * @since 1.0 246 * @version 1.0 247 */ 248 virtual bool IsFormatChanged() = 0; 249 }; 250 } // namespace Media 251 } // namespace OHOS 252 #endif // I_GST_CODEC_H 253