• 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 "deferred_video_processing_session.h"
17 
18 #include "dps_video_report.h"
19 #include "dps.h"
20 #include "video_command.h"
21 #include "sync_command.h"
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 namespace DeferredProcessing {
DeferredVideoProcessingSession(const int32_t userId)26 DeferredVideoProcessingSession::DeferredVideoProcessingSession(const int32_t userId)
27     : userId_(userId)
28 {
29     DP_DEBUG_LOG("entered. userId: %{public}d", userId_);
30 }
31 
~DeferredVideoProcessingSession()32 DeferredVideoProcessingSession::~DeferredVideoProcessingSession()
33 {
34     DP_DEBUG_LOG("entered.");
35     videoIds_.clear();
36 }
37 
BeginSynchronize()38 int32_t DeferredVideoProcessingSession::BeginSynchronize()
39 {
40     std::lock_guard<std::mutex> lock(mutex_);
41     DP_INFO_LOG("DPS_VIDEO: BeginSynchronize.");
42     inSync_.store(true);
43     return DP_OK;
44 }
45 
EndSynchronize()46 int32_t DeferredVideoProcessingSession::EndSynchronize()
47 {
48     std::lock_guard<std::mutex> lock(mutex_);
49     if (inSync_.load()) {
50         DP_INFO_LOG("DPS_VIDEO: EndSynchronize video job num: %{public}d", static_cast<int32_t>(videoIds_.size()));
51         auto ret = DPS_SendCommand<VideoSyncCommand>(userId_, videoIds_);
52         inSync_.store(false);
53         videoIds_.clear();
54         DP_CHECK_ERROR_RETURN_RET_LOG(ret != DP_OK, ret, "video synchronize failed, ret: %{public}d", ret);
55     }
56     return DP_OK;
57 }
58 
AddVideo(const std::string & videoId,const sptr<IPCFileDescriptor> & srcFd,const sptr<IPCFileDescriptor> & dstFd)59 int32_t DeferredVideoProcessingSession::AddVideo(const std::string& videoId,
60     const sptr<IPCFileDescriptor>& srcFd, const sptr<IPCFileDescriptor>& dstFd)
61 {
62     auto infd = sptr<IPCFileDescriptor>::MakeSptr(dup(srcFd->GetFd()));
63     auto outFd = sptr<IPCFileDescriptor>::MakeSptr(dup(dstFd->GetFd()));
64     fdsan_exchange_owner_tag(infd->GetFd(), 0, LOG_DOMAIN);
65     fdsan_exchange_owner_tag(outFd->GetFd(), 0, LOG_DOMAIN);
66     if (inSync_.load()) {
67         std::lock_guard<std::mutex> lock(mutex_);
68         DP_INFO_LOG("AddVideo error, inSync!");
69         auto info = std::make_shared<VideoInfo>(infd, outFd);
70         videoIds_.emplace(videoId, info);
71         return DP_OK;
72     }
73 
74     auto ret = DPS_SendCommand<AddVideoCommand>(userId_, videoId, infd, outFd);
75     DP_INFO_LOG("DPS_VIDEO: AddVideo videoId: %{public}s, ret: %{public}d", videoId.c_str(), ret);
76     DfxVideoReport::GetInstance().ReportAddVideoEvent(videoId, GetDpsCallerInfo());
77     return ret;
78 }
79 
RemoveVideo(const std::string & videoId,bool restorable)80 int32_t DeferredVideoProcessingSession::RemoveVideo(const std::string& videoId, bool restorable)
81 {
82     DP_CHECK_RETURN_RET_LOG(inSync_.load(), DP_OK, "RemoveVideo error, inSync!");
83 
84     auto ret = DPS_SendCommand<RemoveVideoCommand>(userId_, videoId, restorable);
85     DP_INFO_LOG("DPS_VIDEO: RemoveVideo videoId: %{public}s, ret: %{public}d", videoId.c_str(), ret);
86     DfxVideoReport::GetInstance().ReportRemoveVideoEvent(videoId, GetDpsCallerInfo());
87     return ret;
88 }
89 
RestoreVideo(const std::string & videoId)90 int32_t DeferredVideoProcessingSession::RestoreVideo(const std::string& videoId)
91 {
92     DP_CHECK_RETURN_RET_LOG(inSync_.load(), DP_OK, "RestoreVideo error, inSync!");
93 
94     auto ret = DPS_SendCommand<RestoreVideoCommand>(userId_, videoId);
95     DP_INFO_LOG("DPS_VIDEO: RestoreVideo videoId: %{public}s, ret: %{public}d", videoId.c_str(), ret);
96     return ret;
97 }
98 
99 } // namespace DeferredProcessing
100 } // namespace CameraStandard
101 } // namespace OHOS