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_wrapper.h"
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 static OHOS::sptr<OHOS::Camera::IStreamOperatorCallback> g_streamCallback;
22
BindStreamOperatorCallback(const OHOS::sptr<OHOS::Camera::IStreamOperatorCallback> & callback)23 void BindStreamOperatorCallback(const OHOS::sptr<OHOS::Camera::IStreamOperatorCallback>& callback)
24 {
25 g_streamCallback = callback;
26 }
27
StreamCBOnCaptureStarted(int captureId,const int * streamId,int count)28 void StreamCBOnCaptureStarted(int captureId, const int* streamId, int count)
29 {
30 if (g_streamCallback == nullptr) {
31 return;
32 }
33 std::vector<int> ids = {};
34 for (int i = 0; i < count; i++) {
35 ids.push_back(streamId[i]);
36 }
37
38 g_streamCallback->OnCaptureStarted(captureId, ids);
39 }
40
StreamCBOnCaptureEnded(int captureId,CaptureEndedInfoCIF * info,int count)41 void StreamCBOnCaptureEnded(int captureId, CaptureEndedInfoCIF* info, int count)
42 {
43 if (g_streamCallback == nullptr) {
44 return;
45 }
46
47 std::vector<std::shared_ptr<OHOS::Camera::CaptureEndedInfo>> ends;
48 for (int i = 0; i < count; i++) {
49 std::shared_ptr<OHOS::Camera::CaptureEndedInfo> it = std::make_shared<OHOS::Camera::CaptureEndedInfo>();
50 if (it == nullptr) {
51 CAMERA_LOGE("it is nullptr captureId: %{public}d streamId: %{public}d", captureId, info[i].streamId);
52 continue;
53 }
54 it->streamId_ = info[i].streamId;
55 it->frameCount_ = info[i].frameCount;
56 ends.push_back(it);
57 }
58
59 g_streamCallback->OnCaptureEnded(captureId, ends);
60
61 return;
62 }
63
StreamCBOnCaptureError(int captureId,CaptureErrorInfoCIF * info,int count)64 void StreamCBOnCaptureError(int captureId, CaptureErrorInfoCIF* info, int count)
65 {
66 if (g_streamCallback == nullptr) {
67 return;
68 }
69
70 std::vector<std::shared_ptr<OHOS::Camera::CaptureErrorInfo>> errors = {};
71 for (int i = 0; i < count; i++) {
72 std::shared_ptr<OHOS::Camera::CaptureErrorInfo> it = std::make_shared<OHOS::Camera::CaptureErrorInfo>();
73 if (it == nullptr) {
74 CAMERA_LOGE("it is nullptr captureId: %{public}d streamId: %{public}d", captureId, info[i].streamId);
75 continue;
76 }
77 it->streamId_ = info[i].streamId;
78 it->error_ = static_cast<OHOS::Camera::StreamError>(info[i].error);
79 errors.push_back(it);
80 }
81
82 g_streamCallback->OnCaptureError(captureId, errors);
83
84 return;
85 }
86
StreamCBOnFrameShutter(int captureId,const int * streamId,int count,uint64_t timestamp)87 void StreamCBOnFrameShutter(int captureId, const int* streamId, int count, uint64_t timestamp)
88 {
89 if (g_streamCallback == nullptr) {
90 return;
91 }
92
93 if (streamId == nullptr) {
94 return;
95 }
96
97 std::vector<int> ids = {};
98 for (int i = 0; i < count; i++) {
99 ids.push_back(streamId[i]);
100 }
101 g_streamCallback->OnFrameShutter(captureId, ids, timestamp);
102
103 return;
104 }
105
106 #ifdef __cplusplus
107 }
108 #endif
109