• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "stream_operator_callback_proxy.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include <message_parcel.h>
20 
21 namespace OHOS::Camera {
OnCaptureStarted(int32_t captureId,const std::vector<int32_t> & streamId)22 void StreamOperatorCallbackProxy::OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId)
23 {
24     MessageParcel data;
25     MessageParcel reply;
26     MessageOption option;
27 
28     if (!data.WriteInterfaceToken(StreamOperatorCallbackProxy::GetDescriptor())) {
29         HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
30         return;
31     }
32 
33     if (!data.WriteInt32(captureId)) {
34         HDF_LOGE("%{public}s: write captureId failed.", __func__);
35         return;
36     }
37 
38     if (!data.WriteInt32Vector(streamId)) {
39         HDF_LOGE("%{public}s: write streamIds failed.", __func__);
40         return;
41     }
42 
43     int32_t ret = Remote()->SendRequest(
44         CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_STARTED, data, reply, option);
45     if (ret != HDF_SUCCESS) {
46         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
47         return;
48     }
49 }
50 
OnCaptureEnded(int32_t captureId,const std::vector<std::shared_ptr<CaptureEndedInfo>> & info)51 void StreamOperatorCallbackProxy::OnCaptureEnded(int32_t captureId,
52     const std::vector<std::shared_ptr<CaptureEndedInfo>> &info)
53 {
54     MessageParcel data;
55     MessageParcel reply;
56     MessageOption option;
57 
58     if (!data.WriteInterfaceToken(StreamOperatorCallbackProxy::GetDescriptor())) {
59         HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
60         return;
61     }
62 
63     if (!data.WriteInt32(captureId)) {
64         HDF_LOGE("%{public}s: write captureId failed.", __func__);
65         return;
66     }
67 
68     size_t size = info.size();
69     if (!data.WriteInt32(static_cast<int32_t>(size))) {
70         HDF_LOGE("%{public}s: write info size failed.", __func__);
71         return;
72     }
73     for (size_t i = 0; i < size; i++) {
74         auto captureEndInfo = info.at(i);
75         bool bRet = data.WriteBuffer((void*)captureEndInfo.get(), sizeof(CaptureEndedInfo));
76         if (!bRet) {
77             HDF_LOGE("%{public}s: write info index = %d failed.", __func__, i);
78             return;
79         }
80     }
81 
82     int32_t ret = Remote()->SendRequest(
83         CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_ENDED, data, reply, option);
84     if (ret != HDF_SUCCESS) {
85         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
86         return;
87     }
88 }
89 
OnCaptureError(int32_t captureId,const std::vector<std::shared_ptr<CaptureErrorInfo>> & info)90 void StreamOperatorCallbackProxy::OnCaptureError(int32_t captureId,
91     const std::vector<std::shared_ptr<CaptureErrorInfo>> &info)
92 {
93     MessageParcel data;
94     MessageParcel reply;
95     MessageOption option;
96 
97     if (!data.WriteInterfaceToken(StreamOperatorCallbackProxy::GetDescriptor())) {
98         HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
99         return;
100     }
101 
102     if (!data.WriteInt32(captureId)) {
103         HDF_LOGE("%{public}s: write captureId failed.", __func__);
104         return;
105     }
106 
107     size_t size = info.size();
108     if (!data.WriteInt32(static_cast<int32_t>(size))) {
109         HDF_LOGE("%{public}s: write info size failed.", __func__);
110         return;
111     }
112     for (size_t i = 0; i < size; i++) {
113         auto captureErrorInfo = info.at(i);
114         bool bRet = data.WriteBuffer((void*)captureErrorInfo.get(), sizeof(CaptureErrorInfo));
115         if (!bRet) {
116             HDF_LOGE("%{public}s: write info index = %d failed.", __func__, i);
117             return;
118         }
119     }
120 
121     int32_t ret = Remote()->SendRequest(
122         CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_ERROR, data, reply, option);
123     if (ret != HDF_SUCCESS) {
124         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
125         return;
126     }
127 }
128 
OnFrameShutter(int32_t captureId,const std::vector<int32_t> & streamId,uint64_t timestamp)129 void StreamOperatorCallbackProxy::OnFrameShutter(int32_t captureId,
130     const std::vector<int32_t> &streamId, uint64_t timestamp)
131 {
132     MessageParcel data;
133     MessageParcel reply;
134     MessageOption option;
135     HDF_LOGV("%{public}s: enter OnFrameShutter Callback", __func__);
136 
137     if (!data.WriteInterfaceToken(StreamOperatorCallbackProxy::GetDescriptor())) {
138         HDF_LOGE("%{public}s: write interface descriptor failed.", __func__);
139         return;
140     }
141 
142     if (!data.WriteInt32(captureId)) {
143         HDF_LOGE("%{public}s: write captureId failed.", __func__);
144         return;
145     }
146 
147     if (!data.WriteInt32Vector(streamId)) {
148         HDF_LOGE("%{public}s: write streamId failed.", __func__);
149         return;
150     }
151 
152     if (!data.WriteUint64(timestamp)) {
153         HDF_LOGE("%{public}s: write streamId failed.", __func__);
154         return;
155     }
156 
157     int32_t ret = Remote()->SendRequest(
158         CMD_STREAM_OPERATOR_CALLBACK_ON_FRAME_SHUTTER, data, reply, option);
159     if (ret != HDF_SUCCESS) {
160         HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
161         return;
162     }
163 }
164 }