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 "plugin/common/plugin_caps.h" 21 #include "plugin/interface/plugin_base.h" 22 #include "plugin/interface/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(const 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(const 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 QueueInputBuffer 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 Queues output data 85 * 86 * This function works with DataCallback::OnOutputBufferDone to implement output data transmission. 87 * 88 * The function is valid only in the RUNNING state. 89 * 90 * @param outputBuffers Indicates the pointer to the output data. 91 * @param timeoutMs Indicates the timeout duration. 92 * @return Execution status return 93 * @retval OK: Plugin QueueOutputBuffer succeeded. 94 * @retval ERROR_INVALID_DATA: The output buffer is invalid. 95 * @retval ERROR_TIMED_OUT: Operation timeout. 96 */ 97 virtual Status QueueOutputBuffer(const std::shared_ptr<Buffer>& outputBuffers, int32_t timeoutMs) = 0; 98 99 /** 100 * @brief Flushes data in the audio buffer. 101 * 102 * The function is valid only in after RUNNING state. 103 * 104 * @return Execution status return 105 * @retval OK: Plugin Flush succeeded. 106 */ 107 virtual Status Flush() = 0; 108 109 /** 110 * @brief Sets the plugin callback data to notify the plugin user. 111 * 112 * This function can be called in any state except DESTROYED and INVALID. 113 * 114 * @param cb Data callback, NULL callback listening is canceled. 115 * @return Execution status return 116 * @retval OK: Plugin SetDataCallback succeeded. 117 */ 118 virtual Status SetDataCallback(DataCallback* dataCallback) = 0; 119 }; 120 121 /// Codec plugin api major number. 122 #define CODEC_API_VERSION_MAJOR (1) 123 124 /// Codec plugin api minor number 125 #define CODEC_API_VERSION_MINOR (0) 126 127 /// Codec plugin version 128 #define CODEC_API_VERSION MAKE_VERSION(CODEC_API_VERSION_MAJOR, CODEC_API_VERSION_MINOR) 129 130 /** 131 * @brief Describes the codec plugin information. 132 * 133 * @since 1.0 134 * @version 1.0 135 */ 136 struct CodecPluginDef : public PluginDefBase { 137 CodecMode codecMode {CodecMode::SOFTWARE}; 138 CapabilitySet inCaps {}; ///< Plug-in input capability, For details, @see Capability. 139 CapabilitySet outCaps {}; ///< Plug-in output capability, For details, @see Capability. 140 PluginCreatorFunc<CodecPlugin> creator {nullptr}; ///< Codec plugin create function. CodecPluginDefCodecPluginDef141 CodecPluginDef() 142 { 143 apiVersion = CODEC_API_VERSION; ///< Codec plugin version 144 } 145 }; 146 } // namespace Plugin 147 } // namespace Media 148 } // namespace OHOS 149 #endif // HISTREAMER_PLUGIN_INTF_CODEC_PLUGIN_H 150