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_PIPELINE_MANAGER_H
17 #define HOS_CAMERA_OFFLINE_PIPELINE_MANAGER_H
18 
19 #include "camera.h"
20 #include "istream_pipeline_core.h"
21 #include "offline_pipeline.h"
22 #include <functional>
23 #include <list>
24 #include <memory>
25 #include <mutex>
26 
27 namespace OHOS::Camera {
28 class OfflinePipelineManager {
29 public:
30     static OfflinePipelineManager& GetInstance();
31     RetCode SwitchToOfflinePipeline(int32_t streamId,
32                                     int32_t streamType,
33                                     const std::shared_ptr<IStreamPipelineCore>& pipeline,
34                                     std::function<void(std::shared_ptr<IBuffer>&)> callback);
35     RetCode CancelCapture(int32_t streamId, int32_t captureId);
36     RetCode DestoryOfflinePipeline(int32_t id);
37     RetCode DestoryOfflinePipelines();
38     bool CheckCaptureIdExist(int32_t id, int32_t captureId);
39 
40 private:
41     OfflinePipelineManager() = default;
42     OfflinePipelineManager(const OfflinePipelineManager&);
43     OfflinePipelineManager& operator=(const OfflinePipelineManager&);
44     OfflinePipelineManager(OfflinePipelineManager&&);
45     OfflinePipelineManager& operator=(OfflinePipelineManager&&);
46     ~OfflinePipelineManager();
47 
48     std::shared_ptr<OfflinePipeline> GetOfflinePipeline(int32_t streamId,
49                                                         const std::shared_ptr<IStreamPipelineCore>& pipeline);
50     std::shared_ptr<OfflinePipeline> FindOfflinePipeline(int32_t id);
51 
52 private:
53     std::mutex lock_;
54     std::list<std::pair<int32_t, std::shared_ptr<OfflinePipeline>>> offlinePipelineList_ = {};
55 };
56 } // namespace OHOS::Camera
57 #endif
58 
59