From 31c26b16e03357ec2b85e0bd05d849d34942279b Mon Sep 17 00:00:00 2001 From: Clone_Zhang Date: Sat, 29 Oct 2022 14:24:43 +0800 Subject: [PATCH] fix: add property channel to deliver 'surface', add time out monitoring mechanism to status of softbus before use it. Signed-off-by: Clone_Zhang --- .../client/include/dcamera_client.h | 3 +- .../client/include/icamera_operator.h | 5 +- .../client/src/dcamera_client.cpp | 11 +- .../client/src/dcamera_client_common.cpp | 11 +- .../cameraoperator/dcamera_client_test.cpp | 11 +- .../dcamera_sink_controller.h | 2 + .../dcamera_sink_data_process.h | 2 + .../dcamera_sink_output.h | 4 + .../interface/icamera_sink_data_process.h | 4 + .../interface/icamera_sink_output.h | 2 + .../dcamera_sink_controller.cpp | 9 +- .../dcamera_sink_data_process.cpp | 9 ++ .../dcamera_sink_data_process_common.cpp | 9 ++ .../dcamera_sink_output.cpp | 9 ++ .../mock_camera_operator.h | 3 +- .../mock_data_process_pipeline.h | 5 + .../mock_dcamera_sink_data_process.h | 4 + .../mock_dcamera_sink_output.h | 4 + services/cameraservice/sourceservice/BUILD.gn | 2 + .../dcamera_source_controller.h | 7 + .../dcameradata/dcamera_source_input.h | 9 ++ .../dcamera_source_controller.cpp | 52 +++++-- .../dcameradata/dcamera_source_input.cpp | 140 +++++++++++++----- .../common/distributedcameramgr/BUILD.gn | 2 + services/data_process/BUILD.gn | 5 +- .../interfaces/idata_process_pipeline.h | 3 + .../include/pipeline/abstract_data_process.h | 7 +- .../include/pipeline/dcamera_pipeline_sink.h | 2 + .../pipeline/dcamera_pipeline_source.h | 2 + .../color_format_process.h | 2 + .../fpscontroller/fps_controller_process.h | 2 + .../decoder/decode_data_process.h | 2 + .../encoder/encode_data_process.h | 3 + .../scale_conversion/scale_convert_process.h | 2 + .../include/utils/property_carrier.h | 36 +++++ .../src/pipeline/dcamera_pipeline_sink.cpp | 18 +++ .../src/pipeline/dcamera_pipeline_source.cpp | 5 + .../color_format_process.cpp | 5 + .../fpscontroller/fps_controller_process.cpp | 5 + .../decoder/decode_data_process.cpp | 5 + .../decoder/decode_data_process_common.cpp | 5 + .../encoder/encode_data_process.cpp | 16 +- .../encoder/encode_data_process_common.cpp | 16 +- .../scale_convert_process.cpp | 5 + .../src/utils/property_carrier.cpp | 37 +++++ 45 files changed, 421 insertions(+), 81 deletions(-) create mode 100644 services/data_process/include/utils/property_carrier.h create mode 100644 services/data_process/src/utils/property_carrier.cpp diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index e2b53474..d17ffc23 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -44,7 +44,8 @@ public: int32_t Init() override; int32_t UnInit() override; int32_t UpdateSettings(std::vector>& settings) override; - int32_t StartCapture(std::vector>& captureInfos) override; + int32_t StartCapture(std::vector>& captureInfos, + sptr& surface) override; int32_t StopCapture() override; int32_t SetStateCallback(std::shared_ptr& callback) override; int32_t SetResultCallback(std::shared_ptr& callback) override; diff --git a/services/cameraservice/cameraoperator/client/include/icamera_operator.h b/services/cameraservice/cameraoperator/client/include/icamera_operator.h index 1cee3a13..e5d33b7b 100644 --- a/services/cameraservice/cameraoperator/client/include/icamera_operator.h +++ b/services/cameraservice/cameraoperator/client/include/icamera_operator.h @@ -26,6 +26,8 @@ #include "dcamera_event_cmd.h" #include "v1_0/dcamera_types.h" +#include "surface.h" + namespace OHOS { namespace DistributedHardware { using namespace OHOS::HDI::DistributedCamera::V1_0; @@ -55,7 +57,8 @@ public: virtual int32_t Init() = 0; virtual int32_t UnInit() = 0; virtual int32_t UpdateSettings(std::vector>& settings) = 0; - virtual int32_t StartCapture(std::vector>& captureInfos) = 0; + virtual int32_t StartCapture(std::vector>& captureInfos, + sptr& surface) = 0; virtual int32_t StopCapture() = 0; virtual int32_t SetStateCallback(std::shared_ptr& callback) = 0; virtual int32_t SetResultCallback(std::shared_ptr& callback) = 0; diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index d63afb60..edc4892f 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -169,11 +169,17 @@ void DCameraClient::FindCameraMetadata(const std::string& metadataStr) } } -int32_t DCameraClient::StartCapture(std::vector>& captureInfos) +int32_t DCameraClient::StartCapture(std::vector>& captureInfos, + sptr& surface) { DHLOGI("DCameraClient::StartCapture cameraId: %s", GetAnonyString(cameraId_).c_str()); if ((photoOutput_ == nullptr) && (videoOutput_ == nullptr)) { DHLOGI("DCameraClient::StartCapture %s config capture session", GetAnonyString(cameraId_).c_str()); + if (surface == nullptr) { + DHLOGE("DCameraClient::StartCapture: input surface is nullptr."); + return DCAMERA_BAD_VALUE; + } + videoSurface_ = surface; int32_t ret = ConfigCaptureSession(captureInfos); if (ret != DCAMERA_OK) { DHLOGE("DCameraClient::StartCapture config capture session failed, cameraId: %s, ret: %d", @@ -453,9 +459,6 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in DHLOGI("DCameraClient::CreateVideoOutput camId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, info->isCapture_); - videoSurface_ = Surface::CreateSurfaceAsConsumer(); - videoListener_ = new DCameraVideoSurfaceListener(videoSurface_, resultCallback_); - videoSurface_->RegisterConsumerListener((sptr &)videoListener_); CameraStandard::CameraFormat videoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size videoSize = {info->width_, info->height_}; std::vector framerates = {}; diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp index afcf3254..9fea2dbe 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp @@ -171,11 +171,17 @@ void DCameraClient::FindCameraMetadata(const std::string& metadataStr) } } -int32_t DCameraClient::StartCapture(std::vector>& captureInfos) +int32_t DCameraClient::StartCapture(std::vector>& captureInfos, + sptr& surface) { DHLOGI("DCameraClientCommon::StartCapture cameraId: %s", GetAnonyString(cameraId_).c_str()); if ((photoOutput_ == nullptr) && (previewOutput_ == nullptr)) { DHLOGI("DCameraClientCommon::StartCapture %s config capture session", GetAnonyString(cameraId_).c_str()); + if (surface == nullptr) { + DHLOGE("DCameraClient::StartCapture: input surface is nullptr."); + return DCAMERA_BAD_VALUE; + } + videoSurface_ = surface; int32_t ret = ConfigCaptureSession(captureInfos); if (ret != DCAMERA_OK) { DHLOGE("DCameraClientCommon::StartCapture config capture session failed, cameraId: %s, ret: %d", @@ -445,9 +451,6 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in DHLOGI("DCameraClientCommon::CreatePreviewOutput camId: %s, w: %d, h: %d, f: %d, stream: %d, isCapture: %d", GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, info->isCapture_); - videoSurface_ = Surface::CreateSurfaceAsConsumer(); - videoListener_ = new DCameraVideoSurfaceListener(videoSurface_, resultCallback_); - videoSurface_->RegisterConsumerListener((sptr &)videoListener_); CameraStandard::CameraFormat previewFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size previewSize = {info->width_, info->height_}; CameraStandard::Profile previewProfile(previewFormat, previewSize); diff --git a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp index 64839c97..f9e89d18 100644 --- a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp +++ b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp @@ -24,6 +24,7 @@ #include "distributed_hardware_log.h" #include "nativetoken_kit.h" #include "token_setproc.h" +#include "surface.h" using namespace testing::ext; @@ -77,7 +78,8 @@ public: void SetUp(); void TearDown(); void SetTokenID(); - + + sptr surface_; std::shared_ptr client_; std::shared_ptr photoInfo_false_; std::shared_ptr videoInfo_false_; @@ -101,6 +103,7 @@ void DCameraClientTest::SetUp(void) DCameraHandler::GetInstance().Initialize(); std::vector cameras = DCameraHandler::GetInstance().GetCameras(); client_ = std::make_shared(cameras[0]); + surface_ = Surface::CreateSurfaceAsConsumer(); photoInfo_false_ = std::make_shared(); photoInfo_false_->width_ = TEST_WIDTH; @@ -239,7 +242,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_004, TestSize.Level1) videoInfo_true_->width_, videoInfo_true_->height_, videoInfo_true_->format_, videoInfo_true_->isCapture_); std::vector> captureInfos; captureInfos.push_back(videoInfo_true_); - ret = client_->StartCapture(captureInfos); + ret = client_->StartCapture(captureInfos, surface_); EXPECT_EQ(DCAMERA_OK, ret); sleep(TEST_SLEEP_SEC); @@ -279,7 +282,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) std::vector> captureInfos; captureInfos.push_back(videoInfo_true_); captureInfos.push_back(photoInfo_false_); - ret = client_->StartCapture(captureInfos); + ret = client_->StartCapture(captureInfos, surface_); EXPECT_EQ(DCAMERA_OK, ret); sleep(TEST_SLEEP_SEC); @@ -291,7 +294,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) captureInfos.clear(); captureInfos.push_back(videoInfo_false_); captureInfos.push_back(photoInfo_true_); - ret = client_->StartCapture(captureInfos); + ret = client_->StartCapture(captureInfos, surface_); EXPECT_EQ(DCAMERA_OK, ret); sleep(TEST_SLEEP_SEC); diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h index 80d9e6b8..2fc69739 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h @@ -27,6 +27,8 @@ #include "icamera_sink_output.h" #include +#include "property_carrier.h" + namespace OHOS { namespace DistributedHardware { class DCameraSinkController : public ICameraController, public EventSender, diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_data_process.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_data_process.h index 01c108d3..1872fdcc 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_data_process.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_data_process.h @@ -45,6 +45,8 @@ public: void OnProcessedVideoBuffer(const std::shared_ptr& videoResult); void OnError(DataProcessErrorType errorType); + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: int32_t FeedStreamInner(std::shared_ptr& dataBuffer); VideoCodecType GetPipelineCodecType(DCEncodeType encodeType); diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_output.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_output.h index 839a8c14..37abe638 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_output.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_output.h @@ -24,6 +24,8 @@ #include "icamera_operator.h" #include "icamera_sink_data_process.h" +#include "property_carrier.h" + namespace OHOS { namespace DistributedHardware { class DCameraSinkOutput : public ICameraSinkOutput, public std::enable_shared_from_this { @@ -45,6 +47,8 @@ public: void OnSessionError(DCStreamType type, int32_t eventType, int32_t eventReason, std::string detail); void OnDataReceived(DCStreamType type, std::vector>& dataBuffers); + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: void InitInner(DCStreamType type); diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_data_process.h b/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_data_process.h index 035cec5e..87ffc229 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_data_process.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_data_process.h @@ -22,6 +22,8 @@ #include "data_buffer.h" #include "dcamera_capture_info_cmd.h" +#include "property_carrier.h" + namespace OHOS { namespace DistributedHardware { class ICameraSinkDataProcess { @@ -32,6 +34,8 @@ public: virtual int32_t StartCapture(std::shared_ptr& captureInfo) = 0; virtual int32_t StopCapture() = 0; virtual int32_t FeedStream(std::shared_ptr& dataBuffer) = 0; + + virtual int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_output.h b/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_output.h index fe118349..5b8b2d94 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_output.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/interface/icamera_sink_output.h @@ -22,6 +22,7 @@ #include "dcamera_capture_info_cmd.h" #include "dcamera_channel_info_cmd.h" +#include "property_carrier.h" namespace OHOS { namespace DistributedHardware { @@ -36,6 +37,7 @@ public: virtual int32_t StopCapture() = 0; virtual int32_t OpenChannel(std::shared_ptr& info) = 0; virtual int32_t CloseChannel() = 0; + virtual int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index 774d7af2..a0f4ea03 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -430,8 +430,13 @@ int32_t DCameraSinkController::StartCaptureInner(std::vectorStartCapture(captureInfos); + PropertyCarrier carrier; + ret = output_->GetProperty(SURFACE, carrier); + if (ret != DCAMERA_OK) { + DHLOGD("DCameraSinkController::StartCaptureInner: get property fail."); + return DCAMERA_BAD_VALUE; + } + ret = operator_->StartCapture(captureInfos, carrier.surface_); if (ret != DCAMERA_OK) { DHLOGE("DCameraSinkController::StartCaptureInner camera client start capture failed, dhId: %s, ret: %d", GetAnonyString(dhId_).c_str(), ret); diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp index 1133c184..a7439387 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp @@ -182,5 +182,14 @@ Videoformat DCameraSinkDataProcess::GetPipelineFormat(int32_t format) { return Videoformat::NV21; } + +int32_t DCameraSinkDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + if (pipeline_ == nullptr) { + DHLOGD("DCameraSinkDataProcess::GetProperty: pipeline is nullptr."); + return DCAMERA_BAD_VALUE; + } + return pipeline_->GetProperty(propertyName, propertyCarrier); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp index 8c76340f..ef21f348 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp @@ -175,5 +175,14 @@ Videoformat DCameraSinkDataProcess::GetPipelineFormat(int32_t format) { return Videoformat::NV21; } + +int32_t DCameraSinkDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + if (pipeline_ == nullptr) { + DHLOGD("DCameraSinkDataProcess::GetProperty: pipeline is nullptr."); + return DCAMERA_BAD_VALUE; + } + return pipeline_->GetProperty(propertyName, propertyCarrier); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp index e0ef91c1..8be7e043 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp @@ -235,5 +235,14 @@ void DCameraSinkOutput::OnSessionError(DCStreamType type, int32_t eventType, int void DCameraSinkOutput::OnDataReceived(DCStreamType type, std::vector>& dataBuffers) { } + +int32_t DCameraSinkOutput::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + if (dataProcesses_[CONTINUOUS_FRAME] == nullptr) { + DHLOGD("DCameraSinkOutput::GetProperty: continuous frame is nullptr."); + return DCAMERA_BAD_VALUE; + } + return dataProcesses_[CONTINUOUS_FRAME]->GetProperty(propertyName, propertyCarrier); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h index 340a683f..6627eb8d 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h @@ -56,7 +56,8 @@ public: return DCAMERA_OK; } - int32_t StartCapture(std::vector>& captureInfos) + int32_t StartCapture(std::vector>& captureInfos, + sptr& surface) { return DCAMERA_OK; } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_data_process_pipeline.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_data_process_pipeline.h index b5ba3374..f71ea5f4 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_data_process_pipeline.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_data_process_pipeline.h @@ -49,6 +49,11 @@ public: void DestroyDataProcessPipeline() { } + + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) + { + return DCAMERA_OK; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_data_process.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_data_process.h index 53809375..3e17d081 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_data_process.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_data_process.h @@ -71,6 +71,10 @@ public: void OnError(DataProcessErrorType errorType) { } + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) + { + return DCAMERA_OK; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h index ff036664..1fb1af63 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_output.h @@ -56,6 +56,10 @@ public: { return DCAMERA_OK; } + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) + { + return DCAMERA_OK; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 578d38a5..d260b73c 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -45,6 +45,7 @@ ohos_shared_library("distributed_camera_source") { "${services_path}/data_process/include/interfaces", "${services_path}/data_process/include/pipeline", "${services_path}/data_process/include/utils", + "${graphicstandard_path}/frameworks/surface/include", ] sources = [ @@ -84,6 +85,7 @@ ohos_shared_library("distributed_camera_source") { deps = [ "${common_path}:distributed_camera_utils", + "${graphicstandard_path}:libsurface", "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", "//third_party/jsoncpp:jsoncpp", diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h index 1879f334..7598457f 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h @@ -51,6 +51,8 @@ public: private: void HandleMetaDataResult(std::string& jsonStr); + void PostChannelDisconnectedEvent(); + int32_t WaitforSessionResult(); private: std::string devId_; @@ -64,6 +66,11 @@ private: bool isInit; const std::string SESSION_FLAG = "control"; + + static constexpr uint8_t CHANNEL_REL_SECONDS = 5; + std::atomic isChannelConnected_ = false; + std::mutex channelMtx_; + std::condition_variable channelCond_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input.h index f242821d..33c59689 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input.h @@ -50,6 +50,10 @@ public: private: void FinshFrameAsyncTrace(DCStreamType streamType); + void PostChannelDisconnectedEvent(); + int32_t WaitforSessionResult(); + int32_t EstablishContinuousFrameSession(std::vector& indexs); + int32_t EstablishSnapshotFrameSession(std::vector& indexs); private: std::map> channels_; @@ -61,6 +65,11 @@ private: std::shared_ptr eventBus_; bool isInit = false; + + static constexpr uint8_t CHANNEL_REL_SECONDS = 5; + std::atomic isChannelConnected_ = false; + std::mutex channelMtx_; + std::condition_variable channelCond_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 3713473e..be1b418e 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -284,20 +284,17 @@ int32_t DCameraSourceController::OpenChannel(std::shared_ptr& o DHLOGE("DCameraSourceController can not get service, devId: %s", GetAnonyString(devId).c_str()); return DCAMERA_BAD_OPERATE; } - + std::string jsonStr; DCameraOpenInfoCmd cmd; cmd.type_ = DCAMERA_PROTOCOL_TYPE_MESSAGE; cmd.dhId_ = dhId; cmd.command_ = DCAMERA_PROTOCOL_CMD_OPEN_CHANNEL; cmd.value_ = openInfo; - std::string jsonStr; int32_t ret = cmd.Marshal(jsonStr); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceController Marshal OpenInfo failed %d", ret); return ret; } - DHLOGD("DCameraSourceController OpenChannel devId: %s, dhId: %s openCommand: %s", GetAnonyString(devId).c_str(), - GetAnonyString(dhId).c_str(), cmd.command_.c_str()); ret = camSinkSrv->OpenChannel(dhId, jsonStr); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceController SA OpenChannel failed %d", ret); @@ -315,11 +312,11 @@ int32_t DCameraSourceController::OpenChannel(std::shared_ptr& o } ret = channel_->OpenSession(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceController OpenChannel OpenChannel failed %d", ret); + DHLOGE("DCameraSourceController OpenSession failed."); + PostChannelDisconnectedEvent(); return ret; } - - return DCAMERA_OK; + return WaitforSessionResult(); } int32_t DCameraSourceController::CloseChannel() @@ -379,6 +376,7 @@ int32_t DCameraSourceController::UnInit() DHLOGI("DCameraSourceController UnInit"); indexs_.clear(); isInit = false; + isChannelConnected_.store(false); return DCAMERA_OK; } @@ -389,6 +387,8 @@ void DCameraSourceController::OnSessionState(int32_t state) switch (state) { case DCAMERA_CHANNEL_STATE_CONNECTED: { DcameraFinishAsyncTrace(DCAMERA_OPEN_CHANNEL_CONTROL, DCAMERA_OPEN_CHANNEL_TASKID); + isChannelConnected_.store(true); + channelCond_.notify_all(); stateMachine_->UpdateState(DCAMERA_STATE_OPENED); std::shared_ptr camEvent = std::make_shared(); camEvent->eventType_ = DCAMERA_MESSAGE; @@ -401,14 +401,8 @@ void DCameraSourceController::OnSessionState(int32_t state) DcameraFinishAsyncTrace(DCAMERA_OPEN_CHANNEL_CONTROL, DCAMERA_OPEN_CHANNEL_TASKID); DHLOGI("DCameraSourceDev PostTask Controller CloseSession OnClose devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DCameraIndex camIndex(devId_, dhId_); - DCameraSourceEvent event(*this, DCAMERA_EVENT_CLOSE, camIndex); - eventBus_->PostEvent(event); - std::shared_ptr camEvent = std::make_shared(); - camEvent->eventType_ = DCAMERA_MESSAGE; - camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; - DCameraSourceEvent eventNotify(*this, DCAMERA_EVENT_NOFIFY, camEvent); - eventBus_->PostEvent(eventNotify); + isChannelConnected_.store(false); + PostChannelDisconnectedEvent(); break; } default: { @@ -480,5 +474,33 @@ void DCameraSourceController::HandleMetaDataResult(std::string& jsonStr) GetAnonyString(dhId_).c_str()); } } + +int32_t DCameraSourceController::WaitforSessionResult() +{ + isChannelConnected_.store(false); + std::unique_lock lck(channelMtx_); + DHLOGD("DCameraSourceController::WaitforSessionResult: wait for channel session callback notify."); + bool isChannelConnected = channelCond_.wait_for(lck, std::chrono::seconds(CHANNEL_REL_SECONDS), + [this]() { return isChannelConnected_.load(); }); + if (!isChannelConnected) { + DHLOGE("DCameraSourceController::WaitforSessionResult: wait for channel session callback timeout(%ds).", + CHANNEL_REL_SECONDS); + PostChannelDisconnectedEvent(); + return DCAMERA_BAD_VALUE; + } + return DCAMERA_OK; +} + +void DCameraSourceController::PostChannelDisconnectedEvent() +{ + DCameraIndex camIndex(devId_, dhId_); + DCameraSourceEvent event(*this, DCAMERA_EVENT_CLOSE, camIndex); + eventBus_->PostEvent(event); + std::shared_ptr camEvent = std::make_shared(); + camEvent->eventType_ = DCAMERA_MESSAGE; + camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; + DCameraSourceEvent eventNotify(*this, DCAMERA_EVENT_NOFIFY, camEvent); + eventBus_->PostEvent(eventNotify); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp index a7c885b6..a20af0b2 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp @@ -183,43 +183,19 @@ int32_t DCameraSourceInput::OpenChannel(std::vector& indexs) DHLOGI("DCameraSourceInput OpenChannel devId %s dhId %s continue state: %d, snapshot state: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), channelState_[CONTINUOUS_FRAME], channelState_[SNAPSHOT_FRAME]); - int32_t ret = DCAMERA_OK; if (channelState_[CONTINUOUS_FRAME] == DCAMERA_CHANNEL_STATE_DISCONNECTED) { - DcameraStartAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); - ret = channels_[CONTINUOUS_FRAME]->CreateSession(indexs, CONTINUE_SESSION_FLAG, DCAMERA_SESSION_MODE_VIDEO, - listeners_[CONTINUOUS_FRAME]); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceInput CreateSession continue failed ret: %d, devId: %s, dhId: %s", ret, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); - return ret; - } - - ret = channels_[CONTINUOUS_FRAME]->OpenSession(); + int32_t ret = EstablishContinuousFrameSession(indexs); if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceInput OpenChannel continue stream failed ret: %d, devId: %s, dhId: %s", ret, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + DHLOGE("DCameraSourceInput::OpenChannel: esdablish continuous frame failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); return ret; } } - if (channelState_[SNAPSHOT_FRAME] == DCAMERA_CHANNEL_STATE_DISCONNECTED) { - DcameraStartAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); - ret = channels_[SNAPSHOT_FRAME]->CreateSession(indexs, SNAP_SHOT_SESSION_FLAG, DCAMERA_SESSION_MODE_JPEG, - listeners_[SNAPSHOT_FRAME]); + int32_t ret = EstablishSnapshotFrameSession(indexs); if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceInput Init CreateSession snapshot failed ret: %d, devId: %s, dhId: %s", ret, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); - return ret; - } - - ret = channels_[SNAPSHOT_FRAME]->OpenSession(); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceInput OpenChannel snapshot stream failed ret: %d, devId: %s, dhId: %s", ret, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); + DHLOGE("DCameraSourceInput::OpenChannel: esdablish snapshot frame failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); return ret; } } @@ -303,6 +279,7 @@ int32_t DCameraSourceInput::UnInit() dataProcess_.clear(); channelState_.clear(); isInit = false; + isChannelConnected_.store(false); return DCAMERA_OK; } @@ -321,18 +298,14 @@ void DCameraSourceInput::OnSessionState(DCStreamType streamType, int32_t state) FinshFrameAsyncTrace(streamType); DHLOGI("DCameraSourceDev PostTask CloseSession Input OnClose devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DCameraIndex camIndex(devId_, dhId_); - DCameraSourceEvent event(*this, DCAMERA_EVENT_CLOSE, camIndex); - eventBus_->PostEvent(event); - std::shared_ptr camEvent = std::make_shared(); - camEvent->eventType_ = DCAMERA_MESSAGE; - camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; - DCameraSourceEvent srcEvent(*this, DCAMERA_EVENT_NOFIFY, camEvent); - eventBus_->PostEvent(srcEvent); + isChannelConnected_.store(false); + PostChannelDisconnectedEvent(); break; } case DCAMERA_CHANNEL_STATE_CONNECTED: { FinshFrameAsyncTrace(streamType); + isChannelConnected_.store(true); + channelCond_.notify_one(); DHLOGI("DCameraSourceInput OnSessionState state %d", state); break; } @@ -415,5 +388,96 @@ int32_t DCameraSourceInput::StopAllCapture() } return DCAMERA_OK; } + +void DCameraSourceInput::PostChannelDisconnectedEvent() +{ + DCameraIndex camIndex(devId_, dhId_); + DCameraSourceEvent event(*this, DCAMERA_EVENT_CLOSE, camIndex); + eventBus_->PostEvent(event); + std::shared_ptr camEvent = std::make_shared(); + camEvent->eventType_ = DCAMERA_MESSAGE; + camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; + DCameraSourceEvent eventNotify(*this, DCAMERA_EVENT_NOFIFY, camEvent); + eventBus_->PostEvent(eventNotify); +} + +int32_t DCameraSourceInput::WaitforSessionResult() +{ + isChannelConnected_.store(false); + std::unique_lock lck(channelMtx_); + DHLOGD("DCameraSourceInput::WaitforSessionResult: wait for channel session callback notify."); + bool isChannelConnected = channelCond_.wait_for(lck, std::chrono::seconds(CHANNEL_REL_SECONDS), + [this]() { return isChannelConnected_.load(); }); + if (!isChannelConnected) { + DHLOGE("DCameraSourceInput::WaitforSessionResult: wait for channel session callback timeout(%ds).", + CHANNEL_REL_SECONDS); + PostChannelDisconnectedEvent(); + return DCAMERA_BAD_VALUE; + } + return DCAMERA_OK; +} + +int32_t DCameraSourceInput::EstablishContinuousFrameSession(std::vector& indexs) +{ + DcameraStartAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + int32_t ret = channels_[CONTINUOUS_FRAME]->CreateSession(indexs, CONTINUE_SESSION_FLAG, DCAMERA_SESSION_MODE_VIDEO, + listeners_[CONTINUOUS_FRAME]); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput::EstablishContinuousFrameSession: Create Session failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + return ret; + } + + ret = channels_[CONTINUOUS_FRAME]->OpenSession(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput::EstablishContinuousFrameSession: open session failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + PostChannelDisconnectedEvent(); + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + return ret; + } + + ret = WaitforSessionResult(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput::EstablishContinuousFrameSession: waitfor session result failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + return ret; + } + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + return DCAMERA_OK; +} + +int32_t DCameraSourceInput::EstablishSnapshotFrameSession(std::vector& indexs) +{ + DcameraStartAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); + int32_t ret = channels_[SNAPSHOT_FRAME]->CreateSession(indexs, SNAP_SHOT_SESSION_FLAG, DCAMERA_SESSION_MODE_JPEG, + listeners_[SNAPSHOT_FRAME]); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput::EstablishSnapshotFrameSession create session failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); + return ret; + } + + ret = channels_[SNAPSHOT_FRAME]->OpenSession(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput::EstablishSnapshotFrameSession: open session failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + PostChannelDisconnectedEvent(); + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); + return ret; + } + + ret = WaitforSessionResult(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput::EstablishSnapshotFrameSession: waitfor session result failed ret: %d,"+ + "devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + DcameraFinishAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); + return ret; + } + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn index a0d5df7a..df665ed1 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -48,6 +48,7 @@ config("module_private_config") { "//utils/system/safwk/native/include", "//third_party/jsoncpp/include", "//drivers/peripheral/base/", + "${graphicstandard_path}/frameworks/surface/include", ] } @@ -64,6 +65,7 @@ ohos_unittest("DCameraSourceMgrTest") { deps = [ "${common_path}:distributed_camera_utils", + "${graphicstandard_path}:libsurface", "${services_path}/cameraservice/sourceservice:distributed_camera_source", "${services_path}/channel:distributed_camera_channel", "//third_party/googletest:gtest_main", diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index dbf7b80d..340f645c 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -22,10 +22,10 @@ ohos_shared_library("distributed_camera_data_process") { "//commonlibrary/c_utils/base/include", "//utils/system/safwk/native/include", "//foundation/graphic/graphic_2d/interfaces/innerkits/common", - "//foundation/graphic/graphic_2d/interfaces/innerkits/surface", "//foundation/multimedia/player_framework/interfaces/innerkits/native/media/include", "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/eventbus", + "${graphicstandard_path}/frameworks/surface/include", ] include_dirs += [ @@ -54,6 +54,7 @@ ohos_shared_library("distributed_camera_data_process") { "src/pipeline_node/multimedia_codec/encoder/encode_video_callback.cpp", "src/pipeline_node/scale_conversion/scale_convert_process.cpp", "src/utils/image_common_type.cpp", + "src/utils/property_carrier.cpp", ] if (!distributed_camera_common) { @@ -70,7 +71,7 @@ ohos_shared_library("distributed_camera_data_process") { deps = [ "${common_path}:distributed_camera_utils", - "//foundation/graphic/graphic_2d/frameworks/surface:surface", + "${graphicstandard_path}:libsurface", "//third_party/ffmpeg:libohosffmpeg", ] diff --git a/services/data_process/include/interfaces/idata_process_pipeline.h b/services/data_process/include/interfaces/idata_process_pipeline.h index 053c1af6..ef4e0115 100644 --- a/services/data_process/include/interfaces/idata_process_pipeline.h +++ b/services/data_process/include/interfaces/idata_process_pipeline.h @@ -24,6 +24,8 @@ #include "distributed_camera_errno.h" #include "data_process_listener.h" +#include "property_carrier.h" + namespace OHOS { namespace DistributedHardware { class IDataProcessPipeline { @@ -34,6 +36,7 @@ public: const VideoConfigParams& targetConfig, const std::shared_ptr& listener) = 0; virtual int32_t ProcessData(std::vector>& dataBuffers) = 0; virtual void DestroyDataProcessPipeline() = 0; + virtual int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/include/pipeline/abstract_data_process.h b/services/data_process/include/pipeline/abstract_data_process.h index b50c523c..d7d9a5c3 100644 --- a/services/data_process/include/pipeline/abstract_data_process.h +++ b/services/data_process/include/pipeline/abstract_data_process.h @@ -23,6 +23,8 @@ #include "image_common_type.h" #include "distributed_camera_errno.h" +#include "property_carrier.h" + namespace OHOS { namespace DistributedHardware { class AbstractDataProcess { @@ -35,9 +37,12 @@ public: VideoConfigParams& processedConfig) = 0; virtual int32_t ProcessData(std::vector>& inputBuffers) = 0; virtual void ReleaseProcessNode() = 0; + virtual int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) = 0; -protected: +public: std::shared_ptr nextDataProcess_ = nullptr; + +protected: size_t nodeRank_; }; } // namespace DistributedHardware diff --git a/services/data_process/include/pipeline/dcamera_pipeline_sink.h b/services/data_process/include/pipeline/dcamera_pipeline_sink.h index 200d14ec..3abf2c87 100644 --- a/services/data_process/include/pipeline/dcamera_pipeline_sink.h +++ b/services/data_process/include/pipeline/dcamera_pipeline_sink.h @@ -48,6 +48,8 @@ public: void OnError(DataProcessErrorType errorType); void OnProcessedVideoBuffer(const std::shared_ptr& videoResult); + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: bool IsInRange(const VideoConfigParams& curConfig); int32_t InitDCameraPipNodes(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig); diff --git a/services/data_process/include/pipeline/dcamera_pipeline_source.h b/services/data_process/include/pipeline/dcamera_pipeline_source.h index 2d7310a2..44c9e34b 100644 --- a/services/data_process/include/pipeline/dcamera_pipeline_source.h +++ b/services/data_process/include/pipeline/dcamera_pipeline_source.h @@ -50,6 +50,8 @@ public: void OnError(DataProcessErrorType errorType); void OnProcessedVideoBuffer(const std::shared_ptr& videoResult); + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: bool IsInRange(const VideoConfigParams& curConfig); void InitDCameraPipEvent(); diff --git a/services/data_process/include/pipeline_node/colorspace_conversion/color_format_process.h b/services/data_process/include/pipeline_node/colorspace_conversion/color_format_process.h index 4cf3cc91..7f3f8ede 100644 --- a/services/data_process/include/pipeline_node/colorspace_conversion/color_format_process.h +++ b/services/data_process/include/pipeline_node/colorspace_conversion/color_format_process.h @@ -36,6 +36,8 @@ public: int32_t ProcessData(std::vector>& inputBuffers) override; void ReleaseProcessNode() override; + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: bool IsConvertible(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig); int32_t GetImageUnitInfo(ImageUnitInfo& imgInfo, const std::shared_ptr& imgBuf); diff --git a/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h b/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h index 44e939a5..eaa715aa 100644 --- a/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h +++ b/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h @@ -36,6 +36,8 @@ public: int32_t ProcessData(std::vector>& inputBuffers) override; void ReleaseProcessNode() override; + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: void UpdateFPSControllerInfo(int64_t nowMs); void UpdateFrameRateCorrectionFactor(int64_t nowMs); diff --git a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h index 0b6913be..155ba9be 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h @@ -71,6 +71,8 @@ public: VideoConfigParams GetSourceConfig() const; VideoConfigParams GetTargetConfig() const; + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: bool IsInDecoderRange(const VideoConfigParams& curConfig); bool IsConvertible(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig); diff --git a/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h b/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h index 46eea982..bf281173 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h @@ -57,6 +57,8 @@ public: VideoConfigParams GetSourceConfig() const; VideoConfigParams GetTargetConfig() const; + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: bool IsInEncoderRange(const VideoConfigParams& curConfig); bool IsConvertible(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig); @@ -128,6 +130,7 @@ private: std::string processType_; Media::Format metadataFormat_; Media::Format encodeOutputFormat_; + std::string surfaceStr_ = "surface"; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/include/pipeline_node/scale_conversion/scale_convert_process.h b/services/data_process/include/pipeline_node/scale_conversion/scale_convert_process.h index ea4749d2..34891a7c 100644 --- a/services/data_process/include/pipeline_node/scale_conversion/scale_convert_process.h +++ b/services/data_process/include/pipeline_node/scale_conversion/scale_convert_process.h @@ -48,6 +48,8 @@ public: int32_t ProcessData(std::vector>& inputBuffers) override; void ReleaseProcessNode() override; + int32_t GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) override; + private: bool IsConvertible(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig); bool IsCorrectImageUnitInfo(const ImageUnitInfo& imgInfo); diff --git a/services/data_process/include/utils/property_carrier.h b/services/data_process/include/utils/property_carrier.h new file mode 100644 index 00000000..ffd17337 --- /dev/null +++ b/services/data_process/include/utils/property_carrier.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_PROPERTY_CARRIER_H +#define OHOS_PROPERTY_CARRIER_H + +#include "distributed_hardware_log.h" +#include "distributed_camera_errno.h" +#include "surface.h" + +namespace OHOS { +namespace DistributedHardware { +static const std::string SURFACE = "surface"; +class PropertyCarrier { +public: + ~PropertyCarrier(); + + int32_t carrySurfaceProperty(sptr& surface); +public: + sptr surface_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_PROPERTY_CARRIER_H \ No newline at end of file diff --git a/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp b/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp index af38f4db..9f28d417 100644 --- a/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp +++ b/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp @@ -182,5 +182,23 @@ void DCameraPipelineSink::OnProcessedVideoBuffer(const std::shared_ptrOnProcessedVideoBuffer(videoResult); } + +int32_t DCameraPipelineSink::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + if (pipelineHead_ == nullptr) { + DHLOGD("DCameraPipelineSink::GetProperty: pipelineHead is nullptr."); + return DCAMERA_BAD_VALUE; + } + std::shared_ptr cur = pipelineHead_; + while (cur) { + int32_t ret = cur->GetProperty(propertyName, propertyCarrier); + if (ret != DCAMERA_OK) { + DHLOGD("DCameraPipelineSink::GetProperty: get dataProcess property fail."); + return DCAMERA_BAD_VALUE; + } + cur = cur->nextDataProcess_; + } + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline/dcamera_pipeline_source.cpp b/services/data_process/src/pipeline/dcamera_pipeline_source.cpp index a32515df..0dcb6a25 100644 --- a/services/data_process/src/pipeline/dcamera_pipeline_source.cpp +++ b/services/data_process/src/pipeline/dcamera_pipeline_source.cpp @@ -224,5 +224,10 @@ void DCameraPipelineSource::OnProcessedVideoBuffer(const std::shared_ptrOnProcessedVideoBuffer(videoResult); } + +int32_t DCameraPipelineSource::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/colorspace_conversion/color_format_process.cpp b/services/data_process/src/pipeline_node/colorspace_conversion/color_format_process.cpp index 61f751e9..8b091150 100644 --- a/services/data_process/src/pipeline_node/colorspace_conversion/color_format_process.cpp +++ b/services/data_process/src/pipeline_node/colorspace_conversion/color_format_process.cpp @@ -474,5 +474,10 @@ int32_t ColorFormatProcess::ColorFormatDone(std::vectorOnProcessedVideoBuffer(outputBuffers[0]); return DCAMERA_OK; } + +int32_t ColorFormatProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp b/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp index cfa057f8..4c748db8 100644 --- a/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp +++ b/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp @@ -335,5 +335,10 @@ int32_t FpsControllerProcess::FpsControllerDone(std::vectorOnProcessedVideoBuffer(outputBuffers[0]); return DCAMERA_OK; } + +int32_t FpsControllerProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp index 98a50226..eb4b9330 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp @@ -787,5 +787,10 @@ VideoConfigParams DecodeDataProcess::GetTargetConfig() const { return targetConfig_; } + +int32_t DecodeDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp index b247424b..74d720eb 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp @@ -671,5 +671,10 @@ VideoConfigParams DecodeDataProcess::GetTargetConfig() const { return targetConfig_; } + +int32_t DecodeDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp index 2a2bc923..75a2c277 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp @@ -364,8 +364,6 @@ int32_t EncodeDataProcess::ProcessData(std::vector>& DHLOGE("Feed encoder input Buffer failed."); return err; } - - IncreaseWaitEncodeCnt(); return DCAMERA_OK; } @@ -573,8 +571,6 @@ void EncodeDataProcess::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBu DHLOGE("Get encode output Buffer failed."); return; } - ReduceWaitEncodeCnt(); - if (videoEncoder_ == nullptr) { DHLOGE("The video encoder does not exist before release output buffer index."); return; @@ -594,5 +590,17 @@ VideoConfigParams EncodeDataProcess::GetTargetConfig() const { return targetConfig_; } + +int32_t EncodeDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + if (propertyName != surfaceStr_) { + return DCAMERA_OK; + } + if (encodeProducerSurface_ == nullptr) { + DHLOGD("EncodeDataProcess::GetProperty: encode dataProcess get property fail, encode surface is nullptr."); + return DCAMERA_BAD_VALUE; + } + return propertyCarrier.carrySurfaceProperty(encodeProducerSurface_); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp index af4db477..98887df7 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp @@ -337,8 +337,6 @@ int32_t EncodeDataProcess::ProcessData(std::vector>& DHLOGE("Feed encoder input Buffer fail."); return err; } - - IncreaseWaitEncodeCnt(); return DCAMERA_OK; } @@ -530,8 +528,6 @@ void EncodeDataProcess::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBu DHLOGE("Get encode output Buffer fail."); return; } - ReduceWaitEncodeCnt(); - if (videoEncoder_ == nullptr) { DHLOGE("The video encoder does not exist before release output buffer index."); return; @@ -550,5 +546,17 @@ VideoConfigParams EncodeDataProcess::GetTargetConfig() const { return targetConfig_; } + +int32_t EncodeDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + if (propertyName != surfaceStr_) { + return DCAMERA_OK; + } + if (encodeProducerSurface_ == nullptr) { + DHLOGD("EncodeDataProcess::GetProperty: encode dataProcess get property fail, encode surface is nullptr."); + return DCAMERA_BAD_VALUE; + } + return propertyCarrier.carrySurfaceProperty(encodeProducerSurface_); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process.cpp b/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process.cpp index 590425ea..b5621571 100644 --- a/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process.cpp +++ b/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process.cpp @@ -402,5 +402,10 @@ AVPixelFormat ScaleConvertProcess::GetAVPixelFormat(Videoformat colorFormat) } return format; } + +int32_t ScaleConvertProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/utils/property_carrier.cpp b/services/data_process/src/utils/property_carrier.cpp new file mode 100644 index 00000000..0cdedc3f --- /dev/null +++ b/services/data_process/src/utils/property_carrier.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "property_carrier.h" +#include + +namespace OHOS { +namespace DistributedHardware { +PropertyCarrier::~PropertyCarrier() +{ + surface_ = nullptr; +} + +int32_t PropertyCarrier::carrySurfaceProperty(sptr& surface) +{ + if (surface == nullptr) { + DHLOGD("PropertyCarrier::carrySurfaceProperty: carry surface fail, input surface is nullptr."); + return DCAMERA_BAD_VALUE; + } + surface_ = surface; + DHLOGD("PropertyCarrier::carrySurfaceProperty: carry surface success."); + return DCAMERA_OK; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee