From 2de04ce0225a0bb5a1ddd06940fbc9ed9ff61e4a Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Mon, 18 Jul 2022 11:37:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E5=A4=9A=E5=8F=B0=E8=AE=BE=E5=A4=87=E5=90=8C=E6=97=B6=E6=96=AD?= =?UTF-8?q?=E5=BC=80=E6=8A=95=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- .../include/screen_data_channel_impl.h | 3 +++ .../screendatachannel/src/screen_data_channel_impl.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h index 9ec16416..1fa438ea 100644 --- a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h +++ b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h @@ -17,6 +17,7 @@ #define OHOS_SCREEN_DATA_CHANNEL_IMPL_H #include +#include #include #include "data_buffer.h" @@ -49,6 +50,8 @@ private: const std::string peerDevId_; int32_t sessionId_ = 0; + int32_t sessionNum_ = 0; + std::mutex sessionNumMutex_; std::weak_ptr channelListener_; }; } // namespace DistributedHardware diff --git a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp index 8a1c390a..4db0181a 100644 --- a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp +++ b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp @@ -55,6 +55,14 @@ int32_t ScreenDataChannelImpl::CreateSession(const std::shared_ptr sessionNumLock(sessionNumMutex_); + sessionNum_--; + if (sessionNum_ != 0) { + DHLOGI("%s: opened session number isn't zero", LOG_TAG); + return DH_SUCCESS; + } + } int32_t ret = SoftbusAdapter::GetInstance().RemoveSoftbusSessionServer(PKG_NAME, DATA_SESSION_NAME, peerDevId_); if (ret != DH_SUCCESS) { DHLOGE("%s: Release softbus session failed ret: %d.", LOG_TAG, ret); @@ -83,6 +91,8 @@ int32_t ScreenDataChannelImpl::OpenSession() } sessionId_ = sessionId; + std::lock_guard sessionNumLock(sessionNumMutex_); + sessionNum_++; DHLOGI("%s: Open screen session success, sessionId(%d)", LOG_TAG, sessionId_); return DH_SUCCESS; } -- Gitee From 038eacdb58ca14ac85684bb59a99fc195f5aa1b9 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Tue, 19 Jul 2022 11:51:22 +0800 Subject: [PATCH 2/2] fix bug Signed-off-by: gaoqiang_strong --- .../include/screen_data_channel_impl.h | 3 --- .../src/screen_data_channel_impl.cpp | 10 ---------- .../include/screen_source_trans.h | 3 +++ .../screensourcetrans/src/screen_source_trans.cpp | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h index 1fa438ea..9ec16416 100644 --- a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h +++ b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h @@ -17,7 +17,6 @@ #define OHOS_SCREEN_DATA_CHANNEL_IMPL_H #include -#include #include #include "data_buffer.h" @@ -50,8 +49,6 @@ private: const std::string peerDevId_; int32_t sessionId_ = 0; - int32_t sessionNum_ = 0; - std::mutex sessionNumMutex_; std::weak_ptr channelListener_; }; } // namespace DistributedHardware diff --git a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp index 4db0181a..8a1c390a 100644 --- a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp +++ b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp @@ -55,14 +55,6 @@ int32_t ScreenDataChannelImpl::CreateSession(const std::shared_ptr sessionNumLock(sessionNumMutex_); - sessionNum_--; - if (sessionNum_ != 0) { - DHLOGI("%s: opened session number isn't zero", LOG_TAG); - return DH_SUCCESS; - } - } int32_t ret = SoftbusAdapter::GetInstance().RemoveSoftbusSessionServer(PKG_NAME, DATA_SESSION_NAME, peerDevId_); if (ret != DH_SUCCESS) { DHLOGE("%s: Release softbus session failed ret: %d.", LOG_TAG, ret); @@ -91,8 +83,6 @@ int32_t ScreenDataChannelImpl::OpenSession() } sessionId_ = sessionId; - std::lock_guard sessionNumLock(sessionNumMutex_); - sessionNum_++; DHLOGI("%s: Open screen session success, sessionId(%d)", LOG_TAG, sessionId_); return DH_SUCCESS; } diff --git a/services/screentransport/screensourcetrans/include/screen_source_trans.h b/services/screentransport/screensourcetrans/include/screen_source_trans.h index 667212b3..5add1de5 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 2ad9f920..50929c1a 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 = -- Gitee