| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; | 119 media_error_ = cricket::VideoMediaChannel::ERROR_NONE; |
| 120 cricket::VideoRecvParameters parameters; | 120 cricket::VideoRecvParameters parameters; |
| 121 parameters.codecs = engine_.codecs(); | 121 parameters.codecs = engine_.codecs(); |
| 122 channel_->SetRecvParameters(parameters); | 122 channel_->SetRecvParameters(parameters); |
| 123 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); | 123 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); |
| 124 video_capturer_.reset(CreateFakeVideoCapturer()); | 124 video_capturer_.reset(CreateFakeVideoCapturer()); |
| 125 cricket::VideoFormat format(640, 480, | 125 cricket::VideoFormat format(640, 480, |
| 126 cricket::VideoFormat::FpsToInterval(30), | 126 cricket::VideoFormat::FpsToInterval(30), |
| 127 cricket::FOURCC_I420); | 127 cricket::FOURCC_I420); |
| 128 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); | 128 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); |
| 129 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); | 129 channel_->SetSource(kSsrc, video_capturer_.get()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() { | 132 virtual cricket::FakeVideoCapturer* CreateFakeVideoCapturer() { |
| 133 return new cricket::FakeVideoCapturer(); | 133 return new cricket::FakeVideoCapturer(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // 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. |
| 137 // Used to test send and recv between two streams. | 137 // Used to test send and recv between two streams. |
| 138 void SetUpSecondStream() { | 138 void SetUpSecondStream() { |
| 139 SetUpSecondStreamWithNoRecv(); | 139 SetUpSecondStreamWithNoRecv(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 156 cricket::StreamParams::CreateLegacy(kSsrc + 2))); | 156 cricket::StreamParams::CreateLegacy(kSsrc + 2))); |
| 157 // We dont add recv for the second stream. | 157 // We dont add recv for the second stream. |
| 158 | 158 |
| 159 // Setup the receive and renderer for second stream after send. | 159 // Setup the receive and renderer for second stream after send. |
| 160 video_capturer_2_.reset(CreateFakeVideoCapturer()); | 160 video_capturer_2_.reset(CreateFakeVideoCapturer()); |
| 161 cricket::VideoFormat format(640, 480, | 161 cricket::VideoFormat format(640, 480, |
| 162 cricket::VideoFormat::FpsToInterval(30), | 162 cricket::VideoFormat::FpsToInterval(30), |
| 163 cricket::FOURCC_I420); | 163 cricket::FOURCC_I420); |
| 164 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); | 164 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); |
| 165 | 165 |
| 166 EXPECT_TRUE(channel_->SetCapturer(kSsrc + 2, video_capturer_2_.get())); | 166 channel_->SetSource(kSsrc + 2, video_capturer_2_.get()); |
| 167 } | 167 } |
| 168 virtual void TearDown() { | 168 virtual void TearDown() { |
| 169 channel_.reset(); | 169 channel_.reset(); |
| 170 } | 170 } |
| 171 bool SetDefaultCodec() { | 171 bool SetDefaultCodec() { |
| 172 return SetOneCodec(DefaultCodec()); | 172 return SetOneCodec(DefaultCodec()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) { | 175 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) { |
| 176 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0)); | 176 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0)); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 367 } |
| 368 | 368 |
| 369 void OnVideoChannelError(uint32_t ssrc, | 369 void OnVideoChannelError(uint32_t ssrc, |
| 370 cricket::VideoMediaChannel::Error error) { | 370 cricket::VideoMediaChannel::Error error) { |
| 371 media_error_ = error; | 371 media_error_ = error; |
| 372 } | 372 } |
| 373 | 373 |
| 374 // Test that SetSend works. | 374 // Test that SetSend works. |
| 375 void SetSend() { | 375 void SetSend() { |
| 376 EXPECT_FALSE(channel_->sending()); | 376 EXPECT_FALSE(channel_->sending()); |
| 377 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); | 377 channel_->SetSource(kSsrc, video_capturer_.get()); |
| 378 EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 378 EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 379 EXPECT_FALSE(channel_->sending()); | 379 EXPECT_FALSE(channel_->sending()); |
| 380 EXPECT_TRUE(SetSend(true)); | 380 EXPECT_TRUE(SetSend(true)); |
| 381 EXPECT_TRUE(channel_->sending()); | 381 EXPECT_TRUE(channel_->sending()); |
| 382 EXPECT_TRUE(SendFrame()); | 382 EXPECT_TRUE(SendFrame()); |
| 383 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); | 383 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 384 EXPECT_TRUE(SetSend(false)); | 384 EXPECT_TRUE(SetSend(false)); |
| 385 EXPECT_FALSE(channel_->sending()); | 385 EXPECT_FALSE(channel_->sending()); |
| 386 } | 386 } |
| 387 // Test that SetSend fails without codecs being set. | 387 // Test that SetSend fails without codecs being set. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 std::unique_ptr<cricket::FakeVideoCapturer> capturer( | 561 std::unique_ptr<cricket::FakeVideoCapturer> capturer( |
| 562 CreateFakeVideoCapturer()); | 562 CreateFakeVideoCapturer()); |
| 563 const int kTestWidth = 160; | 563 const int kTestWidth = 160; |
| 564 const int kTestHeight = 120; | 564 const int kTestHeight = 120; |
| 565 cricket::VideoFormat format(kTestWidth, kTestHeight, | 565 cricket::VideoFormat format(kTestWidth, kTestHeight, |
| 566 cricket::VideoFormat::FpsToInterval(5), | 566 cricket::VideoFormat::FpsToInterval(5), |
| 567 cricket::FOURCC_I420); | 567 cricket::FOURCC_I420); |
| 568 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); | 568 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |
| 569 EXPECT_TRUE(channel_->AddSendStream( | 569 EXPECT_TRUE(channel_->AddSendStream( |
| 570 cricket::StreamParams::CreateLegacy(5678))); | 570 cricket::StreamParams::CreateLegacy(5678))); |
| 571 EXPECT_TRUE(channel_->SetCapturer(5678, capturer.get())); | 571 channel_->SetSource(5678, capturer.get()); |
| 572 EXPECT_TRUE(channel_->AddRecvStream( | 572 EXPECT_TRUE(channel_->AddRecvStream( |
| 573 cricket::StreamParams::CreateLegacy(5678))); | 573 cricket::StreamParams::CreateLegacy(5678))); |
| 574 EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); | 574 EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); |
| 575 EXPECT_TRUE(capturer->CaptureCustomFrame( | 575 EXPECT_TRUE(capturer->CaptureCustomFrame( |
| 576 kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 576 kTestWidth, kTestHeight, cricket::FOURCC_I420)); |
| 577 EXPECT_FRAME_ON_RENDERER_WAIT( | 577 EXPECT_FRAME_ON_RENDERER_WAIT( |
| 578 renderer2, 1, kTestWidth, kTestHeight, kTimeout); | 578 renderer2, 1, kTestWidth, kTestHeight, kTimeout); |
| 579 | 579 |
| 580 // Get stats, and make sure they are correct for two senders. We wait until | 580 // Get stats, and make sure they are correct for two senders. We wait until |
| 581 // the number of expected packets have been sent to avoid races where we | 581 // the number of expected packets have been sent to avoid races where we |
| (...skipping 15 matching lines...) Expand all Loading... |
| 597 << "Timed out while waiting for packet counts for all sent packets."; | 597 << "Timed out while waiting for packet counts for all sent packets."; |
| 598 EXPECT_EQ(1U, info.senders[0].ssrcs().size()); | 598 EXPECT_EQ(1U, info.senders[0].ssrcs().size()); |
| 599 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); | 599 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); |
| 600 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); | 600 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); |
| 601 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); | 601 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); |
| 602 EXPECT_EQ(1U, info.senders[1].ssrcs().size()); | 602 EXPECT_EQ(1U, info.senders[1].ssrcs().size()); |
| 603 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); | 603 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); |
| 604 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); | 604 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); |
| 605 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); | 605 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); |
| 606 // The capturer must be unregistered here as it runs out of it's scope next. | 606 // The capturer must be unregistered here as it runs out of it's scope next. |
| 607 EXPECT_TRUE(channel_->SetCapturer(5678, NULL)); | 607 channel_->SetSource(5678, NULL); |
| 608 } | 608 } |
| 609 | 609 |
| 610 // Test that we can set the bandwidth. | 610 // Test that we can set the bandwidth. |
| 611 void SetSendBandwidth() { | 611 void SetSendBandwidth() { |
| 612 cricket::VideoSendParameters parameters; | 612 cricket::VideoSendParameters parameters; |
| 613 parameters.codecs.push_back(DefaultCodec()); | 613 parameters.codecs.push_back(DefaultCodec()); |
| 614 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. | 614 parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. |
| 615 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 615 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 616 parameters.max_bandwidth_bps = 128 * 1024; | 616 parameters.max_bandwidth_bps = 128 * 1024; |
| 617 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 617 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 634 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); | 634 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); |
| 635 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); | 635 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); |
| 636 } | 636 } |
| 637 // Test that we can set the SSRC even after codecs are set. | 637 // Test that we can set the SSRC even after codecs are set. |
| 638 void SetSendSsrcAfterSetCodecs() { | 638 void SetSendSsrcAfterSetCodecs() { |
| 639 // Remove stream added in Setup. | 639 // Remove stream added in Setup. |
| 640 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 640 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 641 EXPECT_TRUE(SetDefaultCodec()); | 641 EXPECT_TRUE(SetDefaultCodec()); |
| 642 EXPECT_TRUE(channel_->AddSendStream( | 642 EXPECT_TRUE(channel_->AddSendStream( |
| 643 cricket::StreamParams::CreateLegacy(999))); | 643 cricket::StreamParams::CreateLegacy(999))); |
| 644 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); | 644 channel_->SetSource(999u, video_capturer_.get()); |
| 645 EXPECT_TRUE(SetSend(true)); | 645 EXPECT_TRUE(SetSend(true)); |
| 646 EXPECT_TRUE(WaitAndSendFrame(0)); | 646 EXPECT_TRUE(WaitAndSendFrame(0)); |
| 647 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); | 647 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 648 uint32_t ssrc = 0; | 648 uint32_t ssrc = 0; |
| 649 std::unique_ptr<const rtc::Buffer> p(GetRtpPacket(0)); | 649 std::unique_ptr<const rtc::Buffer> p(GetRtpPacket(0)); |
| 650 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 650 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 651 EXPECT_EQ(999u, ssrc); | 651 EXPECT_EQ(999u, ssrc); |
| 652 // Packets are being paced out, so these can mismatch between the first and | 652 // Packets are being paced out, so these can mismatch between the first and |
| 653 // second call to NumRtpPackets until pending packets are paced out. | 653 // second call to NumRtpPackets until pending packets are paced out. |
| 654 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); | 654 EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 p(GetRtpPacket(static_cast<int>(last_packet))); | 700 p(GetRtpPacket(static_cast<int>(last_packet))); |
| 701 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 701 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 702 EXPECT_EQ(kSsrc, ssrc); | 702 EXPECT_EQ(kSsrc, ssrc); |
| 703 | 703 |
| 704 // Remove the send stream that was added during Setup. | 704 // Remove the send stream that was added during Setup. |
| 705 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 705 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 706 int rtp_packets = NumRtpPackets(); | 706 int rtp_packets = NumRtpPackets(); |
| 707 | 707 |
| 708 EXPECT_TRUE(channel_->AddSendStream( | 708 EXPECT_TRUE(channel_->AddSendStream( |
| 709 cricket::StreamParams::CreateLegacy(789u))); | 709 cricket::StreamParams::CreateLegacy(789u))); |
| 710 EXPECT_TRUE(channel_->SetCapturer(789u, video_capturer_.get())); | 710 channel_->SetSource(789u, video_capturer_.get()); |
| 711 EXPECT_EQ(rtp_packets, NumRtpPackets()); | 711 EXPECT_EQ(rtp_packets, NumRtpPackets()); |
| 712 // Wait 30ms to guarantee the engine does not drop the frame. | 712 // Wait 30ms to guarantee the engine does not drop the frame. |
| 713 EXPECT_TRUE(WaitAndSendFrame(30)); | 713 EXPECT_TRUE(WaitAndSendFrame(30)); |
| 714 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); | 714 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); |
| 715 | 715 |
| 716 last_packet = NumRtpPackets() - 1; | 716 last_packet = NumRtpPackets() - 1; |
| 717 p.reset(GetRtpPacket(static_cast<int>(last_packet))); | 717 p.reset(GetRtpPacket(static_cast<int>(last_packet))); |
| 718 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 718 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 719 EXPECT_EQ(789u, ssrc); | 719 EXPECT_EQ(789u, ssrc); |
| 720 } | 720 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 cricket::FOURCC_I420); | 783 cricket::FOURCC_I420); |
| 784 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); | 784 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |
| 785 // All capturers start generating frames with the same timestamp. ViE does | 785 // All capturers start generating frames with the same timestamp. ViE does |
| 786 // not allow the same timestamp to be used. Capture one frame before | 786 // not allow the same timestamp to be used. Capture one frame before |
| 787 // associating the capturer with the channel. | 787 // associating the capturer with the channel. |
| 788 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, | 788 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, |
| 789 cricket::FOURCC_I420)); | 789 cricket::FOURCC_I420)); |
| 790 | 790 |
| 791 int captured_frames = 1; | 791 int captured_frames = 1; |
| 792 for (int iterations = 0; iterations < 2; ++iterations) { | 792 for (int iterations = 0; iterations < 2; ++iterations) { |
| 793 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); | 793 channel_->SetSource(kSsrc, capturer.get()); |
| 794 rtc::Thread::Current()->ProcessMessages(time_between_send); | 794 rtc::Thread::Current()->ProcessMessages(time_between_send); |
| 795 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, | 795 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, |
| 796 cricket::FOURCC_I420)); | 796 cricket::FOURCC_I420)); |
| 797 ++captured_frames; | 797 ++captured_frames; |
| 798 // Wait until frame of right size is captured. | 798 // Wait until frame of right size is captured. |
| 799 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && | 799 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |
| 800 format.width == renderer_.width() && | 800 format.width == renderer_.width() && |
| 801 format.height == renderer_.height() && | 801 format.height == renderer_.height() && |
| 802 !renderer_.black_frame(), kTimeout); | 802 !renderer_.black_frame(), kTimeout); |
| 803 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); | 803 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |
| 804 EXPECT_EQ(format.width, renderer_.width()); | 804 EXPECT_EQ(format.width, renderer_.width()); |
| 805 EXPECT_EQ(format.height, renderer_.height()); | 805 EXPECT_EQ(format.height, renderer_.height()); |
| 806 captured_frames = renderer_.num_rendered_frames() + 1; | 806 captured_frames = renderer_.num_rendered_frames() + 1; |
| 807 EXPECT_FALSE(renderer_.black_frame()); | 807 EXPECT_FALSE(renderer_.black_frame()); |
| 808 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); | 808 channel_->SetSource(kSsrc, NULL); |
| 809 // Make sure a black frame is generated within the specified timeout. | 809 // Make sure a black frame is generated within the specified timeout. |
| 810 // The black frame should be the resolution of the previous frame to | 810 // The black frame should be the resolution of the previous frame to |
| 811 // prevent expensive encoder reconfigurations. | 811 // prevent expensive encoder reconfigurations. |
| 812 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && | 812 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |
| 813 format.width == renderer_.width() && | 813 format.width == renderer_.width() && |
| 814 format.height == renderer_.height() && | 814 format.height == renderer_.height() && |
| 815 renderer_.black_frame(), kTimeout); | 815 renderer_.black_frame(), kTimeout); |
| 816 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); | 816 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |
| 817 EXPECT_EQ(format.width, renderer_.width()); | 817 EXPECT_EQ(format.width, renderer_.width()); |
| 818 EXPECT_EQ(format.height, renderer_.height()); | 818 EXPECT_EQ(format.height, renderer_.height()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 833 EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 833 EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 834 EXPECT_TRUE(SetSend(true)); | 834 EXPECT_TRUE(SetSend(true)); |
| 835 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); | 835 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 836 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 836 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 837 EXPECT_TRUE(SendFrame()); | 837 EXPECT_TRUE(SendFrame()); |
| 838 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); | 838 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); |
| 839 // Wait for one frame so they don't get dropped because we send frames too | 839 // Wait for one frame so they don't get dropped because we send frames too |
| 840 // tightly. | 840 // tightly. |
| 841 rtc::Thread::Current()->ProcessMessages(30); | 841 rtc::Thread::Current()->ProcessMessages(30); |
| 842 // Remove the capturer. | 842 // Remove the capturer. |
| 843 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); | 843 channel_->SetSource(kSsrc, NULL); |
| 844 // Wait for one black frame for removing the capturer. | 844 // Wait for one black frame for removing the capturer. |
| 845 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); | 845 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); |
| 846 | 846 |
| 847 // No capturer was added, so this RemoveCapturer should | 847 // No capturer was added, so this RemoveCapturer should |
| 848 // fail. | 848 // be a NOP. |
| 849 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL)); | 849 channel_->SetSource(kSsrc, NULL); |
| 850 rtc::Thread::Current()->ProcessMessages(300); | 850 rtc::Thread::Current()->ProcessMessages(300); |
| 851 // Verify no more frames were sent. | 851 // Verify no more frames were sent. |
| 852 EXPECT_EQ(2, renderer_.num_rendered_frames()); | 852 EXPECT_EQ(2, renderer_.num_rendered_frames()); |
| 853 } | 853 } |
| 854 | 854 |
| 855 // Tests that we can add and remove capturer as unique sources. | 855 // Tests that we can add and remove capturer as unique sources. |
| 856 void AddRemoveCapturerMultipleSources() { | 856 void AddRemoveCapturerMultipleSources() { |
| 857 // WebRTC implementation will drop frames if pushed to quickly. Wait the | 857 // WebRTC implementation will drop frames if pushed to quickly. Wait the |
| 858 // interval time to avoid that. | 858 // interval time to avoid that. |
| 859 // WebRTC implementation will drop frames if pushed to quickly. Wait the | 859 // WebRTC implementation will drop frames if pushed to quickly. Wait the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 881 EXPECT_TRUE(channel_->AddRecvStream( | 881 EXPECT_TRUE(channel_->AddRecvStream( |
| 882 cricket::StreamParams::CreateLegacy(2))); | 882 cricket::StreamParams::CreateLegacy(2))); |
| 883 EXPECT_TRUE(channel_->SetSink(2, &renderer2)); | 883 EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
| 884 EXPECT_TRUE(channel_->AddSendStream( | 884 EXPECT_TRUE(channel_->AddSendStream( |
| 885 cricket::StreamParams::CreateLegacy(2))); | 885 cricket::StreamParams::CreateLegacy(2))); |
| 886 std::unique_ptr<cricket::FakeVideoCapturer> capturer2( | 886 std::unique_ptr<cricket::FakeVideoCapturer> capturer2( |
| 887 CreateFakeVideoCapturer()); | 887 CreateFakeVideoCapturer()); |
| 888 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); | 888 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); |
| 889 // State for all the streams. | 889 // State for all the streams. |
| 890 EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 890 EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 891 // A limitation in the lmi implementation requires that SetCapturer() is | 891 // A limitation in the lmi implementation requires that SetSource() is |
| 892 // called after SetOneCodec(). | 892 // called after SetOneCodec(). |
| 893 // TODO(hellner): this seems like an unnecessary constraint, fix it. | 893 // TODO(hellner): this seems like an unnecessary constraint, fix it. |
| 894 EXPECT_TRUE(channel_->SetCapturer(1, capturer1.get())); | 894 channel_->SetSource(1, capturer1.get()); |
| 895 EXPECT_TRUE(channel_->SetCapturer(2, capturer2.get())); | 895 channel_->SetSource(2, capturer2.get()); |
| 896 EXPECT_TRUE(SetSend(true)); | 896 EXPECT_TRUE(SetSend(true)); |
| 897 // Test capturer associated with engine. | 897 // Test capturer associated with engine. |
| 898 const int kTestWidth = 160; | 898 const int kTestWidth = 160; |
| 899 const int kTestHeight = 120; | 899 const int kTestHeight = 120; |
| 900 EXPECT_TRUE(capturer1->CaptureCustomFrame( | 900 EXPECT_TRUE(capturer1->CaptureCustomFrame( |
| 901 kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 901 kTestWidth, kTestHeight, cricket::FOURCC_I420)); |
| 902 EXPECT_FRAME_ON_RENDERER_WAIT( | 902 EXPECT_FRAME_ON_RENDERER_WAIT( |
| 903 renderer1, 1, kTestWidth, kTestHeight, kTimeout); | 903 renderer1, 1, kTestWidth, kTestHeight, kTimeout); |
| 904 // Capture a frame with additional capturer2, frames should be received | 904 // Capture a frame with additional capturer2, frames should be received |
| 905 EXPECT_TRUE(capturer2->CaptureCustomFrame( | 905 EXPECT_TRUE(capturer2->CaptureCustomFrame( |
| 906 kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 906 kTestWidth, kTestHeight, cricket::FOURCC_I420)); |
| 907 EXPECT_FRAME_ON_RENDERER_WAIT( | 907 EXPECT_FRAME_ON_RENDERER_WAIT( |
| 908 renderer2, 1, kTestWidth, kTestHeight, kTimeout); | 908 renderer2, 1, kTestWidth, kTestHeight, kTimeout); |
| 909 // Successfully remove the capturer. | 909 // Successfully remove the capturer. |
| 910 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); | 910 channel_->SetSource(kSsrc, NULL); |
| 911 // Fail to re-remove the capturer. | 911 // Fail to re-remove the capturer. |
| 912 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL)); | 912 channel_->SetSource(kSsrc, NULL); |
| 913 // The capturers must be unregistered here as it runs out of it's scope | 913 // The capturers must be unregistered here as it runs out of it's scope |
| 914 // next. | 914 // next. |
| 915 EXPECT_TRUE(channel_->SetCapturer(1, NULL)); | 915 channel_->SetSource(1, NULL); |
| 916 EXPECT_TRUE(channel_->SetCapturer(2, NULL)); | 916 channel_->SetSource(2, NULL); |
| 917 } | 917 } |
| 918 | 918 |
| 919 void HighAspectHighHeightCapturer() { | 919 void HighAspectHighHeightCapturer() { |
| 920 const int kWidth = 80; | 920 const int kWidth = 80; |
| 921 const int kHeight = 10000; | 921 const int kHeight = 10000; |
| 922 const int kScaledWidth = 20; | 922 const int kScaledWidth = 20; |
| 923 const int kScaledHeight = 2500; | 923 const int kScaledHeight = 2500; |
| 924 | 924 |
| 925 cricket::VideoCodec codec(DefaultCodec()); | 925 cricket::VideoCodec codec(DefaultCodec()); |
| 926 EXPECT_TRUE(SetOneCodec(codec)); | 926 EXPECT_TRUE(SetOneCodec(codec)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 939 // Registering an external capturer is currently the same as screen casting | 939 // Registering an external capturer is currently the same as screen casting |
| 940 // (update the test when this changes). | 940 // (update the test when this changes). |
| 941 std::unique_ptr<cricket::FakeVideoCapturer> capturer( | 941 std::unique_ptr<cricket::FakeVideoCapturer> capturer( |
| 942 CreateFakeVideoCapturer()); | 942 CreateFakeVideoCapturer()); |
| 943 const std::vector<cricket::VideoFormat>* formats = | 943 const std::vector<cricket::VideoFormat>* formats = |
| 944 capturer->GetSupportedFormats(); | 944 capturer->GetSupportedFormats(); |
| 945 cricket::VideoFormat capture_format = (*formats)[0]; | 945 cricket::VideoFormat capture_format = (*formats)[0]; |
| 946 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); | 946 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); |
| 947 // Capture frame to not get same frame timestamps as previous capturer. | 947 // Capture frame to not get same frame timestamps as previous capturer. |
| 948 capturer->CaptureFrame(); | 948 capturer->CaptureFrame(); |
| 949 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); | 949 channel_->SetSource(kSsrc, capturer.get()); |
| 950 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); | 950 EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); |
| 951 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, | 951 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, |
| 952 cricket::FOURCC_ARGB)); | 952 cricket::FOURCC_ARGB)); |
| 953 EXPECT_GT_FRAME_ON_RENDERER_WAIT( | 953 EXPECT_GT_FRAME_ON_RENDERER_WAIT( |
| 954 renderer, 2, kScaledWidth, kScaledHeight, kTimeout); | 954 renderer, 2, kScaledWidth, kScaledHeight, kTimeout); |
| 955 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); | 955 channel_->SetSource(kSsrc, NULL); |
| 956 } | 956 } |
| 957 | 957 |
| 958 // Tests that we can adapt video resolution with 16:10 aspect ratio properly. | 958 // Tests that we can adapt video resolution with 16:10 aspect ratio properly. |
| 959 void AdaptResolution16x10() { | 959 void AdaptResolution16x10() { |
| 960 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); | 960 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 961 cricket::VideoCodec codec(DefaultCodec()); | 961 cricket::VideoCodec codec(DefaultCodec()); |
| 962 codec.width = 640; | 962 codec.width = 640; |
| 963 codec.height = 400; | 963 codec.height = 400; |
| 964 SendAndReceive(codec); | 964 SendAndReceive(codec); |
| 965 codec.width /= 2; | 965 codec.width /= 2; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 | 1065 |
| 1066 // Tests that we can mute and unmute the channel properly. | 1066 // Tests that we can mute and unmute the channel properly. |
| 1067 void MuteStream() { | 1067 void MuteStream() { |
| 1068 EXPECT_TRUE(SetDefaultCodec()); | 1068 EXPECT_TRUE(SetDefaultCodec()); |
| 1069 cricket::FakeVideoCapturer video_capturer; | 1069 cricket::FakeVideoCapturer video_capturer; |
| 1070 video_capturer.Start( | 1070 video_capturer.Start( |
| 1071 cricket::VideoFormat( | 1071 cricket::VideoFormat( |
| 1072 640, 480, | 1072 640, 480, |
| 1073 cricket::VideoFormat::FpsToInterval(30), | 1073 cricket::VideoFormat::FpsToInterval(30), |
| 1074 cricket::FOURCC_I420)); | 1074 cricket::FOURCC_I420)); |
| 1075 EXPECT_TRUE(channel_->SetCapturer(kSsrc, &video_capturer)); | 1075 channel_->SetSource(kSsrc, &video_capturer); |
| 1076 EXPECT_TRUE(SetSend(true)); | 1076 EXPECT_TRUE(SetSend(true)); |
| 1077 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); | 1077 EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1078 EXPECT_EQ(0, renderer_.num_rendered_frames()); | 1078 EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1079 // Mute the channel and expect black output frame. | 1079 // Mute the channel and expect black output frame. |
| 1080 int frame_count = 0; | 1080 int frame_count = 0; |
| 1081 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); | 1081 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); |
| 1082 EXPECT_TRUE(video_capturer.CaptureFrame()); | 1082 EXPECT_TRUE(video_capturer.CaptureFrame()); |
| 1083 ++frame_count; | 1083 ++frame_count; |
| 1084 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); | 1084 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); |
| 1085 EXPECT_TRUE(renderer_.black_frame()); | 1085 EXPECT_TRUE(renderer_.black_frame()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1104 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); | 1104 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout); |
| 1105 EXPECT_FALSE(renderer_.black_frame()); | 1105 EXPECT_FALSE(renderer_.black_frame()); |
| 1106 // Test that muting an existing stream succeeds even if it's muted. | 1106 // Test that muting an existing stream succeeds even if it's muted. |
| 1107 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); | 1107 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); |
| 1108 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); | 1108 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, false, nullptr)); |
| 1109 // Test that unmuting an existing stream succeeds even if it's not muted. | 1109 // Test that unmuting an existing stream succeeds even if it's not muted. |
| 1110 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); | 1110 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); |
| 1111 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); | 1111 EXPECT_TRUE(channel_->SetVideoSend(kSsrc, true, nullptr)); |
| 1112 // Test that muting an invalid stream fails. | 1112 // Test that muting an invalid stream fails. |
| 1113 EXPECT_FALSE(channel_->SetVideoSend(kSsrc+1, false, nullptr)); | 1113 EXPECT_FALSE(channel_->SetVideoSend(kSsrc+1, false, nullptr)); |
| 1114 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); | 1114 channel_->SetSource(kSsrc, NULL); |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 // Test that multiple send streams can be created and deleted properly. | 1117 // Test that multiple send streams can be created and deleted properly. |
| 1118 void MultipleSendStreams() { | 1118 void MultipleSendStreams() { |
| 1119 // Remove stream added in Setup. I.e. remove stream corresponding to default | 1119 // Remove stream added in Setup. I.e. remove stream corresponding to default |
| 1120 // channel. | 1120 // channel. |
| 1121 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 1121 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1122 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); | 1122 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); |
| 1123 for (unsigned int i = 0; i < kSsrcsSize; ++i) { | 1123 for (unsigned int i = 0; i < kSsrcsSize; ++i) { |
| 1124 EXPECT_TRUE(channel_->AddSendStream( | 1124 EXPECT_TRUE(channel_->AddSendStream( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 // Re-use default channel. | 1165 // Re-use default channel. |
| 1166 EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc()); | 1166 EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc()); |
| 1167 EXPECT_FALSE(channel_->AddSendStream( | 1167 EXPECT_FALSE(channel_->AddSendStream( |
| 1168 cricket::StreamParams::CreateLegacy(new_ssrc))); | 1168 cricket::StreamParams::CreateLegacy(new_ssrc))); |
| 1169 EXPECT_TRUE(channel_->AddRecvStream( | 1169 EXPECT_TRUE(channel_->AddRecvStream( |
| 1170 cricket::StreamParams::CreateLegacy(new_ssrc))); | 1170 cricket::StreamParams::CreateLegacy(new_ssrc))); |
| 1171 EXPECT_TRUE(channel_->SetSink(new_ssrc, &renderer_)); | 1171 EXPECT_TRUE(channel_->SetSink(new_ssrc, &renderer_)); |
| 1172 EXPECT_FALSE(channel_->AddRecvStream( | 1172 EXPECT_FALSE(channel_->AddRecvStream( |
| 1173 cricket::StreamParams::CreateLegacy(new_ssrc))); | 1173 cricket::StreamParams::CreateLegacy(new_ssrc))); |
| 1174 | 1174 |
| 1175 EXPECT_TRUE(channel_->SetCapturer(new_ssrc, video_capturer_.get())); | 1175 channel_->SetSource(new_ssrc, video_capturer_.get()); |
| 1176 | 1176 |
| 1177 SendAndReceive(codec); | 1177 SendAndReceive(codec); |
| 1178 EXPECT_TRUE(channel_->RemoveSendStream(new_ssrc)); | 1178 EXPECT_TRUE(channel_->RemoveSendStream(new_ssrc)); |
| 1179 EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc()); | 1179 EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc()); |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 const std::unique_ptr<webrtc::Call> call_; | 1182 const std::unique_ptr<webrtc::Call> call_; |
| 1183 VideoEngineOverride<E> engine_; | 1183 VideoEngineOverride<E> engine_; |
| 1184 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_; | 1184 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_; |
| 1185 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_2_; | 1185 std::unique_ptr<cricket::FakeVideoCapturer> video_capturer_2_; |
| 1186 std::unique_ptr<C> channel_; | 1186 std::unique_ptr<C> channel_; |
| 1187 cricket::FakeNetworkInterface network_interface_; | 1187 cricket::FakeNetworkInterface network_interface_; |
| 1188 cricket::FakeVideoRenderer renderer_; | 1188 cricket::FakeVideoRenderer renderer_; |
| 1189 cricket::VideoMediaChannel::Error media_error_; | 1189 cricket::VideoMediaChannel::Error media_error_; |
| 1190 | 1190 |
| 1191 // Used by test cases where 2 streams are run on the same channel. | 1191 // Used by test cases where 2 streams are run on the same channel. |
| 1192 cricket::FakeVideoRenderer renderer2_; | 1192 cricket::FakeVideoRenderer renderer2_; |
| 1193 }; | 1193 }; |
| 1194 | 1194 |
| 1195 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT | 1195 #endif // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT |
| OLD | NEW |