• 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_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         it->streamId_ = info[i].streamId;
51         it->frameCount_ = info[i].frameCount;
52         ends.push_back(it);
53     }
54 
55     g_streamCallback->OnCaptureEnded(captureId, ends);
56 
57     return;
58 }
59 
StreamCBOnCaptureError(int captureId,CaptureErrorInfoCIF * info,int count)60 void StreamCBOnCaptureError(int captureId, CaptureErrorInfoCIF* info, int count)
61 {
62     if (g_streamCallback == nullptr) {
63         return;
64     }
65 
66     std::vector<std::shared_ptr<OHOS::Camera::CaptureErrorInfo>> errors = {};
67     for (int i = 0; i < count; i++) {
68         std::shared_ptr<OHOS::Camera::CaptureErrorInfo> it = std::make_shared<OHOS::Camera::CaptureErrorInfo>();
69         it->streamId_ = info[i].streamId;
70         it->error_ = static_cast<OHOS::Camera::StreamError>(info[i].error);
71         errors.push_back(it);
72     }
73 
74     g_streamCallback->OnCaptureError(captureId, errors);
75 
76     return;
77 }
78 
StreamCBOnFrameShutter(int captureId,const int * streamId,int count,uint64_t timestamp)79 void StreamCBOnFrameShutter(int captureId, const int* streamId, int count, uint64_t timestamp)
80 {
81     if (g_streamCallback == nullptr) {
82         return;
83     }
84 
85     if (streamId == nullptr) {
86         return;
87     }
88 
89     std::vector<int> ids = {};
90     for (int i = 0; i < count; i++) {
91         ids.push_back(streamId[i]);
92     }
93     g_streamCallback->OnFrameShutter(captureId, ids, timestamp);
94 
95     return;
96 }
97 
98 #ifdef __cplusplus
99 }
100 #endif
101