1 /* 2 * Copyright (c) 2021-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 HISTREAMER_PLUGIN_INTF_CODEC_PLUGIN_H 17 #define HISTREAMER_PLUGIN_INTF_CODEC_PLUGIN_H 18 19 #include <vector> 20 #include "common/plugin_caps.h" 21 #include "plugin_base.h" 22 #include "plugin_definition.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Plugin { 27 /** 28 * @brief Plugin data callback interface. 29 * 30 * @since 1.0 31 * @version 1.0 32 */ 33 struct DataCallback { 34 virtual ~DataCallback() = default; 35 36 /** 37 * @brief When the input buffer has been consumed inside the plugin. 38 * 39 * This function works with QueueInputBuffer to implement input data transmission. 40 * 41 * @param input Indicates the pointer to the input data. 42 */ 43 virtual void OnInputBufferDone(std::shared_ptr<Buffer>& input) = 0; 44 45 /** 46 * @brief When the out buffer has been produced inside the plugin. 47 * 48 * This function works with QueueOutputBuffer to implement out data transmission. 49 * 50 * @param output Indicates the pointer to the output data. 51 */ 52 virtual void OnOutputBufferDone(std::shared_ptr<Buffer>& output) = 0; 53 }; 54 55 /** 56 * @brief Codec Plugin Interface. 57 * 58 * Used for audio and video encoding and decoding. 59 * 60 * @since 1.0 61 * @version 1.0 62 */ 63 struct CodecPlugin : public PluginBase { 64 /// constructor CodecPluginCodecPlugin65 explicit CodecPlugin(std::string name): PluginBase(std::move(name)) {} 66 67 /** 68 * @brief Queues input data 69 * 70 * This function works with DataCallback::OnInputBufferDone to implement input data transmission. 71 * 72 * The function is valid only in the RUNNING state. 73 * 74 * @param inputBuffer Indicates the pointer to the input data. 75 * @param timeoutMs Indicates the timeout duration. 76 * @return Execution status return 77 * @retval OK: Plugin reset succeeded. 78 * @retval ERROR_INVALID_DATA: The input buffer is invalid. 79 * @retval ERROR_TIMED_OUT: Operation timeout. 80 */ 81 virtual Status QueueInputBuffer(const std::shared_ptr<Buffer>& inputBuffer, int32_t timeoutMs) = 0; 82 83 /** 84 * @brief Dequeue input data 85 * 86 * This function works in sync mode if need. 87 * 88 * The function is valid only in the RUNNING state. 89 * 90 * @param inputBuffer Indicates the pointer to the input data. 91 * @param timeoutMs Indicates the timeout duration. 92 * @return Execution status return 93 * @retval OK: Plugin reset succeeded. 94 * @retval ERROR_INVALID_DATA: The input buffer is invalid. 95 * @retval ERROR_TIMED_OUT: Operation timeout. 96 */ 97 virtual Status DequeueInputBuffer(std::shared_ptr<Buffer>& inputBuffer, int32_t timeoutMs) = 0; 98 99 /** 100 * @brief Queues output data 101 * 102 * This function works with DataCallback::OnOutputBufferDone to implement output data transmission. 103 * 104 * The function is valid only in the RUNNING state. 105 * 106 * @param outputBuffers Indicates the pointer to the output data. 107 * @param timeoutMs Indicates the timeout duration. 108 * @return Execution status return 109 * @retval OK: Plugin reset succeeded. 110 * @retval ERROR_INVALID_DATA: The output buffer is invalid. 111 * @retval ERROR_TIMED_OUT: Operation timeout. 112 */ 113 virtual Status QueueOutputBuffer(const std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs) = 0; 114 115 /** 116 * @brief Dequeues output data 117 * 118 * This function works in sync mode if need. 119 * 120 * The function is valid only in the RUNNING state. 121 * 122 * @param outputBuffers Indicates the pointer to the output data. 123 * @param timeoutMs Indicates the timeout duration. 124 * @return Execution status return 125 * @retval OK: Plugin reset succeeded. 126 * @retval ERROR_INVALID_DATA: The output buffer is invalid. 127 * @retval ERROR_TIMED_OUT: Operation timeout. 128 */ 129 virtual Status DequeueOutputBuffer(std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs) = 0; 130 131 /** 132 * @brief Flushes data in the audio buffer. 133 * 134 * The function is valid only in after RUNNING state. 135 * 136 * @return Execution status return 137 * @retval OK: Plugin reset succeeded. 138 */ 139 virtual Status Flush() = 0; 140 141 /** 142 * @brief Sets the plugin callback data to notify the plugin user. 143 * 144 * This function can be called in any state except DESTROYED and INVALID. 145 * 146 * @param cb Data callback, NULL callback listening is canceled. 147 * @return Execution status return 148 * @retval OK: Plugin reset succeeded. 149 */ 150 virtual Status SetDataCallback(DataCallback* dataCallback) = 0; 151 }; 152 153 /// Codec plugin api major number. 154 #define CODEC_API_VERSION_MAJOR (1) 155 156 /// Codec plugin api minor number 157 #define CODEC_API_VERSION_MINOR (0) 158 159 /// Codec plugin version 160 #define CODEC_API_VERSION MAKE_VERSION(CODEC_API_VERSION_MAJOR, CODEC_API_VERSION_MINOR) 161 162 /** 163 * @brief The Codec Type. 164 * 165 * @since 1.0 166 * @version 1.0 167 */ 168 enum struct CodecType { 169 AUDIO_DECODER, ///< Audio decoder 170 AUDIO_ENCODER, ///< Audio encoder 171 VIDEO_DECODER, ///< video decoder 172 VIDEO_ENCODER, ///< video encoder 173 }; 174 175 /** 176 * @brief Describes the codec plugin information. 177 * 178 * @since 1.0 179 * @version 1.0 180 */ 181 struct CodecPluginDef : public PluginDefBase { 182 CodecType codecType {}; 183 CapabilitySet inCaps {}; ///< Plug-in input capability, For details, @see Capability. 184 CapabilitySet outCaps {}; ///< Plug-in output capability, For details, @see Capability. 185 PluginCreatorFunc<CodecPlugin> creator {nullptr}; ///< Codec plugin create function. CodecPluginDefCodecPluginDef186 CodecPluginDef() 187 { 188 apiVersion = CODEC_API_VERSION; ///< Codec plugin version 189 pluginType = PluginType::CODEC; ///< Plugin type, MUST be CODEC. 190 } 191 }; 192 } // namespace Plugin 193 } // namespace Media 194 } // namespace OHOS 195 #endif // HISTREAMER_PLUGIN_INTF_CODEC_PLUGIN_H 196