diff --git a/services/engine/histreamer/recorder/hirecorder_impl.cpp b/services/engine/histreamer/recorder/hirecorder_impl.cpp index a72e90047f6f3807354dfb0aae2f52d0d6d08f9d..24f6fde719c7c49d43f39cbbc7a170db93bccff0 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.cpp +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -29,15 +29,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_; }; @@ -45,16 +58,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_; }; @@ -62,18 +88,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) { - if (hiRecorderImpl_) { - hiRecorderImpl_->OnAudioCaptureChange(capturerChangeInfo); - } + 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_); } @@ -349,8 +395,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 f0974a95d94b08530b4490d8a3b17fa85c3aaf9a..1a9c68c5405c6252134aa8e4f4edcba13b9a2213 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); @@ -132,7 +133,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;