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 /** 42 * Retrieve the meta data associated with the specified key. This method must be 43 * called after the SetSource. 44 * @param key One of the constants listed above at the definition of {@link AVMetadataCode}. 45 * @return Returns the meta data value associate with the given key code on 46 * success; empty string on failure. 47 */ 48 virtual std::string ResolveMetadata(int32_t key) = 0; 49 50 /** 51 * Retrieve all meta data within the listed above at the definition of {@link AVMetadataCode}. 52 * This method must be called after the SetSource. 53 * @return Returns the meta data values on success; empty string on failure. 54 */ 55 virtual std::unordered_map<int32_t, std::string> ResolveMetadata() = 0; 56 57 /** 58 * This method must be called after the SetSource. 59 *@return Returns metadata on success; nullptr on failure 60 */ 61 virtual std::shared_ptr<Meta> GetAVMetadata() = 0; 62 63 /** 64 * Fetch the album art picture associated with the data source. If there are 65 * more than one pictures, the cover image will be returned preferably. 66 * @return Returns the a chunk of shared memory containing a picture, which can be 67 * null, if such a picture can not be fetched. 68 */ 69 virtual std::shared_ptr<AVSharedMemory> FetchArtPicture() = 0; 70 71 /** 72 * Fetch a representative video frame near a given timestamp by considering the given 73 * option if possible, and return a video frame with given parameters. This method must be 74 * called after the SetSource. 75 * @param timeMs The time position in microseconds where the frame will be fetched. 76 * When fetching the frame at the given time position, there is no guarantee that 77 * the video source has a frame located at the position. When this happens, a frame 78 * nearby will be returned. If timeUs is negative, time position and option will ignored, 79 * and any frame that the implementation considers as representative may be returned. 80 * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption} 81 * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}. 82 * @return Returns a chunk of shared memory containing a scaled video frame, which 83 * can be null, if such a frame cannot be fetched. 84 */ 85 virtual std::shared_ptr<AVSharedMemory> FetchFrameAtTime( 86 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) = 0; 87 88 /** 89 * Get timestamp according to frame index. 90 * @param timeUs : Index of the frame. 91 * @returns returns time 92 */ 93 virtual int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) = 0; 94 95 /** 96 * Get frame index according to the given timestamp. 97 * @param timeUs : Timestamp of the frame, in microseconds. 98 * @returns Returns frame 99 */ 100 virtual int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) = 0; 101 102 /** 103 * Fetch a representative video frame near a given timestamp by considering the given 104 * option if possible, and return a video frame with given parameters. This method must be 105 * called after the SetSource. 106 * @param timeMs The time position in microseconds where the frame will be fetched. 107 * When fetching the frame at the given time position, there is no guarantee that 108 * the video source has a frame located at the position. When this happens, a frame 109 * nearby will be returned. If timeUs is negative, time position and option will ignored, 110 * and any frame that the implementation considers as representative may be returned. 111 * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption} 112 * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}. 113 * @return Returns a chunk of shared memory containing a scaled video frame, which 114 * can be null, if such a frame cannot be fetched. 115 */ 116 virtual std::shared_ptr<AVBuffer> FetchFrameYuv( 117 int64_t timeUs, int32_t option, const OutputConfiguration ¶m) = 0; 118 119 /** 120 * Set interrupt state to demuxer and source 121 * @param isInterruptNeeded : If should interrupt demuxer and source 122 */ SetInterruptState(bool isInterruptNeeded)123 virtual void SetInterruptState(bool isInterruptNeeded) {} 124 }; 125 } // namespace Media 126 } // namespace OHOS 127 128 #endif