1 /* 2 * Copyright (c) 2023-2023 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 AVCODEC_SOURCE_PLUGIN_H 17 #define AVCODEC_SOURCE_PLUGIN_H 18 19 #include <map> 20 #include <string> 21 22 #include "common/media_source.h" 23 #include "plugin/plugin_base.h" 24 #include "plugin/plugin_buffer.h" 25 #include "plugin/plugin_caps.h" 26 #include "plugin/plugin_definition.h" 27 #include "plugin/plugin_time.h" 28 29 namespace OHOS { 30 namespace Media { 31 namespace Plugins { 32 /** 33 * @brief Source Plugin Interface. 34 * 35 * The data source may be network push or active read. 36 * 37 * @since 1.0 38 * @version 1.0 39 */ 40 class SourcePlugin : public PluginBase { 41 /// constructor 42 public: SourcePlugin(std::string name)43 explicit SourcePlugin(std::string name): PluginBase(std::move(name)) {} 44 /** 45 * @brief Set the data source to source plugin. 46 * 47 * The function is valid only in the CREATED state. 48 * 49 * @param source data source, uri or stream source 50 * @return Execution status return 51 * @retval OK: Plugin SetSource succeeded. 52 * @retval ERROR_WRONG_STATE: Call this function in non wrong state 53 * @retval ERROR_NOT_EXISTED: Uri is not existed. 54 * @retval ERROR_UNSUPPORTED_FORMAT: Uri is not supported. 55 * @retval ERROR_INVALID_PARAMETER: Uri is invalid. 56 */ 57 virtual Status SetSource(std::shared_ptr<MediaSource> source) = 0; 58 59 /** 60 * @brief Read data from data source. 61 * 62 * The function is valid only after RUNNING state. 63 * 64 * @param buffer Buffer to store the data, it can be nullptr or empty to get the buffer from plugin. 65 * @param expectedLen Expected data size to be read 66 * @return Execution status return 67 * @retval OK: Plugin Read succeeded. 68 * @retval ERROR_NOT_ENOUGH_DATA: Data not enough 69 * @retval END_OF_STREAM: End of stream 70 */ 71 virtual Status Read(std::shared_ptr<Buffer>& buffer, uint64_t offset, size_t expectedLen) = 0; 72 73 /** 74 * @brief Get data source size. 75 * 76 * The function is valid only after INITIALIZED state. 77 * 78 * @param size data source size. 79 * @return Execution status return. 80 * @retval OK: Plugin GetSize succeeded. 81 */ 82 virtual Status GetSize(uint64_t& size) = 0; 83 84 /** 85 * @brief Indicates that the current source can be seek. 86 * 87 * The function is valid only after INITIALIZED state. 88 * 89 * @return Execution status return 90 * @retval OK: Plugin GetSeekable succeeded. 91 */ 92 virtual Seekable GetSeekable() = 0; 93 94 /** 95 * @brief Seeks for a specified position for the source. 96 * 97 * After being started, the source seeks for a specified position to read data frames. 98 * 99 * The function is valid only after RUNNING state. 100 * 101 * @param offset position to read data frames 102 * @return Execution status return 103 * @retval OK: Plugin SeekTo succeeded. 104 * @retval ERROR_INVALID_DATA: The offset is invalid. 105 */ 106 virtual Status SeekTo(uint64_t offset) = 0; 107 108 virtual Status Reset() = 0; 109 GetBitRates(std::vector<uint32_t> & bitRates)110 virtual Status GetBitRates(std::vector<uint32_t>& bitRates) 111 { 112 return Status::OK; 113 } 114 SelectBitRate(uint32_t bitRate)115 virtual Status SelectBitRate(uint32_t bitRate) 116 { 117 return Status::OK; 118 } 119 IsSeekToTimeSupported()120 virtual bool IsSeekToTimeSupported() 121 { 122 return false; 123 } 124 SeekToTime(int64_t seekTime)125 virtual Status SeekToTime(int64_t seekTime) 126 { 127 return Status::OK; 128 } 129 GetDuration(int64_t & duration)130 virtual Status GetDuration(int64_t& duration) 131 { 132 duration = Plugins::HST_TIME_NONE; 133 return Status::OK; 134 } 135 IsNeedPreDownload()136 virtual bool IsNeedPreDownload() 137 { 138 return false; 139 } 140 SetReadBlockingFlag(bool isReadBlockingAllowed)141 virtual Status SetReadBlockingFlag(bool isReadBlockingAllowed) 142 { 143 return Status::OK; 144 } 145 }; 146 147 /// Source plugin api major number. 148 #define SOURCE_API_VERSION_MAJOR (1) 149 150 /// Source plugin api minor number 151 #define SOURCE_API_VERSION_MINOR (0) 152 153 /// Source plugin version 154 #define SOURCE_API_VERSION MAKE_VERSION(SOURCE_API_VERSION_MAJOR, SOURCE_API_VERSION_MINOR) 155 156 /** 157 * @brief Describes the source plugin information. 158 * 159 * @since 1.0 160 * @version 1.0 161 */ 162 struct SourcePluginDef : public PluginDefBase { SourcePluginDefSourcePluginDef163 SourcePluginDef() 164 : PluginDefBase() 165 { 166 apiVersion = SOURCE_API_VERSION; ///< Source plugin version. 167 pluginType = PluginType::SOURCE; ///< Plugin type, MUST be SOURCE. 168 } 169 }; 170 } // namespace Plugins 171 } // namespace Media 172 } // namespace OHOS 173 #endif // AVCODEC_SOURCE_PLUGIN_H 174