From 0799e0e4e479bcf955f6ce7433bcf0d788e4da77 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Thu, 13 Oct 2022 15:54:06 +0800 Subject: [PATCH] fix bug Signed-off-by: gaoqiang_strong --- common/include/dscreen_errcode.h | 1 + .../screen_sink/src/dscreen_sink_handler.cpp | 8 +++++++ .../src/dscreen_source_handler.cpp | 8 +++++++ services/screenclient/src/screen_client.cpp | 4 ---- .../screenregionmgr/include/screenregion.h | 1 + .../screenregionmgr/src/screenregion.cpp | 24 +++++++++++++++---- .../sourceservice/dscreenmgr/src/dscreen.cpp | 4 ++++ .../dscreenmgr/src/dscreen_manager.cpp | 4 ++-- .../src/screen_data_channel_impl.cpp | 5 ---- .../src/image_sink_processor.cpp | 5 ---- .../screensinktrans/src/screen_sink_trans.cpp | 9 ------- .../encoder/src/image_source_encoder.cpp | 4 ---- .../src/image_source_processor.cpp | 5 ---- .../src/screen_source_trans.cpp | 9 ------- 14 files changed, 43 insertions(+), 48 deletions(-) diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index ae4b32b3..f19faef9 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -59,6 +59,7 @@ enum DScreenErrorCode { ERR_DH_SCREEN_SA_HIDUMPER_ERROR = -500033, ERR_DH_SCREEN_SA_ENABLE_JSON_ERROR = -500034, ERR_DH_SCREEN_SA_VALUE_NOT_INIT = -500035, + ERR_DH_SCREEN_SA_DSCREEN_SETUP_FAILED = -500036, // Transport component error code ERR_DH_SCREEN_TRANS_ERROR = -51000, ERR_DH_SCREEN_TRANS_TIMEOUT = -51001, diff --git a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp index e3147404..db6a3f1e 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp @@ -53,6 +53,10 @@ DScreenSinkHandler::~DScreenSinkHandler() int32_t DScreenSinkHandler::InitSink(const std::string ¶ms) { + if (params.empty()) { + DHLOGE("InitSink params is invalid."); + return ERR_DH_SCREEN_INPUT_PARAM_INVALID; + } DHLOGI("DScreenSinkHandler InitSink"); std::unique_lock lock(proxyMutex_); if (dScreenSinkProxy_ == nullptr) { @@ -159,6 +163,10 @@ int32_t DScreenSinkHandler::UnsubscribeLocalHardware(const std::string &dhId) void DScreenSinkHandler::DScreenSinkSvrRecipient::OnRemoteDied(const wptr &remote) { + if (remote == nullptr) { + DHLOGI("OnRemoteDied remote is nullptr."); + return; + } DHLOGI("DScreenSinkSvrRecipient OnRemoteDied."); DScreenSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote); } diff --git a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp index c60c24ad..28521796 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp @@ -54,6 +54,10 @@ DScreenSourceHandler::DScreenSourceHandler() int32_t DScreenSourceHandler::InitSource(const std::string ¶ms) { + if (params.empty()) { + DHLOGE("InitSource params is invalid."); + return ERR_DH_SCREEN_INPUT_PARAM_INVALID; + } DHLOGI("DScreenSourceHandler InitSource"); std::unique_lock lock(proxyMutex_); if (dScreenSourceProxy_ == nullptr) { @@ -198,6 +202,10 @@ int32_t DScreenSourceHandler::ConfigDistributedHardware(const std::string &devId void DScreenSourceHandler::DScreenSourceSvrRecipient::OnRemoteDied(const wptr &remote) { + if (remote == nullptr) { + DHLOGI("OnRemoteDied remote is nullptr."); + return; + } DHLOGI("DScreenSourceSvrRecipient OnRemoteDied"); DScreenSourceHandler::GetInstance().OnRemoteSourceSvrDied(remote); } diff --git a/services/screenclient/src/screen_client.cpp b/services/screenclient/src/screen_client.cpp index 5a61184e..2a0b1754 100644 --- a/services/screenclient/src/screen_client.cpp +++ b/services/screenclient/src/screen_client.cpp @@ -131,10 +131,6 @@ sptr ScreenClient::GetSurface(int32_t windowId) } surface = iter->second; } - if (surface == nullptr) { - DHLOGE("Get surface is null(ID = %d).", windowId); - return nullptr; - } DHLOGD("Get surface (ID = %d) success.", windowId); return surface; } diff --git a/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h b/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h index 23bfe298..4aba6850 100644 --- a/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h +++ b/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h @@ -50,6 +50,7 @@ public: uint64_t GetDisplayId(); std::shared_ptr GetVideoParam(); int32_t GetWindowId(); + int32_t SetUpWindow(); int32_t SetUp(); int32_t Start(); int32_t Stop(); diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp index f3708406..8c549d2a 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp @@ -89,13 +89,15 @@ std::shared_ptr ScreenRegion::GetWindowProperty() return windowProperty_; } -int32_t ScreenRegion::SetUp() +int32_t ScreenRegion::SetUpWindow() { - DHLOGI("ScreenRegion::SetUp, remoteDevId: %s", GetAnonyString(remoteDevId_).c_str()); - + DHLOGI("ScreenRegion::SetUpWindow"); std::shared_ptr windowProperty = std::make_shared(); windowProperty->displayId = displayId_; - + if (mapRelation_ == nullptr) { + DHLOGE("ScreenRegion::SetUp mapRelation is nullptr."); + return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED; + } ScreenRect screenRect = mapRelation_->GetScreenRect(); windowProperty->startX = screenRect.startX; windowProperty->startY = screenRect.startY; @@ -122,9 +124,21 @@ int32_t ScreenRegion::SetUp() ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED, "get window surface failed."); return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED; } - surface_ = surface; + return DH_SUCCESS; +} + + +int32_t ScreenRegion::SetUp() +{ + DHLOGI("ScreenRegion::SetUp, remoteDevId: %s", GetAnonyString(remoteDevId_).c_str()); + int32_t ret = SetUpWindow(); + if (ret != DH_SUCCESS) { + DHLOGE("SetUpWindow failed."); + return ret; + } + if (sinkTrans_ == nullptr) { sinkTrans_ = std::make_shared(); } diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp index ce7e1816..3f0510dc 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp @@ -378,6 +378,10 @@ int32_t DScreen::SetUp() } sptr surface = sourceTrans_->GetImageSurface(); + if (surface == nullptr) { + DHLOGE("DScreen SetUp failed."); + return ERR_DH_SCREEN_SA_DSCREEN_SETUP_FAILED; + } ScreenMgrAdapter::GetInstance().SetImageSurface(screenId_, surface); DHLOGI("DScreen SetUp success."); diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index aa345d42..e39c290d 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -252,8 +252,8 @@ int32_t DScreenManager::EnableDistributedScreen(const std::string &devId, const int32_t dScreenState = dScreen->GetState(); if (dScreenState == ENABLED || dScreenState == ENABLING) { - DHLOGE("dScreen state is ENABLED or ENABLING."); - return ERR_DH_SCREEN_SA_ENABLE_FAILED; + DHLOGI("dScreen state Already is ENABLED or ENABLING."); + return DH_SUCCESS; } dScreens_[dScreenIdx] = dScreen; diff --git a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp index b19f70b7..1df31ccc 100644 --- a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp +++ b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp @@ -183,11 +183,6 @@ void ScreenDataChannelImpl::OnStreamReceived(int32_t sessionId, const StreamData DHLOGI("%s: OnScreenStreamReceived, sessionId(%d) dataSize(%zu).", LOG_TAG, sessionId, data->bufLen); auto dataBuffer = std::make_shared(data->bufLen); - if (dataBuffer == nullptr) { - DHLOGE("%s: DataBuffer is null.", LOG_TAG); - return; - } - int32_t ret = memcpy_s(dataBuffer->Data(), dataBuffer->Capacity(), (uint8_t *)data->buf, data->bufLen); if (ret != EOK) { DHLOGE("%s: Data memcpy_s failed.", LOG_TAG); diff --git a/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp b/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp index e692bff8..dae84b72 100644 --- a/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp +++ b/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp @@ -31,11 +31,6 @@ int32_t ImageSinkProcessor::ConfigureImageProcessor( remoteParam_ = remoteParam; imageDecoder_ = std::make_shared(imageListener); - if (imageDecoder_ == nullptr) { - DHLOGE("%s: Decoder is null.", LOG_TAG); - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } - int32_t ret = imageDecoder_->ConfigureDecoder(localParam); if (ret != DH_SUCCESS) { DHLOGE("%s: ConfigureDecoder failed ret:%d.", LOG_TAG, ret); diff --git a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp index 8b92aa29..319d6220 100644 --- a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp +++ b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp @@ -208,10 +208,6 @@ int32_t ScreenSinkTrans::InitScreenTrans(const VideoParam &localParam, const Vid const std::string &peerDevId) { screenChannel_ = std::make_shared(peerDevId); - if (screenChannel_ == nullptr) { - DHLOGE("%s: Create screen data channel failed.", LOG_TAG); - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } int32_t ret = RegisterChannelListener(); if (ret != DH_SUCCESS) { DHLOGE("%s: Register channel listener failed.", LOG_TAG); @@ -220,11 +216,6 @@ int32_t ScreenSinkTrans::InitScreenTrans(const VideoParam &localParam, const Vid } imageProcessor_ = std::make_shared(); - if (imageProcessor_ == nullptr) { - DHLOGE("%s: Create image processor failed.", LOG_TAG); - screenChannel_ = nullptr; - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } ret = RegisterProcessorListener(localParam, remoteParam, peerDevId); if (ret != DH_SUCCESS) { DHLOGE("%s: Register processor listener failed.", LOG_TAG); diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index a265b8dc..5b7220f0 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -236,10 +236,6 @@ void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecB return; } auto dataBuf = std::make_shared(dataSize); - if (dataBuf == nullptr) { - DHLOGE("%s: Create buffer failed.", LOG_TAG); - return; - } int32_t ret = memcpy_s(dataBuf->Data(), dataBuf->Capacity(), videoSharedMemory_->GetBase(), dataSize); if (ret != EOK) { DHLOGE("%s: Copy data failed.", LOG_TAG); diff --git a/services/screentransport/screensourceprocessor/src/image_source_processor.cpp b/services/screentransport/screensourceprocessor/src/image_source_processor.cpp index 52cc5b52..93d1b622 100644 --- a/services/screentransport/screensourceprocessor/src/image_source_processor.cpp +++ b/services/screentransport/screensourceprocessor/src/image_source_processor.cpp @@ -27,11 +27,6 @@ int32_t ImageSourceProcessor::ConfigureImageProcessor(const VideoParam &localPar { DHLOGI("%s: ConfigureImageProcessor.", LOG_TAG); imageEncoder_ = std::make_shared(listener); - if (imageEncoder_ == nullptr) { - DHLOGE("%s: Create screen encoder failed.", LOG_TAG); - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } - int32_t ret = imageEncoder_->ConfigureEncoder(localParam); if (ret != DH_SUCCESS) { DHLOGE("%s: Configure screen encoder failed ret: %d.", LOG_TAG, ret); diff --git a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp index fc075ca9..14d4d470 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -226,10 +226,6 @@ int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const V { DHLOGI("%s:InitScreenTrans.", LOG_TAG); screenChannel_ = std::make_shared(peerDevId); - if (screenChannel_ == nullptr) { - DHLOGE("%s: Create screen data channel failed.", LOG_TAG); - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } int32_t ret = RegisterChannelListener(); if (ret != DH_SUCCESS) { DHLOGE("%s: Register channel listener failed ret: %d.", LOG_TAG, ret); @@ -238,11 +234,6 @@ int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const V } imageProcessor_ = std::make_shared(); - if (imageProcessor_ == nullptr) { - DHLOGE("%s: Create image processor failed.", LOG_TAG); - screenChannel_ = nullptr; - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } ret = RegisterProcessorListener(localParam, remoteParam); if (ret != DH_SUCCESS) { DHLOGE("%s: Register data processor listener failed ret: %d.", LOG_TAG, ret); -- Gitee