From 17458d73b72c1fdc238a9908be389d98ff51fd2c Mon Sep 17 00:00:00 2001 From: zhuxu Date: Mon, 16 May 2022 16:29:45 +0800 Subject: [PATCH 1/5] support distributed camera video recording mode Signed-off-by: zhuxu --- .../dcamera_provider/dcamera_provider.h | 2 +- .../dstream_operator/dstream_operator.h | 1 + .../src/dcamera_device/dcamera_device.cpp | 10 ++- .../src/dcamera_provider/dcamera_provider.cpp | 15 +++-- .../src/dstream_operator/dstream_operator.cpp | 64 ++++++++++++++++-- .../provider/dcamera_provider_callback.cpp | 3 +- .../provider/dcamera_provider_callback.h | 3 +- .../dcamera_provider_callback_stub.cpp | 8 ++- .../dcamera_provider_callback_proxy.cpp | 9 ++- .../dcamera_provider_callback_proxy.h | 3 +- .../idistributed_camera_provider_callback.h | 2 +- .../distributedcameramgr/dcamera_source_dev.h | 5 +- .../dcameradata/dcamera_source_data_process.h | 3 +- .../dcameradata/dcamera_source_input.h | 5 +- .../dcameradata/dcamera_stream_data_process.h | 7 +- .../dcamera_provider_callback_impl.h | 2 +- .../dcamerainterface/icamera_input.h | 3 +- .../icamera_source_data_process.h | 3 +- .../dcamera_source_dev.cpp | 31 +++++++-- .../dcamera_source_data_process.cpp | 30 +++++++-- .../dcameradata/dcamera_source_input.cpp | 54 ++++++++++----- .../dcamera_stream_data_process.cpp | 65 +++++++++++++++---- .../dcamera_stream_data_process_producer.cpp | 8 +-- .../dcamera_provider_callback_impl.cpp | 5 +- .../dcamera_source_capture_state.cpp | 30 ++++++--- 25 files changed, 286 insertions(+), 85 deletions(-) diff --git a/camera_hdf/hdi_impl/include/dcamera_provider/dcamera_provider.h b/camera_hdf/hdi_impl/include/dcamera_provider/dcamera_provider.h index 166d8149..21ad7a29 100644 --- a/camera_hdf/hdi_impl/include/dcamera_provider/dcamera_provider.h +++ b/camera_hdf/hdi_impl/include/dcamera_provider/dcamera_provider.h @@ -51,7 +51,7 @@ public: DCamRetCode ReleaseStreams(const std::shared_ptr &dhBase, const std::vector &streamIds); DCamRetCode StartCapture(const std::shared_ptr &dhBase, const std::vector> &captureInfos); - DCamRetCode StopCapture(const std::shared_ptr &dhBase); + DCamRetCode StopCapture(const std::shared_ptr &dhBase, const std::vector &streamIds); DCamRetCode UpdateSettings(const std::shared_ptr &dhBase, const std::vector> &settings); diff --git a/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h b/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h index 4f1a4bc3..3d259f6a 100644 --- a/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h +++ b/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h @@ -65,6 +65,7 @@ public: DCamRetCode SetDeviceCallback(function &errorCbk, function)> &resultCbk); void Release(); + std::vector GetStreamIds(); private: bool IsCapturing(); diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp index bad778bd..35072c70 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp @@ -225,7 +225,10 @@ void DCameraDevice::Close() std::shared_ptr provider = DCameraProvider::GetInstance(); if (provider != nullptr) { - provider->StopCapture(dhBase_); + if (dCameraStreamOperator_ != nullptr) { + std::vector streamIds = dCameraStreamOperator_->GetStreamIds(); + provider->StopCapture(dhBase_, streamIds); + } } if (dCameraStreamOperator_ != nullptr) { dCameraStreamOperator_->Release(); @@ -394,7 +397,10 @@ DCamRetCode DCameraDevice::Notify(const std::shared_ptr &event) } std::shared_ptr provider = DCameraProvider::GetInstance(); if (provider != nullptr) { - provider->StopCapture(dhBase_); + if (dCameraStreamOperator_ != nullptr) { + std::vector streamIds = dCameraStreamOperator_->GetStreamIds(); + provider->StopCapture(dhBase_, streamIds); + } } if (dCameraStreamOperator_ != nullptr) { dCameraStreamOperator_->Release(); diff --git a/camera_hdf/hdi_impl/src/dcamera_provider/dcamera_provider.cpp b/camera_hdf/hdi_impl/src/dcamera_provider/dcamera_provider.cpp index 7476c854..0417ada3 100644 --- a/camera_hdf/hdi_impl/src/dcamera_provider/dcamera_provider.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_provider/dcamera_provider.cpp @@ -285,14 +285,15 @@ DCamRetCode DCameraProvider::StartCapture(const std::shared_ptr &dhBase, for (int id : info->streamIds_) { idString += (std::to_string(id) + ", "); } - DHLOGI("StartCapture: ids=[%s], width=%d, height=%d, format=%d, type=%d.", + DHLOGI("DCameraProvider::StartCapture: ids=[%s], width=%d, height=%d, format=%d, type=%d, isCapture=%d.", (idString.empty() ? idString.c_str() : (idString.substr(0, idString.length() - INGNORE_STR_LEN)).c_str()), - info->width_, info->height_, info->format_, info->type_); + info->width_, info->height_, info->format_, info->type_, info->isCapture_); } return callback->StartCapture(dhBase, captureInfos); } -DCamRetCode DCameraProvider::StopCapture(const std::shared_ptr &dhBase) +DCamRetCode DCameraProvider::StopCapture(const std::shared_ptr &dhBase, + const std::vector &streamIds) { if (dhBase == nullptr) { DHLOGE("DCameraProvider::StopCapture, dhBase is null."); @@ -307,7 +308,13 @@ DCamRetCode DCameraProvider::StopCapture(const std::shared_ptr &dhBase) return DCamRetCode::INVALID_ARGUMENT; } - return callback->StopCapture(dhBase); + std::string idString = ""; + for (int id : streamIds) { + idString += (std::to_string(id) + ", "); + } + DHLOGI("DCameraProvider::StopCapture: ids=[%s].", + idString.empty() ? idString.c_str() : (idString.substr(0, idString.length() - INGNORE_STR_LEN)).c_str()); + return callback->StopCapture(dhBase, streamIds); } DCamRetCode DCameraProvider::UpdateSettings(const std::shared_ptr &dhBase, diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp index 98e1f877..894d098e 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -109,7 +109,7 @@ CamRetCode DStreamOperator::ReleaseStreams(const std::vector& streamIds) DHLOGE("Release distributed camera buffer queue for stream %d failed.", id); return MapToExternalRetCode(ret); } else { - DHLOGE("Release distributed camera buffer queue for stream %d successs.", id); + DHLOGI("Release distributed camera buffer queue for stream %d successs.", id); } stream = nullptr; halStreamMap_.erase(id); @@ -304,17 +304,18 @@ CamRetCode DStreamOperator::CancelCapture(int captureId) std::unique_lock lock(requestLock_); if (captureId < 0 || halCaptureInfoMap_.find(captureId) == halCaptureInfoMap_.end()) { - DHLOGE("Input captureId %d is exist.", captureId); + DHLOGE("Input captureId %d is not exist.", captureId); return CamRetCode::INVALID_ARGUMENT; } - SetCapturing(false); std::shared_ptr provider = DCameraProvider::GetInstance(); if (provider == nullptr) { DHLOGE("Distributed camera provider not init."); return CamRetCode::DEVICE_ERROR; } - DCamRetCode ret = provider->StopCapture(dhBase_); + + std::vector streamIds = halCaptureInfoMap_[captureId]->streamIds_; + DCamRetCode ret = provider->StopCapture(dhBase_, streamIds); if (ret != SUCCESS) { DHLOGE("Cancel distributed camera capture failed."); return MapToExternalRetCode(ret); @@ -335,9 +336,31 @@ CamRetCode DStreamOperator::CancelCapture(int captureId) if (dcStreamOperatorCallback_) { dcStreamOperatorCallback_->OnCaptureEnded(captureId, info); } - cachedDCaptureInfoList_.clear(); + halCaptureInfoMap_.erase(captureId); + bool hasContinuousCaptureInfo = false; + for (auto iter : halCaptureInfoMap_) { + for (auto id : iter.second->streamIds_) { + DHLOGI("DStreamOperator::CancelCapture, captureId=%d, streamId=%d.", captureId, id); + auto dcStreamInfo = dcStreamInfoMap_.find(id); + if (dcStreamInfo == dcStreamInfoMap_.end()) { + continue; + } + if (dcStreamInfo->second->type_ == DCStreamType::CONTINUOUS_FRAME) { + DHLOGI("DStreamOperator::CancelCapture, captureId=%d, stream %d is continuous stream.", captureId, id); + hasContinuousCaptureInfo = true; + } + } + } + + DHLOGI("DStreamOperator::CancelCapture, captureId=%d, hasContinuousCaptureInfo=%d", + captureId, hasContinuousCaptureInfo); + if (!hasContinuousCaptureInfo) { + SetCapturing(false); + cachedDCaptureInfoList_.clear(); + } + DHLOGI("DStreamOperator::CancelCapture success, captureId=%d.", captureId); return CamRetCode::NO_ERROR; } @@ -580,6 +603,19 @@ void DStreamOperator::Release() dcStreamOperatorCallback_ = nullptr; } +std::vector DStreamOperator::GetStreamIds() +{ + DHLOGI("DStreamOperator::GetStreamIds, begin get stream id."); + std::vector streamIds; + std::string idString = ""; + for (auto iter : halStreamMap_) { + streamIds.push_back(iter.first); + idString += (std::to_string(iter.first) + ", "); + } + DHLOGI("DStreamOperator::GetStreamIds, ids=[%s]", idString.c_str()); + return streamIds; +} + bool DStreamOperator::IsCapturing() { std::unique_lock lock(isCapturingLock_); @@ -618,6 +654,10 @@ void DStreamOperator::ConvertStreamInfo(std::shared_ptr &srcInfo, st DCamRetCode DStreamOperator::NegotiateSuitableCaptureInfo(const std::shared_ptr& srcCaptureInfo, bool isStreaming) { + for (auto streamId : srcCaptureInfo->streamIds_) { + DHLOGI("DStreamOperator::NegotiateSuitableCaptureInfo, streamId=%d, isStreaming=%d", streamId, isStreaming); + } + std::vector> srcStreamInfo; for (auto &id : srcCaptureInfo->streamIds_) { auto iter = dcStreamInfoMap_.find(id); @@ -659,12 +699,26 @@ DCamRetCode DStreamOperator::NegotiateSuitableCaptureInfo(const std::shared_ptr< break; } } + if (isStreaming) { + inputCaptureInfo->isCapture_ = false; + } } cachedDCaptureInfoList_.clear(); cachedDCaptureInfoList_.push_back(inputCaptureInfo); if (appendCaptureInfo != nullptr) { cachedDCaptureInfoList_.push_back(appendCaptureInfo); } + + for (auto info : cachedDCaptureInfoList_) { + std::string idString = ""; + for (auto id : info->streamIds_) { + idString += (std::to_string(id) + ", "); + } + DHLOGI("DStreamOperator::NegotiateSuitableCaptureInfo, cachedDCaptureInfo: " + + "ids=[%s], width=%d, height=%d, format=%d, type=%d, isCapture=%d", + idString.empty() ? idString.c_str() : (idString.substr(0, idString.length() - INGNORE_STR_LEN)).c_str(), + info->width_, info->height_, info->format_, info->type_, info->isCapture_); + } return SUCCESS; } diff --git a/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.cpp b/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.cpp index fb93aed1..b822feba 100644 --- a/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.cpp +++ b/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.cpp @@ -51,7 +51,8 @@ DCamRetCode DCameraProviderCallback::StartCapture(const std::shared_ptr return DCamRetCode::SUCCESS; } -DCamRetCode DCameraProviderCallback::StopCapture(const std::shared_ptr &dhBase) +DCamRetCode DCameraProviderCallback::StopCapture(const std::shared_ptr &dhBase, + const std::vector &streamIds) { DHLOGW("DCameraProviderCallback::StopCapture enter."); return DCamRetCode::SUCCESS; diff --git a/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.h b/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.h index c36cd351..d5602676 100644 --- a/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.h +++ b/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback.h @@ -34,7 +34,8 @@ public: const std::vector &streamIds) override; virtual DCamRetCode StartCapture(const std::shared_ptr &dhBase, const std::vector> &captureInfos) override; - virtual DCamRetCode StopCapture(const std::shared_ptr &dhBase) override; + virtual DCamRetCode StopCapture(const std::shared_ptr &dhBase, + const std::vector &streamIds) override; virtual DCamRetCode UpdateSettings(const std::shared_ptr &dhBase, const std::vector> &settings) override; }; diff --git a/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback_stub.cpp b/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback_stub.cpp index 607f5def..da4f979c 100644 --- a/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback_stub.cpp +++ b/camera_hdf/interfaces/hdi_ipc/client/provider/dcamera_provider_callback_stub.cpp @@ -218,7 +218,13 @@ int32_t DCameraProviderCallbackStub::DCProviderStopCaptureStub(MessageParcel &da std::shared_ptr dhBase = std::make_shared(data.ReadString(), data.ReadString()); - DCamRetCode ret = StopCapture(dhBase); + std::vector streamIds; + if (!data.ReadInt32Vector(&streamIds)) { + DHLOGE("Read streamIds failed."); + return HDF_FAILURE; + } + + DCamRetCode ret = StopCapture(dhBase, streamIds); if (!reply.WriteInt32(static_cast(ret))) { DHLOGE("Write retcode failed."); return HDF_FAILURE; diff --git a/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.cpp b/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.cpp index 7a2208b7..f49c7d30 100644 --- a/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.cpp +++ b/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.cpp @@ -201,7 +201,8 @@ DCamRetCode DCameraProviderCallbackProxy::StartCapture(const std::shared_ptr(reply.ReadInt32()); } -DCamRetCode DCameraProviderCallbackProxy::StopCapture(const std::shared_ptr &dhBase) +DCamRetCode DCameraProviderCallbackProxy::StopCapture(const std::shared_ptr &dhBase, + const std::vector &streamIds) { MessageParcel data; MessageParcel reply; @@ -217,6 +218,12 @@ DCamRetCode DCameraProviderCallbackProxy::StopCapture(const std::shared_ptr pxyStreamIds = streamIds; + if (!data.WriteInt32Vector(pxyStreamIds)) { + DHLOGE("Write streamId failed."); + return INVALID_ARGUMENT; + } + int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_STOP_CAPTURE, data, reply, option); if (ret != HDF_SUCCESS) { DHLOGE("SendRequest failed, error code is %d.", ret); diff --git a/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.h b/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.h index a7f5e3ed..d83c7359 100644 --- a/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.h +++ b/camera_hdf/interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.h @@ -36,7 +36,8 @@ public: const std::vector &streamIds); virtual DCamRetCode StartCapture(const std::shared_ptr &dhBase, const std::vector> &captureInfos); - virtual DCamRetCode StopCapture(const std::shared_ptr &dhBase); + virtual DCamRetCode StopCapture(const std::shared_ptr &dhBase, + const std::vector &streamIds); virtual DCamRetCode UpdateSettings(const std::shared_ptr &dhBase, const std::vector> &settings); diff --git a/camera_hdf/interfaces/include/idistributed_camera_provider_callback.h b/camera_hdf/interfaces/include/idistributed_camera_provider_callback.h index 6f4f5210..bce2bc45 100644 --- a/camera_hdf/interfaces/include/idistributed_camera_provider_callback.h +++ b/camera_hdf/interfaces/include/idistributed_camera_provider_callback.h @@ -136,7 +136,7 @@ public: * @since 1.0 * @version 1.0 */ - virtual DCamRetCode StopCapture(const std::shared_ptr &dhBase) = 0; + virtual DCamRetCode StopCapture(const std::shared_ptr &dhBase, const std::vector &streamIds) = 0; /** * @brief Updates distributed camera device control parameters. diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h index cb5b41d9..401ccd64 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h @@ -46,7 +46,7 @@ public: int32_t ConfigStreams(const std::vector>& streamInfos); int32_t ReleaseStreams(const std::vector& streamIds); int32_t StartCapture(const std::vector>& captureInfos); - int32_t StopCapture(); + int32_t StopCapture(const std::vector& streamIds); int32_t UpdateCameraSettings(const std::vector>& settings); void OnEvent(DCameraSourceEvent& event) override; @@ -60,7 +60,8 @@ public: virtual int32_t ExecuteReleaseStreams(std::vector& streamIds, bool& isAllRelease); virtual int32_t ExecuteReleaseAllStreams(); virtual int32_t ExecuteStartCapture(std::vector>& captureInfos); - virtual int32_t ExecuteStopCapture(); + virtual int32_t ExecuteStopCapture(std::vector& streamIds, bool& isAllStop); + virtual int32_t ExecuteStopAllCapture(); virtual int32_t ExecuteUpdateSettings(std::vector>& settings); virtual int32_t ExecuteCameraEventNotify(std::shared_ptr& events); diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_data_process.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_data_process.h index 7690058f..d5c53cff 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_data_process.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_data_process.h @@ -35,7 +35,8 @@ public: int32_t ConfigStreams(std::vector>& streamInfos) override; int32_t ReleaseStreams(std::vector& streamIds) override; int32_t StartCapture(std::shared_ptr& captureInfo) override; - int32_t StopCapture() override; + int32_t StopCapture(std::vector& streamIds) override; + int32_t GetProducerSize() override; void GetAllStreamIds(std::vector& streamIds) override; private: 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 072487c4..9ffec16c 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input.h @@ -36,7 +36,8 @@ public: int32_t ReleaseStreams(std::vector& streamIds, bool& isAllRelease) override; int32_t ReleaseAllStreams() override; int32_t StartCapture(std::vector>& captureInfos) override; - int32_t StopCapture() override; + int32_t StopCapture(std::vector& streamIds, bool& isAllStop) override; + int32_t StopAllCapture() override; int32_t OpenChannel(std::vector& indexs) override; int32_t CloseChannel() override; int32_t Init() override; @@ -57,8 +58,6 @@ private: std::shared_ptr eventBus_; bool isInit = false; - std::mutex inputMutex_; - bool isCapture_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process.h index dea0a58f..a6871969 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process.h @@ -16,6 +16,7 @@ #ifndef OHOS_DCAMERA_STREAM_DATA_PROCESS_H #define OHOS_DCAMERA_STREAM_DATA_PROCESS_H +#include #include #include "data_buffer.h" @@ -36,8 +37,9 @@ public: void ConfigStreams(std::shared_ptr& dstConfig, std::set& streamIds); void ReleaseStreams(std::set& streamIds); void StartCapture(std::shared_ptr& srcConfig, std::set& streamIds); - void StopCapture(); + void StopCapture(std::set& streamIds); void GetAllStreamIds(std::set& streamIds); + int32_t GetProducerSize(); void OnProcessedVideoBuffer(const std::shared_ptr& videoResult); void OnError(DataProcessErrorType errorType); @@ -55,6 +57,9 @@ private: std::string dhId_; DCStreamType streamType_; + std::mutex pipelineMutex_; + std::mutex producerMutex_; + std::set streamIds_; std::shared_ptr srcConfig_; std::shared_ptr dstConfig_; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.h index ebe3b9d3..f0d1c2be 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.h @@ -33,7 +33,7 @@ public: DCamRetCode ReleaseStreams(const std::shared_ptr& dhBase, const std::vector& streamIds) override; DCamRetCode StartCapture(const std::shared_ptr& dhBase, const std::vector>& captureInfos) override; - DCamRetCode StopCapture(const std::shared_ptr& dhBase) override; + DCamRetCode StopCapture(const std::shared_ptr& dhBase, const std::vector& streamIds) override; DCamRetCode UpdateSettings(const std::shared_ptr& dhBase, const std::vector>& settings) override; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_input.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_input.h index 3733723d..30b851cd 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_input.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_input.h @@ -28,7 +28,8 @@ public: virtual int32_t ReleaseStreams(std::vector& streamIds, bool& isAllRelease) = 0; virtual int32_t ReleaseAllStreams() = 0; virtual int32_t StartCapture(std::vector>& captureInfos) = 0; - virtual int32_t StopCapture() = 0; + virtual int32_t StopCapture(std::vector& streamIds, bool& isAllStop) = 0; + virtual int32_t StopAllCapture() = 0; virtual int32_t OpenChannel(std::vector& indexs) = 0; virtual int32_t CloseChannel() = 0; virtual int32_t Init() = 0; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_source_data_process.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_source_data_process.h index 12934cac..95e3a611 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_source_data_process.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_source_data_process.h @@ -59,7 +59,8 @@ public: virtual int32_t ConfigStreams(std::vector>& streamInos) = 0; virtual int32_t ReleaseStreams(std::vector& streamIds) = 0; virtual int32_t StartCapture(std::shared_ptr& captureInfo) = 0; - virtual int32_t StopCapture() = 0; + virtual int32_t StopCapture(std::vector& streamIds) = 0; + virtual int32_t GetProducerSize() = 0; virtual void GetAllStreamIds(std::vector& streamIds) = 0; }; } // namespace DistributedHardware diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index 80dd2552..7911b2d4 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -181,11 +181,11 @@ int32_t DCameraSourceDev::StartCapture(const std::vector& streamIds) { DHLOGI("DCameraSourceDev PostTask StopCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - DCameraSourceEvent event(*this, DCAMERA_EVENT_STOP_CAPTURE); + DCameraSourceEvent event(*this, DCAMERA_EVENT_STOP_CAPTURE, streamIds); eventBus_->PostEvent(event); return DCAMERA_OK; } @@ -436,19 +436,38 @@ int32_t DCameraSourceDev::ExecuteStartCapture(std::vector& streamIds, bool& isAllStop) { DHLOGI("DCameraSourceDev Execute StopCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - int32_t ret = input_->StopCapture(); + int32_t ret = input_->StopCapture(streamIds, isAllStop); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceDev Execute StopCapture input StopCapture failed, ret: %d, devId: %s dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); } + if (isAllStop) { + ret = controller_->StopCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceDev Execute StopCapture controller StopCapture failed, ret: %d, devId: %s dhId: %s", + ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + } + } + return DCAMERA_OK; +} + +int32_t DCameraSourceDev::ExecuteStopAllCapture() +{ + DHLOGI("DCameraSourceDev Execute StopAllCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), + GetAnonyString(dhId_).c_str()); + int32_t ret = input_->StopAllCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceDev Execute StopAllCapture input StopAllCapture failed, ret: %d, devId: %s dhId: %s", + ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + } ret = controller_->StopCapture(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceDev Execute StopCapture controller StopCapture failed, ret: %d, devId: %s dhId: %s", ret, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + DHLOGE("DCameraSourceDev Execute StopAllCapture controller StopAllCapture failed, ret: %d, devId: %s dhId: %s", + ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); } return DCAMERA_OK; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp index 73497f80..04d483d1 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp @@ -128,10 +128,10 @@ int32_t DCameraSourceDataProcess::ReleaseStreams(std::vector& streamIds int32_t DCameraSourceDataProcess::StartCapture(std::shared_ptr& captureInfo) { - DHLOGI("DCameraSourceDataProcess StartCapture devId %s dhId %s, info: width: %d, height: %d, format: %d,\ - dataspace: %d, encodeType: %d streamType: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), - captureInfo->width_, captureInfo->height_, captureInfo->format_, captureInfo->dataspace_, - captureInfo->encodeType_, captureInfo->type_); + DHLOGI("DCameraSourceDataProcess StartCapture devId %s dhId %s width: %d, height: %d, format: %d, isCapture: %d," + + "dataspace: %d, encodeType: %d, streamType: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), + captureInfo->width_, captureInfo->height_, captureInfo->format_, captureInfo->isCapture_, + captureInfo->dataspace_, captureInfo->encodeType_, captureInfo->type_); std::shared_ptr streamConfig = std::make_shared(captureInfo->width_, captureInfo->height_, captureInfo->format_, @@ -147,16 +147,34 @@ int32_t DCameraSourceDataProcess::StartCapture(std::shared_ptr& c return DCAMERA_OK; } -int32_t DCameraSourceDataProcess::StopCapture() +int32_t DCameraSourceDataProcess::StopCapture(std::vector& streamIds) { DHLOGI("DCameraSourceDataProcess StopCapture devId %s dhId %s streamType: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_); + std::set streamIdSet(streamIds.begin(), streamIds.end()); + for (auto iterSet = streamIdSet.begin(); iterSet != streamIdSet.end(); iterSet++) { + DHLOGI("DCameraSourceDataProcess StopCapture devId %s dhId %s stream id: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), *iterSet); + } for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { - (*iter)->StopCapture(); + (*iter)->StopCapture(streamIdSet); } return DCAMERA_OK; } +int32_t DCameraSourceDataProcess::GetProducerSize() +{ + int32_t ret = 0; + for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { + std::shared_ptr streamDataProcess = *iter; + int32_t size = streamDataProcess->GetProducerSize(); + ret += size; + } + DHLOGI("DCameraSourceDataProcess GetProducerSize devId %s dhId %s size %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), ret); + return ret; +} + void DCameraSourceDataProcess::GetAllStreamIds(std::vector& streamIds) { streamIds.assign(streamIds_.begin(), streamIds_.end()); 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 c1de16dc..89cca1d2 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp @@ -28,7 +28,7 @@ namespace OHOS { namespace DistributedHardware { DCameraSourceInput::DCameraSourceInput(std::string devId, std::string dhId, std::shared_ptr& eventBus) - : devId_(devId), dhId_(dhId), eventBus_(eventBus), isInit(false), isCapture_(false) + : devId_(devId), dhId_(dhId), eventBus_(eventBus), isInit(false) { DHLOGI("DCameraSourceInput Constructor devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); @@ -148,29 +148,29 @@ int32_t DCameraSourceInput::StartCapture(std::vector autoLock(inputMutex_); - isCapture_ = true; return DCAMERA_OK; } -int32_t DCameraSourceInput::StopCapture() +int32_t DCameraSourceInput::StopCapture(std::vector& streamIds, bool& isAllStop) { DHLOGI("DCameraSourceInput StopCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - std::lock_guard autoLock(inputMutex_); - isCapture_ = false; - int32_t ret = dataProcess_[CONTINUOUS_FRAME]->StopCapture(); + int32_t ret = dataProcess_[CONTINUOUS_FRAME]->StopCapture(streamIds); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceInput StopCapture continue ret: %d, devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); return ret; } - ret = dataProcess_[SNAPSHOT_FRAME]->StopCapture(); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceInput StopCapture snapshot ret: %d, devId: %s, dhId: %s", ret, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - return ret; + int32_t size = dataProcess_[CONTINUOUS_FRAME]->GetProducerSize(); + if (size == 0) { + isAllStop = true; + ret = dataProcess_[SNAPSHOT_FRAME]->StopCapture(streamIds); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput StopCapture snapshot ret: %d, devId: %s, dhId: %s", ret, + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + return ret; + } } return DCAMERA_OK; } @@ -337,12 +337,6 @@ void DCameraSourceInput::OnSessionError(DCStreamType streamType, int32_t eventTy void DCameraSourceInput::OnDataReceived(DCStreamType streamType, std::vector>& buffers) { - std::lock_guard autoLock(inputMutex_); - if (!isCapture_) { - DHLOGE("DCameraSourceInput OnDataReceived FeedStream %d stream capture stop, devId: %s, dhId: %s", streamType, - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - return; - } int32_t ret = dataProcess_[streamType]->FeedStream(buffers); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceInput OnDataReceived FeedStream %d stream failed ret: %d, devId: %s, dhId: %s", streamType, @@ -373,5 +367,29 @@ int32_t DCameraSourceInput::ReleaseAllStreams() } return DCAMERA_OK; } + +int32_t DCameraSourceInput::StopAllCapture() +{ + DHLOGI("DCameraSourceInput StopAllCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), + GetAnonyString(dhId_).c_str()); + std::vector continueStreamIds; + dataProcess_[CONTINUOUS_FRAME]->GetAllStreamIds(continueStreamIds); + int32_t ret = dataProcess_[CONTINUOUS_FRAME]->StopCapture(continueStreamIds); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput StopAllCapture continue ret: %d, devId: %s, dhId: %s", ret, + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + return ret; + } + + std::vector snapStreamIds; + dataProcess_[SNAPSHOT_FRAME]->GetAllStreamIds(snapStreamIds); + ret = dataProcess_[SNAPSHOT_FRAME]->StopCapture(snapStreamIds); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceInput StopAllCapture snapshot ret: %d, devId: %s, dhId: %s", ret, + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + return ret; + } + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp index ac683661..ace5b3ec 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp @@ -74,6 +74,9 @@ void DCameraStreamDataProcess::ConfigStreams(std::shared_ptr& streamIds) { + DHLOGI("DCameraStreamDataProcess ReleaseStreams devId %s dhId %s streamType: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_); + std::lock_guard autoLock(producerMutex_); for (auto iter = streamIds.begin(); iter != streamIds.end(); iter++) { int32_t streamId = *iter; DHLOGI("DCameraStreamDataProcess ReleaseStreams devId %s dhId %s streamId: %d", GetAnonyString(devId_).c_str(), @@ -91,14 +94,20 @@ void DCameraStreamDataProcess::ReleaseStreams(std::set& streamIds) void DCameraStreamDataProcess::StartCapture(std::shared_ptr& srcConfig, std::set& streamIds) { + for (auto iter = streamIds.begin(); iter != streamIds.end(); iter++) { + DHLOGI("DCameraStreamDataProcess StartCapture devId %s dhId %s streamType: %d streamId: %d, " + + "srcConfig: width: %d, height: %d, format: %d, dataspace: %d, streamType: %d, encodeType: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, *iter, + srcConfig->width_, srcConfig->height_, srcConfig->format_, srcConfig->dataspace_, + srcConfig->type_, srcConfig->encodeType_); + } + std::lock_guard autoLock(producerMutex_); srcConfig_ = srcConfig; if (streamType_ == CONTINUOUS_FRAME) { CreatePipeline(); } for (auto iter = streamIds_.begin(); iter != streamIds_.end(); iter++) { uint32_t streamId = *iter; - DHLOGI("DCameraStreamDataProcess StartCapture devId %s dhId %s streamType: %d streamId: %d", - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId); if (streamIds.find(streamId) == streamIds.end()) { continue; } @@ -116,17 +125,34 @@ void DCameraStreamDataProcess::StartCapture(std::shared_ptr } } -void DCameraStreamDataProcess::StopCapture() +void DCameraStreamDataProcess::StopCapture(std::set& streamIds) { - DHLOGI("DCameraStreamDataProcess StopCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), - GetAnonyString(dhId_).c_str()); - if (streamType_ == CONTINUOUS_FRAME) { - DestroyPipeline(); + for (auto iter = streamIds.begin(); iter != streamIds.end(); iter++) { + DHLOGI("DCameraStreamDataProcess StopCapture devId %s dhId %s streamType: %d streamId: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, *iter); + } + std::lock_guard autoLock(producerMutex_); + for (auto iter = streamIds_.begin(); iter != streamIds_.end(); iter++) { + uint32_t streamId = *iter; + if (streamIds.find(streamId) == streamIds.end()) { + continue; + } + + DHLOGI("DCameraStreamDataProcess StopCapture findProducer devId %s dhId %s streamType: %d streamId: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId); + auto producerIter = producers_.find(streamId); + if (producerIter == producers_.end()) { + DHLOGE("DCameraStreamDataProcess StopCapture no producer, devId %s dhId %s streamType: %d streamId: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId); + continue; + } + DHLOGI("DCameraStreamDataProcess StopCapture stop producer, devId %s dhId %s streamType: %d streamId: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId); + producerIter->second->Stop(); + producerIter = producers_.erase(producerIter); } - auto iter = producers_.begin(); - while (iter != producers_.end()) { - iter->second->Stop(); - iter = producers_.erase(iter); + if (streamType_ == CONTINUOUS_FRAME && producers_.empty()) { + DestroyPipeline(); } } @@ -135,10 +161,19 @@ void DCameraStreamDataProcess::GetAllStreamIds(std::set& streamIds) streamIds = streamIds_; } +int32_t DCameraStreamDataProcess::GetProducerSize() +{ + DHLOGI("DCameraStreamDataProcess GetProducerSize devId %s dhId %s", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + std::lock_guard autoLock(producerMutex_); + return producers_.size(); +} + void DCameraStreamDataProcess::FeedStreamToSnapShot(const std::shared_ptr& buffer) { DHLOGD("DCameraStreamDataProcess FeedStreamToSnapShot devId %s dhId %s streamType %d streamSize: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, buffer->Size()); + std::lock_guard autoLock(producerMutex_); for (auto iter = producers_.begin(); iter != producers_.end(); iter++) { iter->second->FeedStream(buffer); } @@ -148,6 +183,7 @@ void DCameraStreamDataProcess::FeedStreamToContinue(const std::shared_ptrSize()); + std::lock_guard autoLock(pipelineMutex_); std::vector> buffers; buffers.push_back(buffer); if (pipeline_ == nullptr) { @@ -165,6 +201,7 @@ void DCameraStreamDataProcess::OnProcessedVideoBuffer(const std::shared_ptrSize()); + std::lock_guard autoLock(producerMutex_); for (auto iter = producers_.begin(); iter != producers_.end(); iter++) { iter->second->FeedStream(videoResult); } @@ -177,6 +214,9 @@ void DCameraStreamDataProcess::OnError(DataProcessErrorType errorType) void DCameraStreamDataProcess::CreatePipeline() { + DHLOGI("DCameraStreamDataProcess CreatePipeline devId %s dhId %s", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + std::lock_guard autoLock(pipelineMutex_); if (pipeline_ != nullptr) { DHLOGI("DCameraStreamDataProcess CreatePipeline already exist, devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); @@ -197,6 +237,9 @@ void DCameraStreamDataProcess::CreatePipeline() void DCameraStreamDataProcess::DestroyPipeline() { + DHLOGI("DCameraStreamDataProcess DestroyPipeline devId %s dhId %s", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + std::lock_guard autoLock(pipelineMutex_); if (pipeline_ == nullptr) { return; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp index 98195202..f2aabfe1 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp @@ -178,8 +178,8 @@ void DCameraStreamDataProcessProducer::LooperSnapShot() int32_t DCameraStreamDataProcessProducer::FeedStreamToDriver(const std::shared_ptr& dhBase, const std::shared_ptr& buffer) { - DHLOGD("LooperFeed devId %s dhId %s streamSize: %d streamType: %d", GetAnonyString(devId_).c_str(), - GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_); + DHLOGD("LooperFeed devId %s dhId %s streamSize: %d streamType: %d, streamId: %d", GetAnonyString(devId_).c_str(), + GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_, streamId_); sptr camHdiProvider = IDCameraProvider::Get(); if (camHdiProvider == nullptr) { DHLOGI("camHdiProvider is nullptr"); @@ -227,8 +227,8 @@ int32_t DCameraStreamDataProcessProducer::FeedStreamToDriver(const std::shared_p GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, retHdi); return DCAMERA_BAD_OPERATE; } - DHLOGD("LooperFeed end devId %s dhId %s streamSize: %d streamType: %d", GetAnonyString(devId_).c_str(), - GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_); + DHLOGD("LooperFeed end devId %s dhId %s streamSize: %d streamType: %d, streamId: %d", GetAnonyString(devId_).c_str(), + GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_, streamId_); return ret; } } // namespace DistributedHardware diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.cpp index f0014a5b..20d7f303 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.cpp @@ -139,7 +139,8 @@ DCamRetCode DCameraProviderCallbackImpl::StartCapture(const std::shared_ptr& dhBase) +DCamRetCode DCameraProviderCallbackImpl::StopCapture(const std::shared_ptr& dhBase, + const std::vector& streamIds) { DHLOGI("DCameraProviderCallbackImpl StopCapture devId: %s dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); @@ -149,7 +150,7 @@ DCamRetCode DCameraProviderCallbackImpl::StopCapture(const std::shared_ptrStopCapture(); + int32_t ret = sourceDev->StopCapture(streamIds); if (ret != DCAMERA_OK) { DHLOGE("DCameraProviderCallbackImpl StopCapture failed, ret: %d, devId: %s, dhId: %s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp index 8823d109..cbc7e26c 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp @@ -75,9 +75,9 @@ int32_t DCameraSourceCaptureState::DoUnregisterTask(std::shared_ptrExecuteStopCapture(); + ret = camDev->ExecuteStopAllCapture(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceCaptureState DoUnregisterTask ExecuteStopCapture failed: %d", ret); + DHLOGE("DCameraSourceCaptureState DoUnregisterTask ExecuteStopAllCapture failed: %d", ret); return ret; } @@ -120,9 +120,9 @@ int32_t DCameraSourceCaptureState::DoOpenTask(std::shared_ptr& int32_t DCameraSourceCaptureState::DoCloseTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { - int32_t ret = camDev->ExecuteStopCapture(); + int32_t ret = camDev->ExecuteStopAllCapture(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceCaptureState ExecuteStopCapture failed, ret: %d", ret); + DHLOGE("DCameraSourceCaptureState ExecuteStopAllCapture failed, ret: %d", ret); return ret; } @@ -166,17 +166,27 @@ int32_t DCameraSourceCaptureState::DoStartCaptureTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { - int32_t ret = camDev->ExecuteStopCapture(); + std::vector streamIds; + int32_t ret = event.GetStreamIds(streamIds); + if (ret != DCAMERA_OK) { + return ret; + } + + bool isAllStop = false; + ret = camDev->ExecuteStopCapture(streamIds, isAllStop); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceCaptureState ExecuteStopCapture failed, ret: %d", ret); return ret; } - std::shared_ptr stateMachine = stateMachine_.lock(); - if (stateMachine == nullptr) { - DHLOGE("DCameraSourceCaptureState DoStopCaptureTask can not get stateMachine"); - return DCAMERA_BAD_VALUE; + + if (isAllStop) { + std::shared_ptr stateMachine = stateMachine_.lock(); + if (stateMachine == nullptr) { + DHLOGE("DCameraSourceCaptureState DoStopCaptureTask can not get stateMachine"); + return DCAMERA_BAD_VALUE; + } + stateMachine->UpdateState(DCAMERA_STATE_CONFIG_STREAM); } - stateMachine->UpdateState(DCAMERA_STATE_CONFIG_STREAM); return DCAMERA_OK; } -- Gitee From 0037c7e5b93f74ff004ae056cc107f5882b548e3 Mon Sep 17 00:00:00 2001 From: zhuxu Date: Mon, 16 May 2022 17:27:33 +0800 Subject: [PATCH 2/5] support distributed camera video recording mode Signed-off-by: zhuxu --- .../dstream_operator/dstream_operator.h | 1 + .../src/dstream_operator/dstream_operator.cpp | 48 ++++++++----------- .../dcamera_stream_data_process_producer.cpp | 4 +- .../mock_dcamera_source_dev.h | 6 ++- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h b/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h index 3d259f6a..9b099882 100644 --- a/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h +++ b/camera_hdf/hdi_impl/include/dstream_operator/dstream_operator.h @@ -84,6 +84,7 @@ private: std::shared_ptr BuildSuitableCaptureInfo(const shared_ptr& srcCaptureInfo, std::vector> &srcStreamInfo); void SnapShotStreamOnCaptureEnded(int32_t captureId, int streamId); + bool HasContinuousCaptureInfo(int captureId); private: std::shared_ptr dMetadataProcessor_; diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp index 894d098e..3014f314 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -338,30 +338,35 @@ CamRetCode DStreamOperator::CancelCapture(int captureId) } halCaptureInfoMap_.erase(captureId); + if (!HasContinuousCaptureInfo(captureId)) { + SetCapturing(false); + cachedDCaptureInfoList_.clear(); + } + DHLOGI("DStreamOperator::CancelCapture success, captureId=%d.", captureId); + return CamRetCode::NO_ERROR; +} - bool hasContinuousCaptureInfo = false; +bool DStreamOperator::HasContinuousCaptureInfo(int captureId) +{ + bool flag = false; for (auto iter : halCaptureInfoMap_) { for (auto id : iter.second->streamIds_) { - DHLOGI("DStreamOperator::CancelCapture, captureId=%d, streamId=%d.", captureId, id); auto dcStreamInfo = dcStreamInfoMap_.find(id); if (dcStreamInfo == dcStreamInfoMap_.end()) { continue; } - if (dcStreamInfo->second->type_ == DCStreamType::CONTINUOUS_FRAME) { - DHLOGI("DStreamOperator::CancelCapture, captureId=%d, stream %d is continuous stream.", captureId, id); - hasContinuousCaptureInfo = true; + + DHLOGI("DStreamOperator::HasContinuousCaptureInfo, captureId=%d, streamId=%d, streamType=%d", + captureId, id, dcStreamInfo.second->type_); + if (dcStreamInfo.second->type_ == DCStreamType::CONTINUOUS_FRAME) { + DHLOGI("DStreamOperator::HasContinuousCaptureInfo, captureId=%d, stream %d is continuous stream.", + captureId, id); + flag = true; + break; } } } - - DHLOGI("DStreamOperator::CancelCapture, captureId=%d, hasContinuousCaptureInfo=%d", - captureId, hasContinuousCaptureInfo); - if (!hasContinuousCaptureInfo) { - SetCapturing(false); - cachedDCaptureInfoList_.clear(); - } - DHLOGI("DStreamOperator::CancelCapture success, captureId=%d.", captureId); - return CamRetCode::NO_ERROR; + return flag; } CamRetCode DStreamOperator::ChangeToOfflineStream(const std::vector& streamIds, @@ -654,10 +659,6 @@ void DStreamOperator::ConvertStreamInfo(std::shared_ptr &srcInfo, st DCamRetCode DStreamOperator::NegotiateSuitableCaptureInfo(const std::shared_ptr& srcCaptureInfo, bool isStreaming) { - for (auto streamId : srcCaptureInfo->streamIds_) { - DHLOGI("DStreamOperator::NegotiateSuitableCaptureInfo, streamId=%d, isStreaming=%d", streamId, isStreaming); - } - std::vector> srcStreamInfo; for (auto &id : srcCaptureInfo->streamIds_) { auto iter = dcStreamInfoMap_.find(id); @@ -708,17 +709,6 @@ DCamRetCode DStreamOperator::NegotiateSuitableCaptureInfo(const std::shared_ptr< if (appendCaptureInfo != nullptr) { cachedDCaptureInfoList_.push_back(appendCaptureInfo); } - - for (auto info : cachedDCaptureInfoList_) { - std::string idString = ""; - for (auto id : info->streamIds_) { - idString += (std::to_string(id) + ", "); - } - DHLOGI("DStreamOperator::NegotiateSuitableCaptureInfo, cachedDCaptureInfo: " + - "ids=[%s], width=%d, height=%d, format=%d, type=%d, isCapture=%d", - idString.empty() ? idString.c_str() : (idString.substr(0, idString.length() - INGNORE_STR_LEN)).c_str(), - info->width_, info->height_, info->format_, info->type_, info->isCapture_); - } return SUCCESS; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp index f2aabfe1..bd611bc8 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp @@ -227,8 +227,8 @@ int32_t DCameraStreamDataProcessProducer::FeedStreamToDriver(const std::shared_p GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, retHdi); return DCAMERA_BAD_OPERATE; } - DHLOGD("LooperFeed end devId %s dhId %s streamSize: %d streamType: %d, streamId: %d", GetAnonyString(devId_).c_str(), - GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_, streamId_); + DHLOGD("LooperFeed end devId %s dhId %s streamSize: %d streamType: %d, streamId: %d", + GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_, streamId_); return ret; } } // namespace DistributedHardware diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h index 78480d94..0925195c 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h @@ -61,7 +61,11 @@ public: { return DCAMERA_OK; } - int32_t ExecuteStopCapture() + int32_t ExecuteStopCapture(std::vector& streamIds, bool& isAllStop) + { + return DCAMERA_OK; + } + int32_t ExecuteStopAllCapture() { return DCAMERA_OK; } -- Gitee From 4d0f120d62eeb807daefaa8c5822fe49ed8f6fef Mon Sep 17 00:00:00 2001 From: zhuxu Date: Mon, 16 May 2022 17:40:06 +0800 Subject: [PATCH 3/5] support distributed camera video recording mode Signed-off-by: zhuxu --- camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp index 3014f314..c8e678b9 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -357,8 +357,8 @@ bool DStreamOperator::HasContinuousCaptureInfo(int captureId) } DHLOGI("DStreamOperator::HasContinuousCaptureInfo, captureId=%d, streamId=%d, streamType=%d", - captureId, id, dcStreamInfo.second->type_); - if (dcStreamInfo.second->type_ == DCStreamType::CONTINUOUS_FRAME) { + captureId, id, dcStreamInfo->second->type_); + if (dcStreamInfo->second->type_ == DCStreamType::CONTINUOUS_FRAME) { DHLOGI("DStreamOperator::HasContinuousCaptureInfo, captureId=%d, stream %d is continuous stream.", captureId, id); flag = true; -- Gitee From ad32c223ca897f08b545fb264719aa86320817f8 Mon Sep 17 00:00:00 2001 From: zhuxu Date: Mon, 16 May 2022 20:54:19 +0800 Subject: [PATCH 4/5] support distributed camera video recording mode Signed-off-by: zhuxu --- .../dcamera_source_state_machine_test.cpp | 4 ++-- .../common/distributedcameramgr/mock_dcamera_source_dev.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_state_machine_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_state_machine_test.cpp index 2e736ff5..cadfb7c9 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_state_machine_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_state_machine_test.cpp @@ -272,7 +272,7 @@ HWTEST_F(DCameraSourceStateMachineTest, dcamera_source_state_machine_test_004, T DCameraSourceEvent event4(*camDev_, DCAMERA_EVENT_CONFIG_STREAMS, g_streamInfosSnap); DCameraSourceEvent event5(*camDev_, DCAMERA_EVENT_RELEASE_STREAMS, g_streamIdSnap); DCameraSourceEvent event6(*camDev_, DCAMERA_EVENT_START_CAPTURE, g_captureInfoSnap); - DCameraSourceEvent event7(*camDev_, DCAMERA_EVENT_STOP_CAPTURE); + DCameraSourceEvent event7(*camDev_, DCAMERA_EVENT_STOP_CAPTURE, g_streamIdSnap); DCameraSourceEvent event8(*camDev_, DCAMERA_EVENT_UPDATE_SETTINGS, g_cameraSettingSnap); DCameraSourceEvent event9(*camDev_, DCAMERA_EVENT_NOFIFY, g_camEvent); stateMachine_ ->UpdateState(DCAMERA_STATE_INIT); @@ -323,7 +323,7 @@ HWTEST_F(DCameraSourceStateMachineTest, dcamera_source_state_machine_test_005, T DCameraSourceEvent event2(*camDev_, DCAMERA_EVENT_OPEN, g_camIndex); DCameraSourceEvent event3(*camDev_, DCAMERA_EVENT_CLOSE, g_camIndex); DCameraSourceEvent event6(*camDev_, DCAMERA_EVENT_START_CAPTURE, g_captureInfoSnap); - DCameraSourceEvent event7(*camDev_, DCAMERA_EVENT_STOP_CAPTURE); + DCameraSourceEvent event7(*camDev_, DCAMERA_EVENT_STOP_CAPTURE, g_streamIdSnap); DCameraSourceEvent event8(*camDev_, DCAMERA_EVENT_UPDATE_SETTINGS, g_cameraSettingSnap); DCameraSourceEvent event9(*camDev_, DCAMERA_EVENT_NOFIFY, g_camEvent); stateMachine_ ->UpdateState(DCAMERA_STATE_INIT); diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h index 0925195c..29b637b0 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_dev.h @@ -51,6 +51,7 @@ public: } int32_t ExecuteReleaseStreams(std::vector& streamIds, bool& isAllRelease) { + isAllRelease = true; return DCAMERA_OK; } int32_t ExecuteReleaseAllStreams() @@ -63,6 +64,7 @@ public: } int32_t ExecuteStopCapture(std::vector& streamIds, bool& isAllStop) { + isAllStop = true; return DCAMERA_OK; } int32_t ExecuteStopAllCapture() -- Gitee From ab9940b3982f9f9c9e9327a3cb0327dc4bdc4846 Mon Sep 17 00:00:00 2001 From: zhuxu Date: Wed, 18 May 2022 09:12:34 +0800 Subject: [PATCH 5/5] support distributed camera video recording mode Signed-off-by: zhuxu --- .../src/dcamera_device/dcamera_device.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp index 35072c70..a84061ca 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp @@ -224,11 +224,9 @@ void DCameraDevice::Close() DHLOGI("DCameraDevice::Close distributed camera: %s", dCameraId_.c_str()); std::shared_ptr provider = DCameraProvider::GetInstance(); - if (provider != nullptr) { - if (dCameraStreamOperator_ != nullptr) { - std::vector streamIds = dCameraStreamOperator_->GetStreamIds(); - provider->StopCapture(dhBase_, streamIds); - } + if ((provider != nullptr) && (dCameraStreamOperator_ != nullptr)) { + std::vector streamIds = dCameraStreamOperator_->GetStreamIds(); + provider->StopCapture(dhBase_, streamIds); } if (dCameraStreamOperator_ != nullptr) { dCameraStreamOperator_->Release(); @@ -396,11 +394,9 @@ DCamRetCode DCameraDevice::Notify(const std::shared_ptr &event) dCameraDeviceCallback_->OnError(ErrorType::REQUEST_TIMEOUT, 0); } std::shared_ptr provider = DCameraProvider::GetInstance(); - if (provider != nullptr) { - if (dCameraStreamOperator_ != nullptr) { - std::vector streamIds = dCameraStreamOperator_->GetStreamIds(); - provider->StopCapture(dhBase_, streamIds); - } + if ((provider != nullptr) && (dCameraStreamOperator_ != nullptr)) { + std::vector streamIds = dCameraStreamOperator_->GetStreamIds(); + provider->StopCapture(dhBase_, streamIds); } if (dCameraStreamOperator_ != nullptr) { dCameraStreamOperator_->Release(); -- Gitee