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
16 #ifndef FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
18
19 #include "medialibrary_db_const.h"
20
21 #include <unordered_map>
22 #include <unordered_set>
23
24 namespace OHOS {
25 namespace Media {
26 constexpr int32_t THUMBNAIL_VERSION = 0;
27 constexpr int32_t DEFAULT_YEAR_SIZE = 64;
28 constexpr int32_t DEFAULT_MTH_SIZE = 128;
29 constexpr int32_t DEFAULT_THUMB_SIZE = 256;
30 constexpr int32_t MAX_DEFAULT_THUMB_SIZE = 768;
31 constexpr int32_t DEFAULT_LCD_SIZE = 1080;
32 constexpr uint32_t INT32_MAX_VALUE_LENGTH = 10;
33 constexpr int32_t VERTICAL_ANGLE = 90;
34 constexpr int32_t STRAIGHT_ANGLE = 180;
35 constexpr int32_t STAMP_PARAM = 4;
36 constexpr int32_t STAMP_PARAM_ZERO = 0;
37 constexpr int32_t STAMP_PARAM_ONE = 1;
38 constexpr int32_t STAMP_PARAM_TWO = 2;
39 constexpr int32_t STAMP_PARAM_THREE = 3;
40 enum class ThumbnailType : int32_t {
41 NOT_DEFINED = -1,
42 LCD,
43 THUMB,
44 MTH,
45 YEAR,
46 THUMB_ASTC,
47 MTH_ASTC,
48 YEAR_ASTC,
49 LCD_EX,
50 THUMB_EX,
51 };
52
53 enum class GenerateScene : int32_t {
54 LOCAL = 0,
55 CLOUD,
56 BACKGROUND,
57 FOREGROUND,
58 RESTORE,
59 UPGRADE,
60 REPAIR,
61 };
62
63 enum class LoadSourceType : int32_t {
64 LOCAL_PHOTO = 0,
65 CLOUD_THUMB,
66 CLOUD_LCD,
67 CLOUD_PHOTO,
68 };
69
70 enum class ThumbnailReady : int32_t {
71 GENERATE_THUMB_LATER,
72 GENERATE_THUMB_NOW,
73 GENERATE_THUMB_RETRY,
74 GENERATE_THUMB_COMPLETED,
75 THUMB_TO_UPLOAD,
76 THUMB_UPLOAD_COMPLETED,
77 THUMB_UPGRADE,
78 };
79
80 enum class LcdReady : int64_t {
81 GENERATE_LCD_LATER,
82 GENERATE_LCD_FAILED,
83 GENERATE_LCD_COMPLETED,
84 };
85
86 const std::unordered_map<ThumbnailType, std::string> TYPE_NAME_MAP = {
87 { ThumbnailType::LCD, "LCD" },
88 { ThumbnailType::THUMB, "THUMB" },
89 { ThumbnailType::MTH, "MTH" },
90 { ThumbnailType::YEAR, "YEAR" },
91 { ThumbnailType::THUMB_ASTC, "THUMB_ASTC" },
92 { ThumbnailType::MTH_ASTC, "MTH_ASTC" },
93 { ThumbnailType::YEAR_ASTC, "YEAR_ASTC" },
94 };
95
96 enum class ThumbnailQuality : uint8_t {
97 ASTC_LOW_QUALITY = 20,
98 POOR = 50,
99 NOT_BAD = 60,
100 MID = 70,
101 GOOD = 80,
102 DEFAULT = 90,
103 HIGH = 100,
104 };
105
106 constexpr uint32_t DEVICE_UDID_LENGTH = 65;
107
108 constexpr int32_t THUMBNAIL_LCD_GENERATE_THRESHOLD = 5000;
109 constexpr int32_t THUMBNAIL_LCD_AGING_THRESHOLD = 10000;
110 constexpr int32_t WAIT_FOR_MS = 1000;
111 constexpr int32_t WAIT_FOR_SECOND = 3;
112
113 constexpr float EPSILON = 1e-6;
114 constexpr int32_t MONTH_SHORT_SIDE_THRESHOLD = 128;
115 constexpr int32_t SHORT_SIDE_THRESHOLD = 350;
116 constexpr int32_t MAXIMUM_SHORT_SIDE_THRESHOLD = 1050;
117 constexpr int32_t LCD_SHORT_SIDE_THRESHOLD = 512;
118 constexpr int32_t LCD_LONG_SIDE_THRESHOLD = 1920;
119 constexpr int32_t MAXIMUM_LCD_LONG_SIDE = 4096;
120 constexpr int32_t ASPECT_RATIO_THRESHOLD = 3;
121 constexpr int32_t MIN_COMPRESS_BUF_SIZE = 8192;
122 constexpr int32_t DECODE_SCALE_BASE = 2;
123 constexpr int32_t FLAT_ANGLE = 180;
124 constexpr int32_t THUMBNAIL_GENERATE_BATCH_COUNT = 200;
125 constexpr int32_t ASTC_GENERATE_COUNT_AFTER_RESTORE = 2000;
126 constexpr int32_t READY_TEMPERATURE_LEVEL = 4;
127 constexpr int32_t EVEN_BASE_NUMBER = 2;
128 constexpr int32_t LOCAL_GENERATION_BATTERY_CAPACITY = 10;
129 const std::string DEFAULT_EXIF_ORIENTATION = "1";
130
131 const std::string THUMBNAIL_LCD_SUFFIX = "LCD"; // The size fit to screen
132 const std::string THUMBNAIL_THUMB_SUFFIX = "THM"; // The size which height is 256 and width is 256
133 const std::string THUMBNAIL_THUMB_ASTC_SUFFIX = "THM_ASTC";
134 const std::string THUMBNAIL_MTH_SUFFIX = "MTH"; // The size which height is 128 and width is 128
135 const std::string THUMBNAIL_YEAR_SUFFIX = "YEAR"; // The size which height is 64 and width is 64
136 const std::string THUMBNAIL_LCD_EX_SUFFIX = "THM_EX/LCD";
137 const std::string THUMBNAIL_THUMB_EX_SUFFIX = "THM_EX/THM";
138
139 const std::string FILE_URI_PREX = "file://";
140 const std::string LOCAL_MEDIA_PREFIX = "/storage/media/local/files/";
141
142 const std::string PHOTO_URI_PREFIX = "file://media/Photo/";
143
144 const std::string THUMBNAIL_FORMAT = "image/jpeg";
145 const std::string THUMBASTC_FORMAT = "image/astc/4*4";
146
147 constexpr uint32_t THUMBNAIL_QUERY_MAX = 2000;
148 constexpr uint32_t THUMBNAIL_QUERY_MIN = 200;
149 constexpr int64_t AV_FRAME_TIME = 0;
150 constexpr int64_t MS_TRANSFER_US = 1000;
151
152 constexpr uint8_t NUMBER_HINT_1 = 1;
153
154 constexpr int32_t DEFAULT_ORIGINAL = -1;
155
156 const std::string DYNAMIC_RANGE = "decodeDynamicRange";
157
158 const std::string THUMBNAIL_OPERN_KEYWORD = "operation";
159 const std::string THUMBNAIL_OPER = "oper";
160 const std::string THUMBNAIL_HEIGHT = "height";
161 const std::string THUMBNAIL_WIDTH = "width";
162 const std::string THUMBNAIL_PATH = "path";
163 const std::string THUMBNAIL_BEGIN_STAMP = "begin_stamp";
164 const std::string THUMBNAIL_TYPE = "type";
165 const std::string THUMBNAIL_USER = "user";
166
167 // create thumbnail in close operation
168 const std::string CLOSE_CREATE_THUMB_STATUS = "create_thumbnail_sync_status";
169 const int32_t CREATE_THUMB_SYNC_STATUS = 1;
170 const int32_t CREATE_THUMB_ASYNC_STATUS = 0;
171
172 constexpr float FLOAT_EPSILON = 1e-6;
173
174 // request photo type
175 const std::string REQUEST_PHOTO_TYPE = "requestPhotoType";
176
177 const int32_t CLOUD_PHOTO_POSITION = 2;
178 const int32_t CLOUD_THUMB_STATUS_DOWNLOAD = 0;
179 const int32_t CLOUD_THUMBNAIL_DOWNLOAD_FINISH_NUMBER = 1000;
180 const std::string RDB_QUERY_COUNT = "count";
181
182 const int32_t THUMBNAIL_READY_FAILED = 2;
183
184 const int32_t THUMBNAIL_FREE_SIZE_LIMIT_1 = 1;
185 const int32_t THUMBNAIL_FREE_SIZE_LIMIT_10 = 10;
186
187 // LCD that is over 2MB would not be uploaded
188 const size_t LCD_UPLOAD_LIMIT_SIZE = 2048000;
189
190 // Only check the latest 3000 data to avoid opreation taking too long time
191 const uint32_t MAXIMUM_LCD_CHECK_NUM = 3000;
192
193 const std::unordered_set<ThumbnailQuality> THUMBNAIL_QUALITY_SET = {
194 ThumbnailQuality::POOR,
195 ThumbnailQuality::NOT_BAD,
196 ThumbnailQuality::MID,
197 ThumbnailQuality::GOOD,
198 ThumbnailQuality::DEFAULT,
199 ThumbnailQuality::HIGH,
200 };
201
GetThumbnailPath(const std::string & path,const std::string & key)202 static inline std::string GetThumbnailPath(const std::string &path, const std::string &key)
203 {
204 if (path.length() < ROOT_MEDIA_DIR.length()) {
205 return "";
206 }
207 std::string suffix = (key == "THM_ASTC") ? ".astc" : ".jpg";
208 return ROOT_MEDIA_DIR + ".thumbs/" + path.substr(ROOT_MEDIA_DIR.length()) + "/" + key + suffix;
209 }
210
GetThumbnailPathHighlight(const std::string & path,const std::string & key,const std::string & timeStamp)211 static inline std::string GetThumbnailPathHighlight(const std::string &path, const std::string &key,
212 const std::string &timeStamp)
213 {
214 if (path.length() < ROOT_MEDIA_DIR.length()) {
215 return "";
216 }
217 std::string suffix = (key == "THM_ASTC") ? ".astc" : ".jpg";
218 return ROOT_MEDIA_DIR + ".thumbs/" + path.substr(ROOT_MEDIA_DIR.length()) +
219 "/beginTimeStamp" + timeStamp + "/" + key + suffix;
220 }
221
GetThumbSuffix(ThumbnailType type)222 static std::string GetThumbSuffix(ThumbnailType type)
223 {
224 switch (type) {
225 case ThumbnailType::MTH:
226 return THUMBNAIL_MTH_SUFFIX;
227 case ThumbnailType::YEAR:
228 return THUMBNAIL_YEAR_SUFFIX;
229 case ThumbnailType::THUMB:
230 return THUMBNAIL_THUMB_SUFFIX;
231 case ThumbnailType::THUMB_ASTC:
232 return THUMBNAIL_THUMB_ASTC_SUFFIX;
233 case ThumbnailType::LCD:
234 return THUMBNAIL_LCD_SUFFIX;
235 default:
236 return "";
237 }
238 }
239
GetKeyFrameThumbSuffix(int32_t type)240 static std::string GetKeyFrameThumbSuffix(int32_t type)
241 {
242 switch (type) {
243 case KEY_FRAME_LCD:
244 return THUMBNAIL_LCD_SUFFIX;
245 case KEY_FRAME_THM:
246 return THUMBNAIL_THUMB_SUFFIX;
247 case KEY_FRAME_THM_ASTC:
248 return THUMBNAIL_THUMB_ASTC_SUFFIX;
249 default:
250 return "";
251 }
252 }
253
254 static inline ThumbnailType GetThumbType(const int32_t width, const int32_t height, bool isAstc = false)
255 {
256 if (width == DEFAULT_ORIGINAL && height == DEFAULT_ORIGINAL) {
257 return ThumbnailType::LCD;
258 }
259
260 if (std::min(width, height) <= DEFAULT_THUMB_SIZE &&
261 std::max(width, height) <= MAX_DEFAULT_THUMB_SIZE) {
262 return isAstc ? ThumbnailType::THUMB_ASTC : ThumbnailType::THUMB;
263 }
264
265 return ThumbnailType::LCD;
266 }
267
GetSandboxPath(const std::string & path,ThumbnailType type)268 static inline std::string GetSandboxPath(const std::string &path, ThumbnailType type)
269 {
270 if (path.length() < ROOT_MEDIA_DIR.length()) {
271 return "";
272 }
273 std::string suffix = (type == ThumbnailType::THUMB_ASTC) ? ".astc" : ".jpg";
274 std::string suffixStr = path.substr(ROOT_MEDIA_DIR.length()) + "/" + GetThumbSuffix(type) + suffix;
275 return ROOT_SANDBOX_DIR + ".thumbs/" + suffixStr;
276 }
277
GetKeyFrameSandboxPath(const std::string & path,const int32_t & beginStamp,const int32_t & type)278 static inline std::string GetKeyFrameSandboxPath(const std::string &path, const int32_t &beginStamp,
279 const int32_t &type)
280 {
281 if (path.length() < ROOT_MEDIA_DIR.length()) {
282 return "";
283 }
284 std::string suffix = (type == KEY_FRAME_THM_ASTC) ? ".astc" : ".jpg";
285 std::string suffixStr = path.substr(ROOT_MEDIA_DIR.length()) + "/beginTimeStamp" + std::to_string(beginStamp) +
286 "/" + GetKeyFrameThumbSuffix(type) + suffix;
287 return ROOT_MEDIA_DIR + ".thumbs/" + suffixStr;
288 }
289
IsThumbnail(const int32_t width,const int32_t height)290 static inline bool IsThumbnail(const int32_t width, const int32_t height)
291 {
292 if (width == DEFAULT_ORIGINAL && height == DEFAULT_ORIGINAL) {
293 return false;
294 }
295 return std::min(width, height) <= DEFAULT_THUMB_SIZE &&
296 std::max(width, height) <= MAX_DEFAULT_THUMB_SIZE;
297 }
298
299 } // namespace Media
300 } // namespace OHOS
301
302 #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
303