1fa7767c5Sopenharmony_ci/* 2fa7767c5Sopenharmony_ci * Copyright (c) 2021-2021 Huawei Device Co., Ltd. 3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License. 5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at 6fa7767c5Sopenharmony_ci * 7fa7767c5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fa7767c5Sopenharmony_ci * 9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and 13fa7767c5Sopenharmony_ci * limitations under the License. 14fa7767c5Sopenharmony_ci */ 15fa7767c5Sopenharmony_ci 16fa7767c5Sopenharmony_ci#ifndef HISTREAMER_PLUGIN_INTF_SOURCE_PLUGIN_H 17fa7767c5Sopenharmony_ci#define HISTREAMER_PLUGIN_INTF_SOURCE_PLUGIN_H 18fa7767c5Sopenharmony_ci 19fa7767c5Sopenharmony_ci#include <map> 20fa7767c5Sopenharmony_ci#include <string> 21fa7767c5Sopenharmony_ci#include "plugin/common/media_source.h" 22fa7767c5Sopenharmony_ci#include "plugin/common/plugin_caps.h" 23fa7767c5Sopenharmony_ci#include "plugin/common/plugin_source_tags.h" 24fa7767c5Sopenharmony_ci#include "plugin/interface/plugin_base.h" 25fa7767c5Sopenharmony_ci#include "plugin/interface/plugin_definition.h" 26fa7767c5Sopenharmony_ci 27fa7767c5Sopenharmony_cinamespace OHOS { 28fa7767c5Sopenharmony_cinamespace Media { 29fa7767c5Sopenharmony_cinamespace Plugin { 30fa7767c5Sopenharmony_ci/** 31fa7767c5Sopenharmony_ci * @brief Source Plugin Interface. 32fa7767c5Sopenharmony_ci * 33fa7767c5Sopenharmony_ci * The data source may be network push or active read. 34fa7767c5Sopenharmony_ci * 35fa7767c5Sopenharmony_ci * @since 1.0 36fa7767c5Sopenharmony_ci * @version 1.0 37fa7767c5Sopenharmony_ci */ 38fa7767c5Sopenharmony_cistruct SourcePlugin : public PluginBase { 39fa7767c5Sopenharmony_ci /// constructor 40fa7767c5Sopenharmony_ci explicit SourcePlugin(std::string name): PluginBase(std::move(name)) {} 41fa7767c5Sopenharmony_ci /** 42fa7767c5Sopenharmony_ci * @brief Set the data source to source plugin. 43fa7767c5Sopenharmony_ci * 44fa7767c5Sopenharmony_ci * The function is valid only in the CREATED state. 45fa7767c5Sopenharmony_ci * 46fa7767c5Sopenharmony_ci * @param source data source, uri or stream source 47fa7767c5Sopenharmony_ci * @return Execution status return 48fa7767c5Sopenharmony_ci * @retval OK: Plugin SetSource succeeded. 49fa7767c5Sopenharmony_ci * @retval ERROR_WRONG_STATE: Call this function in non wrong state 50fa7767c5Sopenharmony_ci * @retval ERROR_NOT_EXISTED: Uri is not existed. 51fa7767c5Sopenharmony_ci * @retval ERROR_UNSUPPORTED_FORMAT: Uri is not supported. 52fa7767c5Sopenharmony_ci * @retval ERROR_INVALID_PARAMETER: Uri is invalid. 53fa7767c5Sopenharmony_ci */ 54fa7767c5Sopenharmony_ci virtual OHOS::Media::Plugin::Status SetSource(std::shared_ptr<MediaSource> source) = 0; 55fa7767c5Sopenharmony_ci 56fa7767c5Sopenharmony_ci /** 57fa7767c5Sopenharmony_ci * @brief Read data from data source. 58fa7767c5Sopenharmony_ci * 59fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 60fa7767c5Sopenharmony_ci * 61fa7767c5Sopenharmony_ci * @param buffer Buffer to store the data, it can be nullptr or empty to get the buffer from plugin. 62fa7767c5Sopenharmony_ci * @param expectedLen Expected data size to be read 63fa7767c5Sopenharmony_ci * @return Execution status return 64fa7767c5Sopenharmony_ci * @retval OK: Plugin Read succeeded. 65fa7767c5Sopenharmony_ci * @retval ERROR_NOT_ENOUGH_DATA: Data not enough 66fa7767c5Sopenharmony_ci * @retval END_OF_STREAM: End of stream 67fa7767c5Sopenharmony_ci */ 68fa7767c5Sopenharmony_ci virtual Status Read(std::shared_ptr<Buffer>& buffer, size_t expectedLen) = 0; 69fa7767c5Sopenharmony_ci 70fa7767c5Sopenharmony_ci /** 71fa7767c5Sopenharmony_ci * @brief Get data source size. 72fa7767c5Sopenharmony_ci * 73fa7767c5Sopenharmony_ci * The function is valid only after INITIALIZED state. 74fa7767c5Sopenharmony_ci * 75fa7767c5Sopenharmony_ci * @param size data source size. 76fa7767c5Sopenharmony_ci * @return Execution status return. 77fa7767c5Sopenharmony_ci * @retval OK: Plugin GetSize succeeded. 78fa7767c5Sopenharmony_ci */ 79fa7767c5Sopenharmony_ci virtual Status GetSize(uint64_t& size) = 0; 80fa7767c5Sopenharmony_ci 81fa7767c5Sopenharmony_ci /** 82fa7767c5Sopenharmony_ci * @brief Indicates that the current source can be seek. 83fa7767c5Sopenharmony_ci * 84fa7767c5Sopenharmony_ci * The function is valid only after INITIALIZED state. 85fa7767c5Sopenharmony_ci * 86fa7767c5Sopenharmony_ci * @return Execution status return 87fa7767c5Sopenharmony_ci * @retval OK: Plugin GetSeekable succeeded. 88fa7767c5Sopenharmony_ci */ 89fa7767c5Sopenharmony_ci virtual Seekable GetSeekable() = 0; 90fa7767c5Sopenharmony_ci 91fa7767c5Sopenharmony_ci /** 92fa7767c5Sopenharmony_ci * @brief Seeks for a specified position for the source. 93fa7767c5Sopenharmony_ci * 94fa7767c5Sopenharmony_ci * After being started, the source seeks for a specified position to read data frames. 95fa7767c5Sopenharmony_ci * 96fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 97fa7767c5Sopenharmony_ci * 98fa7767c5Sopenharmony_ci * @param offset position to read data frames 99fa7767c5Sopenharmony_ci * @return Execution status return 100fa7767c5Sopenharmony_ci * @retval OK: Plugin SeekTo succeeded. 101fa7767c5Sopenharmony_ci * @retval ERROR_INVALID_DATA: The offset is invalid. 102fa7767c5Sopenharmony_ci */ 103fa7767c5Sopenharmony_ci virtual Status SeekToPos(int64_t offset) 104fa7767c5Sopenharmony_ci { 105fa7767c5Sopenharmony_ci return Status::ERROR_UNIMPLEMENTED; 106fa7767c5Sopenharmony_ci } 107fa7767c5Sopenharmony_ci 108fa7767c5Sopenharmony_ci /** 109fa7767c5Sopenharmony_ci * @brief seek to pos by time 110fa7767c5Sopenharmony_ci * @return Execution status return 111fa7767c5Sopenharmony_ci */ 112fa7767c5Sopenharmony_ci virtual Status SeekToTime(int64_t offset) 113fa7767c5Sopenharmony_ci { 114fa7767c5Sopenharmony_ci return Status::ERROR_UNIMPLEMENTED; 115fa7767c5Sopenharmony_ci } 116fa7767c5Sopenharmony_ci 117fa7767c5Sopenharmony_ci /** 118fa7767c5Sopenharmony_ci * @brief Get duration from current source 119fa7767c5Sopenharmony_ci * @return Execution status return 120fa7767c5Sopenharmony_ci */ 121fa7767c5Sopenharmony_ci virtual Status GetDuration(int64_t& duration) 122fa7767c5Sopenharmony_ci { 123fa7767c5Sopenharmony_ci return Status::ERROR_UNIMPLEMENTED; 124fa7767c5Sopenharmony_ci } 125fa7767c5Sopenharmony_ci 126fa7767c5Sopenharmony_ci /** 127fa7767c5Sopenharmony_ci * @brief Get bitrates that current source supports 128fa7767c5Sopenharmony_ci * @return Execution status return 129fa7767c5Sopenharmony_ci */ 130fa7767c5Sopenharmony_ci virtual Status GetBitRates(std::vector<uint32_t>& bitRates) 131fa7767c5Sopenharmony_ci { 132fa7767c5Sopenharmony_ci return Status::ERROR_UNIMPLEMENTED; 133fa7767c5Sopenharmony_ci } 134fa7767c5Sopenharmony_ci 135fa7767c5Sopenharmony_ci /** 136fa7767c5Sopenharmony_ci * @brief Select bitrate for current source 137fa7767c5Sopenharmony_ci * @param bitRate user selects a bitrate 138fa7767c5Sopenharmony_ci * @return Execution status return 139fa7767c5Sopenharmony_ci */ 140fa7767c5Sopenharmony_ci virtual Status SelectBitRate(uint32_t bitRate) 141fa7767c5Sopenharmony_ci { 142fa7767c5Sopenharmony_ci return Status::ERROR_UNIMPLEMENTED; 143fa7767c5Sopenharmony_ci } 144fa7767c5Sopenharmony_ci}; 145fa7767c5Sopenharmony_ci 146fa7767c5Sopenharmony_ci/// Source plugin api major number. 147fa7767c5Sopenharmony_ci#define SOURCE_API_VERSION_MAJOR (1) 148fa7767c5Sopenharmony_ci 149fa7767c5Sopenharmony_ci/// Source plugin api minor number 150fa7767c5Sopenharmony_ci#define SOURCE_API_VERSION_MINOR (0) 151fa7767c5Sopenharmony_ci 152fa7767c5Sopenharmony_ci/// Source plugin version 153fa7767c5Sopenharmony_ci#define SOURCE_API_VERSION MAKE_VERSION(SOURCE_API_VERSION_MAJOR, SOURCE_API_VERSION_MINOR) 154fa7767c5Sopenharmony_ci 155fa7767c5Sopenharmony_ci/** 156fa7767c5Sopenharmony_ci * @brief Describes the source plugin information. 157fa7767c5Sopenharmony_ci * 158fa7767c5Sopenharmony_ci * @since 1.0 159fa7767c5Sopenharmony_ci * @version 1.0 160fa7767c5Sopenharmony_ci */ 161fa7767c5Sopenharmony_cistruct SourcePluginDef : public PluginDefBase { 162fa7767c5Sopenharmony_ci std::vector<ProtocolType> protocol; ///< Protocols supported by playback source 163fa7767c5Sopenharmony_ci SrcInputType inputType; ///< Input type supported by record source 164fa7767c5Sopenharmony_ci CapabilitySet outCaps; ///< Plug-in output capability, For details, @see Capability. 165fa7767c5Sopenharmony_ci PluginCreatorFunc<SourcePlugin> creator {nullptr}; ///< Source plugin create function. 166fa7767c5Sopenharmony_ci SourcePluginDef() 167fa7767c5Sopenharmony_ci { 168fa7767c5Sopenharmony_ci apiVersion = SOURCE_API_VERSION; ///< Source plugin version. 169fa7767c5Sopenharmony_ci pluginType = PluginType::SOURCE; ///< Plugin type, MUST be SOURCE. 170fa7767c5Sopenharmony_ci } 171fa7767c5Sopenharmony_ci}; 172fa7767c5Sopenharmony_ci} // namespace Plugin 173fa7767c5Sopenharmony_ci} // namespace Media 174fa7767c5Sopenharmony_ci} // namespace OHOS 175fa7767c5Sopenharmony_ci#endif // HISTREAMER_PLUGIN_INTF_SOURCE_PLUGIN_H 176