From 86d4f74572a44d9e6818a4f3708dbe7f2ac89a01 Mon Sep 17 00:00:00 2001 From: qinlong Date: Mon, 17 Oct 2022 10:38:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinlong --- common/include/dscreen_errcode.h | 2 ++ services/screenclient/src/screen_client.cpp | 2 +- .../src/screen_client_window_adapter.cpp | 12 ++++++++++++ .../sourceservice/dscreenmgr/src/dscreen.cpp | 11 +++++++++++ .../dscreenmgr/src/dscreen_manager.cpp | 12 ++++++++++++ .../dscreenmgr/src/screen_manager_adapter.cpp | 16 ++++++++++++++++ .../src/dscreen_source_service.cpp | 4 ++++ .../decoder/src/image_sink_decoder.cpp | 12 ++++++++---- .../src/image_sink_processor.cpp | 8 ++++---- .../screensinktrans/src/screen_sink_trans.cpp | 12 ++++++++++-- .../src/image_source_processor.cpp | 1 - .../src/screen_source_trans.cpp | 4 ++-- 12 files changed, 82 insertions(+), 14 deletions(-) diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index ae4b32b3..8009b6e0 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -59,6 +59,8 @@ 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_SET_IMAGESURFACE_FAIL = -500037, + ERR_DH_SCREEN_SA_INIT_SOURCE_FAIL = -500038, // Transport component error code ERR_DH_SCREEN_TRANS_ERROR = -51000, ERR_DH_SCREEN_TRANS_TIMEOUT = -51001, diff --git a/services/screenclient/src/screen_client.cpp b/services/screenclient/src/screen_client.cpp index 5a61184e..fd06dba5 100644 --- a/services/screenclient/src/screen_client.cpp +++ b/services/screenclient/src/screen_client.cpp @@ -156,7 +156,7 @@ int32_t ScreenClient::RemoveWindow(int32_t windowId) return ret; } DHLOGD("windowId (ID = %d) remove success.", windowId); - return DH_SUCCESS; + return ret; } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/screenclient/src/screen_client_window_adapter.cpp b/services/screenclient/src/screen_client_window_adapter.cpp index ef6279b9..16266dc2 100644 --- a/services/screenclient/src/screen_client_window_adapter.cpp +++ b/services/screenclient/src/screen_client_window_adapter.cpp @@ -203,6 +203,10 @@ int32_t ScreenClientWindowAdapter::RemoveWindow(int32_t windowId) bool ScreenClientInputEventListener::OnInputEvent(const std::shared_ptr& pointerEvent) const { + if (pointerEvent == nullptr) { + DHLOGE("OnInputEvent failed, pointerEvent is nullptr."); + return false; + } DHLOGI("onInputEvent, pointerEvent"); pointerEvent->MarkProcessed(); return true; @@ -210,6 +214,10 @@ bool ScreenClientInputEventListener::OnInputEvent(const std::shared_ptr& keyEvent) const { + if (keyEvent == nullptr) { + DHLOGE("OnInputEvent failed, keyEvent is nullptr."); + return false; + } DHLOGI("onInputEvent, keyEvent"); keyEvent->MarkProcessed(); return true; @@ -217,6 +225,10 @@ bool ScreenClientInputEventListener::OnInputEvent(const std::shared_ptr& axisEvent) const { + if (axisEvent == nullptr) { + DHLOGE("OnInputEvent failed, axisEvent is nullptr."); + return false; + } DHLOGI("onInputEvent, axisEvent"); axisEvent->MarkProcessed(); return true; diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp index ce7e1816..66610c81 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp @@ -182,6 +182,10 @@ void DScreen::HandleTask(const std::shared_ptr &task) void DScreen::HandleEnable(const std::string ¶m, const std::string &taskId) { + if (dscreenCallback_ == nullptr) { + DHLOGE("DScreen::HandleEnable, dscreenCallback_ is nullptr"); + return; + } DHLOGI("HandleEnable, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); if (curState_ == ENABLED || curState_ == ENABLING || curState_ == CONNECTING || curState_ == CONNECTED) { dscreenCallback_->OnRegResult(shared_from_this(), taskId, DH_SUCCESS, "dscreen enable success."); @@ -266,6 +270,9 @@ int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) } std::vector> caps = codecList->GetVideoEncoderCaps(); for (const auto &cap : caps) { + if (cap == nullptr) { + continue; + } std::shared_ptr codecInfo = cap->GetCodecInfo(); if (codecInfo == nullptr) { continue; @@ -299,6 +306,10 @@ int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) void DScreen::HandleDisable(const std::string &taskId) { + if (dscreenCallback_ == nullptr) { + DHLOGE("DScreen::HandleDisable, dscreenCallback_ is nullptr"); + return; + } DHLOGI("HandleDisable, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); SetState(DISABLING); int32_t ret = ScreenMgrAdapter::GetInstance().RemoveVirtualScreen(screenId_); diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index aa345d42..ac433245 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -160,6 +160,10 @@ int32_t DScreenManager::AddToGroup(const std::shared_ptr &changedScreen } std::shared_ptr videoParam = changedScreen->GetVideoParam(); + if (videoParam == nullptr) { + DHLOGE("videoParam is nullptr."); + return ERR_DH_SCREEN_SA_VALUE_NOT_INIT; + } DisplayRect displayRect = mapRelation->GetDisplayRect(); videoParam->SetVideoWidth(displayRect.width); videoParam->SetVideoHeight(displayRect.height); @@ -196,6 +200,10 @@ int32_t DScreenManager::RemoveFromGroup(const std::shared_ptr &changedS void DScreenCallback::OnRegResult(const std::shared_ptr &dScreen, const std::string &reqId, const int32_t status, const std::string &data) { + if (dScreen == nullptr) { + DHLOGE("DScreenCallback::OnRegResult, dScreen id nullptr"); + return; + } DHLOGI("DScreenCallback::OnRegResult, devId: %s, dhId: %s, reqId: %s", GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str()); DScreenManager::GetInstance().OnRegResult(dScreen, reqId, status, data); @@ -204,6 +212,10 @@ void DScreenCallback::OnRegResult(const std::shared_ptr &dScreen, void DScreenCallback::OnUnregResult(const std::shared_ptr &dScreen, const std::string &reqId, const int32_t status, const std::string &data) { + if (dScreen == nullptr) { + DHLOGE("DScreenCallback::OnUnregResult, dScreen id nullptr"); + return; + } DHLOGI("DScreenCallback::OnUnregResult, devId: %s, dhId: %s, reqId: %s", GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str()); DScreenManager::GetInstance().OnUnregResult(dScreen, reqId, status, data); diff --git a/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp b/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp index 309af680..05227512 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp @@ -39,6 +39,10 @@ ScreenMgrAdapter::~ScreenMgrAdapter() uint64_t ScreenMgrAdapter::CreateVirtualScreen(const std::string &devId, const std::string &dhId, const std::shared_ptr &videoParam) { + if (videoParam == nullptr) { + DHLOGE("ScreenMgrAdapter::CreateVirtualScreen, videoParam is nullptr"); + return SCREEN_ID_INVALID; + } DHLOGI("CreateVirtualScreen, width: %u, height: %u", videoParam->GetScreenWidth(), videoParam->GetScreenHeight()); std::string screenName = DSCREEN_PREFIX + SEPERATOR + GetInterruptString(devId) + @@ -72,6 +76,10 @@ uint64_t ScreenMgrAdapter::CreateVirtualScreen(const std::string &devId, const s int32_t ScreenMgrAdapter::RegisterScreenGroupListener(sptr listener) { + if (listener == nullptr) { + DHLOGE("ScreenMgrAdapter::RegisterScreenGroupListener, listener is nullptr."); + return ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL; + } DHLOGI("RegisterScreenGroupListener"); if (listenerRegistered_) { DHLOGI("already registered listener."); @@ -88,6 +96,10 @@ int32_t ScreenMgrAdapter::RegisterScreenGroupListener(sptr listener) { + if (listener == nullptr) { + DHLOGE("ScreenMgrAdapter::UnregisterScreenGroupListener, listener is nullptr."); + return ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL; + } DHLOGI("UnregisterScreenGroupListener"); if (!listenerRegistered_) { DHLOGI("listener already unregistered."); @@ -123,6 +135,10 @@ int32_t ScreenMgrAdapter::RemoveVirtualScreen(uint64_t screenId) int32_t ScreenMgrAdapter::SetImageSurface(uint64_t screenId, sptr surface) { + if (surface == nullptr) { + DHLOGE("ScreenMgrAdapter::SetImageSurface, surface is nullptr"); + return ERR_DH_SCREEN_SA_SET_IMAGESURFACE_FAIL; + } DHLOGI("SetImageSurface for virtualscreen, screenId: %ulld", screenId); Rosen::ScreenManager::GetInstance().SetVirtualScreenSurface(screenId, surface); return DH_SUCCESS; diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index 1f24b76c..db9b47de 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -76,6 +76,10 @@ bool DScreenSourceService::Init() int32_t DScreenSourceService::InitSource(const std::string ¶ms, const sptr &callback) { + if (callback == nullptr) { + DHLOGE("DScreenSourceService::InitSource, callback is nullptr."); + return ERR_DH_SCREEN_SA_INIT_SOURCE_FAIL; + } DHLOGI("InitSource"); int32_t ret = DScreenManager::GetInstance().Init(); if (ret != DH_SUCCESS) { diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 2d85f41e..53ce8b59 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -200,8 +200,8 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) int32_t ImageSinkDecoder::SetOutputSurface(sptr &surface) { DHLOGI("%s: SetOutputSurface.", LOG_TAG); - if (videoDecoder_ == nullptr) { - DHLOGE("%s: Decoder is null.", LOG_TAG); + if (videoDecoder_ == nullptr || surface == nullptr) { + DHLOGE("%s: Decoder or surface is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -216,6 +216,10 @@ int32_t ImageSinkDecoder::SetOutputSurface(sptr &surface) int32_t ImageSinkDecoder::InputScreenData(const std::shared_ptr &data) { + if (data == nullptr) { + DHLOGE("%s: InputScreenData failed, data is nullptr.", LOG_TAG); + return ERR_DH_SCREEN_TRANS_NULL_VALUE; + } DHLOGD("%s: InputScreenData.", LOG_TAG); std::lock_guard dataLock(dataMutex_); while (videoDataQueue_.size() >= DATA_QUEUE_MAX_SIZE) { @@ -327,8 +331,8 @@ void ImageSinkDecoder::DecodeScreenData() int32_t ImageSinkDecoder::ProcessData(const std::shared_ptr &screenData, const int32_t bufferIndex) { DHLOGI("%s: ProcessData.", LOG_TAG); - if (videoDecoder_ == nullptr) { - DHLOGE("%s: Decoder is null.", LOG_TAG); + if (videoDecoder_ == nullptr || screenData == nullptr) { + DHLOGE("%s: Decoder or screenData is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } diff --git a/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp b/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp index 6cc0e46b..7059fc7b 100644 --- a/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp +++ b/services/screentransport/screensinkprocessor/src/image_sink_processor.cpp @@ -107,8 +107,8 @@ int32_t ImageSinkProcessor::StopImageProcessor() int32_t ImageSinkProcessor::SetImageSurface(sptr &surface) { DHLOGI("%s: SetImageSurface.", LOG_TAG); - if (imageDecoder_ == nullptr) { - DHLOGE("%s: Decoder is null.", LOG_TAG); + if (imageDecoder_ == nullptr || surface == nullptr) { + DHLOGE("%s: Decoder or surface is null.", LOG_TAG); ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "SetImageSurface Decoder is null."); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -126,8 +126,8 @@ int32_t ImageSinkProcessor::SetImageSurface(sptr &surface) int32_t ImageSinkProcessor::ProcessImage(const std::shared_ptr &data) { DHLOGI("%s: ProcessImage.", LOG_TAG); - if (imageDecoder_ == nullptr) { - DHLOGE("%s: Decoder is null.", LOG_TAG); + if (imageDecoder_ == nullptr || data == nullptr) { + DHLOGE("%s: Decoder or data is null.", LOG_TAG); ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "processImage Decoder is null."); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } diff --git a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp index f574ad10..8cbcc9dc 100644 --- a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp +++ b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp @@ -73,8 +73,8 @@ int32_t ScreenSinkTrans::Release() int32_t ScreenSinkTrans::Start() { DHLOGI("%s: Start.", LOG_TAG); - if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { - DHLOGE("%s: Processor or channel is null, Setup first.", LOG_TAG); + if (imageProcessor_ == nullptr) { + DHLOGE("%s: Processor is null, Setup first.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -251,6 +251,10 @@ int32_t ScreenSinkTrans::RegisterChannelListener() int32_t ScreenSinkTrans::RegisterProcessorListener(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId) { + if (imageProcessor_ == nullptr || decoderSurface_ == nullptr) { + DHLOGE("%s: imageProcessor_ or decoderSurface_ is nullptr.", LOG_TAG); + return ERR_DH_SCREEN_TRANS_NULL_VALUE; + } DHLOGI("%s: RegisterProcessorListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); if (listener == nullptr) { @@ -291,6 +295,10 @@ void ScreenSinkTrans::OnSessionClosed() void ScreenSinkTrans::OnDataReceived(const std::shared_ptr &data) { + if (imageProcessor_ == nullptr || data == nullptr) { + DHLOGE("%s: imageProcessor_ or data is nullptr.", LOG_TAG); + return; + } DHLOGD("%s: OnChannelDataReceived.", LOG_TAG); int32_t ret = imageProcessor_->ProcessImage(data); if (ret != DH_SUCCESS) { diff --git a/services/screentransport/screensourceprocessor/src/image_source_processor.cpp b/services/screentransport/screensourceprocessor/src/image_source_processor.cpp index 077fb2f2..93d1b622 100644 --- a/services/screentransport/screensourceprocessor/src/image_source_processor.cpp +++ b/services/screentransport/screensourceprocessor/src/image_source_processor.cpp @@ -27,7 +27,6 @@ int32_t ImageSourceProcessor::ConfigureImageProcessor(const VideoParam &localPar { DHLOGI("%s: ConfigureImageProcessor.", LOG_TAG); imageEncoder_ = std::make_shared(listener); - 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 b46522ea..63141660 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -80,8 +80,8 @@ int32_t ScreenSourceTrans::Release() int32_t ScreenSourceTrans::Start() { DHLOGI("%s: Start.", LOG_TAG); - if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { - DHLOGE("%s: Processor or channel is null, Setup first.", LOG_TAG); + if (screenChannel_ == nullptr) { + DHLOGE("%s: channel is null, Setup first.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } -- Gitee