1 /*
2 * Copyright (c) 2023-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 #include "scheduler_manager.h"
17
18 #include "dp_utils.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
Create()23 std::shared_ptr<SchedulerManager> SchedulerManager::Create()
24 {
25 DP_DEBUG_LOG("entered.");
26 return CreateShared<SchedulerManager>();
27 }
28
SchedulerManager()29 SchedulerManager::SchedulerManager()
30 {
31 DP_DEBUG_LOG("entered.");
32 }
33
~SchedulerManager()34 SchedulerManager::~SchedulerManager()
35 {
36 DP_DEBUG_LOG("entered.");
37 photoPosts_.clear();
38 photoController_.clear();
39 photoProcessors_.clear();
40 videoPosts_.clear();
41 videoController_.clear();
42 videoProcessors_.clear();
43 }
44
Initialize()45 int32_t SchedulerManager::Initialize()
46 {
47 DP_DEBUG_LOG("entered.");
48 return DP_OK;
49 }
50
GetPhotoPostProcessor(const int32_t userId)51 std::shared_ptr<PhotoPostProcessor> SchedulerManager::GetPhotoPostProcessor(const int32_t userId)
52 {
53 DP_DEBUG_LOG("entered.");
54 auto item = photoPosts_.find(userId);
55 DP_CHECK_ERROR_RETURN_RET_LOG(item == photoPosts_.end(), nullptr,
56 "PhotoPostProcessor not found for userId: %{public}d.", userId);
57 return item->second;
58 }
59
GetPhotoProcessor(const int32_t userId)60 std::shared_ptr<DeferredPhotoProcessor> SchedulerManager::GetPhotoProcessor(const int32_t userId)
61 {
62 DP_DEBUG_LOG("entered.");
63 auto item = photoProcessors_.find(userId);
64 DP_CHECK_ERROR_RETURN_RET_LOG(item == photoProcessors_.end(), nullptr,
65 "PhotoProcessors not found for userId: %{public}d.", userId);
66 return item->second;
67 }
68
69
CreatePhotoProcessor(const int32_t userId,const std::shared_ptr<IImageProcessCallbacks> & callbacks)70 void SchedulerManager::CreatePhotoProcessor(const int32_t userId,
71 const std::shared_ptr<IImageProcessCallbacks>& callbacks)
72 {
73 DP_INFO_LOG("entered");
74 auto photoRepository = std::make_shared<PhotoJobRepository>(userId);
75 auto photoPost = CreateShared<PhotoPostProcessor>(userId);
76 auto photoProcessor = CreateShared<DeferredPhotoProcessor>(userId, photoRepository, photoPost, callbacks);
77 auto photoController = CreateShared<DeferredPhotoController>(userId, photoRepository, photoProcessor);
78 photoController->Initialize();
79 photoPosts_[userId] = photoPost;
80 photoProcessors_[userId] = photoProcessor;
81 photoController_[userId] = photoController;
82 }
83
GetVideoPostProcessor(const int32_t userId)84 std::shared_ptr<VideoPostProcessor> SchedulerManager::GetVideoPostProcessor(const int32_t userId)
85 {
86 DP_DEBUG_LOG("entered.");
87 auto it = videoPosts_.find(userId);
88 DP_CHECK_ERROR_RETURN_RET_LOG(it == videoPosts_.end(), nullptr,
89 "VideoPostProcessor not found for userId: %{public}d", userId);
90
91 return it->second;
92 }
93
GetVideoProcessor(const int32_t userId)94 std::shared_ptr<DeferredVideoProcessor> SchedulerManager::GetVideoProcessor(const int32_t userId)
95 {
96 DP_DEBUG_LOG("entered.");
97 auto it = videoProcessors_.find(userId);
98 DP_CHECK_ERROR_RETURN_RET_LOG(it == videoProcessors_.end(), nullptr,
99 "VideoProcessor not found for userId: %{public}d", userId);
100
101 return it->second;
102 }
103
GetVideoController(const int32_t userId)104 std::shared_ptr<DeferredVideoController> SchedulerManager::GetVideoController(const int32_t userId)
105 {
106 DP_DEBUG_LOG("entered.");
107 auto it = videoController_.find(userId);
108 DP_CHECK_ERROR_RETURN_RET_LOG(it == videoController_.end(), nullptr,
109 "VideoController not found for userId: %{public}d", userId);
110
111 return it->second;
112 }
113
CreateVideoProcessor(const int32_t userId,const std::shared_ptr<IVideoProcessCallbacks> & callbacks)114 void SchedulerManager::CreateVideoProcessor(const int32_t userId,
115 const std::shared_ptr<IVideoProcessCallbacks>& callbacks)
116 {
117 DP_DEBUG_LOG("entered.");
118 auto videoRepository = std::make_shared<VideoJobRepository>(userId);
119 auto videoPost = CreateShared<VideoPostProcessor>(userId);
120 auto videoProcessor = CreateShared<DeferredVideoProcessor>(videoRepository, videoPost, callbacks);
121 auto videoController = CreateShared<DeferredVideoController>(userId, videoRepository, videoProcessor);
122 videoController->Initialize();
123 videoPosts_[userId] = videoPost;
124 videoProcessors_[userId] = videoProcessor;
125 videoController_[userId] = videoController;
126 }
127 } // namespace DeferredProcessing
128 } // namespace CameraStandard
129 } // namespace OHOS