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