1 /* 2 * Copyright (c) 2022-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_PIPELINE_SOURCE_H 17 #define OHOS_DCAMERA_PIPELINE_SOURCE_H 18 19 #include <memory> 20 #include <vector> 21 #include "event_handler.h" 22 23 #include "data_buffer.h" 24 #include "image_common_type.h" 25 #include "distributed_camera_errno.h" 26 #include "dcamera_pipeline_event.h" 27 #include "idata_process_pipeline.h" 28 #include "abstract_data_process.h" 29 #include "data_process_listener.h" 30 31 namespace OHOS { 32 namespace DistributedHardware { 33 class DecodeDataProcess; 34 35 class DCameraPipelineSource : public IDataProcessPipeline, public std::enable_shared_from_this<DCameraPipelineSource> { 36 public: 37 ~DCameraPipelineSource() override; 38 39 int32_t CreateDataProcessPipeline(PipelineType piplineType, const VideoConfigParams& sourceConfig, 40 const VideoConfigParams& targetConfig, const std::shared_ptr<DataProcessListener>& listener) override; 41 int32_t ProcessData(std::vector<std::shared_ptr<DataBuffer>>& dataBuffers) override; 42 void DestroyDataProcessPipeline() override; 43 44 void OnError(DataProcessErrorType errorType); 45 void OnProcessedVideoBuffer(const std::shared_ptr<DataBuffer>& videoResult); 46 47 int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; 48 49 private: 50 bool IsInRange(const VideoConfigParams& curConfig); 51 void InitDCameraPipEvent(); 52 int32_t InitDCameraPipNodes(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig); 53 void StartEventHandler(); 54 55 private: 56 const static std::string PIPELINE_OWNER; 57 constexpr static int32_t MIN_FRAME_RATE = 0; 58 constexpr static int32_t MAX_FRAME_RATE = 30; 59 constexpr static int32_t MIN_VIDEO_WIDTH = 320; 60 constexpr static int32_t MIN_VIDEO_HEIGHT = 240; 61 constexpr static int32_t MAX_VIDEO_WIDTH = 1920; 62 constexpr static int32_t MAX_VIDEO_HEIGHT = 1080; 63 64 std::shared_ptr<DataProcessListener> processListener_ = nullptr; 65 std::shared_ptr<AbstractDataProcess> pipelineHead_ = nullptr; 66 67 bool isProcess_ = false; 68 PipelineType piplineType_ = PipelineType::VIDEO; 69 std::vector<std::shared_ptr<AbstractDataProcess>> pipNodeRanks_; 70 71 std::mutex eventMutex_; 72 std::thread eventThread_; 73 std::condition_variable eventCon_; 74 std::shared_ptr<AppExecFwk::EventHandler> pipeEventHandler_ = nullptr; 75 }; 76 } // namespace DistributedHardware 77 } // namespace OHOS 78 #endif // OHOS_DCAMERA_PIPELINE_SOURCE_H 79