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     option.SetFlags(option.TF_ASYNC);
31 
32     data.WriteInterfaceToken(GetDescriptor());
33     data.WriteInt32(captureId);
34     int error = Remote()->SendRequest(
35         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_STARTED),
36         data, reply, option);
37     if (error != ERR_NONE) {
38         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureStarted failed, error: %{public}d", error);
39     }
40 
41     return error;
42 }
43 
OnCaptureStarted(int32_t captureId,uint32_t exposureTime)44 int32_t HStreamCaptureCallbackProxy::OnCaptureStarted(int32_t captureId, uint32_t exposureTime)
45 {
46     MessageParcel data;
47     MessageParcel reply;
48     MessageOption option;
49     option.SetFlags(option.TF_ASYNC);
50 
51     data.WriteInterfaceToken(GetDescriptor());
52     data.WriteInt32(captureId);
53     data.WriteUint32(exposureTime);
54     int error = Remote()->SendRequest(
55         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_STARTED_V1_2),
56         data, reply, option);
57     if (error != ERR_NONE) {
58         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureStarted failed, error: %{public}d", error);
59     }
60 
61     return error;
62 }
63 
OnCaptureEnded(int32_t captureId,int32_t frameCount)64 int32_t HStreamCaptureCallbackProxy::OnCaptureEnded(int32_t captureId, int32_t frameCount)
65 {
66     MessageParcel data;
67     MessageParcel reply;
68     MessageOption option;
69     option.SetFlags(option.TF_ASYNC);
70 
71     data.WriteInterfaceToken(GetDescriptor());
72     data.WriteInt32(captureId);
73     data.WriteInt32(frameCount);
74     int error = Remote()->SendRequest(
75         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_ENDED),
76         data, reply, option);
77     if (error != ERR_NONE) {
78         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded failed, error: %{public}d", error);
79     }
80 
81     return error;
82 }
83 
OnCaptureError(int32_t captureId,int32_t errorCode)84 int32_t HStreamCaptureCallbackProxy::OnCaptureError(int32_t captureId, int32_t errorCode)
85 {
86     MessageParcel data;
87     MessageParcel reply;
88     MessageOption option;
89     option.SetFlags(option.TF_ASYNC);
90 
91     data.WriteInterfaceToken(GetDescriptor());
92     data.WriteInt32(captureId);
93     data.WriteInt32(errorCode);
94 
95     int error = Remote()->SendRequest(
96         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_ERROR),
97         data, reply, option);
98     if (error != ERR_NONE) {
99         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError failed, error: %{public}d", error);
100     }
101 
102     return error;
103 }
104 
OnFrameShutter(int32_t captureId,uint64_t timestamp)105 int32_t HStreamCaptureCallbackProxy::OnFrameShutter(int32_t captureId, uint64_t timestamp)
106 {
107     MessageParcel data;
108     MessageParcel reply;
109     MessageOption option;
110     option.SetFlags(option.TF_ASYNC);
111 
112     data.WriteInterfaceToken(GetDescriptor());
113     data.WriteInt32(captureId);
114     data.WriteUint64(timestamp);
115 
116     int error = Remote()->SendRequest(
117         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_FRAME_SHUTTER),
118         data, reply, option);
119     if (error != ERR_NONE) {
120         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter failed, error: %{public}d", error);
121     }
122 
123     return error;
124 }
125 
OnFrameShutterEnd(int32_t captureId,uint64_t timestamp)126 int32_t HStreamCaptureCallbackProxy::OnFrameShutterEnd(int32_t captureId, uint64_t timestamp)
127 {
128     MessageParcel data;
129     MessageParcel reply;
130     MessageOption option;
131     option.SetFlags(option.TF_ASYNC);
132 
133     data.WriteInterfaceToken(GetDescriptor());
134     data.WriteInt32(captureId);
135     data.WriteUint64(timestamp);
136 
137     int error = Remote()->SendRequest(
138         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_FRAME_SHUTTER_END),
139         data, reply, option);
140     if (error != ERR_NONE) {
141         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutterEnd failed, error: %{public}d", error);
142     }
143     return error;
144 }
145 
OnCaptureReady(int32_t captureId,uint64_t timestamp)146 int32_t HStreamCaptureCallbackProxy::OnCaptureReady(int32_t captureId, uint64_t timestamp)
147 {
148     MessageParcel data;
149     MessageParcel reply;
150     MessageOption option;
151     option.SetFlags(option.TF_ASYNC);
152 
153     data.WriteInterfaceToken(GetDescriptor());
154     data.WriteInt32(captureId);
155     data.WriteUint64(timestamp);
156 
157     int error = Remote()->SendRequest(
158         static_cast<uint32_t>(StreamCaptureCallbackInterfaceCode::CAMERA_STREAM_CAPTURE_ON_CAPTURE_READY),
159         data, reply, option);
160     if (error != ERR_NONE) {
161         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureReady failed, error: %{public}d", error);
162     }
163     return error;
164 }
165 } // namespace CameraStandard
166 } // namespace OHOS