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

Side by Side Diff: webrtc/media/base/videocapturer_unittest.cc

Issue 1740963002: Revert of Removed unused cricket::VideoCapturer methods (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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
« no previous file with comments | « webrtc/media/base/videocapturer.cc ('k') | webrtc/media/engine/webrtcvideocapturer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2008 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 #include <vector> 12 #include <vector>
13 13
14 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
15 #include "webrtc/base/logging.h" 15 #include "webrtc/base/logging.h"
16 #include "webrtc/base/thread.h" 16 #include "webrtc/base/thread.h"
17 #include "webrtc/media/base/fakevideocapturer.h" 17 #include "webrtc/media/base/fakevideocapturer.h"
18 #include "webrtc/media/base/fakevideorenderer.h" 18 #include "webrtc/media/base/fakevideorenderer.h"
19 #include "webrtc/media/base/testutils.h" 19 #include "webrtc/media/base/testutils.h"
20 #include "webrtc/media/base/videocapturer.h" 20 #include "webrtc/media/base/videocapturer.h"
21 21
22 using cricket::FakeVideoCapturer; 22 using cricket::FakeVideoCapturer;
23 23
24 namespace { 24 namespace {
25 25
26 const int kMsCallbackWait = 500; 26 const int kMsCallbackWait = 500;
27 // For HD only the height matters. 27 // For HD only the height matters.
28 const int kMinHdHeight = 720; 28 const int kMinHdHeight = 720;
29 const uint32_t kTimeout = 5000U;
29 30
30 } // namespace 31 } // namespace
31 32
32 class VideoCapturerTest 33 class VideoCapturerTest
33 : public sigslot::has_slots<>, 34 : public sigslot::has_slots<>,
34 public testing::Test { 35 public testing::Test {
35 public: 36 public:
36 VideoCapturerTest() 37 VideoCapturerTest()
37 : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) { 38 : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) {
38 capturer_.SignalStateChange.connect(this, 39 capturer_.SignalStateChange.connect(this,
(...skipping 28 matching lines...) Expand all
67 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 68 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
68 EXPECT_EQ(1, num_state_changes()); 69 EXPECT_EQ(1, num_state_changes());
69 capturer_.Stop(); 70 capturer_.Stop();
70 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); 71 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait);
71 EXPECT_EQ(2, num_state_changes()); 72 EXPECT_EQ(2, num_state_changes());
72 capturer_.Stop(); 73 capturer_.Stop();
73 rtc::Thread::Current()->ProcessMessages(100); 74 rtc::Thread::Current()->ProcessMessages(100);
74 EXPECT_EQ(2, num_state_changes()); 75 EXPECT_EQ(2, num_state_changes());
75 } 76 }
76 77
78 TEST_F(VideoCapturerTest, TestRestart) {
79 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
80 640,
81 480,
82 cricket::VideoFormat::FpsToInterval(30),
83 cricket::FOURCC_I420)));
84 EXPECT_TRUE(capturer_.IsRunning());
85 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
86 EXPECT_EQ(1, num_state_changes());
87 EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat(
88 320,
89 240,
90 cricket::VideoFormat::FpsToInterval(30),
91 cricket::FOURCC_I420)));
92 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
93 EXPECT_TRUE(capturer_.IsRunning());
94 EXPECT_GE(1, num_state_changes());
95 capturer_.Stop();
96 rtc::Thread::Current()->ProcessMessages(100);
97 EXPECT_FALSE(capturer_.IsRunning());
98 }
99
100 TEST_F(VideoCapturerTest, TestStartingWithRestart) {
101 EXPECT_FALSE(capturer_.IsRunning());
102 EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat(
103 640,
104 480,
105 cricket::VideoFormat::FpsToInterval(30),
106 cricket::FOURCC_I420)));
107 EXPECT_TRUE(capturer_.IsRunning());
108 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
109 }
110
111 TEST_F(VideoCapturerTest, TestRestartWithSameFormat) {
112 cricket::VideoFormat format(640, 480,
113 cricket::VideoFormat::FpsToInterval(30),
114 cricket::FOURCC_I420);
115 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(format));
116 EXPECT_TRUE(capturer_.IsRunning());
117 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
118 EXPECT_EQ(1, num_state_changes());
119 EXPECT_TRUE(capturer_.Restart(format));
120 EXPECT_EQ(cricket::CS_RUNNING, capture_state());
121 EXPECT_TRUE(capturer_.IsRunning());
122 EXPECT_EQ(1, num_state_changes());
123 }
124
125 TEST_F(VideoCapturerTest, CameraOffOnMute) {
126 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
127 640,
128 480,
129 cricket::VideoFormat::FpsToInterval(30),
130 cricket::FOURCC_I420)));
131 EXPECT_TRUE(capturer_.IsRunning());
132 EXPECT_EQ(0, renderer_.num_rendered_frames());
133 EXPECT_TRUE(capturer_.CaptureFrame());
134 EXPECT_EQ(1, renderer_.num_rendered_frames());
135 EXPECT_FALSE(capturer_.IsMuted());
136
137 // Mute the camera and expect black output frame.
138 capturer_.MuteToBlackThenPause(true);
139 EXPECT_TRUE(capturer_.IsMuted());
140 for (int i = 0; i < 31; ++i) {
141 EXPECT_TRUE(capturer_.CaptureFrame());
142 EXPECT_TRUE(renderer_.black_frame());
143 }
144 EXPECT_EQ(32, renderer_.num_rendered_frames());
145 EXPECT_EQ_WAIT(cricket::CS_PAUSED,
146 capturer_.capture_state(), kTimeout);
147
148 // Verify that the camera is off.
149 EXPECT_FALSE(capturer_.CaptureFrame());
150 EXPECT_EQ(32, renderer_.num_rendered_frames());
151
152 // Unmute the camera and expect non-black output frame.
153 capturer_.MuteToBlackThenPause(false);
154 EXPECT_FALSE(capturer_.IsMuted());
155 EXPECT_EQ_WAIT(cricket::CS_RUNNING,
156 capturer_.capture_state(), kTimeout);
157 EXPECT_TRUE(capturer_.CaptureFrame());
158 EXPECT_FALSE(renderer_.black_frame());
159 EXPECT_EQ(33, renderer_.num_rendered_frames());
160 }
161
77 TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { 162 TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) {
78 capturer_.SetScreencast(true); 163 capturer_.SetScreencast(true);
79 164
80 int kWidth = 1281; 165 int kWidth = 1281;
81 int kHeight = 720; 166 int kHeight = 720;
82 167
83 std::vector<cricket::VideoFormat> formats; 168 std::vector<cricket::VideoFormat> formats;
84 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 169 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
85 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); 170 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB));
86 capturer_.ResetSupportedFormats(formats); 171 capturer_.ResetSupportedFormats(formats);
(...skipping 17 matching lines...) Expand all
104 int frame_count = 0; 189 int frame_count = 0;
105 190
106 std::vector<cricket::VideoFormat> formats; 191 std::vector<cricket::VideoFormat> formats;
107 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 192 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
108 cricket::VideoFormat::FpsToInterval(5), 193 cricket::VideoFormat::FpsToInterval(5),
109 cricket::FOURCC_I420)); 194 cricket::FOURCC_I420));
110 195
111 capturer_.ResetSupportedFormats(formats); 196 capturer_.ResetSupportedFormats(formats);
112 197
113 // capturer_ should compensate rotation as default. 198 // capturer_ should compensate rotation as default.
199 capturer_.UpdateAspectRatio(400, 200);
200
114 EXPECT_EQ(cricket::CS_RUNNING, 201 EXPECT_EQ(cricket::CS_RUNNING,
115 capturer_.Start(cricket::VideoFormat( 202 capturer_.Start(cricket::VideoFormat(
116 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), 203 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30),
117 cricket::FOURCC_I420))); 204 cricket::FOURCC_I420)));
118 EXPECT_TRUE(capturer_.IsRunning()); 205 EXPECT_TRUE(capturer_.IsRunning());
119 EXPECT_EQ(0, renderer_.num_rendered_frames()); 206 EXPECT_EQ(0, renderer_.num_rendered_frames());
120 207
121 // If the frame's rotation is compensated anywhere in the pipeline based on 208 // If the frame's rotation is compensated anywhere in the pipeline based on
122 // the rotation information, the renderer should be given the right dimension 209 // the rotation information, the renderer should be given the right dimension
123 // such that the frame could be rendered. 210 // such that the frame could be rendered.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 242 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
156 cricket::VideoFormat::FpsToInterval(5), 243 cricket::VideoFormat::FpsToInterval(5),
157 cricket::FOURCC_I420)); 244 cricket::FOURCC_I420));
158 245
159 capturer_.ResetSupportedFormats(formats); 246 capturer_.ResetSupportedFormats(formats);
160 rtc::VideoSinkWants wants; 247 rtc::VideoSinkWants wants;
161 // capturer_ should not compensate rotation. 248 // capturer_ should not compensate rotation.
162 wants.rotation_applied = false; 249 wants.rotation_applied = false;
163 capturer_.AddOrUpdateSink(&renderer_, wants); 250 capturer_.AddOrUpdateSink(&renderer_, wants);
164 251
252 capturer_.UpdateAspectRatio(400, 200);
253
165 EXPECT_EQ(cricket::CS_RUNNING, 254 EXPECT_EQ(cricket::CS_RUNNING,
166 capturer_.Start(cricket::VideoFormat( 255 capturer_.Start(cricket::VideoFormat(
167 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), 256 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30),
168 cricket::FOURCC_I420))); 257 cricket::FOURCC_I420)));
169 EXPECT_TRUE(capturer_.IsRunning()); 258 EXPECT_TRUE(capturer_.IsRunning());
170 EXPECT_EQ(0, renderer_.num_rendered_frames()); 259 EXPECT_EQ(0, renderer_.num_rendered_frames());
171 260
172 // If the frame's rotation is compensated anywhere in the pipeline, the frame 261 // If the frame's rotation is compensated anywhere in the pipeline, the frame
173 // won't have its original dimension out from capturer. Since the renderer 262 // won't have its original dimension out from capturer. Since the renderer
174 // here has the same dimension as the capturer, it will skip that frame as the 263 // here has the same dimension as the capturer, it will skip that frame as the
(...skipping 29 matching lines...) Expand all
204 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 293 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
205 cricket::VideoFormat::FpsToInterval(5), 294 cricket::VideoFormat::FpsToInterval(5),
206 cricket::FOURCC_I420)); 295 cricket::FOURCC_I420));
207 296
208 capturer_.ResetSupportedFormats(formats); 297 capturer_.ResetSupportedFormats(formats);
209 rtc::VideoSinkWants wants; 298 rtc::VideoSinkWants wants;
210 // capturer_ should not compensate rotation. 299 // capturer_ should not compensate rotation.
211 wants.rotation_applied = false; 300 wants.rotation_applied = false;
212 capturer_.AddOrUpdateSink(&renderer_, wants); 301 capturer_.AddOrUpdateSink(&renderer_, wants);
213 302
303 capturer_.UpdateAspectRatio(400, 200);
304
214 EXPECT_EQ(cricket::CS_RUNNING, 305 EXPECT_EQ(cricket::CS_RUNNING,
215 capturer_.Start(cricket::VideoFormat( 306 capturer_.Start(cricket::VideoFormat(
216 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), 307 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30),
217 cricket::FOURCC_I420))); 308 cricket::FOURCC_I420)));
218 EXPECT_TRUE(capturer_.IsRunning()); 309 EXPECT_TRUE(capturer_.IsRunning());
219 EXPECT_EQ(0, renderer_.num_rendered_frames()); 310 EXPECT_EQ(0, renderer_.num_rendered_frames());
220 311
221 int frame_count = 0; 312 int frame_count = 0;
222 capturer_.SetRotation(webrtc::kVideoRotation_90); 313 capturer_.SetRotation(webrtc::kVideoRotation_90);
223 EXPECT_TRUE(capturer_.CaptureFrame()); 314 EXPECT_TRUE(capturer_.CaptureFrame());
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 capturer_.set_enable_camera_list(true); 804 capturer_.set_enable_camera_list(true);
714 capturer_.ConstrainSupportedFormats(vga_format); 805 capturer_.ConstrainSupportedFormats(vga_format);
715 EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); 806 EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size());
716 // To make sure it's not just the camera list being broken, add in VGA and 807 // To make sure it's not just the camera list being broken, add in VGA and
717 // try again. This time, only the VGA format should be there. 808 // try again. This time, only the VGA format should be there.
718 supported_formats.push_back(vga_format); 809 supported_formats.push_back(vga_format);
719 capturer_.ResetSupportedFormats(supported_formats); 810 capturer_.ResetSupportedFormats(supported_formats);
720 ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size()); 811 ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size());
721 EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height); 812 EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height);
722 } 813 }
OLDNEW
« no previous file with comments | « webrtc/media/base/videocapturer.cc ('k') | webrtc/media/engine/webrtcvideocapturer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698