• 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 "hstream_capture_callback_proxy.h"
17 #include "camera_log.h"
18 #include "remote_request_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(CAMERA_STREAM_CAPTURE_ON_CAPTURE_STARTED, data, reply, option);
40     if (error != ERR_NONE) {
41         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureStarted failed, error: %{public}d", error);
42     }
43 
44     return error;
45 }
46 
OnCaptureEnded(int32_t captureId,int32_t frameCount)47 int32_t HStreamCaptureCallbackProxy::OnCaptureEnded(int32_t captureId, int32_t frameCount)
48 {
49     MessageParcel data;
50     MessageParcel reply;
51     MessageOption option;
52 
53     if (!data.WriteInterfaceToken(GetDescriptor())) {
54         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded Write interface token failed");
55         return IPC_PROXY_ERR;
56     }
57     if (!data.WriteInt32(captureId)) {
58         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded Write captureId failed");
59         return IPC_PROXY_ERR;
60     }
61     if (!data.WriteInt32(frameCount)) {
62         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded Write frameCount failed");
63         return IPC_PROXY_ERR;
64     }
65     int error = Remote()->SendRequest(CAMERA_STREAM_CAPTURE_ON_CAPTURE_ENDED, data, reply, option);
66     if (error != ERR_NONE) {
67         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureEnded failed, error: %{public}d", error);
68     }
69 
70     return error;
71 }
72 
OnCaptureError(int32_t captureId,int32_t errorCode)73 int32_t HStreamCaptureCallbackProxy::OnCaptureError(int32_t captureId, int32_t errorCode)
74 {
75     MessageParcel data;
76     MessageParcel reply;
77     MessageOption option;
78 
79     if (!data.WriteInterfaceToken(GetDescriptor())) {
80         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError Write interface token failed");
81         return IPC_PROXY_ERR;
82     }
83     if (!data.WriteInt32(captureId)) {
84         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError Write captureId failed");
85         return IPC_PROXY_ERR;
86     }
87     if (!data.WriteInt32(errorCode)) {
88         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError Write errorType failed");
89         return IPC_PROXY_ERR;
90     }
91 
92     int error = Remote()->SendRequest(CAMERA_STREAM_CAPTURE_ON_CAPTURE_ERROR, data, reply, option);
93     if (error != ERR_NONE) {
94         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnCaptureError failed, error: %{public}d", error);
95     }
96 
97     return error;
98 }
99 
OnFrameShutter(int32_t captureId,uint64_t timestamp)100 int32_t HStreamCaptureCallbackProxy::OnFrameShutter(int32_t captureId, uint64_t timestamp)
101 {
102     MessageParcel data;
103     MessageParcel reply;
104     MessageOption option;
105 
106     if (!data.WriteInterfaceToken(GetDescriptor())) {
107         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter Write interface token failed");
108         return IPC_PROXY_ERR;
109     }
110     if (!data.WriteInt32(captureId)) {
111         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter Write captureId failed");
112         return IPC_PROXY_ERR;
113     }
114     if (!data.WriteUint64(timestamp)) {
115         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter Write errorType failed");
116         return IPC_PROXY_ERR;
117     }
118 
119     int error = Remote()->SendRequest(CAMERA_STREAM_CAPTURE_ON_FRAME_SHUTTER, data, reply, option);
120     if (error != ERR_NONE) {
121         MEDIA_ERR_LOG("HStreamCaptureCallbackProxy OnFrameShutter failed, error: %{public}d", error);
122     }
123 
124     return error;
125 }
126 } // namespace CameraStandard
127 } // namespace OHOS