• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_AVMETA_DATA_H
16 #define OHOS_AVMETA_DATA_H
17 
18 #include <bitset>
19 #include <memory>
20 #include <string>
21 #include <map>
22 
23 #include "iremote_proxy.h"
24 #include "parcel.h"
25 #include "avsession_pixel_map.h"
26 
27 #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) and !defined(IOS_PLATFORM)
28 #include <malloc.h>
29 #endif
30 
31 namespace OHOS::AVSession {
32 class AVMetaData : public Parcelable {
33 public:
34     static constexpr std::int64_t DURATION_ALWAYS_PLAY = -1;
35     enum {
36         META_KEY_ASSET_ID = 0,
37         META_KEY_TITLE = 1,
38         META_KEY_ARTIST = 2,
39         META_KEY_AUTHOR = 3,
40         META_KEY_AVQUEUE_NAME = 4,
41         META_KEY_AVQUEUE_ID = 5,
42         META_KEY_AVQUEUE_IMAGE = 6,
43         META_KEY_AVQUEUE_IMAGE_URI = 7,
44         META_KEY_ALBUM = 8,
45         META_KEY_WRITER = 9,
46         META_KEY_COMPOSER = 10,
47         META_KEY_DURATION = 11,
48         META_KEY_MEDIA_IMAGE = 12,
49         META_KEY_MEDIA_IMAGE_URI = 13,
50         META_KEY_PUBLISH_DATE = 14,
51         META_KEY_SUBTITLE = 15,
52         META_KEY_DESCRIPTION = 16,
53         META_KEY_LYRIC = 17,
54         META_KEY_PREVIOUS_ASSET_ID = 18,
55         META_KEY_NEXT_ASSET_ID = 19,
56         META_KEY_SKIP_INTERVALS = 20,
57         META_KEY_FILTER = 21,
58         META_KEY_DISPLAY_TAGS = 22,
59         META_KEY_DRM_SCHEMES = 23,
60         META_KEY_BUNDLE_ICON = 24,
61         META_KEY_SINGLE_LYRIC_TEXT = 25,
62         META_KEY_MAX = 26
63     };
64 
65     enum {
66         SECONDS_10 = 10,
67         SECONDS_15 = 15,
68         SECONDS_30 = 30
69     };
70 
71     enum {
72         DISPLAY_TAG_AUDIO_VIVID = 1,
73         // indicate all supported sound source for gold flag, you should make OR operation if add new options
74         DISPLAY_TAG_ALL = DISPLAY_TAG_AUDIO_VIVID
75     };
76 
77     using MetaMaskType = std::bitset<META_KEY_MAX>;
78 
79     AVMetaData() = default;
80     ~AVMetaData() = default;
81 
82     static AVMetaData* Unmarshalling(Parcel& in);
83     bool ReadFromParcel(MessageParcel& in, int32_t twoImageLength);
84     bool Marshalling(Parcel& parcel) const override;
85     bool WriteToParcel(MessageParcel& parcel) const;
86 
87     bool UnmarshallingExceptImg(MessageParcel& data);
88     bool MarshallingExceptImg(MessageParcel& data) const;
89 
90     bool WriteDrmSchemes(Parcel& parcel) const;
91     bool WriteDrmSchemes(MessageParcel& parcel);
92     bool ReadDrmSchemes(MessageParcel& parcel);
93     static bool ReadDrmSchemes(Parcel& parcel, AVMetaData *metaData);
94 
95     void SetAssetId(const std::string& assetId);
96     std::string GetAssetId() const;
97 
98     void SetTitle(const std::string& title);
99     std::string GetTitle() const;
100 
101     void SetArtist(const std::string& artist);
102     std::string GetArtist() const;
103 
104     void SetAuthor(const std::string& author);
105     std::string GetAuthor() const;
106 
107     void SetAVQueueName(const std::string& avQueueName);
108     std::string GetAVQueueName() const;
109 
110     void SetAVQueueId(const std::string& avQueueId);
111     std::string GetAVQueueId() const;
112 
113     void SetAVQueueImage(const std::shared_ptr<AVSessionPixelMap>& avQueueImage);
114     std::shared_ptr<AVSessionPixelMap> GetAVQueueImage() const;
115 
116     void SetAVQueueImageUri(const std::string& avQueueImageUri);
117     std::string GetAVQueueImageUri() const;
118 
119     void SetBundleIcon(const std::shared_ptr<AVSessionPixelMap>& avQueueImage);
120     std::shared_ptr<AVSessionPixelMap> GetBundleIcon() const;
121 
122     void SetAlbum(const std::string& album);
123     std::string GetAlbum() const;
124 
125     void SetWriter(const std::string& writer);
126     std::string GetWriter() const;
127 
128     void SetComposer(const std::string& composer);
129     std::string GetComposer() const;
130 
131     void SetDuration(int64_t duration);
132     int64_t GetDuration() const;
133 
134     void SetMediaImage(const std::shared_ptr<AVSessionPixelMap>& mediaImage);
135     std::shared_ptr<AVSessionPixelMap> GetMediaImage() const;
136 
137     void SetMediaImageUri(const std::string& mediaImageUri);
138     std::string GetMediaImageUri() const;
139 
140     void SetPublishDate(double date);
141     double GetPublishDate() const;
142 
143     void SetSubTitle(const std::string& subTitle);
144     std::string GetSubTitle() const;
145 
146     void SetDescription(const std::string& description);
147     std::string GetDescription() const;
148 
149     void SetLyric(const std::string& lyric);
150     std::string GetLyric() const;
151 
152     void SetSingleLyricText(const std::string& singleLyricText);
153     std::string GetSingleLyricText() const;
154 
155     void SetPreviousAssetId(const std::string& assetId);
156     std::string GetPreviousAssetId() const;
157 
158     void SetNextAssetId(const std::string& assetId);
159     std::string GetNextAssetId() const;
160 
161     void SetSkipIntervals(int32_t assetId);
162     int32_t GetSkipIntervals() const;
163 
164     void SetFilter(int32_t filter);
165     int32_t GetFilter() const;
166 
167     void SetMediaLength(int32_t mediaLength) const;
168     int32_t GetMediaLength() const;
169 
170     void SetAVQueueLength(int32_t avQueueLength) const;
171     int32_t GetAVQueueLength() const;
172 
173     void SetDisplayTags(int32_t displayTags);
174     int32_t GetDisplayTags() const;
175 
176     void SetDrmSchemes(std::vector<std::string> drmSchemes);
177     std::vector<std::string> GetDrmSchemes() const;
178 
179     void Reset();
180     void ResetToBaseMeta();
181 
182     MetaMaskType GetMetaMask() const;
183 
184     bool CopyToByMask(MetaMaskType& mask, AVMetaData& metaOut) const;
185     bool CopyFrom(const AVMetaData& metaIn);
186 
187     bool EqualWithUri(const AVMetaData& metaData);
188 
189     bool IsValid() const;
190 
191     const static inline std::vector<int32_t> localCapability {
192         META_KEY_ASSET_ID,
193         META_KEY_TITLE,
194         META_KEY_ARTIST,
195         META_KEY_AUTHOR,
196         META_KEY_AVQUEUE_NAME,
197         META_KEY_AVQUEUE_ID,
198         META_KEY_AVQUEUE_IMAGE,
199         META_KEY_AVQUEUE_IMAGE_URI,
200         META_KEY_ALBUM,
201         META_KEY_WRITER,
202         META_KEY_COMPOSER,
203         META_KEY_DURATION,
204         META_KEY_MEDIA_IMAGE,
205         META_KEY_MEDIA_IMAGE_URI,
206         META_KEY_PUBLISH_DATE,
207         META_KEY_SUBTITLE,
208         META_KEY_DESCRIPTION,
209         META_KEY_LYRIC,
210         META_KEY_PREVIOUS_ASSET_ID,
211         META_KEY_NEXT_ASSET_ID,
212         META_KEY_SKIP_INTERVALS,
213         META_KEY_FILTER,
214         META_KEY_DISPLAY_TAGS,
215         META_KEY_DRM_SCHEMES,
216         META_KEY_BUNDLE_ICON,
217         META_KEY_SINGLE_LYRIC_TEXT
218     };
219 
220 private:
221     MetaMaskType metaMask_;
222 
223     std::string assetId_ = "";
224     std::string title_ = "";
225     std::string artist_ = "";
226     std::string author_ = "";
227     std::string avQueueName_ = "";
228     std::string avQueueId_ = "";
229     std::shared_ptr<AVSessionPixelMap> avQueueImage_ = nullptr;
230     std::string avQueueImageUri_ = "";
231     std::string album_ = "";
232     std::string writer_ = "";
233     std::string composer_ = "";
234     int64_t duration_ = 0;
235     std::shared_ptr<AVSessionPixelMap> mediaImage_ = nullptr;
236     std::string mediaImageUri_ = "";
237     double publishDate_ = 0;
238     std::string subTitle_ = "";
239     std::string description_ = "";
240     std::string lyric_ = "";
241     std::string previousAssetId_ = "";
242     std::string nextAssetId_ = "";
243     int32_t skipIntervals_ = SECONDS_15;
244     int32_t filter_ = 2;
245     mutable int32_t mediaLength_ = 0;
246     mutable int32_t avQueueLength_ = 0;
247     int32_t displayTags_ = 0;
248     std::vector<std::string> drmSchemes_;
249     std::shared_ptr<AVSessionPixelMap> bundleIcon_ = nullptr;
250     std::string singleLyricText_ = "";
251 
252     static void CloneAssetId(const AVMetaData& from, AVMetaData& to);
253     static void CloneTitle(const AVMetaData& from, AVMetaData& to);
254     static void CloneArtist(const AVMetaData& from, AVMetaData& to);
255     static void CloneAuthor(const AVMetaData& from, AVMetaData& to);
256     static void CloneAVQueueName(const AVMetaData& from, AVMetaData& to);
257     static void CloneAVQueueId(const AVMetaData& from, AVMetaData& to);
258     static void CloneAVQueueImage(const AVMetaData& from, AVMetaData& to);
259     static void CloneAVQueueImageUri(const AVMetaData& from, AVMetaData& to);
260     static void CloneAlbum(const AVMetaData& from, AVMetaData& to);
261     static void CloneWriter(const AVMetaData& from, AVMetaData& to);
262     static void CloneComposer(const AVMetaData& from, AVMetaData& to);
263     static void CloneDuration(const AVMetaData& from, AVMetaData& to);
264     static void CloneMediaImage(const AVMetaData& from, AVMetaData& to);
265     static void CloneMediaImageUri(const AVMetaData& from, AVMetaData& to);
266     static void ClonePublishData(const AVMetaData& from, AVMetaData& to);
267     static void CloneSubTitle(const AVMetaData& from, AVMetaData& to);
268     static void CloneDescription(const AVMetaData& from, AVMetaData& to);
269     static void CloneLyric(const AVMetaData& from, AVMetaData& to);
270     static void ClonePreviousAssetId(const AVMetaData& from, AVMetaData& to);
271     static void CloneNextAssetId(const AVMetaData& from, AVMetaData& to);
272     static void CloneSkipIntervals(const AVMetaData& from, AVMetaData& to);
273     static void CloneFilter(const AVMetaData& from, AVMetaData& to);
274     static void CloneDisplayTags(const AVMetaData& from, AVMetaData& to);
275     static void CloneDrmSchemes(const AVMetaData& from, AVMetaData& to);
276     static void CloneBundleIcon(const AVMetaData& from, AVMetaData& to);
277     static void CloneSingleLyricText(const AVMetaData& from, AVMetaData& to);
278 
279     using CloneActionType = void(*)(const AVMetaData& from, AVMetaData& to);
280     static inline CloneActionType cloneActions[META_KEY_MAX] = {
281         &AVMetaData::CloneAssetId,
282         &AVMetaData::CloneTitle,
283         &AVMetaData::CloneArtist,
284         &AVMetaData::CloneAuthor,
285         &AVMetaData::CloneAVQueueName,
286         &AVMetaData::CloneAVQueueId,
287         &AVMetaData::CloneAVQueueImage,
288         &AVMetaData::CloneAVQueueImageUri,
289         &AVMetaData::CloneAlbum,
290         &AVMetaData::CloneWriter,
291         &AVMetaData::CloneComposer,
292         &AVMetaData::CloneDuration,
293         &AVMetaData::CloneMediaImage,
294         &AVMetaData::CloneMediaImageUri,
295         &AVMetaData::ClonePublishData,
296         &AVMetaData::CloneSubTitle,
297         &AVMetaData::CloneDescription,
298         &AVMetaData::CloneLyric,
299         &AVMetaData::ClonePreviousAssetId,
300         &AVMetaData::CloneNextAssetId,
301         &AVMetaData::CloneSkipIntervals,
302         &AVMetaData::CloneFilter,
303         &AVMetaData::CloneDisplayTags,
304         &AVMetaData::CloneDrmSchemes,
305         &AVMetaData::CloneBundleIcon,
306         &AVMetaData::CloneSingleLyricText
307     };
308 };
309 } // namespace OHOS::AVSession
310 #endif // OHOS_AVMETA_DATA_H