1 /* 2 * Copyright (C) 2021 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 16 #ifndef METADATA_H 17 #define METADATA_H 18 19 #include <unordered_map> 20 #include <variant> 21 #include "scanner_utils.h" 22 #include "abs_shared_result_set.h" 23 24 namespace OHOS { 25 namespace Media { 26 class Metadata { 27 public: 28 Metadata(); 29 ~Metadata() = default; 30 using VariantData = std::variant<int32_t, int64_t, std::string, MediaType>; 31 32 void SetFileId(const VariantData &id); 33 int32_t GetFileId() const; 34 35 void SetFilePath(const VariantData &path); 36 std::string GetFilePath() const; 37 38 void SetUri(const VariantData &uri); 39 std::string GetUri() const; 40 41 void SetRelativePath(const VariantData &relativePath); 42 std::string GetRelativePath() const; 43 44 void SetFileMimeType(const VariantData &mimeType); 45 std::string GetFileMimeType() const; 46 47 void SetFileMediaType(const VariantData &mediaType); 48 MediaType GetFileMediaType() const; 49 50 void SetFileName(const VariantData &name); 51 std::string GetFileName() const; 52 53 void SetFileSize(const VariantData &size); 54 int64_t GetFileSize() const; 55 56 void SetFileDateAdded(const VariantData &dateAdded); 57 int64_t GetFileDateAdded() const; 58 59 void SetFileDateModified(const VariantData &dateModified); 60 int64_t GetFileDateModified() const; 61 62 void SetFileExtension(const VariantData &fileExt); 63 std::string GetFileExtension() const; 64 65 void SetFileTitle(const VariantData &title); 66 std::string GetFileTitle() const; 67 68 void SetFileArtist(const VariantData &artist); 69 std::string GetFileArtist() const; 70 71 void SetAlbum(const VariantData &album); 72 std::string GetAlbum() const; 73 74 void SetFileHeight(const VariantData &height); 75 int32_t GetFileHeight() const; 76 77 void SetFileWidth(const VariantData &width); 78 int32_t GetFileWidth() const; 79 80 void SetOrientation(const VariantData &orientation); 81 int32_t GetOrientation() const; 82 83 void SetFileDuration(const VariantData &duration); 84 int32_t GetFileDuration() const; 85 86 int32_t GetParentId() const; 87 void SetParentId(const VariantData &id); 88 89 void SetAlbumId(const VariantData &albumId); 90 int32_t GetAlbumId() const; 91 92 void SetAlbumName(const VariantData &album); 93 std::string GetAlbumName() const; 94 95 void Init(); 96 97 using MetadataFnPtr = void (Metadata::*)(const VariantData &); 98 std::unordered_map<std::string, std::pair<DataType, MetadataFnPtr>> memberFuncMap_; 99 100 private: 101 int32_t id_; 102 std::string uri_; 103 std::string filePath_; 104 std::string relativePath_; 105 106 std::string mimeType_; 107 MediaType mediaType_; 108 std::string name_; 109 110 int64_t size_; 111 int64_t dateModified_; 112 int64_t dateAdded_; 113 114 std::string fileExt_; 115 int32_t parentId_; 116 117 // audio 118 std::string title_; 119 std::string artist_; 120 std::string album_; 121 122 // video, image 123 int32_t height_; 124 int32_t width_; 125 int32_t duration_; 126 int32_t orientation_; 127 128 // album 129 int32_t albumId_; 130 std::string albumName_; 131 }; 132 } // namespace Media 133 } // namespace OHOS 134 135 #endif // METADATA_H 136