| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   366   } |   366   } | 
|   367  |   367  | 
|   368   void OnVideoChannelError(uint32_t ssrc, |   368   void OnVideoChannelError(uint32_t ssrc, | 
|   369                            cricket::VideoMediaChannel::Error error) { |   369                            cricket::VideoMediaChannel::Error error) { | 
|   370     media_error_ = error; |   370     media_error_ = error; | 
|   371   } |   371   } | 
|   372  |   372  | 
|   373   // Test that SetSend works. |   373   // Test that SetSend works. | 
|   374   void SetSend() { |   374   void SetSend() { | 
|   375     EXPECT_FALSE(channel_->sending()); |   375     EXPECT_FALSE(channel_->sending()); | 
|   376     EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); |   376     channel_->SetSource(kSsrc, video_capturer_.get()); | 
|   377     EXPECT_TRUE(SetOneCodec(DefaultCodec())); |   377     EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 
|   378     EXPECT_FALSE(channel_->sending()); |   378     EXPECT_FALSE(channel_->sending()); | 
|   379     EXPECT_TRUE(SetSend(true)); |   379     EXPECT_TRUE(SetSend(true)); | 
|   380     EXPECT_TRUE(channel_->sending()); |   380     EXPECT_TRUE(channel_->sending()); | 
|   381     EXPECT_TRUE(SendFrame()); |   381     EXPECT_TRUE(SendFrame()); | 
|   382     EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |   382     EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); | 
|   383     EXPECT_TRUE(SetSend(false)); |   383     EXPECT_TRUE(SetSend(false)); | 
|   384     EXPECT_FALSE(channel_->sending()); |   384     EXPECT_FALSE(channel_->sending()); | 
|   385   } |   385   } | 
|   386   // Test that SetSend fails without codecs being set. |   386   // Test that SetSend fails without codecs being set. | 
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   560     std::unique_ptr<cricket::FakeVideoCapturer> capturer( |   560     std::unique_ptr<cricket::FakeVideoCapturer> capturer( | 
|   561         CreateFakeVideoCapturer()); |   561         CreateFakeVideoCapturer()); | 
|   562     const int kTestWidth = 160; |   562     const int kTestWidth = 160; | 
|   563     const int kTestHeight = 120; |   563     const int kTestHeight = 120; | 
|   564     cricket::VideoFormat format(kTestWidth, kTestHeight, |   564     cricket::VideoFormat format(kTestWidth, kTestHeight, | 
|   565                                 cricket::VideoFormat::FpsToInterval(5), |   565                                 cricket::VideoFormat::FpsToInterval(5), | 
|   566                                 cricket::FOURCC_I420); |   566                                 cricket::FOURCC_I420); | 
|   567     EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |   567     EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); | 
|   568     EXPECT_TRUE(channel_->AddSendStream( |   568     EXPECT_TRUE(channel_->AddSendStream( | 
|   569         cricket::StreamParams::CreateLegacy(5678))); |   569         cricket::StreamParams::CreateLegacy(5678))); | 
|   570     EXPECT_TRUE(channel_->SetCapturer(5678, capturer.get())); |   570     channel_->SetSource(5678, capturer.get()); | 
|   571     EXPECT_TRUE(channel_->AddRecvStream( |   571     EXPECT_TRUE(channel_->AddRecvStream( | 
|   572         cricket::StreamParams::CreateLegacy(5678))); |   572         cricket::StreamParams::CreateLegacy(5678))); | 
|   573     EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); |   573     EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); | 
|   574     EXPECT_TRUE(capturer->CaptureCustomFrame( |   574     EXPECT_TRUE(capturer->CaptureCustomFrame( | 
|   575         kTestWidth, kTestHeight, cricket::FOURCC_I420)); |   575         kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 
|   576     EXPECT_FRAME_ON_RENDERER_WAIT( |   576     EXPECT_FRAME_ON_RENDERER_WAIT( | 
|   577         renderer2, 1, kTestWidth, kTestHeight, kTimeout); |   577         renderer2, 1, kTestWidth, kTestHeight, kTimeout); | 
|   578  |   578  | 
|   579     // Get stats, and make sure they are correct for two senders. We wait until |   579     // 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 |   580     // the number of expected packets have been sent to avoid races where we | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|   596         << "Timed out while waiting for packet counts for all sent packets."; |   596         << "Timed out while waiting for packet counts for all sent packets."; | 
|   597     EXPECT_EQ(1U, info.senders[0].ssrcs().size()); |   597     EXPECT_EQ(1U, info.senders[0].ssrcs().size()); | 
|   598     EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); |   598     EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); | 
|   599     EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); |   599     EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); | 
|   600     EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); |   600     EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); | 
|   601     EXPECT_EQ(1U, info.senders[1].ssrcs().size()); |   601     EXPECT_EQ(1U, info.senders[1].ssrcs().size()); | 
|   602     EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); |   602     EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); | 
|   603     EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); |   603     EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); | 
|   604     EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); |   604     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. |   605     // The capturer must be unregistered here as it runs out of it's scope next. | 
|   606     EXPECT_TRUE(channel_->SetCapturer(5678, NULL)); |   606     channel_->SetSource(5678, NULL); | 
|   607   } |   607   } | 
|   608  |   608  | 
|   609   // Test that we can set the bandwidth. |   609   // Test that we can set the bandwidth. | 
|   610   void SetSendBandwidth() { |   610   void SetSendBandwidth() { | 
|   611     cricket::VideoSendParameters parameters; |   611     cricket::VideoSendParameters parameters; | 
|   612     parameters.codecs.push_back(DefaultCodec()); |   612     parameters.codecs.push_back(DefaultCodec()); | 
|   613     parameters.max_bandwidth_bps = -1;  // <= 0 means unlimited. |   613     parameters.max_bandwidth_bps = -1;  // <= 0 means unlimited. | 
|   614     EXPECT_TRUE(channel_->SetSendParameters(parameters)); |   614     EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 
|   615     parameters.max_bandwidth_bps = 128 * 1024; |   615     parameters.max_bandwidth_bps = 128 * 1024; | 
|   616     EXPECT_TRUE(channel_->SetSendParameters(parameters)); |   616     EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|   633     EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); |   633     EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); | 
|   634     EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); |   634     EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); | 
|   635   } |   635   } | 
|   636   // Test that we can set the SSRC even after codecs are set. |   636   // Test that we can set the SSRC even after codecs are set. | 
|   637   void SetSendSsrcAfterSetCodecs() { |   637   void SetSendSsrcAfterSetCodecs() { | 
|   638     // Remove stream added in Setup. |   638     // Remove stream added in Setup. | 
|   639     EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |   639     EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 
|   640     EXPECT_TRUE(SetDefaultCodec()); |   640     EXPECT_TRUE(SetDefaultCodec()); | 
|   641     EXPECT_TRUE(channel_->AddSendStream( |   641     EXPECT_TRUE(channel_->AddSendStream( | 
|   642         cricket::StreamParams::CreateLegacy(999))); |   642         cricket::StreamParams::CreateLegacy(999))); | 
|   643     EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get())); |   643     channel_->SetSource(999u, video_capturer_.get()); | 
|   644     EXPECT_TRUE(SetSend(true)); |   644     EXPECT_TRUE(SetSend(true)); | 
|   645     EXPECT_TRUE(WaitAndSendFrame(0)); |   645     EXPECT_TRUE(WaitAndSendFrame(0)); | 
|   646     EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |   646     EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); | 
|   647     uint32_t ssrc = 0; |   647     uint32_t ssrc = 0; | 
|   648     std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |   648     std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); | 
|   649     ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |   649     ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 
|   650     EXPECT_EQ(999u, ssrc); |   650     EXPECT_EQ(999u, ssrc); | 
|   651     // Packets are being paced out, so these can mismatch between the first and |   651     // Packets are being paced out, so these can mismatch between the first and | 
|   652     // second call to NumRtpPackets until pending packets are paced out. |   652     // second call to NumRtpPackets until pending packets are paced out. | 
|   653     EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); |   653     EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   699         p(GetRtpPacket(static_cast<int>(last_packet))); |   699         p(GetRtpPacket(static_cast<int>(last_packet))); | 
|   700     ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |   700     ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 
|   701     EXPECT_EQ(kSsrc, ssrc); |   701     EXPECT_EQ(kSsrc, ssrc); | 
|   702  |   702  | 
|   703     // Remove the send stream that was added during Setup. |   703     // Remove the send stream that was added during Setup. | 
|   704     EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |   704     EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 
|   705     int rtp_packets = NumRtpPackets(); |   705     int rtp_packets = NumRtpPackets(); | 
|   706  |   706  | 
|   707     EXPECT_TRUE(channel_->AddSendStream( |   707     EXPECT_TRUE(channel_->AddSendStream( | 
|   708         cricket::StreamParams::CreateLegacy(789u))); |   708         cricket::StreamParams::CreateLegacy(789u))); | 
|   709     EXPECT_TRUE(channel_->SetCapturer(789u, video_capturer_.get())); |   709     channel_->SetSource(789u, video_capturer_.get()); | 
|   710     EXPECT_EQ(rtp_packets, NumRtpPackets()); |   710     EXPECT_EQ(rtp_packets, NumRtpPackets()); | 
|   711     // Wait 30ms to guarantee the engine does not drop the frame. |   711     // Wait 30ms to guarantee the engine does not drop the frame. | 
|   712     EXPECT_TRUE(WaitAndSendFrame(30)); |   712     EXPECT_TRUE(WaitAndSendFrame(30)); | 
|   713     EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); |   713     EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); | 
|   714  |   714  | 
|   715     last_packet = NumRtpPackets() - 1; |   715     last_packet = NumRtpPackets() - 1; | 
|   716     p.reset(GetRtpPacket(static_cast<int>(last_packet))); |   716     p.reset(GetRtpPacket(static_cast<int>(last_packet))); | 
|   717     ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |   717     ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); | 
|   718     EXPECT_EQ(789u, ssrc); |   718     EXPECT_EQ(789u, ssrc); | 
|   719   } |   719   } | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   782                                 cricket::FOURCC_I420); |   782                                 cricket::FOURCC_I420); | 
|   783     EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |   783     EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); | 
|   784     // All capturers start generating frames with the same timestamp. ViE does |   784     // All capturers start generating frames with the same timestamp. ViE does | 
|   785     // not allow the same timestamp to be used. Capture one frame before |   785     // not allow the same timestamp to be used. Capture one frame before | 
|   786     // associating the capturer with the channel. |   786     // associating the capturer with the channel. | 
|   787     EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, |   787     EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, | 
|   788                                              cricket::FOURCC_I420)); |   788                                              cricket::FOURCC_I420)); | 
|   789  |   789  | 
|   790     int captured_frames = 1; |   790     int captured_frames = 1; | 
|   791     for (int iterations = 0; iterations < 2; ++iterations) { |   791     for (int iterations = 0; iterations < 2; ++iterations) { | 
|   792       EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); |   792       channel_->SetSource(kSsrc, capturer.get()); | 
|   793       rtc::Thread::Current()->ProcessMessages(time_between_send); |   793       rtc::Thread::Current()->ProcessMessages(time_between_send); | 
|   794       EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, |   794       EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height, | 
|   795                                                cricket::FOURCC_I420)); |   795                                                cricket::FOURCC_I420)); | 
|   796       ++captured_frames; |   796       ++captured_frames; | 
|   797       // Wait until frame of right size is captured. |   797       // Wait until frame of right size is captured. | 
|   798       EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |   798       EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && | 
|   799                        format.width == renderer_.width() && |   799                        format.width == renderer_.width() && | 
|   800                        format.height == renderer_.height() && |   800                        format.height == renderer_.height() && | 
|   801                        !renderer_.black_frame(), kTimeout); |   801                        !renderer_.black_frame(), kTimeout); | 
|   802       EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |   802       EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); | 
|   803       EXPECT_EQ(format.width, renderer_.width()); |   803       EXPECT_EQ(format.width, renderer_.width()); | 
|   804       EXPECT_EQ(format.height, renderer_.height()); |   804       EXPECT_EQ(format.height, renderer_.height()); | 
|   805       captured_frames = renderer_.num_rendered_frames() + 1; |   805       captured_frames = renderer_.num_rendered_frames() + 1; | 
|   806       EXPECT_FALSE(renderer_.black_frame()); |   806       EXPECT_FALSE(renderer_.black_frame()); | 
|   807       EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); |   807       channel_->SetSource(kSsrc, NULL); | 
|   808       // Make sure a black frame is generated within the specified timeout. |   808       // Make sure a black frame is generated within the specified timeout. | 
|   809       // The black frame should be the resolution of the previous frame to |   809       // The black frame should be the resolution of the previous frame to | 
|   810       // prevent expensive encoder reconfigurations. |   810       // prevent expensive encoder reconfigurations. | 
|   811       EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |   811       EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && | 
|   812                        format.width == renderer_.width() && |   812                        format.width == renderer_.width() && | 
|   813                        format.height == renderer_.height() && |   813                        format.height == renderer_.height() && | 
|   814                        renderer_.black_frame(), kTimeout); |   814                        renderer_.black_frame(), kTimeout); | 
|   815       EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |   815       EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); | 
|   816       EXPECT_EQ(format.width, renderer_.width()); |   816       EXPECT_EQ(format.width, renderer_.width()); | 
|   817       EXPECT_EQ(format.height, renderer_.height()); |   817       EXPECT_EQ(format.height, renderer_.height()); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   832     EXPECT_TRUE(SetOneCodec(DefaultCodec())); |   832     EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 
|   833     EXPECT_TRUE(SetSend(true)); |   833     EXPECT_TRUE(SetSend(true)); | 
|   834     EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |   834     EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); | 
|   835     EXPECT_EQ(0, renderer_.num_rendered_frames()); |   835     EXPECT_EQ(0, renderer_.num_rendered_frames()); | 
|   836     EXPECT_TRUE(SendFrame()); |   836     EXPECT_TRUE(SendFrame()); | 
|   837     EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); |   837     EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); | 
|   838     // Wait for one frame so they don't get dropped because we send frames too |   838     // Wait for one frame so they don't get dropped because we send frames too | 
|   839     // tightly. |   839     // tightly. | 
|   840     rtc::Thread::Current()->ProcessMessages(30); |   840     rtc::Thread::Current()->ProcessMessages(30); | 
|   841     // Remove the capturer. |   841     // Remove the capturer. | 
|   842     EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); |   842     channel_->SetSource(kSsrc, NULL); | 
|   843     // Wait for one black frame for removing the capturer. |   843     // Wait for one black frame for removing the capturer. | 
|   844     EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); |   844     EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); | 
|   845  |   845  | 
|   846     // No capturer was added, so this RemoveCapturer should |   846     // No capturer was added, so this SetSource should be a NOP. | 
|   847     // fail. |   847     channel_->SetSource(kSsrc, NULL); | 
|   848     EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL)); |  | 
|   849     rtc::Thread::Current()->ProcessMessages(300); |   848     rtc::Thread::Current()->ProcessMessages(300); | 
|   850     // Verify no more frames were sent. |   849     // Verify no more frames were sent. | 
|   851     EXPECT_EQ(2, renderer_.num_rendered_frames()); |   850     EXPECT_EQ(2, renderer_.num_rendered_frames()); | 
|   852   } |   851   } | 
|   853  |   852  | 
|   854   // Tests that we can add and remove capturer as unique sources. |   853   // Tests that we can add and remove capturer as unique sources. | 
|   855   void AddRemoveCapturerMultipleSources() { |   854   void AddRemoveCapturerMultipleSources() { | 
|   856     // WebRTC implementation will drop frames if pushed to quickly. Wait the |   855     // WebRTC implementation will drop frames if pushed to quickly. Wait the | 
|   857     // interval time to avoid that. |   856     // interval time to avoid that. | 
|   858     // WebRTC implementation will drop frames if pushed to quickly. Wait the |   857     // WebRTC implementation will drop frames if pushed to quickly. Wait the | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|   880     EXPECT_TRUE(channel_->AddRecvStream( |   879     EXPECT_TRUE(channel_->AddRecvStream( | 
|   881         cricket::StreamParams::CreateLegacy(2))); |   880         cricket::StreamParams::CreateLegacy(2))); | 
|   882     EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |   881     EXPECT_TRUE(channel_->SetSink(2, &renderer2)); | 
|   883     EXPECT_TRUE(channel_->AddSendStream( |   882     EXPECT_TRUE(channel_->AddSendStream( | 
|   884         cricket::StreamParams::CreateLegacy(2))); |   883         cricket::StreamParams::CreateLegacy(2))); | 
|   885     std::unique_ptr<cricket::FakeVideoCapturer> capturer2( |   884     std::unique_ptr<cricket::FakeVideoCapturer> capturer2( | 
|   886         CreateFakeVideoCapturer()); |   885         CreateFakeVideoCapturer()); | 
|   887     EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); |   886     EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); | 
|   888     // State for all the streams. |   887     // State for all the streams. | 
|   889     EXPECT_TRUE(SetOneCodec(DefaultCodec())); |   888     EXPECT_TRUE(SetOneCodec(DefaultCodec())); | 
|   890     // A limitation in the lmi implementation requires that SetCapturer() is |   889     // A limitation in the lmi implementation requires that SetSource() is | 
|   891     // called after SetOneCodec(). |   890     // called after SetOneCodec(). | 
|   892     // TODO(hellner): this seems like an unnecessary constraint, fix it. |   891     // TODO(hellner): this seems like an unnecessary constraint, fix it. | 
|   893     EXPECT_TRUE(channel_->SetCapturer(1, capturer1.get())); |   892     channel_->SetSource(1, capturer1.get()); | 
|   894     EXPECT_TRUE(channel_->SetCapturer(2, capturer2.get())); |   893     channel_->SetSource(2, capturer2.get()); | 
|   895     EXPECT_TRUE(SetSend(true)); |   894     EXPECT_TRUE(SetSend(true)); | 
|   896     // Test capturer associated with engine. |   895     // Test capturer associated with engine. | 
|   897     const int kTestWidth = 160; |   896     const int kTestWidth = 160; | 
|   898     const int kTestHeight = 120; |   897     const int kTestHeight = 120; | 
|   899     EXPECT_TRUE(capturer1->CaptureCustomFrame( |   898     EXPECT_TRUE(capturer1->CaptureCustomFrame( | 
|   900         kTestWidth, kTestHeight, cricket::FOURCC_I420)); |   899         kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 
|   901     EXPECT_FRAME_ON_RENDERER_WAIT( |   900     EXPECT_FRAME_ON_RENDERER_WAIT( | 
|   902         renderer1, 1, kTestWidth, kTestHeight, kTimeout); |   901         renderer1, 1, kTestWidth, kTestHeight, kTimeout); | 
|   903     // Capture a frame with additional capturer2, frames should be received |   902     // Capture a frame with additional capturer2, frames should be received | 
|   904     EXPECT_TRUE(capturer2->CaptureCustomFrame( |   903     EXPECT_TRUE(capturer2->CaptureCustomFrame( | 
|   905         kTestWidth, kTestHeight, cricket::FOURCC_I420)); |   904         kTestWidth, kTestHeight, cricket::FOURCC_I420)); | 
|   906     EXPECT_FRAME_ON_RENDERER_WAIT( |   905     EXPECT_FRAME_ON_RENDERER_WAIT( | 
|   907         renderer2, 1, kTestWidth, kTestHeight, kTimeout); |   906         renderer2, 1, kTestWidth, kTestHeight, kTimeout); | 
|   908     // Successfully remove the capturer. |   907     // Successfully remove the capturer. | 
|   909     EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); |   908     channel_->SetSource(kSsrc, NULL); | 
|   910     // Fail to re-remove the capturer. |   909     // Fail to re-remove the capturer. | 
|   911     EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL)); |   910     channel_->SetSource(kSsrc, NULL); | 
|   912     // The capturers must be unregistered here as it runs out of it's scope |   911     // The capturers must be unregistered here as it runs out of it's scope | 
|   913     // next. |   912     // next. | 
|   914     EXPECT_TRUE(channel_->SetCapturer(1, NULL)); |   913     channel_->SetSource(1, NULL); | 
|   915     EXPECT_TRUE(channel_->SetCapturer(2, NULL)); |   914     channel_->SetSource(2, NULL); | 
|   916   } |   915   } | 
|   917  |   916  | 
|   918   void HighAspectHighHeightCapturer() { |   917   void HighAspectHighHeightCapturer() { | 
|   919     const int kWidth  = 80; |   918     const int kWidth  = 80; | 
|   920     const int kHeight = 10000; |   919     const int kHeight = 10000; | 
|   921     const int kScaledWidth = 20; |   920     const int kScaledWidth = 20; | 
|   922     const int kScaledHeight = 2500; |   921     const int kScaledHeight = 2500; | 
|   923  |   922  | 
|   924     cricket::VideoCodec codec(DefaultCodec()); |   923     cricket::VideoCodec codec(DefaultCodec()); | 
|   925     EXPECT_TRUE(SetOneCodec(codec)); |   924     EXPECT_TRUE(SetOneCodec(codec)); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|   938     // Registering an external capturer is currently the same as screen casting |   937     // Registering an external capturer is currently the same as screen casting | 
|   939     // (update the test when this changes). |   938     // (update the test when this changes). | 
|   940     std::unique_ptr<cricket::FakeVideoCapturer> capturer( |   939     std::unique_ptr<cricket::FakeVideoCapturer> capturer( | 
|   941         CreateFakeVideoCapturer()); |   940         CreateFakeVideoCapturer()); | 
|   942     const std::vector<cricket::VideoFormat>* formats = |   941     const std::vector<cricket::VideoFormat>* formats = | 
|   943         capturer->GetSupportedFormats(); |   942         capturer->GetSupportedFormats(); | 
|   944     cricket::VideoFormat capture_format = (*formats)[0]; |   943     cricket::VideoFormat capture_format = (*formats)[0]; | 
|   945     EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); |   944     EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format)); | 
|   946     // Capture frame to not get same frame timestamps as previous capturer. |   945     // Capture frame to not get same frame timestamps as previous capturer. | 
|   947     capturer->CaptureFrame(); |   946     capturer->CaptureFrame(); | 
|   948     EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get())); |   947     channel_->SetSource(kSsrc, capturer.get()); | 
|   949     EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); |   948     EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(30)); | 
|   950     EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, |   949     EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, | 
|   951                                              cricket::FOURCC_ARGB)); |   950                                              cricket::FOURCC_ARGB)); | 
|   952     EXPECT_GT_FRAME_ON_RENDERER_WAIT( |   951     EXPECT_GT_FRAME_ON_RENDERER_WAIT( | 
|   953         renderer, 2, kScaledWidth, kScaledHeight, kTimeout); |   952         renderer, 2, kScaledWidth, kScaledHeight, kTimeout); | 
|   954     EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); |   953     channel_->SetSource(kSsrc, NULL); | 
|   955   } |   954   } | 
|   956  |   955  | 
|   957   // Tests that we can adapt video resolution with 16:10 aspect ratio properly. |   956   // Tests that we can adapt video resolution with 16:10 aspect ratio properly. | 
|   958   void AdaptResolution16x10() { |   957   void AdaptResolution16x10() { | 
|   959     EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |   958     EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); | 
|   960     cricket::VideoCodec codec(DefaultCodec()); |   959     cricket::VideoCodec codec(DefaultCodec()); | 
|   961     codec.width = 640; |   960     codec.width = 640; | 
|   962     codec.height = 400; |   961     codec.height = 400; | 
|   963     SendAndReceive(codec); |   962     SendAndReceive(codec); | 
|   964     codec.width /= 2; |   963     codec.width /= 2; | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1055     EXPECT_TRUE(SendFrame()); |  1054     EXPECT_TRUE(SendFrame()); | 
|  1056     EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); |  1055     EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); | 
|  1057  |  1056  | 
|  1058     // Check that we send smaller frames at the new resolution. |  1057     // Check that we send smaller frames at the new resolution. | 
|  1059     EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(33)); |  1058     EXPECT_TRUE(rtc::Thread::Current()->ProcessMessages(33)); | 
|  1060     EXPECT_TRUE(video_capturer_->CaptureCustomFrame( |  1059     EXPECT_TRUE(video_capturer_->CaptureCustomFrame( | 
|  1061         codec.width / 2, codec.height / 2, cricket::FOURCC_I420)); |  1060         codec.width / 2, codec.height / 2, cricket::FOURCC_I420)); | 
|  1062     EXPECT_FRAME_WAIT(2, codec.width / 2, codec.height / 2, kTimeout); |  1061     EXPECT_FRAME_WAIT(2, codec.width / 2, codec.height / 2, kTimeout); | 
|  1063   } |  1062   } | 
|  1064  |  1063  | 
|  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. |  1064   // Test that multiple send streams can be created and deleted properly. | 
|  1117   void MultipleSendStreams() { |  1065   void MultipleSendStreams() { | 
|  1118     // Remove stream added in Setup. I.e. remove stream corresponding to default |  1066     // Remove stream added in Setup. I.e. remove stream corresponding to default | 
|  1119     // channel. |  1067     // channel. | 
|  1120     EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |  1068     EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); | 
|  1121     const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); |  1069     const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); | 
|  1122     for (unsigned int i = 0; i < kSsrcsSize; ++i) { |  1070     for (unsigned int i = 0; i < kSsrcsSize; ++i) { | 
|  1123       EXPECT_TRUE(channel_->AddSendStream( |  1071       EXPECT_TRUE(channel_->AddSendStream( | 
|  1124           cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |  1072           cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); | 
|  1125     } |  1073     } | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  1150   std::unique_ptr<C> channel_; |  1098   std::unique_ptr<C> channel_; | 
|  1151   cricket::FakeNetworkInterface network_interface_; |  1099   cricket::FakeNetworkInterface network_interface_; | 
|  1152   cricket::FakeVideoRenderer renderer_; |  1100   cricket::FakeVideoRenderer renderer_; | 
|  1153   cricket::VideoMediaChannel::Error media_error_; |  1101   cricket::VideoMediaChannel::Error media_error_; | 
|  1154  |  1102  | 
|  1155   // Used by test cases where 2 streams are run on the same channel. |  1103   // Used by test cases where 2 streams are run on the same channel. | 
|  1156   cricket::FakeVideoRenderer renderer2_; |  1104   cricket::FakeVideoRenderer renderer2_; | 
|  1157 }; |  1105 }; | 
|  1158  |  1106  | 
|  1159 #endif  // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_  NOLINT |  1107 #endif  // WEBRTC_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_  NOLINT | 
| OLD | NEW |