1 /*
2  * Copyright (c) 2021-2024 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 OHOS_DCAMERA_SINK_DATA_PROCESS_H
17 #define OHOS_DCAMERA_SINK_DATA_PROCESS_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <thread>
22 
23 #include "event_handler.h"
24 #include "icamera_channel.h"
25 #include "icamera_sink_data_process.h"
26 #include "idata_process_pipeline.h"
27 #include "image_common_type.h"
28 #include "dcamera_utils_tools.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class DCameraSinkDataProcess : public ICameraSinkDataProcess,
33     public std::enable_shared_from_this<DCameraSinkDataProcess> {
34 public:
35     DCameraSinkDataProcess(const std::string& dhId, std::shared_ptr<ICameraChannel>& channel);
36     ~DCameraSinkDataProcess();
37 
38     int32_t StartCapture(std::shared_ptr<DCameraCaptureInfo>& captureInfo) override;
39     int32_t StopCapture() override;
40     int32_t FeedStream(std::shared_ptr<DataBuffer>& dataBuffer) override;
41     void Init() override;
42 
43     void OnProcessedVideoBuffer(const std::shared_ptr<DataBuffer>& videoResult);
44     void OnError(DataProcessErrorType errorType);
45 
46     int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override;
47 
48 private:
49     int32_t FeedStreamInner(std::shared_ptr<DataBuffer>& dataBuffer);
50     VideoCodecType GetPipelineCodecType(DCEncodeType encodeType);
51     Videoformat GetPipelineFormat(int32_t format);
52     void StartEventHandler();
53     void SendDataAsync(const std::shared_ptr<DataBuffer>& buffer);
54 
55     std::string dhId_;
56     std::shared_ptr<DCameraCaptureInfo> captureInfo_;
57     std::shared_ptr<ICameraChannel> channel_;
58     std::shared_ptr<IDataProcessPipeline> pipeline_;
59 
60     std::mutex eventMutex_;
61     std::thread eventThread_;
62     std::condition_variable eventCon_;
63     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
64     FILE *dumpFile_ = nullptr;
65 };
66 } // namespace DistributedHardware
67 } // namespace OHOS
68 #endif // OHOS_DCAMERA_SINK_DATA_PROCESS_H