• 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 IAVMETADATAHELPER_SERVICE_H
17 #define IAVMETADATAHELPER_SERVICE_H
18 
19 #include "avmetadatahelper.h"
20 #include "avsharedmemory.h"
21 
22 namespace OHOS {
23 namespace Media {
24 struct OutputFrame {
25 public:
OutputFrameOutputFrame26     OutputFrame(int32_t width, int32_t height, int32_t stride, int32_t bytesPerPixel)
27         : width_(width),
28           height_(height),
29           stride_(stride),
30           bytesPerPixel_(bytesPerPixel),
31           size_(stride_ * height) // interleaved layout
32     {
33     }
34 
GetFlattenedSizeOutputFrame35     int32_t GetFlattenedSize() const
36     {
37         return sizeof(OutputFrame) + size_;
38     }
39 
GetFlattenedDataOutputFrame40     uint8_t *GetFlattenedData() const
41     {
42         return const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(this)) + sizeof(OutputFrame);
43     }
44 
45     int32_t width_;
46     int32_t height_;
47     int32_t stride_; // interleaved layout
48     int32_t bytesPerPixel_;
49     int32_t size_;
50 };
51 
52 struct OutputConfiguration {
53     int32_t dstWidth = -1;
54     int32_t dstHeight = -1;
55     PixelFormat colorFormat = PixelFormat::RGB_565;
56 };
57 
58 class IAVMetadataHelperService {
59 public:
60     virtual ~IAVMetadataHelperService() = default;
61 
62     /**
63      * Set the media source uri to use. Calling this method before the reset
64      * of the methods in this class. This method maybe time consuming.
65      * @param uri the URI of input media source.
66      * @param usage indicates which scene the avmedatahelper's instance will
67      * be used to, see {@link AVMetadataUsage}. If the usage need to be changed,
68      * this method must be called again.
69      * @return Returns {@link MSERR_OK} if the setting is successful; returns
70      * an error code otherwise.
71      */
72     virtual int32_t SetSource(const std::string &uri, int32_t usage) = 0;
73 
74     /**
75      * @brief Sets the media file descriptor source to resolve. Calling this method
76      * before the reset of the methods in this class. This method maybe time consuming.
77      * @param fd Indicates the file descriptor of media source.
78      * @param offset Indicates the offset of media source in file descriptor.
79      * @param size Indicates the size of media source.
80      * @param usage Indicates which scene the avmedatahelper's instance will
81      * be used to, see {@link AVMetadataUsage}. If the usage need to be changed,
82      * this method must be called again.
83      * @return Returns {@link MSERR_OK} if the setting is successful; returns
84      * an error code otherwise.
85      */
86     virtual int32_t SetSource(int32_t fd, int64_t offset, int64_t size, int32_t usage) = 0;
87 
88     /**
89      * Retrieve the meta data associated with the specified key. This method can be
90      * called after the SetSource.
91      * @param key One of the constants listed above at the definition of {@link AVMetadataCode}.
92      * @return Returns the meta data value associate with the given key code on
93      * success; empty string on failure.
94      */
95     virtual std::string ResolveMetadata(int32_t key) = 0;
96 
97     /**
98      * Fetch the album art picture associated with the data source. If there are
99      * more than one pictures, the cover image will be returned preferably.
100      * @return Returns the a chunk of shared memory containing a picture, which can be
101      * null, if such a picture can not be fetched.
102      */
103     virtual std::shared_ptr<AVSharedMemory> FetchArtPicture() = 0;
104 
105     /**
106      * Retrieve all meta data within the listed above at the definition of {@link AVMetadataCode}.
107      * This method must be called after the SetSource.
108      * @return Returns the meta data values on success; empty hash map on failure.
109      */
110     virtual std::unordered_map<int32_t, std::string> ResolveMetadata() = 0;
111 
112     /**
113      * Fetch a representative video frame near a given timestamp by considering the given
114      * option if possible, and return a video frame with given parameters. This method must be
115      * called after the SetSource.
116      * @param timeMs The time position in microseconds where the frame will be fetched.
117      * When fetching the frame at the given time position, there is no guarantee that
118      * the video source has a frame located at the position. When this happens, a frame
119      * nearby will be returned. If timeUs is negative, time position and option will ignored,
120      * and any frame that the implementation considers as representative may be returned.
121      * @param option the hint about how to fetch a frame, see {@link AVMetadataQueryOption}
122      * @param param the desired configuration of returned video frame, see {@link OutputConfiguration}.
123      * @return Returns a chunk of shared memory containing a scaled video frame, which
124      * can be null, if such a frame cannot be fetched.
125      */
126     virtual std::shared_ptr<AVSharedMemory> FetchFrameAtTime(
127         int64_t timeUs, int32_t option, const OutputConfiguration &param) = 0;
128 
129     /**
130      * Release the internel resource. After this method called, the service instance
131      * can not be used again.
132      */
133     virtual void Release() = 0;
134 };
135 } // namespace Media
136 } // namespace OHOS
137 
138 #endif