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

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

Issue 1900673002: Delete webrtc::VideoFrame methods buffer and stride. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update H.264 video_toolbox encoder. Created 4 years, 8 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 <memory>
15 #include <sstream> 15 #include <sstream>
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.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/test/frame_utils.h"
26 #include "webrtc/video_frame.h" 27 #include "webrtc/video_frame.h"
27 28
28 using webrtc::CriticalSectionWrapper; 29 using webrtc::CriticalSectionWrapper;
29 using webrtc::CriticalSectionScoped; 30 using webrtc::CriticalSectionScoped;
30 using webrtc::SleepMs; 31 using webrtc::SleepMs;
31 using webrtc::TickTime; 32 using webrtc::TickTime;
32 using webrtc::VideoCaptureAlarm; 33 using webrtc::VideoCaptureAlarm;
33 using webrtc::VideoCaptureCapability; 34 using webrtc::VideoCaptureCapability;
34 using webrtc::VideoCaptureDataCallback; 35 using webrtc::VideoCaptureDataCallback;
35 using webrtc::VideoCaptureFactory; 36 using webrtc::VideoCaptureFactory;
(...skipping 17 matching lines...) Expand all
53 WAIT_(ex, timeout, res); \ 54 WAIT_(ex, timeout, res); \
54 if (!res) EXPECT_TRUE(ex); \ 55 if (!res) EXPECT_TRUE(ex); \
55 } while (0) 56 } while (0)
56 57
57 58
58 static const int kTimeOut = 5000; 59 static const int kTimeOut = 5000;
59 static const int kTestHeight = 288; 60 static const int kTestHeight = 288;
60 static const int kTestWidth = 352; 61 static const int kTestWidth = 352;
61 static const int kTestFramerate = 30; 62 static const int kTestFramerate = 30;
62 63
63 // Compares the content of two video frames.
64 static bool CompareFrames(const webrtc::VideoFrame& frame1,
65 const webrtc::VideoFrame& frame2) {
66 bool result =
67 (frame1.stride(webrtc::kYPlane) == frame2.stride(webrtc::kYPlane)) &&
68 (frame1.stride(webrtc::kUPlane) == frame2.stride(webrtc::kUPlane)) &&
69 (frame1.stride(webrtc::kVPlane) == frame2.stride(webrtc::kVPlane)) &&
70 (frame1.width() == frame2.width()) &&
71 (frame1.height() == frame2.height());
72
73 if (!result)
74 return false;
75 for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) {
76 webrtc::PlaneType plane_type = static_cast<webrtc::PlaneType>(plane);
77 int allocated_size1 = frame1.allocated_size(plane_type);
78 int allocated_size2 = frame2.allocated_size(plane_type);
79 if (allocated_size1 != allocated_size2)
80 return false;
81 const uint8_t* plane_buffer1 = frame1.buffer(plane_type);
82 const uint8_t* plane_buffer2 = frame2.buffer(plane_type);
83 if (memcmp(plane_buffer1, plane_buffer2, allocated_size1))
84 return false;
85 }
86 return true;
87 }
88
89 class TestVideoCaptureCallback : public VideoCaptureDataCallback { 64 class TestVideoCaptureCallback : public VideoCaptureDataCallback {
90 public: 65 public:
91 TestVideoCaptureCallback() 66 TestVideoCaptureCallback()
92 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), 67 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()),
93 capture_delay_(-1), 68 capture_delay_(-1),
94 last_render_time_ms_(0), 69 last_render_time_ms_(0),
95 incoming_frames_(0), 70 incoming_frames_(0),
96 timing_warnings_(0), 71 timing_warnings_(0),
97 rotate_frame_(webrtc::kVideoRotation_0) {} 72 rotate_frame_(webrtc::kVideoRotation_0) {}
98 73
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 CriticalSectionScoped cs(capture_cs_.get()); 136 CriticalSectionScoped cs(capture_cs_.get());
162 return timing_warnings_; 137 return timing_warnings_;
163 } 138 }
164 VideoCaptureCapability capability() { 139 VideoCaptureCapability capability() {
165 CriticalSectionScoped cs(capture_cs_.get()); 140 CriticalSectionScoped cs(capture_cs_.get());
166 return capability_; 141 return capability_;
167 } 142 }
168 143
169 bool CompareLastFrame(const webrtc::VideoFrame& frame) { 144 bool CompareLastFrame(const webrtc::VideoFrame& frame) {
170 CriticalSectionScoped cs(capture_cs_.get()); 145 CriticalSectionScoped cs(capture_cs_.get());
171 return CompareFrames(last_frame_, frame); 146 return webrtc::test::FramesEqual(last_frame_, frame);
172 } 147 }
173 148
174 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { 149 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) {
175 CriticalSectionScoped cs(capture_cs_.get()); 150 CriticalSectionScoped cs(capture_cs_.get());
176 rotate_frame_ = rotation; 151 rotate_frame_ = rotation;
177 } 152 }
178 153
179 private: 154 private:
180 std::unique_ptr<CriticalSectionWrapper> capture_cs_; 155 std::unique_ptr<CriticalSectionWrapper> capture_cs_;
181 VideoCaptureCapability capability_; 156 VideoCaptureCapability capability_;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 VideoCaptureCapability capability; 417 VideoCaptureCapability capability;
443 capability.width = kTestWidth; 418 capability.width = kTestWidth;
444 capability.height = kTestHeight; 419 capability.height = kTestHeight;
445 capability.rawType = webrtc::kVideoYV12; 420 capability.rawType = webrtc::kVideoYV12;
446 capability.maxFPS = kTestFramerate; 421 capability.maxFPS = kTestFramerate;
447 capture_callback_.SetExpectedCapability(capability); 422 capture_callback_.SetExpectedCapability(capability);
448 423
449 test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth, 424 test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth,
450 ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); 425 ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2);
451 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. 426 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp.
452 memset(test_frame_.buffer(webrtc::kYPlane), 127, kTestWidth * kTestHeight); 427 memset(test_frame_.video_frame_buffer()->MutableDataY(), 127,
453 memset(test_frame_.buffer(webrtc::kUPlane), 127, 428 kTestWidth * kTestHeight);
429 memset(test_frame_.video_frame_buffer()->MutableDataU(), 127,
454 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); 430 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2));
455 memset(test_frame_.buffer(webrtc::kVPlane), 127, 431 memset(test_frame_.video_frame_buffer()->MutableDataV(), 127,
456 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); 432 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2));
457 433
458 capture_module_->RegisterCaptureDataCallback(capture_callback_); 434 capture_module_->RegisterCaptureDataCallback(capture_callback_);
459 capture_module_->RegisterCaptureCallback(capture_feedback_); 435 capture_module_->RegisterCaptureCallback(capture_feedback_);
460 capture_module_->EnableFrameRateCallback(true); 436 capture_module_->EnableFrameRateCallback(true);
461 capture_module_->EnableNoPictureAlarm(true); 437 capture_module_->EnableNoPictureAlarm(true);
462 } 438 }
463 439
464 void TearDown() { 440 void TearDown() {
465 process_module_->Stop(); 441 process_module_->Stop();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 length, capture_callback_.capability(), 0)); 520 length, capture_callback_.capability(), 0));
545 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); 521 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180));
546 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); 522 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180);
547 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 523 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
548 length, capture_callback_.capability(), 0)); 524 length, capture_callback_.capability(), 0));
549 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); 525 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270));
550 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); 526 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270);
551 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 527 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
552 length, capture_callback_.capability(), 0)); 528 length, capture_callback_.capability(), 0));
553 } 529 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698