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 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 29 namespace OHOS { 30 namespace DistributedHardware { 31 class DCameraSinkDataProcess : public ICameraSinkDataProcess, 32 public std::enable_shared_from_this<DCameraSinkDataProcess> { 33 public: 34 DCameraSinkDataProcess(const std::string& dhId, std::shared_ptr<ICameraChannel>& channel); 35 ~DCameraSinkDataProcess(); 36 37 int32_t StartCapture(std::shared_ptr<DCameraCaptureInfo>& captureInfo) override; 38 int32_t StopCapture() override; 39 int32_t FeedStream(std::shared_ptr<DataBuffer>& dataBuffer) override; 40 void Init() override; 41 42 void OnProcessedVideoBuffer(const std::shared_ptr<DataBuffer>& videoResult); 43 void OnError(DataProcessErrorType errorType); 44 45 int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; 46 47 private: 48 int32_t FeedStreamInner(std::shared_ptr<DataBuffer>& dataBuffer); 49 VideoCodecType GetPipelineCodecType(DCEncodeType encodeType); 50 Videoformat GetPipelineFormat(int32_t format); 51 void StartEventHandler(); 52 void SendDataAsync(const std::shared_ptr<DataBuffer>& buffer); 53 54 std::string dhId_; 55 std::shared_ptr<DCameraCaptureInfo> captureInfo_; 56 std::shared_ptr<ICameraChannel> channel_; 57 std::shared_ptr<IDataProcessPipeline> pipeline_; 58 59 std::mutex eventMutex_; 60 std::thread eventThread_; 61 std::condition_variable eventCon_; 62 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 63 }; 64 } // namespace DistributedHardware 65 } // namespace OHOS 66 #endif // OHOS_DCAMERA_SINK_DATA_PROCESS_H