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_command.h"
17
18 #include "dps.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
23
VideoCommand(const int32_t userId,const std::string & videoId)24 VideoCommand::VideoCommand(const int32_t userId, const std::string& videoId)
25 : userId_(userId), videoId_(videoId)
26 {
27 DP_DEBUG_LOG("entered. userId: %{public}d, videoId: %{public}s", userId_, videoId_.c_str());
28 }
29
~VideoCommand()30 VideoCommand::~VideoCommand()
31 {
32 DP_DEBUG_LOG("entered.");
33 schedulerManager_ = nullptr;
34 processor_ = nullptr;
35 }
36
Initialize()37 int32_t VideoCommand::Initialize()
38 {
39 DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
40
41 schedulerManager_ = DPS_GetSchedulerManager();
42 DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager_ == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr.");
43 processor_ = schedulerManager_->GetVideoProcessor(userId_);
44 DP_CHECK_ERROR_RETURN_RET_LOG(processor_ == nullptr, DP_NULL_POINTER, "VideoProcessor is nullptr.");
45 initialized_.store(true);
46 return DP_OK;
47 }
48
AddVideoCommand(const int32_t userId,const std::string & videoId,const sptr<IPCFileDescriptor> & srcFd,const sptr<IPCFileDescriptor> & dstFd)49 AddVideoCommand::AddVideoCommand(const int32_t userId, const std::string& videoId,
50 const sptr<IPCFileDescriptor>& srcFd, const sptr<IPCFileDescriptor>& dstFd)
51 : VideoCommand(userId, videoId), srcFd_(srcFd), dstFd_(dstFd)
52 {
53 DP_DEBUG_LOG("AddVideoCommand, videoId: %{public}s, srcFd: %{public}d, dstFd: %{public}d",
54 videoId_.c_str(), srcFd_->GetFd(), dstFd_->GetFd());
55 }
56
Executing()57 int32_t AddVideoCommand::Executing()
58 {
59 if (int32_t ret = Initialize() != DP_OK) {
60 return ret;
61 }
62
63 processor_->AddVideo(videoId_, srcFd_, dstFd_);
64 return DP_OK;
65 }
66
RemoveVideoCommand(const int32_t userId,const std::string & videoId,const bool restorable)67 RemoveVideoCommand::RemoveVideoCommand(const int32_t userId, const std::string& videoId, const bool restorable)
68 : VideoCommand(userId, videoId), restorable_(restorable)
69 {
70 DP_DEBUG_LOG("RemoveVideoCommand, videoId: %{public}s, restorable: %{public}d", videoId_.c_str(), restorable_);
71 }
72
Executing()73 int32_t RemoveVideoCommand::Executing()
74 {
75 if (int32_t ret = Initialize() != DP_OK) {
76 return ret;
77 }
78
79 processor_->RemoveVideo(videoId_, restorable_);
80 return DP_OK;
81 }
82
Executing()83 int32_t RestoreCommand::Executing()
84 {
85 if (int32_t ret = Initialize() != DP_OK) {
86 return ret;
87 }
88
89 processor_->RestoreVideo(videoId_);
90 return DP_OK;
91 }
92 } // namespace DeferredProcessing
93 } // namespace CameraStandard
94 } // namespace OHOS