1049e185fSopenharmony_ci/* 2049e185fSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 3049e185fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4049e185fSopenharmony_ci * you may not use this file except in compliance with the License. 5049e185fSopenharmony_ci * You may obtain a copy of the License at 6049e185fSopenharmony_ci * 7049e185fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8049e185fSopenharmony_ci * 9049e185fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10049e185fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11049e185fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12049e185fSopenharmony_ci * See the License for the specific language governing permissions and 13049e185fSopenharmony_ci * limitations under the License. 14049e185fSopenharmony_ci */ 15049e185fSopenharmony_ci 16049e185fSopenharmony_ci#ifndef IAVMETADATAHELPER_SERVICE_H 17049e185fSopenharmony_ci#define IAVMETADATAHELPER_SERVICE_H 18049e185fSopenharmony_ci 19049e185fSopenharmony_ci#include "avmetadatahelper.h" 20049e185fSopenharmony_ci#include "buffer/avsharedmemory.h" 21049e185fSopenharmony_ci#include "meta/meta.h" 22049e185fSopenharmony_ci 23049e185fSopenharmony_cinamespace OHOS { 24049e185fSopenharmony_cinamespace Media { 25049e185fSopenharmony_cistruct OutputFrame { 26049e185fSopenharmony_cipublic: 27049e185fSopenharmony_ci OutputFrame(int32_t width, int32_t height, int32_t stride, int32_t bytesPerPixel) 28049e185fSopenharmony_ci : width_(width), 29049e185fSopenharmony_ci height_(height), 30049e185fSopenharmony_ci stride_(stride), 31049e185fSopenharmony_ci bytesPerPixel_(bytesPerPixel), 32049e185fSopenharmony_ci size_(stride_ * height), // interleaved layout 33049e185fSopenharmony_ci rotation_(0) 34049e185fSopenharmony_ci { 35049e185fSopenharmony_ci } 36049e185fSopenharmony_ci 37049e185fSopenharmony_ci int32_t GetFlattenedSize() const 38049e185fSopenharmony_ci { 39049e185fSopenharmony_ci return sizeof(OutputFrame) + size_; 40049e185fSopenharmony_ci } 41049e185fSopenharmony_ci 42049e185fSopenharmony_ci uint8_t *GetFlattenedData() const 43049e185fSopenharmony_ci { 44049e185fSopenharmony_ci return const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(this)) + sizeof(OutputFrame); 45049e185fSopenharmony_ci } 46049e185fSopenharmony_ci 47049e185fSopenharmony_ci int32_t width_; 48049e185fSopenharmony_ci int32_t height_; 49049e185fSopenharmony_ci int32_t stride_; // interleaved layout 50049e185fSopenharmony_ci int32_t bytesPerPixel_; 51049e185fSopenharmony_ci int32_t size_; 52049e185fSopenharmony_ci int32_t rotation_; 53049e185fSopenharmony_ci}; 54049e185fSopenharmony_ci 55049e185fSopenharmony_cistruct OutputConfiguration { 56049e185fSopenharmony_ci int32_t dstWidth = -1; 57049e185fSopenharmony_ci int32_t dstHeight = -1; 58049e185fSopenharmony_ci PixelFormat colorFormat = PixelFormat::RGB_565; 59049e185fSopenharmony_ci 60049e185fSopenharmony_ci bool operator==(const OutputConfiguration &other) const 61049e185fSopenharmony_ci { 62049e185fSopenharmony_ci return dstWidth == other.dstWidth && dstHeight == other.dstHeight && colorFormat == other.colorFormat; 63049e185fSopenharmony_ci } 64049e185fSopenharmony_ci}; 65049e185fSopenharmony_ci 66049e185fSopenharmony_ciclass IAVMetadataHelperService { 67049e185fSopenharmony_cipublic: 68049e185fSopenharmony_ci virtual ~IAVMetadataHelperService() = default; 69049e185fSopenharmony_ci 70049e185fSopenharmony_ci /** 71049e185fSopenharmony_ci * @brief Method to set helper callback. 72049e185fSopenharmony_ci * 73049e185fSopenharmony_ci * @param callback object pointer. 74049e185fSopenharmony_ci * @return Returns {@link MSERR_OK} if the helpercallback is set; returns an error code defined 75049e185fSopenharmony_ci * in {@link media_errors.h} otherwise. 76049e185fSopenharmony_ci */ 77049e185fSopenharmony_ci virtual int32_t SetHelperCallback(const std::shared_ptr<HelperCallback> &callback) = 0; 78049e185fSopenharmony_ci 79049e185fSopenharmony_ci /** 80049e185fSopenharmony_ci * Set the media source uri to use. Calling this method before the reset 81049e185fSopenharmony_ci * of the methods in this class. This method maybe time consuming. 82049e185fSopenharmony_ci * @param uri the URI of input media source. 83049e185fSopenharmony_ci * @param usage indicates which scene the avmedatahelper's instance will 84049e185fSopenharmony_ci * be used to, see {@link AVMetadataUsage}. If the usage need to be changed, 85049e185fSopenharmony_ci * this method must be called again. 86049e185fSopenharmony_ci * @return Returns {@link MSERR_OK} if the setting is successful; returns 87049e185fSopenharmony_ci * an error code otherwise. 88049e185fSopenharmony_ci */ 89049e185fSopenharmony_ci virtual int32_t SetSource(const std::string &uri, int32_t usage) = 0; 90049e185fSopenharmony_ci 91049e185fSopenharmony_ci /** 92049e185fSopenharmony_ci * @brief Sets the media file descriptor source to resolve. Calling this method 93049e185fSopenharmony_ci * before the reset of the methods in this class. This method maybe time consuming. 94049e185fSopenharmony_ci * @param fd Indicates the file descriptor of media source. 95049e185fSopenharmony_ci * @param offset Indicates the offset of media source in file descriptor. 96049e185fSopenharmony_ci * @param size Indicates the size of media source. 97049e185fSopenharmony_ci * @param usage Indicates which scene the avmedatahelper's instance will 98049e185fSopenharmony_ci * be used to, see {@link AVMetadataUsage}. If the usage need to be changed, 99049e185fSopenharmony_ci * this method must be called again. 100049e185fSopenharmony_ci * @return Returns {@link MSERR_OK} if the setting is successful; returns 101049e185fSopenharmony_ci * an error code otherwise. 102049e185fSopenharmony_ci */ 103049e185fSopenharmony_ci virtual int32_t SetSource(int32_t fd, int64_t offset, int64_t size, int32_t usage) = 0; 104049e185fSopenharmony_ci 105049e185fSopenharmony_ci /** 106049e185fSopenharmony_ci * Sets the media data source to resolve. 107049e185fSopenharmony_ci * @param dataSrc A data source instance with the fileSize and a callback {@link IMediaDataSource}. 108049e185fSopenharmony_ci * @return Returns the status code. 109049e185fSopenharmony_ci */ 110049e185fSopenharmony_ci virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0; 111049e185fSopenharmony_ci 112049e185fSopenharmony_ci /** 113049e185fSopenharmony_ci * Retrieve the meta data associated with the specified key. This method can be 114049e185fSopenharmony_ci * called after the SetSource. 115049e185fSopenharmony_ci * @param key One of the constants listed above at the definition of {@link AVMetadataCode}. 116049e185fSopenharmony_ci * @return Returns the meta data value associate with the given key code on 117049e185fSopenharmony_ci * success; empty string on failure. 118049e185fSopenharmony_ci */ 119049e185fSopenharmony_ci virtual std::string ResolveMetadata(int32_t key) = 0; 120049e185fSopenharmony_ci 121049e185fSopenharmony_ci /** 122049e185fSopenharmony_ci * Fetch the album art picture associated with the data source. If there are 123049e185fSopenharmony_ci * more than one pictures, the cover image will be returned preferably. 124049e185fSopenharmony_ci * @return Returns the a chunk of shared memory containing a picture, which can be 125049e185fSopenharmony_ci * null, if such a picture can not be fetched. 126049e185fSopenharmony_ci */ 127049e185fSopenharmony_ci virtual std::shared_ptr<AVSharedMemory> FetchArtPicture() = 0; 128049e185fSopenharmony_ci 129049e185fSopenharmony_ci /** 130049e185fSopenharmony_ci * Retrieve all meta data within the listed above at the definition of {@link AVMetadataCode}. 131049e185fSopenharmony_ci * This method must be called after the SetSource. 132049e185fSopenharmony_ci * @return Returns the meta data values on success; empty hash map on failure. 133049e185fSopenharmony_ci */ 134049e185fSopenharmony_ci virtual std::unordered_map<int32_t, std::string> ResolveMetadata() = 0; 135049e185fSopenharmony_ci 136049e185fSopenharmony_ci /** 137049e185fSopenharmony_ci * get all avmetadata. 138049e185fSopenharmony_ci * This method must be called after the SetSource. 139049e185fSopenharmony_ci * @return Returns the meta data values on success; nullptr on failure. 140049e185fSopenharmony_ci */ 141049e185fSopenharmony_ci virtual std::shared_ptr<Meta> GetAVMetadata() = 0; 142049e185fSopenharmony_ci 143049e185fSopenharmony_ci /** 144049e185fSopenharmony_ci * Fetch a representative video frame near a given timestamp by considering the given 145049e185fSopenharmony_ci * option if possible, and return a video frame with given parameters. This method must be 146049e185fSopenharmony_ci * called after the SetSource. 147049e185fSopenharmony_ci * @param timeMs The time position in microseconds where the frame will be fetched. 148049e185fSopenharmony_ci * When fetching the frame at the given time position, there is no guarantee that 149049e185fSopenharmony_ci * the video source has a frame located at the position. When this happens, a frame 150049e185fSopenharmony_ci * nearby will be returned. If timeUs is negative, time position and option will ignored, 151049e185fSopenharmony_ci * and any frame that the implementation considers as representative may be returned. 152049e185fSopenharmony_ci * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption} 153049e185fSopenharmony_ci * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}. 154049e185fSopenharmony_ci * @return Returns a chunk of shared memory containing a scaled video frame, which 155049e185fSopenharmony_ci * can be null, if such a frame cannot be fetched. 156049e185fSopenharmony_ci */ 157049e185fSopenharmony_ci virtual std::shared_ptr<AVSharedMemory> FetchFrameAtTime( 158049e185fSopenharmony_ci int64_t timeUs, int32_t option, const OutputConfiguration ¶m) = 0; 159049e185fSopenharmony_ci 160049e185fSopenharmony_ci /** 161049e185fSopenharmony_ci * Fetch a representative video frame near a given timestamp by considering the given 162049e185fSopenharmony_ci * option if possible, and return a video frame with given parameters. This method must be 163049e185fSopenharmony_ci * called after the SetSource. 164049e185fSopenharmony_ci * @param timeMs The time position in microseconds where the frame will be fetched. 165049e185fSopenharmony_ci * When fetching the frame at the given time position, there is no guarantee that 166049e185fSopenharmony_ci * the video source has a frame located at the position. When this happens, a frame 167049e185fSopenharmony_ci * nearby will be returned. If timeUs is negative, time position and option will ignored, 168049e185fSopenharmony_ci * and any frame that the implementation considers as representative may be returned. 169049e185fSopenharmony_ci * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption} 170049e185fSopenharmony_ci * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}. 171049e185fSopenharmony_ci * @return Returns a chunk of shared memory containing a scaled video frame, which 172049e185fSopenharmony_ci * can be null, if such a frame cannot be fetched. 173049e185fSopenharmony_ci */ 174049e185fSopenharmony_ci virtual std::shared_ptr<AVBuffer> FetchFrameYuv( 175049e185fSopenharmony_ci int64_t timeUs, int32_t option, const OutputConfiguration ¶m) = 0; 176049e185fSopenharmony_ci 177049e185fSopenharmony_ci /** 178049e185fSopenharmony_ci * Release the internel resource. After this method called, the service instance 179049e185fSopenharmony_ci * can not be used again. 180049e185fSopenharmony_ci */ 181049e185fSopenharmony_ci virtual void Release() = 0; 182049e185fSopenharmony_ci 183049e185fSopenharmony_ci /** 184049e185fSopenharmony_ci * Get timestamp according to frame index. 185049e185fSopenharmony_ci * @param timeUs : Index of the frame. 186049e185fSopenharmony_ci * @returns returns time 187049e185fSopenharmony_ci */ 188049e185fSopenharmony_ci virtual int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) = 0; 189049e185fSopenharmony_ci 190049e185fSopenharmony_ci /** 191049e185fSopenharmony_ci * Get frame index according to the given timestamp. 192049e185fSopenharmony_ci * @param timeUs : Timestamp of the frame, in microseconds. 193049e185fSopenharmony_ci * @returns Returns frame 194049e185fSopenharmony_ci */ 195049e185fSopenharmony_ci virtual int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) = 0; 196049e185fSopenharmony_ci 197049e185fSopenharmony_ci /** 198049e185fSopenharmony_ci * Set is created from napi instance 199049e185fSopenharmony_ci * @param isNapiInstance : IsNapiInstance, bool 200049e185fSopenharmony_ci */ 201049e185fSopenharmony_ci virtual void SetIsNapiInstance(bool isNapiInstance) = 0; 202049e185fSopenharmony_ci}; 203049e185fSopenharmony_ci} // namespace Media 204049e185fSopenharmony_ci} // namespace OHOS 205049e185fSopenharmony_ci 206049e185fSopenharmony_ci#endif