diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index 56d44c5f43facbea14e6b6d69148251976482883..086cf4f8b61773e22b55f3bd6fd3e9f8f5ec9ce3 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -208,7 +208,7 @@ constexpr int32_t PARTIAL_REFRESH_ENABLED_VALUE = 1; 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 = 60; +constexpr double DEFAULT_FPS = 60.0; 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; diff --git a/common/include/dscreen_json_util.h b/common/include/dscreen_json_util.h index 877b64f0be85115d117393009d4027f597ad1f6a..ef7743df29315d8c649a74b0949dea24fa4613b2 100644 --- a/common/include/dscreen_json_util.h +++ b/common/include/dscreen_json_util.h @@ -24,6 +24,7 @@ bool IsString(const nlohmann::json &jsonObj, const std::string &key); bool IsUInt8(const nlohmann::json &jsonObj, const std::string &key); bool IsInt32(const nlohmann::json &jsonObj, const std::string &key); bool IsUInt32(const nlohmann::json &jsonObj, const std::string &key); +bool IsFloat(const nlohmann::json &jsonObj, const std::string &key); bool IsInt64(const nlohmann::json &jsonObj, const std::string &key); bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key); bool IsArray(const nlohmann::json &jsonObj, const std::string &key); diff --git a/common/src/dscreen_json_util.cpp b/common/src/dscreen_json_util.cpp index 12bb5a8d2f02b7f336d65642256074177a421230..0c8b5f7ef56c3f06153ee1b20a03587635178fcf 100644 --- a/common/src/dscreen_json_util.cpp +++ b/common/src/dscreen_json_util.cpp @@ -76,6 +76,15 @@ bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key) return res; } +bool IsFloat(const nlohmann::json &jsonObj, const std::string &key) +{ + bool res = jsonObj.contains(key) && jsonObj[key].is_number_float(); + if (!res) { + DHLOGE("the key %s in jsonObj is invalid.", key.c_str()); + } + return res; +} + bool IsArray(const nlohmann::json &jsonObj, const std::string &key) { bool res = jsonObj.contains(key) && jsonObj[key].is_array(); diff --git a/services/common/test/unittest/utils/video_param_test.cpp b/services/common/test/unittest/utils/video_param_test.cpp index 2f5dbfe4535c663edc49991d8e8cdc89ec4ac662..7d822da4c76fb1dbd09530f2acd8356b2f7d3592 100644 --- a/services/common/test/unittest/utils/video_param_test.cpp +++ b/services/common/test/unittest/utils/video_param_test.cpp @@ -98,9 +98,9 @@ HWTEST_F(VideoParamTest, GetVideoHeight_001, TestSize.Level1) */ HWTEST_F(VideoParamTest, GetFps_001, TestSize.Level1) { - uint32_t fps = 1; + double fps = 1.0; videoParam_->SetFps(fps); - uint32_t actual = videoParam_->GetFps(); + double actual = videoParam_->GetFps(); EXPECT_EQ(fps, actual); } @@ -145,7 +145,7 @@ HWTEST_F(VideoParamTest, to_json_001, TestSize.Level1) uint32_t screenHeight = 100; uint32_t videoWidth = 100; uint32_t videoHeight = 100; - uint32_t fps = 30; + double fps = 30.0; uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; uint8_t codecType = DEFAULT_CODECTYPE; @@ -177,7 +177,7 @@ HWTEST_F(VideoParamTest, from_json_001, TestSize.Level1) uint32_t screenHeight = 100; uint32_t videoWidth = 100; uint32_t videoHeight = 100; - uint32_t fps = 30; + double fps = 30.0; uint8_t codecType = DEFAULT_CODECTYPE; uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; @@ -208,7 +208,7 @@ HWTEST_F(VideoParamTest, from_json_002, TestSize.Level1) uint32_t screenHeight = 200; uint32_t videoWidth = 200; uint32_t videoHeight = 200; - uint32_t fps = 30; + double fps = 30.0; uint8_t codecType = DEFAULT_CODECTYPE; uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; VideoParam jsonVideoParam; diff --git a/services/common/utils/include/video_param.h b/services/common/utils/include/video_param.h index 5f1122a13862940963b3eec152638adac34cac56..76fd4971b89f05a14c722e5c9efe3efa63603802 100644 --- a/services/common/utils/include/video_param.h +++ b/services/common/utils/include/video_param.h @@ -34,8 +34,8 @@ public: uint32_t GetVideoWidth() const; void SetVideoHeight(uint32_t videoHeight); uint32_t GetVideoHeight() const; - void SetFps(uint32_t fps); - uint32_t GetFps() const; + void SetFps(double fps); + double GetFps() const; void SetCodecType(uint8_t codecType); uint8_t GetCodecType() const; void SetVideoFormat(uint8_t videoFormat); @@ -50,7 +50,7 @@ private: uint32_t screenHeight_; uint32_t videoWidth_; uint32_t videoHeight_; - uint32_t fps_ = DEFAULT_FPS; + double fps_ = DEFAULT_FPS; uint8_t codecType_ = DEFAULT_CODECTYPE; uint8_t videoFormat_ = DEFAULT_VIDEO_FORMAT; bool isPartialRefresh_ = false; diff --git a/services/common/utils/src/video_param.cpp b/services/common/utils/src/video_param.cpp index 24e84f7982bf2d67224ae26bd6fd3bae12a913ca..69e3ce997a56a6cc6962c31db28aa565c09f4108 100644 --- a/services/common/utils/src/video_param.cpp +++ b/services/common/utils/src/video_param.cpp @@ -71,12 +71,12 @@ uint32_t VideoParam::GetVideoHeight() const return videoHeight_; } -void VideoParam::SetFps(uint32_t fps) +void VideoParam::SetFps(double fps) { fps_ = fps; } -uint32_t VideoParam::GetFps() const +double VideoParam::GetFps() const { return fps_; } @@ -119,7 +119,7 @@ void from_json(const json &j, DistributedHardware::VideoParam &videoParam) { if (!IsUInt32(j, KEY_SCREEN_WIDTH) || !IsUInt32(j, KEY_SCREEN_HEIGHT) || !IsUInt32(j, KEY_VIDEO_WIDTH) || !IsUInt32(j, KEY_VIDEO_HEIGHT) || - !IsUInt32(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) || + !IsFloat(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) || !IsUInt8(j, KEY_COLOR_FORMAT)) { return; } @@ -128,7 +128,7 @@ void from_json(const json &j, DistributedHardware::VideoParam &videoParam) videoParam.screenHeight_ = j[KEY_SCREEN_HEIGHT].get(); videoParam.videoWidth_ = j[KEY_VIDEO_WIDTH].get(); videoParam.videoHeight_ = j[KEY_VIDEO_HEIGHT].get(); - videoParam.fps_ = j[KEY_FPS].get(); + videoParam.fps_ = j[KEY_FPS].get(); videoParam.codecType_ = j[KEY_CODECTYPE].get(); videoParam.videoFormat_ = j[KEY_COLOR_FORMAT].get(); videoParam.isPartialRefresh_ = false; diff --git a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp index 5a8844d596e3d79ffb099a27f07f64edccac10d1..4d1e4ee37b69e853110aefb2c50fc92c6dd2cc3d 100644 --- a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp @@ -107,7 +107,8 @@ int32_t ScreenRegion::StartReceiverEngine(const std::string &content) } ret = receiverAdapter_->Start(); if (ret != DH_SUCCESS) { - DHLOGE("start av receiver engine failed."); + DHLOGE("start av receiver engine failed, remove window."); + (void)ScreenClient::GetInstance().RemoveWindow(windowId_); return ERR_DH_AV_TRANS_START_FAILED; } isRunning = true; diff --git a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp index 47e0e20603d629560d18d033faf2146e3f2c58e5..03e6018f7cab44a30780a06634e97e6faa4882a1 100644 --- a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp @@ -239,7 +239,6 @@ int32_t DScreenManager::EnableDistributedScreen(const std::string &devId, const int32_t ret = ScreenMgrAdapter::GetInstance().RegisterScreenGroupListener(dScreenGroupListener_); if (ret != DH_SUCCESS) { DHLOGE("DScreenManager2.0 EnableDistributedScreen failed, err: %" PRId32, ret); - delete dScreenGroupListener_; dScreenGroupListener_ = nullptr; return ERR_DH_SCREEN_SA_ENABLE_FAILED; } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp index 0401884a2e5db276b23c11695f4611c6b2e46eae..b55c2ada431c5dd8a0c7284954986a3eab1d6014 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp @@ -52,7 +52,7 @@ void DScreenTestV1::SetUp(void) dScreen_->videoParam_->SetVideoWidth(videoDataNum); dScreen_->videoParam_->SetScreenHeight(videoDataNum); dScreen_->videoParam_->SetScreenWidth(videoDataNum); - dScreen_->videoParam_->SetFps(videoDataNum); + dScreen_->videoParam_->SetFps(DEFAULT_FPS); dScreen_->devId_ = "peerDevId"; } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp index d36d7a965d6b7a5fd8206dacc788611f36b9ebfb..85e1acc0ce893b6bbb93bfb04c5f73346de5df4d 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp @@ -234,7 +234,7 @@ HWTEST_F(DScreenManagerAdapterTest, SetImageSurface_001, TestSize.Level1) */ HWTEST_F(DScreenManagerAdapterTest, GetMapRelation_001, TestSize.Level1) { - std::shared_ptr ret = ScreenMgrAdapter::GetInstance().GetMapRelation(1000); + std::shared_ptr ret = ScreenMgrAdapter::GetInstance().GetMapRelation(100000); EXPECT_EQ(nullptr, ret); } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp index 5534a2cd0e51e00516a98f4ff30eb7953c9fd6de..4fcda388d64d4f24413c2d7eda96d04dff1c13ce 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp @@ -50,7 +50,7 @@ void DScreenTestV2::SetUp(void) dScreen_->videoParam_->SetVideoWidth(videoDataNum); dScreen_->videoParam_->SetScreenHeight(videoDataNum); dScreen_->videoParam_->SetScreenWidth(videoDataNum); - dScreen_->videoParam_->SetFps(videoDataNum); + dScreen_->videoParam_->SetFps(DEFAULT_FPS); dScreen_->devId_ = "peerDevId"; } @@ -310,7 +310,7 @@ HWTEST_F(DScreenTestV2, SetUp_002, TestSize.Level1) HWTEST_F(DScreenTestV2, SetUp_003, TestSize.Level1) { dScreen_->senderAdapter_ = std::make_shared(); - dScreen_->screenId_ = 2; + dScreen_->screenId_ = 200000; int32_t ret = dScreen_->SetUp(); EXPECT_EQ(ERR_DH_AV_TRANS_SETUP_FAILED, ret); } diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 49790da1e96bd9129b4c38e4273f06b69ec5a6a9..425c3cf96a69a5d8089198db03622ac22f191bbe 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -350,7 +350,7 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) imageFormat_.PutLongValue("max_input_size", MAX_YUV420_BUFFER_SIZE); imageFormat_.PutIntValue("width", configParam.GetVideoWidth()); imageFormat_.PutIntValue("height", configParam.GetVideoHeight()); - imageFormat_.PutIntValue("frame_rate", configParam.GetFps()); + imageFormat_.PutDoubleValue("frame_rate", configParam.GetFps()); int32_t ret = videoDecoder_->Configure(imageFormat_); if (ret != MediaAVCodec::AVCS_ERR_OK) { diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index d43d3d2aabe2a2174e5ef23442e7b3fee6f2aadc..228276553fb75fc537896569df1ef204774606d4 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -373,7 +373,7 @@ int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam) imageFormat_.PutLongValue("max_input_size", MAX_YUV420_BUFFER_SIZE); imageFormat_.PutIntValue("width", configParam.GetVideoWidth()); imageFormat_.PutIntValue("height", configParam.GetVideoHeight()); - imageFormat_.PutIntValue("frame_rate", configParam.GetFps()); + imageFormat_.PutDoubleValue("frame_rate", configParam.GetFps()); int32_t ret = videoEncoder_->Configure(imageFormat_); if (ret != MediaAVCodec::AVCS_ERR_OK) { diff --git a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp index 625458eba0a7f2463d2dc3997ad89bf6ab7e08cf..f07f96b0aec430134b888de6e8b3d49aab55d902 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp +++ b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp @@ -43,7 +43,8 @@ void ImageSinkDecoderTest::SetUp(void) imageListener_ = std::make_shared(); imageDecoder_ = std::make_shared(imageListener_); - imageDecoder_->videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime("video/avc"); + imageDecoder_->videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); } void ImageSinkDecoderTest::TearDown(void) {} diff --git a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp index 4e4df023234e79d7a17f671df434c710a482d508..56516af904573946089b413103e3c04e1ea808e4 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp +++ b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp @@ -43,7 +43,8 @@ void ImageSinkProcessorTest::SetUp(void) processor_ = std::make_shared(); imageListener_ = std::make_shared(); processor_->imageDecoder_ = std::make_shared(imageListener_); - processor_->imageDecoder_->videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime("video/avc"); + processor_->imageDecoder_->videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); } void ImageSinkProcessorTest::TearDown(void) {} diff --git a/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp b/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp index db6688fcb255123d7524e421e0624b071f23d985..391c4e36f802021130fe558ba1b69bdcc64c4e5e 100644 --- a/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp +++ b/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp @@ -97,7 +97,8 @@ HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_001, TestSize.Level1) */ HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_002, TestSize.Level1) { - encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime("video/avc"); + encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); int32_t actual = encoder->ReleaseEncoder(); EXPECT_EQ(DH_SUCCESS, actual); @@ -149,7 +150,8 @@ HWTEST_F(ImageSourceEncoderTest, StopEncoder_001, TestSize.Level1) */ HWTEST_F(ImageSourceEncoderTest, StopEncoder_002, TestSize.Level1) { - encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime("video/avc"); + encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); int32_t actual = encoder->StopEncoder(); EXPECT_EQ(ERR_DH_SCREEN_CODEC_STOP_FAILED, actual); diff --git a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h index c005e074622d1102bea160faf216429a6a3869c6..a0a36c99fc850f8882cbbfd998f57ce499d53e93 100644 --- a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h +++ b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h @@ -32,7 +32,7 @@ constexpr int32_t VIDEO_CODEC_TYPE_INVALID = -1; constexpr int32_t VIDEO_DATA_FORMAT_INVALID = -1; constexpr int32_t WIDTH_INVALID = 9999; constexpr int32_t HEIGHT_INVALID = 9999; -constexpr int32_t FPS = 30; +constexpr double FPS = 30.0; constexpr size_t DATA_LEN = 128; class MockIScreenSinkTransCallback : public IScreenSinkTransCallback { diff --git a/services/softbusadapter/src/softbus_adapter.cpp b/services/softbusadapter/src/softbus_adapter.cpp index cfad3800e59b1fc9c40de959571288b06fa510d1..624298b2d44d3be4044d252b11f934b4c2885960 100644 --- a/services/softbusadapter/src/softbus_adapter.cpp +++ b/services/softbusadapter/src/softbus_adapter.cpp @@ -208,7 +208,10 @@ int32_t SoftbusAdapter::OpenSoftbusSession(const std::string &mySessionName, con return ERR_DH_SCREEN_TRANS_ERROR; } PeerSocketInfo info; - listener->OnSessionOpened(socketId, info); + ret = OnSoftbusSessionOpened(socketId, info); + if (ret != DH_SUCCESS) { + return ret; + } DHLOGI("%s: OpenSoftbusSession success sessionId: %." PRId32, LOG_TAG, socketId); return socketId; } @@ -255,7 +258,7 @@ int32_t SoftbusAdapter::SendSoftbusStream(int32_t sessionId, const StreamData *d std::shared_ptr &SoftbusAdapter::GetSoftbusListenerByName(int32_t sessionId) { - DHLOGD("%s: SendSoftbusStream, sessionId:%" PRId32, LOG_TAG, sessionId); + DHLOGD("%s: GetSoftbusListenerByName, sessionId:%" PRId32, LOG_TAG, sessionId); std::string strListenerKey = ""; { std::lock_guard lock(idMapMutex_); @@ -287,11 +290,14 @@ std::shared_ptr &SoftbusAdapter::GetSoftbusListenerById(int32_ int32_t SoftbusAdapter::OnSoftbusSessionOpened(int32_t sessionId, PeerSocketInfo info) { - DHLOGI("%s: OnSessionOpened session:%" PRId32, LOG_TAG, sessionId); - std::string peerDevId(info.networkId); + DHLOGI("%s: OnSoftbusSessionOpened session:%" PRId32, LOG_TAG, sessionId); { std::lock_guard lock(serverIdMapMutex_); for (auto it = serverIdMap_.begin(); it != serverIdMap_.end(); it++) { + if (info.networkId == nullptr) { + break; + } + std::string peerDevId(info.networkId); if ((it->second).find(peerDevId) != std::string::npos) { std::lock_guard sessionLock(idMapMutex_); devId2SessIdMap_.insert(std::make_pair(sessionId, it->second));