diff --git a/services/screentransport/screensourcetrans/include/screen_source_trans.h b/services/screentransport/screensourcetrans/include/screen_source_trans.h index 667212b3459818258f1f25389995d114969b16f7..5add1de5a3651761aa48e0d4aa9cd85698a72e4b 100644 --- a/services/screentransport/screensourcetrans/include/screen_source_trans.h +++ b/services/screentransport/screensourcetrans/include/screen_source_trans.h @@ -76,6 +76,9 @@ private: sptr encoderSurface_; std::queue> dataQueue_; + int32_t sessionNum_ = 0; + std::mutex sessionNumMutex_; + std::shared_ptr imageProcessor_; std::shared_ptr screenChannel_; std::weak_ptr transCallback_; diff --git a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp index 2ad9f920a308cc616a4b65d7e378f732641ae2f1..50929c1ab4b078f2620026540a6bd473ffcbfe16 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -60,6 +60,15 @@ int32_t ScreenSourceTrans::Release() } imageProcessor_ = nullptr; + { + std::lock_guard sessionNumLock(sessionNumMutex_); + sessionNum_--; + if (sessionNum_ != 0) { + DHLOGI("%s: opened session number is %d.", LOG_TAG, sessionNum_); + return DH_SUCCESS; + } + } + StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_SOURCE_RELEASE_SESSION_START); ret = screenChannel_->ReleaseSession(); FinishTrace(DSCREEN_HITRACE_LABEL); @@ -92,6 +101,11 @@ int32_t ScreenSourceTrans::Start() return ret; } + { + std::lock_guard sessionNumLock(sessionNumMutex_); + sessionNum_++; + } + DHLOGI("%s: Wait for channel session opened.", LOG_TAG); std::unique_lock lck(sessionMtx_); auto status =