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_DEMUXER_PLUGIN_H 17 #define AVCODEC_DEMUXER_PLUGIN_H 18 19 #include <memory> 20 #include <vector> 21 #include "meta/meta.h" 22 #include "plugin/plugin_base.h" 23 #include "plugin/plugin_caps.h" 24 #include "plugin/plugin_definition.h" 25 #include "plugin/plugin_info.h" 26 #include "common/media_core.h" 27 28 namespace OHOS { 29 namespace Media { 30 namespace Plugins { 31 /** 32 * @brief Demuxer Plugin Interface. 33 * 34 * Used for audio and video media file parse. 35 * 36 * @since 1.0 37 * @version 1.0 38 */ 39 struct DemuxerPlugin : public PluginBase { 40 /// constructor DemuxerPluginDemuxerPlugin41 explicit DemuxerPlugin(std::string name): PluginBase(std::move(name)) {} 42 /** 43 * @brief Set the data source to demuxer component. 44 * 45 * The function is valid only in the CREATED state. 46 * 47 * @param source Data source where data read from. 48 * @return Execution Status return 49 * @retval OK: Plugin SetDataSource succeeded. 50 */ 51 virtual Status SetDataSource(const std::shared_ptr<DataSource>& source) = 0; 52 53 /** 54 * @brief Get the attributes of a media file. 55 * 56 * The attributes contain file and stream attributes. 57 * The function is valid only after INITIALIZED state. 58 * 59 * @param mediaInfo Indicates the pointer to the source attributes 60 * @return Execution status return 61 * @retval OK: Plugin GetMediaInfo succeeded. 62 */ 63 virtual Status GetMediaInfo(MediaInfo& mediaInfo) = 0; 64 65 /** 66 * @brief Get the user meta of a media file. 67 * 68 * The attributes contain file and stream attributes. 69 * The function is valid only after INITIALIZED state. 70 * 71 * @param mediaInfo Indicates the pointer to the user meta attributes 72 * @return Execution status return 73 * @retval OK: Plugin GetUserMeta succeeded. 74 */ 75 virtual Status GetUserMeta(std::shared_ptr<Meta> meta) = 0; 76 77 /** 78 * @brief Select a specified media track. 79 * 80 * The function is valid only after RUNNING state. 81 * 82 * @param trackId Identifies the media track. If an invalid value is passed, the default media track specified. 83 * @return Execution Status return 84 * @retval OK: Plugin SelectTrack succeeded. 85 */ 86 virtual Status SelectTrack(uint32_t trackId) = 0; 87 88 /** 89 * @brief Unselect a specified media track from which the demuxer reads data frames. 90 * 91 * The function is valid only after RUNNING state. 92 * 93 * @param trackId Identifies the media track. ignore the invalid value is passed. 94 * @return Execution Status return 95 * @retval OK: Plugin UnselectTrack succeeded. 96 */ 97 virtual Status UnselectTrack(uint32_t trackId) = 0; 98 99 /** 100 * @brief Reads data frames. 101 * 102 * The function is valid only after RUNNING state. 103 * 104 * @param trackId Identifies the media track. ignore the invalid value is passed. 105 * @param sample Buffer where store data frames. 106 * @return Execution Status return 107 * @retval OK: Plugin ReadFrame succeeded. 108 * @retval ERROR_TIMED_OUT: Operation timeout. 109 */ 110 virtual Status ReadSample(uint32_t trackId, std::shared_ptr<AVBuffer> sample) = 0; 111 112 /** 113 * @brief Get next sample size. 114 * 115 * The function is valid only after RUNNING state. 116 * 117 * @param trackId Identifies the media track. ignore the invalid value is passed. 118 * @return Execution Status 119 */ 120 virtual Status GetNextSampleSize(uint32_t trackId, int32_t& size) = 0; 121 122 /** 123 * @brief Seeks for a specified position for the demuxer. 124 * 125 * After being started, the demuxer seeks for a specified position to read data frames. 126 * 127 * The function is valid only after RUNNING state. 128 * 129 * @param trackId Identifies the stream in the media file. 130 * @param seekTime Indicates the target position, based on {@link HST_TIME_BASE} . 131 * @param mode Indicates the seek mode. 132 * @param realSeekTime Indicates the accurate target position, based on {@link HST_TIME_BASE} . 133 * @return Execution Status return 134 * @retval OK: Plugin SeekTo succeeded. 135 * @retval ERROR_INVALID_DATA: The input data is invalid. 136 */ 137 virtual Status SeekTo(int32_t trackId, int64_t seekTime, SeekMode mode, int64_t& realSeekTime) = 0; 138 139 virtual Status Reset() = 0; 140 141 virtual Status Start() = 0; 142 143 virtual Status Stop() = 0; 144 145 virtual Status Flush() = 0; 146 147 virtual void ResetEosStatus() = 0; 148 IsRefParserSupportedDemuxerPlugin149 virtual bool IsRefParserSupported() { return false; }; 150 virtual Status ParserRefUpdatePos(int64_t timeStampMs, bool isForward = true) = 0; 151 virtual Status ParserRefInfo() = 0; 152 virtual Status GetFrameLayerInfo(std::shared_ptr<AVBuffer> videoSample, FrameLayerInfo &frameLayerInfo) = 0; 153 virtual Status GetFrameLayerInfo(uint32_t frameId, FrameLayerInfo &frameLayerInfo) = 0; 154 virtual Status GetGopLayerInfo(uint32_t gopId, GopLayerInfo &gopLayerInfo) = 0; 155 virtual Status GetIFramePos(std::vector<uint32_t> &IFramePos) = 0; 156 virtual Status Dts2FrameId(int64_t dts, uint32_t &frameId, bool offset = true) = 0; 157 GetDrmInfoDemuxerPlugin158 virtual Status GetDrmInfo(std::multimap<std::string, std::vector<uint8_t>>& drmInfo) 159 { 160 (void)drmInfo; 161 return Status::OK; 162 } 163 164 virtual Status GetIndexByRelativePresentationTimeUs(const uint32_t trackIndex, 165 const uint64_t relativePresentationTimeUs, uint32_t &index) = 0; 166 167 virtual Status GetRelativePresentationTimeUsByIndex(const uint32_t trackIndex, 168 const uint32_t index, uint64_t &relativePresentationTimeUs) = 0; 169 170 virtual void SetCacheLimit(uint32_t limitSize) = 0; 171 }; 172 173 /// Demuxer plugin api major number. 174 #define DEMUXER_API_VERSION_MAJOR (1) 175 176 /// Demuxer plugin api minor number 177 #define DEMUXER_API_VERSION_MINOR (0) 178 179 /// Demuxer plugin version 180 #define DEMUXER_API_VERSION MAKE_VERSION(DEMUXER_API_VERSION_MAJOR, DEMUXER_API_VERSION_MINOR) 181 182 /** 183 * @brief Describes the demuxer plugin information. 184 * 185 * @since 1.0 186 * @version 1.0 187 */ 188 struct DemuxerPluginDef : public PluginDefBase { DemuxerPluginDefDemuxerPluginDef189 DemuxerPluginDef() 190 : PluginDefBase() 191 { 192 apiVersion = DEMUXER_API_VERSION; ///< Demuxer plugin version. 193 pluginType = PluginType::DEMUXER; ///< Plugin type, MUST be DEMUXER. 194 } 195 }; 196 } // namespace Plugins 197 } // namespace Media 198 } // namespace OHOS 199 #endif // AVCODEC_DEMUXER_PLUGIN_H 200