• 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_MAX = 23
60     };
61 
62     enum {
63         SECONDS_10 = 10,
64         SECONDS_15 = 15,
65         SECONDS_30 = 30,
66     };
67 
68     enum {
69         DISPLAY_TAG_AUDIO_VIVID = 1,
70         // indicate all supported sound source for gold flag, you should make OR operation if add new options
71         DISPLAY_TAG_ALL = DISPLAY_TAG_AUDIO_VIVID
72     };
73 
74     using MetaMaskType = std::bitset<META_KEY_MAX>;
75 
76     AVMetaData() = default;
77     ~AVMetaData() = default;
78 
79     static AVMetaData* Unmarshalling(Parcel& data);
80     bool Marshalling(Parcel& parcel) const override;
81 
82     static bool UnmarshallingCheckParamTask(Parcel& data,  AVMetaData *result);
83     static bool UnmarshallingCheckImageTask(Parcel& data,  AVMetaData *result);
84 
85     static bool UnmarshallingExceptImg(MessageParcel& data, AVMetaData& metaOut);
86     static bool MarshallingExceptImg(MessageParcel& data, const AVMetaData metaIn);
87 
88     void SetAssetId(const std::string& assetId);
89     std::string GetAssetId() const;
90 
91     void SetTitle(const std::string& title);
92     std::string GetTitle() const;
93 
94     void SetArtist(const std::string& artist);
95     std::string GetArtist() const;
96 
97     void SetAuthor(const std::string& author);
98     std::string GetAuthor() const;
99 
100     void SetAVQueueName(const std::string& avQueueName);
101     std::string GetAVQueueName() const;
102 
103     void SetAVQueueId(const std::string& avQueueId);
104     std::string GetAVQueueId() const;
105 
106     void SetAVQueueImage(const std::shared_ptr<AVSessionPixelMap>& avQueueImage);
107     std::shared_ptr<AVSessionPixelMap> GetAVQueueImage() const;
108 
109     void SetAVQueueImageUri(const std::string& avQueueImageUri);
110     std::string GetAVQueueImageUri() const;
111 
112     void SetAlbum(const std::string& album);
113     std::string GetAlbum() const;
114 
115     void SetWriter(const std::string& writer);
116     std::string GetWriter() const;
117 
118     void SetComposer(const std::string& composer);
119     std::string GetComposer() const;
120 
121     void SetDuration(int64_t duration);
122     int64_t GetDuration() const;
123 
124     void SetMediaImage(const std::shared_ptr<AVSessionPixelMap>& mediaImage);
125     std::shared_ptr<AVSessionPixelMap> GetMediaImage() const;
126 
127     void SetMediaImageUri(const std::string& mediaImageUri);
128     std::string GetMediaImageUri() const;
129 
130     void SetPublishDate(double date);
131     double GetPublishDate() const;
132 
133     void SetSubTitle(const std::string& subTitle);
134     std::string GetSubTitle() const;
135 
136     void SetDescription(const std::string& description);
137     std::string GetDescription() const;
138 
139     void SetLyric(const std::string& lyric);
140     std::string GetLyric() const;
141 
142     void SetPreviousAssetId(const std::string& assetId);
143     std::string GetPreviousAssetId() const;
144 
145     void SetNextAssetId(const std::string& assetId);
146     std::string GetNextAssetId() const;
147 
148     void SetSkipIntervals(int32_t skipIntervals);
149     int32_t GetSkipIntervals() const;
150 
151     void SetFilter(int32_t filter);
152     int32_t GetFilter() const;
153 
154     void SetMediaLength(int32_t mediaLength);
155     int32_t GetMediaLength() const;
156 
157     void SetAVQueueLength(int32_t avQueueLength);
158     int32_t GetAVQueueLength() const;
159 
160     void SetDisplayTags(int32_t displayTags);
161     int32_t GetDisplayTags() const;
162 
163     void Reset();
164 
165     MetaMaskType GetMetaMask() const;
166 
167     bool CopyToByMask(MetaMaskType& mask, AVMetaData& metaOut) const;
168     bool CopyFrom(const AVMetaData& metaIn);
169 
170     bool IsValid() const;
171 
172     const static inline std::vector<int32_t> localCapability {
173         META_KEY_ASSET_ID,
174         META_KEY_TITLE,
175         META_KEY_ARTIST,
176         META_KEY_AUTHOR,
177         META_KEY_AVQUEUE_NAME,
178         META_KEY_AVQUEUE_ID,
179         META_KEY_AVQUEUE_IMAGE,
180         META_KEY_AVQUEUE_IMAGE_URI,
181         META_KEY_ALBUM,
182         META_KEY_WRITER,
183         META_KEY_COMPOSER,
184         META_KEY_DURATION,
185         META_KEY_MEDIA_IMAGE,
186         META_KEY_MEDIA_IMAGE_URI,
187         META_KEY_PUBLISH_DATE,
188         META_KEY_SUBTITLE,
189         META_KEY_DESCRIPTION,
190         META_KEY_LYRIC,
191         META_KEY_PREVIOUS_ASSET_ID,
192         META_KEY_NEXT_ASSET_ID,
193         META_KEY_SKIP_INTERVALS,
194         META_KEY_FILTER,
195         META_KEY_DISPLAY_TAGS
196     };
197 
198 private:
199     MetaMaskType metaMask_;
200 
201     std::string assetId_ = "";
202     std::string title_ = "";
203     std::string artist_ = "";
204     std::string author_ = "";
205     std::string avQueueName_ = "";
206     std::string avQueueId_ = "";
207     std::shared_ptr<AVSessionPixelMap> avQueueImage_ = nullptr;
208     std::string avQueueImageUri_ = "";
209     std::string album_ = "";
210     std::string writer_ = "";
211     std::string composer_ = "";
212     int64_t duration_ = 0;
213     std::shared_ptr<AVSessionPixelMap> mediaImage_ = nullptr;
214     std::string mediaImageUri_ = "";
215     double publishDate_ = 0;
216     std::string subTitle_ = "";
217     std::string description_ = "";
218     std::string lyric_ = "";
219     std::string previousAssetId_ = "";
220     std::string nextAssetId_ = "";
221     int32_t skipIntervals_ = SECONDS_15;
222     int32_t filter_ = 2;
223     int32_t mediaLength_ = 0;
224     int32_t avQueueLength_ = 0;
225     int32_t displayTags_ = 0;
226 
227     static void CloneAssetId(const AVMetaData& from, AVMetaData& to);
228     static void CloneTitle(const AVMetaData& from, AVMetaData& to);
229     static void CloneArtist(const AVMetaData& from, AVMetaData& to);
230     static void CloneAuthor(const AVMetaData& from, AVMetaData& to);
231     static void CloneAVQueueName(const AVMetaData& from, AVMetaData& to);
232     static void CloneAVQueueId(const AVMetaData& from, AVMetaData& to);
233     static void CloneAVQueueImage(const AVMetaData& from, AVMetaData& to);
234     static void CloneAVQueueImageUri(const AVMetaData& from, AVMetaData& to);
235     static void CloneAlbum(const AVMetaData& from, AVMetaData& to);
236     static void CloneWriter(const AVMetaData& from, AVMetaData& to);
237     static void CloneComposer(const AVMetaData& from, AVMetaData& to);
238     static void CloneDuration(const AVMetaData& from, AVMetaData& to);
239     static void CloneMediaImage(const AVMetaData& from, AVMetaData& to);
240     static void CloneMediaImageUri(const AVMetaData& from, AVMetaData& to);
241     static void ClonePublishData(const AVMetaData& from, AVMetaData& to);
242     static void CloneSubTitle(const AVMetaData& from, AVMetaData& to);
243     static void CloneDescription(const AVMetaData& from, AVMetaData& to);
244     static void CloneLyric(const AVMetaData& from, AVMetaData& to);
245     static void ClonePreviousAssetId(const AVMetaData& from, AVMetaData& to);
246     static void CloneNextAssetId(const AVMetaData& from, AVMetaData& to);
247     static void CloneSkipIntervals(const AVMetaData& from, AVMetaData& to);
248     static void CloneFilter(const AVMetaData& from, AVMetaData& to);
249     static void CloneDisplayTags(const AVMetaData& from, AVMetaData& to);
250 
251     using CloneActionType = void(*)(const AVMetaData& from, AVMetaData& to);
252     static inline CloneActionType cloneActions[META_KEY_MAX] = {
253         &AVMetaData::CloneAssetId,
254         &AVMetaData::CloneTitle,
255         &AVMetaData::CloneArtist,
256         &AVMetaData::CloneAuthor,
257         &AVMetaData::CloneAVQueueName,
258         &AVMetaData::CloneAVQueueId,
259         &AVMetaData::CloneAVQueueImage,
260         &AVMetaData::CloneAVQueueImageUri,
261         &AVMetaData::CloneAlbum,
262         &AVMetaData::CloneWriter,
263         &AVMetaData::CloneComposer,
264         &AVMetaData::CloneDuration,
265         &AVMetaData::CloneMediaImage,
266         &AVMetaData::CloneMediaImageUri,
267         &AVMetaData::ClonePublishData,
268         &AVMetaData::CloneSubTitle,
269         &AVMetaData::CloneDescription,
270         &AVMetaData::CloneLyric,
271         &AVMetaData::ClonePreviousAssetId,
272         &AVMetaData::CloneNextAssetId,
273         &AVMetaData::CloneSkipIntervals,
274         &AVMetaData::CloneFilter,
275         &AVMetaData::CloneDisplayTags
276     };
277 };
278 } // namespace OHOS::AVSession
279 #endif // OHOS_AVMETA_DATA_H