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& data); 83 bool Marshalling(Parcel& parcel) const override; 84 85 static bool UnmarshallingCheckParamTask(Parcel& data, AVMetaData *result); 86 static bool UnmarshallingCheckImageTask(Parcel& data, AVMetaData *result); 87 88 static bool UnmarshallingExceptImg(MessageParcel& data, AVMetaData& metaOut); 89 static bool MarshallingExceptImg(MessageParcel& data, const AVMetaData metaIn); 90 91 bool WriteDrmSchemes(Parcel& parcel) const; 92 static bool WriteDrmSchemes(MessageParcel& parcel, const AVMetaData metaData); 93 static bool ReadDrmSchemes(Parcel& parcel, AVMetaData *metaData); 94 static bool ReadDrmSchemes(MessageParcel& parcel, AVMetaData& metaData); 95 96 void SetAssetId(const std::string& assetId); 97 std::string GetAssetId() const; 98 99 void SetTitle(const std::string& title); 100 std::string GetTitle() const; 101 102 void SetArtist(const std::string& artist); 103 std::string GetArtist() const; 104 105 void SetAuthor(const std::string& author); 106 std::string GetAuthor() const; 107 108 void SetAVQueueName(const std::string& avQueueName); 109 std::string GetAVQueueName() const; 110 111 void SetAVQueueId(const std::string& avQueueId); 112 std::string GetAVQueueId() const; 113 114 void SetAVQueueImage(const std::shared_ptr<AVSessionPixelMap>& avQueueImage); 115 std::shared_ptr<AVSessionPixelMap> GetAVQueueImage() const; 116 117 void SetAVQueueImageUri(const std::string& avQueueImageUri); 118 std::string GetAVQueueImageUri() const; 119 120 void SetBundleIcon(const std::shared_ptr<AVSessionPixelMap>& avQueueImage); 121 std::shared_ptr<AVSessionPixelMap> GetBundleIcon() const; 122 123 void SetAlbum(const std::string& album); 124 std::string GetAlbum() const; 125 126 void SetWriter(const std::string& writer); 127 std::string GetWriter() const; 128 129 void SetComposer(const std::string& composer); 130 std::string GetComposer() const; 131 132 void SetDuration(int64_t duration); 133 int64_t GetDuration() const; 134 135 void SetMediaImage(const std::shared_ptr<AVSessionPixelMap>& mediaImage); 136 std::shared_ptr<AVSessionPixelMap> GetMediaImage() const; 137 138 void SetMediaImageUri(const std::string& mediaImageUri); 139 std::string GetMediaImageUri() const; 140 141 void SetPublishDate(double date); 142 double GetPublishDate() const; 143 144 void SetSubTitle(const std::string& subTitle); 145 std::string GetSubTitle() const; 146 147 void SetDescription(const std::string& description); 148 std::string GetDescription() const; 149 150 void SetLyric(const std::string& lyric); 151 std::string GetLyric() const; 152 153 void SetSingleLyricText(const std::string& singleLyricText); 154 std::string GetSingleLyricText() const; 155 156 void SetPreviousAssetId(const std::string& assetId); 157 std::string GetPreviousAssetId() const; 158 159 void SetNextAssetId(const std::string& assetId); 160 std::string GetNextAssetId() const; 161 162 void SetSkipIntervals(int32_t assetId); 163 int32_t GetSkipIntervals() const; 164 165 void SetFilter(int32_t filter); 166 int32_t GetFilter() const; 167 168 void SetMediaLength(int32_t mediaLength); 169 int32_t GetMediaLength() const; 170 171 void SetAVQueueLength(int32_t avQueueLength); 172 int32_t GetAVQueueLength() const; 173 174 void SetDisplayTags(int32_t displayTags); 175 int32_t GetDisplayTags() const; 176 177 void SetDrmSchemes(std::vector<std::string> drmSchemes); 178 std::vector<std::string> GetDrmSchemes() const; 179 180 void Reset(); 181 void ResetExtAssetId(); 182 183 MetaMaskType GetMetaMask() const; 184 185 bool CopyToByMask(MetaMaskType& mask, AVMetaData& metaOut) const; 186 bool CopyFrom(const AVMetaData& metaIn); 187 188 bool EqualWithUri(const AVMetaData& metaData); 189 190 bool IsValid() const; 191 192 const static inline std::vector<int32_t> localCapability { 193 META_KEY_ASSET_ID, 194 META_KEY_TITLE, 195 META_KEY_ARTIST, 196 META_KEY_AUTHOR, 197 META_KEY_AVQUEUE_NAME, 198 META_KEY_AVQUEUE_ID, 199 META_KEY_AVQUEUE_IMAGE, 200 META_KEY_AVQUEUE_IMAGE_URI, 201 META_KEY_ALBUM, 202 META_KEY_WRITER, 203 META_KEY_COMPOSER, 204 META_KEY_DURATION, 205 META_KEY_MEDIA_IMAGE, 206 META_KEY_MEDIA_IMAGE_URI, 207 META_KEY_PUBLISH_DATE, 208 META_KEY_SUBTITLE, 209 META_KEY_DESCRIPTION, 210 META_KEY_LYRIC, 211 META_KEY_PREVIOUS_ASSET_ID, 212 META_KEY_NEXT_ASSET_ID, 213 META_KEY_SKIP_INTERVALS, 214 META_KEY_FILTER, 215 META_KEY_DISPLAY_TAGS, 216 META_KEY_DRM_SCHEMES, 217 META_KEY_BUNDLE_ICON, 218 META_KEY_SINGLE_LYRIC_TEXT 219 }; 220 221 private: 222 MetaMaskType metaMask_; 223 224 std::string assetId_ = ""; 225 std::string title_ = ""; 226 std::string artist_ = ""; 227 std::string author_ = ""; 228 std::string avQueueName_ = ""; 229 std::string avQueueId_ = ""; 230 std::shared_ptr<AVSessionPixelMap> avQueueImage_ = nullptr; 231 std::string avQueueImageUri_ = ""; 232 std::string album_ = ""; 233 std::string writer_ = ""; 234 std::string composer_ = ""; 235 int64_t duration_ = 0; 236 std::shared_ptr<AVSessionPixelMap> mediaImage_ = nullptr; 237 std::string mediaImageUri_ = ""; 238 double publishDate_ = 0; 239 std::string subTitle_ = ""; 240 std::string description_ = ""; 241 std::string lyric_ = ""; 242 std::string previousAssetId_ = ""; 243 std::string nextAssetId_ = ""; 244 int32_t skipIntervals_ = SECONDS_15; 245 int32_t filter_ = 2; 246 int32_t mediaLength_ = 0; 247 int32_t avQueueLength_ = 0; 248 int32_t displayTags_ = 0; 249 std::vector<std::string> drmSchemes_; 250 std::shared_ptr<AVSessionPixelMap> bundleIcon_ = nullptr; 251 std::string singleLyricText_ = ""; 252 253 static void CloneAssetId(const AVMetaData& from, AVMetaData& to); 254 static void CloneTitle(const AVMetaData& from, AVMetaData& to); 255 static void CloneArtist(const AVMetaData& from, AVMetaData& to); 256 static void CloneAuthor(const AVMetaData& from, AVMetaData& to); 257 static void CloneAVQueueName(const AVMetaData& from, AVMetaData& to); 258 static void CloneAVQueueId(const AVMetaData& from, AVMetaData& to); 259 static void CloneAVQueueImage(const AVMetaData& from, AVMetaData& to); 260 static void CloneAVQueueImageUri(const AVMetaData& from, AVMetaData& to); 261 static void CloneAlbum(const AVMetaData& from, AVMetaData& to); 262 static void CloneWriter(const AVMetaData& from, AVMetaData& to); 263 static void CloneComposer(const AVMetaData& from, AVMetaData& to); 264 static void CloneDuration(const AVMetaData& from, AVMetaData& to); 265 static void CloneMediaImage(const AVMetaData& from, AVMetaData& to); 266 static void CloneMediaImageUri(const AVMetaData& from, AVMetaData& to); 267 static void ClonePublishData(const AVMetaData& from, AVMetaData& to); 268 static void CloneSubTitle(const AVMetaData& from, AVMetaData& to); 269 static void CloneDescription(const AVMetaData& from, AVMetaData& to); 270 static void CloneLyric(const AVMetaData& from, AVMetaData& to); 271 static void ClonePreviousAssetId(const AVMetaData& from, AVMetaData& to); 272 static void CloneNextAssetId(const AVMetaData& from, AVMetaData& to); 273 static void CloneSkipIntervals(const AVMetaData& from, AVMetaData& to); 274 static void CloneFilter(const AVMetaData& from, AVMetaData& to); 275 static void CloneDisplayTags(const AVMetaData& from, AVMetaData& to); 276 static void CloneDrmSchemes(const AVMetaData& from, AVMetaData& to); 277 static void CloneBundleIcon(const AVMetaData& from, AVMetaData& to); 278 static void CloneSingleLyricText(const AVMetaData& from, AVMetaData& to); 279 280 using CloneActionType = void(*)(const AVMetaData& from, AVMetaData& to); 281 static inline CloneActionType cloneActions[META_KEY_MAX] = { 282 &AVMetaData::CloneAssetId, 283 &AVMetaData::CloneTitle, 284 &AVMetaData::CloneArtist, 285 &AVMetaData::CloneAuthor, 286 &AVMetaData::CloneAVQueueName, 287 &AVMetaData::CloneAVQueueId, 288 &AVMetaData::CloneAVQueueImage, 289 &AVMetaData::CloneAVQueueImageUri, 290 &AVMetaData::CloneAlbum, 291 &AVMetaData::CloneWriter, 292 &AVMetaData::CloneComposer, 293 &AVMetaData::CloneDuration, 294 &AVMetaData::CloneMediaImage, 295 &AVMetaData::CloneMediaImageUri, 296 &AVMetaData::ClonePublishData, 297 &AVMetaData::CloneSubTitle, 298 &AVMetaData::CloneDescription, 299 &AVMetaData::CloneLyric, 300 &AVMetaData::ClonePreviousAssetId, 301 &AVMetaData::CloneNextAssetId, 302 &AVMetaData::CloneSkipIntervals, 303 &AVMetaData::CloneFilter, 304 &AVMetaData::CloneDisplayTags, 305 &AVMetaData::CloneDrmSchemes, 306 &AVMetaData::CloneBundleIcon, 307 &AVMetaData::CloneSingleLyricText 308 }; 309 }; 310 } // namespace OHOS::AVSession 311 #endif // OHOS_AVMETA_DATA_H