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_SOURCE_PLUGIN_H 17 #define HISTREAMER_PLUGIN_INTF_SOURCE_PLUGIN_H 18 19 #include <map> 20 #include <string> 21 #include "plugin/common/media_source.h" 22 #include "plugin/common/plugin_caps.h" 23 #include "plugin/common/plugin_source_tags.h" 24 #include "plugin/interface/plugin_base.h" 25 #include "plugin/interface/plugin_definition.h" 26 27 namespace OHOS { 28 namespace Media { 29 namespace Plugin { 30 /** 31 * @brief Source Plugin Interface. 32 * 33 * The data source may be network push or active read. 34 * 35 * @since 1.0 36 * @version 1.0 37 */ 38 struct SourcePlugin : public PluginBase { 39 /// constructor SourcePluginSourcePlugin40 explicit SourcePlugin(std::string name): PluginBase(std::move(name)) {} 41 /** 42 * @brief Set the data source to source plugin. 43 * 44 * The function is valid only in the CREATED state. 45 * 46 * @param source data source, uri or stream source 47 * @return Execution status return 48 * @retval OK: Plugin SetSource succeeded. 49 * @retval ERROR_WRONG_STATE: Call this function in non wrong state 50 * @retval ERROR_NOT_EXISTED: Uri is not existed. 51 * @retval ERROR_UNSUPPORTED_FORMAT: Uri is not supported. 52 * @retval ERROR_INVALID_PARAMETER: Uri is invalid. 53 */ 54 virtual OHOS::Media::Plugin::Status SetSource(std::shared_ptr<MediaSource> source) = 0; 55 56 /** 57 * @brief Read data from data source. 58 * 59 * The function is valid only after RUNNING state. 60 * 61 * @param buffer Buffer to store the data, it can be nullptr or empty to get the buffer from plugin. 62 * @param expectedLen Expected data size to be read 63 * @return Execution status return 64 * @retval OK: Plugin Read succeeded. 65 * @retval ERROR_NOT_ENOUGH_DATA: Data not enough 66 * @retval END_OF_STREAM: End of stream 67 */ 68 virtual Status Read(std::shared_ptr<Buffer>& buffer, size_t expectedLen) = 0; 69 70 /** 71 * @brief Get data source size. 72 * 73 * The function is valid only after INITIALIZED state. 74 * 75 * @param size data source size. 76 * @return Execution status return. 77 * @retval OK: Plugin GetSize succeeded. 78 */ 79 virtual Status GetSize(uint64_t& size) = 0; 80 81 /** 82 * @brief Indicates that the current source can be seek. 83 * 84 * The function is valid only after INITIALIZED state. 85 * 86 * @return Execution status return 87 * @retval OK: Plugin GetSeekable succeeded. 88 */ 89 virtual Seekable GetSeekable() = 0; 90 91 /** 92 * @brief Seeks for a specified position for the source. 93 * 94 * After being started, the source seeks for a specified position to read data frames. 95 * 96 * The function is valid only after RUNNING state. 97 * 98 * @param offset position to read data frames 99 * @return Execution status return 100 * @retval OK: Plugin SeekTo succeeded. 101 * @retval ERROR_INVALID_DATA: The offset is invalid. 102 */ 103 virtual Status SeekTo(uint64_t offset) = 0; 104 }; 105 106 /// Source plugin api major number. 107 #define SOURCE_API_VERSION_MAJOR (1) 108 109 /// Source plugin api minor number 110 #define SOURCE_API_VERSION_MINOR (0) 111 112 /// Source plugin version 113 #define SOURCE_API_VERSION MAKE_VERSION(SOURCE_API_VERSION_MAJOR, SOURCE_API_VERSION_MINOR) 114 115 /** 116 * @brief Describes the source plugin information. 117 * 118 * @since 1.0 119 * @version 1.0 120 */ 121 struct SourcePluginDef : public PluginDefBase { 122 std::vector<ProtocolType> protocol; ///< Protocols supported by playback source 123 SrcInputType inputType; ///< Input type supported by record source 124 CapabilitySet outCaps; ///< Plug-in output capability, For details, @see Capability. 125 PluginCreatorFunc<SourcePlugin> creator {nullptr}; ///< Source plugin create function. SourcePluginDefSourcePluginDef126 SourcePluginDef() 127 { 128 apiVersion = SOURCE_API_VERSION; ///< Source plugin version. 129 pluginType = PluginType::SOURCE; ///< Plugin type, MUST be SOURCE. 130 } 131 }; 132 } // namespace Plugin 133 } // namespace Media 134 } // namespace OHOS 135 #endif // HISTREAMER_PLUGIN_INTF_SOURCE_PLUGIN_H 136