1 /*
2 * Copyright (c) 2024-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 "photo_process_command.h"
17
18 #include "basic_definitions.h"
19 #include "dp_utils.h"
20 #include "dps.h"
21 #include <utility>
22
23 namespace OHOS {
24 namespace CameraStandard {
25 namespace DeferredProcessing {
PhotoProcessCommand(const int32_t userId)26 PhotoProcessCommand::PhotoProcessCommand(const int32_t userId) : userId_(userId)
27 {
28 DP_DEBUG_LOG("entered. userId: %{public}d", userId_);
29 }
30
~PhotoProcessCommand()31 PhotoProcessCommand::~PhotoProcessCommand()
32 {
33 DP_DEBUG_LOG("entered.");
34 }
35
Initialize()36 int32_t PhotoProcessCommand::Initialize()
37 {
38 DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
39 auto schedulerManager = DPS_GetSchedulerManager();
40 DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr.");
41
42 postProcessor_ = schedulerManager->GetPhotoPostProcessor(userId_);
43 DP_CHECK_ERROR_RETURN_RET_LOG(postProcessor_ == nullptr, DP_NULL_POINTER, "PhotoPostProcessor is nullptr.");
44
45 initialized_.store(true);
46 return DP_OK;
47 }
48
PhotoProcessSuccessCommand(const int32_t userId,const std::string & imageId,const std::shared_ptr<BufferInfo> & bufferInfo)49 PhotoProcessSuccessCommand::PhotoProcessSuccessCommand(const int32_t userId, const std::string& imageId,
50 const std::shared_ptr<BufferInfo>& bufferInfo)
51 : PhotoProcessCommand(userId), imageId_(imageId), bufferInfo_(bufferInfo)
52 {
53 DP_DEBUG_LOG("entered.");
54 }
55
Executing()56 int32_t PhotoProcessSuccessCommand::Executing()
57 {
58 if (int32_t ret = Initialize() != DP_OK) {
59 return ret;
60 }
61
62 postProcessor_->OnProcessDone(imageId_, bufferInfo_);
63 return DP_OK;
64 }
65
PhotoProcessSuccessExtCommand(const int32_t userId,const std::string & imageId,const std::shared_ptr<BufferInfoExt> & bufferInfo)66 PhotoProcessSuccessExtCommand::PhotoProcessSuccessExtCommand(const int32_t userId, const std::string& imageId,
67 const std::shared_ptr<BufferInfoExt>& bufferInfo)
68 : PhotoProcessCommand(userId), imageId_(imageId), bufferInfo_(bufferInfo)
69 {
70 DP_DEBUG_LOG("entered.");
71 }
72
Executing()73 int32_t PhotoProcessSuccessExtCommand::Executing()
74 {
75 if (int32_t ret = Initialize() != DP_OK) {
76 return ret;
77 }
78
79 postProcessor_->OnProcessDoneExt(imageId_, bufferInfo_);
80 return DP_OK;
81 }
82
PhotoProcessFailedCommand(const int32_t userId,const std::string & imageId,DpsError errorCode)83 PhotoProcessFailedCommand::PhotoProcessFailedCommand(const int32_t userId,
84 const std::string& imageId, DpsError errorCode)
85 : PhotoProcessCommand(userId), imageId_(imageId), error_(errorCode)
86 {
87 DP_DEBUG_LOG("entered.");
88 }
89
Executing()90 int32_t PhotoProcessFailedCommand::Executing()
91 {
92 if (int32_t ret = Initialize() != DP_OK) {
93 return ret;
94 }
95
96 postProcessor_->OnError(imageId_, error_);
97 return DP_OK;
98 }
99
Executing()100 int32_t PhotoStateChangedCommand::Executing()
101 {
102 postProcessor_->OnStateChanged(status_);
103 return DP_OK;
104 }
105 } // namespace DeferredProcessing
106 } // namespace CameraStandard
107 } // namespace OHOS