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

Side by Side Diff: webrtc/media/base/videoengine_unittest.h

Issue 1838413002: Combining SetVideoSend and SetSource into one method. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding TODO. Created 4 years, 6 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
« no previous file with comments | « webrtc/media/base/mediachannel.h ('k') | webrtc/media/engine/webrtcvideoengine2.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; 97 media_error_ = cricket::VideoMediaChannel::ERROR_NONE;
98 cricket::VideoRecvParameters parameters; 98 cricket::VideoRecvParameters parameters;
99 parameters.codecs = engine_.codecs(); 99 parameters.codecs = engine_.codecs();
100 channel_->SetRecvParameters(parameters); 100 channel_->SetRecvParameters(parameters);
101 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); 101 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams()));
102 video_capturer_.reset(CreateFakeVideoCapturer()); 102 video_capturer_.reset(CreateFakeVideoCapturer());
103 cricket::VideoFormat format(640, 480, 103 cricket::VideoFormat format(640, 480,
104 cricket::VideoFormat::FpsToInterval(30), 104 cricket::VideoFormat::FpsToInterval(30),
105 cricket::FOURCC_I420); 105 cricket::FOURCC_I420);
106 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); 106 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format));
107 channel_->SetSource(kSsrc, video_capturer_.get()); 107 EXPECT_TRUE(
108 channel_->SetVideoSend(kSsrc, true, nullptr, video_capturer_.get()));
108 } 109 }
109 110
110 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() { 111 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() {
111 return new cricket::FakeVideoCapturer(); 112 return new cricket::FakeVideoCapturer();
112 } 113 }
113 114
114 // Utility method to setup an additional stream to send and receive video. 115 // Utility method to setup an additional stream to send and receive video.
115 // Used to test send and recv between two streams. 116 // Used to test send and recv between two streams.
116 void SetUpSecondStream() { 117 void SetUpSecondStream() {
117 SetUpSecondStreamWithNoRecv(); 118 SetUpSecondStreamWithNoRecv();
(...skipping 16 matching lines...) Expand all
134 cricket::StreamParams::CreateLegacy(kSsrc + 2))); 135 cricket::StreamParams::CreateLegacy(kSsrc + 2)));
135 // We dont add recv for the second stream. 136 // We dont add recv for the second stream.
136 137
137 // Setup the receive and renderer for second stream after send. 138 // Setup the receive and renderer for second stream after send.
138 video_capturer_2_.reset(CreateFakeVideoCapturer()); 139 video_capturer_2_.reset(CreateFakeVideoCapturer());
139 cricket::VideoFormat format(640, 480, 140 cricket::VideoFormat format(640, 480,
140 cricket::VideoFormat::FpsToInterval(30), 141 cricket::VideoFormat::FpsToInterval(30),
141 cricket::FOURCC_I420); 142 cricket::FOURCC_I420);
142 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); 143 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format));
143 144
144 channel_->SetSource(kSsrc + 2, video_capturer_2_.get()); 145 EXPECT_TRUE(channel_->SetVideoSend(kSsrc + 2, true, nullptr,
146 video_capturer_2_.get()));
145 } 147 }
146 virtual void TearDown() { 148 virtual void TearDown() {
147 channel_.reset(); 149 channel_.reset();
148 } 150 }
149 bool SetDefaultCodec() { 151 bool SetDefaultCodec() {
150 return SetOneCodec(DefaultCodec()); 152 return SetOneCodec(DefaultCodec());
151 } 153 }
152 154
153 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) { 155 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) {
154 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr)); 156 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr));
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 347 }
346 348
347 void OnVideoChannelError(uint32_t ssrc, 349 void OnVideoChannelError(uint32_t ssrc,
348 cricket::VideoMediaChannel::Error error) { 350 cricket::VideoMediaChannel::Error error) {
349 media_error_ = error; 351 media_error_ = error;
350 } 352 }
351 353
352 // Test that SetSend works. 354 // Test that SetSend works.
353 void SetSend() { 355 void SetSend() {
354 EXPECT_FALSE(channel_->sending()); 356 EXPECT_FALSE(channel_->sending());
355 channel_->SetSource(kSsrc, video_capturer_.get()); 357 EXPECT_TRUE(
358 channel_->SetVideoSend(kSsrc, true, nullptr, video_capturer_.get()));
356 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 359 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
357 EXPECT_FALSE(channel_->sending()); 360 EXPECT_FALSE(channel_->sending());
358 EXPECT_TRUE(SetSend(true)); 361 EXPECT_TRUE(SetSend(true));
359 EXPECT_TRUE(channel_->sending()); 362 EXPECT_TRUE(channel_->sending());
360 EXPECT_TRUE(SendFrame()); 363 EXPECT_TRUE(SendFrame());
361 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 364 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
362 EXPECT_TRUE(SetSend(false)); 365 EXPECT_TRUE(SetSend(false));
363 EXPECT_FALSE(channel_->sending()); 366 EXPECT_FALSE(channel_->sending());
364 } 367 }
365 // Test that SetSend fails without codecs being set. 368 // Test that SetSend fails without codecs being set.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 542 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
540 CreateFakeVideoCapturer()); 543 CreateFakeVideoCapturer());
541 const int kTestWidth = 160; 544 const int kTestWidth = 160;
542 const int kTestHeight = 120; 545 const int kTestHeight = 120;
543 cricket::VideoFormat format(kTestWidth, kTestHeight, 546 cricket::VideoFormat format(kTestWidth, kTestHeight,
544 cricket::VideoFormat::FpsToInterval(5), 547 cricket::VideoFormat::FpsToInterval(5),
545 cricket::FOURCC_I420); 548 cricket::FOURCC_I420);
546 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); 549 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
547 EXPECT_TRUE(channel_->AddSendStream( 550 EXPECT_TRUE(channel_->AddSendStream(
548 cricket::StreamParams::CreateLegacy(5678))); 551 cricket::StreamParams::CreateLegacy(5678)));
549 channel_->SetSource(5678, capturer.get()); 552 EXPECT_TRUE(channel_->SetVideoSend(5678, true, nullptr, capturer.get()));
550 EXPECT_TRUE(channel_->AddRecvStream( 553 EXPECT_TRUE(channel_->AddRecvStream(
551 cricket::StreamParams::CreateLegacy(5678))); 554 cricket::StreamParams::CreateLegacy(5678)));
552 EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); 555 EXPECT_TRUE(channel_->SetSink(5678, &renderer2));
553 EXPECT_TRUE(capturer->CaptureCustomFrame( 556 EXPECT_TRUE(capturer->CaptureCustomFrame(
554 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 557 kTestWidth, kTestHeight, cricket::FOURCC_I420));
555 EXPECT_FRAME_ON_RENDERER_WAIT( 558 EXPECT_FRAME_ON_RENDERER_WAIT(
556 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 559 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
557 560
558 // Get stats, and make sure they are correct for two senders. We wait until 561 // Get stats, and make sure they are correct for two senders. We wait until
559 // the number of expected packets have been sent to avoid races where we 562 // the number of expected packets have been sent to avoid races where we
(...skipping 15 matching lines...) Expand all
575 << "Timed out while waiting for packet counts for all sent packets."; 578 << "Timed out while waiting for packet counts for all sent packets.";
576 EXPECT_EQ(1U, info.senders[0].ssrcs().size()); 579 EXPECT_EQ(1U, info.senders[0].ssrcs().size());
577 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); 580 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]);
578 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); 581 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width);
579 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); 582 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height);
580 EXPECT_EQ(1U, info.senders[1].ssrcs().size()); 583 EXPECT_EQ(1U, info.senders[1].ssrcs().size());
581 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); 584 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]);
582 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); 585 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width);
583 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); 586 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height);
584 // The capturer must be unregistered here as it runs out of it's scope next. 587 // The capturer must be unregistered here as it runs out of it's scope next.
585 channel_->SetSource(5678, NULL); 588 channel_->SetVideoSend(5678, true, nullptr, nullptr);
586 } 589 }
587 590
588 // Test that we can set the bandwidth. 591 // Test that we can set the bandwidth.
589 void SetSendBandwidth() { 592 void SetSendBandwidth() {
590 cricket::VideoSendParameters parameters; 593 cricket::VideoSendParameters parameters;
591 parameters.codecs.push_back(DefaultCodec()); 594 parameters.codecs.push_back(DefaultCodec());
592 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. 595 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited.
593 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 596 EXPECT_TRUE(channel_->SetSendParameters(parameters));
594 parameters.max_bandwidth_bps = 128 * 1024; 597 parameters.max_bandwidth_bps = 128 * 1024;
595 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 598 EXPECT_TRUE(channel_->SetSendParameters(parameters));
(...skipping 16 matching lines...) Expand all
612 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); 615 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1));
613 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); 616 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1));
614 } 617 }
615 // Test that we can set the SSRC even after codecs are set. 618 // Test that we can set the SSRC even after codecs are set.
616 void SetSendSsrcAfterSetCodecs() { 619 void SetSendSsrcAfterSetCodecs() {
617 // Remove stream added in Setup. 620 // Remove stream added in Setup.
618 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 621 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
619 EXPECT_TRUE(SetDefaultCodec()); 622 EXPECT_TRUE(SetDefaultCodec());
620 EXPECT_TRUE(channel_->AddSendStream( 623 EXPECT_TRUE(channel_->AddSendStream(
621 cricket::StreamParams::CreateLegacy(999))); 624 cricket::StreamParams::CreateLegacy(999)));
622 channel_->SetSource(999u, video_capturer_.get()); 625 EXPECT_TRUE(
626 channel_->SetVideoSend(999u, true, nullptr, video_capturer_.get()));
623 EXPECT_TRUE(SetSend(true)); 627 EXPECT_TRUE(SetSend(true));
624 EXPECT_TRUE(WaitAndSendFrame(0)); 628 EXPECT_TRUE(WaitAndSendFrame(0));
625 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 629 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
626 uint32_t ssrc = 0; 630 uint32_t ssrc = 0;
627 std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); 631 std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0));
628 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 632 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
629 EXPECT_EQ(999u, ssrc); 633 EXPECT_EQ(999u, ssrc);
630 // Packets are being paced out, so these can mismatch between the first and 634 // Packets are being paced out, so these can mismatch between the first and
631 // second call to NumRtpPackets until pending packets are paced out. 635 // second call to NumRtpPackets until pending packets are paced out.
632 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); 636 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 p(GetRtpPacket(static_cast<int>(last_packet))); 682 p(GetRtpPacket(static_cast<int>(last_packet)));
679 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 683 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
680 EXPECT_EQ(kSsrc, ssrc); 684 EXPECT_EQ(kSsrc, ssrc);
681 685
682 // Remove the send stream that was added during Setup. 686 // Remove the send stream that was added during Setup.
683 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 687 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
684 int rtp_packets = NumRtpPackets(); 688 int rtp_packets = NumRtpPackets();
685 689
686 EXPECT_TRUE(channel_->AddSendStream( 690 EXPECT_TRUE(channel_->AddSendStream(
687 cricket::StreamParams::CreateLegacy(789u))); 691 cricket::StreamParams::CreateLegacy(789u)));
688 channel_->SetSource(789u, video_capturer_.get()); 692 EXPECT_TRUE(
693 channel_->SetVideoSend(789u, true, nullptr, video_capturer_.get()));
689 EXPECT_EQ(rtp_packets, NumRtpPackets()); 694 EXPECT_EQ(rtp_packets, NumRtpPackets());
690 // Wait 30ms to guarantee the engine does not drop the frame. 695 // Wait 30ms to guarantee the engine does not drop the frame.
691 EXPECT_TRUE(WaitAndSendFrame(30)); 696 EXPECT_TRUE(WaitAndSendFrame(30));
692 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); 697 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout);
693 698
694 last_packet = NumRtpPackets() - 1; 699 last_packet = NumRtpPackets() - 1;
695 p.reset(GetRtpPacket(static_cast<int>(last_packet))); 700 p.reset(GetRtpPacket(static_cast<int>(last_packet)));
696 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 701 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
697 EXPECT_EQ(789u, ssrc); 702 EXPECT_EQ(789u, ssrc);
698 } 703 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_TRUE(SendFrame()); 752 EXPECT_TRUE(SendFrame());
748 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); 753 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
749 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 754 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
750 CreateFakeVideoCapturer()); 755 CreateFakeVideoCapturer());
751 756
752 // TODO(nisse): This testcase fails if we don't configure 757 // TODO(nisse): This testcase fails if we don't configure
753 // screencast. It's unclear why, I see nothing obvious in this 758 // screencast. It's unclear why, I see nothing obvious in this
754 // test which is related to screencast logic. 759 // test which is related to screencast logic.
755 cricket::VideoOptions video_options; 760 cricket::VideoOptions video_options;
756 video_options.is_screencast = rtc::Optional<bool>(true); 761 video_options.is_screencast = rtc::Optional<bool>(true);
757 channel_->SetVideoSend(kSsrc, true, &video_options); 762 channel_->SetVideoSend(kSsrc, true, &video_options, nullptr);
758 763
759 cricket::VideoFormat format(480, 360, 764 cricket::VideoFormat format(480, 360,
760 cricket::VideoFormat::FpsToInterval(30), 765 cricket::VideoFormat::FpsToInterval(30),
761 cricket::FOURCC_I420); 766 cricket::FOURCC_I420);
762 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); 767 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
763 // All capturers start generating frames with the same timestamp. ViE does 768 // All capturers start generating frames with the same timestamp. ViE does
764 // not allow the same timestamp to be used. Capture one frame before 769 // not allow the same timestamp to be used. Capture one frame before
765 // associating the capturer with the channel. 770 // associating the capturer with the channel.
766 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 771 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
767 cricket::FOURCC_I420)); 772 cricket::FOURCC_I420));
768 773
769 int captured_frames = 1; 774 int captured_frames = 1;
770 for (int iterations = 0; iterations < 2; ++iterations) { 775 for (int iterations = 0; iterations < 2; ++iterations) {
771 channel_->SetSource(kSsrc, capturer.get()); 776 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, capturer.get()));
772 rtc::Thread::Current()->ProcessMessages(time_between_send); 777 rtc::Thread::Current()->ProcessMessages(time_between_send);
773 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 778 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
774 cricket::FOURCC_I420)); 779 cricket::FOURCC_I420));
775 ++captured_frames; 780 ++captured_frames;
776 // Wait until frame of right size is captured. 781 // Wait until frame of right size is captured.
777 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && 782 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
778 format.width == renderer_.width() && 783 format.width == renderer_.width() &&
779 format.height == renderer_.height() && 784 format.height == renderer_.height() &&
780 !renderer_.black_frame(), kTimeout); 785 !renderer_.black_frame(), kTimeout);
781 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); 786 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
782 EXPECT_EQ(format.width, renderer_.width()); 787 EXPECT_EQ(format.width, renderer_.width());
783 EXPECT_EQ(format.height, renderer_.height()); 788 EXPECT_EQ(format.height, renderer_.height());
784 captured_frames = renderer_.num_rendered_frames() + 1; 789 captured_frames = renderer_.num_rendered_frames() + 1;
785 EXPECT_FALSE(renderer_.black_frame()); 790 EXPECT_FALSE(renderer_.black_frame());
786 channel_->SetSource(kSsrc, NULL); 791 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
787 // Make sure a black frame is generated within the specified timeout. 792 // Make sure a black frame is generated within the specified timeout.
788 // The black frame should be the resolution of the previous frame to 793 // The black frame should be the resolution of the previous frame to
789 // prevent expensive encoder reconfigurations. 794 // prevent expensive encoder reconfigurations.
790 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && 795 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
791 format.width == renderer_.width() && 796 format.width == renderer_.width() &&
792 format.height == renderer_.height() && 797 format.height == renderer_.height() &&
793 renderer_.black_frame(), kTimeout); 798 renderer_.black_frame(), kTimeout);
794 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); 799 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
795 EXPECT_EQ(format.width, renderer_.width()); 800 EXPECT_EQ(format.width, renderer_.width());
796 EXPECT_EQ(format.height, renderer_.height()); 801 EXPECT_EQ(format.height, renderer_.height());
797 EXPECT_TRUE(renderer_.black_frame()); 802 EXPECT_TRUE(renderer_.black_frame());
798 803
799 // The black frame has the same timestamp as the next frame since it's 804 // The black frame has the same timestamp as the next frame since it's
800 // timestamp is set to the last frame's timestamp + interval. WebRTC will 805 // timestamp is set to the last frame's timestamp + interval. WebRTC will
801 // not render a frame with the same timestamp so capture another frame 806 // not render a frame with the same timestamp so capture another frame
802 // with the frame capturer to increment the next frame's timestamp. 807 // with the frame capturer to increment the next frame's timestamp.
803 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 808 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
804 cricket::FOURCC_I420)); 809 cricket::FOURCC_I420));
805 } 810 }
806 } 811 }
807 812
808 // Tests that if RemoveCapturer is called without a capturer ever being 813 // Tests that if SetVideoSend is called with a NULL capturer after the
809 // added, the plugin shouldn't crash (and no black frame should be sent). 814 // capturer was already removed, the application doesn't crash (and no black
815 // frame is sent).
810 void RemoveCapturerWithoutAdd() { 816 void RemoveCapturerWithoutAdd() {
811 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 817 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
812 EXPECT_TRUE(SetSend(true)); 818 EXPECT_TRUE(SetSend(true));
813 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 819 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
814 EXPECT_EQ(0, renderer_.num_rendered_frames()); 820 EXPECT_EQ(0, renderer_.num_rendered_frames());
815 EXPECT_TRUE(SendFrame()); 821 EXPECT_TRUE(SendFrame());
816 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); 822 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout);
817 // Wait for one frame so they don't get dropped because we send frames too 823 // Wait for one frame so they don't get dropped because we send frames too
818 // tightly. 824 // tightly.
819 rtc::Thread::Current()->ProcessMessages(30); 825 rtc::Thread::Current()->ProcessMessages(30);
820 // Remove the capturer. 826 // Remove the capturer.
821 channel_->SetSource(kSsrc, NULL); 827 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
822 // Wait for one black frame for removing the capturer. 828 // Wait for one black frame for removing the capturer.
823 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); 829 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout);
824 830
825 // No capturer was added, so this SetSource should be a NOP. 831 // No capturer was added, so this SetVideoSend shouldn't do anything.
826 channel_->SetSource(kSsrc, NULL); 832 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
827 rtc::Thread::Current()->ProcessMessages(300); 833 rtc::Thread::Current()->ProcessMessages(300);
828 // Verify no more frames were sent. 834 // Verify no more frames were sent.
829 EXPECT_EQ(2, renderer_.num_rendered_frames()); 835 EXPECT_EQ(2, renderer_.num_rendered_frames());
830 } 836 }
831 837
832 // Tests that we can add and remove capturer as unique sources. 838 // Tests that we can add and remove capturer as unique sources.
833 void AddRemoveCapturerMultipleSources() { 839 void AddRemoveCapturerMultipleSources() {
834 // WebRTC implementation will drop frames if pushed to quickly. Wait the 840 // WebRTC implementation will drop frames if pushed to quickly. Wait the
835 // interval time to avoid that. 841 // interval time to avoid that.
836 // WebRTC implementation will drop frames if pushed to quickly. Wait the 842 // WebRTC implementation will drop frames if pushed to quickly. Wait the
(...skipping 21 matching lines...) Expand all
858 EXPECT_TRUE(channel_->AddRecvStream( 864 EXPECT_TRUE(channel_->AddRecvStream(
859 cricket::StreamParams::CreateLegacy(2))); 865 cricket::StreamParams::CreateLegacy(2)));
860 EXPECT_TRUE(channel_->SetSink(2, &renderer2)); 866 EXPECT_TRUE(channel_->SetSink(2, &renderer2));
861 EXPECT_TRUE(channel_->AddSendStream( 867 EXPECT_TRUE(channel_->AddSendStream(
862 cricket::StreamParams::CreateLegacy(2))); 868 cricket::StreamParams::CreateLegacy(2)));
863 std::unique_ptr<cricket::FakeVideoCapturer> capturer2( 869 std::unique_ptr<cricket::FakeVideoCapturer> capturer2(
864 CreateFakeVideoCapturer()); 870 CreateFakeVideoCapturer());
865 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); 871 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format));
866 // State for all the streams. 872 // State for all the streams.
867 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 873 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
868 // A limitation in the lmi implementation requires that SetSource() is 874 // A limitation in the lmi implementation requires that SetVideoSend() is
869 // called after SetOneCodec(). 875 // called after SetOneCodec().
870 // TODO(hellner): this seems like an unnecessary constraint, fix it. 876 // TODO(hellner): this seems like an unnecessary constraint, fix it.
871 channel_->SetSource(1, capturer1.get()); 877 EXPECT_TRUE(channel_->SetVideoSend(1, true, nullptr, capturer1.get()));
872 channel_->SetSource(2, capturer2.get()); 878 EXPECT_TRUE(channel_->SetVideoSend(2, true, nullptr, capturer2.get()));
873 EXPECT_TRUE(SetSend(true)); 879 EXPECT_TRUE(SetSend(true));
874 // Test capturer associated with engine. 880 // Test capturer associated with engine.
875 const int kTestWidth = 160; 881 const int kTestWidth = 160;
876 const int kTestHeight = 120; 882 const int kTestHeight = 120;
877 EXPECT_TRUE(capturer1->CaptureCustomFrame( 883 EXPECT_TRUE(capturer1->CaptureCustomFrame(
878 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 884 kTestWidth, kTestHeight, cricket::FOURCC_I420));
879 EXPECT_FRAME_ON_RENDERER_WAIT( 885 EXPECT_FRAME_ON_RENDERER_WAIT(
880 renderer1, 1, kTestWidth, kTestHeight, kTimeout); 886 renderer1, 1, kTestWidth, kTestHeight, kTimeout);
881 // Capture a frame with additional capturer2, frames should be received 887 // Capture a frame with additional capturer2, frames should be received
882 EXPECT_TRUE(capturer2->CaptureCustomFrame( 888 EXPECT_TRUE(capturer2->CaptureCustomFrame(
883 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 889 kTestWidth, kTestHeight, cricket::FOURCC_I420));
884 EXPECT_FRAME_ON_RENDERER_WAIT( 890 EXPECT_FRAME_ON_RENDERER_WAIT(
885 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 891 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
886 // Successfully remove the capturer. 892 // Successfully remove the capturer.
887 channel_->SetSource(kSsrc, NULL); 893 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
888 // Fail to re-remove the capturer.
889 channel_->SetSource(kSsrc, NULL);
890 // The capturers must be unregistered here as it runs out of it's scope 894 // The capturers must be unregistered here as it runs out of it's scope
891 // next. 895 // next.
892 channel_->SetSource(1, NULL); 896 EXPECT_TRUE(channel_->SetVideoSend(1, true, nullptr, nullptr));
893 channel_->SetSource(2, NULL); 897 EXPECT_TRUE(channel_->SetVideoSend(2, true, nullptr, nullptr));
894 } 898 }
895 899
896 void HighAspectHighHeightCapturer() { 900 void HighAspectHighHeightCapturer() {
897 const int kWidth = 80; 901 const int kWidth = 80;
898 const int kHeight = 10000; 902 const int kHeight = 10000;
899 const int kScaledWidth = 20; 903 const int kScaledWidth = 20;
900 const int kScaledHeight = 2500; 904 const int kScaledHeight = 2500;
901 905
902 cricket::VideoCodec codec(DefaultCodec()); 906 cricket::VideoCodec codec(DefaultCodec());
903 EXPECT_TRUE(SetOneCodec(codec)); 907 EXPECT_TRUE(SetOneCodec(codec));
(...skipping 12 matching lines...) Expand all
916 // Registering an external capturer is currently the same as screen casting 920 // Registering an external capturer is currently the same as screen casting
917 // (update the test when this changes). 921 // (update the test when this changes).
918 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 922 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
919 CreateFakeVideoCapturer()); 923 CreateFakeVideoCapturer());
920 const std::vector<cricket::VideoFormat>* formats = 924 const std::vector<cricket::VideoFormat>* formats =
921 capturer->GetSupportedFormats(); 925 capturer->GetSupportedFormats();
922 cricket::VideoFormat capture_format = (*formats)[0]; 926 cricket::VideoFormat capture_format = (*formats)[0];
923 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); 927 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format));
924 // Capture frame to not get same frame timestamps as previous capturer. 928 // Capture frame to not get same frame timestamps as previous capturer.
925 capturer->CaptureFrame(); 929 capturer->CaptureFrame();
926 channel_->SetSource(kSsrc, capturer.get()); 930 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, capturer.get()));
927 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); 931 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
928 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, 932 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight,
929 cricket::FOURCC_ARGB)); 933 cricket::FOURCC_ARGB));
930 EXPECT_GT_FRAME_ON_RENDERER_WAIT( 934 EXPECT_GT_FRAME_ON_RENDERER_WAIT(
931 renderer, 2, kScaledWidth, kScaledHeight, kTimeout); 935 renderer, 2, kScaledWidth, kScaledHeight, kTimeout);
932 channel_->SetSource(kSsrc, NULL); 936 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
933 } 937 }
934 938
935 // Tests that we can adapt video resolution with 16:10 aspect ratio properly. 939 // Tests that we can adapt video resolution with 16:10 aspect ratio properly.
936 void AdaptResolution16x10() { 940 void AdaptResolution16x10() {
937 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 941 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
938 cricket::VideoCodec codec(DefaultCodec()); 942 cricket::VideoCodec codec(DefaultCodec());
939 codec.width = 640; 943 codec.width = 640;
940 codec.height = 400; 944 codec.height = 400;
941 SendAndReceive(codec); 945 SendAndReceive(codec);
942 codec.width /= 2; 946 codec.width /= 2;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 std::unique_ptr<C> channel_; 1081 std::unique_ptr<C> channel_;
1078 cricket::FakeNetworkInterface network_interface_; 1082 cricket::FakeNetworkInterface network_interface_;
1079 cricket::FakeVideoRenderer renderer_; 1083 cricket::FakeVideoRenderer renderer_;
1080 cricket::VideoMediaChannel::Error media_error_; 1084 cricket::VideoMediaChannel::Error media_error_;
1081 1085
1082 // Used by test cases where 2 streams are run on the same channel. 1086 // Used by test cases where 2 streams are run on the same channel.
1083 cricket::FakeVideoRenderer renderer2_; 1087 cricket::FakeVideoRenderer renderer2_;
1084 }; 1088 };
1085 1089
1086 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT 1090 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT
OLDNEW
« no previous file with comments | « webrtc/media/base/mediachannel.h ('k') | webrtc/media/engine/webrtcvideoengine2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698