diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index 083d0b44d4ac2a7ab59a21433a5efa0ecda9bd25..7b016d562fe0cc68c0372980885a8d1f22ee9c0d 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -135,6 +135,11 @@ const std::string KEY_DISPLAY_RECT = "displayRect"; const std::string KEY_SCREEN_RECT = "screenRect"; const std::string KEY_POINT_START_X = "startX"; const std::string KEY_POINT_START_Y = "startY"; +const std::string KEY_POINT_DIRTY_X = "dirtyX"; +const std::string KEY_POINT_DIRTY_Y = "dirtyY"; +const std::string KEY_POINT_DIRTY_W = "dirtyW"; +const std::string KEY_POINT_DIRTY_H = "dirtyH"; +const std::string KEY_POINT_DIRTY_SIZE = "dirtySize"; const std::string KEY_WIDTH = "width"; const std::string KEY_HEIGHT = "height"; const std::string KEY_SCREEN_WIDTH = "screenWidth"; @@ -169,6 +174,7 @@ constexpr uint32_t MAX_MESSAGES_LEN = 40 * 1024 * 1024; constexpr float DEFAULT_DENSITY = 2.0; constexpr int32_t DEFAULT_SCREEN_FLAGS = 0; constexpr uint32_t DEFAULT_FPS = 30; +constexpr int32_t DIRTY_MAX_SIZE = 10; constexpr uint8_t DEFAULT_CODECTYPE = VIDEO_CODEC_TYPE_VIDEO_H264; constexpr uint8_t DEFAULT_VIDEO_FORMAT = VIDEO_DATA_FORMAT_NV12; constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID = 4807; diff --git a/services/common/utils/src/dscreen_maprelation.cpp b/services/common/utils/src/dscreen_maprelation.cpp index 57d3db3e7efcebfe55992c039168bc373bd95a6e..0572b1579b5c5dba81f3774f422e7dbae5162baf 100644 --- a/services/common/utils/src/dscreen_maprelation.cpp +++ b/services/common/utils/src/dscreen_maprelation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -84,7 +84,9 @@ void from_json(const json &j, DScreenMapRelation &dScreenMapRelation) } dScreenMapRelation.displayId_ = j[KEY_DISPLAY_ID].get(); dScreenMapRelation.screenId_ = j[KEY_SCREEN_ID].get(); - + if (!j.contains(KEY_DISPLAY_RECT) || !j.contains(KEY_SCREEN_RECT)) { + return; + } from_json(j.at(KEY_DISPLAY_RECT), dScreenMapRelation.displayRect_); from_json(j.at(KEY_SCREEN_RECT), dScreenMapRelation.screenRect_); } diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp index bfc0368dd61025d779efe7a5594336bb83176ba0..85f1d512d77656cc2f0148cd36a8a3c49e34b588 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp @@ -136,7 +136,7 @@ void ScreenRegionManager::HandleNotifySetUp(const std::string &remoteDevId, cons NotifyRemoteSourceSetUpResult(remoteDevId, "", ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, ""); return; } - if (eventContentJson.contains(KEY_VERSION)) { + if (IsString(eventContentJson, KEY_VERSION)) { version_ = eventContentJson[KEY_VERSION].get(); } uint64_t screenId = eventContentJson[KEY_SCREEN_ID].get(); diff --git a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h index 0b43f3b4ceab1f3b48ae5be30b9074290798b961..5a7158386cd1962192f93b21c6c44e64da818f72 100644 --- a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h +++ b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,6 +23,7 @@ #include "iscreen_channel.h" #include "softbus_adapter.h" +#include "nlohmann/json.hpp" namespace OHOS { namespace DistributedHardware { class ScreenDataChannelImpl : public IScreenChannel, @@ -46,7 +47,8 @@ public: void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override; void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param) override; - + void DirtyVecToJson(nlohmann::json &rectJson, const std::shared_ptr &screenData); + void JsonToDirtyJson(nlohmann::json &rectJson, std::shared_ptr &screenData); private: static const constexpr char *LOG_TAG = "ScreenDataChannel"; bool jpegSessionFlag_ = false; diff --git a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp index dcf23a66b9687d66e887b20ea863904a0c44310b..47a2811d9ef2732b92afdeb862e24e05be22168d 100644 --- a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp +++ b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,7 +22,6 @@ #include "dscreen_hisysevent.h" #include "dscreen_log.h" #include "dscreen_util.h" -#include "nlohmann/json.hpp" #include "dscreen_json_util.h" namespace OHOS { @@ -202,15 +201,7 @@ int32_t ScreenDataChannelImpl::SendDirtyData(const std::shared_ptr & return ERR_DH_SCREEN_TRANS_NULL_VALUE; } nlohmann::json rectJson; - std::vector dirtyRectVec = screenData->GetDirtyRectVec(); - rectJson["dataType"] = screenData->DataType(); - rectJson["dirtySize"] = static_cast(dirtyRectVec.size()); - int32_t rectIndex = 0; - for (auto item : dirtyRectVec) { - std::string tempRectIndex = std::to_string(rectIndex); - rectJson[tempRectIndex] = {item.xPos, item.yPos, item.width, item.height, item.dirtySize}; - rectIndex++; - } + DirtyVecToJson(rectJson, screenData); StreamData data = {reinterpret_cast(screenData->Data()), screenData->Capacity()}; std::string rectInfo = rectJson.dump(); char *dirtyInfo = new char[rectInfo.length() + 1] {0}; @@ -341,28 +332,61 @@ void ScreenDataChannelImpl::ProcessDirtyData(const StreamData *data, DHLOGE("%s: OnStreamReceived rectJson invalid", LOG_TAG); return; } + JsonToDirtyJson(rectJson, dataBuffer); + listener->OnDataReceived(dataBuffer); +} + +void ScreenDataChannelImpl::DirtyVecToJson(nlohmann::json &rectJson, const std::shared_ptr &screenData) +{ + std::vector dirtyRectVec = screenData->GetDirtyRectVec(); + rectJson["dataType"] = screenData->DataType(); + rectJson["dirtySize"] = dirtyRectVec.size(); + int32_t rectIndex = 0; + for (auto item : dirtyRectVec) { + std::string tempRectIndex = std::to_string(rectIndex); + rectJson[tempRectIndex] = nlohmann::json { + {KEY_POINT_DIRTY_X, item.xPos}, + {KEY_POINT_DIRTY_Y, item.yPos}, + {KEY_POINT_DIRTY_W, item.width}, + {KEY_POINT_DIRTY_H, item.height}, + {KEY_POINT_DIRTY_SIZE, item.dirtySize} + }; + rectIndex++; + } +} + +void ScreenDataChannelImpl::JsonToDirtyJson(nlohmann::json &rectJson, std::shared_ptr &screenData) +{ if (!IsInt32(rectJson, "dirtySize") || !IsInt32(rectJson, "dataType")) { return; } int32_t dirtySize = rectJson["dirtySize"].get(); int32_t dataType = rectJson["dataType"].get(); - uint8_t num = 0; + int32_t num = 0; + if (dirtySize >= DIRTY_MAX_SIZE) { + return; + } while (num < dirtySize) { auto item = std::to_string(num); if (!rectJson.contains(item)) { return; } - int32_t X = rectJson[item][0].get(); - int32_t Y = rectJson[item][1].get(); - int32_t W = rectJson[item][2].get(); - int32_t H = rectJson[item][3].get(); - int32_t Size = rectJson[item][4].get(); + if (!IsInt32(rectJson[item], KEY_POINT_DIRTY_X) || !IsInt32(rectJson[item], KEY_POINT_DIRTY_Y) || + !IsInt32(rectJson[item], KEY_POINT_DIRTY_W) || !IsInt32(rectJson[item], KEY_POINT_DIRTY_H) || + !IsInt32(rectJson[item], KEY_POINT_DIRTY_SIZE)) { + DHLOGE("%s: JsonToDirtyJson rectJson not contain int32."); + return; + } + int32_t X = rectJson[item][KEY_POINT_DIRTY_X].get(); + int32_t Y = rectJson[item][KEY_POINT_DIRTY_Y].get(); + int32_t W = rectJson[item][KEY_POINT_DIRTY_W].get(); + int32_t H = rectJson[item][KEY_POINT_DIRTY_H].get(); + int32_t Size = rectJson[item][KEY_POINT_DIRTY_SIZE].get(); DirtyRect rect = {X, Y, W, H, Size}; - dataBuffer->AddDirtyRect(rect); + screenData->AddDirtyRect(rect); num++; } - dataBuffer->SetDataType(dataType); - listener->OnDataReceived(dataBuffer); + screenData->SetDataType(dataType); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file