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