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 |
11 #include <array> | |
12 #include <memory> | 11 #include <memory> |
13 #include <vector> | 12 #include <vector> |
14 | 13 |
15 #include "webrtc/common_video/include/video_frame_buffer.h" | 14 #include "webrtc/common_video/include/video_frame_buffer.h" |
16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | 15 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" |
17 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" | 16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" |
18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
19 #include "webrtc/test/gmock.h" | 18 #include "webrtc/test/gmock.h" |
20 | 19 |
21 namespace webrtc { | 20 namespace webrtc { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 int32_t(const VideoFrame& inputImage, | 110 int32_t(const VideoFrame& inputImage, |
112 const CodecSpecificInfo* codecSpecificInfo, | 111 const CodecSpecificInfo* codecSpecificInfo, |
113 const std::vector<FrameType>* frame_types) /* override */); | 112 const std::vector<FrameType>* frame_types) /* override */); |
114 | 113 |
115 int32_t RegisterEncodeCompleteCallback( | 114 int32_t RegisterEncodeCompleteCallback( |
116 EncodedImageCallback* callback) /* override */ { | 115 EncodedImageCallback* callback) /* override */ { |
117 callback_ = callback; | 116 callback_ = callback; |
118 return 0; | 117 return 0; |
119 } | 118 } |
120 | 119 |
121 MOCK_METHOD0(Release, int32_t()); | 120 int32_t Release() /* override */ { return 0; } |
122 | 121 |
123 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, | 122 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, |
124 uint32_t framerate) { | 123 uint32_t framerate) { |
125 last_set_bitrate_ = bitrate_allocation; | 124 last_set_bitrate_ = bitrate_allocation; |
126 return 0; | 125 return 0; |
127 } | 126 } |
128 | 127 |
129 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); | 128 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); |
130 | 129 |
131 bool SupportsNativeHandle() const /* override */ { | 130 bool SupportsNativeHandle() const /* override */ { |
132 return supports_native_handle_; | 131 return supports_native_handle_; |
133 } | 132 } |
134 | 133 |
135 virtual ~MockVideoEncoder() {} | 134 virtual ~MockVideoEncoder() {} |
136 | 135 |
137 const VideoCodec& codec() const { return codec_; } | 136 const VideoCodec& codec() const { return codec_; } |
138 | 137 |
139 void SendEncodedImage(int width, int height) { | 138 void SendEncodedImage(int width, int height) { |
140 // Sends a fake image of the given width/height. | 139 // Sends a fake image of the given width/height. |
141 EncodedImage image; | 140 EncodedImage image; |
142 image._encodedWidth = width; | 141 image._encodedWidth = width; |
143 image._encodedHeight = height; | 142 image._encodedHeight = height; |
144 CodecSpecificInfo codec_specific_info; | 143 CodecSpecificInfo codec_specific_info; |
145 memset(&codec_specific_info, 0, sizeof(codec_specific_info)); | 144 memset(&codec_specific_info, 0, sizeof(codec_specific_info)); |
146 callback_->OnEncodedImage(image, &codec_specific_info, nullptr); | 145 callback_->OnEncodedImage(image, &codec_specific_info, NULL); |
147 } | 146 } |
148 | 147 |
149 void set_supports_native_handle(bool enabled) { | 148 void set_supports_native_handle(bool enabled) { |
150 supports_native_handle_ = enabled; | 149 supports_native_handle_ = enabled; |
151 } | 150 } |
152 | 151 |
153 void set_init_encode_return_value(int32_t value) { | 152 void set_init_encode_return_value(int32_t value) { |
154 init_encode_return_value_ = value; | 153 init_encode_return_value_ = value; |
155 } | 154 } |
156 | 155 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 236 |
238 class TestSimulcastEncoderAdapterFake : public ::testing::Test, | 237 class TestSimulcastEncoderAdapterFake : public ::testing::Test, |
239 public EncodedImageCallback { | 238 public EncodedImageCallback { |
240 public: | 239 public: |
241 TestSimulcastEncoderAdapterFake() | 240 TestSimulcastEncoderAdapterFake() |
242 : helper_(new TestSimulcastEncoderAdapterFakeHelper()), | 241 : helper_(new TestSimulcastEncoderAdapterFakeHelper()), |
243 adapter_(helper_->CreateMockEncoderAdapter()), | 242 adapter_(helper_->CreateMockEncoderAdapter()), |
244 last_encoded_image_width_(-1), | 243 last_encoded_image_width_(-1), |
245 last_encoded_image_height_(-1), | 244 last_encoded_image_height_(-1), |
246 last_encoded_image_simulcast_index_(-1) {} | 245 last_encoded_image_simulcast_index_(-1) {} |
247 virtual ~TestSimulcastEncoderAdapterFake() { | 246 virtual ~TestSimulcastEncoderAdapterFake() {} |
248 if (adapter_) { | |
249 adapter_->Release(); | |
250 } | |
251 } | |
252 | 247 |
253 Result OnEncodedImage(const EncodedImage& encoded_image, | 248 Result OnEncodedImage(const EncodedImage& encoded_image, |
254 const CodecSpecificInfo* codec_specific_info, | 249 const CodecSpecificInfo* codec_specific_info, |
255 const RTPFragmentationHeader* fragmentation) override { | 250 const RTPFragmentationHeader* fragmentation) override { |
256 last_encoded_image_width_ = encoded_image._encodedWidth; | 251 last_encoded_image_width_ = encoded_image._encodedWidth; |
257 last_encoded_image_height_ = encoded_image._encodedHeight; | 252 last_encoded_image_height_ = encoded_image._encodedHeight; |
258 if (codec_specific_info) { | 253 if (codec_specific_info) { |
259 last_encoded_image_simulcast_index_ = | 254 last_encoded_image_simulcast_index_ = |
260 codec_specific_info->codecSpecific.VP8.simulcastIdx; | 255 codec_specific_info->codecSpecific.VP8.simulcastIdx; |
261 } | 256 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 int last_encoded_image_simulcast_index_; | 360 int last_encoded_image_simulcast_index_; |
366 TemporalLayersFactory tl_factory_; | 361 TemporalLayersFactory tl_factory_; |
367 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; | 362 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; |
368 }; | 363 }; |
369 | 364 |
370 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { | 365 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { |
371 SetupCodec(); | 366 SetupCodec(); |
372 VerifyCodecSettings(); | 367 VerifyCodecSettings(); |
373 } | 368 } |
374 | 369 |
375 TEST_F(TestSimulcastEncoderAdapterFake, ReleaseWithoutInitEncode) { | |
376 EXPECT_EQ(0, adapter_->Release()); | |
377 } | |
378 | |
379 TEST_F(TestSimulcastEncoderAdapterFake, Reinit) { | |
380 SetupCodec(); | |
381 EXPECT_EQ(0, adapter_->Release()); | |
382 | |
383 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
384 } | |
385 | |
386 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { | 370 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { |
387 SetupCodec(); | 371 SetupCodec(); |
388 const uint32_t packetLoss = 5; | 372 const uint32_t packetLoss = 5; |
389 const int64_t rtt = 30; | 373 const int64_t rtt = 30; |
390 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); | 374 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); |
391 adapter_->SetChannelParameters(packetLoss, rtt); | 375 adapter_->SetChannelParameters(packetLoss, rtt); |
392 } | 376 } |
393 | 377 |
394 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { | 378 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { |
395 SetupCodec(); | 379 SetupCodec(); |
396 | 380 |
397 // Set bitrates so that we send all layers. | 381 // Set bitrates so that we send all layers. |
398 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); | 382 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); |
399 | 383 |
400 // At this point, the simulcast encoder adapter should have 3 streams: HD, | 384 // At this point, the simulcast encoder adapter should have 3 streams: HD, |
401 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact | 385 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact |
402 // resolutions, to test that the adapter forwards on the correct resolution | 386 // resolutions, to test that the adapter forwards on the correct resolution |
403 // and simulcast index values, going only off the encoder that generates the | 387 // and simulcast index values, going only off the encoder that generates the |
404 // image. | 388 // image. |
405 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders(); | 389 EXPECT_EQ(3u, helper_->factory()->encoders().size()); |
406 ASSERT_EQ(3u, encoders.size()); | 390 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); |
407 encoders[0]->SendEncodedImage(1152, 704); | |
408 int width; | 391 int width; |
409 int height; | 392 int height; |
410 int simulcast_index; | 393 int simulcast_index; |
411 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | 394 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); |
412 EXPECT_EQ(1152, width); | 395 EXPECT_EQ(1152, width); |
413 EXPECT_EQ(704, height); | 396 EXPECT_EQ(704, height); |
414 EXPECT_EQ(0, simulcast_index); | 397 EXPECT_EQ(0, simulcast_index); |
415 | 398 |
416 encoders[1]->SendEncodedImage(300, 620); | 399 helper_->factory()->encoders()[1]->SendEncodedImage(300, 620); |
417 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | 400 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); |
418 EXPECT_EQ(300, width); | 401 EXPECT_EQ(300, width); |
419 EXPECT_EQ(620, height); | 402 EXPECT_EQ(620, height); |
420 EXPECT_EQ(1, simulcast_index); | 403 EXPECT_EQ(1, simulcast_index); |
421 | 404 |
422 encoders[2]->SendEncodedImage(120, 240); | 405 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); |
423 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | 406 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); |
424 EXPECT_EQ(120, width); | 407 EXPECT_EQ(120, width); |
425 EXPECT_EQ(240, height); | 408 EXPECT_EQ(240, height); |
426 EXPECT_EQ(2, simulcast_index); | 409 EXPECT_EQ(2, simulcast_index); |
427 } | 410 } |
428 | 411 |
429 // This test verifies that the underlying encoders are reused, when the adapter | |
430 // is reinited with different number of simulcast streams. It further checks | |
431 // that the allocated encoders are reused in the same order as before, starting | |
432 // with the lowest stream. | |
433 TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) { | |
434 // Set up common settings for three streams. | |
435 TestVp8Simulcast::DefaultSettings( | |
436 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | |
437 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); | |
438 tl_factory_.SetListener(rate_allocator_.get()); | |
439 codec_.VP8()->tl_factory = &tl_factory_; | |
440 adapter_->RegisterEncodeCompleteCallback(this); | |
441 | |
442 // Input data. | |
443 rtc::scoped_refptr<VideoFrameBuffer> buffer(I420Buffer::Create(1280, 720)); | |
444 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); | |
445 std::vector<FrameType> frame_types; | |
446 | |
447 // Encode with three streams. | |
448 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
449 VerifyCodecSettings(); | |
450 std::vector<MockVideoEncoder*> original_encoders = | |
451 helper_->factory()->encoders(); | |
452 ASSERT_EQ(3u, original_encoders.size()); | |
453 EXPECT_CALL(*original_encoders[0], Encode(_, _, _)) | |
454 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
455 EXPECT_CALL(*original_encoders[1], Encode(_, _, _)) | |
456 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
457 EXPECT_CALL(*original_encoders[2], Encode(_, _, _)) | |
458 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
459 frame_types.resize(3, kVideoFrameKey); | |
460 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types)); | |
461 EXPECT_CALL(*original_encoders[0], Release()) | |
462 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
463 EXPECT_CALL(*original_encoders[1], Release()) | |
464 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
465 EXPECT_CALL(*original_encoders[2], Release()) | |
466 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
467 EXPECT_EQ(0, adapter_->Release()); | |
468 | |
469 // Encode with two streams. | |
470 codec_.width /= 2; | |
471 codec_.height /= 2; | |
472 codec_.numberOfSimulcastStreams = 2; | |
473 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
474 std::vector<MockVideoEncoder*> new_encoders = helper_->factory()->encoders(); | |
475 ASSERT_EQ(2u, new_encoders.size()); | |
476 ASSERT_EQ(original_encoders[0], new_encoders[0]); | |
477 EXPECT_CALL(*original_encoders[0], Encode(_, _, _)) | |
478 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
479 ASSERT_EQ(original_encoders[1], new_encoders[1]); | |
480 EXPECT_CALL(*original_encoders[1], Encode(_, _, _)) | |
481 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
482 frame_types.resize(2, kVideoFrameKey); | |
483 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types)); | |
484 EXPECT_CALL(*original_encoders[0], Release()) | |
485 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
486 EXPECT_CALL(*original_encoders[1], Release()) | |
487 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
488 EXPECT_EQ(0, adapter_->Release()); | |
489 | |
490 // Encode with single stream. | |
491 codec_.width /= 2; | |
492 codec_.height /= 2; | |
493 codec_.numberOfSimulcastStreams = 1; | |
494 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
495 new_encoders = helper_->factory()->encoders(); | |
496 ASSERT_EQ(1u, new_encoders.size()); | |
497 ASSERT_EQ(original_encoders[0], new_encoders[0]); | |
498 EXPECT_CALL(*original_encoders[0], Encode(_, _, _)) | |
499 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
500 frame_types.resize(1, kVideoFrameKey); | |
501 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types)); | |
502 EXPECT_CALL(*original_encoders[0], Release()) | |
503 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
504 EXPECT_EQ(0, adapter_->Release()); | |
505 | |
506 // Encode with three streams, again. | |
507 codec_.width *= 4; | |
508 codec_.height *= 4; | |
509 codec_.numberOfSimulcastStreams = 3; | |
510 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
511 new_encoders = helper_->factory()->encoders(); | |
512 ASSERT_EQ(3u, new_encoders.size()); | |
513 // The first encoder is reused. | |
514 ASSERT_EQ(original_encoders[0], new_encoders[0]); | |
515 EXPECT_CALL(*original_encoders[0], Encode(_, _, _)) | |
516 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
517 // The second and third encoders are new. | |
518 EXPECT_CALL(*new_encoders[1], Encode(_, _, _)) | |
519 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
520 EXPECT_CALL(*new_encoders[2], Encode(_, _, _)) | |
521 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
522 frame_types.resize(3, kVideoFrameKey); | |
523 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types)); | |
524 EXPECT_CALL(*original_encoders[0], Release()) | |
525 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
526 EXPECT_CALL(*new_encoders[1], Release()) | |
527 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
528 EXPECT_CALL(*new_encoders[2], Release()) | |
529 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); | |
530 EXPECT_EQ(0, adapter_->Release()); | |
531 } | |
532 | |
533 TEST_F(TestSimulcastEncoderAdapterFake, DoesNotLeakEncoders) { | |
534 SetupCodec(); | |
535 VerifyCodecSettings(); | |
536 | |
537 EXPECT_EQ(3u, helper_->factory()->encoders().size()); | |
538 | |
539 // The adapter should destroy all encoders it has allocated. Since | |
540 // |helper_->factory()| is owned by |adapter_|, however, we need to rely on | |
541 // lsan to find leaks here. | |
542 EXPECT_EQ(0, adapter_->Release()); | |
543 adapter_.reset(); | |
544 } | |
545 | |
546 // This test verifies that an adapter reinit with the same codec settings as | |
547 // before does not change the underlying encoder codec settings. | |
548 TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderEncoderSettings) { | |
549 SetupCodec(); | |
550 VerifyCodecSettings(); | |
551 | |
552 // Capture current codec settings. | |
553 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders(); | |
554 ASSERT_EQ(3u, encoders.size()); | |
555 std::array<VideoCodec, 3> codecs_before; | |
556 for (int i = 0; i < 3; ++i) { | |
557 codecs_before[i] = encoders[i]->codec(); | |
558 } | |
559 | |
560 // Reinitialize and verify that the new codec settings are the same. | |
561 EXPECT_EQ(0, adapter_->Release()); | |
562 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
563 for (int i = 0; i < 3; ++i) { | |
564 const VideoCodec& codec_before = codecs_before[i]; | |
565 const VideoCodec& codec_after = encoders[i]->codec(); | |
566 | |
567 // webrtc::VideoCodec does not implement operator==. | |
568 EXPECT_EQ(codec_before.codecType, codec_after.codecType); | |
569 EXPECT_EQ(codec_before.plType, codec_after.plType); | |
570 EXPECT_EQ(codec_before.width, codec_after.width); | |
571 EXPECT_EQ(codec_before.height, codec_after.height); | |
572 EXPECT_EQ(codec_before.startBitrate, codec_after.startBitrate); | |
573 EXPECT_EQ(codec_before.maxBitrate, codec_after.maxBitrate); | |
574 EXPECT_EQ(codec_before.minBitrate, codec_after.minBitrate); | |
575 EXPECT_EQ(codec_before.targetBitrate, codec_after.targetBitrate); | |
576 EXPECT_EQ(codec_before.maxFramerate, codec_after.maxFramerate); | |
577 EXPECT_EQ(codec_before.qpMax, codec_after.qpMax); | |
578 EXPECT_EQ(codec_before.numberOfSimulcastStreams, | |
579 codec_after.numberOfSimulcastStreams); | |
580 EXPECT_EQ(codec_before.mode, codec_after.mode); | |
581 EXPECT_EQ(codec_before.expect_encode_from_texture, | |
582 codec_after.expect_encode_from_texture); | |
583 } | |
584 } | |
585 | |
586 // This test is similar to the one above, except that it tests the simulcastIdx | |
587 // from the CodecSpecificInfo that is connected to an encoded frame. The | |
588 // PayloadRouter demuxes the incoming encoded frames on different RTP modules | |
589 // using the simulcastIdx, so it's important that there is no corresponding | |
590 // encoder reordering in between adapter reinits as this would lead to PictureID | |
591 // discontinuities. | |
592 TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) { | |
593 SetupCodec(); | |
594 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); | |
595 VerifyCodecSettings(); | |
596 | |
597 // Send frames on all streams. | |
598 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders(); | |
599 ASSERT_EQ(3u, encoders.size()); | |
600 encoders[0]->SendEncodedImage(1152, 704); | |
601 int width; | |
602 int height; | |
603 int simulcast_index; | |
604 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | |
605 EXPECT_EQ(0, simulcast_index); | |
606 | |
607 encoders[1]->SendEncodedImage(300, 620); | |
608 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | |
609 EXPECT_EQ(1, simulcast_index); | |
610 | |
611 encoders[2]->SendEncodedImage(120, 240); | |
612 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | |
613 EXPECT_EQ(2, simulcast_index); | |
614 | |
615 // Reinitialize. | |
616 EXPECT_EQ(0, adapter_->Release()); | |
617 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
618 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); | |
619 | |
620 // Verify that the same encoder sends out frames on the same simulcast index. | |
621 encoders[0]->SendEncodedImage(1152, 704); | |
622 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | |
623 EXPECT_EQ(0, simulcast_index); | |
624 | |
625 encoders[1]->SendEncodedImage(300, 620); | |
626 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | |
627 EXPECT_EQ(1, simulcast_index); | |
628 | |
629 encoders[2]->SendEncodedImage(120, 240); | |
630 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | |
631 EXPECT_EQ(2, simulcast_index); | |
632 } | |
633 | |
634 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { | 412 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { |
635 TestVp8Simulcast::DefaultSettings( | 413 TestVp8Simulcast::DefaultSettings( |
636 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 414 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
637 codec_.VP8()->tl_factory = &tl_factory_; | 415 codec_.VP8()->tl_factory = &tl_factory_; |
638 codec_.numberOfSimulcastStreams = 1; | 416 codec_.numberOfSimulcastStreams = 1; |
639 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 417 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
640 adapter_->RegisterEncodeCompleteCallback(this); | 418 adapter_->RegisterEncodeCompleteCallback(this); |
641 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 419 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
642 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 420 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
643 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 421 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 std::vector<const char*> encoder_names; | 460 std::vector<const char*> encoder_names; |
683 encoder_names.push_back("codec1"); | 461 encoder_names.push_back("codec1"); |
684 encoder_names.push_back("codec2"); | 462 encoder_names.push_back("codec2"); |
685 encoder_names.push_back("codec3"); | 463 encoder_names.push_back("codec3"); |
686 helper_->factory()->SetEncoderNames(encoder_names); | 464 helper_->factory()->SetEncoderNames(encoder_names); |
687 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 465 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
688 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", | 466 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", |
689 adapter_->ImplementationName()); | 467 adapter_->ImplementationName()); |
690 | 468 |
691 // Single streams should not expose "SimulcastEncoderAdapter" in name. | 469 // Single streams should not expose "SimulcastEncoderAdapter" in name. |
692 EXPECT_EQ(0, adapter_->Release()); | 470 adapter_->Release(); |
693 codec_.numberOfSimulcastStreams = 1; | 471 codec_.numberOfSimulcastStreams = 1; |
694 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 472 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
695 adapter_->RegisterEncodeCompleteCallback(this); | 473 adapter_->RegisterEncodeCompleteCallback(this); |
696 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 474 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
697 EXPECT_STREQ("codec1", adapter_->ImplementationName()); | 475 EXPECT_STREQ("codec1", adapter_->ImplementationName()); |
698 } | 476 } |
699 | 477 |
700 TEST_F(TestSimulcastEncoderAdapterFake, | 478 TEST_F(TestSimulcastEncoderAdapterFake, |
701 SupportsNativeHandleForMultipleStreams) { | 479 SupportsNativeHandleForMultipleStreams) { |
702 TestVp8Simulcast::DefaultSettings( | 480 TestVp8Simulcast::DefaultSettings( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 521 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
744 | 522 |
745 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 523 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
746 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); | 524 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); |
747 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); | 525 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); |
748 // Expect calls with the given video frame verbatim, since it's a texture | 526 // Expect calls with the given video frame verbatim, since it's a texture |
749 // frame and can't otherwise be modified/resized. | 527 // frame and can't otherwise be modified/resized. |
750 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 528 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
751 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); | 529 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); |
752 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 530 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
753 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types)); | 531 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); |
754 } | 532 } |
755 | 533 |
756 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { | 534 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { |
757 TestVp8Simulcast::DefaultSettings( | 535 TestVp8Simulcast::DefaultSettings( |
758 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 536 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
759 codec_.VP8()->tl_factory = &tl_factory_; | 537 codec_.VP8()->tl_factory = &tl_factory_; |
760 codec_.numberOfSimulcastStreams = 3; | 538 codec_.numberOfSimulcastStreams = 3; |
761 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 539 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
762 adapter_->RegisterEncodeCompleteCallback(this); | 540 adapter_->RegisterEncodeCompleteCallback(this); |
763 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 541 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
(...skipping 19 matching lines...) Expand all Loading... |
783 codec_.numberOfSimulcastStreams = 3; | 561 codec_.numberOfSimulcastStreams = 3; |
784 helper_->factory()->set_init_encode_return_value( | 562 helper_->factory()->set_init_encode_return_value( |
785 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); | 563 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); |
786 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 564 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
787 adapter_->InitEncode(&codec_, 1, 1200)); | 565 adapter_->InitEncode(&codec_, 1, 1200)); |
788 EXPECT_TRUE(helper_->factory()->encoders().empty()); | 566 EXPECT_TRUE(helper_->factory()->encoders().empty()); |
789 } | 567 } |
790 | 568 |
791 } // namespace testing | 569 } // namespace testing |
792 } // namespace webrtc | 570 } // namespace webrtc |
OLD | NEW |