Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: webrtc/modules/video_capture/test/video_capture_unittest.cc

Issue 1738863002: Replace scoped_ptr with unique_ptr in webrtc/modules/video_*/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@up4
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 #include <map> 13 #include <map>
14 #include <memory>
14 #include <sstream> 15 #include <sstream>
15 16
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/base/scoped_ref_ptr.h" 18 #include "webrtc/base/scoped_ref_ptr.h"
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
20 #include "webrtc/modules/utility/include/process_thread.h" 20 #include "webrtc/modules/utility/include/process_thread.h"
21 #include "webrtc/modules/video_capture/video_capture.h" 21 #include "webrtc/modules/video_capture/video_capture.h"
22 #include "webrtc/modules/video_capture/video_capture_factory.h" 22 #include "webrtc/modules/video_capture/video_capture_factory.h"
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
24 #include "webrtc/system_wrappers/include/sleep.h" 24 #include "webrtc/system_wrappers/include/sleep.h"
25 #include "webrtc/system_wrappers/include/tick_util.h" 25 #include "webrtc/system_wrappers/include/tick_util.h"
26 #include "webrtc/video_frame.h" 26 #include "webrtc/video_frame.h"
27 27
28 using rtc::scoped_ptr;
29 using webrtc::CriticalSectionWrapper; 28 using webrtc::CriticalSectionWrapper;
30 using webrtc::CriticalSectionScoped; 29 using webrtc::CriticalSectionScoped;
31 using webrtc::SleepMs; 30 using webrtc::SleepMs;
32 using webrtc::TickTime; 31 using webrtc::TickTime;
33 using webrtc::VideoCaptureAlarm; 32 using webrtc::VideoCaptureAlarm;
34 using webrtc::VideoCaptureCapability; 33 using webrtc::VideoCaptureCapability;
35 using webrtc::VideoCaptureDataCallback; 34 using webrtc::VideoCaptureDataCallback;
36 using webrtc::VideoCaptureFactory; 35 using webrtc::VideoCaptureFactory;
37 using webrtc::VideoCaptureFeedBack; 36 using webrtc::VideoCaptureFeedBack;
38 using webrtc::VideoCaptureModule; 37 using webrtc::VideoCaptureModule;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 CriticalSectionScoped cs(capture_cs_.get()); 175 CriticalSectionScoped cs(capture_cs_.get());
177 return CompareFrames(last_frame_, frame); 176 return CompareFrames(last_frame_, frame);
178 } 177 }
179 178
180 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { 179 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) {
181 CriticalSectionScoped cs(capture_cs_.get()); 180 CriticalSectionScoped cs(capture_cs_.get());
182 rotate_frame_ = rotation; 181 rotate_frame_ = rotation;
183 } 182 }
184 183
185 private: 184 private:
186 scoped_ptr<CriticalSectionWrapper> capture_cs_; 185 std::unique_ptr<CriticalSectionWrapper> capture_cs_;
187 VideoCaptureCapability capability_; 186 VideoCaptureCapability capability_;
188 int capture_delay_; 187 int capture_delay_;
189 int64_t last_render_time_ms_; 188 int64_t last_render_time_ms_;
190 int incoming_frames_; 189 int incoming_frames_;
191 int timing_warnings_; 190 int timing_warnings_;
192 webrtc::VideoFrame last_frame_; 191 webrtc::VideoFrame last_frame_;
193 webrtc::VideoRotation rotate_frame_; 192 webrtc::VideoRotation rotate_frame_;
194 }; 193 };
195 194
196 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack { 195 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack {
(...skipping 19 matching lines...) Expand all
216 CriticalSectionScoped cs(capture_cs_.get()); 215 CriticalSectionScoped cs(capture_cs_.get());
217 return frame_rate_; 216 return frame_rate_;
218 217
219 } 218 }
220 VideoCaptureAlarm alarm() { 219 VideoCaptureAlarm alarm() {
221 CriticalSectionScoped cs(capture_cs_.get()); 220 CriticalSectionScoped cs(capture_cs_.get());
222 return alarm_; 221 return alarm_;
223 } 222 }
224 223
225 private: 224 private:
226 scoped_ptr<CriticalSectionWrapper> capture_cs_; 225 std::unique_ptr<CriticalSectionWrapper> capture_cs_;
227 unsigned int frame_rate_; 226 unsigned int frame_rate_;
228 VideoCaptureAlarm alarm_; 227 VideoCaptureAlarm alarm_;
229 }; 228 };
230 229
231 class VideoCaptureTest : public testing::Test { 230 class VideoCaptureTest : public testing::Test {
232 public: 231 public:
233 VideoCaptureTest() : number_of_devices_(0) {} 232 VideoCaptureTest() : number_of_devices_(0) {}
234 233
235 void SetUp() { 234 void SetUp() {
236 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0)); 235 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0));
(...skipping 26 matching lines...) Expand all
263 VideoCaptureCapability capability) { 262 VideoCaptureCapability capability) {
264 ASSERT_EQ(0, capture_module->StartCapture(capability)); 263 ASSERT_EQ(0, capture_module->StartCapture(capability));
265 EXPECT_TRUE(capture_module->CaptureStarted()); 264 EXPECT_TRUE(capture_module->CaptureStarted());
266 265
267 VideoCaptureCapability resulting_capability; 266 VideoCaptureCapability resulting_capability;
268 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability)); 267 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability));
269 EXPECT_EQ(capability.width, resulting_capability.width); 268 EXPECT_EQ(capability.width, resulting_capability.width);
270 EXPECT_EQ(capability.height, resulting_capability.height); 269 EXPECT_EQ(capability.height, resulting_capability.height);
271 } 270 }
272 271
273 scoped_ptr<VideoCaptureModule::DeviceInfo> device_info_; 272 std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info_;
274 unsigned int number_of_devices_; 273 unsigned int number_of_devices_;
275 }; 274 };
276 275
277 #ifdef WEBRTC_MAC 276 #ifdef WEBRTC_MAC
278 // Currently fails on Mac 64-bit, see 277 // Currently fails on Mac 64-bit, see
279 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406 278 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406
280 #define MAYBE_CreateDelete DISABLED_CreateDelete 279 #define MAYBE_CreateDelete DISABLED_CreateDelete
281 #else 280 #else
282 #define MAYBE_CreateDelete CreateDelete 281 #define MAYBE_CreateDelete CreateDelete
283 #endif 282 #endif
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 EXPECT_EQ(0, module2->StopCapture()); 432 EXPECT_EQ(0, module2->StopCapture());
434 EXPECT_EQ(0, module1->StopCapture()); 433 EXPECT_EQ(0, module1->StopCapture());
435 } 434 }
436 435
437 // Test class for testing external capture and capture feedback information 436 // Test class for testing external capture and capture feedback information
438 // such as frame rate and picture alarm. 437 // such as frame rate and picture alarm.
439 class VideoCaptureExternalTest : public testing::Test { 438 class VideoCaptureExternalTest : public testing::Test {
440 public: 439 public:
441 void SetUp() { 440 void SetUp() {
442 capture_module_ = VideoCaptureFactory::Create(0, capture_input_interface_); 441 capture_module_ = VideoCaptureFactory::Create(0, capture_input_interface_);
443 process_module_ = webrtc::ProcessThread::Create("ProcessThread"); 442 process_module_ =
443 rtc::ScopedToUnique(webrtc::ProcessThread::Create("ProcessThread"));
444 process_module_->Start(); 444 process_module_->Start();
445 process_module_->RegisterModule(capture_module_); 445 process_module_->RegisterModule(capture_module_);
446 446
447 VideoCaptureCapability capability; 447 VideoCaptureCapability capability;
448 capability.width = kTestWidth; 448 capability.width = kTestWidth;
449 capability.height = kTestHeight; 449 capability.height = kTestHeight;
450 capability.rawType = webrtc::kVideoYV12; 450 capability.rawType = webrtc::kVideoYV12;
451 capability.maxFPS = kTestFramerate; 451 capability.maxFPS = kTestFramerate;
452 capture_callback_.SetExpectedCapability(capability); 452 capture_callback_.SetExpectedCapability(capability);
453 453
(...skipping 11 matching lines...) Expand all
465 capture_module_->EnableFrameRateCallback(true); 465 capture_module_->EnableFrameRateCallback(true);
466 capture_module_->EnableNoPictureAlarm(true); 466 capture_module_->EnableNoPictureAlarm(true);
467 } 467 }
468 468
469 void TearDown() { 469 void TearDown() {
470 process_module_->Stop(); 470 process_module_->Stop();
471 } 471 }
472 472
473 webrtc::VideoCaptureExternal* capture_input_interface_; 473 webrtc::VideoCaptureExternal* capture_input_interface_;
474 rtc::scoped_refptr<VideoCaptureModule> capture_module_; 474 rtc::scoped_refptr<VideoCaptureModule> capture_module_;
475 rtc::scoped_ptr<webrtc::ProcessThread> process_module_; 475 std::unique_ptr<webrtc::ProcessThread> process_module_;
476 webrtc::VideoFrame test_frame_; 476 webrtc::VideoFrame test_frame_;
477 TestVideoCaptureCallback capture_callback_; 477 TestVideoCaptureCallback capture_callback_;
478 TestVideoCaptureFeedBack capture_feedback_; 478 TestVideoCaptureFeedBack capture_feedback_;
479 }; 479 };
480 480
481 // Test input of external video frames. 481 // Test input of external video frames.
482 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { 482 TEST_F(VideoCaptureExternalTest, TestExternalCapture) {
483 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 483 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
484 test_frame_.width(), 484 test_frame_.width(),
485 test_frame_.height()); 485 test_frame_.height());
486 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 486 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
487 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 487 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
488 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 488 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
489 length, capture_callback_.capability(), 0)); 489 length, capture_callback_.capability(), 0));
490 EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_)); 490 EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_));
491 } 491 }
492 492
493 // Test frame rate and no picture alarm. 493 // Test frame rate and no picture alarm.
494 // Flaky on Win32, see webrtc:3270. 494 // Flaky on Win32, see webrtc:3270.
495 #if defined(WEBRTC_WIN) 495 #if defined(WEBRTC_WIN)
496 #define MAYBE_FrameRate DISABLED_FrameRate 496 #define MAYBE_FrameRate DISABLED_FrameRate
497 #else 497 #else
498 #define MAYBE_FrameRate FrameRate 498 #define MAYBE_FrameRate FrameRate
499 #endif 499 #endif
500 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { 500 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) {
501 int64_t testTime = 3; 501 int64_t testTime = 3;
502 TickTime startTime = TickTime::Now(); 502 TickTime startTime = TickTime::Now();
503 503
504 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { 504 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) {
505 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 505 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
506 test_frame_.width(), 506 test_frame_.width(),
507 test_frame_.height()); 507 test_frame_.height());
508 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 508 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
509 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 509 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
510 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 510 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
511 length, capture_callback_.capability(), 0)); 511 length, capture_callback_.capability(), 0));
512 SleepMs(100); 512 SleepMs(100);
513 } 513 }
514 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && 514 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 &&
515 capture_feedback_.frame_rate() <= 10); 515 capture_feedback_.frame_rate() <= 10);
516 SleepMs(500); 516 SleepMs(500);
517 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); 517 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm());
518 518
519 startTime = TickTime::Now(); 519 startTime = TickTime::Now();
520 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { 520 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) {
521 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 521 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
522 test_frame_.width(), 522 test_frame_.width(),
523 test_frame_.height()); 523 test_frame_.height());
524 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 524 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
525 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 525 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
526 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 526 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
527 length, capture_callback_.capability(), 0)); 527 length, capture_callback_.capability(), 0));
528 SleepMs(1000 / 30); 528 SleepMs(1000 / 30);
529 } 529 }
530 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); 530 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm());
531 // Frame rate might be less than 33 since we have paused providing 531 // Frame rate might be less than 33 since we have paused providing
532 // frames for a while. 532 // frames for a while.
533 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 && 533 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 &&
534 capture_feedback_.frame_rate() <= 33); 534 capture_feedback_.frame_rate() <= 33);
535 } 535 }
536 536
537 TEST_F(VideoCaptureExternalTest, Rotation) { 537 TEST_F(VideoCaptureExternalTest, Rotation) {
538 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); 538 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0));
539 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 539 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
540 test_frame_.width(), 540 test_frame_.width(),
541 test_frame_.height()); 541 test_frame_.height());
542 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 542 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
543 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 543 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
544 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 544 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
545 length, capture_callback_.capability(), 0)); 545 length, capture_callback_.capability(), 0));
546 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); 546 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90));
547 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); 547 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90);
548 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 548 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
549 length, capture_callback_.capability(), 0)); 549 length, capture_callback_.capability(), 0));
550 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); 550 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180));
551 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); 551 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180);
552 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 552 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
553 length, capture_callback_.capability(), 0)); 553 length, capture_callback_.capability(), 0));
554 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); 554 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270));
555 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); 555 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270);
556 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 556 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
557 length, capture_callback_.capability(), 0)); 557 length, capture_callback_.capability(), 0));
558 } 558 }
OLDNEW
« no previous file with comments | « webrtc/modules/video_capture/linux/video_capture_linux.h ('k') | webrtc/modules/video_processing/frame_preprocessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698