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 "parcel.h" 24 #include "avsession_pixel_map.h" 25 26 #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) and !defined(IOS_PLATFORM) 27 #include <malloc.h> 28 #endif 29 30 namespace OHOS::AVSession { 31 class AVMetaData : public Parcelable { 32 public: 33 static constexpr std::int64_t DURATION_ALWAYS_PLAY = -1; 34 enum { 35 META_KEY_ASSET_ID = 0, 36 META_KEY_TITLE = 1, 37 META_KEY_ARTIST = 2, 38 META_KEY_AUTHOR = 3, 39 META_KEY_ALBUM = 4, 40 META_KEY_WRITER = 5, 41 META_KEY_COMPOSER = 6, 42 META_KEY_DURATION = 7, 43 META_KEY_MEDIA_IMAGE = 8, 44 META_KEY_MEDIA_IMAGE_URI = 9, 45 META_KEY_PUBLISH_DATE = 10, 46 META_KEY_SUBTITLE = 11, 47 META_KEY_DESCRIPTION = 12, 48 META_KEY_LYRIC = 13, 49 META_KEY_PREVIOUS_ASSET_ID = 14, 50 META_KEY_NEXT_ASSET_ID = 15, 51 META_KEY_MAX = 16 52 }; 53 54 using MetaMaskType = std::bitset<META_KEY_MAX>; 55 56 AVMetaData() = default; 57 ~AVMetaData() = default; 58 59 static AVMetaData* Unmarshalling(Parcel& data); 60 bool Marshalling(Parcel& parcel) const override; 61 62 void SetAssetId(const std::string& assetId); 63 std::string GetAssetId() const; 64 65 void SetTitle(const std::string& title); 66 std::string GetTitle() const; 67 68 void SetArtist(const std::string& artist); 69 std::string GetArtist() const; 70 71 void SetAuthor(const std::string& author); 72 std::string GetAuthor() const; 73 74 void SetAlbum(const std::string& album); 75 std::string GetAlbum() const; 76 77 void SetWriter(const std::string& writer); 78 std::string GetWriter() const; 79 80 void SetComposer(const std::string& composer); 81 std::string GetComposer() const; 82 83 void SetDuration(int64_t duration); 84 int64_t GetDuration() const; 85 86 void SetMediaImage(const std::shared_ptr<AVSessionPixelMap>& mediaImage); 87 std::shared_ptr<AVSessionPixelMap> GetMediaImage() const; 88 89 void SetMediaImageUri(const std::string& mediaImageUri); 90 std::string GetMediaImageUri() const; 91 92 void SetPublishDate(double date); 93 double GetPublishDate() const; 94 95 void SetSubTitle(const std::string& subTitle); 96 std::string GetSubTitle() const; 97 98 void SetDescription(const std::string& description); 99 std::string GetDescription() const; 100 101 void SetLyric(const std::string& lyric); 102 std::string GetLyric() const; 103 104 void SetPreviousAssetId(const std::string& assetId); 105 std::string GetPreviousAssetId() const; 106 107 void SetNextAssetId(const std::string& assetId); 108 std::string GetNextAssetId() const; 109 110 void Reset(); 111 112 MetaMaskType GetMetaMask() const; 113 114 bool CopyToByMask(MetaMaskType& mask, AVMetaData& metaOut) const; 115 bool CopyFrom(const AVMetaData& metaIn); 116 117 bool IsValid() const; 118 119 const static inline std::vector<int32_t> localCapability { 120 META_KEY_ASSET_ID, 121 META_KEY_TITLE, 122 META_KEY_ARTIST, 123 META_KEY_AUTHOR, 124 META_KEY_ALBUM, 125 META_KEY_WRITER, 126 META_KEY_COMPOSER, 127 META_KEY_DURATION, 128 META_KEY_MEDIA_IMAGE, 129 META_KEY_MEDIA_IMAGE_URI, 130 META_KEY_PUBLISH_DATE, 131 META_KEY_SUBTITLE, 132 META_KEY_DESCRIPTION, 133 META_KEY_LYRIC, 134 META_KEY_PREVIOUS_ASSET_ID, 135 META_KEY_NEXT_ASSET_ID, 136 }; 137 138 private: 139 MetaMaskType metaMask_; 140 141 std::string assetId_ = ""; 142 std::string title_ = ""; 143 std::string artist_ = ""; 144 std::string author_ = ""; 145 std::string album_ = ""; 146 std::string writer_ = ""; 147 std::string composer_ = ""; 148 int64_t duration_ = 0; 149 std::shared_ptr<AVSessionPixelMap> mediaImage_ = nullptr; 150 std::string mediaImageUri_ = ""; 151 double publishDate_ = 0; 152 std::string subTitle_ = ""; 153 std::string description_ = ""; 154 std::string lyric_ = ""; 155 std::string previousAssetId_ = ""; 156 std::string nextAssetId_ = ""; 157 158 static void CloneAssetId(const AVMetaData& from, AVMetaData& to); 159 static void CloneTitle(const AVMetaData& from, AVMetaData& to); 160 static void CloneArtist(const AVMetaData& from, AVMetaData& to); 161 static void CloneAuthor(const AVMetaData& from, AVMetaData& to); 162 static void CloneAlbum(const AVMetaData& from, AVMetaData& to); 163 static void CloneWriter(const AVMetaData& from, AVMetaData& to); 164 static void CloneComposer(const AVMetaData& from, AVMetaData& to); 165 static void CloneDuration(const AVMetaData& from, AVMetaData& to); 166 static void CloneMediaImage(const AVMetaData& from, AVMetaData& to); 167 static void CloneMediaImageUri(const AVMetaData& from, AVMetaData& to); 168 static void ClonePublishData(const AVMetaData& from, AVMetaData& to); 169 static void CloneSubTitle(const AVMetaData& from, AVMetaData& to); 170 static void CloneDescription(const AVMetaData& from, AVMetaData& to); 171 static void CloneLyric(const AVMetaData& from, AVMetaData& to); 172 static void ClonePreviousAssetId(const AVMetaData& from, AVMetaData& to); 173 static void CloneNextAssetId(const AVMetaData& from, AVMetaData& to); 174 175 using CloneActionType = void(*)(const AVMetaData& from, AVMetaData& to); 176 static inline CloneActionType cloneActions[META_KEY_MAX] = { 177 [META_KEY_ASSET_ID] = &AVMetaData::CloneAssetId, 178 [META_KEY_TITLE] = &AVMetaData::CloneTitle, 179 [META_KEY_ARTIST] = &AVMetaData::CloneArtist, 180 [META_KEY_AUTHOR] = &AVMetaData::CloneAuthor, 181 [META_KEY_ALBUM] = &AVMetaData::CloneAlbum, 182 [META_KEY_WRITER] = &AVMetaData::CloneWriter, 183 [META_KEY_COMPOSER] = &AVMetaData::CloneComposer, 184 [META_KEY_DURATION] = &AVMetaData::CloneDuration, 185 [META_KEY_MEDIA_IMAGE] = &AVMetaData::CloneMediaImage, 186 [META_KEY_MEDIA_IMAGE_URI] = &AVMetaData::CloneMediaImageUri, 187 [META_KEY_PUBLISH_DATE] = &AVMetaData::ClonePublishData, 188 [META_KEY_SUBTITLE] = &AVMetaData::CloneSubTitle, 189 [META_KEY_DESCRIPTION] = &AVMetaData::CloneDescription, 190 [META_KEY_LYRIC] = &AVMetaData::CloneLyric, 191 [META_KEY_PREVIOUS_ASSET_ID] = &AVMetaData::ClonePreviousAssetId, 192 [META_KEY_NEXT_ASSET_ID] = &AVMetaData::CloneNextAssetId, 193 }; 194 }; 195 } // namespace OHOS::AVSession 196 #endif // OHOS_AVMETA_DATA_H