• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 namespace OHOS {
28 namespace Media {
29 namespace Plugins {
30 /**
31  * @brief Demuxer Plugin Interface.
32  *
33  * Used for audio and video media file parse.
34  *
35  * @since 1.0
36  * @version 1.0
37  */
38 struct DemuxerPlugin : public PluginBase {
39     /// constructor
DemuxerPluginDemuxerPlugin40     explicit DemuxerPlugin(std::string name): PluginBase(std::move(name)) {}
41     /**
42      * @brief Set the data source to demuxer component.
43      *
44      * The function is valid only in the CREATED state.
45      *
46      * @param source Data source where data read from.
47      * @return  Execution Status return
48      *  @retval OK: Plugin SetDataSource succeeded.
49      */
50     virtual Status SetDataSource(const std::shared_ptr<DataSource>& source) = 0;
51 
52     /**
53      * @brief Get the attributes of a media file.
54      *
55      * The attributes contain file and stream attributes.
56      * The function is valid only after INITIALIZED state.
57      *
58      * @param mediaInfo Indicates the pointer to the source attributes
59      * @return  Execution status return
60      *  @retval OK: Plugin GetMediaInfo succeeded.
61      */
62     virtual Status GetMediaInfo(MediaInfo& mediaInfo) = 0;
63 
64     /**
65      * @brief Select a specified media track.
66      *
67      * The function is valid only after RUNNING state.
68      *
69      * @param trackId Identifies the media track. If an invalid value is passed, the default media track specified.
70      * @return  Execution Status return
71      *  @retval OK: Plugin SelectTrack succeeded.
72      */
73     virtual Status SelectTrack(uint32_t trackId) = 0;
74 
75     /**
76      * @brief Unselect a specified media track from which the demuxer reads data frames.
77      *
78      * The function is valid only after RUNNING state.
79      *
80      * @param trackId Identifies the media track. ignore the invalid value is passed.
81      * @return  Execution Status return
82      *  @retval OK: Plugin UnselectTrack succeeded.
83      */
84     virtual Status UnselectTrack(uint32_t trackId) = 0;
85 
86     /**
87      * @brief Reads data frames.
88      *
89      * The function is valid only after RUNNING state.
90      *
91      * @param trackId Identifies the media track. ignore the invalid value is passed.
92      * @param sample Buffer where store data frames.
93      * @return  Execution Status return
94      *  @retval OK: Plugin ReadFrame succeeded.
95      *  @retval ERROR_TIMED_OUT: Operation timeout.
96      */
97     virtual Status ReadSample(uint32_t trackId, std::shared_ptr<AVBuffer> sample) = 0;
98 
99     /**
100      * @brief Get next sample size.
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      * @return  size
106      */
107     virtual int32_t GetNextSampleSize(uint32_t trackId) = 0;
108 
109     /**
110      * @brief Seeks for a specified position for the demuxer.
111      *
112      * After being started, the demuxer seeks for a specified position to read data frames.
113      *
114      * The function is valid only after RUNNING state.
115      *
116      * @param trackId Identifies the stream in the media file.
117      * @param seekTime Indicates the target position, based on {@link HST_TIME_BASE} .
118      * @param mode Indicates the seek mode.
119      * @param realSeekTime Indicates the accurate target position, based on {@link HST_TIME_BASE} .
120      * @return  Execution Status return
121      *  @retval OK: Plugin SeekTo succeeded.
122      *  @retval ERROR_INVALID_DATA: The input data is invalid.
123      */
124     virtual Status SeekTo(int32_t trackId, int64_t seekTime, SeekMode mode, int64_t& realSeekTime) = 0;
125 
126     virtual Status Reset() = 0;
127 
128     virtual Status Start() = 0;
129 
130     virtual Status Stop() = 0;
131 
132     virtual Status Flush() = 0;
133 
GetDrmInfoDemuxerPlugin134     virtual Status GetDrmInfo(std::multimap<std::string, std::vector<uint8_t>>& drmInfo)
135     {
136         (void)drmInfo;
137         return Status::OK;
138     }
139 };
140 
141 /// Demuxer plugin api major number.
142 #define DEMUXER_API_VERSION_MAJOR (1)
143 
144 /// Demuxer plugin api minor number
145 #define DEMUXER_API_VERSION_MINOR (0)
146 
147 /// Demuxer plugin version
148 #define DEMUXER_API_VERSION MAKE_VERSION(DEMUXER_API_VERSION_MAJOR, DEMUXER_API_VERSION_MINOR)
149 
150 /**
151  * @brief Describes the demuxer plugin information.
152  *
153  * @since 1.0
154  * @version 1.0
155  */
156 struct DemuxerPluginDef : public PluginDefBase {
DemuxerPluginDefDemuxerPluginDef157     DemuxerPluginDef()
158         : PluginDefBase()
159     {
160         apiVersion = DEMUXER_API_VERSION; ///< Demuxer plugin version.
161         pluginType = PluginType::DEMUXER; ///< Plugin type, MUST be DEMUXER.
162     }
163 };
164 } // namespace Plugins
165 } // namespace Media
166 } // namespace OHOS
167 #endif // AVCODEC_DEMUXER_PLUGIN_H
168