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 #ifndef HOS_CAMERA_OFFLINE_STREAM_H
17 #define HOS_CAMERA_OFFLINE_STREAM_H
18 
19 #include "camera.h"
20 #include "offline_stream_context.h"
21 #include "v1_0/istream_operator_vdi_callback.h"
22 #include <condition_variable>
23 #include <mutex>
24 #include "capture_message.h"
25 
26 namespace OHOS::Camera {
27 using namespace OHOS::VDI::Camera::V1_0;
28 class OfflineStream {
29 public:
30     OfflineStream() = default;
31     virtual ~OfflineStream();
32     OfflineStream(int32_t id, const OHOS::sptr<IStreamOperatorVdiCallback> &callback);
33 
34     RetCode Init(std::shared_ptr<OfflineStreamContext> &context);
35     RetCode CancelCapture(int32_t captureId);
36     RetCode Release();
37     bool CheckCaptureIdExist(int32_t captureId);
38     void ReceiveOfflineBuffer(std::shared_ptr<IBuffer> &buffer);
39     int32_t GetStreamId() const;
40 
41 private:
42     RetCode ReturnBuffer(std::shared_ptr<IBuffer> &buffer);
43     void HandleMessage(MessageGroup& message);
44     void OnCaptureEnded(int32_t captureId, const std::vector<VdiCaptureEndedInfo> &infos);
45     void OnCaptureError(int32_t captureId, const std::vector<VdiCaptureErrorInfo> &infos);
46 
47 private:
48     int32_t streamId_ = -1;
49     std::shared_ptr<OfflineStreamContext> context_ = {};
50     OHOS::sptr<IStreamOperatorVdiCallback> callback_ = nullptr;
51     std::mutex lock_;
52     std::shared_ptr<CaptureMessageOperator> messenger_ = nullptr;
53 };
54 } // namespace OHOS::Camera
55 #endif
56