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 "offline_stream_operator.h"
17 
18 namespace OHOS::Camera {
19 
OfflineStreamOperator()20 OfflineStreamOperator::OfflineStreamOperator()
21 {
22 }
23 
~OfflineStreamOperator()24 OfflineStreamOperator::~OfflineStreamOperator()
25 {
26 }
27 
Init(OfflineStreamOperatorCIF * op)28 void OfflineStreamOperator::Init(OfflineStreamOperatorCIF* op)
29 {
30     operator_ = op;
31 }
32 
CancelCapture(int captureId)33 CamRetCode OfflineStreamOperator::CancelCapture(int captureId)
34 {
35     if (operator_ == nullptr) {
36         return INSUFFICIENT_RESOURCES;
37     }
38     int ret = operator_->CancelCapture(captureId);
39 
40     return static_cast<CamRetCode>(ret);
41 }
42 
ReleaseStreams(const std::vector<int> & streamIds)43 CamRetCode OfflineStreamOperator::ReleaseStreams(const std::vector<int>& streamIds)
44 {
45     if (operator_ == nullptr) {
46         return INSUFFICIENT_RESOURCES;
47     }
48 
49     int count = streamIds.size();
50     if (count <= 0) {
51         return DEVICE_ERROR;
52     }
53     int* ids = new int[count];
54     if (ids == nullptr) {
55         return INSUFFICIENT_RESOURCES;
56     }
57 
58     int ret = operator_->ReleaseStreams(ids, count);
59 
60     if (ids != nullptr) {
61         delete [] ids;
62     }
63 
64     return static_cast<CamRetCode>(ret);
65 }
66 
Release()67 CamRetCode OfflineStreamOperator::Release()
68 {
69     if (operator_ == nullptr) {
70         return INSUFFICIENT_RESOURCES;
71     }
72 
73     int ret = operator_->Release();
74 
75     return static_cast<CamRetCode>(ret);
76 }
77 
78 } // end namespace OHOS::Camera
79