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

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

Issue 1766653002: Replace SetCapturer and SetCaptureDevice by SetSource. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased, no longer any proxy object changes. 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
« 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return s; 67 return s;
68 } 68 }
69 } // namespace std 69 } // namespace std
70 70
71 inline int TimeBetweenSend(const cricket::VideoCodec& codec) { 71 inline int TimeBetweenSend(const cricket::VideoCodec& codec) {
72 return static_cast<int>( 72 return static_cast<int>(
73 cricket::VideoFormat::FpsToInterval(codec.framerate) / 73 cricket::VideoFormat::FpsToInterval(codec.framerate) /
74 rtc::kNumNanosecsPerMillisec); 74 rtc::kNumNanosecsPerMillisec);
75 } 75 }
76 76
77 // Fake video engine that makes it possible to test enabling and disabling
78 // capturer (checking that the engine state is updated and that the capturer
79 // is indeed capturing) without having to create a channel. It also makes it
80 // possible to test that the media processors are indeed being called when
81 // registered.
82 template<class T>
83 class VideoEngineOverride : public T {
84 public:
85 VideoEngineOverride() : T() {
86 }
87 virtual ~VideoEngineOverride() {
88 }
89 bool is_camera_on() const { return T::GetVideoCapturer()->IsRunning(); }
90
91 void TriggerMediaFrame(uint32_t ssrc,
92 cricket::VideoFrame* frame,
93 bool* drop_frame) {
94 T::SignalMediaFrame(ssrc, frame, drop_frame);
95 }
96 };
97
98 template<class E, class C> 77 template<class E, class C>
99 class VideoMediaChannelTest : public testing::Test, 78 class VideoMediaChannelTest : public testing::Test,
100 public sigslot::has_slots<> { 79 public sigslot::has_slots<> {
101 protected: 80 protected:
102 VideoMediaChannelTest<E, C>() 81 VideoMediaChannelTest<E, C>()
103 : call_(webrtc::Call::Create(webrtc::Call::Config())) {} 82 : call_(webrtc::Call::Create(webrtc::Call::Config())) {}
104 83
105 virtual cricket::VideoCodec DefaultCodec() = 0; 84 virtual cricket::VideoCodec DefaultCodec() = 0;
106 85
107 virtual cricket::StreamParams DefaultSendStreamParams() { 86 virtual cricket::StreamParams DefaultSendStreamParams() {
(...skipping 10 matching lines...) Expand all
118 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; 97 media_error_ = cricket::VideoMediaChannel::ERROR_NONE;
119 cricket::VideoRecvParameters parameters; 98 cricket::VideoRecvParameters parameters;
120 parameters.codecs = engine_.codecs(); 99 parameters.codecs = engine_.codecs();
121 channel_->SetRecvParameters(parameters); 100 channel_->SetRecvParameters(parameters);
122 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); 101 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams()));
123 video_capturer_.reset(CreateFakeVideoCapturer()); 102 video_capturer_.reset(CreateFakeVideoCapturer());
124 cricket::VideoFormat format(640, 480, 103 cricket::VideoFormat format(640, 480,
125 cricket::VideoFormat::FpsToInterval(30), 104 cricket::VideoFormat::FpsToInterval(30),
126 cricket::FOURCC_I420); 105 cricket::FOURCC_I420);
127 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); 106 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format));
128 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); 107 channel_->SetSource(kSsrc, video_capturer_.get());
129 } 108 }
130 109
131 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() { 110 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() {
132 return new cricket::FakeVideoCapturer(); 111 return new cricket::FakeVideoCapturer();
133 } 112 }
134 113
135 // Utility method to setup an additional stream to send and receive video. 114 // Utility method to setup an additional stream to send and receive video.
136 // Used to test send and recv between two streams. 115 // Used to test send and recv between two streams.
137 void SetUpSecondStream() { 116 void SetUpSecondStream() {
138 SetUpSecondStreamWithNoRecv(); 117 SetUpSecondStreamWithNoRecv();
(...skipping 16 matching lines...) Expand all
155 cricket::StreamParams::CreateLegacy(kSsrc + 2))); 134 cricket::StreamParams::CreateLegacy(kSsrc + 2)));
156 // We dont add recv for the second stream. 135 // We dont add recv for the second stream.
157 136
158 // Setup the receive and renderer for second stream after send. 137 // Setup the receive and renderer for second stream after send.
159 video_capturer_2_.reset(CreateFakeVideoCapturer()); 138 video_capturer_2_.reset(CreateFakeVideoCapturer());
160 cricket::VideoFormat format(640, 480, 139 cricket::VideoFormat format(640, 480,
161 cricket::VideoFormat::FpsToInterval(30), 140 cricket::VideoFormat::FpsToInterval(30),
162 cricket::FOURCC_I420); 141 cricket::FOURCC_I420);
163 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); 142 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format));
164 143
165 EXPECT_TRUE(channel_->SetCapturer(kSsrc + 2, video_capturer_2_.get())); 144 channel_->SetSource(kSsrc + 2, video_capturer_2_.get());
166 } 145 }
167 virtual void TearDown() { 146 virtual void TearDown() {
168 channel_.reset(); 147 channel_.reset();
169 } 148 }
170 bool SetDefaultCodec() { 149 bool SetDefaultCodec() {
171 return SetOneCodec(DefaultCodec()); 150 return SetOneCodec(DefaultCodec());
172 } 151 }
173 152
174 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) { 153 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) {
175 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0)); 154 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0));
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 345 }
367 346
368 void OnVideoChannelError(uint32_t ssrc, 347 void OnVideoChannelError(uint32_t ssrc,
369 cricket::VideoMediaChannel::Error error) { 348 cricket::VideoMediaChannel::Error error) {
370 media_error_ = error; 349 media_error_ = error;
371 } 350 }
372 351
373 // Test that SetSend works. 352 // Test that SetSend works.
374 void SetSend() { 353 void SetSend() {
375 EXPECT_FALSE(channel_->sending()); 354 EXPECT_FALSE(channel_->sending());
376 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); 355 channel_->SetSource(kSsrc, video_capturer_.get());
377 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 356 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
378 EXPECT_FALSE(channel_->sending()); 357 EXPECT_FALSE(channel_->sending());
379 EXPECT_TRUE(SetSend(true)); 358 EXPECT_TRUE(SetSend(true));
380 EXPECT_TRUE(channel_->sending()); 359 EXPECT_TRUE(channel_->sending());
381 EXPECT_TRUE(SendFrame()); 360 EXPECT_TRUE(SendFrame());
382 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 361 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
383 EXPECT_TRUE(SetSend(false)); 362 EXPECT_TRUE(SetSend(false));
384 EXPECT_FALSE(channel_->sending()); 363 EXPECT_FALSE(channel_->sending());
385 } 364 }
386 // Test that SetSend fails without codecs being set. 365 // Test that SetSend fails without codecs being set.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 539 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
561 CreateFakeVideoCapturer()); 540 CreateFakeVideoCapturer());
562 const int kTestWidth = 160; 541 const int kTestWidth = 160;
563 const int kTestHeight = 120; 542 const int kTestHeight = 120;
564 cricket::VideoFormat format(kTestWidth, kTestHeight, 543 cricket::VideoFormat format(kTestWidth, kTestHeight,
565 cricket::VideoFormat::FpsToInterval(5), 544 cricket::VideoFormat::FpsToInterval(5),
566 cricket::FOURCC_I420); 545 cricket::FOURCC_I420);
567 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); 546 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
568 EXPECT_TRUE(channel_->AddSendStream( 547 EXPECT_TRUE(channel_->AddSendStream(
569 cricket::StreamParams::CreateLegacy(5678))); 548 cricket::StreamParams::CreateLegacy(5678)));
570 EXPECT_TRUE(channel_->SetCapturer(5678, capturer.get())); 549 channel_->SetSource(5678, capturer.get());
571 EXPECT_TRUE(channel_->AddRecvStream( 550 EXPECT_TRUE(channel_->AddRecvStream(
572 cricket::StreamParams::CreateLegacy(5678))); 551 cricket::StreamParams::CreateLegacy(5678)));
573 EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); 552 EXPECT_TRUE(channel_->SetSink(5678, &renderer2));
574 EXPECT_TRUE(capturer->CaptureCustomFrame( 553 EXPECT_TRUE(capturer->CaptureCustomFrame(
575 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 554 kTestWidth, kTestHeight, cricket::FOURCC_I420));
576 EXPECT_FRAME_ON_RENDERER_WAIT( 555 EXPECT_FRAME_ON_RENDERER_WAIT(
577 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 556 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
578 557
579 // Get stats, and make sure they are correct for two senders. We wait until 558 // Get stats, and make sure they are correct for two senders. We wait until
580 // the number of expected packets have been sent to avoid races where we 559 // the number of expected packets have been sent to avoid races where we
(...skipping 15 matching lines...) Expand all
596 << "Timed out while waiting for packet counts for all sent packets."; 575 << "Timed out while waiting for packet counts for all sent packets.";
597 EXPECT_EQ(1U, info.senders[0].ssrcs().size()); 576 EXPECT_EQ(1U, info.senders[0].ssrcs().size());
598 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); 577 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]);
599 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); 578 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width);
600 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); 579 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height);
601 EXPECT_EQ(1U, info.senders[1].ssrcs().size()); 580 EXPECT_EQ(1U, info.senders[1].ssrcs().size());
602 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); 581 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]);
603 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); 582 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width);
604 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); 583 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height);
605 // The capturer must be unregistered here as it runs out of it's scope next. 584 // The capturer must be unregistered here as it runs out of it's scope next.
606 EXPECT_TRUE(channel_->SetCapturer(5678, NULL)); 585 channel_->SetSource(5678, NULL);
607 } 586 }
608 587
609 // Test that we can set the bandwidth. 588 // Test that we can set the bandwidth.
610 void SetSendBandwidth() { 589 void SetSendBandwidth() {
611 cricket::VideoSendParameters parameters; 590 cricket::VideoSendParameters parameters;
612 parameters.codecs.push_back(DefaultCodec()); 591 parameters.codecs.push_back(DefaultCodec());
613 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. 592 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited.
614 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 593 EXPECT_TRUE(channel_->SetSendParameters(parameters));
615 parameters.max_bandwidth_bps = 128 * 1024; 594 parameters.max_bandwidth_bps = 128 * 1024;
616 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 595 EXPECT_TRUE(channel_->SetSendParameters(parameters));
(...skipping 16 matching lines...) Expand all
633 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); 612 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1));
634 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); 613 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1));
635 } 614 }
636 // Test that we can set the SSRC even after codecs are set. 615 // Test that we can set the SSRC even after codecs are set.
637 void SetSendSsrcAfterSetCodecs() { 616 void SetSendSsrcAfterSetCodecs() {
638 // Remove stream added in Setup. 617 // Remove stream added in Setup.
639 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 618 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
640 EXPECT_TRUE(SetDefaultCodec()); 619 EXPECT_TRUE(SetDefaultCodec());
641 EXPECT_TRUE(channel_->AddSendStream( 620 EXPECT_TRUE(channel_->AddSendStream(
642 cricket::StreamParams::CreateLegacy(999))); 621 cricket::StreamParams::CreateLegacy(999)));
643 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); 622 channel_->SetSource(999u, video_capturer_.get());
644 EXPECT_TRUE(SetSend(true)); 623 EXPECT_TRUE(SetSend(true));
645 EXPECT_TRUE(WaitAndSendFrame(0)); 624 EXPECT_TRUE(WaitAndSendFrame(0));
646 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); 625 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
647 uint32_t ssrc = 0; 626 uint32_t ssrc = 0;
648 std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); 627 std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0));
649 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 628 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
650 EXPECT_EQ(999u, ssrc); 629 EXPECT_EQ(999u, ssrc);
651 // Packets are being paced out, so these can mismatch between the first and 630 // Packets are being paced out, so these can mismatch between the first and
652 // second call to NumRtpPackets until pending packets are paced out. 631 // second call to NumRtpPackets until pending packets are paced out.
653 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); 632 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 p(GetRtpPacket(static_cast<int>(last_packet))); 678 p(GetRtpPacket(static_cast<int>(last_packet)));
700 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 679 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
701 EXPECT_EQ(kSsrc, ssrc); 680 EXPECT_EQ(kSsrc, ssrc);
702 681
703 // Remove the send stream that was added during Setup. 682 // Remove the send stream that was added during Setup.
704 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 683 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
705 int rtp_packets = NumRtpPackets(); 684 int rtp_packets = NumRtpPackets();
706 685
707 EXPECT_TRUE(channel_->AddSendStream( 686 EXPECT_TRUE(channel_->AddSendStream(
708 cricket::StreamParams::CreateLegacy(789u))); 687 cricket::StreamParams::CreateLegacy(789u)));
709 EXPECT_TRUE(channel_->SetCapturer(789u, video_capturer_.get())); 688 channel_->SetSource(789u, video_capturer_.get());
710 EXPECT_EQ(rtp_packets, NumRtpPackets()); 689 EXPECT_EQ(rtp_packets, NumRtpPackets());
711 // Wait 30ms to guarantee the engine does not drop the frame. 690 // Wait 30ms to guarantee the engine does not drop the frame.
712 EXPECT_TRUE(WaitAndSendFrame(30)); 691 EXPECT_TRUE(WaitAndSendFrame(30));
713 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); 692 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout);
714 693
715 last_packet = NumRtpPackets() - 1; 694 last_packet = NumRtpPackets() - 1;
716 p.reset(GetRtpPacket(static_cast<int>(last_packet))); 695 p.reset(GetRtpPacket(static_cast<int>(last_packet)));
717 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); 696 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
718 EXPECT_EQ(789u, ssrc); 697 EXPECT_EQ(789u, ssrc);
719 } 698 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 cricket::FOURCC_I420); 761 cricket::FOURCC_I420);
783 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); 762 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
784 // All capturers start generating frames with the same timestamp. ViE does 763 // All capturers start generating frames with the same timestamp. ViE does
785 // not allow the same timestamp to be used. Capture one frame before 764 // not allow the same timestamp to be used. Capture one frame before
786 // associating the capturer with the channel. 765 // associating the capturer with the channel.
787 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 766 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
788 cricket::FOURCC_I420)); 767 cricket::FOURCC_I420));
789 768
790 int captured_frames = 1; 769 int captured_frames = 1;
791 for (int iterations = 0; iterations < 2; ++iterations) { 770 for (int iterations = 0; iterations < 2; ++iterations) {
792 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); 771 channel_->SetSource(kSsrc, capturer.get());
793 rtc::Thread::Current()->ProcessMessages(time_between_send); 772 rtc::Thread::Current()->ProcessMessages(time_between_send);
794 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, 773 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
795 cricket::FOURCC_I420)); 774 cricket::FOURCC_I420));
796 ++captured_frames; 775 ++captured_frames;
797 // Wait until frame of right size is captured. 776 // Wait until frame of right size is captured.
798 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && 777 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
799 format.width == renderer_.width() && 778 format.width == renderer_.width() &&
800 format.height == renderer_.height() && 779 format.height == renderer_.height() &&
801 !renderer_.black_frame(), kTimeout); 780 !renderer_.black_frame(), kTimeout);
802 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); 781 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
803 EXPECT_EQ(format.width, renderer_.width()); 782 EXPECT_EQ(format.width, renderer_.width());
804 EXPECT_EQ(format.height, renderer_.height()); 783 EXPECT_EQ(format.height, renderer_.height());
805 captured_frames = renderer_.num_rendered_frames() + 1; 784 captured_frames = renderer_.num_rendered_frames() + 1;
806 EXPECT_FALSE(renderer_.black_frame()); 785 EXPECT_FALSE(renderer_.black_frame());
807 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 786 channel_->SetSource(kSsrc, NULL);
808 // Make sure a black frame is generated within the specified timeout. 787 // Make sure a black frame is generated within the specified timeout.
809 // The black frame should be the resolution of the previous frame to 788 // The black frame should be the resolution of the previous frame to
810 // prevent expensive encoder reconfigurations. 789 // prevent expensive encoder reconfigurations.
811 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && 790 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
812 format.width == renderer_.width() && 791 format.width == renderer_.width() &&
813 format.height == renderer_.height() && 792 format.height == renderer_.height() &&
814 renderer_.black_frame(), kTimeout); 793 renderer_.black_frame(), kTimeout);
815 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); 794 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
816 EXPECT_EQ(format.width, renderer_.width()); 795 EXPECT_EQ(format.width, renderer_.width());
817 EXPECT_EQ(format.height, renderer_.height()); 796 EXPECT_EQ(format.height, renderer_.height());
(...skipping 14 matching lines...) Expand all
832 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 811 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
833 EXPECT_TRUE(SetSend(true)); 812 EXPECT_TRUE(SetSend(true));
834 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 813 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
835 EXPECT_EQ(0, renderer_.num_rendered_frames()); 814 EXPECT_EQ(0, renderer_.num_rendered_frames());
836 EXPECT_TRUE(SendFrame()); 815 EXPECT_TRUE(SendFrame());
837 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); 816 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout);
838 // Wait for one frame so they don't get dropped because we send frames too 817 // Wait for one frame so they don't get dropped because we send frames too
839 // tightly. 818 // tightly.
840 rtc::Thread::Current()->ProcessMessages(30); 819 rtc::Thread::Current()->ProcessMessages(30);
841 // Remove the capturer. 820 // Remove the capturer.
842 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 821 channel_->SetSource(kSsrc, NULL);
843 // Wait for one black frame for removing the capturer. 822 // Wait for one black frame for removing the capturer.
844 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); 823 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout);
845 824
846 // No capturer was added, so this RemoveCapturer should 825 // No capturer was added, so this SetSource should be a NOP.
847 // fail. 826 channel_->SetSource(kSsrc, NULL);
848 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL));
849 rtc::Thread::Current()->ProcessMessages(300); 827 rtc::Thread::Current()->ProcessMessages(300);
850 // Verify no more frames were sent. 828 // Verify no more frames were sent.
851 EXPECT_EQ(2, renderer_.num_rendered_frames()); 829 EXPECT_EQ(2, renderer_.num_rendered_frames());
852 } 830 }
853 831
854 // Tests that we can add and remove capturer as unique sources. 832 // Tests that we can add and remove capturer as unique sources.
855 void AddRemoveCapturerMultipleSources() { 833 void AddRemoveCapturerMultipleSources() {
856 // WebRTC implementation will drop frames if pushed to quickly. Wait the 834 // WebRTC implementation will drop frames if pushed to quickly. Wait the
857 // interval time to avoid that. 835 // interval time to avoid that.
858 // WebRTC implementation will drop frames if pushed to quickly. Wait the 836 // WebRTC implementation will drop frames if pushed to quickly. Wait the
(...skipping 21 matching lines...) Expand all
880 EXPECT_TRUE(channel_->AddRecvStream( 858 EXPECT_TRUE(channel_->AddRecvStream(
881 cricket::StreamParams::CreateLegacy(2))); 859 cricket::StreamParams::CreateLegacy(2)));
882 EXPECT_TRUE(channel_->SetSink(2, &renderer2)); 860 EXPECT_TRUE(channel_->SetSink(2, &renderer2));
883 EXPECT_TRUE(channel_->AddSendStream( 861 EXPECT_TRUE(channel_->AddSendStream(
884 cricket::StreamParams::CreateLegacy(2))); 862 cricket::StreamParams::CreateLegacy(2)));
885 std::unique_ptr<cricket::FakeVideoCapturer> capturer2( 863 std::unique_ptr<cricket::FakeVideoCapturer> capturer2(
886 CreateFakeVideoCapturer()); 864 CreateFakeVideoCapturer());
887 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); 865 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format));
888 // State for all the streams. 866 // State for all the streams.
889 EXPECT_TRUE(SetOneCodec(DefaultCodec())); 867 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
890 // A limitation in the lmi implementation requires that SetCapturer() is 868 // A limitation in the lmi implementation requires that SetSource() is
891 // called after SetOneCodec(). 869 // called after SetOneCodec().
892 // TODO(hellner): this seems like an unnecessary constraint, fix it. 870 // TODO(hellner): this seems like an unnecessary constraint, fix it.
893 EXPECT_TRUE(channel_->SetCapturer(1, capturer1.get())); 871 channel_->SetSource(1, capturer1.get());
894 EXPECT_TRUE(channel_->SetCapturer(2, capturer2.get())); 872 channel_->SetSource(2, capturer2.get());
895 EXPECT_TRUE(SetSend(true)); 873 EXPECT_TRUE(SetSend(true));
896 // Test capturer associated with engine. 874 // Test capturer associated with engine.
897 const int kTestWidth = 160; 875 const int kTestWidth = 160;
898 const int kTestHeight = 120; 876 const int kTestHeight = 120;
899 EXPECT_TRUE(capturer1->CaptureCustomFrame( 877 EXPECT_TRUE(capturer1->CaptureCustomFrame(
900 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 878 kTestWidth, kTestHeight, cricket::FOURCC_I420));
901 EXPECT_FRAME_ON_RENDERER_WAIT( 879 EXPECT_FRAME_ON_RENDERER_WAIT(
902 renderer1, 1, kTestWidth, kTestHeight, kTimeout); 880 renderer1, 1, kTestWidth, kTestHeight, kTimeout);
903 // Capture a frame with additional capturer2, frames should be received 881 // Capture a frame with additional capturer2, frames should be received
904 EXPECT_TRUE(capturer2->CaptureCustomFrame( 882 EXPECT_TRUE(capturer2->CaptureCustomFrame(
905 kTestWidth, kTestHeight, cricket::FOURCC_I420)); 883 kTestWidth, kTestHeight, cricket::FOURCC_I420));
906 EXPECT_FRAME_ON_RENDERER_WAIT( 884 EXPECT_FRAME_ON_RENDERER_WAIT(
907 renderer2, 1, kTestWidth, kTestHeight, kTimeout); 885 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
908 // Successfully remove the capturer. 886 // Successfully remove the capturer.
909 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 887 channel_->SetSource(kSsrc, NULL);
910 // Fail to re-remove the capturer. 888 // Fail to re-remove the capturer.
911 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL)); 889 channel_->SetSource(kSsrc, NULL);
912 // The capturers must be unregistered here as it runs out of it's scope 890 // The capturers must be unregistered here as it runs out of it's scope
913 // next. 891 // next.
914 EXPECT_TRUE(channel_->SetCapturer(1, NULL)); 892 channel_->SetSource(1, NULL);
915 EXPECT_TRUE(channel_->SetCapturer(2, NULL)); 893 channel_->SetSource(2, NULL);
916 } 894 }
917 895
918 void HighAspectHighHeightCapturer() { 896 void HighAspectHighHeightCapturer() {
919 const int kWidth = 80; 897 const int kWidth = 80;
920 const int kHeight = 10000; 898 const int kHeight = 10000;
921 const int kScaledWidth = 20; 899 const int kScaledWidth = 20;
922 const int kScaledHeight = 2500; 900 const int kScaledHeight = 2500;
923 901
924 cricket::VideoCodec codec(DefaultCodec()); 902 cricket::VideoCodec codec(DefaultCodec());
925 EXPECT_TRUE(SetOneCodec(codec)); 903 EXPECT_TRUE(SetOneCodec(codec));
(...skipping 12 matching lines...) Expand all
938 // Registering an external capturer is currently the same as screen casting 916 // Registering an external capturer is currently the same as screen casting
939 // (update the test when this changes). 917 // (update the test when this changes).
940 std::unique_ptr<cricket::FakeVideoCapturer> capturer( 918 std::unique_ptr<cricket::FakeVideoCapturer> capturer(
941 CreateFakeVideoCapturer()); 919 CreateFakeVideoCapturer());
942 const std::vector<cricket::VideoFormat>* formats = 920 const std::vector<cricket::VideoFormat>* formats =
943 capturer->GetSupportedFormats(); 921 capturer->GetSupportedFormats();
944 cricket::VideoFormat capture_format = (*formats)[0]; 922 cricket::VideoFormat capture_format = (*formats)[0];
945 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); 923 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format));
946 // Capture frame to not get same frame timestamps as previous capturer. 924 // Capture frame to not get same frame timestamps as previous capturer.
947 capturer->CaptureFrame(); 925 capturer->CaptureFrame();
948 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); 926 channel_->SetSource(kSsrc, capturer.get());
949 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); 927 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
950 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, 928 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight,
951 cricket::FOURCC_ARGB)); 929 cricket::FOURCC_ARGB));
952 EXPECT_GT_FRAME_ON_RENDERER_WAIT( 930 EXPECT_GT_FRAME_ON_RENDERER_WAIT(
953 renderer, 2, kScaledWidth, kScaledHeight, kTimeout); 931 renderer, 2, kScaledWidth, kScaledHeight, kTimeout);
954 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 932 channel_->SetSource(kSsrc, NULL);
955 } 933 }
956 934
957 // Tests that we can adapt video resolution with 16:10 aspect ratio properly. 935 // Tests that we can adapt video resolution with 16:10 aspect ratio properly.
958 void AdaptResolution16x10() { 936 void AdaptResolution16x10() {
959 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); 937 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
960 cricket::VideoCodec codec(DefaultCodec()); 938 cricket::VideoCodec codec(DefaultCodec());
961 codec.width = 640; 939 codec.width = 640;
962 codec.height = 400; 940 codec.height = 400;
963 SendAndReceive(codec); 941 SendAndReceive(codec);
964 codec.width /= 2; 942 codec.width /= 2;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 EXPECT_TRUE(SendFrame()); 1033 EXPECT_TRUE(SendFrame());
1056 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); 1034 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1057 1035
1058 // Check that we send smaller frames at the new resolution. 1036 // Check that we send smaller frames at the new resolution.
1059 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(33)); 1037 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(33));
1060 EXPECT_TRUE(video_capturer_->CaptureCustomFrame( 1038 EXPECT_TRUE(video_capturer_->CaptureCustomFrame(
1061 codec.width / 2, codec.height / 2, cricket::FOURCC_I420)); 1039 codec.width / 2, codec.height / 2, cricket::FOURCC_I420));
1062 EXPECT_FRAME_WAIT(2, codec.width / 2, codec.height / 2, kTimeout); 1040 EXPECT_FRAME_WAIT(2, codec.width / 2, codec.height / 2, kTimeout);
1063 } 1041 }
1064 1042
1065 // Tests that we can mute and unmute the channel properly.
1066 void MuteStream() {
1067 EXPECT_TRUE(SetDefaultCodec());
1068 cricket::FakeVideoCapturer video_capturer;
1069 video_capturer.Start(
1070 cricket::VideoFormat(
1071 640, 480,
1072 cricket::VideoFormat::FpsToInterval(30),
1073 cricket::FOURCC_I420));
1074 EXPECT_TRUE(channel_->SetCapturer(kSsrc, &video_capturer));
1075 EXPECT_TRUE(SetSend(true));
1076 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_));
1077 EXPECT_EQ(0, renderer_.num_rendered_frames());
1078 // Mute the channel and expect black output frame.
1079 int frame_count = 0;
1080 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr));
1081 EXPECT_TRUE(video_capturer.CaptureFrame());
1082 ++frame_count;
1083 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1084 EXPECT_TRUE(renderer_.black_frame());
1085 // Unmute the channel and expect non-black output frame.
1086 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr));
1087 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
1088 EXPECT_TRUE(video_capturer.CaptureFrame());
1089 ++frame_count;
1090 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1091 EXPECT_FALSE(renderer_.black_frame());
1092 // Test that we can also Mute using the correct send stream SSRC.
1093 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr));
1094 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
1095 EXPECT_TRUE(video_capturer.CaptureFrame());
1096 ++frame_count;
1097 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1098 EXPECT_TRUE(renderer_.black_frame());
1099 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr));
1100 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30));
1101 EXPECT_TRUE(video_capturer.CaptureFrame());
1102 ++frame_count;
1103 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1104 EXPECT_FALSE(renderer_.black_frame());
1105 // Test that muting an existing stream succeeds even if it's muted.
1106 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr));
1107 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr));
1108 // Test that unmuting an existing stream succeeds even if it's not muted.
1109 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr));
1110 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr));
1111 // Test that muting an invalid stream fails.
1112 EXPECT_FALSE(channel_->SetVideoSend(kSsrc+1, false, nullptr));
1113 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
1114 }
1115
1116 // Test that multiple send streams can be created and deleted properly. 1043 // Test that multiple send streams can be created and deleted properly.
1117 void MultipleSendStreams() { 1044 void MultipleSendStreams() {
1118 // Remove stream added in Setup. I.e. remove stream corresponding to default 1045 // Remove stream added in Setup. I.e. remove stream corresponding to default
1119 // channel. 1046 // channel.
1120 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); 1047 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1121 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); 1048 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]);
1122 for (unsigned int i = 0; i < kSsrcsSize; ++i) { 1049 for (unsigned int i = 0; i < kSsrcsSize; ++i) {
1123 EXPECT_TRUE(channel_->AddSendStream( 1050 EXPECT_TRUE(channel_->AddSendStream(
1124 cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); 1051 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1125 } 1052 }
(...skipping 11 matching lines...) Expand all
1137 SetUpSecondStream(); 1064 SetUpSecondStream();
1138 // Test sending and receiving on first stream. 1065 // Test sending and receiving on first stream.
1139 SendAndReceive(codec); 1066 SendAndReceive(codec);
1140 // Test sending and receiving on second stream. 1067 // Test sending and receiving on second stream.
1141 EXPECT_EQ_WAIT(1, renderer2_.num_rendered_frames(), kTimeout); 1068 EXPECT_EQ_WAIT(1, renderer2_.num_rendered_frames(), kTimeout);
1142 EXPECT_GT(NumRtpPackets(), 0); 1069 EXPECT_GT(NumRtpPackets(), 0);
1143 EXPECT_EQ(1, renderer2_.num_rendered_frames()); 1070 EXPECT_EQ(1, renderer2_.num_rendered_frames());
1144 } 1071 }
1145 1072
1146 const std::unique_ptr<webrtc::Call> call_; 1073 const std::unique_ptr<webrtc::Call> call_;
1147 VideoEngineOverride<E> engine_; 1074 E engine_;
1148 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_; 1075 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_;
1149 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_2_; 1076 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_2_;
1150 std::unique_ptr<C> channel_; 1077 std::unique_ptr<C> channel_;
1151 cricket::FakeNetworkInterface network_interface_; 1078 cricket::FakeNetworkInterface network_interface_;
1152 cricket::FakeVideoRenderer renderer_; 1079 cricket::FakeVideoRenderer renderer_;
1153 cricket::VideoMediaChannel::Error media_error_; 1080 cricket::VideoMediaChannel::Error media_error_;
1154 1081
1155 // Used by test cases where 2 streams are run on the same channel. 1082 // Used by test cases where 2 streams are run on the same channel.
1156 cricket::FakeVideoRenderer renderer2_; 1083 cricket::FakeVideoRenderer renderer2_;
1157 }; 1084 };
1158 1085
1159 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT 1086 #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