• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_MANAGER_H
17 #define FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_MANAGER_H
18 
19 #include <mutex>
20 #include <string>
21 #include <unordered_map>
22 
23 namespace OHOS {
24 namespace Media {
25 #define EXPORT __attribute__ ((visibility ("default")))
26 
27 constexpr int32_t TYPE_MANUAL_ENHANCEMENT = 0;
28 constexpr int32_t TYPE_AUTO_ENHANCEMENT_FOREGROUND = 1;
29 constexpr int32_t TYPE_AUTO_ENHANCEMENT_BACKGROUND = 2;
30 
31 struct EnhancementTaskInfo {
32     std::string taskId;
33     int32_t fileId;
34     int32_t requestCount;
35     int32_t taskType;
EnhancementTaskInfoEnhancementTaskInfo36     EnhancementTaskInfo() : taskId(""), fileId(0), requestCount(0), taskType(0) {}
EnhancementTaskInfoEnhancementTaskInfo37     EnhancementTaskInfo(std::string taskId, int32_t fileId, int32_t count, int32_t taskType)
38         : taskId(taskId), fileId(fileId), requestCount(count), taskType(taskType) {}
39 };
40 
41 class EnhancementTaskManager {
42 public:
43     EXPORT static void AddEnhancementTask(int32_t fileId, const std::string &photoId,
44         int32_t taskType);
45     EXPORT static void RemoveEnhancementTask(const std::string &photoId);
46     EXPORT static void RemoveAllEnhancementTask(std::vector<std::string> &taskIds);
47     EXPORT static bool InProcessingTask(const std::string &photoId);
48     EXPORT static std::string QueryPhotoIdByFileId(int32_t fileId);
49     EXPORT static int32_t QueryTaskTypeByPhotoId(const std::string &photoId);
50     EXPORT static void SetTaskRequestCount(const std::string &photoId, int32_t count);
51     EXPORT static int32_t GetTaskRequestCount(const std::string &photoId);
52 
53 private:
54     // key: photo_id
55     EXPORT static std::unordered_map<std::string, std::shared_ptr<EnhancementTaskInfo>> taskInProcess_;
56     EXPORT static std::unordered_map<int32_t, std::string> fileId2PhotoId_;
57 
58     static std::mutex mutex_;
59 };
60 } // namespace Media
61 } // namespace OHOS
62 #endif // FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_MANAGER_H