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