• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "common/plugin_caps.h"
22 #include "plugin_base.h"
23 #include "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     TagMap general;             ///< General information
42     std::vector<TagMap> 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 reset 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 reset succeeded.
74      */
75     virtual Status GetSize(size_t& size) = 0;
76 };
77 
78 /**
79  * @brief Demuxer Plugin Interface.
80  *
81  * Used for audio and video media file parse.
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 struct DemuxerPlugin : public PluginBase {
87     /// constructor
DemuxerPluginDemuxerPlugin88     explicit DemuxerPlugin(std::string name): PluginBase(std::move(name)) {}
89     /**
90      * @brief Set the data source to demuxer component.
91      *
92      * The function is valid only in the CREATED state.
93      *
94      * @param source Data source where data read from.
95      * @return  Execution status return
96      *  @retval OK: Plugin reset succeeded.
97      */
98     virtual Status SetDataSource(const std::shared_ptr<DataSource>& source) = 0;
99 
100     /**
101      * @brief Get the attributes of a media file.
102      *
103      * The attributes contain file and stream attributes.
104      * The function is valid only after INITIALIZED state.
105      *
106      * @param mediaInfo Indicates the pointer to the source attributes
107      * @return  Execution status return
108      *  @retval OK: Plugin reset succeeded.
109      */
110     virtual Status GetMediaInfo(MediaInfo& mediaInfo) = 0;
111 
112     /**
113      * @brief Get the stack count from the data source.
114      *
115      * The function is valid only after INITIALIZED state.
116      *
117      * @return number of tracks.
118      */
119     virtual size_t GetTrackCount() = 0;
120 
121     /**
122      * @brief Select a specified media track.
123      *
124      * The function is valid only after RUNNING state.
125      *
126      * @param trackId Identifies the media track. If an invalid value is passed, the default media track specified.
127      * @return  Execution status return
128      *  @retval OK: Plugin reset succeeded.
129      */
130     virtual Status SelectTrack(int32_t trackId) = 0;
131 
132     /**
133      * @brief Unselect a specified media track from which the demuxer reads data frames.
134      *
135      * The function is valid only after RUNNING state.
136      *
137      * @param trackId Identifies the media track. ignore the invalid value is passed.
138      * @return  Execution status return
139      *  @retval OK: Plugin reset succeeded.
140      */
141     virtual Status UnselectTrack(int32_t trackId) = 0;
142 
143     /**
144      * @brief Get the ID of the media track selected by the demuxer for output.
145      *
146      * The function is valid only after RUNNING state.
147      *
148      * @param trackIds Identifies the array of selected media tracks.
149      * @return  Execution status return
150      *  @retval OK: Plugin reset succeeded.
151      */
152     virtual Status GetSelectedTracks(std::vector<int32_t>& trackIds) = 0;
153 
154     /**
155      * @brief Reads data frames.
156      *
157      * The function is valid only after RUNNING state.
158      *
159      * @param buffer Indicates the pointer to the data buffer.
160      * @param timeOutMs Indicates the time required for waiting data frame read.
161      * @return  Execution status return
162      *  @retval OK: Plugin reset succeeded.
163      *  @retval ERROR_TIMED_OUT: Operation timeout.
164      */
165     virtual Status ReadFrame(Buffer& buffer, int32_t timeOutMs) = 0;
166 
167     /**
168      * @brief Seeks for a specified position for the demuxer.
169      *
170      * After being started, the demuxer seeks for a specified position to read data frames.
171      *
172      * The function is valid only after RUNNING state.
173      *
174      * @param trackId Identifies the stream in the media file.
175      * @param hstTime Indicates the target position, based on {@link HST_TIME_BASE} .
176      * @param mode Indicates the seek mode.
177      * @return  Execution status return
178      *  @retval OK: Plugin reset succeeded.
179      *  @retval ERROR_INVALID_DATA: The input data is invalid.
180      */
181     virtual Status SeekTo(int32_t trackId, int64_t hstTime, SeekMode mode) = 0;
182 };
183 
184 /// Demuxer plugin api major number.
185 #define DEMUXER_API_VERSION_MAJOR (1)
186 
187 /// Demuxer plugin api minor number
188 #define DEMUXER_API_VERSION_MINOR (0)
189 
190 /// Demuxer plugin version
191 #define DEMUXER_API_VERSION MAKE_VERSION(DEMUXER_API_VERSION_MAJOR, DEMUXER_API_VERSION_MINOR)
192 
193 /// Demuxer sniff function
194 using DemuxerPluginSnifferFunc = int (*)(const std::string& name, std::shared_ptr<DataSource> dataSource);
195 
196 /**
197  * @brief Describes the demuxer plugin information.
198  *
199  * @since 1.0
200  * @version 1.0
201  */
202 struct DemuxerPluginDef : public PluginDefBase {
203     std::vector<std::string> extensions;      ///< File extensions supported by demuxer
204     CapabilitySet inCaps;                     ///< Plug-in input capability, For details, @see Capability.
205     CapabilitySet outCaps;                    ///< Plug-in output capability, For details, @see Capability.
206     PluginCreatorFunc<DemuxerPlugin> creator {nullptr}; ///< Demuxer plugin create function.
207     DemuxerPluginSnifferFunc sniffer {nullptr};         ///< Demuxer plugin sniff function.
DemuxerPluginDefDemuxerPluginDef208     DemuxerPluginDef()
209     {
210         apiVersion = DEMUXER_API_VERSION; ///< Demuxer plugin version.
211         pluginType = PluginType::DEMUXER; ///< Plugin type, MUST be DEMUXER.
212     }
213 };
214 } // namespace Plugin
215 } // namespace Media
216 } // namespace OHOS
217 #endif // HISTREAMER_PLUGIN_INTF_DEMUXER_PLUGIN_H
218