From 4cb730906adb7b1f44eb85a944720439884be29e Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Sat, 30 Mar 2024 22:01:13 +0800 Subject: [PATCH] NewFeature. fix tdd bug for screencapture Signed-off-by: yuanjinghua Change-Id: I68de452ab560b7ee60aa71b0510d8abebc846fce --- .../screencapture/native_avscreen_capture.cpp | 2 +- .../screen_capture/screen_capture_impl.cpp | 2 +- .../server/audio_capturer_wrapper.cpp | 9 +- .../server/audio_capturer_wrapper.h | 2 +- .../server/screen_capture_server.cpp | 57 ++++-- .../src/screen_capture_unit_test.cpp | 188 ++++++++++-------- .../src/screen_capture_unit_test_state.cpp | 149 +++++++------- 7 files changed, 215 insertions(+), 194 deletions(-) diff --git a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp index 8278026f1..231a7ab77 100644 --- a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp +++ b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp @@ -812,7 +812,7 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetDataCallback(struct OH_AVScree if (screenCaptureObj->callback_ == nullptr || !screenCaptureObj->callback_->SetDataCallback(callback, userData)) { - MEDIA_LOGE("OH_AVScreenCapture_SetErrorCallback error"); + MEDIA_LOGE("OH_AVScreenCapture_SetDataCallback error"); return AV_SCREEN_CAPTURE_ERR_NO_MEMORY; } MEDIA_LOGD("OH_AVScreenCapture_SetDataCallback E"); diff --git a/frameworks/native/screen_capture/screen_capture_impl.cpp b/frameworks/native/screen_capture/screen_capture_impl.cpp index c25f8316f..8cd38147f 100644 --- a/frameworks/native/screen_capture/screen_capture_impl.cpp +++ b/frameworks/native/screen_capture/screen_capture_impl.cpp @@ -246,7 +246,7 @@ int32_t ScreenCaptureImpl::StartScreenCaptureWithSurface(sptr surface) if (dataType_ == ORIGINAL_STREAM) { return screenCaptureService_->StartScreenCaptureWithSurface(surface, isPrivacyAuthorityEnabled_); } else { - MEDIA_LOGE("ScreenCaptureImpl::StartScreenCapture error , dataType_ : %{public}d", dataType_); + MEDIA_LOGE("ScreenCaptureImpl::StartScreenCaptureWithSurface error , dataType_ : %{public}d", dataType_); return MSERR_INVALID_VAL; } } diff --git a/services/services/screen_capture/server/audio_capturer_wrapper.cpp b/services/services/screen_capture/server/audio_capturer_wrapper.cpp index 4bf7b9cc7..df71566f8 100644 --- a/services/services/screen_capture/server/audio_capturer_wrapper.cpp +++ b/services/services/screen_capture/server/audio_capturer_wrapper.cpp @@ -19,7 +19,7 @@ #include "media_errors.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SC_AudioCapturerWrapper"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "ScreenCaptureACW"}; } namespace OHOS { @@ -105,7 +105,7 @@ void AudioCapturerWrapper::SetIsMuted(bool isMuted) isMuted_.store(isMuted); } -void AudioCapturerWrapper::SetInnerAudioStreamUsage(std::vector &usages) +void AudioCapturerWrapper::SetInnerStreamUsage(std::vector &usages) { // If do not call this function, the audio framework use MUSIC/MOVIE/GAME/AUDIOBOOK usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); @@ -117,8 +117,7 @@ void AudioCapturerWrapper::SetInnerAudioStreamUsage(std::vector AudioCapturerWrapper::CreateAudioCapturer( - const OHOS::AudioStandard::AppInfo &appInfo) +std::shared_ptr AudioCapturerWrapper::CreateAudioCapturer(const OHOS::AudioStandard::AppInfo &appInfo) { AudioCapturerOptions capturerOptions; capturerOptions.streamInfo.samplingRate = static_cast(audioInfo_.audioSampleRate); @@ -131,7 +130,7 @@ std::shared_ptr AudioCapturerWrapper::CreateAudioCapturer( } else if (audioInfo_.audioSource == AudioCaptureSourceType::ALL_PLAYBACK || audioInfo_.audioSource == AudioCaptureSourceType::APP_PLAYBACK) { capturerOptions.capturerInfo.sourceType = SourceType::SOURCE_TYPE_PLAYBACK_CAPTURE; - SetInnerAudioStreamUsage(capturerOptions.playbackCaptureConfig.filterOptions.usages); + SetInnerStreamUsage(capturerOptions.playbackCaptureConfig.filterOptions.usages); } capturerOptions.capturerInfo.capturerFlags = 0; std::shared_ptr audioCapturer = AudioCapturer::Create(capturerOptions, appInfo); diff --git a/services/services/screen_capture/server/audio_capturer_wrapper.h b/services/services/screen_capture/server/audio_capturer_wrapper.h index 042c020f2..c3fda9826 100644 --- a/services/services/screen_capture/server/audio_capturer_wrapper.h +++ b/services/services/screen_capture/server/audio_capturer_wrapper.h @@ -56,7 +56,7 @@ protected: private: std::shared_ptr CreateAudioCapturer( const OHOS::AudioStandard::AppInfo &appInfo); - static void SetInnerAudioStreamUsage(std::vector &usages); + static void SetInnerStreamUsage(std::vector &usages); protected: std::shared_ptr screenCaptureCb_; diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index f51f087db..6d7742938 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -331,7 +331,7 @@ int32_t ScreenCaptureServer::InitVideoEncInfo(VideoEncInfo videoEncInfo) MEDIA_LOGD("videoEncInfo videoCodec:%{public}d, videoBitrate:%{public}d, videoFrameRate:%{public}d", videoEncInfo.videoCodec, videoEncInfo.videoBitrate, videoEncInfo.videoFrameRate); int32_t ret = CheckVideoEncInfo(videoEncInfo); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "CheckVideoEncInfo failed, ret:%{public}d", ret); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "InitVideoEncInfo failed, ret:%{public}d", ret); captureConfig_.videoInfo.videoEncInfo = videoEncInfo; return MSERR_OK; } @@ -918,6 +918,9 @@ bool ScreenCaptureServer::UpdatePrivacyUsingPermissionState(VideoPermissionState int32_t ScreenCaptureServer::StartScreenCaptureInner(bool isPrivacyAuthorityEnabled) { + MEDIA_LOGI("StartScreenCaptureInner S, appUid:%{public}d, appPid:%{pulibc}d, isPrivacyAuthorityEnabled:%{pulibc}d" + ", isSurfaceMode:%{public}d, dataType:%{public}d", appInfo_.appUid, appInfo_.appPid, isPrivacyAuthorityEnabled, + isSurfaceMode_, captureConfig_.dataType); MediaTrace trace("ScreenCaptureServer::StartScreenCaptureInner"); int32_t ret = CheckAllParams(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "StartScreenCaptureInner failed, invalid params"); @@ -950,6 +953,7 @@ int32_t ScreenCaptureServer::StartScreenCaptureInner(bool isPrivacyAuthorityEnab ret = OnStartScreenCapture(); PostStartScreenCapture(ret == MSERR_OK); + MEDIA_LOGI("StartScreenCaptureInner E, appUid:%{public}d, appPid:%{pulibc}d", appInfo_.appUid, appInfo_.appPid); return ret; } @@ -1137,8 +1141,10 @@ void ScreenCaptureServer::UpdateLiveViewContent() int32_t ScreenCaptureServer::StartScreenCapture(bool isPrivacyAuthorityEnabled) { std::lock_guard lock(mutex_); - CHECK_AND_RETURN_RET_LOG(captureState_ == AVScreenCaptureState::CREATED, MSERR_INVALID_OPERATION, - "StartScreenCapture failed, capture is not CREATED, state:%{public}d", captureState_); + CHECK_AND_RETURN_RET_LOG( + captureState_ == AVScreenCaptureState::CREATED || captureState_ == AVScreenCaptureState::STOPPED, + MSERR_INVALID_OPERATION, "StartScreenCapture failed, not in CREATED or STOPPED, state:%{public}d", + captureState_); MEDIA_LOGI("StartScreenCapture isPrivacyAuthorityEnabled:%{public}d", isPrivacyAuthorityEnabled); isSurfaceMode_ = false; return StartScreenCaptureInner(isPrivacyAuthorityEnabled); @@ -1147,8 +1153,10 @@ int32_t ScreenCaptureServer::StartScreenCapture(bool isPrivacyAuthorityEnabled) int32_t ScreenCaptureServer::StartScreenCaptureWithSurface(sptr surface, bool isPrivacyAuthorityEnabled) { std::lock_guard lock(mutex_); - CHECK_AND_RETURN_RET_LOG(captureState_ == AVScreenCaptureState::CREATED, MSERR_INVALID_OPERATION, - "StartScreenCaptureWithSurface failed, capture is not CREATED, state:%{public}d", captureState_); + CHECK_AND_RETURN_RET_LOG( + captureState_ == AVScreenCaptureState::CREATED || captureState_ == AVScreenCaptureState::STOPPED, + MSERR_INVALID_OPERATION, "StartScreenCaptureWithSurface failed, not in CREATED or STOPPED, state:%{public}d", + captureState_); MEDIA_LOGI("StartScreenCaptureWithSurface isPrivacyAuthorityEnabled:%{public}d", isPrivacyAuthorityEnabled); if (surface == nullptr) { MEDIA_LOGE("surface is nullptr"); @@ -1171,12 +1179,14 @@ int32_t ScreenCaptureServer::StartVideoCapture() int32_t ret = StartHomeVideoCapture(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, - "StartHomeVideoCapture failed, invalid param, dataType:%{public}d", captureConfig_.dataType); + "StartHomeVideoCapture failed, isSurfaceMode:%{public}d, dataType:%{public}d", + isSurfaceMode_, captureConfig_.dataType); return MSERR_OK; } int32_t ScreenCaptureServer::StartHomeVideoCapture() { + MediaTrace trace("ScreenCaptureServer::StartHomeVideoCapture"); std::string virtualScreenName = "screen_capture"; if (isSurfaceMode_) { int32_t ret = CreateVirtualScreen(virtualScreenName, surface_); @@ -1256,30 +1266,34 @@ int32_t ScreenCaptureServer::MakeVirtualScreenMirror() CHECK_AND_RETURN_RET_LOG(screenId_ >= 0 && screenId_ != SCREEN_ID_INVALID, MSERR_UNKNOWN, "MakeVirtualScreenMirror failed, invalid screenId"); std::vector> screens; - ScreenManager::GetInstance().GetAllScreens(screens); + DMError ret = ScreenManager::GetInstance().GetAllScreens(screens); + CHECK_AND_RETURN_RET_LOG(screens.size() > 0, MSERR_UNKNOWN, + "MakeVirtualScreenMirror failed to GetAllScreens, ret:%{public}d", ret); std::vector mirrorIds; mirrorIds.push_back(screenId_); ScreenId mirrorGroup = static_cast(1); - DMError ret = DMError::DM_OK; if (captureConfig_.captureMode != CAPTURE_SPECIFIED_SCREEN) { ret = ScreenManager::GetInstance().MakeMirror(screens[0]->GetId(), mirrorIds, mirrorGroup); - MEDIA_LOGI("MakeVirtualScreenMirror main screen"); + CHECK_AND_RETURN_RET_LOG(ret == DMError::DM_OK, MSERR_UNKNOWN, + "MakeVirtualScreenMirror failed to MakeMirror, captureMode:%{public}d, ret:%{public}d", + captureConfig_.captureMode, ret); + MEDIA_LOGI("MakeVirtualScreenMirror main screen success, screenId:%{public}" PRIu64, screens[0]->GetId()); + return MSERR_OK; } for (uint32_t i = 0; i < screens.size() ; i++) { if (screens[i]->GetId() == captureConfig_.videoInfo.videoCapInfo.displayId) { ret = ScreenManager::GetInstance().MakeMirror(screens[i]->GetId(), mirrorIds, mirrorGroup); - MEDIA_LOGI("MakeVirtualScreenMirror extand screen"); - break; + CHECK_AND_RETURN_RET_LOG(ret == DMError::DM_OK, MSERR_UNKNOWN, + "MakeVirtualScreenMirror failed to MakeMirror for CAPTURE_SPECIFIED_SCREEN, ret:%{public}d", ret); + MEDIA_LOGI("MakeVirtualScreenMirror extand screen success, screenId:%{public}" PRIu64, + captureConfig_.videoInfo.videoCapInfo.displayId); + return MSERR_OK; } } - if (ret == DMError::DM_OK) { - MEDIA_LOGI("MakeMirror success"); - return MSERR_OK; - } else { - MEDIA_LOGI("MakeMirror fail"); - return MSERR_UNKNOWN; - } + MEDIA_LOGE("MakeVirtualScreenMirror failed to find screenId:%{public}" PRIu64, + captureConfig_.videoInfo.videoCapInfo.displayId); + return MSERR_UNKNOWN; } void ScreenCaptureServer::DestroyVirtualScreen() @@ -1473,8 +1487,9 @@ int32_t ScreenCaptureServer::StopVideoCapture() } DestroyVirtualScreen(); - if ((consumer_ != nullptr)) { + if (consumer_ != nullptr) { consumer_->UnregisterConsumerListener(); + consumer_ = nullptr; } if (surfaceCb_ != nullptr) { @@ -1487,7 +1502,7 @@ int32_t ScreenCaptureServer::StopVideoCapture() int32_t ScreenCaptureServer::StopScreenCaptureRecorder() { - MEDIA_LOGE("StopScreenCaptureRecorder start"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances StopScreenCaptureRecorder S", FAKE_POINTER(this)); MediaTrace trace("ScreenCaptureServer::StopScreenCaptureRecorder"); int32_t ret = MSERR_OK; if (recorder_ != nullptr) { @@ -1507,7 +1522,7 @@ int32_t ScreenCaptureServer::StopScreenCaptureRecorder() int32_t ScreenCaptureServer::StopScreenCaptureByEvent(AVScreenCaptureStateCode stateCode) { - MEDIA_LOGE("StopScreenCaptureByEvent start"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances StopScreenCaptureByEvent S", FAKE_POINTER(this)); MediaTrace trace("ScreenCaptureServer::StopScreenCaptureByEvent"); std::lock_guard lock(mutex_); return StopScreenCaptureInner(stateCode); diff --git a/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp b/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp index 5867431d9..673bdfb10 100644 --- a/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp +++ b/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp @@ -40,9 +40,6 @@ namespace Media { HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_01, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_01 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); RecorderInfo recorderInfo; SetRecorderInfo("screen_capture_specified_window_file_01.mp4", recorderInfo); SetConfigFile(config_, recorderInfo); @@ -57,14 +54,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_01, TestSiz std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 20, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_01 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_01 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); + MEDIA_LOGI("screen_capture_specified_window_file_01 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_01 missionId : %{public}d", info.id); + MEDIA_LOGI("screen_capture_specified_window_file_01 missionId : %{public}d", info.id); } if (missionInfos.size() > 0) { config_.videoInfo.videoCapInfo.taskIDs.push_back(missionInfos[0].id); + } else { + MEDIA_LOGE("screen_capture_specified_window_file_01 GetMissionInfos failed"); } EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); @@ -84,9 +82,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_01, TestSiz HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_02, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_02 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); RecorderInfo recorderInfo; SetRecorderInfo("screen_capture_specified_window_file_02.mp4", recorderInfo); SetConfigFile(config_, recorderInfo); @@ -101,14 +96,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_02, TestSiz std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 20, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_02 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_02 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); + MEDIA_LOGI("screen_capture_specified_window_file_02 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_02 missionId : %{public}d", info.id); + MEDIA_LOGI("screen_capture_specified_window_file_02 missionId : %{public}d", info.id); } if (missionInfos.size() > 0) { config_.videoInfo.videoCapInfo.taskIDs.push_back(missionInfos[(missionInfos.size()-1)/2].id); + } else { + MEDIA_LOGE("screen_capture_specified_window_file_02 GetMissionInfos failed"); } EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); @@ -128,9 +124,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_02, TestSiz HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_03, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_03 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); RecorderInfo recorderInfo; SetRecorderInfo("screen_capture_specified_window_file_03.mp4", recorderInfo); SetConfigFile(config_, recorderInfo); @@ -145,14 +138,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_03, TestSiz std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 20, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_03 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_03 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); + MEDIA_LOGI("screen_capture_specified_window_file_03 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_03 missionId : %{public}d", info.id); + MEDIA_LOGI("screen_capture_specified_window_file_03 missionId : %{public}d", info.id); } if (missionInfos.size() > 0) { config_.videoInfo.videoCapInfo.taskIDs.push_back(missionInfos[missionInfos.size()-1].id); + } else { + MEDIA_LOGE("screen_capture_specified_window_file_03 GetMissionInfos failed"); } EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); @@ -172,9 +166,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_03, TestSiz HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_04, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_04 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); RecorderInfo recorderInfo; SetRecorderInfo("screen_capture_specified_window_file_04.mp4", recorderInfo); SetConfigFile(config_, recorderInfo); @@ -189,12 +180,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_04, TestSiz std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 20, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_04 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_04 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_04 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_file_04 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_file_04 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_file_04 GetMissionInfos failed"); } EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); @@ -214,23 +208,23 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_file_04, TestSiz HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_WINDOW; std::shared_ptr client_ = OHOS::AAFwk::AbilityManagerClient::GetInstance(); std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window GetMissionInfos failed"); } - OpenFile("screen_capture_specified_window_data"); + OpenFile("screen_capture_specified_window"); aFlag = 1; vFlag = 1; @@ -257,23 +251,23 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window, TestSize.Level2 HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_Rotation, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_Rotation before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_WINDOW; std::shared_ptr client_ = OHOS::AAFwk::AbilityManagerClient::GetInstance(); std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_Rotation result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_Rotation size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_Rotation missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_Rotation missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_Rotation missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_Rotation GetMissionInfos failed"); } - OpenFile("screen_capture_specified_window_data"); + OpenFile("screen_capture_specified_window_Rotation"); aFlag = 1; vFlag = 1; @@ -616,12 +610,18 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_file_01, TestSiz config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_SCREEN; std::vector> screens; - ScreenManager::GetInstance().GetAllScreens(screens); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_01 screens = size-1 : %{public}s", - std::to_string(screens[screens.size()-1]->GetId()).c_str()); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_01 screens = 0 : %{public}s", - std::to_string(screens[0]->GetId()).c_str()); - config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); + DMError ret = ScreenManager::GetInstance().GetAllScreens(screens); + MEDIA_LOGI("screen_capture_specified_screen_file_01 screens size:%{public}s, ret:%{public}d", + std::to_string(screens.size()).c_str(), ret); + if (screens.size() > 0) { + MEDIA_LOGI("screen_capture_specified_screen_file_01 screens id(size-1):%{public}s", + std::to_string(screens[screens.size() - 1]->GetId()).c_str()); + MEDIA_LOGI("screen_capture_specified_screen_file_01 screens id(size-1):%{public}s", + std::to_string(screens[0]->GetId()).c_str()); + config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); + } else { + MEDIA_LOGE("screen_capture_specified_screen_file_01 GetAllScreens failed"); + } EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); @@ -641,10 +641,10 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_file_02, TestSiz { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_02 before"); RecorderInfo recorderInfo; - SetRecorderInfo("screen_capture_get_screen_capture_02.mp4", recorderInfo); + SetRecorderInfo("screen_capture_specified_screen_file_02.mp4", recorderInfo); SetConfigFile(config_, recorderInfo); AudioCaptureInfo innerCapInfo = { - .audioSampleRate = 16000, + .audioSampleRate = 48000, .audioChannels = 2, .audioSource = AudioCaptureSourceType::APP_PLAYBACK }; @@ -652,13 +652,18 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_file_02, TestSiz config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_SCREEN; std::vector> screens; - ScreenManager::GetInstance().GetAllScreens(screens); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_02 size : %{public}s", - std::to_string(screens.size()).c_str()); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_02 screens = size-1 : %{public}s", - std::to_string(screens[screens.size()-1]->GetId()).c_str()); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_02 screens = 0 : %{public}s", - std::to_string(screens[0]->GetId()).c_str()); + DMError ret = ScreenManager::GetInstance().GetAllScreens(screens); + MEDIA_LOGI("screen_capture_specified_screen_file_02 screens size:%{public}s, ret:%{public}d", + std::to_string(screens.size()).c_str(), ret); + if (screens.size() > 0) { + MEDIA_LOGI("screen_capture_specified_screen_file_02 screens id(size-1):%{public}s", + std::to_string(screens[screens.size() - 1]->GetId()).c_str()); + MEDIA_LOGI("screen_capture_specified_screen_file_02 screens id(size-1):%{public}s", + std::to_string(screens[0]->GetId()).c_str()); + config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); + } else { + MEDIA_LOGE("screen_capture_specified_screen_file_02 GetAllScreens failed"); + } config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); @@ -680,7 +685,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_file_03, TestSiz { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_03 before"); RecorderInfo recorderInfo; - SetRecorderInfo("screen_capture_get_screen_capture_03.mp4", recorderInfo); + SetRecorderInfo("screen_capture_specified_screen_file_03.mp4", recorderInfo); SetConfigFile(config_, recorderInfo); AudioCaptureInfo micCapInfo = { .audioSampleRate = 16000, @@ -697,12 +702,18 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_file_03, TestSiz config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_SCREEN; std::vector> screens; - ScreenManager::GetInstance().GetAllScreens(screens); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_03 screens = size-1 : %{public}s", - std::to_string(screens[screens.size()-1]->GetId()).c_str()); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_file_03 screens = 0 : %{public}s", - std::to_string(screens[0]->GetId()).c_str()); - config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); + DMError ret = ScreenManager::GetInstance().GetAllScreens(screens); + MEDIA_LOGI("screen_capture_specified_screen_file_03 screens size:%{public}s, ret:%{public}d", + std::to_string(screens.size()).c_str(), ret); + if (screens.size() > 0) { + MEDIA_LOGI("screen_capture_specified_screen_file_03 screens id(size-1):%{public}s", + std::to_string(screens[screens.size() - 1]->GetId()).c_str()); + MEDIA_LOGI("screen_capture_specified_screen_file_03 screens id(size-1):%{public}s", + std::to_string(screens[0]->GetId()).c_str()); + config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); + } else { + MEDIA_LOGE("screen_capture_specified_screen_file_03 GetAllScreens failed"); + } EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); @@ -720,12 +731,22 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_file_03, TestSiz */ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_01, TestSize.Level1) { + MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_01 before"); SetConfig(config_); config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; std::vector> screens; - ScreenManager::GetInstance().GetAllScreens(screens); - config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); - + DMError ret = ScreenManager::GetInstance().GetAllScreens(screens); + MEDIA_LOGI("screen_capture_specified_screen_01 screens size:%{public}s, ret:%{public}d", + std::to_string(screens.size()).c_str(), ret); + if (screens.size() > 0) { + MEDIA_LOGI("screen_capture_specified_screen_01 screens id(size-1):%{public}s", + std::to_string(screens[screens.size() - 1]->GetId()).c_str()); + MEDIA_LOGI("screen_capture_specified_screen_01 screens id(size-1):%{public}s", + std::to_string(screens[0]->GetId()).c_str()); + config_.videoInfo.videoCapInfo.displayId = screens[0]->GetId(); + } else { + MEDIA_LOGE("screen_capture_specified_screen_01 GetAllScreens failed"); + } OpenFile("screen_capture_specified_screen_01"); aFlag = 1; @@ -741,6 +762,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_screen_01, TestSize.Lev EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); EXPECT_EQ(MSERR_OK, screenCapture_->Release()); CloseFile(); + MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_screen_01 after"); } /** @@ -1743,12 +1765,9 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_mic_close_open_close, TestSize.Le HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_01, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_01 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); - config_.videoInfo.videoCapInfo.videoFrameWidth = 1920; - config_.videoInfo.videoCapInfo.videoFrameHeight = 1080; + config_.videoInfo.videoCapInfo.videoFrameWidth = 720; + config_.videoInfo.videoCapInfo.videoFrameHeight = 1280; config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; bool isMicrophone = true; screenCapture_->SetMicrophoneEnabled(isMicrophone); @@ -1759,7 +1778,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_01, TestSize.Level2) EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); - EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 1080, 1920)); + EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1280)); EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); OpenFileFd("screen_capture_with_surface_01.mp4"); @@ -1790,12 +1809,9 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_01, TestSize.Level2) HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_02, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_02 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); - config_.videoInfo.videoCapInfo.videoFrameWidth = 640; - config_.videoInfo.videoCapInfo.videoFrameHeight = 480; + config_.videoInfo.videoCapInfo.videoFrameWidth = 480; + config_.videoInfo.videoCapInfo.videoFrameHeight = 640; config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; bool isMicrophone = true; screenCapture_->SetMicrophoneEnabled(isMicrophone); diff --git a/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test_state.cpp b/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test_state.cpp index ba255c95b..5ec03bba3 100644 --- a/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test_state.cpp +++ b/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test_state.cpp @@ -109,6 +109,7 @@ void ScreenCaptureUnitTestCallback::OnVideoBufferAvailable(bool isReady) ASSERT_FALSE(screenCapture_->IsDataCallBackEnabled()); if (!isReady) { cout << "OnVideoBufferAvailable isReady false E" << endl; + return; } cout << "OnVideoBufferAvailable isReady true" << endl; int32_t fence = 0; @@ -461,11 +462,13 @@ int32_t ScreenCaptureUnitTest::SetRecorderInfo(std::string name, RecorderInfo &r void ScreenCaptureUnitTest::OpenFileFd(std::string name) { + CloseFile(); outputFd_ = open((SCREEN_CAPTURE_ROOT_DIR + name).c_str(), O_RDWR | O_CREAT, FLIE_CREATE_FLAGS); } void ScreenCaptureUnitTest::OpenFile(std::string name) { + CloseFile(); std::string nameFormt = SCREEN_CAPTURE_ROOT_DIR + "%s.pcm"; if (snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, nameFormt.c_str(), name.c_str()) >= 0) { @@ -578,9 +581,6 @@ void ScreenCaptureUnitTest::AudioLoopWithoutRelease(void) HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_01, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_01 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.innerCapInfo.audioSampleRate = 16000; config_.audioInfo.innerCapInfo.audioChannels = 2; @@ -590,12 +590,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_01, TestSize. std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_01 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_01 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_01 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_01 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_01 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_01 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -632,9 +635,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_01, TestSize. HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_02, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_02 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.innerCapInfo.audioSampleRate = 16000; config_.audioInfo.innerCapInfo.audioChannels = 2; @@ -644,12 +644,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_02, TestSize. std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_02 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_02 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_02 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_02 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_02 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_02 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -684,21 +687,21 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_02, TestSize. HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_03, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_03 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_WINDOW; std::shared_ptr client_ = OHOS::AAFwk::AbilityManagerClient::GetInstance(); std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_03 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_03 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_03 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_03 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_03 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_03 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -733,9 +736,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_03, TestSize. HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_04, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_04 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.micCapInfo.audioSampleRate = 0; config_.audioInfo.micCapInfo.audioChannels = 0; @@ -748,12 +748,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_04, TestSize. std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_04 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_04 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_04 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_04 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_04 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_04 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -788,9 +791,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_04, TestSize. HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_05, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_05 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.videoInfo.videoCapInfo.videoFrameWidth = 0; config_.videoInfo.videoCapInfo.videoFrameHeight = 0; @@ -802,12 +802,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_05, TestSize. std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_05 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_05 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_05 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_05 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_05 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_05 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -842,9 +845,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_05, TestSize. HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_06, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_06 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.videoInfo.videoCapInfo.videoFrameWidth = 0; config_.videoInfo.videoCapInfo.videoFrameHeight = 0; @@ -859,12 +859,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_06, TestSize. std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_06 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_06 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_06 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_06 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_06 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_06 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -899,9 +902,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_06, TestSize. HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_07, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_07 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.micCapInfo.audioSampleRate = 0; config_.audioInfo.micCapInfo.audioChannels = 0; @@ -911,12 +911,15 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_specified_window_cb_07, TestSize. std::string deviceId = ""; std::vector missionInfos; auto result = client_->GetMissionInfos(deviceId, 10, missionInfos); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_07 result : %{public}d", result); - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_07 size : %{public}s", - std::to_string(missionInfos.size()).c_str()); - for (OHOS::AAFwk::MissionInfo info : missionInfos) { - MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_cb_07 missionId : %{public}d", info.id); - config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + MEDIA_LOGI("screen_capture_specified_window_cb_07 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + if (missionInfos.size() > 0) { + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_cb_07 missionId:%{public}d", info.id); + config_.videoInfo.videoCapInfo.taskIDs.push_back(info.id); + } + } else { + MEDIA_LOGE("screen_capture_specified_window_cb_07 GetMissionInfos failed"); } screenCaptureCb_ = std::make_shared(screenCapture_); @@ -1016,9 +1019,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_save_file_cb_02, TestSize.Level2) HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_01, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_cb_01 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.innerCapInfo.audioSampleRate = 16000; config_.audioInfo.innerCapInfo.audioChannels = 2; @@ -1032,7 +1032,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_01, TestSize.Leve EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); - EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 1080, 1920)); + EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); OpenFileFd("screen_capture_with_surface_cb_01.mp4"); @@ -1078,9 +1078,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_01, TestSize.Leve HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_02, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_cb_02 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.micCapInfo.audioSampleRate = 0; config_.audioInfo.micCapInfo.audioChannels = 0; @@ -1096,7 +1093,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_02, TestSize.Leve EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); - EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 1080, 1920)); + EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); OpenFileFd("screen_capture_with_surface_cb_02.mp4"); @@ -1142,9 +1139,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_02, TestSize.Leve HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_03, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_cb_03 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); screenCapture_->SetMicrophoneEnabled(true); MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_cb_03 CreateRecorder"); @@ -1153,7 +1147,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_03, TestSize.Leve EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); - EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 1080, 1920)); + EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); OpenFileFd("screen_capture_with_surface_cb_03.mp4"); @@ -1199,9 +1193,6 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_03, TestSize.Leve HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_04, TestSize.Level2) { MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_cb_04 before"); - Security::AccessToken::AccessTokenID tokenID = - Security::AccessToken::AccessTokenKit::GetNativeTokenId("distributedsched"); - SetSelfTokenID(tokenID); SetConfig(config_); config_.audioInfo.micCapInfo.audioSampleRate = 0; config_.audioInfo.micCapInfo.audioChannels = 0; @@ -1213,7 +1204,7 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_cb_04, TestSize.Leve EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); - EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 1080, 1920)); + EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); OpenFileFd("screen_capture_with_surface_cb_04.mp4"); -- Gitee