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_processing_session_proxy.h"
17 
18 namespace OHOS {
19 namespace CameraStandard {
20 namespace DeferredProcessing {
BeginSynchronize()21 ErrCode DeferredVideoProcessingSessionProxy::BeginSynchronize()
22 {
23     MessageParcel data;
24     MessageParcel reply;
25     MessageOption option(MessageOption::TF_SYNC);
26 
27     if (!data.WriteInterfaceToken(GetDescriptor())) {
28         return ERR_INVALID_VALUE;
29     }
30 
31     sptr<IRemoteObject> remote = Remote();
32     if (remote == nullptr) {
33         return ERR_INVALID_DATA;
34     }
35 
36     int32_t result = remote->SendRequest(COMMAND_BEGIN_SYNCHRONIZE, data, reply, option);
37     if (FAILED(result)) {
38         return result;
39     }
40     ErrCode errCode = reply.ReadInt32();
41     if (FAILED(errCode)) {
42         return errCode;
43     }
44 
45     return ERR_OK;
46 }
47 
EndSynchronize()48 ErrCode DeferredVideoProcessingSessionProxy::EndSynchronize()
49 {
50     MessageParcel data;
51     MessageParcel reply;
52     MessageOption option(MessageOption::TF_SYNC);
53 
54     if (!data.WriteInterfaceToken(GetDescriptor())) {
55         return ERR_INVALID_VALUE;
56     }
57 
58     sptr<IRemoteObject> remote = Remote();
59     if (remote == nullptr) {
60         return ERR_INVALID_DATA;
61     }
62 
63     int32_t result = remote->SendRequest(COMMAND_END_SYNCHRONIZE, data, reply, option);
64     if (FAILED(result)) {
65         return result;
66     }
67     ErrCode errCode = reply.ReadInt32();
68     if (FAILED(errCode)) {
69         return errCode;
70     }
71 
72     return ERR_OK;
73 }
74 
AddVideo(const std::string & videoId,const sptr<IPCFileDescriptor> & srcFd,const sptr<IPCFileDescriptor> & dstFd)75 ErrCode DeferredVideoProcessingSessionProxy::AddVideo(
76     const std::string& videoId,
77     const sptr<IPCFileDescriptor>& srcFd,
78     const sptr<IPCFileDescriptor>& dstFd)
79 {
80     MessageParcel data;
81     MessageParcel reply;
82     MessageOption option(MessageOption::TF_SYNC);
83 
84     if (!data.WriteInterfaceToken(GetDescriptor())) {
85         return ERR_INVALID_VALUE;
86     }
87 
88     if (!data.WriteString16(Str8ToStr16(videoId))) {
89         return ERR_INVALID_DATA;
90     }
91     if (!data.WriteParcelable(srcFd)) {
92         return ERR_INVALID_DATA;
93     }
94     if (!data.WriteParcelable(dstFd)) {
95         return ERR_INVALID_DATA;
96     }
97     sptr<IRemoteObject> remote = Remote();
98     if (remote == nullptr) {
99         return ERR_INVALID_DATA;
100     }
101 
102     int32_t result = remote->SendRequest(COMMAND_ADD_VIDEO, data, reply, option);
103     if (FAILED(result)) {
104         return result;
105     }
106     ErrCode errCode = reply.ReadInt32();
107     if (FAILED(errCode)) {
108         return errCode;
109     }
110 
111     return ERR_OK;
112 }
113 
RemoveVideo(const std::string & videoId,bool restorable)114 ErrCode DeferredVideoProcessingSessionProxy::RemoveVideo(
115     const std::string& videoId,
116     bool restorable)
117 {
118     MessageParcel data;
119     MessageParcel reply;
120     MessageOption option(MessageOption::TF_SYNC);
121 
122     if (!data.WriteInterfaceToken(GetDescriptor())) {
123         return ERR_INVALID_VALUE;
124     }
125 
126     if (!data.WriteString16(Str8ToStr16(videoId))) {
127         return ERR_INVALID_DATA;
128     }
129     if (!data.WriteInt32(restorable ? 1 : 0)) {
130         return ERR_INVALID_DATA;
131     }
132     sptr<IRemoteObject> remote = Remote();
133     if (remote == nullptr) {
134         return ERR_INVALID_DATA;
135     }
136 
137     int32_t result = remote->SendRequest(COMMAND_REMOVE_VIDEO, data, reply, option);
138     if (FAILED(result)) {
139         return result;
140     }
141     ErrCode errCode = reply.ReadInt32();
142     if (FAILED(errCode)) {
143         return errCode;
144     }
145 
146     return ERR_OK;
147 }
148 
RestoreVideo(const std::string & videoId)149 ErrCode DeferredVideoProcessingSessionProxy::RestoreVideo(
150     const std::string& videoId)
151 {
152     MessageParcel data;
153     MessageParcel reply;
154     MessageOption option(MessageOption::TF_SYNC);
155 
156     if (!data.WriteInterfaceToken(GetDescriptor())) {
157         return ERR_INVALID_VALUE;
158     }
159 
160     if (!data.WriteString16(Str8ToStr16(videoId))) {
161         return ERR_INVALID_DATA;
162     }
163     sptr<IRemoteObject> remote = Remote();
164     if (remote == nullptr) {
165         return ERR_INVALID_DATA;
166     }
167 
168     int32_t result = remote->SendRequest(COMMAND_RESTORE_VIDEO, data, reply, option);
169     if (FAILED(result)) {
170         return result;
171     }
172     ErrCode errCode = reply.ReadInt32();
173     if (FAILED(errCode)) {
174         return errCode;
175     }
176 
177     return ERR_OK;
178 }
179 } // namespace DeferredProcessing
180 } // namespace CameraStandard
181 } // namespace OHOS
182