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 "deferred_video_job.h"
17 
18 namespace OHOS {
19 namespace CameraStandard {
20 namespace DeferredProcessing {
21 
22 
DeferredVideoWork(const DeferredVideoJobPtr & jobPtr,ExecutionMode mode,bool isCharging)23 DeferredVideoWork::DeferredVideoWork(const DeferredVideoJobPtr& jobPtr, ExecutionMode mode, bool isCharging)
24     : jobPtr_(jobPtr),
25       executionMode_(mode),
26       startTime_(GetSteadyNow()),
27       isCharging_(isCharging)
28 {
29     DP_DEBUG_LOG("entered");
30 }
31 
~DeferredVideoWork()32 DeferredVideoWork::~DeferredVideoWork()
33 {
34     DP_DEBUG_LOG("entered");
35     jobPtr_ = nullptr;
36 }
37 
DeferredVideoJob(const std::string & videoId,const sptr<IPCFileDescriptor> & srcFd,const sptr<IPCFileDescriptor> & dstFd)38 DeferredVideoJob::DeferredVideoJob(const std::string& videoId, const sptr<IPCFileDescriptor>& srcFd,
39     const sptr<IPCFileDescriptor>& dstFd)
40     : videoId_(videoId),
41       srcFd_(srcFd),
42       dstFd_(dstFd),
43       createTime_(GetSteadyNow())
44 {
45     DP_DEBUG_LOG("videoId: %{public}s, srcFd: %{public}d, dstFd: %{public}d",
46         videoId_.c_str(), srcFd_->GetFd(), dstFd_->GetFd());
47 }
48 
~DeferredVideoJob()49 DeferredVideoJob::~DeferredVideoJob()
50 {
51     DP_DEBUG_LOG("entered");
52     srcFd_ = nullptr;
53     dstFd_ = nullptr;
54 }
55 
SetJobStatus(VideoJobStatus status)56 bool DeferredVideoJob::SetJobStatus(VideoJobStatus status)
57 {
58     DP_DEBUG_LOG("videoId: %{public}s, current status: %{public}d, previous status: %{public}d, "
59         "status to set: %{public}d", videoId_.c_str(), curStatus_, preStatus_, status);
60     DP_CHECK_RETURN_RET(curStatus_ == status, false);
61 
62     preStatus_ = curStatus_;
63     curStatus_ = status;
64     return true;
65 }
66 } // namespace DeferredProcessing
67 } // namespace CameraStandard
68 } // namespace OHOS