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