| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 10 matching lines...) Expand all Loading... |
| 21 #include "webrtc/media/base/testutils.h" | 21 #include "webrtc/media/base/testutils.h" |
| 22 #include "webrtc/media/base/videoadapter.h" | 22 #include "webrtc/media/base/videoadapter.h" |
| 23 | 23 |
| 24 namespace cricket { | 24 namespace cricket { |
| 25 | 25 |
| 26 class VideoAdapterTest : public testing::Test { | 26 class VideoAdapterTest : public testing::Test { |
| 27 public: | 27 public: |
| 28 virtual void SetUp() { | 28 virtual void SetUp() { |
| 29 capturer_.reset(new FakeVideoCapturer); | 29 capturer_.reset(new FakeVideoCapturer); |
| 30 capture_format_ = capturer_->GetSupportedFormats()->at(0); | 30 capture_format_ = capturer_->GetSupportedFormats()->at(0); |
| 31 capture_format_.interval = VideoFormat::FpsToInterval(50); | 31 capture_format_.interval = VideoFormat::FpsToInterval(30); |
| 32 adapter_.SetExpectedInputFrameInterval(capture_format_.interval); | |
| 33 | 32 |
| 34 listener_.reset(new VideoCapturerListener(&adapter_)); | 33 listener_.reset(new VideoCapturerListener(&adapter_)); |
| 35 capturer_->SignalFrameCaptured.connect( | 34 capturer_->SignalFrameCaptured.connect( |
| 36 listener_.get(), &VideoCapturerListener::OnFrameCaptured); | 35 listener_.get(), &VideoCapturerListener::OnFrameCaptured); |
| 37 } | 36 } |
| 38 | 37 |
| 39 virtual void TearDown() { | 38 virtual void TearDown() { |
| 40 // Explicitly disconnect the VideoCapturer before to avoid data races | 39 // Explicitly disconnect the VideoCapturer before to avoid data races |
| 41 // (frames delivered to VideoCapturerListener while it's being destructed). | 40 // (frames delivered to VideoCapturerListener while it's being destructed). |
| 42 capturer_->SignalFrameCaptured.disconnect_all(); | 41 capturer_->SignalFrameCaptured.disconnect_all(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 66 void OnFrameCaptured(VideoCapturer* capturer, | 65 void OnFrameCaptured(VideoCapturer* capturer, |
| 67 const CapturedFrame* captured_frame) { | 66 const CapturedFrame* captured_frame) { |
| 68 rtc::CritScope lock(&crit_); | 67 rtc::CritScope lock(&crit_); |
| 69 const int in_width = captured_frame->width; | 68 const int in_width = captured_frame->width; |
| 70 const int in_height = abs(captured_frame->height); | 69 const int in_height = abs(captured_frame->height); |
| 71 int cropped_width; | 70 int cropped_width; |
| 72 int cropped_height; | 71 int cropped_height; |
| 73 int out_width; | 72 int out_width; |
| 74 int out_height; | 73 int out_height; |
| 75 video_adapter_->AdaptFrameResolution(in_width, in_height, | 74 video_adapter_->AdaptFrameResolution(in_width, in_height, |
| 75 captured_frame->time_stamp, |
| 76 &cropped_width, &cropped_height, | 76 &cropped_width, &cropped_height, |
| 77 &out_width, &out_height); | 77 &out_width, &out_height); |
| 78 if (out_width != 0 && out_height != 0) { | 78 if (out_width != 0 && out_height != 0) { |
| 79 cropped_width_ = cropped_width; | 79 cropped_width_ = cropped_width; |
| 80 cropped_height_ = cropped_height; | 80 cropped_height_ = cropped_height; |
| 81 out_width_ = out_width; | 81 out_width_ = out_width; |
| 82 out_height_ = out_height; | 82 out_height_ = out_height; |
| 83 last_adapt_was_no_op_ = | 83 last_adapt_was_no_op_ = |
| 84 (in_width == cropped_width && in_height == cropped_height && | 84 (in_width == cropped_width && in_height == cropped_height && |
| 85 in_width == out_width && in_height == out_height); | 85 in_width == out_width && in_height == out_height); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // Verify no crash and that frames aren't dropped. | 163 // Verify no crash and that frames aren't dropped. |
| 164 VideoCapturerListener::Stats stats = listener_->GetStats(); | 164 VideoCapturerListener::Stats stats = listener_->GetStats(); |
| 165 EXPECT_GE(stats.captured_frames, 10); | 165 EXPECT_GE(stats.captured_frames, 10); |
| 166 EXPECT_EQ(0, stats.dropped_frames); | 166 EXPECT_EQ(0, stats.dropped_frames); |
| 167 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, | 167 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, |
| 168 capture_format_.width, capture_format_.height); | 168 capture_format_.width, capture_format_.height); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Adapt the frame rate to be half of the capture rate at the beginning. Expect | 171 // Adapt the frame rate to be half of the capture rate at the beginning. Expect |
| 172 // the number of dropped frames to be half of the number the captured frames. | 172 // the number of dropped frames to be half of the number the captured frames. |
| 173 TEST_F(VideoAdapterTest, AdaptFramerate) { | 173 TEST_F(VideoAdapterTest, AdaptFramerateToHalf) { |
| 174 VideoFormat request_format = capture_format_; | 174 VideoFormat request_format = capture_format_; |
| 175 request_format.interval *= 2; | 175 request_format.interval *= 2; |
| 176 adapter_.OnOutputFormatRequest(request_format); | 176 adapter_.OnOutputFormatRequest(request_format); |
| 177 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 177 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 178 |
| 179 // Capture 5 frames and verify that every other frame is dropped. The first |
| 180 // frame should not be dropped. |
| 181 capturer_->CaptureFrame(); |
| 182 EXPECT_GE(listener_->GetStats().captured_frames, 1); |
| 183 EXPECT_EQ(0, listener_->GetStats().dropped_frames); |
| 184 |
| 185 capturer_->CaptureFrame(); |
| 186 EXPECT_GE(listener_->GetStats().captured_frames, 2); |
| 187 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
| 188 |
| 189 capturer_->CaptureFrame(); |
| 190 EXPECT_GE(listener_->GetStats().captured_frames, 3); |
| 191 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
| 192 |
| 193 capturer_->CaptureFrame(); |
| 194 EXPECT_GE(listener_->GetStats().captured_frames, 4); |
| 195 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
| 196 |
| 197 capturer_->CaptureFrame(); |
| 198 EXPECT_GE(listener_->GetStats().captured_frames, 5); |
| 199 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
| 200 } |
| 201 |
| 202 // Adapt the frame rate to be two thirds of the capture rate at the beginning. |
| 203 // Expect the number of dropped frames to be one thirds of the number the |
| 204 // captured frames. |
| 205 TEST_F(VideoAdapterTest, AdaptFramerateToTwoThirds) { |
| 206 VideoFormat request_format = capture_format_; |
| 207 request_format.interval = request_format.interval * 3 / 2; |
| 208 adapter_.OnOutputFormatRequest(request_format); |
| 209 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 210 |
| 211 // Capture 8 frames and verify that every third frame is dropped. The first |
| 212 // frame should not be dropped. |
| 213 capturer_->CaptureFrame(); |
| 214 EXPECT_GE(listener_->GetStats().captured_frames, 1); |
| 215 EXPECT_EQ(0, listener_->GetStats().dropped_frames); |
| 216 |
| 217 capturer_->CaptureFrame(); |
| 218 EXPECT_GE(listener_->GetStats().captured_frames, 2); |
| 219 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
| 220 |
| 221 capturer_->CaptureFrame(); |
| 222 EXPECT_GE(listener_->GetStats().captured_frames, 3); |
| 223 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
| 224 |
| 225 capturer_->CaptureFrame(); |
| 226 EXPECT_GE(listener_->GetStats().captured_frames, 4); |
| 227 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
| 228 |
| 229 capturer_->CaptureFrame(); |
| 230 EXPECT_GE(listener_->GetStats().captured_frames, 5); |
| 231 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
| 232 |
| 233 capturer_->CaptureFrame(); |
| 234 EXPECT_GE(listener_->GetStats().captured_frames, 6); |
| 235 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
| 236 |
| 237 capturer_->CaptureFrame(); |
| 238 EXPECT_GE(listener_->GetStats().captured_frames, 7); |
| 239 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
| 240 |
| 241 capturer_->CaptureFrame(); |
| 242 EXPECT_GE(listener_->GetStats().captured_frames, 8); |
| 243 EXPECT_EQ(3, listener_->GetStats().dropped_frames); |
| 244 } |
| 245 |
| 246 // Request frame rate twice as high as captured frame rate. Expect no frame |
| 247 // drop. |
| 248 TEST_F(VideoAdapterTest, AdaptFramerateHighLimit) { |
| 249 VideoFormat request_format = capture_format_; |
| 250 request_format.interval /= 2; |
| 251 adapter_.OnOutputFormatRequest(request_format); |
| 252 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 178 for (int i = 0; i < 10; ++i) | 253 for (int i = 0; i < 10; ++i) |
| 179 capturer_->CaptureFrame(); | 254 capturer_->CaptureFrame(); |
| 180 | 255 |
| 181 // Verify frame drop and no resolution change. | 256 // Verify no frame drop. |
| 182 VideoCapturerListener::Stats stats = listener_->GetStats(); | 257 EXPECT_EQ(0, listener_->GetStats().dropped_frames); |
| 183 EXPECT_GE(stats.captured_frames, 10); | |
| 184 EXPECT_EQ(stats.captured_frames / 2, stats.dropped_frames); | |
| 185 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, | |
| 186 capture_format_.width, capture_format_.height); | |
| 187 } | 258 } |
| 188 | 259 |
| 189 // Adapt the frame rate to be half of the capture rate at the beginning. Expect | 260 // Adapt three frames where the timestamp of the second frame is incorrectly |
| 190 // the number of dropped frames to be half of the number the captured frames. | 261 // less than the first timestamp. Expect that the adapter is conservative and |
| 191 TEST_F(VideoAdapterTest, AdaptFramerateVariable) { | 262 // does not drop any frame. |
| 192 VideoFormat request_format = capture_format_; | 263 TEST_F(VideoAdapterTest, AdaptFramerateTimestampOutOfOrder) { |
| 193 request_format.interval = request_format.interval * 3 / 2; | 264 const int64_t capture_interval = VideoFormat::FpsToInterval(30); |
| 194 adapter_.OnOutputFormatRequest(request_format); | 265 adapter_.OnOutputFormatRequest( |
| 195 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 266 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY)); |
| 196 for (int i = 0; i < 30; ++i) | |
| 197 capturer_->CaptureFrame(); | |
| 198 | 267 |
| 199 // Verify frame drop and no resolution change. | 268 const int64_t first_timestamp = capture_interval; |
| 200 VideoCapturerListener::Stats stats = listener_->GetStats(); | 269 adapter_.AdaptFrameResolution(640, 480, first_timestamp, |
| 201 EXPECT_GE(stats.captured_frames, 30); | 270 &cropped_width_, &cropped_height_, |
| 202 // Verify 2 / 3 kept (20) and 1 / 3 dropped (10). | 271 &out_width_, &out_height_); |
| 203 EXPECT_EQ(stats.captured_frames * 1 / 3, stats.dropped_frames); | 272 EXPECT_GT(out_width_, 0); |
| 204 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, | 273 EXPECT_GT(out_height_, 0); |
| 205 capture_format_.width, capture_format_.height); | 274 |
| 275 const int64_t second_timestamp = 0; |
| 276 adapter_.AdaptFrameResolution(640, 480, second_timestamp, |
| 277 &cropped_width_, &cropped_height_, |
| 278 &out_width_, &out_height_); |
| 279 EXPECT_GT(out_width_, 0); |
| 280 EXPECT_GT(out_height_, 0); |
| 281 |
| 282 const int64_t third_timestamp = capture_interval; |
| 283 adapter_.AdaptFrameResolution(640, 480, third_timestamp, |
| 284 &cropped_width_, &cropped_height_, |
| 285 &out_width_, &out_height_); |
| 286 EXPECT_GT(out_width_, 0); |
| 287 EXPECT_GT(out_height_, 0); |
| 206 } | 288 } |
| 207 | 289 |
| 208 // Adapt the frame rate to be half of the capture rate after capturing no less | 290 // Adapt the frame rate to be half of the capture rate after capturing no less |
| 209 // than 10 frames. Expect no frame dropped before adaptation and frame dropped | 291 // than 10 frames. Expect no frame dropped before adaptation and frame dropped |
| 210 // after adaptation. | 292 // after adaptation. |
| 211 TEST_F(VideoAdapterTest, AdaptFramerateOntheFly) { | 293 TEST_F(VideoAdapterTest, AdaptFramerateOntheFly) { |
| 212 VideoFormat request_format = capture_format_; | 294 VideoFormat request_format = capture_format_; |
| 213 adapter_.OnOutputFormatRequest(request_format); | 295 adapter_.OnOutputFormatRequest(request_format); |
| 214 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 296 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 215 for (int i = 0; i < 10; ++i) | 297 for (int i = 0; i < 10; ++i) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 230 } | 312 } |
| 231 | 313 |
| 232 // Set a very high output pixel resolution. Expect no cropping or resolution | 314 // Set a very high output pixel resolution. Expect no cropping or resolution |
| 233 // change. | 315 // change. |
| 234 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { | 316 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { |
| 235 VideoFormat output_format = capture_format_; | 317 VideoFormat output_format = capture_format_; |
| 236 output_format.width *= 10; | 318 output_format.width *= 10; |
| 237 output_format.height *= 10; | 319 output_format.height *= 10; |
| 238 adapter_.OnOutputFormatRequest(output_format); | 320 adapter_.OnOutputFormatRequest(output_format); |
| 239 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 321 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, |
| 240 &cropped_width_, &cropped_height_, | 322 0, &cropped_width_, &cropped_height_, |
| 241 &out_width_, &out_height_); | 323 &out_width_, &out_height_); |
| 242 EXPECT_EQ(capture_format_.width, cropped_width_); | 324 EXPECT_EQ(capture_format_.width, cropped_width_); |
| 243 EXPECT_EQ(capture_format_.height, cropped_height_); | 325 EXPECT_EQ(capture_format_.height, cropped_height_); |
| 244 EXPECT_EQ(capture_format_.width, out_width_); | 326 EXPECT_EQ(capture_format_.width, out_width_); |
| 245 EXPECT_EQ(capture_format_.height, out_height_); | 327 EXPECT_EQ(capture_format_.height, out_height_); |
| 246 } | 328 } |
| 247 | 329 |
| 248 // Adapt the frame resolution to be the same as capture resolution. Expect no | 330 // Adapt the frame resolution to be the same as capture resolution. Expect no |
| 249 // cropping or resolution change. | 331 // cropping or resolution change. |
| 250 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) { | 332 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) { |
| 251 adapter_.OnOutputFormatRequest(capture_format_); | 333 adapter_.OnOutputFormatRequest(capture_format_); |
| 252 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 334 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, |
| 253 &cropped_width_, &cropped_height_, | 335 0, &cropped_width_, &cropped_height_, |
| 254 &out_width_, &out_height_); | 336 &out_width_, &out_height_); |
| 255 EXPECT_EQ(capture_format_.width, cropped_width_); | 337 EXPECT_EQ(capture_format_.width, cropped_width_); |
| 256 EXPECT_EQ(capture_format_.height, cropped_height_); | 338 EXPECT_EQ(capture_format_.height, cropped_height_); |
| 257 EXPECT_EQ(capture_format_.width, out_width_); | 339 EXPECT_EQ(capture_format_.width, out_width_); |
| 258 EXPECT_EQ(capture_format_.height, out_height_); | 340 EXPECT_EQ(capture_format_.height, out_height_); |
| 259 } | 341 } |
| 260 | 342 |
| 261 // Adapt the frame resolution to be a quarter of the capture resolution. Expect | 343 // Adapt the frame resolution to be a quarter of the capture resolution. Expect |
| 262 // no cropping, but a resolution change. | 344 // no cropping, but a resolution change. |
| 263 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) { | 345 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) { |
| 264 VideoFormat request_format = capture_format_; | 346 VideoFormat request_format = capture_format_; |
| 265 request_format.width /= 2; | 347 request_format.width /= 2; |
| 266 request_format.height /= 2; | 348 request_format.height /= 2; |
| 267 adapter_.OnOutputFormatRequest(request_format); | 349 adapter_.OnOutputFormatRequest(request_format); |
| 268 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 350 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, |
| 269 &cropped_width_, &cropped_height_, | 351 0, &cropped_width_, &cropped_height_, |
| 270 &out_width_, &out_height_); | 352 &out_width_, &out_height_); |
| 271 EXPECT_EQ(capture_format_.width, cropped_width_); | 353 EXPECT_EQ(capture_format_.width, cropped_width_); |
| 272 EXPECT_EQ(capture_format_.height, cropped_height_); | 354 EXPECT_EQ(capture_format_.height, cropped_height_); |
| 273 EXPECT_EQ(request_format.width, out_width_); | 355 EXPECT_EQ(request_format.width, out_width_); |
| 274 EXPECT_EQ(request_format.height, out_height_); | 356 EXPECT_EQ(request_format.height, out_height_); |
| 275 } | 357 } |
| 276 | 358 |
| 277 // Adapt the pixel resolution to 0. Expect frame drop. | 359 // Adapt the pixel resolution to 0. Expect frame drop. |
| 278 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) { | 360 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) { |
| 279 VideoFormat output_format = capture_format_; | 361 VideoFormat output_format = capture_format_; |
| 280 output_format.width = 0; | 362 output_format.width = 0; |
| 281 output_format.height = 0; | 363 output_format.height = 0; |
| 282 adapter_.OnOutputFormatRequest(output_format); | 364 adapter_.OnOutputFormatRequest(output_format); |
| 283 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 365 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, |
| 284 &cropped_width_, &cropped_height_, | 366 0, &cropped_width_, &cropped_height_, |
| 285 &out_width_, &out_height_); | 367 &out_width_, &out_height_); |
| 286 EXPECT_EQ(0, out_width_); | 368 EXPECT_EQ(0, out_width_); |
| 287 EXPECT_EQ(0, out_height_); | 369 EXPECT_EQ(0, out_height_); |
| 288 } | 370 } |
| 289 | 371 |
| 290 // Adapt the frame resolution to be a quarter of the capture resolution at the | 372 // Adapt the frame resolution to be a quarter of the capture resolution at the |
| 291 // beginning. Expect no cropping but a resolution change. | 373 // beginning. Expect no cropping but a resolution change. |
| 292 TEST_F(VideoAdapterTest, AdaptResolution) { | 374 TEST_F(VideoAdapterTest, AdaptResolution) { |
| 293 VideoFormat request_format = capture_format_; | 375 VideoFormat request_format = capture_format_; |
| 294 request_format.width /= 2; | 376 request_format.width /= 2; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 for (int i = 0; i < 10; ++i) | 423 for (int i = 0; i < 10; ++i) |
| 342 capturer_->CaptureFrame(); | 424 capturer_->CaptureFrame(); |
| 343 | 425 |
| 344 // Verify all frames are dropped. | 426 // Verify all frames are dropped. |
| 345 VideoCapturerListener::Stats stats = listener_->GetStats(); | 427 VideoCapturerListener::Stats stats = listener_->GetStats(); |
| 346 EXPECT_GE(stats.captured_frames, 10); | 428 EXPECT_GE(stats.captured_frames, 10); |
| 347 EXPECT_EQ(stats.captured_frames, stats.dropped_frames); | 429 EXPECT_EQ(stats.captured_frames, stats.dropped_frames); |
| 348 } | 430 } |
| 349 | 431 |
| 350 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) { | 432 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) { |
| 351 VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), 0); | 433 VideoFormat format(640, 400, 0, 0); |
| 352 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 434 adapter_.AdaptFrameResolution(640, 400, 0, |
| 353 adapter_.AdaptFrameResolution(640, 400, | |
| 354 &cropped_width_, &cropped_height_, | 435 &cropped_width_, &cropped_height_, |
| 355 &out_width_, &out_height_); | 436 &out_width_, &out_height_); |
| 356 EXPECT_EQ(640, cropped_width_); | 437 EXPECT_EQ(640, cropped_width_); |
| 357 EXPECT_EQ(400, cropped_height_); | 438 EXPECT_EQ(400, cropped_height_); |
| 358 EXPECT_EQ(640, out_width_); | 439 EXPECT_EQ(640, out_width_); |
| 359 EXPECT_EQ(400, out_height_); | 440 EXPECT_EQ(400, out_height_); |
| 360 | 441 |
| 361 // Format request 640x400. | 442 // Format request 640x400. |
| 362 format.height = 400; | 443 format.height = 400; |
| 363 adapter_.OnOutputFormatRequest(format); | 444 adapter_.OnOutputFormatRequest(format); |
| 364 adapter_.AdaptFrameResolution(640, 400, | 445 adapter_.AdaptFrameResolution(640, 400, 0, |
| 365 &cropped_width_, &cropped_height_, | 446 &cropped_width_, &cropped_height_, |
| 366 &out_width_, &out_height_); | 447 &out_width_, &out_height_); |
| 367 EXPECT_EQ(640, cropped_width_); | 448 EXPECT_EQ(640, cropped_width_); |
| 368 EXPECT_EQ(400, cropped_height_); | 449 EXPECT_EQ(400, cropped_height_); |
| 369 EXPECT_EQ(640, out_width_); | 450 EXPECT_EQ(640, out_width_); |
| 370 EXPECT_EQ(400, out_height_); | 451 EXPECT_EQ(400, out_height_); |
| 371 | 452 |
| 372 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but | 453 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but |
| 373 // no scaling. | 454 // no scaling. |
| 374 format.width = 1280; | 455 format.width = 1280; |
| 375 format.height = 720; | 456 format.height = 720; |
| 376 adapter_.OnOutputFormatRequest(format); | 457 adapter_.OnOutputFormatRequest(format); |
| 377 adapter_.AdaptFrameResolution(640, 400, | 458 adapter_.AdaptFrameResolution(640, 400, 0, |
| 378 &cropped_width_, &cropped_height_, | 459 &cropped_width_, &cropped_height_, |
| 379 &out_width_, &out_height_); | 460 &out_width_, &out_height_); |
| 380 EXPECT_EQ(640, cropped_width_); | 461 EXPECT_EQ(640, cropped_width_); |
| 381 EXPECT_EQ(360, cropped_height_); | 462 EXPECT_EQ(360, cropped_height_); |
| 382 EXPECT_EQ(640, out_width_); | 463 EXPECT_EQ(640, out_width_); |
| 383 EXPECT_EQ(360, out_height_); | 464 EXPECT_EQ(360, out_height_); |
| 384 | 465 |
| 385 // Request 0x0. | 466 // Request 0x0. |
| 386 format.width = 0; | 467 format.width = 0; |
| 387 format.height = 0; | 468 format.height = 0; |
| 388 adapter_.OnOutputFormatRequest(format); | 469 adapter_.OnOutputFormatRequest(format); |
| 389 adapter_.AdaptFrameResolution(640, 400, | 470 adapter_.AdaptFrameResolution(640, 400, 0, |
| 390 &cropped_width_, &cropped_height_, | 471 &cropped_width_, &cropped_height_, |
| 391 &out_width_, &out_height_); | 472 &out_width_, &out_height_); |
| 392 EXPECT_EQ(0, out_width_); | 473 EXPECT_EQ(0, out_width_); |
| 393 EXPECT_EQ(0, out_height_); | 474 EXPECT_EQ(0, out_height_); |
| 394 | 475 |
| 395 // Request 320x200. Expect scaling, but no cropping. | 476 // Request 320x200. Expect scaling, but no cropping. |
| 396 format.width = 320; | 477 format.width = 320; |
| 397 format.height = 200; | 478 format.height = 200; |
| 398 adapter_.OnOutputFormatRequest(format); | 479 adapter_.OnOutputFormatRequest(format); |
| 399 adapter_.AdaptFrameResolution(640, 400, | 480 adapter_.AdaptFrameResolution(640, 400, 0, |
| 400 &cropped_width_, &cropped_height_, | 481 &cropped_width_, &cropped_height_, |
| 401 &out_width_, &out_height_); | 482 &out_width_, &out_height_); |
| 402 EXPECT_EQ(640, cropped_width_); | 483 EXPECT_EQ(640, cropped_width_); |
| 403 EXPECT_EQ(400, cropped_height_); | 484 EXPECT_EQ(400, cropped_height_); |
| 404 EXPECT_EQ(320, out_width_); | 485 EXPECT_EQ(320, out_width_); |
| 405 EXPECT_EQ(200, out_height_); | 486 EXPECT_EQ(200, out_height_); |
| 406 | 487 |
| 407 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 | 488 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 |
| 408 // is not optimized and not allowed, therefore 1/2 scaling will be used | 489 // is not optimized and not allowed, therefore 1/2 scaling will be used |
| 409 // instead. | 490 // instead. |
| 410 format.width = 424; | 491 format.width = 424; |
| 411 format.height = 265; | 492 format.height = 265; |
| 412 adapter_.OnOutputFormatRequest(format); | 493 adapter_.OnOutputFormatRequest(format); |
| 413 adapter_.AdaptFrameResolution(640, 400, | 494 adapter_.AdaptFrameResolution(640, 400, 0, |
| 414 &cropped_width_, &cropped_height_, | 495 &cropped_width_, &cropped_height_, |
| 415 &out_width_, &out_height_); | 496 &out_width_, &out_height_); |
| 416 EXPECT_EQ(640, cropped_width_); | 497 EXPECT_EQ(640, cropped_width_); |
| 417 EXPECT_EQ(400, cropped_height_); | 498 EXPECT_EQ(400, cropped_height_); |
| 418 EXPECT_EQ(320, out_width_); | 499 EXPECT_EQ(320, out_width_); |
| 419 EXPECT_EQ(200, out_height_); | 500 EXPECT_EQ(200, out_height_); |
| 420 | 501 |
| 421 // Request resolution of 3 / 8. Expect adapt down. | 502 // Request resolution of 3 / 8. Expect adapt down. |
| 422 format.width = 640 * 3 / 8; | 503 format.width = 640 * 3 / 8; |
| 423 format.height = 400 * 3 / 8; | 504 format.height = 400 * 3 / 8; |
| 424 adapter_.OnOutputFormatRequest(format); | 505 adapter_.OnOutputFormatRequest(format); |
| 425 adapter_.AdaptFrameResolution(640, 400, | 506 adapter_.AdaptFrameResolution(640, 400, 0, |
| 426 &cropped_width_, &cropped_height_, | 507 &cropped_width_, &cropped_height_, |
| 427 &out_width_, &out_height_); | 508 &out_width_, &out_height_); |
| 428 EXPECT_EQ(640, cropped_width_); | 509 EXPECT_EQ(640, cropped_width_); |
| 429 EXPECT_EQ(400, cropped_height_); | 510 EXPECT_EQ(400, cropped_height_); |
| 430 EXPECT_EQ(640 * 3 / 8, out_width_); | 511 EXPECT_EQ(640 * 3 / 8, out_width_); |
| 431 EXPECT_EQ(400 * 3 / 8, out_height_); | 512 EXPECT_EQ(400 * 3 / 8, out_height_); |
| 432 | 513 |
| 433 // Switch back up. Expect adapt. | 514 // Switch back up. Expect adapt. |
| 434 format.width = 320; | 515 format.width = 320; |
| 435 format.height = 200; | 516 format.height = 200; |
| 436 adapter_.OnOutputFormatRequest(format); | 517 adapter_.OnOutputFormatRequest(format); |
| 437 adapter_.AdaptFrameResolution(640, 400, | 518 adapter_.AdaptFrameResolution(640, 400, 0, |
| 438 &cropped_width_, &cropped_height_, | 519 &cropped_width_, &cropped_height_, |
| 439 &out_width_, &out_height_); | 520 &out_width_, &out_height_); |
| 440 EXPECT_EQ(640, cropped_width_); | 521 EXPECT_EQ(640, cropped_width_); |
| 441 EXPECT_EQ(400, cropped_height_); | 522 EXPECT_EQ(400, cropped_height_); |
| 442 EXPECT_EQ(320, out_width_); | 523 EXPECT_EQ(320, out_width_); |
| 443 EXPECT_EQ(200, out_height_); | 524 EXPECT_EQ(200, out_height_); |
| 444 | 525 |
| 445 // Format request 480x300. | 526 // Format request 480x300. |
| 446 format.width = 480; | 527 format.width = 480; |
| 447 format.height = 300; | 528 format.height = 300; |
| 448 adapter_.OnOutputFormatRequest(format); | 529 adapter_.OnOutputFormatRequest(format); |
| 449 adapter_.AdaptFrameResolution(640, 400, | 530 adapter_.AdaptFrameResolution(640, 400, 0, |
| 450 &cropped_width_, &cropped_height_, | 531 &cropped_width_, &cropped_height_, |
| 451 &out_width_, &out_height_); | 532 &out_width_, &out_height_); |
| 452 EXPECT_EQ(640, cropped_width_); | 533 EXPECT_EQ(640, cropped_width_); |
| 453 EXPECT_EQ(400, cropped_height_); | 534 EXPECT_EQ(400, cropped_height_); |
| 454 EXPECT_EQ(480, out_width_); | 535 EXPECT_EQ(480, out_width_); |
| 455 EXPECT_EQ(300, out_height_); | 536 EXPECT_EQ(300, out_height_); |
| 456 } | 537 } |
| 457 | 538 |
| 458 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { | 539 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { |
| 459 // Start at HD. | 540 // Start at HD. |
| 460 VideoFormat format(1280, 720, VideoFormat::FpsToInterval(30), 0); | 541 VideoFormat format(1280, 720, 0, 0); |
| 461 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 542 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 462 adapter_.AdaptFrameResolution(1280, 720, | |
| 463 &cropped_width_, &cropped_height_, | 543 &cropped_width_, &cropped_height_, |
| 464 &out_width_, &out_height_); | 544 &out_width_, &out_height_); |
| 465 EXPECT_EQ(1280, cropped_width_); | 545 EXPECT_EQ(1280, cropped_width_); |
| 466 EXPECT_EQ(720, cropped_height_); | 546 EXPECT_EQ(720, cropped_height_); |
| 467 EXPECT_EQ(1280, out_width_); | 547 EXPECT_EQ(1280, out_width_); |
| 468 EXPECT_EQ(720, out_height_); | 548 EXPECT_EQ(720, out_height_); |
| 469 | 549 |
| 470 // Format request for VGA. | 550 // Format request for VGA. |
| 471 format.width = 640; | 551 format.width = 640; |
| 472 format.height = 360; | 552 format.height = 360; |
| 473 adapter_.OnOutputFormatRequest(format); | 553 adapter_.OnOutputFormatRequest(format); |
| 474 adapter_.AdaptFrameResolution(1280, 720, | 554 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 475 &cropped_width_, &cropped_height_, | 555 &cropped_width_, &cropped_height_, |
| 476 &out_width_, &out_height_); | 556 &out_width_, &out_height_); |
| 477 EXPECT_EQ(1280, cropped_width_); | 557 EXPECT_EQ(1280, cropped_width_); |
| 478 EXPECT_EQ(720, cropped_height_); | 558 EXPECT_EQ(720, cropped_height_); |
| 479 EXPECT_EQ(640, out_width_); | 559 EXPECT_EQ(640, out_width_); |
| 480 EXPECT_EQ(360, out_height_); | 560 EXPECT_EQ(360, out_height_); |
| 481 | 561 |
| 482 // Now, the camera reopens at VGA. | 562 // Now, the camera reopens at VGA. |
| 483 // Both the frame and the output format should be 640x360. | 563 // Both the frame and the output format should be 640x360. |
| 484 adapter_.AdaptFrameResolution(640, 360, | 564 adapter_.AdaptFrameResolution(640, 360, 0, |
| 485 &cropped_width_, &cropped_height_, | 565 &cropped_width_, &cropped_height_, |
| 486 &out_width_, &out_height_); | 566 &out_width_, &out_height_); |
| 487 EXPECT_EQ(640, cropped_width_); | 567 EXPECT_EQ(640, cropped_width_); |
| 488 EXPECT_EQ(360, cropped_height_); | 568 EXPECT_EQ(360, cropped_height_); |
| 489 EXPECT_EQ(640, out_width_); | 569 EXPECT_EQ(640, out_width_); |
| 490 EXPECT_EQ(360, out_height_); | 570 EXPECT_EQ(360, out_height_); |
| 491 | 571 |
| 492 // And another view request comes in for 640x360, which should have no | 572 // And another view request comes in for 640x360, which should have no |
| 493 // real impact. | 573 // real impact. |
| 494 adapter_.OnOutputFormatRequest(format); | 574 adapter_.OnOutputFormatRequest(format); |
| 495 adapter_.AdaptFrameResolution(640, 360, | 575 adapter_.AdaptFrameResolution(640, 360, 0, |
| 496 &cropped_width_, &cropped_height_, | 576 &cropped_width_, &cropped_height_, |
| 497 &out_width_, &out_height_); | 577 &out_width_, &out_height_); |
| 498 EXPECT_EQ(640, cropped_width_); | 578 EXPECT_EQ(640, cropped_width_); |
| 499 EXPECT_EQ(360, cropped_height_); | 579 EXPECT_EQ(360, cropped_height_); |
| 500 EXPECT_EQ(640, out_width_); | 580 EXPECT_EQ(640, out_width_); |
| 501 EXPECT_EQ(360, out_height_); | 581 EXPECT_EQ(360, out_height_); |
| 502 } | 582 } |
| 503 | 583 |
| 504 TEST_F(VideoAdapterTest, TestVGAWidth) { | 584 TEST_F(VideoAdapterTest, TestVGAWidth) { |
| 505 // Reqeuested Output format is 640x360. | 585 // Reqeuested Output format is 640x360. |
| 506 VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); | 586 VideoFormat format(640, 360, 0, FOURCC_I420); |
| 507 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | |
| 508 adapter_.OnOutputFormatRequest(format); | 587 adapter_.OnOutputFormatRequest(format); |
| 509 | 588 |
| 510 adapter_.AdaptFrameResolution(640, 480, | 589 adapter_.AdaptFrameResolution(640, 480, 0, |
| 511 &cropped_width_, &cropped_height_, | 590 &cropped_width_, &cropped_height_, |
| 512 &out_width_, &out_height_); | 591 &out_width_, &out_height_); |
| 513 // Expect cropping. | 592 // Expect cropping. |
| 514 EXPECT_EQ(640, cropped_width_); | 593 EXPECT_EQ(640, cropped_width_); |
| 515 EXPECT_EQ(360, cropped_height_); | 594 EXPECT_EQ(360, cropped_height_); |
| 516 EXPECT_EQ(640, out_width_); | 595 EXPECT_EQ(640, out_width_); |
| 517 EXPECT_EQ(360, out_height_); | 596 EXPECT_EQ(360, out_height_); |
| 518 | 597 |
| 519 // But if frames come in at 640x360, we shouldn't adapt them down. | 598 // But if frames come in at 640x360, we shouldn't adapt them down. |
| 520 adapter_.AdaptFrameResolution(640, 360, | 599 adapter_.AdaptFrameResolution(640, 360, 0, |
| 521 &cropped_width_, &cropped_height_, | 600 &cropped_width_, &cropped_height_, |
| 522 &out_width_, &out_height_); | 601 &out_width_, &out_height_); |
| 523 EXPECT_EQ(640, cropped_width_); | 602 EXPECT_EQ(640, cropped_width_); |
| 524 EXPECT_EQ(360, cropped_height_); | 603 EXPECT_EQ(360, cropped_height_); |
| 525 EXPECT_EQ(640, out_width_); | 604 EXPECT_EQ(640, out_width_); |
| 526 EXPECT_EQ(360, out_height_); | 605 EXPECT_EQ(360, out_height_); |
| 527 | 606 |
| 528 adapter_.AdaptFrameResolution(640, 480, | 607 adapter_.AdaptFrameResolution(640, 480, 0, |
| 529 &cropped_width_, &cropped_height_, | 608 &cropped_width_, &cropped_height_, |
| 530 &out_width_, &out_height_); | 609 &out_width_, &out_height_); |
| 531 EXPECT_EQ(640, cropped_width_); | 610 EXPECT_EQ(640, cropped_width_); |
| 532 EXPECT_EQ(360, cropped_height_); | 611 EXPECT_EQ(360, cropped_height_); |
| 533 EXPECT_EQ(640, out_width_); | 612 EXPECT_EQ(640, out_width_); |
| 534 EXPECT_EQ(360, out_height_); | 613 EXPECT_EQ(360, out_height_); |
| 535 } | 614 } |
| 536 | 615 |
| 537 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { | 616 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { |
| 538 adapter_.AdaptFrameResolution(1280, 720, | 617 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 539 &cropped_width_, &cropped_height_, | 618 &cropped_width_, &cropped_height_, |
| 540 &out_width_, &out_height_); | 619 &out_width_, &out_height_); |
| 541 EXPECT_EQ(1280, cropped_width_); | 620 EXPECT_EQ(1280, cropped_width_); |
| 542 EXPECT_EQ(720, cropped_height_); | 621 EXPECT_EQ(720, cropped_height_); |
| 543 EXPECT_EQ(1280, out_width_); | 622 EXPECT_EQ(1280, out_width_); |
| 544 EXPECT_EQ(720, out_height_); | 623 EXPECT_EQ(720, out_height_); |
| 545 | 624 |
| 546 // Adapt down one step. | 625 // Adapt down one step. |
| 547 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), | 626 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), |
| 548 rtc::Optional<int>()); | 627 rtc::Optional<int>()); |
| 549 adapter_.AdaptFrameResolution(1280, 720, | 628 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 550 &cropped_width_, &cropped_height_, | 629 &cropped_width_, &cropped_height_, |
| 551 &out_width_, &out_height_); | 630 &out_width_, &out_height_); |
| 552 EXPECT_EQ(1280, cropped_width_); | 631 EXPECT_EQ(1280, cropped_width_); |
| 553 EXPECT_EQ(720, cropped_height_); | 632 EXPECT_EQ(720, cropped_height_); |
| 554 EXPECT_EQ(960, out_width_); | 633 EXPECT_EQ(960, out_width_); |
| 555 EXPECT_EQ(540, out_height_); | 634 EXPECT_EQ(540, out_height_); |
| 556 | 635 |
| 557 // Adapt down one step more. | 636 // Adapt down one step more. |
| 558 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), | 637 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), |
| 559 rtc::Optional<int>()); | 638 rtc::Optional<int>()); |
| 560 adapter_.AdaptFrameResolution(1280, 720, | 639 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 561 &cropped_width_, &cropped_height_, | 640 &cropped_width_, &cropped_height_, |
| 562 &out_width_, &out_height_); | 641 &out_width_, &out_height_); |
| 563 EXPECT_EQ(1280, cropped_width_); | 642 EXPECT_EQ(1280, cropped_width_); |
| 564 EXPECT_EQ(720, cropped_height_); | 643 EXPECT_EQ(720, cropped_height_); |
| 565 EXPECT_EQ(640, out_width_); | 644 EXPECT_EQ(640, out_width_); |
| 566 EXPECT_EQ(360, out_height_); | 645 EXPECT_EQ(360, out_height_); |
| 567 | 646 |
| 568 // Adapt down one step more. | 647 // Adapt down one step more. |
| 569 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 648 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 570 rtc::Optional<int>()); | 649 rtc::Optional<int>()); |
| 571 adapter_.AdaptFrameResolution(1280, 720, | 650 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 572 &cropped_width_, &cropped_height_, | 651 &cropped_width_, &cropped_height_, |
| 573 &out_width_, &out_height_); | 652 &out_width_, &out_height_); |
| 574 EXPECT_EQ(1280, cropped_width_); | 653 EXPECT_EQ(1280, cropped_width_); |
| 575 EXPECT_EQ(720, cropped_height_); | 654 EXPECT_EQ(720, cropped_height_); |
| 576 EXPECT_EQ(480, out_width_); | 655 EXPECT_EQ(480, out_width_); |
| 577 EXPECT_EQ(270, out_height_); | 656 EXPECT_EQ(270, out_height_); |
| 578 | 657 |
| 579 // Adapt up one step. | 658 // Adapt up one step. |
| 580 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 659 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 581 rtc::Optional<int>(480 * 270)); | 660 rtc::Optional<int>(480 * 270)); |
| 582 adapter_.AdaptFrameResolution(1280, 720, | 661 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 583 &cropped_width_, &cropped_height_, | 662 &cropped_width_, &cropped_height_, |
| 584 &out_width_, &out_height_); | 663 &out_width_, &out_height_); |
| 585 EXPECT_EQ(1280, cropped_width_); | 664 EXPECT_EQ(1280, cropped_width_); |
| 586 EXPECT_EQ(720, cropped_height_); | 665 EXPECT_EQ(720, cropped_height_); |
| 587 EXPECT_EQ(640, out_width_); | 666 EXPECT_EQ(640, out_width_); |
| 588 EXPECT_EQ(360, out_height_); | 667 EXPECT_EQ(360, out_height_); |
| 589 | 668 |
| 590 // Adapt up one step more. | 669 // Adapt up one step more. |
| 591 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 670 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 592 rtc::Optional<int>(640 * 360)); | 671 rtc::Optional<int>(640 * 360)); |
| 593 adapter_.AdaptFrameResolution(1280, 720, | 672 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 594 &cropped_width_, &cropped_height_, | 673 &cropped_width_, &cropped_height_, |
| 595 &out_width_, &out_height_); | 674 &out_width_, &out_height_); |
| 596 EXPECT_EQ(1280, cropped_width_); | 675 EXPECT_EQ(1280, cropped_width_); |
| 597 EXPECT_EQ(720, cropped_height_); | 676 EXPECT_EQ(720, cropped_height_); |
| 598 EXPECT_EQ(960, out_width_); | 677 EXPECT_EQ(960, out_width_); |
| 599 EXPECT_EQ(540, out_height_); | 678 EXPECT_EQ(540, out_height_); |
| 600 | 679 |
| 601 // Adapt up one step more. | 680 // Adapt up one step more. |
| 602 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 681 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 603 rtc::Optional<int>(960 * 720)); | 682 rtc::Optional<int>(960 * 720)); |
| 604 adapter_.AdaptFrameResolution(1280, 720, | 683 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 605 &cropped_width_, &cropped_height_, | 684 &cropped_width_, &cropped_height_, |
| 606 &out_width_, &out_height_); | 685 &out_width_, &out_height_); |
| 607 EXPECT_EQ(1280, cropped_width_); | 686 EXPECT_EQ(1280, cropped_width_); |
| 608 EXPECT_EQ(720, cropped_height_); | 687 EXPECT_EQ(720, cropped_height_); |
| 609 EXPECT_EQ(1280, out_width_); | 688 EXPECT_EQ(1280, out_width_); |
| 610 EXPECT_EQ(720, out_height_); | 689 EXPECT_EQ(720, out_height_); |
| 611 } | 690 } |
| 612 | 691 |
| 613 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { | 692 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { |
| 614 adapter_.AdaptFrameResolution(1280, 720, | 693 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 615 &cropped_width_, &cropped_height_, | 694 &cropped_width_, &cropped_height_, |
| 616 &out_width_, &out_height_); | 695 &out_width_, &out_height_); |
| 617 EXPECT_EQ(1280, cropped_width_); | 696 EXPECT_EQ(1280, cropped_width_); |
| 618 EXPECT_EQ(720, cropped_height_); | 697 EXPECT_EQ(720, cropped_height_); |
| 619 EXPECT_EQ(1280, out_width_); | 698 EXPECT_EQ(1280, out_width_); |
| 620 EXPECT_EQ(720, out_height_); | 699 EXPECT_EQ(720, out_height_); |
| 621 | 700 |
| 622 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); | 701 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); |
| 623 adapter_.AdaptFrameResolution(1280, 720, | 702 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 624 &cropped_width_, &cropped_height_, | 703 &cropped_width_, &cropped_height_, |
| 625 &out_width_, &out_height_); | 704 &out_width_, &out_height_); |
| 626 EXPECT_EQ(0, out_width_); | 705 EXPECT_EQ(0, out_width_); |
| 627 EXPECT_EQ(0, out_height_); | 706 EXPECT_EQ(0, out_height_); |
| 628 } | 707 } |
| 629 | 708 |
| 630 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { | 709 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { |
| 631 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 710 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 632 rtc::Optional<int>()); | 711 rtc::Optional<int>()); |
| 633 adapter_.AdaptFrameResolution(1280, 720, | 712 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 634 &cropped_width_, &cropped_height_, | 713 &cropped_width_, &cropped_height_, |
| 635 &out_width_, &out_height_); | 714 &out_width_, &out_height_); |
| 636 EXPECT_EQ(1280, cropped_width_); | 715 EXPECT_EQ(1280, cropped_width_); |
| 637 EXPECT_EQ(720, cropped_height_); | 716 EXPECT_EQ(720, cropped_height_); |
| 638 EXPECT_EQ(480, out_width_); | 717 EXPECT_EQ(480, out_width_); |
| 639 EXPECT_EQ(270, out_height_); | 718 EXPECT_EQ(270, out_height_); |
| 640 | 719 |
| 641 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 720 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 642 rtc::Optional<int>(960 * 720)); | 721 rtc::Optional<int>(960 * 720)); |
| 643 adapter_.AdaptFrameResolution(1280, 720, | 722 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 644 &cropped_width_, &cropped_height_, | 723 &cropped_width_, &cropped_height_, |
| 645 &out_width_, &out_height_); | 724 &out_width_, &out_height_); |
| 646 EXPECT_EQ(1280, cropped_width_); | 725 EXPECT_EQ(1280, cropped_width_); |
| 647 EXPECT_EQ(720, cropped_height_); | 726 EXPECT_EQ(720, cropped_height_); |
| 648 EXPECT_EQ(1280, out_width_); | 727 EXPECT_EQ(1280, out_width_); |
| 649 EXPECT_EQ(720, out_height_); | 728 EXPECT_EQ(720, out_height_); |
| 650 } | 729 } |
| 651 | 730 |
| 652 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { | 731 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { |
| 653 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 732 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 654 rtc::Optional<int>()); | 733 rtc::Optional<int>()); |
| 655 adapter_.AdaptFrameResolution(1280, 720, | 734 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 656 &cropped_width_, &cropped_height_, | 735 &cropped_width_, &cropped_height_, |
| 657 &out_width_, &out_height_); | 736 &out_width_, &out_height_); |
| 658 EXPECT_EQ(1280, cropped_width_); | 737 EXPECT_EQ(1280, cropped_width_); |
| 659 EXPECT_EQ(720, cropped_height_); | 738 EXPECT_EQ(720, cropped_height_); |
| 660 EXPECT_EQ(480, out_width_); | 739 EXPECT_EQ(480, out_width_); |
| 661 EXPECT_EQ(270, out_height_); | 740 EXPECT_EQ(270, out_height_); |
| 662 | 741 |
| 663 VideoFormat new_format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); | 742 VideoFormat new_format(640, 360, 0, FOURCC_I420); |
| 664 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | |
| 665 adapter_.OnOutputFormatRequest(new_format); | 743 adapter_.OnOutputFormatRequest(new_format); |
| 666 adapter_.AdaptFrameResolution(1280, 720, | 744 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 667 &cropped_width_, &cropped_height_, | 745 &cropped_width_, &cropped_height_, |
| 668 &out_width_, &out_height_); | 746 &out_width_, &out_height_); |
| 669 EXPECT_EQ(1280, cropped_width_); | 747 EXPECT_EQ(1280, cropped_width_); |
| 670 EXPECT_EQ(720, cropped_height_); | 748 EXPECT_EQ(720, cropped_height_); |
| 671 EXPECT_EQ(480, out_width_); | 749 EXPECT_EQ(480, out_width_); |
| 672 EXPECT_EQ(270, out_height_); | 750 EXPECT_EQ(270, out_height_); |
| 673 | 751 |
| 674 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 752 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 675 rtc::Optional<int>(960 * 720)); | 753 rtc::Optional<int>(960 * 720)); |
| 676 adapter_.AdaptFrameResolution(1280, 720, | 754 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 677 &cropped_width_, &cropped_height_, | 755 &cropped_width_, &cropped_height_, |
| 678 &out_width_, &out_height_); | 756 &out_width_, &out_height_); |
| 679 EXPECT_EQ(1280, cropped_width_); | 757 EXPECT_EQ(1280, cropped_width_); |
| 680 EXPECT_EQ(720, cropped_height_); | 758 EXPECT_EQ(720, cropped_height_); |
| 681 EXPECT_EQ(640, out_width_); | 759 EXPECT_EQ(640, out_width_); |
| 682 EXPECT_EQ(360, out_height_); | 760 EXPECT_EQ(360, out_height_); |
| 683 } | 761 } |
| 684 | 762 |
| 685 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { | 763 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { |
| 686 adapter_.AdaptFrameResolution(1280, 720, | 764 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 687 &cropped_width_, &cropped_height_, | 765 &cropped_width_, &cropped_height_, |
| 688 &out_width_, &out_height_); | 766 &out_width_, &out_height_); |
| 689 EXPECT_EQ(1280, cropped_width_); | 767 EXPECT_EQ(1280, cropped_width_); |
| 690 EXPECT_EQ(720, cropped_height_); | 768 EXPECT_EQ(720, cropped_height_); |
| 691 EXPECT_EQ(1280, out_width_); | 769 EXPECT_EQ(1280, out_width_); |
| 692 EXPECT_EQ(720, out_height_); | 770 EXPECT_EQ(720, out_height_); |
| 693 | 771 |
| 694 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 772 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 695 rtc::Optional<int>()); | 773 rtc::Optional<int>()); |
| 696 adapter_.AdaptFrameResolution(1280, 720, | 774 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 697 &cropped_width_, &cropped_height_, | 775 &cropped_width_, &cropped_height_, |
| 698 &out_width_, &out_height_); | 776 &out_width_, &out_height_); |
| 699 EXPECT_EQ(1280, cropped_width_); | 777 EXPECT_EQ(1280, cropped_width_); |
| 700 EXPECT_EQ(720, cropped_height_); | 778 EXPECT_EQ(720, cropped_height_); |
| 701 EXPECT_EQ(480, out_width_); | 779 EXPECT_EQ(480, out_width_); |
| 702 EXPECT_EQ(270, out_height_); | 780 EXPECT_EQ(270, out_height_); |
| 703 | 781 |
| 704 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); | 782 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); |
| 705 adapter_.AdaptFrameResolution(1280, 720, | 783 adapter_.AdaptFrameResolution(1280, 720, 0, |
| 706 &cropped_width_, &cropped_height_, | 784 &cropped_width_, &cropped_height_, |
| 707 &out_width_, &out_height_); | 785 &out_width_, &out_height_); |
| 708 EXPECT_EQ(1280, cropped_width_); | 786 EXPECT_EQ(1280, cropped_width_); |
| 709 EXPECT_EQ(720, cropped_height_); | 787 EXPECT_EQ(720, cropped_height_); |
| 710 EXPECT_EQ(1280, out_width_); | 788 EXPECT_EQ(1280, out_width_); |
| 711 EXPECT_EQ(720, out_height_); | 789 EXPECT_EQ(720, out_height_); |
| 712 } | 790 } |
| 713 | 791 |
| 714 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { | 792 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { |
| 715 // Ask for 640x360 (16:9 aspect). | 793 // Ask for 640x360 (16:9 aspect). |
| 716 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 794 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); |
| 717 adapter_.OnOutputFormatRequest( | |
| 718 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); | |
| 719 // Send 640x480 (4:3 aspect). | 795 // Send 640x480 (4:3 aspect). |
| 720 adapter_.AdaptFrameResolution(640, 480, | 796 adapter_.AdaptFrameResolution(640, 480, 0, |
| 721 &cropped_width_, &cropped_height_, | 797 &cropped_width_, &cropped_height_, |
| 722 &out_width_, &out_height_); | 798 &out_width_, &out_height_); |
| 723 // Expect cropping to 16:9 format and no scaling. | 799 // Expect cropping to 16:9 format and no scaling. |
| 724 EXPECT_EQ(640, cropped_width_); | 800 EXPECT_EQ(640, cropped_width_); |
| 725 EXPECT_EQ(360, cropped_height_); | 801 EXPECT_EQ(360, cropped_height_); |
| 726 EXPECT_EQ(640, out_width_); | 802 EXPECT_EQ(640, out_width_); |
| 727 EXPECT_EQ(360, out_height_); | 803 EXPECT_EQ(360, out_height_); |
| 728 | 804 |
| 729 // Adapt down one step. | 805 // Adapt down one step. |
| 730 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 806 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 731 rtc::Optional<int>()); | 807 rtc::Optional<int>()); |
| 732 // Expect cropping to 16:9 format and 3/4 scaling. | 808 // Expect cropping to 16:9 format and 3/4 scaling. |
| 733 adapter_.AdaptFrameResolution(640, 480, | 809 adapter_.AdaptFrameResolution(640, 480, 0, |
| 734 &cropped_width_, &cropped_height_, | 810 &cropped_width_, &cropped_height_, |
| 735 &out_width_, &out_height_); | 811 &out_width_, &out_height_); |
| 736 EXPECT_EQ(640, cropped_width_); | 812 EXPECT_EQ(640, cropped_width_); |
| 737 EXPECT_EQ(360, cropped_height_); | 813 EXPECT_EQ(360, cropped_height_); |
| 738 EXPECT_EQ(480, out_width_); | 814 EXPECT_EQ(480, out_width_); |
| 739 EXPECT_EQ(270, out_height_); | 815 EXPECT_EQ(270, out_height_); |
| 740 | 816 |
| 741 // Adapt down one step more. | 817 // Adapt down one step more. |
| 742 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), | 818 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), |
| 743 rtc::Optional<int>()); | 819 rtc::Optional<int>()); |
| 744 // Expect cropping to 16:9 format and 1/2 scaling. | 820 // Expect cropping to 16:9 format and 1/2 scaling. |
| 745 adapter_.AdaptFrameResolution(640, 480, | 821 adapter_.AdaptFrameResolution(640, 480, 0, |
| 746 &cropped_width_, &cropped_height_, | 822 &cropped_width_, &cropped_height_, |
| 747 &out_width_, &out_height_); | 823 &out_width_, &out_height_); |
| 748 EXPECT_EQ(640, cropped_width_); | 824 EXPECT_EQ(640, cropped_width_); |
| 749 EXPECT_EQ(360, cropped_height_); | 825 EXPECT_EQ(360, cropped_height_); |
| 750 EXPECT_EQ(320, out_width_); | 826 EXPECT_EQ(320, out_width_); |
| 751 EXPECT_EQ(180, out_height_); | 827 EXPECT_EQ(180, out_height_); |
| 752 | 828 |
| 753 // Adapt up one step. | 829 // Adapt up one step. |
| 754 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 830 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 755 rtc::Optional<int>(320 * 180)); | 831 rtc::Optional<int>(320 * 180)); |
| 756 // Expect cropping to 16:9 format and 3/4 scaling. | 832 // Expect cropping to 16:9 format and 3/4 scaling. |
| 757 adapter_.AdaptFrameResolution(640, 480, | 833 adapter_.AdaptFrameResolution(640, 480, 0, |
| 758 &cropped_width_, &cropped_height_, | 834 &cropped_width_, &cropped_height_, |
| 759 &out_width_, &out_height_); | 835 &out_width_, &out_height_); |
| 760 EXPECT_EQ(640, cropped_width_); | 836 EXPECT_EQ(640, cropped_width_); |
| 761 EXPECT_EQ(360, cropped_height_); | 837 EXPECT_EQ(360, cropped_height_); |
| 762 EXPECT_EQ(480, out_width_); | 838 EXPECT_EQ(480, out_width_); |
| 763 EXPECT_EQ(270, out_height_); | 839 EXPECT_EQ(270, out_height_); |
| 764 | 840 |
| 765 // Adapt up one step more. | 841 // Adapt up one step more. |
| 766 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 842 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 767 rtc::Optional<int>(480 * 270)); | 843 rtc::Optional<int>(480 * 270)); |
| 768 // Expect cropping to 16:9 format and no scaling. | 844 // Expect cropping to 16:9 format and no scaling. |
| 769 adapter_.AdaptFrameResolution(640, 480, | 845 adapter_.AdaptFrameResolution(640, 480, 0, |
| 770 &cropped_width_, &cropped_height_, | 846 &cropped_width_, &cropped_height_, |
| 771 &out_width_, &out_height_); | 847 &out_width_, &out_height_); |
| 772 EXPECT_EQ(640, cropped_width_); | 848 EXPECT_EQ(640, cropped_width_); |
| 773 EXPECT_EQ(360, cropped_height_); | 849 EXPECT_EQ(360, cropped_height_); |
| 774 EXPECT_EQ(640, out_width_); | 850 EXPECT_EQ(640, out_width_); |
| 775 EXPECT_EQ(360, out_height_); | 851 EXPECT_EQ(360, out_height_); |
| 776 | 852 |
| 777 // Try to adapt up one step more. | 853 // Try to adapt up one step more. |
| 778 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 854 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 779 rtc::Optional<int>(640 * 360)); | 855 rtc::Optional<int>(640 * 360)); |
| 780 // Expect cropping to 16:9 format and no scaling. | 856 // Expect cropping to 16:9 format and no scaling. |
| 781 adapter_.AdaptFrameResolution(640, 480, | 857 adapter_.AdaptFrameResolution(640, 480, 0, |
| 782 &cropped_width_, &cropped_height_, | 858 &cropped_width_, &cropped_height_, |
| 783 &out_width_, &out_height_); | 859 &out_width_, &out_height_); |
| 784 EXPECT_EQ(640, cropped_width_); | 860 EXPECT_EQ(640, cropped_width_); |
| 785 EXPECT_EQ(360, cropped_height_); | 861 EXPECT_EQ(360, cropped_height_); |
| 786 EXPECT_EQ(640, out_width_); | 862 EXPECT_EQ(640, out_width_); |
| 787 EXPECT_EQ(360, out_height_); | 863 EXPECT_EQ(360, out_height_); |
| 788 } | 864 } |
| 789 | 865 |
| 790 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { | 866 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { |
| 791 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. | 867 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. |
| 792 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | |
| 793 adapter_.OnOutputFormatRequest( | 868 adapter_.OnOutputFormatRequest( |
| 794 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); | 869 VideoFormat(640, 360, 0, FOURCC_I420)); |
| 795 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), | 870 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), |
| 796 rtc::Optional<int>()); | 871 rtc::Optional<int>()); |
| 797 | 872 |
| 798 // Send 640x480 (4:3 aspect). | 873 // Send 640x480 (4:3 aspect). |
| 799 adapter_.AdaptFrameResolution(640, 480, | 874 adapter_.AdaptFrameResolution(640, 480, 0, |
| 800 &cropped_width_, &cropped_height_, | 875 &cropped_width_, &cropped_height_, |
| 801 &out_width_, &out_height_); | 876 &out_width_, &out_height_); |
| 802 | 877 |
| 803 // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 878 // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
| 804 // the resolution should be adjusted to get a perfect scale factor instead. | 879 // the resolution should be adjusted to get a perfect scale factor instead. |
| 805 EXPECT_EQ(640, cropped_width_); | 880 EXPECT_EQ(640, cropped_width_); |
| 806 EXPECT_EQ(368, cropped_height_); | 881 EXPECT_EQ(368, cropped_height_); |
| 807 EXPECT_EQ(120, out_width_); | 882 EXPECT_EQ(120, out_width_); |
| 808 EXPECT_EQ(69, out_height_); | 883 EXPECT_EQ(69, out_height_); |
| 809 } | 884 } |
| 810 | 885 |
| 811 } // namespace cricket | 886 } // namespace cricket |
| OLD | NEW |