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