diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index e2b53474ad326f7ccd457c03882a89ae4d39fcc6..d17ffc23d7567bd393781892989fe5e1fe6a5c6d 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 1cee3a13c1b3c41aa57f58c514afaa17288a831b..e5d33b7baac73f38bee921e8465b96cf6930f4dc 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 d63afb60d2c6c1de373f511adb9964c8190c8f50..edc4892fb93853ec3802f0bb7a83c9c62dbd630f 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 afcf325450b8e7fc95d979df90287a5684e4113d..9fea2dbe93017be3d07d55d741658f6024d07d9a 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 64839c97caded2c4da34c13fbfac19e80e499afe..f9e89d18bb0f230254b2564a67811bb4e475d77d 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 80d9e6b8427a04f75bf165b2c37a2b303adccacf..2fc697397cea4d7a0bfca611c1d856405d963ec6 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 01c108d3fe3eebbe4d80e1a677409df293cf3116..1872fdcc5c513d7b658c83a111c4e379114e1ae4 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 839a8c1489026ea99e0ebb92ed81f48ec92e1b7b..37abe638655b483ecb3d1f981d9c6bbeea395a48 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 035cec5e3ce28ac423ba86516fb45cb973e391fd..87ffc2299e279f164b9ffd33f27da4886aa2abed 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 fe118349c906592a5c5d7373e270917f1bba1f07..5b8b2d94a20630376044845c7fbe1e411d731c20 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 774d7af26f4bc65ade87dd58c9f62cd3f9973c4a..a0f4ea030c47974081b6b7f7df08eaaeb34d939b 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 1133c184b1e716badc8ae7763320cf8688e72acf..a7439387c89022ca03421357feb09af50c050b00 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 8c76340fd962137d93e5b3d272075145b2e712e1..ef21f348384c5624e23583203d4714ecd4445e56 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 e0ef91c16d3873f39b8f4c66d463a8577ffe501c..8be7e04391e20a6398541cded47ad62150f692c8 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 340a683f56e6532a68fcbb0c36f751b9bede7e05..6627eb8d7b24c9f968e77d4437d00bad2f198b19 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 b5ba33741e1170ed4b094b5500fd9472f18714df..f71ea5f4b1234d8fb8436e9b2142f0a2dda02497 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 5380937532e33c946ff9efb79eff756248106b5a..3e17d081e8bb5ed3c4540be9205256ee4f127a91 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 ff03666452bd4663594635d88d527021db052df2..1fb1af638095cac19f4fa75445fd8cef8a4129f5 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 578d38a52475d82b267746afcf4d05b2c7f8d37c..d260b73cf788b111498afbaed1fc9ebaf7e52fdc 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 1879f33456ab2e6557607473a8f1c2b910cf60e4..7598457f816065ff29efc61cb720556c74798583 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 f242821d7c6bea4828303f673bb25e37cc699fd2..33c596899fa076deb2e665ee55547cb72ca74e35 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 3713473eaef083e09b3427c92448340f9780efff..be1b418e85e6cbbd4f4a9d564a42743cfef865e5 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 a7c885b6d245910baedda940b512a6f04cbfa96a..a20af0b21182df2d89fc13295b9448eee1abd595 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 a0d5df7a77022f4a81b462d7bf8170459e3bba51..df665ed1e153c539e7e15afd3856380f9496fc31 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 dbf7b80d200f4efde75ffe899734c5a1c74f01e8..340f645ce1208e65518485f0ca21deb4f8f5e9b4 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 053c1af65b3304a4e2a0d9e1c6aa52f691db14d6..ef4e01158cd17503d970ebdbdb9f2705e0b29c4f 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 b50c523c0e0f04c732a4cb67e3cba01c53b01936..d7d9a5c318cac29b86680d19871d089fbefcece1 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 200d14ecba408f2b44ce6665c5b56d9a19e0c426..3abf2c87ddb99f13337d78fc2935bafddd4c0eca 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 2d7310a2ffe80743c7a5758aab7c260f259bd81b..44c9e34b2eaa7b9f7399ef83ce06afc9f01a6334 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 4cf3cc9144d708c373da567384e790c23479f5ba..7f3f8ede60e1c4dc621795bbc6a424b113234a24 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 44e939a5be980bbde58712943d7c9faec7d657ff..eaa715aa100d449f30a8839789f348a5bc1a59a4 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 0b6913be0161e20ea4d6582a8cc0520baafc7707..155ba9be4476980b2679b9449ed79cf4999e2c7f 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 46eea982c4a27f74274a8a15699bf0eda9f9fef0..bf281173dd105219c7a4f3625469af17b862d505 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 ea4749d20d8f26209428091cbee824b44dce38ab..34891a7cd2d747d1f7f58df7ea875d036a81915a 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 0000000000000000000000000000000000000000..ffd17337c6167b6f127c56970348ca11c8a28488 --- /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 af38f4dbedc12dce6574177a6b15d880b0e60fae..9f28d41725b704e05662244ea0fa86b43df05991 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 a32515dfa48094f9be8e235a55de1b3ba3bfaed2..0dcb6a25d3dad8d73bcf68d1fecb347be3db08af 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 61f751e93dd63002844b8977782145b384cecbaf..8b091150e79e040a562ee5358682ec5b17924c77 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 cfa057f8b0af756a8247f78e393121da309f43c8..4c748db8ac9d5194752c3bb1e17d4a62682eb702 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 98a502268485c2dddcef0a868b52d76f5b78916c..eb4b9330a3b1b86f6f324206920dccf54ccc67ae 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 b247424bdfb0c45ffa3ba15a7e2da294e9bcb65b..74d720eb04abac96cbbe3af689c048b81ede4dfc 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 2a2bc923b81a1550383412adfa43582bcbb4a4e6..75a2c2778e20fc29e3ec67c997d182f8a874d6cf 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 af4db4779604db5cd93d71156d62cb606e9d9b58..98887df7c5c98e96d0e50cdc76c0b5767c31e045 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 590425eabf4419113e259d2639a02d8ad2211145..b562157151fe89ebb8f42ebc73d41856710e8e11 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 0000000000000000000000000000000000000000..0cdedc3ffca4ed6a147587796de540810b875b8a --- /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