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_callback_proxy.h"
17 
18 namespace OHOS {
19 namespace CameraStandard {
20 namespace DeferredProcessing {
OnProcessVideoDone(const std::string & videoId,const sptr<IPCFileDescriptor> & fd)21 ErrCode DeferredVideoProcessingSessionCallbackProxy::OnProcessVideoDone(
22     const std::string& videoId, const sptr<IPCFileDescriptor>& fd)
23 {
24     MessageParcel data;
25     MessageParcel reply;
26     MessageOption option(MessageOption::TF_SYNC);
27 
28     if (!data.WriteInterfaceToken(GetDescriptor())) {
29         return ERR_INVALID_VALUE;
30     }
31 
32     if (!data.WriteString16(Str8ToStr16(videoId))) {
33         return ERR_INVALID_DATA;
34     }
35     if (!data.WriteParcelable(fd)) {
36         return ERR_INVALID_DATA;
37     }
38     sptr<IRemoteObject> remote = Remote();
39     if (remote == nullptr) {
40         return ERR_INVALID_DATA;
41     }
42 
43     int32_t result = remote->SendRequest(COMMAND_ON_PROCESS_VIDEO_DONE, data, reply, option);
44     if (FAILED(result)) {
45         return result;
46     }
47     ErrCode errCode = reply.ReadInt32();
48     if (FAILED(errCode)) {
49         return errCode;
50     }
51 
52     return ERR_OK;
53 }
54 
OnError(const std::string & videoId,int32_t errorCode)55 ErrCode DeferredVideoProcessingSessionCallbackProxy::OnError(
56     const std::string& videoId,
57     int32_t errorCode)
58 {
59     MessageParcel data;
60     MessageParcel reply;
61     MessageOption option(MessageOption::TF_SYNC);
62 
63     if (!data.WriteInterfaceToken(GetDescriptor())) {
64         return ERR_INVALID_VALUE;
65     }
66 
67     if (!data.WriteString16(Str8ToStr16(videoId))) {
68         return ERR_INVALID_DATA;
69     }
70     if (!data.WriteInt32(errorCode)) {
71         return ERR_INVALID_DATA;
72     }
73     sptr<IRemoteObject> remote = Remote();
74     if (remote == nullptr) {
75         return ERR_INVALID_DATA;
76     }
77 
78     int32_t result = remote->SendRequest(COMMAND_ON_ERROR, data, reply, option);
79     if (FAILED(result)) {
80         return result;
81     }
82     ErrCode errCode = reply.ReadInt32();
83     if (FAILED(errCode)) {
84         return errCode;
85     }
86 
87     return ERR_OK;
88 }
89 
OnStateChanged(int32_t status)90 ErrCode DeferredVideoProcessingSessionCallbackProxy::OnStateChanged(
91     int32_t status)
92 {
93     MessageParcel data;
94     MessageParcel reply;
95     MessageOption option(MessageOption::TF_SYNC);
96 
97     if (!data.WriteInterfaceToken(GetDescriptor())) {
98         return ERR_INVALID_VALUE;
99     }
100 
101     if (!data.WriteInt32(status)) {
102         return ERR_INVALID_DATA;
103     }
104     sptr<IRemoteObject> remote = Remote();
105     if (remote == nullptr) {
106         return ERR_INVALID_DATA;
107     }
108 
109     int32_t result = remote->SendRequest(COMMAND_ON_STATE_CHANGED, data, reply, option);
110     if (FAILED(result)) {
111         return result;
112     }
113     ErrCode errCode = reply.ReadInt32();
114     if (FAILED(errCode)) {
115         return errCode;
116     }
117 
118     return ERR_OK;
119 }
120 } // namespace DeferredProcessing
121 } // namespace CameraStandard
122 } // namespace OHOS
123