Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1026)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc

Issue 2901493002: Reland of use allocated encoders in SimulcastEncoderAdapter. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <memory> 12 #include <memory>
12 #include <vector> 13 #include <vector>
13 14
14 #include "webrtc/common_video/include/video_frame_buffer.h" 15 #include "webrtc/common_video/include/video_frame_buffer.h"
15 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" 16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h"
16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" 17 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h"
17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 18 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
18 #include "webrtc/test/gmock.h" 19 #include "webrtc/test/gmock.h"
19 20
20 namespace webrtc { 21 namespace webrtc {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 int32_t(const VideoFrame& inputImage, 111 int32_t(const VideoFrame& inputImage,
111 const CodecSpecificInfo* codecSpecificInfo, 112 const CodecSpecificInfo* codecSpecificInfo,
112 const std::vector<FrameType>* frame_types) /* override */); 113 const std::vector<FrameType>* frame_types) /* override */);
113 114
114 int32_t RegisterEncodeCompleteCallback( 115 int32_t RegisterEncodeCompleteCallback(
115 EncodedImageCallback* callback) /* override */ { 116 EncodedImageCallback* callback) /* override */ {
116 callback_ = callback; 117 callback_ = callback;
117 return 0; 118 return 0;
118 } 119 }
119 120
120 int32_t Release() /* override */ { return 0; } 121 MOCK_METHOD0(Release, int32_t());
121 122
122 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, 123 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation,
123 uint32_t framerate) { 124 uint32_t framerate) {
124 last_set_bitrate_ = bitrate_allocation; 125 last_set_bitrate_ = bitrate_allocation;
125 return 0; 126 return 0;
126 } 127 }
127 128
128 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); 129 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt));
129 130
130 bool SupportsNativeHandle() const /* override */ { 131 bool SupportsNativeHandle() const /* override */ {
131 return supports_native_handle_; 132 return supports_native_handle_;
132 } 133 }
133 134
134 virtual ~MockVideoEncoder() {} 135 virtual ~MockVideoEncoder() {}
135 136
136 const VideoCodec& codec() const { return codec_; } 137 const VideoCodec& codec() const { return codec_; }
137 138
138 void SendEncodedImage(int width, int height) { 139 void SendEncodedImage(int width, int height) {
139 // Sends a fake image of the given width/height. 140 // Sends a fake image of the given width/height.
140 EncodedImage image; 141 EncodedImage image;
141 image._encodedWidth = width; 142 image._encodedWidth = width;
142 image._encodedHeight = height; 143 image._encodedHeight = height;
143 CodecSpecificInfo codec_specific_info; 144 CodecSpecificInfo codec_specific_info;
144 memset(&codec_specific_info, 0, sizeof(codec_specific_info)); 145 memset(&codec_specific_info, 0, sizeof(codec_specific_info));
145 callback_->OnEncodedImage(image, &codec_specific_info, NULL); 146 callback_->OnEncodedImage(image, &codec_specific_info, nullptr);
146 } 147 }
147 148
148 void set_supports_native_handle(bool enabled) { 149 void set_supports_native_handle(bool enabled) {
149 supports_native_handle_ = enabled; 150 supports_native_handle_ = enabled;
150 } 151 }
151 152
152 void set_init_encode_return_value(int32_t value) { 153 void set_init_encode_return_value(int32_t value) {
153 init_encode_return_value_ = value; 154 init_encode_return_value_ = value;
154 } 155 }
155 156
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 237
237 class TestSimulcastEncoderAdapterFake : public ::testing::Test, 238 class TestSimulcastEncoderAdapterFake : public ::testing::Test,
238 public EncodedImageCallback { 239 public EncodedImageCallback {
239 public: 240 public:
240 TestSimulcastEncoderAdapterFake() 241 TestSimulcastEncoderAdapterFake()
241 : helper_(new TestSimulcastEncoderAdapterFakeHelper()), 242 : helper_(new TestSimulcastEncoderAdapterFakeHelper()),
242 adapter_(helper_->CreateMockEncoderAdapter()), 243 adapter_(helper_->CreateMockEncoderAdapter()),
243 last_encoded_image_width_(-1), 244 last_encoded_image_width_(-1),
244 last_encoded_image_height_(-1), 245 last_encoded_image_height_(-1),
245 last_encoded_image_simulcast_index_(-1) {} 246 last_encoded_image_simulcast_index_(-1) {}
246 virtual ~TestSimulcastEncoderAdapterFake() {} 247 virtual ~TestSimulcastEncoderAdapterFake() {
248 if (adapter_) {
249 adapter_->Release();
250 }
251 }
247 252
248 Result OnEncodedImage(const EncodedImage& encoded_image, 253 Result OnEncodedImage(const EncodedImage& encoded_image,
249 const CodecSpecificInfo* codec_specific_info, 254 const CodecSpecificInfo* codec_specific_info,
250 const RTPFragmentationHeader* fragmentation) override { 255 const RTPFragmentationHeader* fragmentation) override {
251 last_encoded_image_width_ = encoded_image._encodedWidth; 256 last_encoded_image_width_ = encoded_image._encodedWidth;
252 last_encoded_image_height_ = encoded_image._encodedHeight; 257 last_encoded_image_height_ = encoded_image._encodedHeight;
253 if (codec_specific_info) { 258 if (codec_specific_info) {
254 last_encoded_image_simulcast_index_ = 259 last_encoded_image_simulcast_index_ =
255 codec_specific_info->codecSpecific.VP8.simulcastIdx; 260 codec_specific_info->codecSpecific.VP8.simulcastIdx;
256 } 261 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 int last_encoded_image_simulcast_index_; 365 int last_encoded_image_simulcast_index_;
361 TemporalLayersFactory tl_factory_; 366 TemporalLayersFactory tl_factory_;
362 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; 367 std::unique_ptr<SimulcastRateAllocator> rate_allocator_;
363 }; 368 };
364 369
365 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { 370 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) {
366 SetupCodec(); 371 SetupCodec();
367 VerifyCodecSettings(); 372 VerifyCodecSettings();
368 } 373 }
369 374
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
370 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { 386 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) {
371 SetupCodec(); 387 SetupCodec();
372 const uint32_t packetLoss = 5; 388 const uint32_t packetLoss = 5;
373 const int64_t rtt = 30; 389 const int64_t rtt = 30;
374 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); 390 helper_->ExpectCallSetChannelParameters(packetLoss, rtt);
375 adapter_->SetChannelParameters(packetLoss, rtt); 391 adapter_->SetChannelParameters(packetLoss, rtt);
376 } 392 }
377 393
378 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { 394 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) {
379 SetupCodec(); 395 SetupCodec();
380 396
381 // Set bitrates so that we send all layers. 397 // Set bitrates so that we send all layers.
382 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); 398 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
383 399
384 // At this point, the simulcast encoder adapter should have 3 streams: HD, 400 // At this point, the simulcast encoder adapter should have 3 streams: HD,
385 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact 401 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact
386 // resolutions, to test that the adapter forwards on the correct resolution 402 // resolutions, to test that the adapter forwards on the correct resolution
387 // and simulcast index values, going only off the encoder that generates the 403 // and simulcast index values, going only off the encoder that generates the
388 // image. 404 // image.
389 EXPECT_EQ(3u, helper_->factory()->encoders().size()); 405 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
390 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); 406 ASSERT_EQ(3u, encoders.size());
407 encoders[0]->SendEncodedImage(1152, 704);
391 int width; 408 int width;
392 int height; 409 int height;
393 int simulcast_index; 410 int simulcast_index;
394 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); 411 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
395 EXPECT_EQ(1152, width); 412 EXPECT_EQ(1152, width);
396 EXPECT_EQ(704, height); 413 EXPECT_EQ(704, height);
397 EXPECT_EQ(0, simulcast_index); 414 EXPECT_EQ(0, simulcast_index);
398 415
399 helper_->factory()->encoders()[1]->SendEncodedImage(300, 620); 416 encoders[1]->SendEncodedImage(300, 620);
400 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); 417 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
401 EXPECT_EQ(300, width); 418 EXPECT_EQ(300, width);
402 EXPECT_EQ(620, height); 419 EXPECT_EQ(620, height);
403 EXPECT_EQ(1, simulcast_index); 420 EXPECT_EQ(1, simulcast_index);
404 421
405 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); 422 encoders[2]->SendEncodedImage(120, 240);
406 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); 423 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
407 EXPECT_EQ(120, width); 424 EXPECT_EQ(120, width);
408 EXPECT_EQ(240, height); 425 EXPECT_EQ(240, height);
409 EXPECT_EQ(2, simulcast_index); 426 EXPECT_EQ(2, simulcast_index);
410 } 427 }
411 428
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
412 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { 634 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) {
413 TestVp8Simulcast::DefaultSettings( 635 TestVp8Simulcast::DefaultSettings(
414 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); 636 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
415 codec_.VP8()->tl_factory = &tl_factory_; 637 codec_.VP8()->tl_factory = &tl_factory_;
416 codec_.numberOfSimulcastStreams = 1; 638 codec_.numberOfSimulcastStreams = 1;
417 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 639 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
418 adapter_->RegisterEncodeCompleteCallback(this); 640 adapter_->RegisterEncodeCompleteCallback(this);
419 ASSERT_EQ(1u, helper_->factory()->encoders().size()); 641 ASSERT_EQ(1u, helper_->factory()->encoders().size());
420 helper_->factory()->encoders()[0]->set_supports_native_handle(true); 642 helper_->factory()->encoders()[0]->set_supports_native_handle(true);
421 EXPECT_TRUE(adapter_->SupportsNativeHandle()); 643 EXPECT_TRUE(adapter_->SupportsNativeHandle());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 std::vector<const char*> encoder_names; 682 std::vector<const char*> encoder_names;
461 encoder_names.push_back("codec1"); 683 encoder_names.push_back("codec1");
462 encoder_names.push_back("codec2"); 684 encoder_names.push_back("codec2");
463 encoder_names.push_back("codec3"); 685 encoder_names.push_back("codec3");
464 helper_->factory()->SetEncoderNames(encoder_names); 686 helper_->factory()->SetEncoderNames(encoder_names);
465 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 687 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
466 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", 688 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)",
467 adapter_->ImplementationName()); 689 adapter_->ImplementationName());
468 690
469 // Single streams should not expose "SimulcastEncoderAdapter" in name. 691 // Single streams should not expose "SimulcastEncoderAdapter" in name.
470 adapter_->Release(); 692 EXPECT_EQ(0, adapter_->Release());
471 codec_.numberOfSimulcastStreams = 1; 693 codec_.numberOfSimulcastStreams = 1;
472 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 694 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
473 adapter_->RegisterEncodeCompleteCallback(this); 695 adapter_->RegisterEncodeCompleteCallback(this);
474 ASSERT_EQ(1u, helper_->factory()->encoders().size()); 696 ASSERT_EQ(1u, helper_->factory()->encoders().size());
475 EXPECT_STREQ("codec1", adapter_->ImplementationName()); 697 EXPECT_STREQ("codec1", adapter_->ImplementationName());
476 } 698 }
477 699
478 TEST_F(TestSimulcastEncoderAdapterFake, 700 TEST_F(TestSimulcastEncoderAdapterFake,
479 SupportsNativeHandleForMultipleStreams) { 701 SupportsNativeHandleForMultipleStreams) {
480 TestVp8Simulcast::DefaultSettings( 702 TestVp8Simulcast::DefaultSettings(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 EXPECT_TRUE(adapter_->SupportsNativeHandle()); 743 EXPECT_TRUE(adapter_->SupportsNativeHandle());
522 744
523 rtc::scoped_refptr<VideoFrameBuffer> buffer( 745 rtc::scoped_refptr<VideoFrameBuffer> buffer(
524 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); 746 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720));
525 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); 747 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180);
526 // Expect calls with the given video frame verbatim, since it's a texture 748 // Expect calls with the given video frame verbatim, since it's a texture
527 // frame and can't otherwise be modified/resized. 749 // frame and can't otherwise be modified/resized.
528 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) 750 for (MockVideoEncoder* encoder : helper_->factory()->encoders())
529 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); 751 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1);
530 std::vector<FrameType> frame_types(3, kVideoFrameKey); 752 std::vector<FrameType> frame_types(3, kVideoFrameKey);
531 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); 753 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types));
532 } 754 }
533 755
534 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { 756 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) {
535 TestVp8Simulcast::DefaultSettings( 757 TestVp8Simulcast::DefaultSettings(
536 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); 758 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
537 codec_.VP8()->tl_factory = &tl_factory_; 759 codec_.VP8()->tl_factory = &tl_factory_;
538 codec_.numberOfSimulcastStreams = 3; 760 codec_.numberOfSimulcastStreams = 3;
539 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 761 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
540 adapter_->RegisterEncodeCompleteCallback(this); 762 adapter_->RegisterEncodeCompleteCallback(this);
541 ASSERT_EQ(3u, helper_->factory()->encoders().size()); 763 ASSERT_EQ(3u, helper_->factory()->encoders().size());
(...skipping 19 matching lines...) Expand all
561 codec_.numberOfSimulcastStreams = 3; 783 codec_.numberOfSimulcastStreams = 3;
562 helper_->factory()->set_init_encode_return_value( 784 helper_->factory()->set_init_encode_return_value(
563 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); 785 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE);
564 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, 786 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE,
565 adapter_->InitEncode(&codec_, 1, 1200)); 787 adapter_->InitEncode(&codec_, 1, 1200));
566 EXPECT_TRUE(helper_->factory()->encoders().empty()); 788 EXPECT_TRUE(helper_->factory()->encoders().empty());
567 } 789 }
568 790
569 } // namespace testing 791 } // namespace testing
570 } // namespace webrtc 792 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc ('k') | webrtc/video/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698