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