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_DEMUXER_PLUGIN_H 17fa7767c5Sopenharmony_ci#define HISTREAMER_PLUGIN_INTF_DEMUXER_PLUGIN_H 18fa7767c5Sopenharmony_ci 19fa7767c5Sopenharmony_ci#include <memory> 20fa7767c5Sopenharmony_ci#include <vector> 21fa7767c5Sopenharmony_ci#include "plugin/common/plugin_caps.h" 22fa7767c5Sopenharmony_ci#include "plugin/interface/plugin_base.h" 23fa7767c5Sopenharmony_ci#include "plugin/interface/plugin_definition.h" 24fa7767c5Sopenharmony_ci 25fa7767c5Sopenharmony_cinamespace OHOS { 26fa7767c5Sopenharmony_cinamespace Media { 27fa7767c5Sopenharmony_cinamespace Plugin { 28fa7767c5Sopenharmony_ci/** 29fa7767c5Sopenharmony_ci * @brief MediaInfo is a facilitate unified display of the relevant technical and 30fa7767c5Sopenharmony_ci * tag data for video and audio files. 31fa7767c5Sopenharmony_ci * 32fa7767c5Sopenharmony_ci * MediaInfo reveals information such as: 33fa7767c5Sopenharmony_ci * - General: artist, album, author, copyright, date, duration, etc. 34fa7767c5Sopenharmony_ci * - Tracks: such as codec, channel, bitrate, etc. 35fa7767c5Sopenharmony_ci * @see Tag 36fa7767c5Sopenharmony_ci * 37fa7767c5Sopenharmony_ci * @since 1.0 38fa7767c5Sopenharmony_ci * @version 1.0 39fa7767c5Sopenharmony_ci */ 40fa7767c5Sopenharmony_cistruct MediaInfo { 41fa7767c5Sopenharmony_ci Meta general; ///< General information 42fa7767c5Sopenharmony_ci std::vector<Meta> tracks; ///< Media tracks, include audio, video and text 43fa7767c5Sopenharmony_ci}; 44fa7767c5Sopenharmony_ci 45fa7767c5Sopenharmony_ci/** 46fa7767c5Sopenharmony_ci * @brief Data source operation interface. 47fa7767c5Sopenharmony_ci * 48fa7767c5Sopenharmony_ci * @since 1.0 49fa7767c5Sopenharmony_ci * @version 1.0 50fa7767c5Sopenharmony_ci */ 51fa7767c5Sopenharmony_cistruct DataSource { 52fa7767c5Sopenharmony_ci /// Destructor 53fa7767c5Sopenharmony_ci virtual ~DataSource() = default; 54fa7767c5Sopenharmony_ci 55fa7767c5Sopenharmony_ci /** 56fa7767c5Sopenharmony_ci * @brief Read data from data source. 57fa7767c5Sopenharmony_ci * 58fa7767c5Sopenharmony_ci * @param offset Offset of read position 59fa7767c5Sopenharmony_ci * @param buffer Storage of the read data 60fa7767c5Sopenharmony_ci * @param expectedLen Expected data size to be read 61fa7767c5Sopenharmony_ci * @return Execution status return 62fa7767c5Sopenharmony_ci * @retval OK: Plugin ReadAt succeeded. 63fa7767c5Sopenharmony_ci * @retval ERROR_NOT_ENOUGH_DATA: Data not enough 64fa7767c5Sopenharmony_ci * @retval END_OF_STREAM: End of stream 65fa7767c5Sopenharmony_ci */ 66fa7767c5Sopenharmony_ci virtual Status ReadAt(int64_t offset, std::shared_ptr<Buffer>& buffer, size_t expectedLen) = 0; 67fa7767c5Sopenharmony_ci 68fa7767c5Sopenharmony_ci /** 69fa7767c5Sopenharmony_ci * @brief Get data source size. 70fa7767c5Sopenharmony_ci * 71fa7767c5Sopenharmony_ci * @param size data source size. 72fa7767c5Sopenharmony_ci * @return Execution status return. 73fa7767c5Sopenharmony_ci * @retval OK: Plugin GetSize succeeded. 74fa7767c5Sopenharmony_ci */ 75fa7767c5Sopenharmony_ci virtual Status GetSize(uint64_t& size) = 0; 76fa7767c5Sopenharmony_ci 77fa7767c5Sopenharmony_ci /** 78fa7767c5Sopenharmony_ci * @brief Indicates that the current data source seekable or not. 79fa7767c5Sopenharmony_ci * 80fa7767c5Sopenharmony_ci * The function is valid only after INITIALIZED state. 81fa7767c5Sopenharmony_ci * 82fa7767c5Sopenharmony_ci * @return Seekable status 83fa7767c5Sopenharmony_ci */ 84fa7767c5Sopenharmony_ci virtual Seekable GetSeekable() = 0; 85fa7767c5Sopenharmony_ci}; 86fa7767c5Sopenharmony_ci 87fa7767c5Sopenharmony_ci/** 88fa7767c5Sopenharmony_ci * @brief Demuxer Plugin Interface. 89fa7767c5Sopenharmony_ci * 90fa7767c5Sopenharmony_ci * Used for audio and video media file parse. 91fa7767c5Sopenharmony_ci * 92fa7767c5Sopenharmony_ci * @since 1.0 93fa7767c5Sopenharmony_ci * @version 1.0 94fa7767c5Sopenharmony_ci */ 95fa7767c5Sopenharmony_cistruct DemuxerPlugin : public PluginBase { 96fa7767c5Sopenharmony_ci /// constructor 97fa7767c5Sopenharmony_ci explicit DemuxerPlugin(std::string name): PluginBase(std::move(name)) {} 98fa7767c5Sopenharmony_ci /** 99fa7767c5Sopenharmony_ci * @brief Set the data source to demuxer component. 100fa7767c5Sopenharmony_ci * 101fa7767c5Sopenharmony_ci * The function is valid only in the CREATED state. 102fa7767c5Sopenharmony_ci * 103fa7767c5Sopenharmony_ci * @param source Data source where data read from. 104fa7767c5Sopenharmony_ci * @return Execution status return 105fa7767c5Sopenharmony_ci * @retval OK: Plugin SetDataSource succeeded. 106fa7767c5Sopenharmony_ci */ 107fa7767c5Sopenharmony_ci virtual Status SetDataSource(const std::shared_ptr<DataSource>& source) = 0; 108fa7767c5Sopenharmony_ci 109fa7767c5Sopenharmony_ci /** 110fa7767c5Sopenharmony_ci * @brief Get the attributes of a media file. 111fa7767c5Sopenharmony_ci * 112fa7767c5Sopenharmony_ci * The attributes contain file and stream attributes. 113fa7767c5Sopenharmony_ci * The function is valid only after INITIALIZED state. 114fa7767c5Sopenharmony_ci * 115fa7767c5Sopenharmony_ci * @param mediaInfo Indicates the pointer to the source attributes 116fa7767c5Sopenharmony_ci * @return Execution status return 117fa7767c5Sopenharmony_ci * @retval OK: Plugin GetMediaInfo succeeded. 118fa7767c5Sopenharmony_ci */ 119fa7767c5Sopenharmony_ci virtual Status GetMediaInfo(MediaInfo& mediaInfo) = 0; 120fa7767c5Sopenharmony_ci 121fa7767c5Sopenharmony_ci /** 122fa7767c5Sopenharmony_ci * @brief Get the stack count from the data source. 123fa7767c5Sopenharmony_ci * 124fa7767c5Sopenharmony_ci * The function is valid only after INITIALIZED state. 125fa7767c5Sopenharmony_ci * 126fa7767c5Sopenharmony_ci * @return number of tracks. 127fa7767c5Sopenharmony_ci */ 128fa7767c5Sopenharmony_ci virtual size_t GetTrackCount() = 0; 129fa7767c5Sopenharmony_ci 130fa7767c5Sopenharmony_ci /** 131fa7767c5Sopenharmony_ci * @brief Select a specified media track. 132fa7767c5Sopenharmony_ci * 133fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 134fa7767c5Sopenharmony_ci * 135fa7767c5Sopenharmony_ci * @param trackId Identifies the media track. If an invalid value is passed, the default media track specified. 136fa7767c5Sopenharmony_ci * @return Execution status return 137fa7767c5Sopenharmony_ci * @retval OK: Plugin SelectTrack succeeded. 138fa7767c5Sopenharmony_ci */ 139fa7767c5Sopenharmony_ci virtual Status SelectTrack(int32_t trackId) = 0; 140fa7767c5Sopenharmony_ci 141fa7767c5Sopenharmony_ci /** 142fa7767c5Sopenharmony_ci * @brief Unselect a specified media track from which the demuxer reads data frames. 143fa7767c5Sopenharmony_ci * 144fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 145fa7767c5Sopenharmony_ci * 146fa7767c5Sopenharmony_ci * @param trackId Identifies the media track. ignore the invalid value is passed. 147fa7767c5Sopenharmony_ci * @return Execution status return 148fa7767c5Sopenharmony_ci * @retval OK: Plugin UnselectTrack succeeded. 149fa7767c5Sopenharmony_ci */ 150fa7767c5Sopenharmony_ci virtual Status UnselectTrack(int32_t trackId) = 0; 151fa7767c5Sopenharmony_ci 152fa7767c5Sopenharmony_ci /** 153fa7767c5Sopenharmony_ci * @brief Get the ID of the media track selected by the demuxer for output. 154fa7767c5Sopenharmony_ci * 155fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 156fa7767c5Sopenharmony_ci * 157fa7767c5Sopenharmony_ci * @param trackIds Identifies the array of selected media tracks. 158fa7767c5Sopenharmony_ci * @return Execution status return 159fa7767c5Sopenharmony_ci * @retval OK: Plugin GetSelectedTracks succeeded. 160fa7767c5Sopenharmony_ci */ 161fa7767c5Sopenharmony_ci virtual Status GetSelectedTracks(std::vector<int32_t>& trackIds) = 0; 162fa7767c5Sopenharmony_ci 163fa7767c5Sopenharmony_ci /** 164fa7767c5Sopenharmony_ci * @brief Reads data frames. 165fa7767c5Sopenharmony_ci * 166fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 167fa7767c5Sopenharmony_ci * 168fa7767c5Sopenharmony_ci * @param buffer Indicates the pointer to the data buffer. 169fa7767c5Sopenharmony_ci * @param timeOutMs Indicates the time required for waiting data frame read. 170fa7767c5Sopenharmony_ci * @return Execution status return 171fa7767c5Sopenharmony_ci * @retval OK: Plugin ReadFrame succeeded. 172fa7767c5Sopenharmony_ci * @retval ERROR_TIMED_OUT: Operation timeout. 173fa7767c5Sopenharmony_ci */ 174fa7767c5Sopenharmony_ci virtual Status ReadFrame(Buffer& buffer, int32_t timeOutMs) = 0; 175fa7767c5Sopenharmony_ci 176fa7767c5Sopenharmony_ci /** 177fa7767c5Sopenharmony_ci * @brief Seeks for a specified position for the demuxer. 178fa7767c5Sopenharmony_ci * 179fa7767c5Sopenharmony_ci * After being started, the demuxer seeks for a specified position to read data frames. 180fa7767c5Sopenharmony_ci * 181fa7767c5Sopenharmony_ci * The function is valid only after RUNNING state. 182fa7767c5Sopenharmony_ci * 183fa7767c5Sopenharmony_ci * @param trackId Identifies the stream in the media file. 184fa7767c5Sopenharmony_ci * @param seekTime Indicates the target position, based on {@link HST_TIME_BASE} . 185fa7767c5Sopenharmony_ci * @param mode Indicates the seek mode. 186fa7767c5Sopenharmony_ci * @param realSeekTime Indicates the accurate target position, based on {@link HST_TIME_BASE} . 187fa7767c5Sopenharmony_ci * @return Execution status return 188fa7767c5Sopenharmony_ci * @retval OK: Plugin SeekTo succeeded. 189fa7767c5Sopenharmony_ci * @retval ERROR_INVALID_DATA: The input data is invalid. 190fa7767c5Sopenharmony_ci */ 191fa7767c5Sopenharmony_ci virtual Status SeekTo(int32_t trackId, int64_t seekTime, SeekMode mode, int64_t& realSeekTime) = 0; 192fa7767c5Sopenharmony_ci}; 193fa7767c5Sopenharmony_ci 194fa7767c5Sopenharmony_ci/// Demuxer plugin api major number. 195fa7767c5Sopenharmony_ci#define DEMUXER_API_VERSION_MAJOR (1) 196fa7767c5Sopenharmony_ci 197fa7767c5Sopenharmony_ci/// Demuxer plugin api minor number 198fa7767c5Sopenharmony_ci#define DEMUXER_API_VERSION_MINOR (0) 199fa7767c5Sopenharmony_ci 200fa7767c5Sopenharmony_ci/// Demuxer plugin version 201fa7767c5Sopenharmony_ci#define DEMUXER_API_VERSION MAKE_VERSION(DEMUXER_API_VERSION_MAJOR, DEMUXER_API_VERSION_MINOR) 202fa7767c5Sopenharmony_ci 203fa7767c5Sopenharmony_ci/// Demuxer sniff function 204fa7767c5Sopenharmony_ciusing DemuxerPluginSnifferFunc = int (*)(const std::string& name, std::shared_ptr<DataSource> dataSource); 205fa7767c5Sopenharmony_ci 206fa7767c5Sopenharmony_ci/** 207fa7767c5Sopenharmony_ci * @brief Describes the demuxer plugin information. 208fa7767c5Sopenharmony_ci * 209fa7767c5Sopenharmony_ci * @since 1.0 210fa7767c5Sopenharmony_ci * @version 1.0 211fa7767c5Sopenharmony_ci */ 212fa7767c5Sopenharmony_cistruct DemuxerPluginDef : public PluginDefBase { 213fa7767c5Sopenharmony_ci std::vector<std::string> extensions; ///< File extensions supported by demuxer 214fa7767c5Sopenharmony_ci CapabilitySet inCaps; ///< Plug-in input capability, For details, @see Capability. 215fa7767c5Sopenharmony_ci CapabilitySet outCaps; ///< Plug-in output capability, For details, @see Capability. 216fa7767c5Sopenharmony_ci PluginCreatorFunc<DemuxerPlugin> creator {nullptr}; ///< Demuxer plugin create function. 217fa7767c5Sopenharmony_ci DemuxerPluginSnifferFunc sniffer {nullptr}; ///< Demuxer plugin sniff function. 218fa7767c5Sopenharmony_ci DemuxerPluginDef() 219fa7767c5Sopenharmony_ci { 220fa7767c5Sopenharmony_ci apiVersion = DEMUXER_API_VERSION; ///< Demuxer plugin version. 221fa7767c5Sopenharmony_ci pluginType = PluginType::DEMUXER; ///< Plugin type, MUST be DEMUXER. 222fa7767c5Sopenharmony_ci } 223fa7767c5Sopenharmony_ci}; 224fa7767c5Sopenharmony_ci} // namespace Plugin 225fa7767c5Sopenharmony_ci} // namespace Media 226fa7767c5Sopenharmony_ci} // namespace OHOS 227fa7767c5Sopenharmony_ci#endif // HISTREAMER_PLUGIN_INTF_DEMUXER_PLUGIN_H 228