• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "hcapture_session_stub.h"
17 #include "media_log.h"
18 #include "ipc_skeleton.h"
19 #include "remote_request_code.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int HCaptureSessionStub::OnRemoteRequest(
24     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
25 {
26     int errCode = -1;
27 
28     if (data.ReadInterfaceToken() != GetDescriptor()) {
29         return errCode;
30     }
31     switch (code) {
32         case CAMERA_CAPTURE_SESSION_BEGIN_CONFIG:
33             errCode = BeginConfig();
34             break;
35         case CAMERA_CAPTURE_SESSION_ADD_INPUT:
36             errCode = HCaptureSessionStub::HandleAddInput(data);
37             break;
38         case CAMERA_CAPTURE_SESSION_ADD_OUTPUT_CAPTURE:
39             errCode = HCaptureSessionStub::HandleAddCaptureOutput(data);
40             break;
41         case CAMERA_CAPTURE_SESSION_ADD_OUTPUT_REPEAT:
42             errCode = HCaptureSessionStub::HandleAddRepeatOutput(data);
43             break;
44         case CAMERA_CAPTURE_SESSION_REMOVE_INPUT:
45             errCode = HCaptureSessionStub::HandleRemoveInput(data);
46             break;
47         case CAMERA_CAPTURE_SESSION_REMOVE_OUTPUT_CAPTURE:
48             errCode = HCaptureSessionStub::HandleRemoveCaptureOutput(data);
49             break;
50         case CAMERA_CAPTURE_SESSION_REMOVE_OUTPUT_REPEAT:
51             errCode = HCaptureSessionStub::HandleRemoveRepeatOutput(data);
52             break;
53         case CAMERA_CAPTURE_SESSION_COMMIT_CONFIG:
54             errCode = CommitConfig();
55             break;
56         case CAMERA_CAPTURE_SESSION_START:
57             errCode = Start();
58             break;
59         case CAMERA_CAPTURE_SESSION_STOP:
60             errCode = Stop();
61             break;
62         case CAMERA_CAPTURE_SESSION_RELEASE: {
63                 pid_t pid = IPCSkeleton::GetCallingPid();
64                 errCode = Release(pid);
65             }
66             break;
67         case CAMERA_CAPTURE_SESSION_SET_CALLBACK:
68             errCode = HandleSetCallback(data);
69             break;
70         default:
71             MEDIA_ERR_LOG("HCaptureSessionStub request code %{public}u not handled", code);
72             errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
73             break;
74     }
75 
76     return errCode;
77 }
78 
HandleAddInput(MessageParcel & data)79 int HCaptureSessionStub::HandleAddInput(MessageParcel &data)
80 {
81     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
82     if (remoteObj == nullptr) {
83         MEDIA_ERR_LOG("HCaptureSessionStub HandleAddInput CameraDevice is null");
84         return IPC_STUB_INVALID_DATA_ERR;
85     }
86 
87     sptr<ICameraDeviceService> cameraDevice = iface_cast<ICameraDeviceService>(remoteObj);
88 
89     return AddInput(cameraDevice);
90 }
91 
HandleRemoveInput(MessageParcel & data)92 int HCaptureSessionStub::HandleRemoveInput(MessageParcel &data)
93 {
94     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
95     if (remoteObj == nullptr) {
96         MEDIA_ERR_LOG("HCaptureSessionStub HandleRemoveInput CameraDevice is null");
97         return IPC_STUB_INVALID_DATA_ERR;
98     }
99 
100     sptr<ICameraDeviceService> cameraDevice = iface_cast<ICameraDeviceService>(remoteObj);
101 
102     return RemoveInput(cameraDevice);
103 }
104 
HandleAddCaptureOutput(MessageParcel & data)105 int HCaptureSessionStub::HandleAddCaptureOutput(MessageParcel &data)
106 {
107     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
108     if (remoteObj == nullptr) {
109         MEDIA_ERR_LOG("HCaptureSessionStub HandleAddCaptureOutput StreamCapture is null");
110         return IPC_STUB_INVALID_DATA_ERR;
111     }
112 
113     sptr<IStreamCapture> streamCapture = iface_cast<IStreamCapture>(remoteObj);
114 
115     return AddOutput(streamCapture);
116 }
117 
HandleAddRepeatOutput(MessageParcel & data)118 int HCaptureSessionStub::HandleAddRepeatOutput(MessageParcel &data)
119 {
120     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
121     if (remoteObj == nullptr) {
122         MEDIA_ERR_LOG("HCaptureSessionStub HandleAddRepeatOutput streamRepeat is null");
123         return IPC_STUB_INVALID_DATA_ERR;
124     }
125 
126     sptr<IStreamRepeat> streamRepeat = iface_cast<IStreamRepeat>(remoteObj);
127 
128     return AddOutput(streamRepeat);
129 }
130 
HandleRemoveCaptureOutput(MessageParcel & data)131 int HCaptureSessionStub::HandleRemoveCaptureOutput(MessageParcel &data)
132 {
133     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
134     if (remoteObj == nullptr) {
135         MEDIA_ERR_LOG("HCaptureSessionStub HandleRemoveCaptureOutput StreamCapture is null");
136         return IPC_STUB_INVALID_DATA_ERR;
137     }
138 
139     sptr<IStreamCapture> streamCapture = iface_cast<IStreamCapture>(remoteObj);
140 
141     return RemoveOutput(streamCapture);
142 }
143 
HandleRemoveRepeatOutput(MessageParcel & data)144 int HCaptureSessionStub::HandleRemoveRepeatOutput(MessageParcel &data)
145 {
146     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
147     if (remoteObj == nullptr) {
148         MEDIA_ERR_LOG("HCaptureSessionStub HandleRemoveRepeatOutput streamRepeat is null");
149         return IPC_STUB_INVALID_DATA_ERR;
150     }
151 
152     sptr<IStreamRepeat> streamRepeat = iface_cast<IStreamRepeat>(remoteObj);
153 
154     return RemoveOutput(streamRepeat);
155 }
156 
HandleSetCallback(MessageParcel & data)157 int HCaptureSessionStub::HandleSetCallback(MessageParcel &data)
158 {
159     auto remoteObject = data.ReadRemoteObject();
160     if (remoteObject == nullptr) {
161         MEDIA_ERR_LOG("HCaptureSessionStub HandleSetCallback CaptureSessionCallback is null");
162         return IPC_STUB_INVALID_DATA_ERR;
163     }
164 
165     auto callback = iface_cast<ICaptureSessionCallback>(remoteObject);
166 
167     return SetCallback(callback);
168 }
169 } // namespace CameraStandard
170 } // namespace OHOS
171