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

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: Created 4 years, 10 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; 28 using std::unique_ptr;
stefan-webrtc 2016/02/25 14:57:33 I guess you can remove this if you're anyway writi
kwiberg-webrtc 2016/02/27 13:14:47 Done.
29 using webrtc::CriticalSectionWrapper; 29 using webrtc::CriticalSectionWrapper;
30 using webrtc::CriticalSectionScoped; 30 using webrtc::CriticalSectionScoped;
31 using webrtc::SleepMs; 31 using webrtc::SleepMs;
32 using webrtc::TickTime; 32 using webrtc::TickTime;
33 using webrtc::VideoCaptureAlarm; 33 using webrtc::VideoCaptureAlarm;
34 using webrtc::VideoCaptureCapability; 34 using webrtc::VideoCaptureCapability;
35 using webrtc::VideoCaptureDataCallback; 35 using webrtc::VideoCaptureDataCallback;
36 using webrtc::VideoCaptureFactory; 36 using webrtc::VideoCaptureFactory;
37 using webrtc::VideoCaptureFeedBack; 37 using webrtc::VideoCaptureFeedBack;
38 using webrtc::VideoCaptureModule; 38 using webrtc::VideoCaptureModule;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 CriticalSectionScoped cs(capture_cs_.get()); 176 CriticalSectionScoped cs(capture_cs_.get());
177 return CompareFrames(last_frame_, frame); 177 return CompareFrames(last_frame_, frame);
178 } 178 }
179 179
180 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { 180 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) {
181 CriticalSectionScoped cs(capture_cs_.get()); 181 CriticalSectionScoped cs(capture_cs_.get());
182 rotate_frame_ = rotation; 182 rotate_frame_ = rotation;
183 } 183 }
184 184
185 private: 185 private:
186 scoped_ptr<CriticalSectionWrapper> capture_cs_; 186 std::unique_ptr<CriticalSectionWrapper> capture_cs_;
187 VideoCaptureCapability capability_; 187 VideoCaptureCapability capability_;
188 int capture_delay_; 188 int capture_delay_;
189 int64_t last_render_time_ms_; 189 int64_t last_render_time_ms_;
190 int incoming_frames_; 190 int incoming_frames_;
191 int timing_warnings_; 191 int timing_warnings_;
192 webrtc::VideoFrame last_frame_; 192 webrtc::VideoFrame last_frame_;
193 webrtc::VideoRotation rotate_frame_; 193 webrtc::VideoRotation rotate_frame_;
194 }; 194 };
195 195
196 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack { 196 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack {
(...skipping 19 matching lines...) Expand all
216 CriticalSectionScoped cs(capture_cs_.get()); 216 CriticalSectionScoped cs(capture_cs_.get());
217 return frame_rate_; 217 return frame_rate_;
218 218
219 } 219 }
220 VideoCaptureAlarm alarm() { 220 VideoCaptureAlarm alarm() {
221 CriticalSectionScoped cs(capture_cs_.get()); 221 CriticalSectionScoped cs(capture_cs_.get());
222 return alarm_; 222 return alarm_;
223 } 223 }
224 224
225 private: 225 private:
226 scoped_ptr<CriticalSectionWrapper> capture_cs_; 226 std::unique_ptr<CriticalSectionWrapper> capture_cs_;
227 unsigned int frame_rate_; 227 unsigned int frame_rate_;
228 VideoCaptureAlarm alarm_; 228 VideoCaptureAlarm alarm_;
229 }; 229 };
230 230
231 class VideoCaptureTest : public testing::Test { 231 class VideoCaptureTest : public testing::Test {
232 public: 232 public:
233 VideoCaptureTest() : number_of_devices_(0) {} 233 VideoCaptureTest() : number_of_devices_(0) {}
234 234
235 void SetUp() { 235 void SetUp() {
236 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0)); 236 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0));
(...skipping 26 matching lines...) Expand all
263 VideoCaptureCapability capability) { 263 VideoCaptureCapability capability) {
264 ASSERT_EQ(0, capture_module->StartCapture(capability)); 264 ASSERT_EQ(0, capture_module->StartCapture(capability));
265 EXPECT_TRUE(capture_module->CaptureStarted()); 265 EXPECT_TRUE(capture_module->CaptureStarted());
266 266
267 VideoCaptureCapability resulting_capability; 267 VideoCaptureCapability resulting_capability;
268 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability)); 268 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability));
269 EXPECT_EQ(capability.width, resulting_capability.width); 269 EXPECT_EQ(capability.width, resulting_capability.width);
270 EXPECT_EQ(capability.height, resulting_capability.height); 270 EXPECT_EQ(capability.height, resulting_capability.height);
271 } 271 }
272 272
273 scoped_ptr<VideoCaptureModule::DeviceInfo> device_info_; 273 std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info_;
274 unsigned int number_of_devices_; 274 unsigned int number_of_devices_;
275 }; 275 };
276 276
277 #ifdef WEBRTC_MAC 277 #ifdef WEBRTC_MAC
278 // Currently fails on Mac 64-bit, see 278 // Currently fails on Mac 64-bit, see
279 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406 279 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406
280 #define MAYBE_CreateDelete DISABLED_CreateDelete 280 #define MAYBE_CreateDelete DISABLED_CreateDelete
281 #else 281 #else
282 #define MAYBE_CreateDelete CreateDelete 282 #define MAYBE_CreateDelete CreateDelete
283 #endif 283 #endif
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 EXPECT_EQ(0, module2->StopCapture()); 433 EXPECT_EQ(0, module2->StopCapture());
434 EXPECT_EQ(0, module1->StopCapture()); 434 EXPECT_EQ(0, module1->StopCapture());
435 } 435 }
436 436
437 // Test class for testing external capture and capture feedback information 437 // Test class for testing external capture and capture feedback information
438 // such as frame rate and picture alarm. 438 // such as frame rate and picture alarm.
439 class VideoCaptureExternalTest : public testing::Test { 439 class VideoCaptureExternalTest : public testing::Test {
440 public: 440 public:
441 void SetUp() { 441 void SetUp() {
442 capture_module_ = VideoCaptureFactory::Create(0, capture_input_interface_); 442 capture_module_ = VideoCaptureFactory::Create(0, capture_input_interface_);
443 process_module_ = webrtc::ProcessThread::Create("ProcessThread"); 443 process_module_ =
444 rtc::ScopedToUnique(webrtc::ProcessThread::Create("ProcessThread"));
444 process_module_->Start(); 445 process_module_->Start();
445 process_module_->RegisterModule(capture_module_); 446 process_module_->RegisterModule(capture_module_);
446 447
447 VideoCaptureCapability capability; 448 VideoCaptureCapability capability;
448 capability.width = kTestWidth; 449 capability.width = kTestWidth;
449 capability.height = kTestHeight; 450 capability.height = kTestHeight;
450 capability.rawType = webrtc::kVideoYV12; 451 capability.rawType = webrtc::kVideoYV12;
451 capability.maxFPS = kTestFramerate; 452 capability.maxFPS = kTestFramerate;
452 capture_callback_.SetExpectedCapability(capability); 453 capture_callback_.SetExpectedCapability(capability);
453 454
(...skipping 11 matching lines...) Expand all
465 capture_module_->EnableFrameRateCallback(true); 466 capture_module_->EnableFrameRateCallback(true);
466 capture_module_->EnableNoPictureAlarm(true); 467 capture_module_->EnableNoPictureAlarm(true);
467 } 468 }
468 469
469 void TearDown() { 470 void TearDown() {
470 process_module_->Stop(); 471 process_module_->Stop();
471 } 472 }
472 473
473 webrtc::VideoCaptureExternal* capture_input_interface_; 474 webrtc::VideoCaptureExternal* capture_input_interface_;
474 rtc::scoped_refptr<VideoCaptureModule> capture_module_; 475 rtc::scoped_refptr<VideoCaptureModule> capture_module_;
475 rtc::scoped_ptr<webrtc::ProcessThread> process_module_; 476 std::unique_ptr<webrtc::ProcessThread> process_module_;
476 webrtc::VideoFrame test_frame_; 477 webrtc::VideoFrame test_frame_;
477 TestVideoCaptureCallback capture_callback_; 478 TestVideoCaptureCallback capture_callback_;
478 TestVideoCaptureFeedBack capture_feedback_; 479 TestVideoCaptureFeedBack capture_feedback_;
479 }; 480 };
480 481
481 // Test input of external video frames. 482 // Test input of external video frames.
482 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { 483 TEST_F(VideoCaptureExternalTest, TestExternalCapture) {
483 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 484 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
484 test_frame_.width(), 485 test_frame_.width(),
485 test_frame_.height()); 486 test_frame_.height());
486 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 487 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
487 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 488 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
488 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 489 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
489 length, capture_callback_.capability(), 0)); 490 length, capture_callback_.capability(), 0));
490 EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_)); 491 EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_));
491 } 492 }
492 493
493 // Test frame rate and no picture alarm. 494 // Test frame rate and no picture alarm.
494 // Flaky on Win32, see webrtc:3270. 495 // Flaky on Win32, see webrtc:3270.
495 #if defined(WEBRTC_WIN) 496 #if defined(WEBRTC_WIN)
496 #define MAYBE_FrameRate DISABLED_FrameRate 497 #define MAYBE_FrameRate DISABLED_FrameRate
497 #else 498 #else
498 #define MAYBE_FrameRate FrameRate 499 #define MAYBE_FrameRate FrameRate
499 #endif 500 #endif
500 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { 501 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) {
501 int64_t testTime = 3; 502 int64_t testTime = 3;
502 TickTime startTime = TickTime::Now(); 503 TickTime startTime = TickTime::Now();
503 504
504 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { 505 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) {
505 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 506 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
506 test_frame_.width(), 507 test_frame_.width(),
507 test_frame_.height()); 508 test_frame_.height());
508 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 509 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
509 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 510 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
510 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 511 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
511 length, capture_callback_.capability(), 0)); 512 length, capture_callback_.capability(), 0));
512 SleepMs(100); 513 SleepMs(100);
513 } 514 }
514 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && 515 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 &&
515 capture_feedback_.frame_rate() <= 10); 516 capture_feedback_.frame_rate() <= 10);
516 SleepMs(500); 517 SleepMs(500);
517 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); 518 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm());
518 519
519 startTime = TickTime::Now(); 520 startTime = TickTime::Now();
520 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) { 521 while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) {
521 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 522 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
522 test_frame_.width(), 523 test_frame_.width(),
523 test_frame_.height()); 524 test_frame_.height());
524 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 525 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
525 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 526 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
526 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 527 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
527 length, capture_callback_.capability(), 0)); 528 length, capture_callback_.capability(), 0));
528 SleepMs(1000 / 30); 529 SleepMs(1000 / 30);
529 } 530 }
530 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); 531 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm());
531 // Frame rate might be less than 33 since we have paused providing 532 // Frame rate might be less than 33 since we have paused providing
532 // frames for a while. 533 // frames for a while.
533 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 && 534 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 &&
534 capture_feedback_.frame_rate() <= 33); 535 capture_feedback_.frame_rate() <= 33);
535 } 536 }
536 537
537 TEST_F(VideoCaptureExternalTest, Rotation) { 538 TEST_F(VideoCaptureExternalTest, Rotation) {
538 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); 539 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0));
539 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 540 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
540 test_frame_.width(), 541 test_frame_.width(),
541 test_frame_.height()); 542 test_frame_.height());
542 scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 543 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
543 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 544 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
544 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 545 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
545 length, capture_callback_.capability(), 0)); 546 length, capture_callback_.capability(), 0));
546 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); 547 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90));
547 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); 548 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90);
548 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 549 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
549 length, capture_callback_.capability(), 0)); 550 length, capture_callback_.capability(), 0));
550 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); 551 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180));
551 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); 552 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180);
552 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 553 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
553 length, capture_callback_.capability(), 0)); 554 length, capture_callback_.capability(), 0));
554 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); 555 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270));
555 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); 556 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270);
556 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 557 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
557 length, capture_callback_.capability(), 0)); 558 length, capture_callback_.capability(), 0));
558 } 559 }
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