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

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: Created 4 years, 8 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
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; 118 media_error_ = cricket::VideoMediaChannel::ERROR_NONE;
119 cricket::VideoRecvParameters parameters; 119 cricket::VideoRecvParameters parameters;
120 parameters.codecs = engine_.codecs(); 120 parameters.codecs = engine_.codecs();
121 channel_->SetRecvParameters(parameters); 121 channel_->SetRecvParameters(parameters);
122 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); 122 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams()));
123 video_capturer_.reset(CreateFakeVideoCapturer()); 123 video_capturer_.reset(CreateFakeVideoCapturer());
124 cricket::VideoFormat format(640, 480, 124 cricket::VideoFormat format(640, 480,
125 cricket::VideoFormat::FpsToInterval(30), 125 cricket::VideoFormat::FpsToInterval(30),
126 cricket::FOURCC_I420); 126 cricket::FOURCC_I420);
127 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); 127 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format));
128 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); 128 EXPECT_TRUE(
129 channel_->SetVideoSend(kSsrc, true, nullptr, video_capturer_.get()));
129 } 130 }
130 131
131 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() { 132 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() {
132 return new cricket::FakeVideoCapturer(); 133 return new cricket::FakeVideoCapturer();
133 } 134 }
134 135
135 // Utility method to setup an additional stream to send and receive video. 136 // Utility method to setup an additional stream to send and receive video.
136 // Used to test send and recv between two streams. 137 // Used to test send and recv between two streams.
137 void SetUpSecondStream() { 138 void SetUpSecondStream() {
138 SetUpSecondStreamWithNoRecv(); 139 SetUpSecondStreamWithNoRecv();
(...skipping 16 matching lines...) Expand all
155 cricket::StreamParams::CreateLegacy(kSsrc + 2))); 156 cricket::StreamParams::CreateLegacy(kSsrc + 2)));
156 // We dont add recv for the second stream. 157 // We dont add recv for the second stream.
157 158
158 // Setup the receive and renderer for second stream after send. 159 // Setup the receive and renderer for second stream after send.
159 video_capturer_2_.reset(CreateFakeVideoCapturer()); 160 video_capturer_2_.reset(CreateFakeVideoCapturer());
160 cricket::VideoFormat format(640, 480, 161 cricket::VideoFormat format(640, 480,
161 cricket::VideoFormat::FpsToInterval(30), 162 cricket::VideoFormat::FpsToInterval(30),
162 cricket::FOURCC_I420); 163 cricket::FOURCC_I420);
163 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); 164 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format));
164 165
165 EXPECT_TRUE(channel_->SetCapturer(kSsrc + 2, video_capturer_2_.get())); 166 EXPECT_TRUE(channel_->SetVideoSend(kSsrc + 2, true, nullptr,
167 video_capturer_2_.get()));
166 } 168 }
167 virtual void TearDown() { 169 virtual void TearDown() {
168 channel_.reset(); 170 channel_.reset();
169 } 171 }
170 bool SetDefaultCodec() { 172 bool SetDefaultCodec() {
171 return SetOneCodec(DefaultCodec()); 173 return SetOneCodec(DefaultCodec());
172 } 174 }
173 175
174 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) { 176 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) {
175 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0)); 177 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 370 }
369 371
370 void OnVideoChannelError(uint32_t ssrc, 372 void OnVideoChannelError(uint32_t ssrc,
371 cricket::VideoMediaChannel::Error error) { 373 cricket::VideoMediaChannel::Error error) {
372 media_error_ = error; 374 media_error_ = error;
373 } 375 }
374 376
375 // Test that SetSend works. 377 // Test that SetSend works.
376 void SetSend() { 378 void SetSend() {
377 EXPECT_FALSE(channel_->sending()); 379 EXPECT_FALSE(channel_->sending());
378 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); 380 EXPECT_TRUE(
381 channel_->SetVideoSend(kSsrc, true, nullptr, video_capturer_.get()));
379 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 382 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
380 EXPECT_FALSE(channel_->sending()); 383 EXPECT_FALSE(channel_->sending());
381 EXPECT_TRUE(SetSend(true)); 384 EXPECT_TRUE(SetSend(true));
382 EXPECT_TRUE(channel_->sending()); 385 EXPECT_TRUE(channel_->sending());
383 EXPECT_TRUE(SendFrame()); 386 EXPECT_TRUE(SendFrame());
384 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 387 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
385 EXPECT_TRUE(SetSend(false)); 388 EXPECT_TRUE(SetSend(false));
386 EXPECT_FALSE(channel_->sending()); 389 EXPECT_FALSE(channel_->sending());
387 } 390 }
388 // Test that SetSend fails without codecs being set. 391 // Test that SetSend fails without codecs being set.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 565 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
563 CreateFakeVideoCapturer()); 566 CreateFakeVideoCapturer());
564 const int kTestWidth = 160; 567 const int kTestWidth = 160;
565 const int kTestHeight = 120; 568 const int kTestHeight = 120;
566 cricket::VideoFormat format(kTestWidth, kTestHeight, 569 cricket::VideoFormat format(kTestWidth, kTestHeight,
567 cricket::VideoFormat::FpsToInterval(5), 570 cricket::VideoFormat::FpsToInterval(5),
568 cricket::FOURCC_I420); 571 cricket::FOURCC_I420);
569 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); 572 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
570 EXPECT_TRUE(channel_->AddSendStream( 573 EXPECT_TRUE(channel_->AddSendStream(
571 cricket::StreamParams::CreateLegacy(5678))); 574 cricket::StreamParams::CreateLegacy(5678)));
572 EXPECT_TRUE(channel_->SetCapturer(5678, capturer.get())); 575 EXPECT_TRUE(channel_->SetVideoSend(5678, true, nullptr, capturer.get()));
573 EXPECT_TRUE(channel_->AddRecvStream( 576 EXPECT_TRUE(channel_->AddRecvStream(
574 cricket::StreamParams::CreateLegacy(5678))); 577 cricket::StreamParams::CreateLegacy(5678)));
575 EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); 578 EXPECT_TRUE(channel_->SetSink(5678, &renderer2));
576 EXPECT_TRUE(capturer->CaptureCustomFrame( 579 EXPECT_TRUE(capturer->CaptureCustomFrame(
577 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 580 kTestWidth, kTestHeight, cricket::FOURCC_I420));
578 EXPECT_FRAME_ON_RENDERER_WAIT( 581 EXPECT_FRAME_ON_RENDERER_WAIT(
579 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 582 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
580 583
581 // Get stats, and make sure they are correct for two senders. We wait until 584 // Get stats, and make sure they are correct for two senders. We wait until
582 // the number of expected packets have been sent to avoid races where we 585 // the number of expected packets have been sent to avoid races where we
(...skipping 15 matching lines...) Expand all
598 << "Timed out while waiting for packet counts for all sent packets."; 601 << "Timed out while waiting for packet counts for all sent packets.";
599 EXPECT_EQ(1U, info.senders[0].ssrcs().size()); 602 EXPECT_EQ(1U, info.senders[0].ssrcs().size());
600 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); 603 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]);
601 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); 604 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width);
602 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); 605 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height);
603 EXPECT_EQ(1U, info.senders[1].ssrcs().size()); 606 EXPECT_EQ(1U, info.senders[1].ssrcs().size());
604 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); 607 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]);
605 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); 608 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width);
606 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); 609 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height);
607 // The capturer must be unregistered here as it runs out of it's scope next. 610 // The capturer must be unregistered here as it runs out of it's scope next.
608 EXPECT_TRUE(channel_->SetCapturer(5678, NULL)); 611 EXPECT_TRUE(channel_->SetVideoSend(5678, true, nullptr, nullptr));
609 } 612 }
610 613
611 // Test that we can set the bandwidth. 614 // Test that we can set the bandwidth.
612 void SetSendBandwidth() { 615 void SetSendBandwidth() {
613 cricket::VideoSendParameters parameters; 616 cricket::VideoSendParameters parameters;
614 parameters.codecs.push_back(DefaultCodec()); 617 parameters.codecs.push_back(DefaultCodec());
615 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. 618 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited.
616 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 619 EXPECT_TRUE(channel_->SetSendParameters(parameters));
617 parameters.max_bandwidth_bps = 128 * 1024; 620 parameters.max_bandwidth_bps = 128 * 1024;
618 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 621 EXPECT_TRUE(channel_->SetSendParameters(parameters));
(...skipping 16 matching lines...) Expand all
635 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); 638 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1));
636 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); 639 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1));
637 } 640 }
638 // Test that we can set the SSRC even after codecs are set. 641 // Test that we can set the SSRC even after codecs are set.
639 void SetSendSsrcAfterSetCodecs() { 642 void SetSendSsrcAfterSetCodecs() {
640 // Remove stream added in Setup. 643 // Remove stream added in Setup.
641 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 644 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
642 EXPECT_TRUE(SetDefaultCodec()); 645 EXPECT_TRUE(SetDefaultCodec());
643 EXPECT_TRUE(channel_->AddSendStream( 646 EXPECT_TRUE(channel_->AddSendStream(
644 cricket::StreamParams::CreateLegacy(999))); 647 cricket::StreamParams::CreateLegacy(999)));
645 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); 648 EXPECT_TRUE(
649 channel_->SetVideoSend(999u, true, nullptr, video_capturer_.get()));
646 EXPECT_TRUE(SetSend(true)); 650 EXPECT_TRUE(SetSend(true));
647 EXPECT_TRUE(WaitAndSendFrame(0)); 651 EXPECT_TRUE(WaitAndSendFrame(0));
648 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 652 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
649 uint32_t ssrc = 0; 653 uint32_t ssrc = 0;
650 std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); 654 std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0));
651 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 655 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
652 EXPECT_EQ(999u, ssrc); 656 EXPECT_EQ(999u, ssrc);
653 // Packets are being paced out, so these can mismatch between the first and 657 // Packets are being paced out, so these can mismatch between the first and
654 // second call to NumRtpPackets until pending packets are paced out. 658 // second call to NumRtpPackets until pending packets are paced out.
655 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); 659 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 p(GetRtpPacket(static_cast<int>(last_packet))); 705 p(GetRtpPacket(static_cast<int>(last_packet)));
702 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 706 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
703 EXPECT_EQ(kSsrc, ssrc); 707 EXPECT_EQ(kSsrc, ssrc);
704 708
705 // Remove the send stream that was added during Setup. 709 // Remove the send stream that was added during Setup.
706 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 710 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
707 int rtp_packets = NumRtpPackets(); 711 int rtp_packets = NumRtpPackets();
708 712
709 EXPECT_TRUE(channel_->AddSendStream( 713 EXPECT_TRUE(channel_->AddSendStream(
710 cricket::StreamParams::CreateLegacy(789u))); 714 cricket::StreamParams::CreateLegacy(789u)));
711 EXPECT_TRUE(channel_->SetCapturer(789u, video_capturer_.get())); 715 EXPECT_TRUE(
716 channel_->SetVideoSend(789u, true, nullptr, video_capturer_.get()));
712 EXPECT_EQ(rtp_packets, NumRtpPackets()); 717 EXPECT_EQ(rtp_packets, NumRtpPackets());
713 // Wait 30ms to guarantee the engine does not drop the frame. 718 // Wait 30ms to guarantee the engine does not drop the frame.
714 EXPECT_TRUE(WaitAndSendFrame(30)); 719 EXPECT_TRUE(WaitAndSendFrame(30));
715 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); 720 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout);
716 721
717 last_packet = NumRtpPackets() - 1; 722 last_packet = NumRtpPackets() - 1;
718 p.reset(GetRtpPacket(static_cast<int>(last_packet))); 723 p.reset(GetRtpPacket(static_cast<int>(last_packet)));
719 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 724 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
720 EXPECT_EQ(789u, ssrc); 725 EXPECT_EQ(789u, ssrc);
721 } 726 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 EXPECT_TRUE(SendFrame()); 775 EXPECT_TRUE(SendFrame());
771 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); 776 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
772 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 777 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
773 CreateFakeVideoCapturer()); 778 CreateFakeVideoCapturer());
774 779
775 // TODO(nisse): This testcase fails if we don't configure 780 // TODO(nisse): This testcase fails if we don't configure
776 // screencast. It's unclear why, I see nothing obvious in this 781 // screencast. It's unclear why, I see nothing obvious in this
777 // test which is related to screencast logic. 782 // test which is related to screencast logic.
778 cricket::VideoOptions video_options; 783 cricket::VideoOptions video_options;
779 video_options.is_screencast = rtc::Optional<bool>(true); 784 video_options.is_screencast = rtc::Optional<bool>(true);
780 channel_->SetVideoSend(kSsrc, true, &video_options); 785 channel_->SetVideoSend(kSsrc, true, &video_options, nullptr);
781 786
782 cricket::VideoFormat format(480, 360, 787 cricket::VideoFormat format(480, 360,
783 cricket::VideoFormat::FpsToInterval(30), 788 cricket::VideoFormat::FpsToInterval(30),
784 cricket::FOURCC_I420); 789 cricket::FOURCC_I420);
785 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); 790 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
786 // All capturers start generating frames with the same timestamp. ViE does 791 // All capturers start generating frames with the same timestamp. ViE does
787 // not allow the same timestamp to be used. Capture one frame before 792 // not allow the same timestamp to be used. Capture one frame before
788 // associating the capturer with the channel. 793 // associating the capturer with the channel.
789 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 794 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
790 cricket::FOURCC_I420)); 795 cricket::FOURCC_I420));
791 796
792 int captured_frames = 1; 797 int captured_frames = 1;
793 for (int iterations = 0; iterations < 2; ++iterations) { 798 for (int iterations = 0; iterations < 2; ++iterations) {
794 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); 799 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, capturer.get()));
795 rtc::Thread::Current()->ProcessMessages(time_between_send); 800 rtc::Thread::Current()->ProcessMessages(time_between_send);
796 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 801 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
797 cricket::FOURCC_I420)); 802 cricket::FOURCC_I420));
798 ++captured_frames; 803 ++captured_frames;
799 // Wait until frame of right size is captured. 804 // Wait until frame of right size is captured.
800 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && 805 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
801 format.width == renderer_.width() && 806 format.width == renderer_.width() &&
802 format.height == renderer_.height() && 807 format.height == renderer_.height() &&
803 !renderer_.black_frame(), kTimeout); 808 !renderer_.black_frame(), kTimeout);
804 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); 809 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
805 EXPECT_EQ(format.width, renderer_.width()); 810 EXPECT_EQ(format.width, renderer_.width());
806 EXPECT_EQ(format.height, renderer_.height()); 811 EXPECT_EQ(format.height, renderer_.height());
807 captured_frames = renderer_.num_rendered_frames() + 1; 812 captured_frames = renderer_.num_rendered_frames() + 1;
808 EXPECT_FALSE(renderer_.black_frame()); 813 EXPECT_FALSE(renderer_.black_frame());
809 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 814 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
810 // Make sure a black frame is generated within the specified timeout. 815 // Make sure a black frame is generated within the specified timeout.
811 // The black frame should be the resolution of the previous frame to 816 // The black frame should be the resolution of the previous frame to
812 // prevent expensive encoder reconfigurations. 817 // prevent expensive encoder reconfigurations.
813 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && 818 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
814 format.width == renderer_.width() && 819 format.width == renderer_.width() &&
815 format.height == renderer_.height() && 820 format.height == renderer_.height() &&
816 renderer_.black_frame(), kTimeout); 821 renderer_.black_frame(), kTimeout);
817 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); 822 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
818 EXPECT_EQ(format.width, renderer_.width()); 823 EXPECT_EQ(format.width, renderer_.width());
819 EXPECT_EQ(format.height, renderer_.height()); 824 EXPECT_EQ(format.height, renderer_.height());
820 EXPECT_TRUE(renderer_.black_frame()); 825 EXPECT_TRUE(renderer_.black_frame());
821 826
822 // The black frame has the same timestamp as the next frame since it's 827 // The black frame has the same timestamp as the next frame since it's
823 // timestamp is set to the last frame's timestamp + interval. WebRTC will 828 // timestamp is set to the last frame's timestamp + interval. WebRTC will
824 // not render a frame with the same timestamp so capture another frame 829 // not render a frame with the same timestamp so capture another frame
825 // with the frame capturer to increment the next frame's timestamp. 830 // with the frame capturer to increment the next frame's timestamp.
826 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 831 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
827 cricket::FOURCC_I420)); 832 cricket::FOURCC_I420));
828 } 833 }
829 } 834 }
830 835
831 // Tests that if RemoveCapturer is called without a capturer ever being 836 // Tests that if SetVideoSend is called with a NULL capturer after the
832 // added, the plugin shouldn't crash (and no black frame should be sent). 837 // capturer was already removed, the application doesn't crash (and no black
838 // frame is sent).
833 void RemoveCapturerWithoutAdd() { 839 void RemoveCapturerWithoutAdd() {
834 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 840 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
835 EXPECT_TRUE(SetSend(true)); 841 EXPECT_TRUE(SetSend(true));
836 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 842 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
837 EXPECT_EQ(0, renderer_.num_rendered_frames()); 843 EXPECT_EQ(0, renderer_.num_rendered_frames());
838 EXPECT_TRUE(SendFrame()); 844 EXPECT_TRUE(SendFrame());
839 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); 845 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout);
840 // Wait for one frame so they don't get dropped because we send frames too 846 // Wait for one frame so they don't get dropped because we send frames too
841 // tightly. 847 // tightly.
842 rtc::Thread::Current()->ProcessMessages(30); 848 rtc::Thread::Current()->ProcessMessages(30);
843 // Remove the capturer. 849 // Remove the capturer.
844 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 850 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
845 // Wait for one black frame for removing the capturer. 851 // Wait for one black frame for removing the capturer.
846 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); 852 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout);
847 853
848 // No capturer was added, so this RemoveCapturer should 854 // No capturer was added, so this SetVideoSend shouldn't do anything.
849 // fail. 855 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
850 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL));
851 rtc::Thread::Current()->ProcessMessages(300); 856 rtc::Thread::Current()->ProcessMessages(300);
852 // Verify no more frames were sent. 857 // Verify no more frames were sent.
853 EXPECT_EQ(2, renderer_.num_rendered_frames()); 858 EXPECT_EQ(2, renderer_.num_rendered_frames());
854 } 859 }
855 860
856 // Tests that we can add and remove capturer as unique sources. 861 // Tests that we can add and remove capturer as unique sources.
857 void AddRemoveCapturerMultipleSources() { 862 void AddRemoveCapturerMultipleSources() {
858 // WebRTC implementation will drop frames if pushed to quickly. Wait the 863 // WebRTC implementation will drop frames if pushed to quickly. Wait the
859 // interval time to avoid that. 864 // interval time to avoid that.
860 // WebRTC implementation will drop frames if pushed to quickly. Wait the 865 // WebRTC implementation will drop frames if pushed to quickly. Wait the
(...skipping 21 matching lines...) Expand all
882 EXPECT_TRUE(channel_->AddRecvStream( 887 EXPECT_TRUE(channel_->AddRecvStream(
883 cricket::StreamParams::CreateLegacy(2))); 888 cricket::StreamParams::CreateLegacy(2)));
884 EXPECT_TRUE(channel_->SetSink(2, &renderer2)); 889 EXPECT_TRUE(channel_->SetSink(2, &renderer2));
885 EXPECT_TRUE(channel_->AddSendStream( 890 EXPECT_TRUE(channel_->AddSendStream(
886 cricket::StreamParams::CreateLegacy(2))); 891 cricket::StreamParams::CreateLegacy(2)));
887 std::unique_ptr<cricket::FakeVideoCapturer> capturer2( 892 std::unique_ptr<cricket::FakeVideoCapturer> capturer2(
888 CreateFakeVideoCapturer()); 893 CreateFakeVideoCapturer());
889 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); 894 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format));
890 // State for all the streams. 895 // State for all the streams.
891 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 896 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
892 // A limitation in the lmi implementation requires that SetCapturer() is 897 // A limitation in the lmi implementation requires that SetVideoSend() is
893 // called after SetOneCodec(). 898 // called after SetOneCodec().
894 // TODO(hellner): this seems like an unnecessary constraint, fix it. 899 // TODO(hellner): this seems like an unnecessary constraint, fix it.
895 EXPECT_TRUE(channel_->SetCapturer(1, capturer1.get())); 900 EXPECT_TRUE(channel_->SetVideoSend(1, true, nullptr, capturer1.get()));
896 EXPECT_TRUE(channel_->SetCapturer(2, capturer2.get())); 901 EXPECT_TRUE(channel_->SetVideoSend(2, true, nullptr, capturer2.get()));
897 EXPECT_TRUE(SetSend(true)); 902 EXPECT_TRUE(SetSend(true));
898 // Test capturer associated with engine. 903 // Test capturer associated with engine.
899 const int kTestWidth = 160; 904 const int kTestWidth = 160;
900 const int kTestHeight = 120; 905 const int kTestHeight = 120;
901 EXPECT_TRUE(capturer1->CaptureCustomFrame( 906 EXPECT_TRUE(capturer1->CaptureCustomFrame(
902 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 907 kTestWidth, kTestHeight, cricket::FOURCC_I420));
903 EXPECT_FRAME_ON_RENDERER_WAIT( 908 EXPECT_FRAME_ON_RENDERER_WAIT(
904 renderer1, 1, kTestWidth, kTestHeight, kTimeout); 909 renderer1, 1, kTestWidth, kTestHeight, kTimeout);
905 // Capture a frame with additional capturer2, frames should be received 910 // Capture a frame with additional capturer2, frames should be received
906 EXPECT_TRUE(capturer2->CaptureCustomFrame( 911 EXPECT_TRUE(capturer2->CaptureCustomFrame(
907 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 912 kTestWidth, kTestHeight, cricket::FOURCC_I420));
908 EXPECT_FRAME_ON_RENDERER_WAIT( 913 EXPECT_FRAME_ON_RENDERER_WAIT(
909 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 914 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
910 // Successfully remove the capturer. 915 // Successfully remove the capturer.
911 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 916 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
912 // Fail to re-remove the capturer.
913 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL));
914 // The capturers must be unregistered here as it runs out of it's scope 917 // The capturers must be unregistered here as it runs out of it's scope
915 // next. 918 // next.
916 EXPECT_TRUE(channel_->SetCapturer(1, NULL)); 919 EXPECT_TRUE(channel_->SetVideoSend(1, true, nullptr, nullptr));
917 EXPECT_TRUE(channel_->SetCapturer(2, NULL)); 920 EXPECT_TRUE(channel_->SetVideoSend(2, true, nullptr, nullptr));
918 } 921 }
919 922
920 void HighAspectHighHeightCapturer() { 923 void HighAspectHighHeightCapturer() {
921 const int kWidth = 80; 924 const int kWidth = 80;
922 const int kHeight = 10000; 925 const int kHeight = 10000;
923 const int kScaledWidth = 20; 926 const int kScaledWidth = 20;
924 const int kScaledHeight = 2500; 927 const int kScaledHeight = 2500;
925 928
926 cricket::VideoCodec codec(DefaultCodec()); 929 cricket::VideoCodec codec(DefaultCodec());
927 EXPECT_TRUE(SetOneCodec(codec)); 930 EXPECT_TRUE(SetOneCodec(codec));
(...skipping 12 matching lines...) Expand all
940 // Registering an external capturer is currently the same as screen casting 943 // Registering an external capturer is currently the same as screen casting
941 // (update the test when this changes). 944 // (update the test when this changes).
942 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 945 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
943 CreateFakeVideoCapturer()); 946 CreateFakeVideoCapturer());
944 const std::vector<cricket::VideoFormat>* formats = 947 const std::vector<cricket::VideoFormat>* formats =
945 capturer->GetSupportedFormats(); 948 capturer->GetSupportedFormats();
946 cricket::VideoFormat capture_format = (*formats)[0]; 949 cricket::VideoFormat capture_format = (*formats)[0];
947 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); 950 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format));
948 // Capture frame to not get same frame timestamps as previous capturer. 951 // Capture frame to not get same frame timestamps as previous capturer.
949 capturer->CaptureFrame(); 952 capturer->CaptureFrame();
950 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); 953 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, capturer.get()));
951 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); 954 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
952 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, 955 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight,
953 cricket::FOURCC_ARGB)); 956 cricket::FOURCC_ARGB));
954 EXPECT_GT_FRAME_ON_RENDERER_WAIT( 957 EXPECT_GT_FRAME_ON_RENDERER_WAIT(
955 renderer, 2, kScaledWidth, kScaledHeight, kTimeout); 958 renderer, 2, kScaledWidth, kScaledHeight, kTimeout);
956 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 959 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
957 } 960 }
958 961
959 // Tests that we can adapt video resolution with 16:10 aspect ratio properly. 962 // Tests that we can adapt video resolution with 16:10 aspect ratio properly.
960 void AdaptResolution16x10() { 963 void AdaptResolution16x10() {
961 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 964 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
962 cricket::VideoCodec codec(DefaultCodec()); 965 cricket::VideoCodec codec(DefaultCodec());
963 codec.width = 640; 966 codec.width = 640;
964 codec.height = 400; 967 codec.height = 400;
965 SendAndReceive(codec); 968 SendAndReceive(codec);
966 codec.width /= 2; 969 codec.width /= 2;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 1069
1067 // Tests that we can mute and unmute the channel properly. 1070 // Tests that we can mute and unmute the channel properly.
1068 void MuteStream() { 1071 void MuteStream() {
1069 EXPECT_TRUE(SetDefaultCodec()); 1072 EXPECT_TRUE(SetDefaultCodec());
1070 cricket::FakeVideoCapturer video_capturer; 1073 cricket::FakeVideoCapturer video_capturer;
1071 video_capturer.Start( 1074 video_capturer.Start(
1072 cricket::VideoFormat( 1075 cricket::VideoFormat(
1073 640, 480, 1076 640, 480,
1074 cricket::VideoFormat::FpsToInterval(30), 1077 cricket::VideoFormat::FpsToInterval(30),
1075 cricket::FOURCC_I420)); 1078 cricket::FOURCC_I420));
1076 EXPECT_TRUE(channel_->SetCapturer(kSsrc, &video_capturer)); 1079 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, &video_capturer));
1077 EXPECT_TRUE(SetSend(true)); 1080 EXPECT_TRUE(SetSend(true));
1078 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 1081 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
1079 EXPECT_EQ(0, renderer_.num_rendered_frames()); 1082 EXPECT_EQ(0, renderer_.num_rendered_frames());
1080 // Mute the channel and expect black output frame. 1083 // Mute the channel and expect black output frame.
1081 int frame_count = 0; 1084 int frame_count = 0;
1082 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); 1085 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr, &video_capturer));
1083 EXPECT_TRUE(video_capturer.CaptureFrame()); 1086 EXPECT_TRUE(video_capturer.CaptureFrame());
1084 ++frame_count; 1087 ++frame_count;
1085 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); 1088 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1086 EXPECT_TRUE(renderer_.black_frame()); 1089 EXPECT_TRUE(renderer_.black_frame());
1087 // Unmute the channel and expect non-black output frame. 1090 // Unmute the channel and expect non-black output frame.
1088 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); 1091 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, &video_capturer));
1089 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); 1092 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
1090 EXPECT_TRUE(video_capturer.CaptureFrame()); 1093 EXPECT_TRUE(video_capturer.CaptureFrame());
1091 ++frame_count; 1094 ++frame_count;
1092 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); 1095 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1093 EXPECT_FALSE(renderer_.black_frame()); 1096 EXPECT_FALSE(renderer_.black_frame());
1094 // Test that we can also Mute using the correct send stream SSRC. 1097 // Test that we can also Mute using the correct send stream SSRC.
1095 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); 1098 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr, &video_capturer));
1096 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); 1099 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
1097 EXPECT_TRUE(video_capturer.CaptureFrame()); 1100 EXPECT_TRUE(video_capturer.CaptureFrame());
1098 ++frame_count; 1101 ++frame_count;
1099 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); 1102 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1100 EXPECT_TRUE(renderer_.black_frame()); 1103 EXPECT_TRUE(renderer_.black_frame());
1101 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); 1104 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, &video_capturer));
1102 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); 1105 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
1103 EXPECT_TRUE(video_capturer.CaptureFrame()); 1106 EXPECT_TRUE(video_capturer.CaptureFrame());
1104 ++frame_count; 1107 ++frame_count;
1105 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); 1108 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1106 EXPECT_FALSE(renderer_.black_frame()); 1109 EXPECT_FALSE(renderer_.black_frame());
1107 // Test that muting an existing stream succeeds even if it's muted. 1110 // Test that muting an existing stream succeeds even if it's muted.
1108 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); 1111 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr, &video_capturer));
1109 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); 1112 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr, &video_capturer));
1110 // Test that unmuting an existing stream succeeds even if it's not muted. 1113 // Test that unmuting an existing stream succeeds even if it's not muted.
1111 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); 1114 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, &video_capturer));
1112 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); 1115 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, &video_capturer));
1113 // Test that muting an invalid stream fails. 1116 // Test that muting an invalid stream fails.
1114 EXPECT_FALSE(channel_->SetVideoSend(kSsrc+1, false, nullptr)); 1117 EXPECT_FALSE(
1115 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 1118 channel_->SetVideoSend(kSsrc + 1, false, nullptr, &video_capturer));
1119 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr, nullptr));
1116 } 1120 }
1117 1121
1118 // Test that multiple send streams can be created and deleted properly. 1122 // Test that multiple send streams can be created and deleted properly.
1119 void MultipleSendStreams() { 1123 void MultipleSendStreams() {
1120 // Remove stream added in Setup. I.e. remove stream corresponding to default 1124 // Remove stream added in Setup. I.e. remove stream corresponding to default
1121 // channel. 1125 // channel.
1122 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 1126 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1123 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); 1127 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]);
1124 for (unsigned int i = 0; i < kSsrcsSize; ++i) { 1128 for (unsigned int i = 0; i < kSsrcsSize; ++i) {
1125 EXPECT_TRUE(channel_->AddSendStream( 1129 EXPECT_TRUE(channel_->AddSendStream(
(...skipping 26 matching lines...) Expand all
1152 std::unique_ptr<C> channel_; 1156 std::unique_ptr<C> channel_;
1153 cricket::FakeNetworkInterface network_interface_; 1157 cricket::FakeNetworkInterface network_interface_;
1154 cricket::FakeVideoRenderer renderer_; 1158 cricket::FakeVideoRenderer renderer_;
1155 cricket::VideoMediaChannel::Error media_error_; 1159 cricket::VideoMediaChannel::Error media_error_;
1156 1160
1157 // Used by test cases where 2 streams are run on the same channel. 1161 // Used by test cases where 2 streams are run on the same channel.
1158 cricket::FakeVideoRenderer renderer2_; 1162 cricket::FakeVideoRenderer renderer2_;
1159 }; 1163 };
1160 1164
1161 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT 1165 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698