diff --git a/services/engine/histreamer/recorder/hirecorder_impl.cpp b/services/engine/histreamer/recorder/hirecorder_impl.cpp index d9a096122fadc6f7168d3dcb39c3346f30fec773..3a851f7a3333be39d902402db86938ed56d731dd 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.cpp +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -30,15 +30,28 @@ class RecorderEventReceiver : public Pipeline::EventReceiver { public: explicit RecorderEventReceiver(HiRecorderImpl *hiRecorderImpl) { + MEDIA_LOG_I("RecorderEventReceiver ctor called."); + std::unique_lock lk(cbMutex_); hiRecorderImpl_ = hiRecorderImpl; } - void OnEvent(const Event &event) + void OnEvent(const Event &event) override { + MEDIA_LOG_D("RecorderEventReceiver OnEvent."); + std::shared_lock lk(cbMutex_); + FALSE_RETURN_MSG(hiRecorderImpl_ != nullptr, "hiRecorderImpl_ is nullptr"); hiRecorderImpl_->OnEvent(event); } + void NotifyRelease() override + { + MEDIA_LOG_D("RecorderEventReceiver NotifyRelease."); + std::unique_lock lk(cbMutex_); + hiRecorderImpl_ = nullptr; + } + private: + std::shared_mutex cbMutex_ {}; HiRecorderImpl *hiRecorderImpl_; }; @@ -46,16 +59,29 @@ class RecorderFilterCallback : public Pipeline::FilterCallback { public: explicit RecorderFilterCallback(HiRecorderImpl *hiRecorderImpl) { + MEDIA_LOG_I("RecorderFilterCallback ctor called."); + std::unique_lock lk(cbMutex_); hiRecorderImpl_ = hiRecorderImpl; } Status OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, - Pipeline::StreamType outType) + Pipeline::StreamType outType) override { + MEDIA_LOG_D("RecorderFilterCallback OnCallBack."); + std::shared_lock lk(cbMutex_); + FALSE_RETURN_V_MSG(hiRecorderImpl_ != nullptr, Status::OK, "hiRecorderImpl_ is nullptr"); return hiRecorderImpl_->OnCallback(filter, cmd, outType); } + void NotifyRelease() override + { + MEDIA_LOG_D("RecorderFilterCallback NotifyRelease."); + std::unique_lock lk(cbMutex_); + hiRecorderImpl_ = nullptr; + } + private: + std::shared_mutex cbMutex_ {}; HiRecorderImpl *hiRecorderImpl_; }; @@ -63,18 +89,29 @@ class CapturerInfoChangeCallback : public AudioStandard::AudioCapturerInfoChange public: explicit CapturerInfoChangeCallback(HiRecorderImpl *hiRecorderImpl) { + MEDIA_LOG_I("CapturerInfoChangeCallback ctor called."); + std::unique_lock lk(cbMutex_); hiRecorderImpl_ = hiRecorderImpl; } void OnStateChange(const AudioStandard::AudioCapturerChangeInfo &capturerChangeInfo) { - FALSE_RETURN_MSG(hiRecorderImpl_ != nullptr, "hiRecorderImpl_ is nullptr"); MEDIA_LOG_I("CapturerInfoChangeCallback hiRecorderImpl_->OnAudioCaptureChange start."); + std::shared_lock lk(cbMutex_); + FALSE_RETURN_MSG(hiRecorderImpl_ != nullptr, "hiRecorderImpl_ is nullptr"); hiRecorderImpl_->OnAudioCaptureChange(capturerChangeInfo); } + void NotifyRelease() + { + MEDIA_LOG_D("CapturerInfoChangeCallback NotifyRelease."); + std::unique_lock lk(cbMutex_); + hiRecorderImpl_ = nullptr; + } + private: HiRecorderImpl *hiRecorderImpl_; + std::shared_mutex cbMutex_ {}; }; static inline MetaSourceType GetMetaSourceType(int32_t sourceId) @@ -90,6 +127,15 @@ HiRecorderImpl::HiRecorderImpl(int32_t appUid, int32_t appPid, uint32_t appToken HiRecorderImpl::~HiRecorderImpl() { + if (recorderCallback_ != nullptr) { + recorderCallback_->NotifyRelease(); + } + if (recorderEventReceiver_ != nullptr) { + recorderEventReceiver_->NotifyRelease(); + } + if (capturerInfoChangeCallback_ != nullptr) { + capturerInfoChangeCallback_->NotifyRelease(); + } Stop(false); PipeLineThreadPool::GetInstance().DestroyThread(recorderId_); } @@ -351,8 +397,8 @@ int32_t HiRecorderImpl::Prepare() audioEncFormat_->Set(Plugins::AudioSampleFormat::SAMPLE_S16LE); audioCaptureFilter_->SetParameter(audioEncFormat_); audioCaptureFilter_->Init(recorderEventReceiver_, recorderCallback_); - CapturerInfoChangeCallback_ = std::make_shared(this); - audioCaptureFilter_->SetAudioCaptureChangeCallback(CapturerInfoChangeCallback_); + capturerInfoChangeCallback_ = std::make_shared(this); + audioCaptureFilter_->SetAudioCaptureChangeCallback(capturerInfoChangeCallback_); } if (audioDataSourceFilter_) { audioEncFormat_->Set(appTokenId_); diff --git a/services/engine/histreamer/recorder/hirecorder_impl.h b/services/engine/histreamer/recorder/hirecorder_impl.h index b037fc950f48532c288adace2198224da74eaa6e..7ac6378dd6440b74eb7e656c584ad49e97058d0e 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.h +++ b/services/engine/histreamer/recorder/hirecorder_impl.h @@ -51,6 +51,7 @@ enum class StateId { const std::string AUIDO_TYPE = "audio"; const std::string VIDEO_TYPE = "video"; +class CapturerInfoChangeCallback; class HiRecorderImpl : public IRecorderEngine { public: HiRecorderImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId); @@ -133,7 +134,7 @@ private: std::map> metaDataFilters_; std::map> metaDataFormats_; - std::shared_ptr CapturerInfoChangeCallback_; + std::shared_ptr capturerInfoChangeCallback_; std::weak_ptr obs_{}; OutputFormatType outputFormatType_{OutputFormatType::FORMAT_BUTT}; int32_t fd_ = -1;