• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 
49 // LCOV_EXCL_START
AddVideoCommand(const int32_t userId,const std::string & videoId,const sptr<IPCFileDescriptor> & srcFd,const sptr<IPCFileDescriptor> & dstFd)50 AddVideoCommand::AddVideoCommand(const int32_t userId, const std::string& videoId,
51     const sptr<IPCFileDescriptor>& srcFd, const sptr<IPCFileDescriptor>& dstFd)
52     : VideoCommand(userId, videoId), srcFd_(srcFd), dstFd_(dstFd)
53 {
54     DP_DEBUG_LOG("AddVideoCommand, videoId: %{public}s, srcFd: %{public}d, dstFd: %{public}d",
55         videoId_.c_str(), srcFd_->GetFd(), dstFd_->GetFd());
56 }
57 
Executing()58 int32_t AddVideoCommand::Executing()
59 {
60     if (int32_t ret = Initialize() != DP_OK) {
61         return ret;
62     }
63 
64     processor_->AddVideo(videoId_, srcFd_, dstFd_);
65     return DP_OK;
66 }
67 // LCOV_EXCL_STOP
68 
RemoveVideoCommand(const int32_t userId,const std::string & videoId,const bool restorable)69 RemoveVideoCommand::RemoveVideoCommand(const int32_t userId, const std::string& videoId, const bool restorable)
70     : VideoCommand(userId, videoId), restorable_(restorable)
71 {
72     DP_DEBUG_LOG("RemoveVideoCommand, videoId: %{public}s, restorable: %{public}d", videoId_.c_str(), restorable_);
73 }
74 
Executing()75 int32_t RemoveVideoCommand::Executing()
76 {
77     if (int32_t ret = Initialize() != DP_OK) {
78         return ret;
79     }
80 
81     processor_->RemoveVideo(videoId_, restorable_);
82     return DP_OK;
83 }
84 
Executing()85 int32_t RestoreVideoCommand::Executing()
86 {
87     if (int32_t ret = Initialize() != DP_OK) {
88         return ret;
89     }
90 
91     processor_->RestoreVideo(videoId_);
92     return DP_OK;
93 }
94 } // namespace DeferredProcessing
95 } // namespace CameraStandard
96 } // namespace OHOS