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 "hstream_capture_callback_proxy.h"
17 #include "camera_log.h"
18 #include "camera_service_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
HStreamCaptureCallbackProxy(const sptr<IRemoteObject> & impl)22 HStreamCaptureCallbackProxy::HStreamCaptureCallbackProxy(const sptr<IRemoteObject> &impl)
23 : IRemoteProxy<IStreamCaptureCallback>(impl) { }
24
OnCaptureStarted(int32_t captureId)25 int32_t HStreamCaptureCallbackProxy::OnCaptureStarted(int32_t captureId)
26 {
27 MessageParcel data;
28 MessageParcel reply;
29 MessageOption option;
30
31 if (!data.WriteInterfaceToken(GetDescriptor())) {
32 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureStarted Write interface token failed");
33 return IPC_PROXY_ERR;
34 }
35 if (!data.WriteInt32(captureId)) {
36 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureStarted Write captureId failed");
37 return IPC_PROXY_ERR;
38 }
39 int error = Remote()->SendRequest(
40 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_STARTED),
41 data, reply, option);
42 if (error != ERR_NONE) {
43 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureStarted failed, error: %{public}d", error);
44 }
45
46 return error;
47 }
48
OnCaptureEnded(int32_t captureId,int32_t frameCount)49 int32_t HStreamCaptureCallbackProxy::OnCaptureEnded(int32_t captureId, int32_t frameCount)
50 {
51 MessageParcel data;
52 MessageParcel reply;
53 MessageOption option;
54
55 if (!data.WriteInterfaceToken(GetDescriptor())) {
56 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded Write interface token failed");
57 return IPC_PROXY_ERR;
58 }
59 if (!data.WriteInt32(captureId)) {
60 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded Write captureId failed");
61 return IPC_PROXY_ERR;
62 }
63 if (!data.WriteInt32(frameCount)) {
64 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded Write frameCount failed");
65 return IPC_PROXY_ERR;
66 }
67 int error = Remote()->SendRequest(
68 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_ENDED),
69 data, reply, option);
70 if (error != ERR_NONE) {
71 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded failed, error: %{public}d", error);
72 }
73
74 return error;
75 }
76
OnCaptureError(int32_t captureId,int32_t errorCode)77 int32_t HStreamCaptureCallbackProxy::OnCaptureError(int32_t captureId, int32_t errorCode)
78 {
79 MessageParcel data;
80 MessageParcel reply;
81 MessageOption option;
82
83 if (!data.WriteInterfaceToken(GetDescriptor())) {
84 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError Write interface token failed");
85 return IPC_PROXY_ERR;
86 }
87 if (!data.WriteInt32(captureId)) {
88 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError Write captureId failed");
89 return IPC_PROXY_ERR;
90 }
91 if (!data.WriteInt32(errorCode)) {
92 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError Write errorType failed");
93 return IPC_PROXY_ERR;
94 }
95
96 int error = Remote()->SendRequest(
97 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_ERROR),
98 data, reply, option);
99 if (error != ERR_NONE) {
100 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError failed, error: %{public}d", error);
101 }
102
103 return error;
104 }
105
OnFrameShutter(int32_t captureId,uint64_t timestamp)106 int32_t HStreamCaptureCallbackProxy::OnFrameShutter(int32_t captureId, uint64_t timestamp)
107 {
108 MessageParcel data;
109 MessageParcel reply;
110 MessageOption option;
111
112 if (!data.WriteInterfaceToken(GetDescriptor())) {
113 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter Write interface token failed");
114 return IPC_PROXY_ERR;
115 }
116 if (!data.WriteInt32(captureId)) {
117 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter Write captureId failed");
118 return IPC_PROXY_ERR;
119 }
120 if (!data.WriteUint64(timestamp)) {
121 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter Write errorType failed");
122 return IPC_PROXY_ERR;
123 }
124
125 int error = Remote()->SendRequest(
126 static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_FRAME_SHUTTER),
127 data, reply, option);
128 if (error != ERR_NONE) {
129 MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter failed, error: %{public}d", error);
130 }
131
132 return error;
133 }
134 } // namespace CameraStandard
135 } // namespace OHOS