1 /*
2  * Copyright (c) 2023-2023 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 "video_process_command.h"
17 
18 #include "basic_definitions.h"
19 #include "dp_utils.h"
20 #include "dps.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 namespace DeferredProcessing {
VideoProcessCommand(const int32_t userId)25 VideoProcessCommand::VideoProcessCommand(const int32_t userId) : userId_(userId)
26 {
27     DP_DEBUG_LOG("entered. userId: %{public}d", userId_);
28 }
29 
~VideoProcessCommand()30 VideoProcessCommand::~VideoProcessCommand()
31 {
32     DP_DEBUG_LOG("entered.");
33     schedulerManager_ = nullptr;
34     controller_ = nullptr;
35 }
36 
Initialize()37 int32_t VideoProcessCommand::Initialize()
38 {
39     DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
40     schedulerManager_ = DPS_GetSchedulerManager();
41     DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager_ == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr.");
42 
43     controller_ = schedulerManager_->GetVideoController(userId_);
44     DP_CHECK_ERROR_RETURN_RET_LOG(controller_ == nullptr, DP_NULL_POINTER, "VideoController is nullptr.");
45     initialized_.store(true);
46     return DP_OK;
47 }
48 
VideoProcessSuccessCommand(const int32_t userId,const DeferredVideoWorkPtr & work)49 VideoProcessSuccessCommand::VideoProcessSuccessCommand(const int32_t userId, const DeferredVideoWorkPtr& work)
50     : VideoProcessCommand(userId),
51       work_(work)
52 {
53     DP_DEBUG_LOG("entered.");
54 }
55 
~VideoProcessSuccessCommand()56 VideoProcessSuccessCommand::~VideoProcessSuccessCommand()
57 {
58     DP_DEBUG_LOG("entered.");
59     work_ = nullptr;
60 }
61 
Executing()62 int32_t VideoProcessSuccessCommand::Executing()
63 {
64     if (int32_t ret = Initialize() != DP_OK) {
65         return ret;
66     }
67 
68     controller_->HandleSuccess(userId_, work_);
69     return DP_OK;
70 }
71 
VideoProcessFailedCommand(const int32_t userId,const DeferredVideoWorkPtr & work,DpsError errorCode)72 VideoProcessFailedCommand::VideoProcessFailedCommand(const int32_t userId,
73     const DeferredVideoWorkPtr& work, DpsError errorCode)
74     : VideoProcessCommand(userId),
75       work_(work),
76       error_(errorCode)
77 {
78     DP_DEBUG_LOG("entered.");
79 }
80 
~VideoProcessFailedCommand()81 VideoProcessFailedCommand::~VideoProcessFailedCommand()
82 {
83     DP_DEBUG_LOG("entered.");
84     work_ = nullptr;
85 }
86 
Executing()87 int32_t VideoProcessFailedCommand::Executing()
88 {
89     if (int32_t ret = Initialize() != DP_OK) {
90         return ret;
91     }
92 
93     controller_->HandleError(userId_, work_, error_);
94     return DP_OK;
95 }
96 
Executing()97 int32_t VideoStateChangedCommand::Executing()
98 {
99     return DP_OK;
100 }
101 } // namespace DeferredProcessing
102 } // namespace CameraStandard
103 } // namespace OHOS