• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 I_AVMETADATAHELPER_ENGINE_H
17 #define I_AVMETADATAHELPER_ENGINE_H
18 
19 #include "avmetadatahelper.h"
20 #include "i_avmetadatahelper_service.h"
21 
22 namespace OHOS {
23 namespace Media {
24 class IAVMetadataHelperEngine {
25 public:
26     virtual ~IAVMetadataHelperEngine() = default;
27 
28     /**
29      * Set the media source uri to use. Calling this method before the reset
30      * of the methods in this class. This method maybe time consuming.
31      * @param uri the URI of input media source.
32      * @param usage indicates which scene the avmedatahelper's instance will
33      * be used to, see {@link AVMetadataUsage}. If the usage need to be changed,
34      * this method must be called again.
35      * @return Returns {@link MSERR_OK} if the setting is successful; returns
36      * an error code otherwise.
37      */
38     virtual int32_t SetSource(const std::string &uri, int32_t usage) = 0;
39     virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0;
40     /**
41      * Set the caller. Calling this method before the reset
42      * of the methods in this class. This method maybe time consuming.
43      * @param caller indicates which scene the avmedatahelper's instance will
44      * be used to, see {@link AVMetadataCaller}. If the caller need to be changed,
45      * this method must be called again.
46      * @return Returns {@link MSERR_OK} if the setting is successful; returns
47      * an error code otherwise.
48      */
SetAVMetadataCaller(AVMetadataCaller caller)49     virtual int32_t SetAVMetadataCaller(AVMetadataCaller caller)
50     {
51         (void)caller;
52         return 0;
53     }
54     /**
55      * Set the media source online uri with header params to resolve. Calling this method before the reset
56      * of the methods in this class. This method maybe time consuming.
57      * @param uri the URI of input http/https on demand media source.
58      * @param header the request parameters of input media source.
59      * @return Returns {@link MSERR_OK} if the setting is successful; returns
60      * an error code otherwise.
61      */
SetUrlSource(const std::string & uri,const std::map<std::string,std::string> & header)62     virtual int32_t SetUrlSource(const std::string &uri, const std::map<std::string, std::string> &header)
63     {
64         (void)uri;
65         (void)header;
66         return 0;
67     }
68 
69     /**
70      * Retrieve the meta data associated with the specified key. This method must be
71      * called after the SetSource.
72      * @param key One of the constants listed above at the definition of {@link AVMetadataCode}.
73      * @return Returns the meta data value associate with the given key code on
74      * success; empty string on failure.
75      */
76     virtual std::string ResolveMetadata(int32_t key) = 0;
77 
78     /**
79      * Retrieve all meta data within the listed above at the definition of {@link AVMetadataCode}.
80      * This method must be called after the SetSource.
81      * @return Returns the meta data values on success; empty string on failure.
82      */
83     virtual std::unordered_map<int32_t, std::string> ResolveMetadata() = 0;
84 
85     /**
86      * This method must be called after the SetSource.
87      *@return Returns metadata on success; nullptr on failure
88     */
89     virtual std::shared_ptr<Meta> GetAVMetadata() = 0;
90 
91     /**
92      * Fetch the album art picture associated with the data source. If there are
93      * more than one pictures, the cover image will be returned preferably.
94      * @return Returns the a chunk of shared memory containing a picture, which can be
95      * null, if such a picture can not be fetched.
96      */
97     virtual std::shared_ptr<AVSharedMemory> FetchArtPicture() = 0;
98 
99     /**
100      * Fetch a representative video frame near a given timestamp by considering the given
101      * option if possible, and return a video frame with given parameters. This method must be
102      * called after the SetSource.
103      * @param timeMs The time position in microseconds where the frame will be fetched.
104      * When fetching the frame at the given time position, there is no guarantee that
105      * the video source has a frame located at the position. When this happens, a frame
106      * nearby will be returned. If timeUs is negative, time position and option will ignored,
107      * and any frame that the implementation considers as representative may be returned.
108      * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption}
109      * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}.
110      * @return Returns a chunk of shared memory containing a scaled video frame, which
111      * can be null, if such a frame cannot be fetched.
112      */
113     virtual std::shared_ptr<AVSharedMemory> FetchFrameAtTime(
114         int64_t timeUs, int32_t option, const OutputConfiguration &param) = 0;
115 
116     /**
117      * Get timestamp according to frame index.
118      * @param timeUs : Index of the frame.
119      * @returns returns time
120      */
121     virtual int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) = 0;
122 
123     /**
124      * Get frame index according to the given timestamp.
125      * @param timeUs : Timestamp of the frame, in microseconds.
126      * @returns Returns frame
127      */
128     virtual int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) = 0;
129 
130     /**
131      * Fetch a representative video frame near a given timestamp by considering the given
132      * option if possible, and return a video frame with given parameters. This method must be
133      * called after the SetSource.
134      * @param timeMs The time position in microseconds where the frame will be fetched.
135      * When fetching the frame at the given time position, there is no guarantee that
136      * the video source has a frame located at the position. When this happens, a frame
137      * nearby will be returned. If timeUs is negative, time position and option will ignored,
138      * and any frame that the implementation considers as representative may be returned.
139      * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption}
140      * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}.
141      * @return Returns a chunk of shared memory containing a scaled video frame, which
142      * can be null, if such a frame cannot be fetched.
143      */
144     virtual std::shared_ptr<AVBuffer> FetchFrameYuv(
145         int64_t timeUs, int32_t option, const OutputConfiguration &param) = 0;
146 
147     /**
148      * Set interrupt state to demuxer and source
149      * @param isInterruptNeeded : If should interrupt demuxer and source
150      */
SetInterruptState(bool isInterruptNeeded)151     virtual void SetInterruptState(bool isInterruptNeeded) {}
152 };
153 } // namespace Media
154 } // namespace OHOS
155 
156 #endif