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

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

Issue 1733673002: Removed unused cricket::VideoCapturer methods (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed thread checker for android. SetCaptureFormat is called on the thread where the capturer is cr… 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;
30 29
31 } // namespace 30 } // namespace
32 31
33 class VideoCapturerTest 32 class VideoCapturerTest
34 : public sigslot::has_slots<>, 33 : public sigslot::has_slots<>,
35 public testing::Test { 34 public testing::Test {
36 public: 35 public:
37 VideoCapturerTest() 36 VideoCapturerTest()
38 : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) { 37 : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) {
39 capturer_.SignalStateChange.connect(this, 38 capturer_.SignalStateChange.connect(this,
(...skipping 28 matching lines...) Expand all
68 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 67 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
69 EXPECT_EQ(1, num_state_changes()); 68 EXPECT_EQ(1, num_state_changes());
70 capturer_.Stop(); 69 capturer_.Stop();
71 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); 70 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait);
72 EXPECT_EQ(2, num_state_changes()); 71 EXPECT_EQ(2, num_state_changes());
73 capturer_.Stop(); 72 capturer_.Stop();
74 rtc::Thread::Current()->ProcessMessages(100); 73 rtc::Thread::Current()->ProcessMessages(100);
75 EXPECT_EQ(2, num_state_changes()); 74 EXPECT_EQ(2, num_state_changes());
76 } 75 }
77 76
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
162 TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { 77 TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) {
163 capturer_.SetScreencast(true); 78 capturer_.SetScreencast(true);
164 79
165 int kWidth = 1281; 80 int kWidth = 1281;
166 int kHeight = 720; 81 int kHeight = 720;
167 82
168 std::vector<cricket::VideoFormat> formats; 83 std::vector<cricket::VideoFormat> formats;
169 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 84 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
170 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); 85 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB));
171 capturer_.ResetSupportedFormats(formats); 86 capturer_.ResetSupportedFormats(formats);
(...skipping 17 matching lines...) Expand all
189 int frame_count = 0; 104 int frame_count = 0;
190 105
191 std::vector<cricket::VideoFormat> formats; 106 std::vector<cricket::VideoFormat> formats;
192 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 107 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
193 cricket::VideoFormat::FpsToInterval(5), 108 cricket::VideoFormat::FpsToInterval(5),
194 cricket::FOURCC_I420)); 109 cricket::FOURCC_I420));
195 110
196 capturer_.ResetSupportedFormats(formats); 111 capturer_.ResetSupportedFormats(formats);
197 112
198 // capturer_ should compensate rotation as default. 113 // capturer_ should compensate rotation as default.
199 capturer_.UpdateAspectRatio(400, 200);
200
201 EXPECT_EQ(cricket::CS_RUNNING, 114 EXPECT_EQ(cricket::CS_RUNNING,
202 capturer_.Start(cricket::VideoFormat( 115 capturer_.Start(cricket::VideoFormat(
203 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), 116 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30),
204 cricket::FOURCC_I420))); 117 cricket::FOURCC_I420)));
205 EXPECT_TRUE(capturer_.IsRunning()); 118 EXPECT_TRUE(capturer_.IsRunning());
206 EXPECT_EQ(0, renderer_.num_rendered_frames()); 119 EXPECT_EQ(0, renderer_.num_rendered_frames());
207 120
208 // If the frame's rotation is compensated anywhere in the pipeline based on 121 // If the frame's rotation is compensated anywhere in the pipeline based on
209 // the rotation information, the renderer should be given the right dimension 122 // the rotation information, the renderer should be given the right dimension
210 // such that the frame could be rendered. 123 // such that the frame could be rendered.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 155 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
243 cricket::VideoFormat::FpsToInterval(5), 156 cricket::VideoFormat::FpsToInterval(5),
244 cricket::FOURCC_I420)); 157 cricket::FOURCC_I420));
245 158
246 capturer_.ResetSupportedFormats(formats); 159 capturer_.ResetSupportedFormats(formats);
247 rtc::VideoSinkWants wants; 160 rtc::VideoSinkWants wants;
248 // capturer_ should not compensate rotation. 161 // capturer_ should not compensate rotation.
249 wants.rotation_applied = false; 162 wants.rotation_applied = false;
250 capturer_.AddOrUpdateSink(&renderer_, wants); 163 capturer_.AddOrUpdateSink(&renderer_, wants);
251 164
252 capturer_.UpdateAspectRatio(400, 200);
253
254 EXPECT_EQ(cricket::CS_RUNNING, 165 EXPECT_EQ(cricket::CS_RUNNING,
255 capturer_.Start(cricket::VideoFormat( 166 capturer_.Start(cricket::VideoFormat(
256 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), 167 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30),
257 cricket::FOURCC_I420))); 168 cricket::FOURCC_I420)));
258 EXPECT_TRUE(capturer_.IsRunning()); 169 EXPECT_TRUE(capturer_.IsRunning());
259 EXPECT_EQ(0, renderer_.num_rendered_frames()); 170 EXPECT_EQ(0, renderer_.num_rendered_frames());
260 171
261 // If the frame's rotation is compensated anywhere in the pipeline, the frame 172 // If the frame's rotation is compensated anywhere in the pipeline, the frame
262 // won't have its original dimension out from capturer. Since the renderer 173 // won't have its original dimension out from capturer. Since the renderer
263 // here has the same dimension as the capturer, it will skip that frame as the 174 // here has the same dimension as the capturer, it will skip that frame as the
(...skipping 29 matching lines...) Expand all
293 formats.push_back(cricket::VideoFormat(kWidth, kHeight, 204 formats.push_back(cricket::VideoFormat(kWidth, kHeight,
294 cricket::VideoFormat::FpsToInterval(5), 205 cricket::VideoFormat::FpsToInterval(5),
295 cricket::FOURCC_I420)); 206 cricket::FOURCC_I420));
296 207
297 capturer_.ResetSupportedFormats(formats); 208 capturer_.ResetSupportedFormats(formats);
298 rtc::VideoSinkWants wants; 209 rtc::VideoSinkWants wants;
299 // capturer_ should not compensate rotation. 210 // capturer_ should not compensate rotation.
300 wants.rotation_applied = false; 211 wants.rotation_applied = false;
301 capturer_.AddOrUpdateSink(&renderer_, wants); 212 capturer_.AddOrUpdateSink(&renderer_, wants);
302 213
303 capturer_.UpdateAspectRatio(400, 200);
304
305 EXPECT_EQ(cricket::CS_RUNNING, 214 EXPECT_EQ(cricket::CS_RUNNING,
306 capturer_.Start(cricket::VideoFormat( 215 capturer_.Start(cricket::VideoFormat(
307 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), 216 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30),
308 cricket::FOURCC_I420))); 217 cricket::FOURCC_I420)));
309 EXPECT_TRUE(capturer_.IsRunning()); 218 EXPECT_TRUE(capturer_.IsRunning());
310 EXPECT_EQ(0, renderer_.num_rendered_frames()); 219 EXPECT_EQ(0, renderer_.num_rendered_frames());
311 220
312 int frame_count = 0; 221 int frame_count = 0;
313 capturer_.SetRotation(webrtc::kVideoRotation_90); 222 capturer_.SetRotation(webrtc::kVideoRotation_90);
314 EXPECT_TRUE(capturer_.CaptureFrame()); 223 EXPECT_TRUE(capturer_.CaptureFrame());
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 capturer_.set_enable_camera_list(true); 713 capturer_.set_enable_camera_list(true);
805 capturer_.ConstrainSupportedFormats(vga_format); 714 capturer_.ConstrainSupportedFormats(vga_format);
806 EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); 715 EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size());
807 // To make sure it's not just the camera list being broken, add in VGA and 716 // To make sure it's not just the camera list being broken, add in VGA and
808 // try again. This time, only the VGA format should be there. 717 // try again. This time, only the VGA format should be there.
809 supported_formats.push_back(vga_format); 718 supported_formats.push_back(vga_format);
810 capturer_.ResetSupportedFormats(supported_formats); 719 capturer_.ResetSupportedFormats(supported_formats);
811 ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size()); 720 ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size());
812 EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height); 721 EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height);
813 } 722 }
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