OLD | NEW |
---|---|
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 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 const uint32_t kTimeout = 5000U; | 29 const uint32_t kTimeout = 5000U; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 class VideoCapturerTest | 33 class VideoCapturerTest |
34 : public sigslot::has_slots<>, | 34 : public sigslot::has_slots<>, |
35 public testing::Test { | 35 public testing::Test { |
36 public: | 36 public: |
37 VideoCapturerTest() | 37 VideoCapturerTest() |
38 : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) { | 38 : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) { |
39 capturer_.SignalStateChange.connect(this, | 39 InitScreencast(false); |
40 &VideoCapturerTest::OnStateChange); | |
41 capturer_.AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); | |
42 } | 40 } |
43 | 41 |
44 protected: | 42 protected: |
43 void InitScreencast(bool is_screencast) { | |
pthatcher1
2016/02/20 08:33:00
Same here.
| |
44 capturer_ = rtc::scoped_ptr<FakeVideoCapturer>( | |
45 new FakeVideoCapturer(is_screencast)); | |
46 capturer_->SignalStateChange.connect(this, | |
47 &VideoCapturerTest::OnStateChange); | |
48 capturer_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); | |
49 } | |
45 void OnStateChange(cricket::VideoCapturer*, | 50 void OnStateChange(cricket::VideoCapturer*, |
46 cricket::CaptureState capture_state) { | 51 cricket::CaptureState capture_state) { |
47 capture_state_ = capture_state; | 52 capture_state_ = capture_state; |
48 ++num_state_changes_; | 53 ++num_state_changes_; |
49 } | 54 } |
50 cricket::CaptureState capture_state() { return capture_state_; } | 55 cricket::CaptureState capture_state() { return capture_state_; } |
51 int num_state_changes() { return num_state_changes_; } | 56 int num_state_changes() { return num_state_changes_; } |
52 | 57 |
53 cricket::FakeVideoCapturer capturer_; | 58 rtc::scoped_ptr<cricket::FakeVideoCapturer> capturer_; |
54 cricket::CaptureState capture_state_; | 59 cricket::CaptureState capture_state_; |
55 int num_state_changes_; | 60 int num_state_changes_; |
56 cricket::FakeVideoRenderer renderer_; | 61 cricket::FakeVideoRenderer renderer_; |
57 bool expects_rotation_applied_; | 62 bool expects_rotation_applied_; |
58 }; | 63 }; |
59 | 64 |
60 TEST_F(VideoCapturerTest, CaptureState) { | 65 TEST_F(VideoCapturerTest, CaptureState) { |
61 EXPECT_TRUE(capturer_.enable_video_adapter()); | 66 EXPECT_TRUE(capturer_->enable_video_adapter()); |
62 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 67 EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( |
63 640, | 68 640, |
64 480, | 69 480, |
65 cricket::VideoFormat::FpsToInterval(30), | 70 cricket::VideoFormat::FpsToInterval(30), |
66 cricket::FOURCC_I420))); | 71 cricket::FOURCC_I420))); |
67 EXPECT_TRUE(capturer_.IsRunning()); | 72 EXPECT_TRUE(capturer_->IsRunning()); |
68 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 73 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
69 EXPECT_EQ(1, num_state_changes()); | 74 EXPECT_EQ(1, num_state_changes()); |
70 capturer_.Stop(); | 75 capturer_->Stop(); |
71 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); | 76 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); |
72 EXPECT_EQ(2, num_state_changes()); | 77 EXPECT_EQ(2, num_state_changes()); |
73 capturer_.Stop(); | 78 capturer_->Stop(); |
74 rtc::Thread::Current()->ProcessMessages(100); | 79 rtc::Thread::Current()->ProcessMessages(100); |
75 EXPECT_EQ(2, num_state_changes()); | 80 EXPECT_EQ(2, num_state_changes()); |
76 } | 81 } |
77 | 82 |
78 TEST_F(VideoCapturerTest, TestRestart) { | 83 TEST_F(VideoCapturerTest, TestRestart) { |
79 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 84 EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( |
80 640, | 85 640, |
81 480, | 86 480, |
82 cricket::VideoFormat::FpsToInterval(30), | 87 cricket::VideoFormat::FpsToInterval(30), |
83 cricket::FOURCC_I420))); | 88 cricket::FOURCC_I420))); |
84 EXPECT_TRUE(capturer_.IsRunning()); | 89 EXPECT_TRUE(capturer_->IsRunning()); |
85 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 90 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
86 EXPECT_EQ(1, num_state_changes()); | 91 EXPECT_EQ(1, num_state_changes()); |
87 EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat( | 92 EXPECT_TRUE(capturer_->Restart(cricket::VideoFormat( |
88 320, | 93 320, |
89 240, | 94 240, |
90 cricket::VideoFormat::FpsToInterval(30), | 95 cricket::VideoFormat::FpsToInterval(30), |
91 cricket::FOURCC_I420))); | 96 cricket::FOURCC_I420))); |
92 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 97 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
93 EXPECT_TRUE(capturer_.IsRunning()); | 98 EXPECT_TRUE(capturer_->IsRunning()); |
94 EXPECT_GE(1, num_state_changes()); | 99 EXPECT_GE(1, num_state_changes()); |
95 capturer_.Stop(); | 100 capturer_->Stop(); |
96 rtc::Thread::Current()->ProcessMessages(100); | 101 rtc::Thread::Current()->ProcessMessages(100); |
97 EXPECT_FALSE(capturer_.IsRunning()); | 102 EXPECT_FALSE(capturer_->IsRunning()); |
98 } | 103 } |
99 | 104 |
100 TEST_F(VideoCapturerTest, TestStartingWithRestart) { | 105 TEST_F(VideoCapturerTest, TestStartingWithRestart) { |
101 EXPECT_FALSE(capturer_.IsRunning()); | 106 EXPECT_FALSE(capturer_->IsRunning()); |
102 EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat( | 107 EXPECT_TRUE(capturer_->Restart(cricket::VideoFormat( |
103 640, | 108 640, |
104 480, | 109 480, |
105 cricket::VideoFormat::FpsToInterval(30), | 110 cricket::VideoFormat::FpsToInterval(30), |
106 cricket::FOURCC_I420))); | 111 cricket::FOURCC_I420))); |
107 EXPECT_TRUE(capturer_.IsRunning()); | 112 EXPECT_TRUE(capturer_->IsRunning()); |
108 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 113 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
109 } | 114 } |
110 | 115 |
111 TEST_F(VideoCapturerTest, TestRestartWithSameFormat) { | 116 TEST_F(VideoCapturerTest, TestRestartWithSameFormat) { |
112 cricket::VideoFormat format(640, 480, | 117 cricket::VideoFormat format(640, 480, |
113 cricket::VideoFormat::FpsToInterval(30), | 118 cricket::VideoFormat::FpsToInterval(30), |
114 cricket::FOURCC_I420); | 119 cricket::FOURCC_I420); |
115 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(format)); | 120 EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(format)); |
116 EXPECT_TRUE(capturer_.IsRunning()); | 121 EXPECT_TRUE(capturer_->IsRunning()); |
117 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); | 122 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
118 EXPECT_EQ(1, num_state_changes()); | 123 EXPECT_EQ(1, num_state_changes()); |
119 EXPECT_TRUE(capturer_.Restart(format)); | 124 EXPECT_TRUE(capturer_->Restart(format)); |
120 EXPECT_EQ(cricket::CS_RUNNING, capture_state()); | 125 EXPECT_EQ(cricket::CS_RUNNING, capture_state()); |
121 EXPECT_TRUE(capturer_.IsRunning()); | 126 EXPECT_TRUE(capturer_->IsRunning()); |
122 EXPECT_EQ(1, num_state_changes()); | 127 EXPECT_EQ(1, num_state_changes()); |
123 } | 128 } |
124 | 129 |
125 TEST_F(VideoCapturerTest, CameraOffOnMute) { | 130 TEST_F(VideoCapturerTest, CameraOffOnMute) { |
126 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 131 EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( |
127 640, | 132 640, |
128 480, | 133 480, |
129 cricket::VideoFormat::FpsToInterval(30), | 134 cricket::VideoFormat::FpsToInterval(30), |
130 cricket::FOURCC_I420))); | 135 cricket::FOURCC_I420))); |
131 EXPECT_TRUE(capturer_.IsRunning()); | 136 EXPECT_TRUE(capturer_->IsRunning()); |
132 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 137 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
133 EXPECT_TRUE(capturer_.CaptureFrame()); | 138 EXPECT_TRUE(capturer_->CaptureFrame()); |
134 EXPECT_EQ(1, renderer_.num_rendered_frames()); | 139 EXPECT_EQ(1, renderer_.num_rendered_frames()); |
135 EXPECT_FALSE(capturer_.IsMuted()); | 140 EXPECT_FALSE(capturer_->IsMuted()); |
136 | 141 |
137 // Mute the camera and expect black output frame. | 142 // Mute the camera and expect black output frame. |
138 capturer_.MuteToBlackThenPause(true); | 143 capturer_->MuteToBlackThenPause(true); |
139 EXPECT_TRUE(capturer_.IsMuted()); | 144 EXPECT_TRUE(capturer_->IsMuted()); |
140 for (int i = 0; i < 31; ++i) { | 145 for (int i = 0; i < 31; ++i) { |
141 EXPECT_TRUE(capturer_.CaptureFrame()); | 146 EXPECT_TRUE(capturer_->CaptureFrame()); |
142 EXPECT_TRUE(renderer_.black_frame()); | 147 EXPECT_TRUE(renderer_.black_frame()); |
143 } | 148 } |
144 EXPECT_EQ(32, renderer_.num_rendered_frames()); | 149 EXPECT_EQ(32, renderer_.num_rendered_frames()); |
145 EXPECT_EQ_WAIT(cricket::CS_PAUSED, | 150 EXPECT_EQ_WAIT(cricket::CS_PAUSED, |
146 capturer_.capture_state(), kTimeout); | 151 capturer_->capture_state(), kTimeout); |
147 | 152 |
148 // Verify that the camera is off. | 153 // Verify that the camera is off. |
149 EXPECT_FALSE(capturer_.CaptureFrame()); | 154 EXPECT_FALSE(capturer_->CaptureFrame()); |
150 EXPECT_EQ(32, renderer_.num_rendered_frames()); | 155 EXPECT_EQ(32, renderer_.num_rendered_frames()); |
151 | 156 |
152 // Unmute the camera and expect non-black output frame. | 157 // Unmute the camera and expect non-black output frame. |
153 capturer_.MuteToBlackThenPause(false); | 158 capturer_->MuteToBlackThenPause(false); |
154 EXPECT_FALSE(capturer_.IsMuted()); | 159 EXPECT_FALSE(capturer_->IsMuted()); |
155 EXPECT_EQ_WAIT(cricket::CS_RUNNING, | 160 EXPECT_EQ_WAIT(cricket::CS_RUNNING, |
156 capturer_.capture_state(), kTimeout); | 161 capturer_->capture_state(), kTimeout); |
157 EXPECT_TRUE(capturer_.CaptureFrame()); | 162 EXPECT_TRUE(capturer_->CaptureFrame()); |
158 EXPECT_FALSE(renderer_.black_frame()); | 163 EXPECT_FALSE(renderer_.black_frame()); |
159 EXPECT_EQ(33, renderer_.num_rendered_frames()); | 164 EXPECT_EQ(33, renderer_.num_rendered_frames()); |
160 } | 165 } |
161 | 166 |
162 TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { | 167 TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { |
163 capturer_.SetScreencast(true); | 168 InitScreencast(true); |
164 | 169 |
165 int kWidth = 1281; | 170 int kWidth = 1281; |
166 int kHeight = 720; | 171 int kHeight = 720; |
167 | 172 |
168 std::vector<cricket::VideoFormat> formats; | 173 std::vector<cricket::VideoFormat> formats; |
169 formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 174 formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
170 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); | 175 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); |
171 capturer_.ResetSupportedFormats(formats); | 176 capturer_->ResetSupportedFormats(formats); |
172 | 177 |
173 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 178 EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( |
174 kWidth, | 179 kWidth, |
175 kHeight, | 180 kHeight, |
176 cricket::VideoFormat::FpsToInterval(30), | 181 cricket::VideoFormat::FpsToInterval(30), |
177 cricket::FOURCC_ARGB))); | 182 cricket::FOURCC_ARGB))); |
178 EXPECT_TRUE(capturer_.IsRunning()); | 183 EXPECT_TRUE(capturer_->IsRunning()); |
179 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 184 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
180 EXPECT_TRUE(capturer_.CaptureFrame()); | 185 EXPECT_TRUE(capturer_->CaptureFrame()); |
181 EXPECT_EQ(1, renderer_.num_rendered_frames()); | 186 EXPECT_EQ(1, renderer_.num_rendered_frames()); |
182 EXPECT_EQ(kWidth, renderer_.width()); | 187 EXPECT_EQ(kWidth, renderer_.width()); |
183 EXPECT_EQ(kHeight, renderer_.height()); | 188 EXPECT_EQ(kHeight, renderer_.height()); |
184 } | 189 } |
185 | 190 |
186 TEST_F(VideoCapturerTest, TestRotationAppliedBySource) { | 191 TEST_F(VideoCapturerTest, TestRotationAppliedBySource) { |
187 int kWidth = 800; | 192 int kWidth = 800; |
188 int kHeight = 400; | 193 int kHeight = 400; |
189 int frame_count = 0; | 194 int frame_count = 0; |
190 | 195 |
191 std::vector<cricket::VideoFormat> formats; | 196 std::vector<cricket::VideoFormat> formats; |
192 formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 197 formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
193 cricket::VideoFormat::FpsToInterval(5), | 198 cricket::VideoFormat::FpsToInterval(5), |
194 cricket::FOURCC_I420)); | 199 cricket::FOURCC_I420)); |
195 | 200 |
196 capturer_.ResetSupportedFormats(formats); | 201 capturer_->ResetSupportedFormats(formats); |
197 | 202 |
198 // capturer_ should compensate rotation as default. | 203 // capturer_ should compensate rotation as default. |
199 capturer_.UpdateAspectRatio(400, 200); | 204 capturer_->UpdateAspectRatio(400, 200); |
200 | 205 |
201 EXPECT_EQ(cricket::CS_RUNNING, | 206 EXPECT_EQ(cricket::CS_RUNNING, |
202 capturer_.Start(cricket::VideoFormat( | 207 capturer_->Start(cricket::VideoFormat( |
203 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), | 208 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |
204 cricket::FOURCC_I420))); | 209 cricket::FOURCC_I420))); |
205 EXPECT_TRUE(capturer_.IsRunning()); | 210 EXPECT_TRUE(capturer_->IsRunning()); |
206 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 211 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
207 | 212 |
208 // If the frame's rotation is compensated anywhere in the pipeline based on | 213 // 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 | 214 // the rotation information, the renderer should be given the right dimension |
210 // such that the frame could be rendered. | 215 // such that the frame could be rendered. |
211 | 216 |
212 capturer_.SetRotation(webrtc::kVideoRotation_90); | 217 capturer_->SetRotation(webrtc::kVideoRotation_90); |
213 EXPECT_TRUE(capturer_.CaptureFrame()); | 218 EXPECT_TRUE(capturer_->CaptureFrame()); |
214 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 219 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
215 // Swapped width and height | 220 // Swapped width and height |
216 EXPECT_EQ(kWidth, renderer_.height()); | 221 EXPECT_EQ(kWidth, renderer_.height()); |
217 EXPECT_EQ(kHeight, renderer_.width()); | 222 EXPECT_EQ(kHeight, renderer_.width()); |
218 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); | 223 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
219 | 224 |
220 capturer_.SetRotation(webrtc::kVideoRotation_270); | 225 capturer_->SetRotation(webrtc::kVideoRotation_270); |
221 EXPECT_TRUE(capturer_.CaptureFrame()); | 226 EXPECT_TRUE(capturer_->CaptureFrame()); |
222 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 227 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
223 // Swapped width and height | 228 // Swapped width and height |
224 EXPECT_EQ(kWidth, renderer_.height()); | 229 EXPECT_EQ(kWidth, renderer_.height()); |
225 EXPECT_EQ(kHeight, renderer_.width()); | 230 EXPECT_EQ(kHeight, renderer_.width()); |
226 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); | 231 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
227 | 232 |
228 capturer_.SetRotation(webrtc::kVideoRotation_180); | 233 capturer_->SetRotation(webrtc::kVideoRotation_180); |
229 EXPECT_TRUE(capturer_.CaptureFrame()); | 234 EXPECT_TRUE(capturer_->CaptureFrame()); |
230 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 235 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
231 // Back to normal width and height | 236 // Back to normal width and height |
232 EXPECT_EQ(kWidth, renderer_.width()); | 237 EXPECT_EQ(kWidth, renderer_.width()); |
233 EXPECT_EQ(kHeight, renderer_.height()); | 238 EXPECT_EQ(kHeight, renderer_.height()); |
234 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); | 239 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
235 } | 240 } |
236 | 241 |
237 TEST_F(VideoCapturerTest, TestRotationAppliedBySink) { | 242 TEST_F(VideoCapturerTest, TestRotationAppliedBySink) { |
238 int kWidth = 800; | 243 int kWidth = 800; |
239 int kHeight = 400; | 244 int kHeight = 400; |
240 | 245 |
241 std::vector<cricket::VideoFormat> formats; | 246 std::vector<cricket::VideoFormat> formats; |
242 formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 247 formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
243 cricket::VideoFormat::FpsToInterval(5), | 248 cricket::VideoFormat::FpsToInterval(5), |
244 cricket::FOURCC_I420)); | 249 cricket::FOURCC_I420)); |
245 | 250 |
246 capturer_.ResetSupportedFormats(formats); | 251 capturer_->ResetSupportedFormats(formats); |
247 rtc::VideoSinkWants wants; | 252 rtc::VideoSinkWants wants; |
248 // capturer_ should not compensate rotation. | 253 // capturer_ should not compensate rotation. |
249 wants.rotation_applied = false; | 254 wants.rotation_applied = false; |
250 capturer_.AddOrUpdateSink(&renderer_, wants); | 255 capturer_->AddOrUpdateSink(&renderer_, wants); |
251 | 256 |
252 capturer_.UpdateAspectRatio(400, 200); | 257 capturer_->UpdateAspectRatio(400, 200); |
253 | 258 |
254 EXPECT_EQ(cricket::CS_RUNNING, | 259 EXPECT_EQ(cricket::CS_RUNNING, |
255 capturer_.Start(cricket::VideoFormat( | 260 capturer_->Start(cricket::VideoFormat( |
256 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), | 261 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |
257 cricket::FOURCC_I420))); | 262 cricket::FOURCC_I420))); |
258 EXPECT_TRUE(capturer_.IsRunning()); | 263 EXPECT_TRUE(capturer_->IsRunning()); |
259 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 264 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
260 | 265 |
261 // If the frame's rotation is compensated anywhere in the pipeline, the frame | 266 // 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 | 267 // 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 | 268 // here has the same dimension as the capturer, it will skip that frame as the |
264 // resolution won't match anymore. | 269 // resolution won't match anymore. |
265 | 270 |
266 int frame_count = 0; | 271 int frame_count = 0; |
267 capturer_.SetRotation(webrtc::kVideoRotation_0); | 272 capturer_->SetRotation(webrtc::kVideoRotation_0); |
268 EXPECT_TRUE(capturer_.CaptureFrame()); | 273 EXPECT_TRUE(capturer_->CaptureFrame()); |
269 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 274 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
270 EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); | 275 EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); |
271 | 276 |
272 capturer_.SetRotation(webrtc::kVideoRotation_90); | 277 capturer_->SetRotation(webrtc::kVideoRotation_90); |
273 EXPECT_TRUE(capturer_.CaptureFrame()); | 278 EXPECT_TRUE(capturer_->CaptureFrame()); |
274 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 279 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
275 EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); | 280 EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); |
276 | 281 |
277 capturer_.SetRotation(webrtc::kVideoRotation_180); | 282 capturer_->SetRotation(webrtc::kVideoRotation_180); |
278 EXPECT_TRUE(capturer_.CaptureFrame()); | 283 EXPECT_TRUE(capturer_->CaptureFrame()); |
279 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 284 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
280 EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); | 285 EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); |
281 | 286 |
282 capturer_.SetRotation(webrtc::kVideoRotation_270); | 287 capturer_->SetRotation(webrtc::kVideoRotation_270); |
283 EXPECT_TRUE(capturer_.CaptureFrame()); | 288 EXPECT_TRUE(capturer_->CaptureFrame()); |
284 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 289 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
285 EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); | 290 EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); |
286 } | 291 } |
287 | 292 |
288 TEST_F(VideoCapturerTest, TestRotationAppliedBySourceWhenDifferentWants) { | 293 TEST_F(VideoCapturerTest, TestRotationAppliedBySourceWhenDifferentWants) { |
289 int kWidth = 800; | 294 int kWidth = 800; |
290 int kHeight = 400; | 295 int kHeight = 400; |
291 | 296 |
292 std::vector<cricket::VideoFormat> formats; | 297 std::vector<cricket::VideoFormat> formats; |
293 formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 298 formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
294 cricket::VideoFormat::FpsToInterval(5), | 299 cricket::VideoFormat::FpsToInterval(5), |
295 cricket::FOURCC_I420)); | 300 cricket::FOURCC_I420)); |
296 | 301 |
297 capturer_.ResetSupportedFormats(formats); | 302 capturer_->ResetSupportedFormats(formats); |
298 rtc::VideoSinkWants wants; | 303 rtc::VideoSinkWants wants; |
299 // capturer_ should not compensate rotation. | 304 // capturer_ should not compensate rotation. |
300 wants.rotation_applied = false; | 305 wants.rotation_applied = false; |
301 capturer_.AddOrUpdateSink(&renderer_, wants); | 306 capturer_->AddOrUpdateSink(&renderer_, wants); |
302 | 307 |
303 capturer_.UpdateAspectRatio(400, 200); | 308 capturer_->UpdateAspectRatio(400, 200); |
304 | 309 |
305 EXPECT_EQ(cricket::CS_RUNNING, | 310 EXPECT_EQ(cricket::CS_RUNNING, |
306 capturer_.Start(cricket::VideoFormat( | 311 capturer_->Start(cricket::VideoFormat( |
307 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), | 312 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |
308 cricket::FOURCC_I420))); | 313 cricket::FOURCC_I420))); |
309 EXPECT_TRUE(capturer_.IsRunning()); | 314 EXPECT_TRUE(capturer_->IsRunning()); |
310 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 315 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
311 | 316 |
312 int frame_count = 0; | 317 int frame_count = 0; |
313 capturer_.SetRotation(webrtc::kVideoRotation_90); | 318 capturer_->SetRotation(webrtc::kVideoRotation_90); |
314 EXPECT_TRUE(capturer_.CaptureFrame()); | 319 EXPECT_TRUE(capturer_->CaptureFrame()); |
315 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 320 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
316 EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); | 321 EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); |
317 | 322 |
318 // Add another sink that wants frames to be rotated. | 323 // Add another sink that wants frames to be rotated. |
319 cricket::FakeVideoRenderer renderer2; | 324 cricket::FakeVideoRenderer renderer2; |
320 wants.rotation_applied = true; | 325 wants.rotation_applied = true; |
321 capturer_.AddOrUpdateSink(&renderer2, wants); | 326 capturer_->AddOrUpdateSink(&renderer2, wants); |
322 | 327 |
323 EXPECT_TRUE(capturer_.CaptureFrame()); | 328 EXPECT_TRUE(capturer_->CaptureFrame()); |
324 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 329 EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
325 EXPECT_EQ(1, renderer2.num_rendered_frames()); | 330 EXPECT_EQ(1, renderer2.num_rendered_frames()); |
326 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); | 331 EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
327 EXPECT_EQ(webrtc::kVideoRotation_0, renderer2.rotation()); | 332 EXPECT_EQ(webrtc::kVideoRotation_0, renderer2.rotation()); |
328 } | 333 } |
329 | 334 |
330 TEST_F(VideoCapturerTest, ScreencastScaledSuperLarge) { | 335 TEST_F(VideoCapturerTest, ScreencastScaledSuperLarge) { |
331 capturer_.SetScreencast(true); | 336 InitScreencast(true); |
332 | 337 |
333 const int kMaxWidth = 4096; | 338 const int kMaxWidth = 4096; |
334 const int kMaxHeight = 3072; | 339 const int kMaxHeight = 3072; |
335 int kWidth = kMaxWidth + 4; | 340 int kWidth = kMaxWidth + 4; |
336 int kHeight = kMaxHeight + 4; | 341 int kHeight = kMaxHeight + 4; |
337 | 342 |
338 std::vector<cricket::VideoFormat> formats; | 343 std::vector<cricket::VideoFormat> formats; |
339 formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 344 formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
340 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); | 345 cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); |
341 capturer_.ResetSupportedFormats(formats); | 346 capturer_->ResetSupportedFormats(formats); |
342 | 347 |
343 EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 348 EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( |
344 kWidth, | 349 kWidth, |
345 kHeight, | 350 kHeight, |
346 cricket::VideoFormat::FpsToInterval(30), | 351 cricket::VideoFormat::FpsToInterval(30), |
347 cricket::FOURCC_ARGB))); | 352 cricket::FOURCC_ARGB))); |
348 EXPECT_TRUE(capturer_.IsRunning()); | 353 EXPECT_TRUE(capturer_->IsRunning()); |
349 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 354 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
350 EXPECT_TRUE(capturer_.CaptureFrame()); | 355 EXPECT_TRUE(capturer_->CaptureFrame()); |
351 EXPECT_EQ(1, renderer_.num_rendered_frames()); | 356 EXPECT_EQ(1, renderer_.num_rendered_frames()); |
352 EXPECT_EQ(kWidth / 2, renderer_.width()); | 357 EXPECT_EQ(kWidth / 2, renderer_.width()); |
353 EXPECT_EQ(kHeight / 2, renderer_.height()); | 358 EXPECT_EQ(kHeight / 2, renderer_.height()); |
354 } | 359 } |
355 | 360 |
356 TEST_F(VideoCapturerTest, TestFourccMatch) { | 361 TEST_F(VideoCapturerTest, TestFourccMatch) { |
357 cricket::VideoFormat desired(640, 480, | 362 cricket::VideoFormat desired(640, 480, |
358 cricket::VideoFormat::FpsToInterval(30), | 363 cricket::VideoFormat::FpsToInterval(30), |
359 cricket::FOURCC_ANY); | 364 cricket::FOURCC_ANY); |
360 cricket::VideoFormat best; | 365 cricket::VideoFormat best; |
361 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 366 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
362 EXPECT_EQ(640, best.width); | 367 EXPECT_EQ(640, best.width); |
363 EXPECT_EQ(480, best.height); | 368 EXPECT_EQ(480, best.height); |
364 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 369 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
365 | 370 |
366 desired.fourcc = cricket::FOURCC_MJPG; | 371 desired.fourcc = cricket::FOURCC_MJPG; |
367 EXPECT_FALSE(capturer_.GetBestCaptureFormat(desired, &best)); | 372 EXPECT_FALSE(capturer_->GetBestCaptureFormat(desired, &best)); |
368 | 373 |
369 desired.fourcc = cricket::FOURCC_I420; | 374 desired.fourcc = cricket::FOURCC_I420; |
370 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 375 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
371 } | 376 } |
372 | 377 |
373 TEST_F(VideoCapturerTest, TestResolutionMatch) { | 378 TEST_F(VideoCapturerTest, TestResolutionMatch) { |
374 cricket::VideoFormat desired(1920, 1080, | 379 cricket::VideoFormat desired(1920, 1080, |
375 cricket::VideoFormat::FpsToInterval(30), | 380 cricket::VideoFormat::FpsToInterval(30), |
376 cricket::FOURCC_ANY); | 381 cricket::FOURCC_ANY); |
377 cricket::VideoFormat best; | 382 cricket::VideoFormat best; |
378 // Ask for 1920x1080. Get HD 1280x720 which is the highest. | 383 // Ask for 1920x1080. Get HD 1280x720 which is the highest. |
379 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 384 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
380 EXPECT_EQ(1280, best.width); | 385 EXPECT_EQ(1280, best.width); |
381 EXPECT_EQ(720, best.height); | 386 EXPECT_EQ(720, best.height); |
382 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 387 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
383 | 388 |
384 desired.width = 360; | 389 desired.width = 360; |
385 desired.height = 250; | 390 desired.height = 250; |
386 // Ask for a little higher than QVGA. Get QVGA. | 391 // Ask for a little higher than QVGA. Get QVGA. |
387 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 392 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
388 EXPECT_EQ(320, best.width); | 393 EXPECT_EQ(320, best.width); |
389 EXPECT_EQ(240, best.height); | 394 EXPECT_EQ(240, best.height); |
390 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 395 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
391 | 396 |
392 desired.width = 480; | 397 desired.width = 480; |
393 desired.height = 270; | 398 desired.height = 270; |
394 // Ask for HVGA. Get VGA. | 399 // Ask for HVGA. Get VGA. |
395 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 400 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
396 EXPECT_EQ(640, best.width); | 401 EXPECT_EQ(640, best.width); |
397 EXPECT_EQ(480, best.height); | 402 EXPECT_EQ(480, best.height); |
398 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 403 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
399 | 404 |
400 desired.width = 320; | 405 desired.width = 320; |
401 desired.height = 240; | 406 desired.height = 240; |
402 // Ask for QVGA. Get QVGA. | 407 // Ask for QVGA. Get QVGA. |
403 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 408 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
404 EXPECT_EQ(320, best.width); | 409 EXPECT_EQ(320, best.width); |
405 EXPECT_EQ(240, best.height); | 410 EXPECT_EQ(240, best.height); |
406 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 411 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
407 | 412 |
408 desired.width = 80; | 413 desired.width = 80; |
409 desired.height = 60; | 414 desired.height = 60; |
410 // Ask for lower than QQVGA. Get QQVGA, which is the lowest. | 415 // Ask for lower than QQVGA. Get QQVGA, which is the lowest. |
411 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 416 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
412 EXPECT_EQ(160, best.width); | 417 EXPECT_EQ(160, best.width); |
413 EXPECT_EQ(120, best.height); | 418 EXPECT_EQ(120, best.height); |
414 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 419 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
415 } | 420 } |
416 | 421 |
417 TEST_F(VideoCapturerTest, TestHDResolutionMatch) { | 422 TEST_F(VideoCapturerTest, TestHDResolutionMatch) { |
418 // Add some HD formats typical of a mediocre HD webcam. | 423 // Add some HD formats typical of a mediocre HD webcam. |
419 std::vector<cricket::VideoFormat> formats; | 424 std::vector<cricket::VideoFormat> formats; |
420 formats.push_back(cricket::VideoFormat(320, 240, | 425 formats.push_back(cricket::VideoFormat(320, 240, |
421 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 426 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
422 formats.push_back(cricket::VideoFormat(640, 480, | 427 formats.push_back(cricket::VideoFormat(640, 480, |
423 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 428 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
424 formats.push_back(cricket::VideoFormat(960, 544, | 429 formats.push_back(cricket::VideoFormat(960, 544, |
425 cricket::VideoFormat::FpsToInterval(24), cricket::FOURCC_I420)); | 430 cricket::VideoFormat::FpsToInterval(24), cricket::FOURCC_I420)); |
426 formats.push_back(cricket::VideoFormat(1280, 720, | 431 formats.push_back(cricket::VideoFormat(1280, 720, |
427 cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); | 432 cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); |
428 formats.push_back(cricket::VideoFormat(2592, 1944, | 433 formats.push_back(cricket::VideoFormat(2592, 1944, |
429 cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); | 434 cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); |
430 capturer_.ResetSupportedFormats(formats); | 435 capturer_->ResetSupportedFormats(formats); |
431 | 436 |
432 cricket::VideoFormat desired(960, 720, | 437 cricket::VideoFormat desired(960, 720, |
433 cricket::VideoFormat::FpsToInterval(30), | 438 cricket::VideoFormat::FpsToInterval(30), |
434 cricket::FOURCC_ANY); | 439 cricket::FOURCC_ANY); |
435 cricket::VideoFormat best; | 440 cricket::VideoFormat best; |
436 // Ask for 960x720 30 fps. Get qHD 24 fps | 441 // Ask for 960x720 30 fps. Get qHD 24 fps |
437 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 442 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
438 EXPECT_EQ(960, best.width); | 443 EXPECT_EQ(960, best.width); |
439 EXPECT_EQ(544, best.height); | 444 EXPECT_EQ(544, best.height); |
440 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); | 445 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); |
441 | 446 |
442 desired.width = 960; | 447 desired.width = 960; |
443 desired.height = 544; | 448 desired.height = 544; |
444 desired.interval = cricket::VideoFormat::FpsToInterval(30); | 449 desired.interval = cricket::VideoFormat::FpsToInterval(30); |
445 // Ask for qHD 30 fps. Get qHD 24 fps | 450 // Ask for qHD 30 fps. Get qHD 24 fps |
446 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 451 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
447 EXPECT_EQ(960, best.width); | 452 EXPECT_EQ(960, best.width); |
448 EXPECT_EQ(544, best.height); | 453 EXPECT_EQ(544, best.height); |
449 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); | 454 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); |
450 | 455 |
451 desired.width = 360; | 456 desired.width = 360; |
452 desired.height = 250; | 457 desired.height = 250; |
453 desired.interval = cricket::VideoFormat::FpsToInterval(30); | 458 desired.interval = cricket::VideoFormat::FpsToInterval(30); |
454 // Ask for a little higher than QVGA. Get QVGA. | 459 // Ask for a little higher than QVGA. Get QVGA. |
455 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 460 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
456 EXPECT_EQ(320, best.width); | 461 EXPECT_EQ(320, best.width); |
457 EXPECT_EQ(240, best.height); | 462 EXPECT_EQ(240, best.height); |
458 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 463 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
459 | 464 |
460 desired.width = 480; | 465 desired.width = 480; |
461 desired.height = 270; | 466 desired.height = 270; |
462 // Ask for HVGA. Get VGA. | 467 // Ask for HVGA. Get VGA. |
463 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 468 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
464 EXPECT_EQ(640, best.width); | 469 EXPECT_EQ(640, best.width); |
465 EXPECT_EQ(480, best.height); | 470 EXPECT_EQ(480, best.height); |
466 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 471 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
467 | 472 |
468 desired.width = 320; | 473 desired.width = 320; |
469 desired.height = 240; | 474 desired.height = 240; |
470 // Ask for QVGA. Get QVGA. | 475 // Ask for QVGA. Get QVGA. |
471 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 476 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
472 EXPECT_EQ(320, best.width); | 477 EXPECT_EQ(320, best.width); |
473 EXPECT_EQ(240, best.height); | 478 EXPECT_EQ(240, best.height); |
474 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 479 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
475 | 480 |
476 desired.width = 160; | 481 desired.width = 160; |
477 desired.height = 120; | 482 desired.height = 120; |
478 // Ask for lower than QVGA. Get QVGA, which is the lowest. | 483 // Ask for lower than QVGA. Get QVGA, which is the lowest. |
479 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 484 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
480 EXPECT_EQ(320, best.width); | 485 EXPECT_EQ(320, best.width); |
481 EXPECT_EQ(240, best.height); | 486 EXPECT_EQ(240, best.height); |
482 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 487 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
483 | 488 |
484 desired.width = 1280; | 489 desired.width = 1280; |
485 desired.height = 720; | 490 desired.height = 720; |
486 // Ask for HD. 720p fps is too low. Get VGA which has 30 fps. | 491 // Ask for HD. 720p fps is too low. Get VGA which has 30 fps. |
487 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 492 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
488 EXPECT_EQ(640, best.width); | 493 EXPECT_EQ(640, best.width); |
489 EXPECT_EQ(480, best.height); | 494 EXPECT_EQ(480, best.height); |
490 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 495 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
491 | 496 |
492 desired.width = 1280; | 497 desired.width = 1280; |
493 desired.height = 720; | 498 desired.height = 720; |
494 desired.interval = cricket::VideoFormat::FpsToInterval(15); | 499 desired.interval = cricket::VideoFormat::FpsToInterval(15); |
495 // Ask for HD 15 fps. Fps matches. Get HD | 500 // Ask for HD 15 fps. Fps matches. Get HD |
496 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 501 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
497 EXPECT_EQ(1280, best.width); | 502 EXPECT_EQ(1280, best.width); |
498 EXPECT_EQ(720, best.height); | 503 EXPECT_EQ(720, best.height); |
499 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); | 504 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); |
500 | 505 |
501 desired.width = 1920; | 506 desired.width = 1920; |
502 desired.height = 1080; | 507 desired.height = 1080; |
503 desired.interval = cricket::VideoFormat::FpsToInterval(30); | 508 desired.interval = cricket::VideoFormat::FpsToInterval(30); |
504 // Ask for 1080p. Fps of HD formats is too low. Get VGA which can do 30 fps. | 509 // Ask for 1080p. Fps of HD formats is too low. Get VGA which can do 30 fps. |
505 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 510 EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); |
506 EXPECT_EQ(640, best.width); | 511 EXPECT_EQ(640, best.width); |
507 EXPECT_EQ(480, best.height); | 512 EXPECT_EQ(480, best.height); |
508 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 513 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
509 } | 514 } |
510 | 515 |
511 // Some cameras support 320x240 and 320x640. Verify we choose 320x240. | 516 // Some cameras support 320x240 and 320x640. Verify we choose 320x240. |
512 TEST_F(VideoCapturerTest, TestStrangeFormats) { | 517 TEST_F(VideoCapturerTest, TestStrangeFormats) { |
513 std::vector<cricket::VideoFormat> supported_formats; | 518 std::vector<cricket::VideoFormat> supported_formats; |
514 supported_formats.push_back(cricket::VideoFormat(320, 240, | 519 supported_formats.push_back(cricket::VideoFormat(320, 240, |
515 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 520 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
516 supported_formats.push_back(cricket::VideoFormat(320, 640, | 521 supported_formats.push_back(cricket::VideoFormat(320, 640, |
517 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 522 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
518 capturer_.ResetSupportedFormats(supported_formats); | 523 capturer_->ResetSupportedFormats(supported_formats); |
519 | 524 |
520 std::vector<cricket::VideoFormat> required_formats; | 525 std::vector<cricket::VideoFormat> required_formats; |
521 required_formats.push_back(cricket::VideoFormat(320, 240, | 526 required_formats.push_back(cricket::VideoFormat(320, 240, |
522 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 527 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
523 required_formats.push_back(cricket::VideoFormat(320, 200, | 528 required_formats.push_back(cricket::VideoFormat(320, 200, |
524 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 529 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
525 required_formats.push_back(cricket::VideoFormat(320, 180, | 530 required_formats.push_back(cricket::VideoFormat(320, 180, |
526 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 531 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
527 cricket::VideoFormat best; | 532 cricket::VideoFormat best; |
528 for (size_t i = 0; i < required_formats.size(); ++i) { | 533 for (size_t i = 0; i < required_formats.size(); ++i) { |
529 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 534 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
530 EXPECT_EQ(320, best.width); | 535 EXPECT_EQ(320, best.width); |
531 EXPECT_EQ(240, best.height); | 536 EXPECT_EQ(240, best.height); |
532 } | 537 } |
533 | 538 |
534 supported_formats.clear(); | 539 supported_formats.clear(); |
535 supported_formats.push_back(cricket::VideoFormat(320, 640, | 540 supported_formats.push_back(cricket::VideoFormat(320, 640, |
536 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 541 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
537 supported_formats.push_back(cricket::VideoFormat(320, 240, | 542 supported_formats.push_back(cricket::VideoFormat(320, 240, |
538 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 543 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
539 capturer_.ResetSupportedFormats(supported_formats); | 544 capturer_->ResetSupportedFormats(supported_formats); |
540 | 545 |
541 for (size_t i = 0; i < required_formats.size(); ++i) { | 546 for (size_t i = 0; i < required_formats.size(); ++i) { |
542 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 547 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
543 EXPECT_EQ(320, best.width); | 548 EXPECT_EQ(320, best.width); |
544 EXPECT_EQ(240, best.height); | 549 EXPECT_EQ(240, best.height); |
545 } | 550 } |
546 } | 551 } |
547 | 552 |
548 // Some cameras only have very low fps. Verify we choose something sensible. | 553 // Some cameras only have very low fps. Verify we choose something sensible. |
549 TEST_F(VideoCapturerTest, TestPoorFpsFormats) { | 554 TEST_F(VideoCapturerTest, TestPoorFpsFormats) { |
550 // all formats are low framerate | 555 // all formats are low framerate |
551 std::vector<cricket::VideoFormat> supported_formats; | 556 std::vector<cricket::VideoFormat> supported_formats; |
552 supported_formats.push_back(cricket::VideoFormat(320, 240, | 557 supported_formats.push_back(cricket::VideoFormat(320, 240, |
553 cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); | 558 cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); |
554 supported_formats.push_back(cricket::VideoFormat(640, 480, | 559 supported_formats.push_back(cricket::VideoFormat(640, 480, |
555 cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); | 560 cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); |
556 supported_formats.push_back(cricket::VideoFormat(1280, 720, | 561 supported_formats.push_back(cricket::VideoFormat(1280, 720, |
557 cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); | 562 cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); |
558 capturer_.ResetSupportedFormats(supported_formats); | 563 capturer_->ResetSupportedFormats(supported_formats); |
559 | 564 |
560 std::vector<cricket::VideoFormat> required_formats; | 565 std::vector<cricket::VideoFormat> required_formats; |
561 required_formats.push_back(cricket::VideoFormat(320, 240, | 566 required_formats.push_back(cricket::VideoFormat(320, 240, |
562 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 567 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
563 required_formats.push_back(cricket::VideoFormat(640, 480, | 568 required_formats.push_back(cricket::VideoFormat(640, 480, |
564 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 569 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
565 cricket::VideoFormat best; | 570 cricket::VideoFormat best; |
566 for (size_t i = 0; i < required_formats.size(); ++i) { | 571 for (size_t i = 0; i < required_formats.size(); ++i) { |
567 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 572 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
568 EXPECT_EQ(required_formats[i].width, best.width); | 573 EXPECT_EQ(required_formats[i].width, best.width); |
569 EXPECT_EQ(required_formats[i].height, best.height); | 574 EXPECT_EQ(required_formats[i].height, best.height); |
570 } | 575 } |
571 | 576 |
572 // Increase framerate of 320x240. Expect low fps VGA avoided. | 577 // Increase framerate of 320x240. Expect low fps VGA avoided. |
573 supported_formats.clear(); | 578 supported_formats.clear(); |
574 supported_formats.push_back(cricket::VideoFormat(320, 240, | 579 supported_formats.push_back(cricket::VideoFormat(320, 240, |
575 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 580 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
576 supported_formats.push_back(cricket::VideoFormat(640, 480, | 581 supported_formats.push_back(cricket::VideoFormat(640, 480, |
577 cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); | 582 cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); |
578 supported_formats.push_back(cricket::VideoFormat(1280, 720, | 583 supported_formats.push_back(cricket::VideoFormat(1280, 720, |
579 cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); | 584 cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); |
580 capturer_.ResetSupportedFormats(supported_formats); | 585 capturer_->ResetSupportedFormats(supported_formats); |
581 | 586 |
582 for (size_t i = 0; i < required_formats.size(); ++i) { | 587 for (size_t i = 0; i < required_formats.size(); ++i) { |
583 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 588 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
584 EXPECT_EQ(320, best.width); | 589 EXPECT_EQ(320, best.width); |
585 EXPECT_EQ(240, best.height); | 590 EXPECT_EQ(240, best.height); |
586 } | 591 } |
587 } | 592 } |
588 | 593 |
589 // Some cameras support same size with different frame rates. Verify we choose | 594 // Some cameras support same size with different frame rates. Verify we choose |
590 // the frame rate properly. | 595 // the frame rate properly. |
591 TEST_F(VideoCapturerTest, TestSameSizeDifferentFpsFormats) { | 596 TEST_F(VideoCapturerTest, TestSameSizeDifferentFpsFormats) { |
592 std::vector<cricket::VideoFormat> supported_formats; | 597 std::vector<cricket::VideoFormat> supported_formats; |
593 supported_formats.push_back(cricket::VideoFormat(320, 240, | 598 supported_formats.push_back(cricket::VideoFormat(320, 240, |
594 cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); | 599 cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); |
595 supported_formats.push_back(cricket::VideoFormat(320, 240, | 600 supported_formats.push_back(cricket::VideoFormat(320, 240, |
596 cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_I420)); | 601 cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_I420)); |
597 supported_formats.push_back(cricket::VideoFormat(320, 240, | 602 supported_formats.push_back(cricket::VideoFormat(320, 240, |
598 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 603 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
599 capturer_.ResetSupportedFormats(supported_formats); | 604 capturer_->ResetSupportedFormats(supported_formats); |
600 | 605 |
601 std::vector<cricket::VideoFormat> required_formats = supported_formats; | 606 std::vector<cricket::VideoFormat> required_formats = supported_formats; |
602 cricket::VideoFormat best; | 607 cricket::VideoFormat best; |
603 for (size_t i = 0; i < required_formats.size(); ++i) { | 608 for (size_t i = 0; i < required_formats.size(); ++i) { |
604 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 609 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
605 EXPECT_EQ(320, best.width); | 610 EXPECT_EQ(320, best.width); |
606 EXPECT_EQ(240, best.height); | 611 EXPECT_EQ(240, best.height); |
607 EXPECT_EQ(required_formats[i].interval, best.interval); | 612 EXPECT_EQ(required_formats[i].interval, best.interval); |
608 } | 613 } |
609 } | 614 } |
610 | 615 |
611 // Some cameras support the correct resolution but at a lower fps than | 616 // Some cameras support the correct resolution but at a lower fps than |
612 // we'd like. This tests we get the expected resolution and fps. | 617 // we'd like. This tests we get the expected resolution and fps. |
613 TEST_F(VideoCapturerTest, TestFpsFormats) { | 618 TEST_F(VideoCapturerTest, TestFpsFormats) { |
614 // We have VGA but low fps. Choose VGA, not HD | 619 // We have VGA but low fps. Choose VGA, not HD |
615 std::vector<cricket::VideoFormat> supported_formats; | 620 std::vector<cricket::VideoFormat> supported_formats; |
616 supported_formats.push_back(cricket::VideoFormat(1280, 720, | 621 supported_formats.push_back(cricket::VideoFormat(1280, 720, |
617 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 622 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
618 supported_formats.push_back(cricket::VideoFormat(640, 480, | 623 supported_formats.push_back(cricket::VideoFormat(640, 480, |
619 cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); | 624 cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); |
620 supported_formats.push_back(cricket::VideoFormat(640, 400, | 625 supported_formats.push_back(cricket::VideoFormat(640, 400, |
621 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 626 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
622 supported_formats.push_back(cricket::VideoFormat(640, 360, | 627 supported_formats.push_back(cricket::VideoFormat(640, 360, |
623 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 628 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
624 capturer_.ResetSupportedFormats(supported_formats); | 629 capturer_->ResetSupportedFormats(supported_formats); |
625 | 630 |
626 std::vector<cricket::VideoFormat> required_formats; | 631 std::vector<cricket::VideoFormat> required_formats; |
627 required_formats.push_back(cricket::VideoFormat(640, 480, | 632 required_formats.push_back(cricket::VideoFormat(640, 480, |
628 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY)); | 633 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY)); |
629 required_formats.push_back(cricket::VideoFormat(640, 480, | 634 required_formats.push_back(cricket::VideoFormat(640, 480, |
630 cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_ANY)); | 635 cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_ANY)); |
631 required_formats.push_back(cricket::VideoFormat(640, 480, | 636 required_formats.push_back(cricket::VideoFormat(640, 480, |
632 cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_ANY)); | 637 cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_ANY)); |
633 cricket::VideoFormat best; | 638 cricket::VideoFormat best; |
634 | 639 |
635 // Expect 30 fps to choose 30 fps format. | 640 // Expect 30 fps to choose 30 fps format. |
636 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[0], &best)); | 641 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[0], &best)); |
637 EXPECT_EQ(640, best.width); | 642 EXPECT_EQ(640, best.width); |
638 EXPECT_EQ(400, best.height); | 643 EXPECT_EQ(400, best.height); |
639 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 644 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
640 | 645 |
641 // Expect 20 fps to choose 30 fps format. | 646 // Expect 20 fps to choose 30 fps format. |
642 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[1], &best)); | 647 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[1], &best)); |
643 EXPECT_EQ(640, best.width); | 648 EXPECT_EQ(640, best.width); |
644 EXPECT_EQ(400, best.height); | 649 EXPECT_EQ(400, best.height); |
645 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); | 650 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
646 | 651 |
647 // Expect 10 fps to choose 15 fps format and set fps to 15. | 652 // Expect 10 fps to choose 15 fps format and set fps to 15. |
648 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best)); | 653 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[2], &best)); |
649 EXPECT_EQ(640, best.width); | 654 EXPECT_EQ(640, best.width); |
650 EXPECT_EQ(480, best.height); | 655 EXPECT_EQ(480, best.height); |
651 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); | 656 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); |
652 | 657 |
653 // We have VGA 60 fps and 15 fps. Choose best fps. | 658 // We have VGA 60 fps and 15 fps. Choose best fps. |
654 supported_formats.clear(); | 659 supported_formats.clear(); |
655 supported_formats.push_back(cricket::VideoFormat(1280, 720, | 660 supported_formats.push_back(cricket::VideoFormat(1280, 720, |
656 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 661 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
657 supported_formats.push_back(cricket::VideoFormat(640, 480, | 662 supported_formats.push_back(cricket::VideoFormat(640, 480, |
658 cricket::VideoFormat::FpsToInterval(60), cricket::FOURCC_MJPG)); | 663 cricket::VideoFormat::FpsToInterval(60), cricket::FOURCC_MJPG)); |
659 supported_formats.push_back(cricket::VideoFormat(640, 480, | 664 supported_formats.push_back(cricket::VideoFormat(640, 480, |
660 cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); | 665 cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); |
661 supported_formats.push_back(cricket::VideoFormat(640, 400, | 666 supported_formats.push_back(cricket::VideoFormat(640, 400, |
662 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 667 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
663 supported_formats.push_back(cricket::VideoFormat(640, 360, | 668 supported_formats.push_back(cricket::VideoFormat(640, 360, |
664 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 669 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
665 capturer_.ResetSupportedFormats(supported_formats); | 670 capturer_->ResetSupportedFormats(supported_formats); |
666 | 671 |
667 // Expect 30 fps to choose 60 fps format and will set best fps to 60. | 672 // Expect 30 fps to choose 60 fps format and will set best fps to 60. |
668 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[0], &best)); | 673 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[0], &best)); |
669 EXPECT_EQ(640, best.width); | 674 EXPECT_EQ(640, best.width); |
670 EXPECT_EQ(480, best.height); | 675 EXPECT_EQ(480, best.height); |
671 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); | 676 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); |
672 | 677 |
673 // Expect 20 fps to choose 60 fps format, and will set best fps to 60. | 678 // Expect 20 fps to choose 60 fps format, and will set best fps to 60. |
674 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[1], &best)); | 679 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[1], &best)); |
675 EXPECT_EQ(640, best.width); | 680 EXPECT_EQ(640, best.width); |
676 EXPECT_EQ(480, best.height); | 681 EXPECT_EQ(480, best.height); |
677 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); | 682 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); |
678 | 683 |
679 // Expect 10 fps to choose 15 fps. | 684 // Expect 10 fps to choose 15 fps. |
680 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best)); | 685 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[2], &best)); |
681 EXPECT_EQ(640, best.width); | 686 EXPECT_EQ(640, best.width); |
682 EXPECT_EQ(480, best.height); | 687 EXPECT_EQ(480, best.height); |
683 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); | 688 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); |
684 } | 689 } |
685 | 690 |
686 TEST_F(VideoCapturerTest, TestRequest16x10_9) { | 691 TEST_F(VideoCapturerTest, TestRequest16x10_9) { |
687 std::vector<cricket::VideoFormat> supported_formats; | 692 std::vector<cricket::VideoFormat> supported_formats; |
688 // We do not support HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. | 693 // We do not support HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. |
689 supported_formats.push_back(cricket::VideoFormat(640, 480, | 694 supported_formats.push_back(cricket::VideoFormat(640, 480, |
690 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 695 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
691 supported_formats.push_back(cricket::VideoFormat(640, 400, | 696 supported_formats.push_back(cricket::VideoFormat(640, 400, |
692 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 697 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
693 supported_formats.push_back(cricket::VideoFormat(640, 360, | 698 supported_formats.push_back(cricket::VideoFormat(640, 360, |
694 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 699 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
695 capturer_.ResetSupportedFormats(supported_formats); | 700 capturer_->ResetSupportedFormats(supported_formats); |
696 | 701 |
697 std::vector<cricket::VideoFormat> required_formats = supported_formats; | 702 std::vector<cricket::VideoFormat> required_formats = supported_formats; |
698 cricket::VideoFormat best; | 703 cricket::VideoFormat best; |
699 // Expect 4x3, 16x10, and 16x9 requests are respected. | 704 // Expect 4x3, 16x10, and 16x9 requests are respected. |
700 for (size_t i = 0; i < required_formats.size(); ++i) { | 705 for (size_t i = 0; i < required_formats.size(); ++i) { |
701 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 706 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
702 EXPECT_EQ(required_formats[i].width, best.width); | 707 EXPECT_EQ(required_formats[i].width, best.width); |
703 EXPECT_EQ(required_formats[i].height, best.height); | 708 EXPECT_EQ(required_formats[i].height, best.height); |
704 } | 709 } |
705 | 710 |
706 // We do not support 16x9 HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. | 711 // We do not support 16x9 HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. |
707 supported_formats.clear(); | 712 supported_formats.clear(); |
708 supported_formats.push_back(cricket::VideoFormat(960, 720, | 713 supported_formats.push_back(cricket::VideoFormat(960, 720, |
709 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 714 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
710 supported_formats.push_back(cricket::VideoFormat(640, 480, | 715 supported_formats.push_back(cricket::VideoFormat(640, 480, |
711 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 716 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
712 supported_formats.push_back(cricket::VideoFormat(640, 400, | 717 supported_formats.push_back(cricket::VideoFormat(640, 400, |
713 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 718 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
714 supported_formats.push_back(cricket::VideoFormat(640, 360, | 719 supported_formats.push_back(cricket::VideoFormat(640, 360, |
715 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 720 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
716 capturer_.ResetSupportedFormats(supported_formats); | 721 capturer_->ResetSupportedFormats(supported_formats); |
717 | 722 |
718 // Expect 4x3, 16x10, and 16x9 requests are respected. | 723 // Expect 4x3, 16x10, and 16x9 requests are respected. |
719 for (size_t i = 0; i < required_formats.size(); ++i) { | 724 for (size_t i = 0; i < required_formats.size(); ++i) { |
720 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 725 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
721 EXPECT_EQ(required_formats[i].width, best.width); | 726 EXPECT_EQ(required_formats[i].width, best.width); |
722 EXPECT_EQ(required_formats[i].height, best.height); | 727 EXPECT_EQ(required_formats[i].height, best.height); |
723 } | 728 } |
724 | 729 |
725 // We support 16x9HD, Expect 4x3, 16x10, and 16x9 requests are respected. | 730 // We support 16x9HD, Expect 4x3, 16x10, and 16x9 requests are respected. |
726 supported_formats.clear(); | 731 supported_formats.clear(); |
727 supported_formats.push_back(cricket::VideoFormat(1280, 720, | 732 supported_formats.push_back(cricket::VideoFormat(1280, 720, |
728 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 733 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
729 supported_formats.push_back(cricket::VideoFormat(640, 480, | 734 supported_formats.push_back(cricket::VideoFormat(640, 480, |
730 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 735 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
731 supported_formats.push_back(cricket::VideoFormat(640, 400, | 736 supported_formats.push_back(cricket::VideoFormat(640, 400, |
732 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 737 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
733 supported_formats.push_back(cricket::VideoFormat(640, 360, | 738 supported_formats.push_back(cricket::VideoFormat(640, 360, |
734 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 739 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
735 capturer_.ResetSupportedFormats(supported_formats); | 740 capturer_->ResetSupportedFormats(supported_formats); |
736 | 741 |
737 // Expect 4x3 for 4x3 and 16x10 requests. | 742 // Expect 4x3 for 4x3 and 16x10 requests. |
738 for (size_t i = 0; i < required_formats.size() - 1; ++i) { | 743 for (size_t i = 0; i < required_formats.size() - 1; ++i) { |
739 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); | 744 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); |
740 EXPECT_EQ(required_formats[i].width, best.width); | 745 EXPECT_EQ(required_formats[i].width, best.width); |
741 EXPECT_EQ(required_formats[i].height, best.height); | 746 EXPECT_EQ(required_formats[i].height, best.height); |
742 } | 747 } |
743 | 748 |
744 // Expect 16x9 for 16x9 request. | 749 // Expect 16x9 for 16x9 request. |
745 EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best)); | 750 EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[2], &best)); |
746 EXPECT_EQ(640, best.width); | 751 EXPECT_EQ(640, best.width); |
747 EXPECT_EQ(360, best.height); | 752 EXPECT_EQ(360, best.height); |
748 } | 753 } |
749 | 754 |
750 bool HdFormatInList(const std::vector<cricket::VideoFormat>& formats) { | 755 bool HdFormatInList(const std::vector<cricket::VideoFormat>& formats) { |
751 for (std::vector<cricket::VideoFormat>::const_iterator found = | 756 for (std::vector<cricket::VideoFormat>::const_iterator found = |
752 formats.begin(); found != formats.end(); ++found) { | 757 formats.begin(); found != formats.end(); ++found) { |
753 if (found->height >= kMinHdHeight) { | 758 if (found->height >= kMinHdHeight) { |
754 return true; | 759 return true; |
755 } | 760 } |
756 } | 761 } |
757 return false; | 762 return false; |
758 } | 763 } |
759 | 764 |
760 TEST_F(VideoCapturerTest, Whitelist) { | 765 TEST_F(VideoCapturerTest, Whitelist) { |
761 // The definition of HD only applies to the height. Set the HD width to the | 766 // The definition of HD only applies to the height. Set the HD width to the |
762 // smallest legal number to document this fact in this test. | 767 // smallest legal number to document this fact in this test. |
763 const int kMinHdWidth = 1; | 768 const int kMinHdWidth = 1; |
764 cricket::VideoFormat hd_format(kMinHdWidth, | 769 cricket::VideoFormat hd_format(kMinHdWidth, |
765 kMinHdHeight, | 770 kMinHdHeight, |
766 cricket::VideoFormat::FpsToInterval(30), | 771 cricket::VideoFormat::FpsToInterval(30), |
767 cricket::FOURCC_I420); | 772 cricket::FOURCC_I420); |
768 cricket::VideoFormat vga_format(640, 480, | 773 cricket::VideoFormat vga_format(640, 480, |
769 cricket::VideoFormat::FpsToInterval(30), | 774 cricket::VideoFormat::FpsToInterval(30), |
770 cricket::FOURCC_I420); | 775 cricket::FOURCC_I420); |
771 std::vector<cricket::VideoFormat> formats = *capturer_.GetSupportedFormats(); | 776 std::vector<cricket::VideoFormat> formats = *capturer_->GetSupportedFormats(); |
772 formats.push_back(hd_format); | 777 formats.push_back(hd_format); |
773 | 778 |
774 // Enable whitelist. Expect HD not in list. | 779 // Enable whitelist. Expect HD not in list. |
775 capturer_.set_enable_camera_list(true); | 780 capturer_->set_enable_camera_list(true); |
776 capturer_.ResetSupportedFormats(formats); | 781 capturer_->ResetSupportedFormats(formats); |
777 EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats())); | 782 EXPECT_TRUE(HdFormatInList(*capturer_->GetSupportedFormats())); |
778 capturer_.ConstrainSupportedFormats(vga_format); | 783 capturer_->ConstrainSupportedFormats(vga_format); |
779 EXPECT_FALSE(HdFormatInList(*capturer_.GetSupportedFormats())); | 784 EXPECT_FALSE(HdFormatInList(*capturer_->GetSupportedFormats())); |
780 | 785 |
781 // Disable whitelist. Expect HD in list. | 786 // Disable whitelist. Expect HD in list. |
782 capturer_.set_enable_camera_list(false); | 787 capturer_->set_enable_camera_list(false); |
783 capturer_.ResetSupportedFormats(formats); | 788 capturer_->ResetSupportedFormats(formats); |
784 EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats())); | 789 EXPECT_TRUE(HdFormatInList(*capturer_->GetSupportedFormats())); |
785 capturer_.ConstrainSupportedFormats(vga_format); | 790 capturer_->ConstrainSupportedFormats(vga_format); |
786 EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats())); | 791 EXPECT_TRUE(HdFormatInList(*capturer_->GetSupportedFormats())); |
787 } | 792 } |
788 | 793 |
789 TEST_F(VideoCapturerTest, BlacklistAllFormats) { | 794 TEST_F(VideoCapturerTest, BlacklistAllFormats) { |
790 cricket::VideoFormat vga_format(640, 480, | 795 cricket::VideoFormat vga_format(640, 480, |
791 cricket::VideoFormat::FpsToInterval(30), | 796 cricket::VideoFormat::FpsToInterval(30), |
792 cricket::FOURCC_I420); | 797 cricket::FOURCC_I420); |
793 std::vector<cricket::VideoFormat> supported_formats; | 798 std::vector<cricket::VideoFormat> supported_formats; |
794 // Mock a device that only supports HD formats. | 799 // Mock a device that only supports HD formats. |
795 supported_formats.push_back(cricket::VideoFormat(1280, 720, | 800 supported_formats.push_back(cricket::VideoFormat(1280, 720, |
796 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 801 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
797 supported_formats.push_back(cricket::VideoFormat(1920, 1080, | 802 supported_formats.push_back(cricket::VideoFormat(1920, 1080, |
798 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 803 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
799 capturer_.ResetSupportedFormats(supported_formats); | 804 capturer_->ResetSupportedFormats(supported_formats); |
800 EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); | 805 EXPECT_EQ(2u, capturer_->GetSupportedFormats()->size()); |
801 // Now, enable the list, which would exclude both formats. However, since | 806 // Now, enable the list, which would exclude both formats. However, since |
802 // only HD formats are available, we refuse to filter at all, so we don't | 807 // only HD formats are available, we refuse to filter at all, so we don't |
803 // break this camera. | 808 // break this camera. |
804 capturer_.set_enable_camera_list(true); | 809 capturer_->set_enable_camera_list(true); |
805 capturer_.ConstrainSupportedFormats(vga_format); | 810 capturer_->ConstrainSupportedFormats(vga_format); |
806 EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); | 811 EXPECT_EQ(2u, capturer_->GetSupportedFormats()->size()); |
807 // To make sure it's not just the camera list being broken, add in VGA and | 812 // 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. | 813 // try again. This time, only the VGA format should be there. |
809 supported_formats.push_back(vga_format); | 814 supported_formats.push_back(vga_format); |
810 capturer_.ResetSupportedFormats(supported_formats); | 815 capturer_->ResetSupportedFormats(supported_formats); |
811 ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size()); | 816 ASSERT_EQ(1u, capturer_->GetSupportedFormats()->size()); |
812 EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height); | 817 EXPECT_EQ(vga_format.height, capturer_->GetSupportedFormats()->at(0).height); |
813 } | 818 } |
OLD | NEW |