1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <fcntl.h> 17 #include <iostream> 18 #include <string> 19 #include "media_errors.h" 20 #include "screen_capture_unit_test.h" 21 #include "ability_manager_client.h" 22 #include "accesstoken_kit.h" 23 #include "token_setproc.h" 24 #include <nativetoken_kit.h> 25 26 using namespace OHOS; 27 using namespace OHOS::Media; 28 using namespace testing::ext; 29 using namespace std; 30 using namespace OHOS::Rosen; 31 using namespace OHOS::Media::ScreenCaptureTestParam; 32 33 namespace OHOS { 34 namespace Media { 35 /** 36 * @tc.name: screen_capture_exclude_content_001 37 * @tc.desc: screen capture exclude window content test 38 * @tc.type: FUNC 39 * @tc.require: 40 */ 41 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_001, TestSize.Level2) 42 { 43 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_001 before"); 44 SetConfig(config_); 45 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 46 OpenFile("screen_capture_exclude_content_001"); 47 aFlag = 0; 48 vFlag = 1; 49 bool isMicrophone = true; 50 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 51 ASSERT_NE(nullptr, screenCaptureCb_); 52 screenCapture_->SetMicrophoneEnabled(isMicrophone); 53 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 54 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 55 vector<int> windowIds = {1, 3, 5}; 56 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 57 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 58 sleep(RECORDER_TIME); 59 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 60 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 61 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_001 after"); 62 } 63 64 /** 65 * @tc.name: screen_capture_exclude_content_002 66 * @tc.desc: screen capture exclude audio content test 67 * @tc.type: FUNC 68 * @tc.require: 69 */ 70 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_002, TestSize.Level2) 71 { 72 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_002 before"); 73 SetConfig(config_); 74 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 75 OpenFile("screen_capture_exclude_content_002"); 76 aFlag = 0; 77 vFlag = 1; 78 bool isMicrophone = true; 79 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 80 ASSERT_NE(nullptr, screenCaptureCb_); 81 screenCapture_->SetMicrophoneEnabled(isMicrophone); 82 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 83 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 84 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 85 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 86 sleep(RECORDER_TIME); 87 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 88 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 89 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_002 after"); 90 } 91 92 /** 93 * @tc.name: screen_capture_exclude_content_003 94 * @tc.desc: screen capture exclude audio content test 95 * @tc.type: FUNC 96 * @tc.require: 97 */ 98 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_003, TestSize.Level2) 99 { 100 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_003 before"); 101 SetConfig(config_); 102 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 103 OpenFile("screen_capture_exclude_content_003"); 104 aFlag = 0; 105 vFlag = 1; 106 bool isMicrophone = true; 107 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 108 ASSERT_NE(nullptr, screenCaptureCb_); 109 screenCapture_->SetMicrophoneEnabled(isMicrophone); 110 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 111 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 112 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 113 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 114 sleep(RECORDER_TIME); 115 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 116 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 117 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_003 after"); 118 } 119 120 /** 121 * @tc.name: screen_capture_exclude_content_004 122 * @tc.desc: screen capture exclude window and audio content test 123 * @tc.type: FUNC 124 * @tc.require: 125 */ 126 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_004, TestSize.Level2) 127 { 128 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_004 before"); 129 SetConfig(config_); 130 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 131 OpenFile("screen_capture_exclude_content_004"); 132 aFlag = 0; 133 vFlag = 1; 134 bool isMicrophone = true; 135 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 136 ASSERT_NE(nullptr, screenCaptureCb_); 137 screenCapture_->SetMicrophoneEnabled(isMicrophone); 138 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 139 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 140 vector<int> windowIds = {1, 3, 5}; 141 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 142 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 143 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 144 sleep(RECORDER_TIME); 145 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 146 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 147 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_004 after"); 148 } 149 150 /** 151 * @tc.name: screen_capture_exclude_content_005 152 * @tc.desc: screen capture exclude audio content 153 * @tc.type: FUNC 154 * @tc.require: 155 */ 156 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_005, TestSize.Level2) 157 { 158 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_005 before"); 159 SetConfig(config_); 160 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 161 OpenFile("screen_capture_exclude_content_005"); 162 aFlag = 0; 163 vFlag = 1; 164 bool isMicrophone = true; 165 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 166 ASSERT_NE(nullptr, screenCaptureCb_); 167 screenCapture_->SetMicrophoneEnabled(isMicrophone); 168 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 169 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 170 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 171 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 172 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 173 sleep(RECORDER_TIME); 174 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 175 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 176 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_005 after"); 177 } 178 179 /** 180 * @tc.name: screen_capture_exclude_content_006 181 * @tc.desc: screen capture exclude audio content 182 * @tc.type: FUNC 183 * @tc.require: 184 */ 185 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_006, TestSize.Level2) 186 { 187 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_006 before"); 188 SetConfig(config_); 189 AudioCaptureInfo micCapInfo = { 190 .audioSampleRate = 16000, 191 .audioChannels = 2, 192 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 193 }; 194 config_.audioInfo.micCapInfo = micCapInfo; 195 AudioCaptureInfo innerCapInfo = { 196 .audioSampleRate = 0, 197 .audioChannels = 0, 198 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 199 }; 200 config_.audioInfo.innerCapInfo = innerCapInfo; 201 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 202 OpenFile("screen_capture_exclude_content_006"); 203 aFlag = 0; 204 vFlag = 1; 205 bool isMicrophone = true; 206 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 207 ASSERT_NE(nullptr, screenCaptureCb_); 208 screenCapture_->SetMicrophoneEnabled(isMicrophone); 209 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 210 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 211 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 212 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 213 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 214 sleep(RECORDER_TIME); 215 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 216 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 217 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_006 after"); 218 } 219 220 /** 221 * @tc.name: screen_capture_exclude_content_007 222 * @tc.desc: screen capture exclude audio content 223 * @tc.type: FUNC 224 * @tc.require: 225 */ 226 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_007, TestSize.Level2) 227 { 228 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_007 before"); 229 SetConfig(config_); 230 AudioCaptureInfo micCapInfo = { 231 .audioSampleRate = 0, 232 .audioChannels = 0, 233 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 234 }; 235 config_.audioInfo.micCapInfo = micCapInfo; 236 AudioCaptureInfo innerCapInfo = { 237 .audioSampleRate = 0, 238 .audioChannels = 0, 239 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 240 }; 241 config_.audioInfo.innerCapInfo = innerCapInfo; 242 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 243 OpenFile("screen_capture_exclude_content_007"); 244 aFlag = 0; 245 vFlag = 1; 246 bool isMicrophone = true; 247 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 248 ASSERT_NE(nullptr, screenCaptureCb_); 249 screenCapture_->SetMicrophoneEnabled(isMicrophone); 250 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 251 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 252 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 253 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 254 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 255 sleep(RECORDER_TIME); 256 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 257 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 258 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_007 after"); 259 } 260 261 /** 262 * @tc.name: screen_capture_exclude_content_008 263 * @tc.desc: screen capture exclude window and audio content test 264 * @tc.type: FUNC 265 * @tc.require: 266 */ 267 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_008, TestSize.Level2) 268 { 269 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_008 before"); 270 SetConfig(config_); 271 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 272 OpenFile("screen_capture_exclude_content_008"); 273 aFlag = 0; 274 vFlag = 1; 275 bool isMicrophone = true; 276 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 277 ASSERT_NE(nullptr, screenCaptureCb_); 278 screenCapture_->SetMicrophoneEnabled(isMicrophone); 279 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 280 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 281 vector<int> windowIds = {1, 3, 5}; 282 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 283 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 284 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 285 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 286 sleep(RECORDER_TIME); 287 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 288 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 289 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_008 after"); 290 } 291 292 /** 293 * @tc.name: screen_capture_exclude_content_009 294 * @tc.desc: screen capture exclude audio content 295 * @tc.type: FUNC 296 * @tc.require: 297 */ 298 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_009, TestSize.Level2) 299 { 300 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_009 after"); 301 SetConfig(config_); 302 AudioCaptureInfo micCapInfo = { 303 .audioSampleRate = 0, 304 .audioChannels = 0, 305 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 306 }; 307 config_.audioInfo.micCapInfo = micCapInfo; 308 AudioCaptureInfo innerCapInfo = { 309 .audioSampleRate = 0, 310 .audioChannels = 0, 311 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 312 }; 313 config_.audioInfo.innerCapInfo = innerCapInfo; 314 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 315 OpenFile("screen_capture_exclude_content_009"); 316 aFlag = 0; 317 vFlag = 1; 318 bool isMicrophone = true; 319 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 320 ASSERT_NE(nullptr, screenCaptureCb_); 321 screenCapture_->SetMicrophoneEnabled(isMicrophone); 322 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 323 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 324 vector<int> windowIds = {1, 3, 5}; 325 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 326 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 327 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 328 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 329 sleep(RECORDER_TIME); 330 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 331 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 332 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_009 after"); 333 } 334 335 /** 336 * @tc.name: screen_capture_exclude_content_010 337 * @tc.desc: screen capture exclude window content test 338 * @tc.type: FUNC 339 * @tc.require: 340 */ 341 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_010, TestSize.Level2) 342 { 343 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_010 before"); 344 SetConfig(config_); 345 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 346 OpenFile("screen_capture_exclude_content_010"); 347 aFlag = 0; 348 vFlag = 1; 349 bool isMicrophone = true; 350 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 351 ASSERT_NE(nullptr, screenCaptureCb_); 352 screenCapture_->SetMicrophoneEnabled(isMicrophone); 353 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 354 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 355 vector<int> windowIds1 = {1, 3, 5}; 356 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 357 vector<int> windowIds2 = {2, 4, 6}; 358 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 359 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 360 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 361 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 362 sleep(RECORDER_TIME); 363 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 364 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 365 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_010 after"); 366 } 367 368 /** 369 * @tc.name: screen_capture_exclude_content_011 370 * @tc.desc: screen capture exclude window content test 371 * @tc.type: FUNC 372 * @tc.require: 373 */ 374 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_011, TestSize.Level2) 375 { 376 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_011 before"); 377 SetConfig(config_); 378 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 379 OpenFile("screen_capture_exclude_content_011"); 380 aFlag = 0; 381 vFlag = 1; 382 bool isMicrophone = true; 383 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 384 ASSERT_NE(nullptr, screenCaptureCb_); 385 screenCapture_->SetMicrophoneEnabled(isMicrophone); 386 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 387 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 388 vector<int> windowIds1 = {1, 3, 5}; 389 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 390 vector<int> windowIds2 = {1, 4, 6}; 391 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 392 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 393 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 394 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 395 sleep(RECORDER_TIME); 396 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 397 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 398 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_011 after"); 399 } 400 401 /** 402 * @tc.name: screen_capture_exclude_content_012 403 * @tc.desc: screen capture exclude window content test 404 * @tc.type: FUNC 405 * @tc.require: 406 */ 407 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_012, TestSize.Level2) 408 { 409 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_012 before"); 410 SetConfig(config_); 411 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 412 OpenFile("screen_capture_exclude_content_012"); 413 aFlag = 0; 414 vFlag = 1; 415 bool isMicrophone = true; 416 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 417 ASSERT_NE(nullptr, screenCaptureCb_); 418 screenCapture_->SetMicrophoneEnabled(isMicrophone); 419 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 420 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 421 vector<int> windowIds1 = {1, 3, 5}; 422 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 423 vector<int> windowIds2 = {1, 3, 5}; 424 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 425 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 426 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 427 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 428 sleep(RECORDER_TIME); 429 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 430 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 431 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_012 after"); 432 } 433 434 /** 435 * @tc.name: screen_capture_exclude_content_save_file_01 436 * @tc.desc: screen capture exclude window content test with save file 437 * @tc.type: FUNC 438 * @tc.require: 439 */ 440 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_save_file_01, TestSize.Level2) 441 { 442 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_01 before"); 443 RecorderInfo recorderInfo; 444 SetRecorderInfo("screen_capture_exclude_content_save_file_01.mp4", recorderInfo); 445 SetConfigFile(config_, recorderInfo); 446 AudioCaptureInfo micCapInfo = { 447 .audioSampleRate = 16000, 448 .audioChannels = 2, 449 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 450 }; 451 config_.audioInfo.micCapInfo = micCapInfo; 452 AudioCaptureInfo innerCapInfo = { 453 .audioSampleRate = 16000, 454 .audioChannels = 2, 455 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 456 }; 457 config_.audioInfo.innerCapInfo = innerCapInfo; 458 459 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 460 vector<int> windowIds = {1, 3, 5}; 461 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 462 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); 463 sleep(RECORDER_TIME); 464 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); 465 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 466 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_01 after"); 467 } 468 469 /** 470 * @tc.name: screen_capture_exclude_content_save_file_02 471 * @tc.desc: screen capture exclude audio content test with save file 472 * @tc.type: FUNC 473 * @tc.require: 474 */ 475 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_save_file_02, TestSize.Level2) 476 { 477 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_02 before"); 478 RecorderInfo recorderInfo; 479 SetRecorderInfo("screen_capture_exclude_content_save_file_02.mp4", recorderInfo); 480 SetConfigFile(config_, recorderInfo); 481 AudioCaptureInfo micCapInfo = { 482 .audioSampleRate = 16000, 483 .audioChannels = 2, 484 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 485 }; 486 config_.audioInfo.micCapInfo = micCapInfo; 487 AudioCaptureInfo innerCapInfo = { 488 .audioSampleRate = 16000, 489 .audioChannels = 2, 490 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 491 }; 492 config_.audioInfo.innerCapInfo = innerCapInfo; 493 494 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 495 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 496 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); 497 sleep(RECORDER_TIME); 498 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); 499 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 500 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_02 after"); 501 } 502 503 /** 504 * @tc.name: screen_capture_exclude_content_save_file_03 505 * @tc.desc: screen capture exclude audio content test with save file 506 * @tc.type: FUNC 507 * @tc.require: 508 */ 509 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_save_file_03, TestSize.Level2) 510 { 511 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_03 before"); 512 RecorderInfo recorderInfo; 513 SetRecorderInfo("screen_capture_exclude_content_save_file_03.mp4", recorderInfo); 514 SetConfigFile(config_, recorderInfo); 515 AudioCaptureInfo micCapInfo = { 516 .audioSampleRate = 16000, 517 .audioChannels = 2, 518 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 519 }; 520 config_.audioInfo.micCapInfo = micCapInfo; 521 AudioCaptureInfo innerCapInfo = { 522 .audioSampleRate = 16000, 523 .audioChannels = 2, 524 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 525 }; 526 config_.audioInfo.innerCapInfo = innerCapInfo; 527 528 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 529 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 530 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); 531 sleep(RECORDER_TIME); 532 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); 533 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 534 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_03 after"); 535 } 536 537 /** 538 * @tc.name: screen_capture_exclude_content_save_file_04 539 * @tc.desc: screen capture exclude window and audio content test with save file 540 * @tc.type: FUNC 541 * @tc.require: 542 */ 543 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_save_file_04, TestSize.Level2) 544 { 545 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_04 before"); 546 RecorderInfo recorderInfo; 547 SetRecorderInfo("screen_capture_exclude_content_save_file_04.mp4", recorderInfo); 548 SetConfigFile(config_, recorderInfo); 549 AudioCaptureInfo micCapInfo = { 550 .audioSampleRate = 0, 551 .audioChannels = 0, 552 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 553 }; 554 config_.audioInfo.micCapInfo = micCapInfo; 555 AudioCaptureInfo innerCapInfo = { 556 .audioSampleRate = 16000, 557 .audioChannels = 2, 558 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 559 }; 560 config_.audioInfo.innerCapInfo = innerCapInfo; 561 562 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 563 vector<int> windowIds = {1, 3, 5}; 564 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 565 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 566 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 567 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); 568 sleep(RECORDER_TIME); 569 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); 570 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 571 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_04 after"); 572 } 573 574 /** 575 * @tc.name: screen_capture_exclude_content_save_file_05 576 * @tc.desc: screen capture exclude window and audio content test with save file and without innerCap audio 577 * @tc.type: FUNC 578 * @tc.require: 579 */ 580 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_save_file_05, TestSize.Level2) 581 { 582 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_05 before"); 583 RecorderInfo recorderInfo; 584 SetRecorderInfo("screen_capture_exclude_content_save_file_05.mp4", recorderInfo); 585 SetConfigFile(config_, recorderInfo); 586 AudioCaptureInfo micCapInfo = { 587 .audioSampleRate = 16000, 588 .audioChannels = 2, 589 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 590 }; 591 config_.audioInfo.micCapInfo = micCapInfo; 592 AudioCaptureInfo innerCapInfo = { 593 .audioSampleRate = 16000, 594 .audioChannels = 2, 595 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 596 }; 597 config_.audioInfo.innerCapInfo = innerCapInfo; 598 599 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 600 vector<int> windowIds = {1, 3, 5}; 601 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 602 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 603 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 604 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); 605 sleep(RECORDER_TIME); 606 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); 607 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 608 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_05 after"); 609 } 610 611 /** 612 * @tc.name: screen_capture_exclude_content_save_file_06 613 * @tc.desc: screen capture exclude window content test with save file 614 * @tc.type: FUNC 615 * @tc.require: 616 */ 617 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_save_file_06, TestSize.Level2) 618 { 619 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_06 before"); 620 RecorderInfo recorderInfo; 621 SetRecorderInfo("screen_capture_exclude_content_save_file_06.mp4", recorderInfo); 622 SetConfigFile(config_, recorderInfo); 623 AudioCaptureInfo micCapInfo = { 624 .audioSampleRate = 16000, 625 .audioChannels = 2, 626 .audioSource = AudioCaptureSourceType::SOURCE_DEFAULT 627 }; 628 config_.audioInfo.micCapInfo = micCapInfo; 629 AudioCaptureInfo innerCapInfo = { 630 .audioSampleRate = 16000, 631 .audioChannels = 2, 632 .audioSource = AudioCaptureSourceType::ALL_PLAYBACK 633 }; 634 config_.audioInfo.innerCapInfo = innerCapInfo; 635 636 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 637 vector<int> windowIds1 = {1, 3, 5}; 638 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 639 vector<int> windowIds2 = {2, 4, 6}; 640 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 641 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 642 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 643 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); 644 sleep(RECORDER_TIME); 645 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); 646 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 647 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_save_file_06 after"); 648 } 649 650 /** 651 * @tc.name: screen_capture_exclude_content_with_surface_01 652 * @tc.desc: do screencapture 653 * @tc.type: FUNC 654 * @tc.require: 655 */ 656 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_01, TestSize.Level2) 657 { 658 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_01 before"); 659 SetConfig(config_); 660 config_.videoInfo.videoCapInfo.videoFrameWidth = 720; 661 config_.videoInfo.videoCapInfo.videoFrameHeight = 1280; 662 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 663 bool isMicrophone = true; 664 screenCapture_->SetMicrophoneEnabled(isMicrophone); 665 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_01 CreateRecorder"); 666 std::shared_ptr<Recorder> recorder = nullptr; 667 recorder = RecorderFactory::CreateRecorder(); 668 int32_t videoSourceId = 0; 669 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 670 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 671 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 672 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1280)); 673 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 674 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 675 OpenFileFd("screen_capture_exclude_content_with_surface_01.mp4"); 676 ASSERT_TRUE(outputFd_ >= 0); 677 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 678 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 679 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 680 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 681 vector<int> windowIds = {1, 3, 5}; 682 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 683 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 684 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 685 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 686 EXPECT_EQ(MSERR_OK, recorder->Start()); 687 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_01 recorder Start"); 688 sleep(RECORDER_TIME); 689 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 690 EXPECT_EQ(MSERR_OK, recorder->Reset()); 691 EXPECT_EQ(MSERR_OK, recorder->Release()); 692 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 693 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 694 CloseFile(); 695 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_01 after"); 696 } 697 698 /** 699 * @tc.name: screen_capture_exclude_content_with_surface_02 700 * @tc.desc: do screencapture without audio and exclude window and audio content 701 * @tc.type: FUNC 702 * @tc.require: 703 */ 704 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_02, TestSize.Level2) 705 { 706 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_02 before"); 707 SetConfig(config_); 708 config_.audioInfo.micCapInfo.audioSampleRate = 0; 709 config_.audioInfo.micCapInfo.audioChannels = 0; 710 config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; 711 config_.audioInfo.innerCapInfo.audioSampleRate = 0; 712 config_.audioInfo.innerCapInfo.audioChannels = 0; 713 config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; 714 config_.videoInfo.videoCapInfo.videoFrameWidth = 720; 715 config_.videoInfo.videoCapInfo.videoFrameHeight = 1280; 716 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 717 bool isMicrophone = true; 718 screenCapture_->SetMicrophoneEnabled(isMicrophone); 719 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_02 CreateRecorder"); 720 std::shared_ptr<Recorder> recorder = nullptr; 721 recorder = RecorderFactory::CreateRecorder(); 722 int32_t videoSourceId = 0; 723 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 724 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 725 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 726 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1280)); 727 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 728 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 729 OpenFileFd("screen_capture_exclude_content_with_surface_02.mp4"); 730 ASSERT_TRUE(outputFd_ >= 0); 731 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 732 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 733 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 734 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 735 vector<int> windowIds = {1, 3, 5}; 736 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 737 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 738 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 739 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 740 EXPECT_EQ(MSERR_OK, recorder->Start()); 741 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_02 recorder Start"); 742 sleep(RECORDER_TIME); 743 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 744 EXPECT_EQ(MSERR_OK, recorder->Reset()); 745 EXPECT_EQ(MSERR_OK, recorder->Release()); 746 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 747 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 748 CloseFile(); 749 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_02 after"); 750 } 751 752 /** 753 * @tc.name: screen_capture_exclude_content_with_surface_03 754 * @tc.desc: do screencapture exclude windows 2 times 755 * @tc.type: FUNC 756 * @tc.require: 757 */ 758 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_03, TestSize.Level2) 759 { 760 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_03 before"); 761 SetConfig(config_); 762 config_.videoInfo.videoCapInfo.videoFrameWidth = 720; 763 config_.videoInfo.videoCapInfo.videoFrameHeight = 1280; 764 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 765 bool isMicrophone = true; 766 screenCapture_->SetMicrophoneEnabled(isMicrophone); 767 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_03 CreateRecorder"); 768 std::shared_ptr<Recorder> recorder = nullptr; 769 recorder = RecorderFactory::CreateRecorder(); 770 int32_t videoSourceId = 0; 771 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 772 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 773 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 774 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1280)); 775 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 776 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 777 OpenFileFd("screen_capture_exclude_content_with_surface_03.mp4"); 778 ASSERT_TRUE(outputFd_ >= 0); 779 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 780 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 781 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 782 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 783 vector<int> windowIds1 = {1, 3, 5}; 784 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 785 vector<int> windowIds2 = {2, 4, 6}; 786 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 787 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 788 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 789 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 790 EXPECT_EQ(MSERR_OK, recorder->Start()); 791 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_03 recorder Start"); 792 sleep(RECORDER_TIME); 793 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 794 EXPECT_EQ(MSERR_OK, recorder->Reset()); 795 EXPECT_EQ(MSERR_OK, recorder->Release()); 796 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 797 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 798 CloseFile(); 799 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_03 after"); 800 } 801 802 /** 803 * @tc.name: screen_capture_exclude_content_after_start_001 804 * @tc.desc: screen capture exclude window content test 805 * @tc.type: FUNC 806 * @tc.require: 807 */ 808 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_after_start_001, TestSize.Level2) 809 { 810 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_001 before"); 811 SetConfig(config_); 812 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 813 814 aFlag = 0; 815 vFlag = 0; 816 bool isMicrophone = true; 817 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 818 ASSERT_NE(nullptr, screenCaptureCb_); 819 screenCapture_->SetMicrophoneEnabled(isMicrophone); 820 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 821 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 822 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 823 vector<int> windowIds = {1, 3, 5}; 824 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 825 sleep(RECORDER_TIME); 826 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 827 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 828 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_001 after"); 829 } 830 831 /** 832 * @tc.name: screen_capture_exclude_content_after_start_002 833 * @tc.desc: screen capture exclude audio content test 834 * @tc.type: FUNC 835 * @tc.require: 836 */ 837 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_after_start_002, TestSize.Level2) 838 { 839 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_002 before"); 840 SetConfig(config_); 841 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 842 843 aFlag = 0; 844 vFlag = 0; 845 bool isMicrophone = true; 846 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 847 ASSERT_NE(nullptr, screenCaptureCb_); 848 screenCapture_->SetMicrophoneEnabled(isMicrophone); 849 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 850 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 851 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 852 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 853 sleep(RECORDER_TIME); 854 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 855 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 856 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_002 after"); 857 } 858 859 /** 860 * @tc.name: screen_capture_exclude_content_after_start_003 861 * @tc.desc: screen capture exclude audio content test 862 * @tc.type: FUNC 863 * @tc.require: 864 */ 865 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_after_start_003, TestSize.Level2) 866 { 867 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_003 before"); 868 SetConfig(config_); 869 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 870 871 aFlag = 0; 872 vFlag = 0; 873 bool isMicrophone = true; 874 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 875 ASSERT_NE(nullptr, screenCaptureCb_); 876 screenCapture_->SetMicrophoneEnabled(isMicrophone); 877 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 878 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 879 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 880 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 881 sleep(RECORDER_TIME); 882 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 883 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 884 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_003 after"); 885 } 886 887 /** 888 * @tc.name: screen_capture_exclude_content_after_start_004 889 * @tc.desc: screen capture exclude window content test 890 * @tc.type: FUNC 891 * @tc.require: 892 */ 893 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_after_start_004, TestSize.Level2) 894 { 895 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_004 before"); 896 SetConfig(config_); 897 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 898 899 aFlag = 0; 900 vFlag = 0; 901 bool isMicrophone = true; 902 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 903 ASSERT_NE(nullptr, screenCaptureCb_); 904 screenCapture_->SetMicrophoneEnabled(isMicrophone); 905 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 906 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 907 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 908 vector<int> windowIds = {1, 3, 5}; 909 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 910 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 911 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 912 sleep(RECORDER_TIME); 913 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 914 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 915 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_after_start_004 after"); 916 } 917 918 /** 919 * @tc.name: screen_capture_exclude_content_video_size_0001 920 * @tc.desc: screen capture with 160x160 921 * @tc.type: FUNC 922 * @tc.require: 923 */ 924 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_video_size_0001, TestSize.Level2) 925 { 926 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0001 before"); 927 SetConfig(config_); 928 config_.videoInfo.videoCapInfo.videoFrameWidth = 160; 929 config_.videoInfo.videoCapInfo.videoFrameHeight = 160; 930 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 931 932 std::string name = SCREEN_CAPTURE_ROOT_DIR + "screen_capture_exclude_content_video_size_0001.yuv"; 933 vFile = fopen(name.c_str(), "w+"); 934 if (vFile == nullptr) { 935 cout << "vFile video open failed, " << strerror(errno) << endl; 936 } 937 938 aFlag = 1; 939 vFlag = 1; 940 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 941 ASSERT_NE(nullptr, screenCaptureCb_); 942 bool isMicrophone = true; 943 screenCapture_->SetMicrophoneEnabled(isMicrophone); 944 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 945 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 946 vector<int> windowIds = {1, 3, 5}; 947 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 948 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 949 sleep(RECORDER_TIME); 950 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 951 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 952 CloseFile(); 953 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0001 after"); 954 } 955 956 /** 957 * @tc.name: screen_capture_exclude_content_video_size_0002 958 * @tc.desc: screen capture with 640x480 959 * @tc.type: FUNC 960 * @tc.require: 961 */ 962 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_video_size_0002, TestSize.Level2) 963 { 964 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0002 before"); 965 SetConfig(config_); 966 config_.videoInfo.videoCapInfo.videoFrameWidth = 640; 967 config_.videoInfo.videoCapInfo.videoFrameHeight = 480; 968 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 969 970 std::string name = SCREEN_CAPTURE_ROOT_DIR + "screen_capture_exclude_content_video_size_0002.yuv"; 971 vFile = fopen(name.c_str(), "w+"); 972 if (vFile == nullptr) { 973 cout << "vFile video open failed, " << strerror(errno) << endl; 974 } 975 976 aFlag = 1; 977 vFlag = 1; 978 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 979 ASSERT_NE(nullptr, screenCaptureCb_); 980 bool isMicrophone = true; 981 screenCapture_->SetMicrophoneEnabled(isMicrophone); 982 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 983 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 984 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 985 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 986 sleep(RECORDER_TIME); 987 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 988 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 989 CloseFile(); 990 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0002 after"); 991 } 992 993 /** 994 * @tc.name: screen_capture_exclude_content_video_size_0003 995 * @tc.desc: screen capture with 160x160 996 * @tc.type: FUNC 997 * @tc.require: 998 */ 999 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_video_size_0003, TestSize.Level2) 1000 { 1001 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0003 before"); 1002 SetConfig(config_); 1003 config_.videoInfo.videoCapInfo.videoFrameWidth = 160; 1004 config_.videoInfo.videoCapInfo.videoFrameHeight = 160; 1005 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1006 1007 std::string name = SCREEN_CAPTURE_ROOT_DIR + "screen_capture_exclude_content_video_size_0003.yuv"; 1008 vFile = fopen(name.c_str(), "w+"); 1009 if (vFile == nullptr) { 1010 cout << "vFile video open failed, " << strerror(errno) << endl; 1011 } 1012 1013 aFlag = 1; 1014 vFlag = 1; 1015 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1016 ASSERT_NE(nullptr, screenCaptureCb_); 1017 bool isMicrophone = true; 1018 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1019 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1020 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1021 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1022 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1023 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1024 sleep(RECORDER_TIME); 1025 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1026 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1027 CloseFile(); 1028 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0003 after"); 1029 } 1030 1031 /** 1032 * @tc.name: screen_capture_exclude_content_video_size_0004 1033 * @tc.desc: screen capture with 160x160 1034 * @tc.type: FUNC 1035 * @tc.require: 1036 */ 1037 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_video_size_0004, TestSize.Level2) 1038 { 1039 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0004 before"); 1040 SetConfig(config_); 1041 config_.videoInfo.videoCapInfo.videoFrameWidth = 160; 1042 config_.videoInfo.videoCapInfo.videoFrameHeight = 160; 1043 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1044 1045 std::string name = SCREEN_CAPTURE_ROOT_DIR + "screen_capture_exclude_content_video_size_0004.yuv"; 1046 vFile = fopen(name.c_str(), "w+"); 1047 if (vFile == nullptr) { 1048 cout << "vFile video open failed, " << strerror(errno) << endl; 1049 } 1050 1051 aFlag = 1; 1052 vFlag = 1; 1053 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1054 ASSERT_NE(nullptr, screenCaptureCb_); 1055 bool isMicrophone = true; 1056 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1057 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1058 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1059 vector<int> windowIds = {1, 3, 5}; 1060 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1061 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1062 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1063 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1064 sleep(RECORDER_TIME); 1065 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1066 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1067 CloseFile(); 1068 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0004 after"); 1069 } 1070 1071 /** 1072 * @tc.name: screen_capture_exclude_content_video_size_0005 1073 * @tc.desc: screen capture with 160x160 1074 * @tc.type: FUNC 1075 * @tc.require: 1076 */ 1077 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_video_size_0005, TestSize.Level2) 1078 { 1079 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0005 before"); 1080 SetConfig(config_); 1081 config_.videoInfo.videoCapInfo.videoFrameWidth = 160; 1082 config_.videoInfo.videoCapInfo.videoFrameHeight = 160; 1083 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1084 1085 std::string name = SCREEN_CAPTURE_ROOT_DIR + "screen_capture_exclude_content_video_size_0005.yuv"; 1086 vFile = fopen(name.c_str(), "w+"); 1087 if (vFile == nullptr) { 1088 cout << "vFile video open failed, " << strerror(errno) << endl; 1089 } 1090 1091 aFlag = 1; 1092 vFlag = 1; 1093 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1094 ASSERT_NE(nullptr, screenCaptureCb_); 1095 bool isMicrophone = true; 1096 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1097 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1098 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1099 vector<int> windowIds1 = {1, 3, 5}; 1100 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 1101 vector<int> windowIds2 = {2, 4, 6}; 1102 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 1103 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1104 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1105 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1106 sleep(RECORDER_TIME); 1107 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1108 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1109 CloseFile(); 1110 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_video_size_0005 after"); 1111 } 1112 1113 /** 1114 * @tc.name: screen_capture_exclude_content_from_display_001 1115 * @tc.desc: screen capture exclude content from display 1116 * @tc.type: FUNC 1117 * @tc.require: 1118 */ 1119 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_from_display_001, TestSize.Level0) 1120 { 1121 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_001 before"); 1122 SetConfig(config_); 1123 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1124 sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplaySync(); 1125 ASSERT_NE(display, nullptr); 1126 cout << "get displayinfo: " << endl; 1127 cout << "width: " << display->GetWidth() << "; height: " << display->GetHeight() << "; density: " << 1128 display->GetDpi() << "; refreshRate: " << display->GetRefreshRate() << endl; 1129 1130 config_.videoInfo.videoCapInfo.videoFrameWidth = display->GetWidth(); 1131 config_.videoInfo.videoCapInfo.videoFrameHeight = display->GetHeight(); 1132 1133 aFlag = 1; 1134 vFlag = 1; 1135 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1136 ASSERT_NE(nullptr, screenCaptureCb_); 1137 bool isMicrophone = true; 1138 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1139 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1140 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1141 vector<int> windowIds = {1, 3, 5}; 1142 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1143 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1144 sleep(RECORDER_TIME); 1145 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1146 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1147 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_001 after"); 1148 } 1149 1150 /** 1151 * @tc.name: screen_capture_exclude_content_from_display_002 1152 * @tc.desc: screen capture exclude content from display 1153 * @tc.type: FUNC 1154 * @tc.require: 1155 */ 1156 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_from_display_002, TestSize.Level0) 1157 { 1158 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_002 before"); 1159 SetConfig(config_); 1160 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1161 sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplaySync(); 1162 ASSERT_NE(display, nullptr); 1163 cout << "get displayinfo: " << endl; 1164 cout << "width: " << display->GetWidth() << "; height: " << display->GetHeight() << "; density: " << 1165 display->GetDpi() << "; refreshRate: " << display->GetRefreshRate() << endl; 1166 1167 config_.videoInfo.videoCapInfo.videoFrameWidth = display->GetWidth(); 1168 config_.videoInfo.videoCapInfo.videoFrameHeight = display->GetHeight(); 1169 1170 aFlag = 1; 1171 vFlag = 1; 1172 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1173 ASSERT_NE(nullptr, screenCaptureCb_); 1174 bool isMicrophone = true; 1175 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1176 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1177 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1178 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1179 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1180 sleep(RECORDER_TIME); 1181 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1182 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1183 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_002 after"); 1184 } 1185 1186 /** 1187 * @tc.name: screen_capture_exclude_content_from_display_003 1188 * @tc.desc: screen capture exclude content from display 1189 * @tc.type: FUNC 1190 * @tc.require: 1191 */ 1192 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_from_display_003, TestSize.Level0) 1193 { 1194 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_003 before"); 1195 SetConfig(config_); 1196 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1197 sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplaySync(); 1198 ASSERT_NE(display, nullptr); 1199 cout << "get displayinfo: " << endl; 1200 cout << "width: " << display->GetWidth() << "; height: " << display->GetHeight() << "; density: " << 1201 display->GetDpi() << "; refreshRate: " << display->GetRefreshRate() << endl; 1202 1203 config_.videoInfo.videoCapInfo.videoFrameWidth = display->GetWidth(); 1204 config_.videoInfo.videoCapInfo.videoFrameHeight = display->GetHeight(); 1205 1206 aFlag = 1; 1207 vFlag = 1; 1208 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1209 ASSERT_NE(nullptr, screenCaptureCb_); 1210 bool isMicrophone = true; 1211 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1212 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1213 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1214 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1215 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1216 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1217 sleep(RECORDER_TIME); 1218 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1219 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1220 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_003 after"); 1221 } 1222 1223 /** 1224 * @tc.name: screen_capture_exclude_content_from_display_004 1225 * @tc.desc: screen capture exclude content from display 1226 * @tc.type: FUNC 1227 * @tc.require: 1228 */ 1229 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_from_display_004, TestSize.Level0) 1230 { 1231 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_004 before"); 1232 SetConfig(config_); 1233 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1234 sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplaySync(); 1235 ASSERT_NE(display, nullptr); 1236 cout << "get displayinfo: " << endl; 1237 cout << "width: " << display->GetWidth() << "; height: " << display->GetHeight() << "; density: " << 1238 display->GetDpi() << "; refreshRate: " << display->GetRefreshRate() << endl; 1239 1240 config_.videoInfo.videoCapInfo.videoFrameWidth = display->GetWidth(); 1241 config_.videoInfo.videoCapInfo.videoFrameHeight = display->GetHeight(); 1242 1243 aFlag = 1; 1244 vFlag = 1; 1245 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1246 ASSERT_NE(nullptr, screenCaptureCb_); 1247 bool isMicrophone = true; 1248 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1249 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1250 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1251 vector<int> windowIds = {1, 3, 5}; 1252 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1253 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1254 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1255 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1256 sleep(RECORDER_TIME); 1257 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1258 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1259 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_004 after"); 1260 } 1261 1262 /** 1263 * @tc.name: screen_capture_exclude_content_from_display_005 1264 * @tc.desc: screen capture exclude content from display 1265 * @tc.type: FUNC 1266 * @tc.require: 1267 */ 1268 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_from_display_005, TestSize.Level0) 1269 { 1270 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_005 before"); 1271 SetConfig(config_); 1272 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1273 sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplaySync(); 1274 ASSERT_NE(display, nullptr); 1275 cout << "get displayinfo: " << endl; 1276 cout << "width: " << display->GetWidth() << "; height: " << display->GetHeight() << "; density: " << 1277 display->GetDpi() << "; refreshRate: " << display->GetRefreshRate() << endl; 1278 1279 config_.videoInfo.videoCapInfo.videoFrameWidth = display->GetWidth(); 1280 config_.videoInfo.videoCapInfo.videoFrameHeight = display->GetHeight(); 1281 1282 aFlag = 1; 1283 vFlag = 1; 1284 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_, aFile, vFile, aFlag, vFlag); 1285 ASSERT_NE(nullptr, screenCaptureCb_); 1286 bool isMicrophone = true; 1287 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1288 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_)); 1289 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1290 vector<int> windowIds1 = {1, 3, 5}; 1291 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 1292 vector<int> windowIds2 = {2, 4, 6}; 1293 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 1294 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1295 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1296 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1297 sleep(RECORDER_TIME); 1298 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1299 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1300 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_from_display_005 after"); 1301 } 1302 1303 /** 1304 * @tc.name: screen_capture_exclude_content_buffertest_001 1305 * @tc.desc: screen capture buffer test 1306 * @tc.type: FUNC 1307 * @tc.require: 1308 */ 1309 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_buffertest_001, TestSize.Level2) 1310 { 1311 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_001 before"); 1312 SetConfig(config_); 1313 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1314 1315 bool isMicrophone = true; 1316 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1317 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1318 vector<int> windowIds = {1, 3, 5}; 1319 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1320 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1321 int index = 200; 1322 int index_video_frame = 0; 1323 audioLoop_ = std::make_unique<std::thread>(&ScreenCaptureUnitTest::AudioLoopWithoutRelease, this); 1324 while (index) { 1325 int32_t fence = 0; 1326 int64_t timestamp = 0; 1327 OHOS::Rect damage; 1328 sptr<OHOS::SurfaceBuffer> surfacebuffer = screenCapture_->AcquireVideoBuffer(fence, timestamp, damage); 1329 if (surfacebuffer != nullptr) { 1330 int32_t length = surfacebuffer->GetSize(); 1331 cout << "index video:" << index_video_frame++ << "; AcquireVideoBuffer, videoBufferLen:" << 1332 surfacebuffer->GetSize() << ", timestamp:" << timestamp << ", size:"<< length << endl; 1333 } else { 1334 cout << "AcquireVideoBuffer failed" << endl; 1335 } 1336 index--; 1337 } 1338 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1339 if (audioLoop_ != nullptr && audioLoop_->joinable()) { 1340 audioLoop_->join(); 1341 audioLoop_.reset(); 1342 audioLoop_ = nullptr; 1343 } 1344 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1345 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_001 after"); 1346 } 1347 1348 /** 1349 * @tc.name: screen_capture_exclude_content_buffertest_002 1350 * @tc.desc: screen capture buffer test 1351 * @tc.type: FUNC 1352 * @tc.require: 1353 */ 1354 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_buffertest_002, TestSize.Level2) 1355 { 1356 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_002 before"); 1357 SetConfig(config_); 1358 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1359 1360 bool isMicrophone = true; 1361 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1362 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1363 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1364 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1365 int index = 200; 1366 int index_video_frame = 0; 1367 audioLoop_ = std::make_unique<std::thread>(&ScreenCaptureUnitTest::AudioLoopWithoutRelease, this); 1368 while (index) { 1369 int32_t fence = 0; 1370 int64_t timestamp = 0; 1371 OHOS::Rect damage; 1372 sptr<OHOS::SurfaceBuffer> surfacebuffer = screenCapture_->AcquireVideoBuffer(fence, timestamp, damage); 1373 if (surfacebuffer != nullptr) { 1374 int32_t length = surfacebuffer->GetSize(); 1375 cout << "index video:" << index_video_frame++ << "; AcquireVideoBuffer, videoBufferLen:" << 1376 surfacebuffer->GetSize() << ", timestamp:" << timestamp << ", size:"<< length << endl; 1377 } else { 1378 cout << "AcquireVideoBuffer failed" << endl; 1379 } 1380 index--; 1381 } 1382 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1383 if (audioLoop_ != nullptr && audioLoop_->joinable()) { 1384 audioLoop_->join(); 1385 audioLoop_.reset(); 1386 audioLoop_ = nullptr; 1387 } 1388 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1389 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_002 after"); 1390 } 1391 1392 /** 1393 * @tc.name: screen_capture_exclude_content_buffertest_003 1394 * @tc.desc: screen capture buffer test 1395 * @tc.type: FUNC 1396 * @tc.require: 1397 */ 1398 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_buffertest_003, TestSize.Level2) 1399 { 1400 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_003 before"); 1401 SetConfig(config_); 1402 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1403 1404 bool isMicrophone = true; 1405 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1406 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1407 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1408 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1409 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1410 int index = 200; 1411 int index_video_frame = 0; 1412 audioLoop_ = std::make_unique<std::thread>(&ScreenCaptureUnitTest::AudioLoopWithoutRelease, this); 1413 while (index) { 1414 int32_t fence = 0; 1415 int64_t timestamp = 0; 1416 OHOS::Rect damage; 1417 sptr<OHOS::SurfaceBuffer> surfacebuffer = screenCapture_->AcquireVideoBuffer(fence, timestamp, damage); 1418 if (surfacebuffer != nullptr) { 1419 int32_t length = surfacebuffer->GetSize(); 1420 cout << "index video:" << index_video_frame++ << "; AcquireVideoBuffer, videoBufferLen:" << 1421 surfacebuffer->GetSize() << ", timestamp:" << timestamp << ", size:"<< length << endl; 1422 } else { 1423 cout << "AcquireVideoBuffer failed" << endl; 1424 } 1425 index--; 1426 } 1427 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1428 if (audioLoop_ != nullptr && audioLoop_->joinable()) { 1429 audioLoop_->join(); 1430 audioLoop_.reset(); 1431 audioLoop_ = nullptr; 1432 } 1433 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1434 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_003 after"); 1435 } 1436 1437 /** 1438 * @tc.name: screen_capture_exclude_content_buffertest_004 1439 * @tc.desc: screen capture buffer test 1440 * @tc.type: FUNC 1441 * @tc.require: 1442 */ 1443 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_buffertest_004, TestSize.Level2) 1444 { 1445 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_004 before"); 1446 SetConfig(config_); 1447 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1448 1449 bool isMicrophone = true; 1450 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1451 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1452 vector<int> windowIds = {1, 3, 5}; 1453 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1454 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1455 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1456 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1457 int index = 200; 1458 int index_video_frame = 0; 1459 audioLoop_ = std::make_unique<std::thread>(&ScreenCaptureUnitTest::AudioLoopWithoutRelease, this); 1460 while (index) { 1461 int32_t fence = 0; 1462 int64_t timestamp = 0; 1463 OHOS::Rect damage; 1464 sptr<OHOS::SurfaceBuffer> surfacebuffer = screenCapture_->AcquireVideoBuffer(fence, timestamp, damage); 1465 if (surfacebuffer != nullptr) { 1466 int32_t length = surfacebuffer->GetSize(); 1467 cout << "index video:" << index_video_frame++ << "; AcquireVideoBuffer, videoBufferLen:" << 1468 surfacebuffer->GetSize() << ", timestamp:" << timestamp << ", size:"<< length << endl; 1469 } else { 1470 cout << "AcquireVideoBuffer failed" << endl; 1471 } 1472 index--; 1473 } 1474 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1475 if (audioLoop_ != nullptr && audioLoop_->joinable()) { 1476 audioLoop_->join(); 1477 audioLoop_.reset(); 1478 audioLoop_ = nullptr; 1479 } 1480 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1481 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_004 after"); 1482 } 1483 1484 /** 1485 * @tc.name: screen_capture_exclude_content_buffertest_005 1486 * @tc.desc: screen capture buffer test 1487 * @tc.type: FUNC 1488 * @tc.require: 1489 */ 1490 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_buffertest_005, TestSize.Level2) 1491 { 1492 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_005 before"); 1493 SetConfig(config_); 1494 config_.videoInfo.videoCapInfo.videoSource = VIDEO_SOURCE_SURFACE_RGBA; 1495 1496 bool isMicrophone = true; 1497 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1498 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1499 vector<int> windowIds1 = {1, 3, 5}; 1500 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds1[0], static_cast<int32_t>(windowIds1.size()))); 1501 vector<int> windowIds2 = {2, 4, 6}; 1502 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds2[0], static_cast<int32_t>(windowIds2.size()))); 1503 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1504 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1505 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCapture()); 1506 int index = 200; 1507 int index_video_frame = 0; 1508 audioLoop_ = std::make_unique<std::thread>(&ScreenCaptureUnitTest::AudioLoopWithoutRelease, this); 1509 while (index) { 1510 int32_t fence = 0; 1511 int64_t timestamp = 0; 1512 OHOS::Rect damage; 1513 sptr<OHOS::SurfaceBuffer> surfacebuffer = screenCapture_->AcquireVideoBuffer(fence, timestamp, damage); 1514 if (surfacebuffer != nullptr) { 1515 int32_t length = surfacebuffer->GetSize(); 1516 cout << "index video:" << index_video_frame++ << "; AcquireVideoBuffer, videoBufferLen:" << 1517 surfacebuffer->GetSize() << ", timestamp:" << timestamp << ", size:"<< length << endl; 1518 } else { 1519 cout << "AcquireVideoBuffer failed" << endl; 1520 } 1521 index--; 1522 } 1523 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1524 if (audioLoop_ != nullptr && audioLoop_->joinable()) { 1525 audioLoop_->join(); 1526 audioLoop_.reset(); 1527 audioLoop_ = nullptr; 1528 } 1529 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1530 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_buffertest_005 after"); 1531 } 1532 1533 /** 1534 * @tc.name: screen_capture_exclude_content_with_surface_cb_001 1535 * @tc.desc: do screencapture capture surface mode, capture screen, inner audio and mic audio, exclude some windows 1536 * @tc.type: FUNC 1537 * @tc.require: play something audio resource to get inner audio 1538 */ 1539 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_001, TestSize.Level2) 1540 { 1541 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_001 before"); 1542 SetConfig(config_); 1543 config_.audioInfo.innerCapInfo.audioSampleRate = 16000; 1544 config_.audioInfo.innerCapInfo.audioChannels = 2; 1545 config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; 1546 bool isMicrophone = true; 1547 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1548 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_001 CreateRecorder"); 1549 std::shared_ptr<Recorder> recorder = nullptr; 1550 recorder = RecorderFactory::CreateRecorder(); 1551 int32_t videoSourceId = 0; 1552 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1553 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1554 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1555 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1556 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1557 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1558 OpenFileFd("screen_capture_exclude_content_with_surface_cb_001.mp4"); 1559 ASSERT_TRUE(outputFd_ >= 0); 1560 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1561 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1562 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1563 1564 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1565 ASSERT_NE(nullptr, screenCaptureCb_); 1566 1567 std::string name = "screen_capture_exclude_content_with_surface_cb_001"; 1568 // track enalbed: inner: true, mic: true, video: true(surface mode) 1569 OpenFile(name, true, true, false); 1570 // check track aquire & release: inner: 1, mic: 1, video: 1 1571 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1572 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1573 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1574 // callback enabled: errorCallback: true, dataCallback: true, stateChangeCallback: true 1575 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1576 1577 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1578 vector<int> windowIds = {1, 3, 5}; 1579 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1580 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1581 EXPECT_EQ(MSERR_OK, recorder->Start()); 1582 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_001 recorder Start"); 1583 sleep(RECORDER_TIME); 1584 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1585 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1586 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1587 EXPECT_EQ(MSERR_OK, recorder->Release()); 1588 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1589 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1590 CloseFile(); 1591 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_001 after"); 1592 } 1593 1594 /** 1595 * @tc.name: screen_capture_exclude_content_with_surface_cb_002 1596 * @tc.desc: do screencapture capture surface mode, capture screen, inner audio and mic audio, exclude app audio 1597 * @tc.type: FUNC 1598 * @tc.require: play something audio resource to get inner audio 1599 */ 1600 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_002, TestSize.Level2) 1601 { 1602 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_002 before"); 1603 SetConfig(config_); 1604 config_.audioInfo.innerCapInfo.audioSampleRate = 16000; 1605 config_.audioInfo.innerCapInfo.audioChannels = 2; 1606 config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; 1607 bool isMicrophone = true; 1608 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1609 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_002 CreateRecorder"); 1610 std::shared_ptr<Recorder> recorder = nullptr; 1611 recorder = RecorderFactory::CreateRecorder(); 1612 int32_t videoSourceId = 0; 1613 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1614 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1615 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1616 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1617 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1618 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1619 OpenFileFd("screen_capture_exclude_content_with_surface_cb_002.mp4"); 1620 ASSERT_TRUE(outputFd_ >= 0); 1621 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1622 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1623 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1624 1625 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1626 ASSERT_NE(nullptr, screenCaptureCb_); 1627 1628 std::string name = "screen_capture_exclude_content_with_surface_cb_002"; 1629 // track enalbed: inner: true, mic: true, video: true(surface mode) 1630 OpenFile(name, true, true, false); 1631 // check track aquire & release: inner: 1, mic: 1, video: 1 1632 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1633 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1634 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1635 // callback enabled: errorCallback: true, dataCallback: true, stateChangeCallback: true 1636 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1637 1638 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1639 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1640 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1641 EXPECT_EQ(MSERR_OK, recorder->Start()); 1642 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_002 recorder Start"); 1643 sleep(RECORDER_TIME); 1644 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1645 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1646 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1647 EXPECT_EQ(MSERR_OK, recorder->Release()); 1648 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1649 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1650 CloseFile(); 1651 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_002 after"); 1652 } 1653 1654 /** 1655 * @tc.name: screen_capture_exclude_content_with_surface_cb_003 1656 * @tc.desc: surface mode, capture screen, inner audio and mic audio, exclude app and notice audio and sone windows 1657 * @tc.type: FUNC 1658 * @tc.require: play something audio resource to get inner audio 1659 */ 1660 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_003, TestSize.Level2) 1661 { 1662 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_003 before"); 1663 SetConfig(config_); 1664 config_.audioInfo.innerCapInfo.audioSampleRate = 16000; 1665 config_.audioInfo.innerCapInfo.audioChannels = 2; 1666 config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; 1667 bool isMicrophone = true; 1668 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1669 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_003 CreateRecorder"); 1670 std::shared_ptr<Recorder> recorder = nullptr; 1671 recorder = RecorderFactory::CreateRecorder(); 1672 int32_t videoSourceId = 0; 1673 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1674 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1675 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1676 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1677 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1678 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1679 OpenFileFd("screen_capture_exclude_content_with_surface_cb_003.mp4"); 1680 ASSERT_TRUE(outputFd_ >= 0); 1681 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1682 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1683 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1684 1685 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1686 ASSERT_NE(nullptr, screenCaptureCb_); 1687 1688 std::string name = "screen_capture_exclude_content_with_surface_cb_003"; 1689 // track enalbed: inner: true, mic: true, video: true(surface mode) 1690 OpenFile(name, true, true, false); 1691 // check track aquire & release: inner: 1, mic: 1, video: 1 1692 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1693 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1694 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1695 // callback enabled: errorCallback: true, dataCallback: true, stateChangeCallback: true 1696 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1697 1698 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1699 vector<int> windowIds = {1, 3, 5}; 1700 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1701 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1702 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1703 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1704 EXPECT_EQ(MSERR_OK, recorder->Start()); 1705 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_003 recorder Start"); 1706 sleep(RECORDER_TIME); 1707 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1708 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1709 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1710 EXPECT_EQ(MSERR_OK, recorder->Release()); 1711 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1712 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1713 CloseFile(); 1714 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_003 after"); 1715 } 1716 1717 /** 1718 * @tc.name: screen_capture_exclude_content_with_surface_cb_004 1719 * @tc.desc: surface mode, capture screen and inner audio, exclude app and notice audio and sone windows 1720 * @tc.type: FUNC 1721 * @tc.require: play something audio resource to get inner audio 1722 */ 1723 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_004, TestSize.Level2) 1724 { 1725 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_004 before"); 1726 SetConfig(config_); 1727 config_.audioInfo.micCapInfo.audioSampleRate = 0; 1728 config_.audioInfo.micCapInfo.audioChannels = 0; 1729 config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; 1730 config_.audioInfo.innerCapInfo.audioSampleRate = 16000; 1731 config_.audioInfo.innerCapInfo.audioChannels = 2; 1732 config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; 1733 screenCapture_->SetMicrophoneEnabled(true); 1734 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_004 CreateRecorder"); 1735 std::shared_ptr<Recorder> recorder = nullptr; 1736 recorder = RecorderFactory::CreateRecorder(); 1737 int32_t videoSourceId = 0; 1738 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1739 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1740 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1741 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1742 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1743 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1744 OpenFileFd("screen_capture_exclude_content_with_surface_cb_004.mp4"); 1745 ASSERT_TRUE(outputFd_ >= 0); 1746 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1747 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1748 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1749 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1750 ASSERT_NE(nullptr, screenCaptureCb_); 1751 std::string name = "screen_capture_exclude_content_with_surface_cb_004"; 1752 OpenFile(name, true, false, false); 1753 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1754 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1755 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1756 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1757 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1758 vector<int> windowIds = {1, 3, 5}; 1759 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1760 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1761 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1762 EXPECT_EQ(MSERR_OK, recorder->Start()); 1763 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_004 recorder Start"); 1764 sleep(RECORDER_TIME); 1765 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1766 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1767 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1768 EXPECT_EQ(MSERR_OK, recorder->Release()); 1769 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1770 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1771 CloseFile(); 1772 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_004 after"); 1773 } 1774 1775 /** 1776 * @tc.name: screen_capture_exclude_content_with_surface_cb_005 1777 * @tc.desc: surface mode, capture screen and mic audio, exclude app and notice audio and sone windows 1778 * @tc.type: FUNC 1779 * @tc.require: 1780 */ 1781 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_005, TestSize.Level2) 1782 { 1783 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_005 before"); 1784 SetConfig(config_); 1785 screenCapture_->SetMicrophoneEnabled(true); 1786 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_005 CreateRecorder"); 1787 std::shared_ptr<Recorder> recorder = RecorderFactory::CreateRecorder(); 1788 int32_t videoSourceId = 0; 1789 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1790 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1791 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1792 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1793 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1794 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1795 OpenFileFd("screen_capture_exclude_content_with_surface_cb_005.mp4"); 1796 ASSERT_TRUE(outputFd_ >= 0); 1797 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1798 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1799 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1800 1801 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1802 ASSERT_NE(nullptr, screenCaptureCb_); 1803 1804 std::string name = "screen_capture_exclude_content_with_surface_cb_005"; 1805 // track enalbed: inner: false, mic: true, video: true(surface mode) 1806 OpenFile(name, false, true, false); 1807 // check track aquire & release: inner: 1, mic: 1, video: 1 1808 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1809 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1810 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1811 // callback enabled: errorCallback: true, dataCallback: true, stateChangeCallback: true 1812 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1813 1814 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1815 vector<int> windowIds = {1, 3, 5}; 1816 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1817 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1818 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1819 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1820 EXPECT_EQ(MSERR_OK, recorder->Start()); 1821 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_005 recorder Start"); 1822 sleep(RECORDER_TIME); 1823 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1824 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1825 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1826 EXPECT_EQ(MSERR_OK, recorder->Release()); 1827 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1828 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1829 CloseFile(); 1830 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_005 after"); 1831 } 1832 1833 /** 1834 * @tc.name: screen_capture_exclude_content_with_surface_cb_006 1835 * @tc.desc: surface mode, capture screen only, exclude app and notice audio and sone windowss 1836 * @tc.type: FUNC 1837 * @tc.require: 1838 */ 1839 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_006, TestSize.Level2) 1840 { 1841 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_006 before"); 1842 SetConfig(config_); 1843 config_.audioInfo.micCapInfo.audioSampleRate = 0; 1844 config_.audioInfo.micCapInfo.audioChannels = 0; 1845 config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; 1846 screenCapture_->SetMicrophoneEnabled(true); 1847 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_006 CreateRecorder"); 1848 std::shared_ptr<Recorder> recorder = RecorderFactory::CreateRecorder(); 1849 int32_t videoSourceId = 0; 1850 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1851 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1852 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1853 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1854 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1855 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1856 OpenFileFd("screen_capture_exclude_content_with_surface_cb_006.mp4"); 1857 ASSERT_TRUE(outputFd_ >= 0); 1858 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1859 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1860 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1861 1862 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1863 ASSERT_NE(nullptr, screenCaptureCb_); 1864 1865 std::string name = "screen_capture_exclude_content_with_surface_cb_006"; 1866 // track enalbed: inner: false, mic: false, video: false 1867 OpenFile(name, false, false, false); 1868 // check track aquire & release: inner: 1, mic: 1, video: 1 1869 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1870 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1871 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1872 // callback enabled: errorCallback: true, dataCallback: true, stateChangeCallback: true 1873 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1874 1875 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1876 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1877 EXPECT_EQ(MSERR_OK, recorder->Start()); 1878 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_006 recorder Start"); 1879 sleep(RECORDER_TIME); 1880 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1881 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1882 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1883 EXPECT_EQ(MSERR_OK, recorder->Release()); 1884 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1885 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1886 CloseFile(); 1887 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_006 after"); 1888 } 1889 1890 /** 1891 * @tc.name: screen_capture_exclude_content_with_surface_cb_007 1892 * @tc.desc: surface mode, capture screen, inner audio and mic audio, exclude app and notice audio and sone windows 1893 * @tc.type: FUNC 1894 * @tc.require: play something audio resource to get inner audio 1895 */ 1896 HWTEST_F(ScreenCaptureUnitTest, screen_capture_exclude_content_with_surface_cb_007, TestSize.Level2) 1897 { 1898 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_007 before"); 1899 SetConfig(config_); 1900 config_.audioInfo.innerCapInfo.audioSampleRate = 16000; 1901 config_.audioInfo.innerCapInfo.audioChannels = 2; 1902 config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; 1903 bool isMicrophone = true; 1904 screenCapture_->SetMicrophoneEnabled(isMicrophone); 1905 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_007 CreateRecorder"); 1906 std::shared_ptr<Recorder> recorder = nullptr; 1907 recorder = RecorderFactory::CreateRecorder(); 1908 int32_t videoSourceId = 0; 1909 EXPECT_EQ(MSERR_OK, recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_RGBA, videoSourceId)); 1910 EXPECT_EQ(MSERR_OK, recorder->SetOutputFormat(OutputFormatType::FORMAT_MPEG_4)); 1911 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncoder(videoSourceId, VideoCodecFormat::H264)); 1912 EXPECT_EQ(MSERR_OK, recorder->SetVideoSize(videoSourceId, 720, 1080)); 1913 EXPECT_EQ(MSERR_OK, recorder->SetVideoFrameRate(videoSourceId, 30)); 1914 EXPECT_EQ(MSERR_OK, recorder->SetVideoEncodingBitRate(videoSourceId, 2000000)); 1915 OpenFileFd("screen_capture_exclude_content_with_surface_cb_007.mp4"); 1916 ASSERT_TRUE(outputFd_ >= 0); 1917 EXPECT_EQ(MSERR_OK, recorder->SetOutputFile(outputFd_)); 1918 EXPECT_EQ(MSERR_OK, recorder->Prepare()); 1919 sptr<OHOS::Surface> consumer = recorder->GetSurface(videoSourceId); 1920 1921 screenCaptureCb_ = std::make_shared<ScreenCaptureUnitTestCallback>(screenCapture_); 1922 ASSERT_NE(nullptr, screenCaptureCb_); 1923 1924 std::string name = "screen_capture_exclude_content_with_surface_cb_007"; 1925 // track enalbed: inner: true, mic: true, video: true(surface mode) 1926 OpenFile(name, true, true, false); 1927 // check track aquire & release: inner: 1, mic: 1, video: 1 1928 screenCaptureCb_->InitCaptureTrackInfo(innerAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_INNER); 1929 screenCaptureCb_->InitCaptureTrackInfo(micAudioFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_AUDIO_MIC); 1930 screenCaptureCb_->InitCaptureTrackInfo(videoFile_, 1, SCREEN_CAPTURE_BUFFERTYPE_VIDEO); 1931 // callback enabled: errorCallback: true, dataCallback: true, stateChangeCallback: true 1932 EXPECT_EQ(MSERR_OK, screenCapture_->SetScreenCaptureCallback(screenCaptureCb_, true, true, true)); 1933 1934 EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); 1935 vector<int> windowIds = {1, 3, 5}; 1936 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeWindowContent(&windowIds[0], static_cast<int32_t>(windowIds.size()))); 1937 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_NOTIFICATION_AUDIO)); 1938 EXPECT_EQ(MSERR_OK, screenCapture_->ExcludeAudioContent(SCREEN_CAPTURE_CURRENT_APP_AUDIO)); 1939 EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenCaptureWithSurface(consumer)); 1940 EXPECT_EQ(MSERR_OK, recorder->Start()); 1941 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_007 recorder Start"); 1942 sleep(RECORDER_TIME); 1943 EXPECT_EQ(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STARTED, screenCaptureCb_->GetScreenCaptureState()); 1944 EXPECT_EQ(MSERR_OK, recorder->Stop(true)); 1945 EXPECT_EQ(MSERR_OK, recorder->Reset()); 1946 EXPECT_EQ(MSERR_OK, recorder->Release()); 1947 EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenCapture()); 1948 EXPECT_EQ(MSERR_OK, screenCapture_->Release()); 1949 CloseFile(); 1950 MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_exclude_content_with_surface_cb_007 after"); 1951 } 1952 } // namespace Media 1953 } // namespace OHOS