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_stub.h"
17
18 namespace OHOS {
19 namespace CameraStandard {
20 namespace DeferredProcessing {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)21 int32_t DeferredVideoProcessingSessionStub::OnRemoteRequest(
22 uint32_t code,
23 MessageParcel& data,
24 MessageParcel& reply,
25 MessageOption& option)
26 {
27 std::u16string localDescriptor = GetDescriptor();
28 std::u16string remoteDescriptor = data.ReadInterfaceToken();
29 if (localDescriptor != remoteDescriptor) {
30 return ERR_TRANSACTION_FAILED;
31 }
32 switch (code) {
33 case COMMAND_BEGIN_SYNCHRONIZE: {
34 ErrCode errCode = BeginSynchronize();
35 if (!reply.WriteInt32(errCode)) {
36 return ERR_INVALID_VALUE;
37 }
38 return ERR_NONE;
39 }
40 case COMMAND_END_SYNCHRONIZE: {
41 ErrCode errCode = EndSynchronize();
42 if (!reply.WriteInt32(errCode)) {
43 return ERR_INVALID_VALUE;
44 }
45 return ERR_NONE;
46 }
47 case COMMAND_ADD_VIDEO: {
48 std::string videoId = Str16ToStr8(data.ReadString16());
49 sptr<IPCFileDescriptor> srcFd(data.ReadParcelable<IPCFileDescriptor>());
50
51 if (!srcFd) {
52 return ERR_INVALID_DATA;
53 }
54 sptr<IPCFileDescriptor> dstFd(data.ReadParcelable<IPCFileDescriptor>());
55
56 if (!dstFd) {
57 return ERR_INVALID_DATA;
58 }
59 ErrCode errCode = AddVideo(videoId, srcFd, dstFd);
60 if (!reply.WriteInt32(errCode)) {
61 return ERR_INVALID_VALUE;
62 }
63 return ERR_NONE;
64 }
65 case COMMAND_REMOVE_VIDEO: {
66 std::string videoId = Str16ToStr8(data.ReadString16());
67 bool restorable = data.ReadInt32() == 1 ? true : false;
68 ErrCode errCode = RemoveVideo(videoId, restorable);
69 if (!reply.WriteInt32(errCode)) {
70 return ERR_INVALID_VALUE;
71 }
72 return ERR_NONE;
73 }
74 case COMMAND_RESTORE_VIDEO: {
75 std::string videoId = Str16ToStr8(data.ReadString16());
76 ErrCode errCode = RestoreVideo(videoId);
77 if (!reply.WriteInt32(errCode)) {
78 return ERR_INVALID_VALUE;
79 }
80 return ERR_NONE;
81 }
82 default:
83 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
84 }
85
86 return ERR_TRANSACTION_FAILED;
87 }
88 } // namespace DeferredProcessing
89 } // namespace CameraStandard
90 } // namespace OHOS
91