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 namespace OHOS {
22 namespace Media {
23 constexpr int32_t DEFAULT_YEAR_SIZE = 64;
24 constexpr int32_t DEFAULT_MTH_SIZE = 128;
25 constexpr int32_t DEFAULT_THUMB_SIZE = 256;
26 constexpr int32_t DEFAULT_LCD_SIZE = 1080;
27
28 enum class ThumbnailType : int32_t {
29 LCD,
30 THUMB,
31 MTH,
32 YEAR,
33 };
34
35 constexpr uint32_t DEVICE_UDID_LENGTH = 65;
36
37 constexpr int32_t THUMBNAIL_LCD_GENERATE_THRESHOLD = 5000;
38 constexpr int32_t THUMBNAIL_LCD_AGING_THRESHOLD = 10000;
39 constexpr int32_t WAIT_FOR_MS = 1000;
40 constexpr int32_t WAIT_FOR_SECOND = 3;
41
42 const std::string THUMBNAIL_LCD_SUFFIX = "LCD"; // The size fit to screen
43 const std::string THUMBNAIL_THUMB_SUFFIX = "THM"; // The size which height is 256 and width is 256
44 const std::string THUMBNAIL_MTH_SUFFIX = "MTH"; // The size which height is 128 and width is 128
45 const std::string THUMBNAIL_YEAR_SUFFIX = "YEAR"; // The size which height is 64 and width is 64
46
47 const std::string FILE_URI_PREX = "file://";
48
49 const std::string THUMBNAIL_FORMAT = "image/jpeg";
50 constexpr uint8_t THUMBNAIL_QUALITY = 80;
51
52 constexpr uint32_t THUMBNAIL_QUERY_MAX = 2000;
53 constexpr int64_t AV_FRAME_TIME = 0;
54
55 constexpr uint8_t NUMBER_HINT_1 = 1;
56
57 const std::string THUMBNAIL_OPERN_KEYWORD = "operation";
58 const std::string THUMBNAIL_HEIGHT = "height";
59 const std::string THUMBNAIL_WIDTH = "width";
60 const std::string THUMBNAIL_PATH = "path";
61
62 // create thumbnail in close operation
63 const std::string CLOSE_CREATE_THUMB_STATUS = "create_thumbnail_sync_status";
64 const int32_t CREATE_THUMB_SYNC_STATUS = 1;
65 const int32_t CREATE_THUMB_ASYNC_STATUS = 0;
66
GetThumbnailPath(const std::string & path,const std::string & key)67 static inline std::string GetThumbnailPath(const std::string &path, const std::string &key)
68 {
69 if (path.length() < ROOT_MEDIA_DIR.length()) {
70 return "";
71 }
72 return ROOT_MEDIA_DIR + ".thumbs/" + path.substr(ROOT_MEDIA_DIR.length()) + "/" + key + ".jpg";
73 }
74
GetSandboxPath(const std::string & path,bool isThumb)75 static inline std::string GetSandboxPath(const std::string &path, bool isThumb)
76 {
77 if (path.length() < ROOT_MEDIA_DIR.length()) {
78 return "";
79 }
80 std::string suffixStr = path.substr(ROOT_MEDIA_DIR.length()) + (isThumb ? "/THM.jpg" : "/LCD.jpg");
81 return ROOT_SANDBOX_DIR + ".thumbs/" + suffixStr;
82 }
83
IsThumbnail(const int32_t width,const int32_t height)84 static inline bool IsThumbnail(const int32_t width, const int32_t height)
85 {
86 return (width <= DEFAULT_THUMB_SIZE) && (height <= DEFAULT_THUMB_SIZE);
87 }
88
89 } // namespace Media
90 } // namespace OHOS
91
92 #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
93