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