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 FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_DATA_UTILS_H_ 16 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_DATA_UTILS_H_ 17 #include <memory> 18 #include <vector> 19 #include <string> 20 #include <variant> 21 #include <sys/time.h> 22 #include <stdio.h> 23 #include <unordered_map> 24 25 #include "datashare_result_set.h" 26 #include "mtp_operation_context.h" 27 #include "property.h" 28 #include "userfile_manager_types.h" 29 #include "result_set_utils.h" 30 31 namespace OHOS { 32 namespace Media { 33 struct PropertyValue { 34 uint64_t outIntVal = 0; 35 uint128_t outLongVal = {0}; 36 std::string outStrVal; 37 }; 38 struct MovingType { 39 uint64_t parent; 40 std::string displayName; 41 }; 42 const std::string MTP_FORMAT_ALL = ".all"; // Undefined 43 const std::string MTP_FORMAT_UNDEFINED = ".undefined"; // Undefined 44 const std::string MTP_FORMAT_ASSOCIATION = ".floader"; // associations (folders and directories) 45 const std::string MTP_FORMAT_SCRIPT = ".js"; // script files 46 const std::string MTP_FORMAT_EXECUTABLE = ".exe"; // executable files 47 const std::string MTP_FORMAT_TEXT = ".txt"; // text files 48 const std::string MTP_FORMAT_HTML = ".html"; // HTML files 49 const std::string MTP_FORMAT_DPOF = ".dp"; // DPOF files 50 const std::string MTP_FORMAT_AIFF = ".aiff"; // AIFF audio files 51 const std::string MTP_FORMAT_WAV = ".wav"; // WAV audio files 52 const std::string MTP_FORMAT_MP3 = ".mp3"; // MP3 audio files 53 const std::string MTP_FORMAT_AVI = ".avi"; // AVI video files 54 const std::string MTP_FORMAT_MPEG = ".mpeg"; // MPEG video files 55 const std::string MTP_FORMAT_ASF = ".asf"; // ASF files 56 // Unknown image files which are not specified in PTP specification 57 const std::string MTP_FORMAT_DEFINED = ".image"; // Unknown image files 58 const std::string MTP_FORMAT_HEIC = ".heic"; // HEIC image files 59 const std::string MTP_FORMAT_HEICS = ".heics"; // HEICS image files 60 const std::string MTP_FORMAT_HEIFS = ".heifs"; // HEIFS image files 61 const std::string MTP_FORMAT_BM = ".bm"; // BM image files 62 const std::string MTP_FORMAT_HEIF = ".heif"; // HEIF image files 63 const std::string MTP_FORMAT_HIF = ".hif"; // HIF image files 64 const std::string MTP_FORMAT_AVIF = ".avif"; // AVIF image files 65 const std::string MTP_FORMAT_CUR = ".cur"; // CUR image files 66 const std::string MTP_FORMAT_WEBP = ".webp"; // WEBP image files 67 const std::string MTP_FORMAT_DNG = ".dng"; // DNG image files 68 const std::string MTP_FORMAT_RAF = ".raf"; // RAF image files 69 const std::string MTP_FORMAT_ICO = ".ico"; // ICO image files 70 const std::string MTP_FORMAT_NRW = ".nrw"; // NRW image files 71 const std::string MTP_FORMAT_RW2 = ".rw2"; // RW2 image files 72 const std::string MTP_FORMAT_PEF = ".pef"; // PEF image files 73 const std::string MTP_FORMAT_SRW = ".srw"; // SRW image files 74 const std::string MTP_FORMAT_ARW = ".arw"; // ARW image files 75 const std::string MTP_FORMAT_SVG = ".svg"; // SVG image files 76 const std::string MTP_FORMAT_RAW = ".raw"; // RAW image files 77 const std::string MTP_FORMAT_EXIF_JPEG = ".jpeg?.jpg"; // JPEG image files 78 const std::string MTP_FORMAT_JPEG = ".jpeg"; 79 const std::string MTP_FORMAT_JPG = ".jpg"; 80 const std::string MTP_FORMAT_TIFF_EP = ".tiff"; // TIFF EP image files 81 const std::string MTP_FORMAT_FLASHPIX = ".swf"; 82 const std::string MTP_FORMAT_BMP = ".bmp"; // BMP image files 83 const std::string MTP_FORMAT_CIFF = ".ciff"; 84 const std::string MTP_FORMAT_GIF = ".giff"; // GIF image files 85 const std::string MTP_FORMAT_JFIF = ".jsif"; // JFIF image files 86 const std::string MTP_FORMAT_CD = ".cd"; 87 const std::string MTP_FORMAT_PICT = ".pict"; // PICT image files 88 const std::string MTP_FORMAT_PNG = ".png"; // PNG image files 89 const std::string MTP_FORMAT_TIFF = ".tif"; // TIFF image files 90 const std::string MTP_FORMAT_TIFF_IT = ".tiff"; 91 const std::string MTP_FORMAT_JP2 = ".jp2"; // JP2 files 92 const std::string MTP_FORMAT_JPX = ".jpx"; // JPX files 93 const std::string MTP_FORMAT_UNDEFINED_FIRMWARE = ".undefinedfirmware"; // firmware files 94 const std::string MTP_FORMAT_WINDOWS_IMAGE_FORMAT = ".img"; // Windows image files 95 const std::string MTP_FORMAT_UNDEFINED_AUDIO = ".undefinedaudio"; // undefined audio files files 96 const std::string MTP_FORMAT_WMA = ".wma"; // WMA audio files 97 const std::string MTP_FORMAT_OGG = ".ogg"; // OGG audio files 98 const std::string MTP_FORMAT_AAC = ".aac"; // AAC audio files 99 const std::string MTP_FORMAT_AUDIBLE = ".aa"; // Audible audio files 100 const std::string MTP_FORMAT_FLAC = ".flac"; // FLAC audio files 101 const std::string MTP_FORMAT_UNDEFINED_VIDEO = ".undefinedvideo"; // undefined video files 102 const std::string MTP_FORMAT_WMV = ".wmv"; // WMV video files 103 const std::string MTP_FORMAT_MP4_CONTAINER = ".mp4"; // MP4 files 104 const std::string MTP_FORMAT_MP2 = ".mp2"; // MP2 files 105 const std::string MTP_FORMAT_3GP_CONTAINER = ".3gp"; // 3GP files 106 const std::string MTP_FORMAT_3GPP2 = ".3gpp2"; // 3GPP2 files 107 const std::string MTP_FORMAT_3GP2 = ".3gp2"; // 3GP2 files 108 const std::string MTP_FORMAT_3G2 = ".3g2"; // 3G2 files 109 const std::string MTP_FORMAT_3GPP = ".3gpp"; // 3GPP files 110 const std::string MTP_FORMAT_M4V = ".m4v"; // M4V files 111 const std::string MTP_FORMAT_F4V = ".f4v"; // F4V files 112 const std::string MTP_FORMAT_MP4V = ".mp4v"; // MP4V files 113 const std::string MTP_FORMAT_MPEG4 = ".mpeg4"; // MPEG4 files 114 const std::string MTP_FORMAT_M2TS = ".m2ts"; // M2TS files 115 const std::string MTP_FORMAT_MTS = ".mts"; // MTS files 116 const std::string MTP_FORMAT_TS = ".ts"; // TS files 117 const std::string MTP_FORMAT_YT = ".yt"; // YT files 118 const std::string MTP_FORMAT_WRF = ".wrf"; // WRF files 119 const std::string MTP_FORMAT_MPEG2 = ".mpeg2"; // MPEG2 files 120 const std::string MTP_FORMAT_MPV2 = ".mpv2"; // MPV2 files 121 const std::string MTP_FORMAT_MP2V = ".mp2v"; // MP2V files 122 const std::string MTP_FORMAT_M2V = ".m2v"; // M2V files 123 const std::string MTP_FORMAT_M2T = ".m2t"; // M2T files 124 const std::string MTP_FORMAT_MPEG1 = ".mpeg1"; // MPEG1 files 125 const std::string MTP_FORMAT_MPV1 = ".mpv1"; // MPV1 files 126 const std::string MTP_FORMAT_MP1V = ".mp1v"; // MP1V files 127 const std::string MTP_FORMAT_M1V = ".m1v"; // M1V files 128 const std::string MTP_FORMAT_MPG = ".mpg"; // MPG files 129 const std::string MTP_FORMAT_MOV = ".mov"; // MOV files 130 const std::string MTP_FORMAT_MKV = ".mkv"; // MKV files 131 const std::string MTP_FORMAT_WEBM = ".webm"; // WEBM files 132 const std::string MTP_FORMAT_H264 = ".h264"; // H264 files 133 const std::string MTP_FORMAT_IEF = ".ief"; // IEF image files 134 const std::string MTP_FORMAT_JPG2 = ".jpg2"; // JPG2 files 135 const std::string MTP_FORMAT_JPM = ".jpm"; // JPM files 136 const std::string MTP_FORMAT_JPF = ".jpf"; // JPF files 137 const std::string MTP_FORMAT_PCX = ".pcx"; // PCX files 138 const std::string MTP_FORMAT_SVGZ = ".svgz"; // SVGZ files 139 const std::string MTP_FORMAT_DJVU = ".djvu"; // DJVU files 140 const std::string MTP_FORMAT_DJV = ".djv"; // DJV files 141 const std::string MTP_FORMAT_WBMP = ".wbmp"; // WBMP files 142 const std::string MTP_FORMAT_CR2 = ".cr2"; // CR2 files 143 const std::string MTP_FORMAT_CRW = ".crw"; // CRW files 144 const std::string MTP_FORMAT_RAS = ".ras"; // RAS files 145 const std::string MTP_FORMAT_CDR = ".cdr"; // CDR files 146 const std::string MTP_FORMAT_PAT = ".pat"; // PAT files 147 const std::string MTP_FORMAT_CDT = ".cdt"; // CDT files 148 const std::string MTP_FORMAT_CPT = ".cpt"; // CPT files 149 const std::string MTP_FORMAT_ERF = ".erf"; // ERF files 150 const std::string MTP_FORMAT_ART = ".art"; // ART files 151 const std::string MTP_FORMAT_JNG = ".jng"; // JNG files 152 const std::string MTP_FORMAT_NEF = ".nef"; // NEF files 153 const std::string MTP_FORMAT_ORF = ".orf"; // ORF files 154 const std::string MTP_FORMAT_PSD = ".psd"; // PSD files 155 const std::string MTP_FORMAT_PNM = ".pnm"; // PNM files 156 const std::string MTP_FORMAT_PBM = ".pbm"; // PBM files 157 const std::string MTP_FORMAT_PGM = ".pgm"; // PGM files 158 const std::string MTP_FORMAT_PPM = ".ppm"; // PPM files 159 const std::string MTP_FORMAT_RGB = ".rgb"; // RGB files 160 const std::string MTP_FORMAT_XBM = ".xbm"; // XBM files 161 const std::string MTP_FORMAT_XPM = ".xpm"; // XPM files 162 const std::string MTP_FORMAT_XWD = ".xwd"; // XWD files 163 const std::string MTP_FORMAT_RMVB = ".rmvb"; // RMVB files 164 const std::string MTP_FORMAT_AXV = ".axv"; // AXV files 165 const std::string MTP_FORMAT_DL = ".dl"; // DL files 166 const std::string MTP_FORMAT_DIF = ".dif"; // DIF files 167 const std::string MTP_FORMAT_DV = ".dv"; // DV files 168 const std::string MTP_FORMAT_DLI = ".fli"; // FLI files 169 const std::string MTP_FORMAT_GL = ".gl"; // GL files 170 const std::string MTP_FORMAT_QT = ".qt"; // QT files 171 const std::string MTP_FORMAT_OGV = ".ogv"; // OGV files 172 const std::string MTP_FORMAT_MXU = ".mxu"; // MXU files 173 const std::string MTP_FORMAT_FLV = ".flv"; // FLV files 174 const std::string MTP_FORMAT_LSF = ".lsf"; // LSF files 175 const std::string MTP_FORMAT_LSX = ".lsx"; // LSX files 176 const std::string MTP_FORMAT_MNG = ".mng"; // MNG files 177 const std::string MTP_FORMAT_WM = ".wm"; // WM files 178 const std::string MTP_FORMAT_WMX = ".wmx"; // WMX files 179 const std::string MTP_FORMAT_MOVIE = ".movie"; // MOVIE files 180 const std::string MTP_FORMAT_MPV = ".mpv"; // MPV files 181 const std::string MTP_FORMAT_MPE = ".mpe"; // MPE files 182 const std::string MTP_FORMAT_WVX = ".wvx"; // WVX files 183 const std::string MTP_FORMAT_FMP4 = ".fmp4"; // FMP4 files 184 const std::string MTP_FORMAT_UNDEFINED_COLLECTION = ".undefinedcollections"; // undefined collections 185 const std::string MTP_FORMAT_ABSTRACT_MULTIMEDIA_ALBUM = ".album"; // multimedia albums 186 const std::string MTP_FORMAT_ABSTRACT_IMAGE_ALBUM = ".albumimage"; // image albums 187 const std::string MTP_FORMAT_ABSTRACT_AUDIO_ALBUM = ".albumaudio"; // audio albums 188 const std::string MTP_FORMAT_ABSTRACT_VIDEO_ALBUM = ".albumvideo"; // video albums 189 const std::string MTP_FORMAT_ABSTRACT_AUDIO_VIDEO_PLAYLIST = ""; // abstract AV playlists 190 const std::string MTP_FORMAT_ABSTRACT_CONTACT_GROUP = ""; 191 const std::string MTP_FORMAT_ABSTRACT_MESSAGE_FOLDER = ".mesfloader"; 192 const std::string MTP_FORMAT_ABSTRACT_CHAPTERED_PRODUCTION = ""; 193 const std::string MTP_FORMAT_ABSTRACT_AUDIO_PLAYLIST = ".allaudio"; // abstract audio playlists 194 const std::string MTP_FORMAT_ABSTRACT_VIDEO_PLAYLIST = ".allvideo"; // abstract video playlists 195 const std::string MTP_FORMAT_ABSTRACT_MEDIACAST = ""; // abstract mediacasts 196 const std::string MTP_FORMAT_WPL_PLAYLIST = ".wpl"; // WPL playlist files 197 const std::string MTP_FORMAT_M3U_PLAYLIST = ".m3u"; // M3u playlist files 198 const std::string MTP_FORMAT_MPL_PLAYLIST = ".mpl"; // MPL playlist files 199 const std::string MTP_FORMAT_ASX_PLAYLIST = ".asx"; // ASX playlist files 200 const std::string MTP_FORMAT_PLS_PLAYLIST = ".pls"; // PLS playlist files 201 const std::string MTP_FORMAT_UNDEFINED_DOCUMENT = ".undefineddocument"; // undefined document files 202 const std::string MTP_FORMAT_ABSTRACT_DOCUMENT = ".alldocuments"; // abstract documents 203 const std::string MTP_FORMAT_XML_DOCUMENT = ".xml"; // XML documents 204 const std::string MTP_FORMAT_MICROSOFT_WORD_DOCUMENT = ".doc"; // MS Word documents 205 const std::string MTP_FORMAT_MHT_COMPILED_HTML_DOCUMENT = ".html"; 206 const std::string MTP_FORMAT_MICROSOFT_EXCEL_SPREADSHEET = ""; // MS Excel spreadsheets 207 const std::string MTP_FORMAT_MICROSOFT_POWERPOINT_PRESENTATION = ""; // MS PowerPoint presentatiosn 208 const std::string MTP_FORMAT_UNDEFINED_MESSAGE = ""; 209 const std::string MTP_FORMAT_ABSTRACT_MESSAGE = ""; 210 const std::string MTP_FORMAT_UNDEFINED_CONTACT = ""; 211 const std::string MTP_FORMAT_ABSTRACT_CONTACT = ""; 212 const std::string MTP_FORMAT_VCARD_2 = ""; 213 214 class MtpDataUtils { 215 public: 216 static int32_t SolveHandlesFormatData(const uint16_t format, std::string &outExtension, MediaType &outMediaType); 217 static int32_t SolveSendObjectFormatData(const uint16_t format, MediaType &outMediaType); 218 static int32_t SolveSetObjectPropValueData(const std::shared_ptr<MtpOperationContext> &context, 219 std::string &outColName, std::variant<int64_t, std::string> &outColVal); 220 static void GetMediaTypeByformat(const uint16_t format, MediaType &outMediaType); 221 static void GetPropGropByMediaType(const MediaType &mediaType, std::vector<std::string> &outPropGrop); 222 static int32_t GetPropListBySet(const std::shared_ptr<MtpOperationContext> &context, 223 const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 224 std::shared_ptr<std::vector<Property>> &outProps); 225 static int32_t GetPropValueBySet(const uint32_t property, 226 const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 227 PropertyValue &outPropValue, bool isVideoOfMovingPhoto); 228 static int32_t GetMediaTypeByName(std::string &displayName, MediaType &outMediaType); 229 // MTP 230 static int32_t GetMtpPropList(const std::shared_ptr<std::unordered_map<uint32_t, std::string>> &handles, 231 const std::unordered_map<std::string, uint32_t> &pathHandles, 232 const std::shared_ptr<MtpOperationContext> &context, shared_ptr<vector<Property>> &outPropValue); 233 static int32_t GetMtpPropValue(const std::string &path, 234 const uint32_t property, const uint16_t format, PropertyValue &outPropValue); 235 static uint32_t GetMtpFormatByPath(const std::string &path, uint16_t &outFormat); 236 static std::string GetMovingOrEnditSourcePath(const std::string &path, const int32_t &subtype, 237 const std::shared_ptr<MtpOperationContext> &context); 238 private: 239 static int32_t GetPropList(const std::shared_ptr<MtpOperationContext> &context, 240 const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 241 const std::shared_ptr<UInt16List> &properties, std::shared_ptr<std::vector<Property>> &outProps); 242 static void GetFormatByPath(const std::string &path, uint16_t &outFormat); 243 static std::variant<int32_t, int64_t, std::string> ReturnError(const std::string &errMsg, 244 const ResultSetDataType &type); 245 static int32_t GetFormat(const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, uint16_t &outFormat); 246 static void GetOneRowPropList(uint32_t handle, const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 247 const std::shared_ptr<UInt16List> &properties, std::shared_ptr<std::vector<Property>> &outProps); 248 static void GetOneRowPropVal(const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 249 const uint32_t property, PropertyValue &outPropValue); 250 static void SetOneDefaultlPropList(uint32_t handle, 251 uint16_t property, std::shared_ptr<std::vector<Property>> &outProps); 252 static void SetProperty(const std::string &column, 253 const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, ResultSetDataType &type, Property &prop); 254 // MTP 255 static void GetMtpOneRowProp(const std::shared_ptr<UInt16List> &properties, const uint32_t parentId, 256 std::unordered_map<uint32_t, std::string>::iterator it, shared_ptr<vector<Property>> &outProps, 257 int32_t storageId); 258 static void SetMtpProperty(const std::string &column, const std::string &path, 259 ResultSetDataType &type, Property &prop); 260 static void SetMtpOneDefaultlPropList(uint32_t handle, 261 uint16_t property, std::shared_ptr<std::vector<Property>> &outProps, int32_t storageId); 262 static void SetPtpProperty(const std::string &column, const std::string &path, const MovingType &movingType, 263 Property &prop); 264 static void GetMovingOrEnditOneRowPropList(const shared_ptr<UInt16List> &properties, const std::string &path, 265 const std::shared_ptr<MtpOperationContext> &context, shared_ptr<vector<Property>> &outProps, 266 const MovingType &movingType); 267 static int32_t GetPropValueForVideoOfMovingPhoto(const std::string &path, 268 const uint32_t property, PropertyValue &outPropValue); 269 }; 270 } // namespace Media 271 } // namespace OHOS 272 #endif // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_DATA_UTILS_H_ 273