OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 input_frame_.allocated_size(kUPlane)); | 331 input_frame_.allocated_size(kUPlane)); |
332 memset(input_frame_.buffer(kVPlane), 0, | 332 memset(input_frame_.buffer(kVPlane), 0, |
333 input_frame_.allocated_size(kVPlane)); | 333 input_frame_.allocated_size(kVPlane)); |
334 } | 334 } |
335 | 335 |
336 virtual void TearDown() { | 336 virtual void TearDown() { |
337 encoder_->Release(); | 337 encoder_->Release(); |
338 decoder_->Release(); | 338 decoder_->Release(); |
339 } | 339 } |
340 | 340 |
341 void ExpectStreams(VideoFrameType frame_type, int expected_video_streams) { | 341 void ExpectStreams(FrameType frame_type, int expected_video_streams) { |
342 ASSERT_GE(expected_video_streams, 0); | 342 ASSERT_GE(expected_video_streams, 0); |
343 ASSERT_LE(expected_video_streams, kNumberOfSimulcastStreams); | 343 ASSERT_LE(expected_video_streams, kNumberOfSimulcastStreams); |
344 if (expected_video_streams >= 1) { | 344 if (expected_video_streams >= 1) { |
345 EXPECT_CALL(encoder_callback_, Encoded( | 345 EXPECT_CALL(encoder_callback_, Encoded( |
346 AllOf(Field(&EncodedImage::_frameType, frame_type), | 346 AllOf(Field(&EncodedImage::_frameType, frame_type), |
347 Field(&EncodedImage::_encodedWidth, kDefaultWidth / 4), | 347 Field(&EncodedImage::_encodedWidth, kDefaultWidth / 4), |
348 Field(&EncodedImage::_encodedHeight, kDefaultHeight / 4)), _, _) | 348 Field(&EncodedImage::_encodedHeight, kDefaultHeight / 4)), _, _) |
349 ) | 349 ) |
350 .Times(1) | 350 .Times(1) |
351 .WillRepeatedly(Return(0)); | 351 .WillRepeatedly(Return(0)); |
(...skipping 30 matching lines...) Expand all Loading... |
382 &layer_sync, i); | 382 &layer_sync, i); |
383 EXPECT_EQ(expected_temporal_idx[i], temporal_layer); | 383 EXPECT_EQ(expected_temporal_idx[i], temporal_layer); |
384 EXPECT_EQ(expected_layer_sync[i], layer_sync); | 384 EXPECT_EQ(expected_layer_sync[i], layer_sync); |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 // We currently expect all active streams to generate a key frame even though | 388 // We currently expect all active streams to generate a key frame even though |
389 // a key frame was only requested for some of them. | 389 // a key frame was only requested for some of them. |
390 void TestKeyFrameRequestsOnAllStreams() { | 390 void TestKeyFrameRequestsOnAllStreams() { |
391 encoder_->SetRates(kMaxBitrates[2], 30); // To get all three streams. | 391 encoder_->SetRates(kMaxBitrates[2], 30); // To get all three streams. |
392 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 392 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
393 kDeltaFrame); | |
394 ExpectStreams(kKeyFrame, kNumberOfSimulcastStreams); | 393 ExpectStreams(kKeyFrame, kNumberOfSimulcastStreams); |
395 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 394 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
396 | 395 |
397 ExpectStreams(kDeltaFrame, kNumberOfSimulcastStreams); | 396 ExpectStreams(kDeltaFrame, kNumberOfSimulcastStreams); |
398 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 397 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
399 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 398 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
400 | 399 |
401 frame_types[0] = kKeyFrame; | 400 frame_types[0] = kKeyFrame; |
402 ExpectStreams(kKeyFrame, kNumberOfSimulcastStreams); | 401 ExpectStreams(kKeyFrame, kNumberOfSimulcastStreams); |
403 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 402 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
(...skipping 13 matching lines...) Expand all Loading... |
417 | 416 |
418 std::fill(frame_types.begin(), frame_types.end(), kDeltaFrame); | 417 std::fill(frame_types.begin(), frame_types.end(), kDeltaFrame); |
419 ExpectStreams(kDeltaFrame, kNumberOfSimulcastStreams); | 418 ExpectStreams(kDeltaFrame, kNumberOfSimulcastStreams); |
420 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 419 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
421 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 420 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
422 } | 421 } |
423 | 422 |
424 void TestPaddingAllStreams() { | 423 void TestPaddingAllStreams() { |
425 // We should always encode the base layer. | 424 // We should always encode the base layer. |
426 encoder_->SetRates(kMinBitrates[0] - 1, 30); | 425 encoder_->SetRates(kMinBitrates[0] - 1, 30); |
427 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 426 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
428 kDeltaFrame); | |
429 ExpectStreams(kKeyFrame, 1); | 427 ExpectStreams(kKeyFrame, 1); |
430 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 428 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
431 | 429 |
432 ExpectStreams(kDeltaFrame, 1); | 430 ExpectStreams(kDeltaFrame, 1); |
433 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 431 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
434 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 432 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
435 } | 433 } |
436 | 434 |
437 void TestPaddingTwoStreams() { | 435 void TestPaddingTwoStreams() { |
438 // We have just enough to get only the first stream and padding for two. | 436 // We have just enough to get only the first stream and padding for two. |
439 encoder_->SetRates(kMinBitrates[0], 30); | 437 encoder_->SetRates(kMinBitrates[0], 30); |
440 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 438 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
441 kDeltaFrame); | |
442 ExpectStreams(kKeyFrame, 1); | 439 ExpectStreams(kKeyFrame, 1); |
443 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 440 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
444 | 441 |
445 ExpectStreams(kDeltaFrame, 1); | 442 ExpectStreams(kDeltaFrame, 1); |
446 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 443 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
447 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 444 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
448 } | 445 } |
449 | 446 |
450 void TestPaddingTwoStreamsOneMaxedOut() { | 447 void TestPaddingTwoStreamsOneMaxedOut() { |
451 // We are just below limit of sending second stream, so we should get | 448 // We are just below limit of sending second stream, so we should get |
452 // the first stream maxed out (at |maxBitrate|), and padding for two. | 449 // the first stream maxed out (at |maxBitrate|), and padding for two. |
453 encoder_->SetRates(kTargetBitrates[0] + kMinBitrates[1] - 1, 30); | 450 encoder_->SetRates(kTargetBitrates[0] + kMinBitrates[1] - 1, 30); |
454 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 451 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
455 kDeltaFrame); | |
456 ExpectStreams(kKeyFrame, 1); | 452 ExpectStreams(kKeyFrame, 1); |
457 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 453 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
458 | 454 |
459 ExpectStreams(kDeltaFrame, 1); | 455 ExpectStreams(kDeltaFrame, 1); |
460 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 456 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
461 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 457 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
462 } | 458 } |
463 | 459 |
464 void TestPaddingOneStream() { | 460 void TestPaddingOneStream() { |
465 // We have just enough to send two streams, so padding for one stream. | 461 // We have just enough to send two streams, so padding for one stream. |
466 encoder_->SetRates(kTargetBitrates[0] + kMinBitrates[1], 30); | 462 encoder_->SetRates(kTargetBitrates[0] + kMinBitrates[1], 30); |
467 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 463 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
468 kDeltaFrame); | |
469 ExpectStreams(kKeyFrame, 2); | 464 ExpectStreams(kKeyFrame, 2); |
470 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 465 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
471 | 466 |
472 ExpectStreams(kDeltaFrame, 2); | 467 ExpectStreams(kDeltaFrame, 2); |
473 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 468 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
474 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 469 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
475 } | 470 } |
476 | 471 |
477 void TestPaddingOneStreamTwoMaxedOut() { | 472 void TestPaddingOneStreamTwoMaxedOut() { |
478 // We are just below limit of sending third stream, so we should get | 473 // We are just below limit of sending third stream, so we should get |
479 // first stream's rate maxed out at |targetBitrate|, second at |maxBitrate|. | 474 // first stream's rate maxed out at |targetBitrate|, second at |maxBitrate|. |
480 encoder_->SetRates(kTargetBitrates[0] + kTargetBitrates[1] + | 475 encoder_->SetRates(kTargetBitrates[0] + kTargetBitrates[1] + |
481 kMinBitrates[2] - 1, 30); | 476 kMinBitrates[2] - 1, 30); |
482 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 477 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
483 kDeltaFrame); | |
484 ExpectStreams(kKeyFrame, 2); | 478 ExpectStreams(kKeyFrame, 2); |
485 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 479 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
486 | 480 |
487 ExpectStreams(kDeltaFrame, 2); | 481 ExpectStreams(kDeltaFrame, 2); |
488 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 482 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
489 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 483 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
490 } | 484 } |
491 | 485 |
492 void TestSendAllStreams() { | 486 void TestSendAllStreams() { |
493 // We have just enough to send all streams. | 487 // We have just enough to send all streams. |
494 encoder_->SetRates(kTargetBitrates[0] + kTargetBitrates[1] + | 488 encoder_->SetRates(kTargetBitrates[0] + kTargetBitrates[1] + |
495 kMinBitrates[2], 30); | 489 kMinBitrates[2], 30); |
496 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 490 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
497 kDeltaFrame); | |
498 ExpectStreams(kKeyFrame, 3); | 491 ExpectStreams(kKeyFrame, 3); |
499 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 492 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
500 | 493 |
501 ExpectStreams(kDeltaFrame, 3); | 494 ExpectStreams(kDeltaFrame, 3); |
502 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 495 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
503 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 496 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
504 } | 497 } |
505 | 498 |
506 void TestDisablingStreams() { | 499 void TestDisablingStreams() { |
507 // We should get three media streams. | 500 // We should get three media streams. |
508 encoder_->SetRates(kMaxBitrates[0] + kMaxBitrates[1] + | 501 encoder_->SetRates(kMaxBitrates[0] + kMaxBitrates[1] + |
509 kMaxBitrates[2], 30); | 502 kMaxBitrates[2], 30); |
510 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 503 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
511 kDeltaFrame); | |
512 ExpectStreams(kKeyFrame, 3); | 504 ExpectStreams(kKeyFrame, 3); |
513 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 505 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
514 | 506 |
515 ExpectStreams(kDeltaFrame, 3); | 507 ExpectStreams(kDeltaFrame, 3); |
516 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); | 508 input_frame_.set_timestamp(input_frame_.timestamp() + 3000); |
517 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 509 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
518 | 510 |
519 // We should only get two streams and padding for one. | 511 // We should only get two streams and padding for one. |
520 encoder_->SetRates(kTargetBitrates[0] + kTargetBitrates[1] + | 512 encoder_->SetRates(kTargetBitrates[0] + kTargetBitrates[1] + |
521 kMinBitrates[2] / 2, 30); | 513 kMinBitrates[2] / 2, 30); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 maxBitrate = 0; | 574 maxBitrate = 0; |
583 // The highest layer has to correspond to the non-simulcast resolution. | 575 // The highest layer has to correspond to the non-simulcast resolution. |
584 settings_.simulcastStream[settings_.numberOfSimulcastStreams - 1]. | 576 settings_.simulcastStream[settings_.numberOfSimulcastStreams - 1]. |
585 width = settings_.width; | 577 width = settings_.width; |
586 settings_.simulcastStream[settings_.numberOfSimulcastStreams - 1]. | 578 settings_.simulcastStream[settings_.numberOfSimulcastStreams - 1]. |
587 height = settings_.height; | 579 height = settings_.height; |
588 EXPECT_EQ(0, encoder_->InitEncode(&settings_, 1, 1200)); | 580 EXPECT_EQ(0, encoder_->InitEncode(&settings_, 1, 1200)); |
589 | 581 |
590 // Encode one frame and verify. | 582 // Encode one frame and verify. |
591 encoder_->SetRates(kMaxBitrates[0] + kMaxBitrates[1], 30); | 583 encoder_->SetRates(kMaxBitrates[0] + kMaxBitrates[1], 30); |
592 std::vector<VideoFrameType> frame_types(kNumberOfSimulcastStreams, | 584 std::vector<FrameType> frame_types(kNumberOfSimulcastStreams, kDeltaFrame); |
593 kDeltaFrame); | |
594 EXPECT_CALL(encoder_callback_, Encoded( | 585 EXPECT_CALL(encoder_callback_, Encoded( |
595 AllOf(Field(&EncodedImage::_frameType, kKeyFrame), | 586 AllOf(Field(&EncodedImage::_frameType, kKeyFrame), |
596 Field(&EncodedImage::_encodedWidth, width), | 587 Field(&EncodedImage::_encodedWidth, width), |
597 Field(&EncodedImage::_encodedHeight, height)), _, _)) | 588 Field(&EncodedImage::_encodedHeight, height)), _, _)) |
598 .Times(1) | 589 .Times(1) |
599 .WillRepeatedly(Return(0)); | 590 .WillRepeatedly(Return(0)); |
600 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); | 591 EXPECT_EQ(0, encoder_->Encode(input_frame_, NULL, &frame_types)); |
601 | 592 |
602 // Switch back. | 593 // Switch back. |
603 DefaultSettings(&settings_, kDefaultTemporalLayerProfile); | 594 DefaultSettings(&settings_, kDefaultTemporalLayerProfile); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 rtc::scoped_ptr<VP8Decoder> decoder_; | 981 rtc::scoped_ptr<VP8Decoder> decoder_; |
991 MockDecodedImageCallback decoder_callback_; | 982 MockDecodedImageCallback decoder_callback_; |
992 VideoCodec settings_; | 983 VideoCodec settings_; |
993 VideoFrame input_frame_; | 984 VideoFrame input_frame_; |
994 }; | 985 }; |
995 | 986 |
996 } // namespace testing | 987 } // namespace testing |
997 } // namespace webrtc | 988 } // namespace webrtc |
998 | 989 |
999 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ | 990 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ |
OLD | NEW |