X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2Flibjingle%2Fsource%2Ftalk%2Fmedia%2Fbase%2Fvideoengine_unittest.h;h=6c782bd0ebc67e3e5e2a9099fe6f25987b08e9a4;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=d8b9bcb29559d31fe1d117e8f48aad88f550bd75;hpb=172ee7c03df346ff158858709f7f6494e695e0e4;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/libjingle/source/talk/media/base/videoengine_unittest.h b/src/third_party/libjingle/source/talk/media/base/videoengine_unittest.h index d8b9bcb..6c782bd 100644 --- a/src/third_party/libjingle/source/talk/media/base/videoengine_unittest.h +++ b/src/third_party/libjingle/source/talk/media/base/videoengine_unittest.h @@ -54,6 +54,12 @@ EXPECT_EQ((h), (r).height()); \ EXPECT_EQ(0, (r).errors()); \ +#define EXPECT_GT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ + EXPECT_TRUE_WAIT((r).num_rendered_frames() >= (c) && \ + (w) == (r).width() && \ + (h) == (r).height(), (t)); \ + EXPECT_EQ(0, (r).errors()); \ + static const uint32 kTimeout = 5000U; static const uint32 kSsrc = 1234u; static const uint32 kRtxSsrc = 4321u; @@ -69,11 +75,13 @@ inline bool IsEqualCodec(const cricket::VideoCodec& a, IsEqualRes(a, b.width, b.height, b.framerate); } +namespace std { inline std::ostream& operator<<(std::ostream& s, const cricket::VideoCodec& c) { s << "{" << c.name << "(" << c.id << "), " << c.width << "x" << c.height << "x" << c.framerate << "}"; return s; } +} // namespace std inline int TimeBetweenSend(const cricket::VideoCodec& codec) { return static_cast( @@ -773,7 +781,7 @@ class VideoMediaChannelTest : public testing::Test, void GetStats() { SendAndReceive(DefaultCodec()); cricket::VideoMediaInfo info; - EXPECT_TRUE(channel_->GetStats(&info)); + EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info)); ASSERT_EQ(1U, info.senders.size()); // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload? @@ -782,15 +790,15 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_EQ(0.0, info.senders[0].fraction_lost); EXPECT_EQ(0, info.senders[0].firs_rcvd); EXPECT_EQ(0, info.senders[0].nacks_rcvd); - EXPECT_EQ(DefaultCodec().width, info.senders[0].frame_width); - EXPECT_EQ(DefaultCodec().height, info.senders[0].frame_height); + EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); + EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); EXPECT_GT(info.senders[0].framerate_input, 0); EXPECT_GT(info.senders[0].framerate_sent, 0); ASSERT_EQ(1U, info.receivers.size()); - EXPECT_EQ(1U, info.senders[0].ssrcs.size()); - EXPECT_EQ(1U, info.receivers[0].ssrcs.size()); - EXPECT_EQ(info.senders[0].ssrcs[0], info.receivers[0].ssrcs[0]); + EXPECT_EQ(1U, info.senders[0].ssrcs().size()); + EXPECT_EQ(1U, info.receivers[0].ssrcs().size()); + EXPECT_EQ(info.senders[0].ssrcs()[0], info.receivers[0].ssrcs()[0]); EXPECT_EQ(NumRtpBytes(), info.receivers[0].bytes_rcvd); EXPECT_EQ(NumRtpPackets(), info.receivers[0].packets_rcvd); EXPECT_EQ(0.0, info.receivers[0].fraction_lost); @@ -831,7 +839,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_FRAME_ON_RENDERER_WAIT( renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout); cricket::VideoMediaInfo info; - EXPECT_TRUE(channel_->GetStats(&info)); + EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info)); ASSERT_EQ(1U, info.senders.size()); // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload? @@ -840,15 +848,15 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_EQ(0.0, info.senders[0].fraction_lost); EXPECT_EQ(0, info.senders[0].firs_rcvd); EXPECT_EQ(0, info.senders[0].nacks_rcvd); - EXPECT_EQ(DefaultCodec().width, info.senders[0].frame_width); - EXPECT_EQ(DefaultCodec().height, info.senders[0].frame_height); + EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); + EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); EXPECT_GT(info.senders[0].framerate_input, 0); EXPECT_GT(info.senders[0].framerate_sent, 0); ASSERT_EQ(2U, info.receivers.size()); for (size_t i = 0; i < info.receivers.size(); ++i) { - EXPECT_EQ(1U, info.receivers[i].ssrcs.size()); - EXPECT_EQ(i + 1, info.receivers[i].ssrcs[0]); + EXPECT_EQ(1U, info.receivers[i].ssrcs().size()); + EXPECT_EQ(i + 1, info.receivers[i].ssrcs()[0]); EXPECT_EQ(NumRtpBytes(), info.receivers[i].bytes_rcvd); EXPECT_EQ(NumRtpPackets(), info.receivers[i].packets_rcvd); EXPECT_EQ(0.0, info.receivers[i].fraction_lost); @@ -885,8 +893,11 @@ class VideoMediaChannelTest : public testing::Test, talk_base::scoped_ptr capturer( new cricket::FakeVideoCapturer); capturer->SetScreencast(true); - cricket::VideoFormat format(1024, 768, - cricket::VideoFormat::FpsToInterval(5), 0); + const int kTestWidth = 160; + const int kTestHeight = 120; + cricket::VideoFormat format(kTestWidth, kTestHeight, + cricket::VideoFormat::FpsToInterval(5), + cricket::FOURCC_I420); EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); EXPECT_TRUE(channel_->AddSendStream( cricket::StreamParams::CreateLegacy(5678))); @@ -894,33 +905,34 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(channel_->AddRecvStream( cricket::StreamParams::CreateLegacy(5678))); EXPECT_TRUE(channel_->SetRenderer(5678, &renderer1)); - EXPECT_TRUE(capturer->CaptureCustomFrame(1024, 768, cricket::FOURCC_I420)); - EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, 1024, 768, kTimeout); + EXPECT_TRUE(capturer->CaptureCustomFrame( + kTestWidth, kTestHeight, cricket::FOURCC_I420)); + EXPECT_FRAME_ON_RENDERER_WAIT( + renderer1, 1, kTestWidth, kTestHeight, kTimeout); // Get stats, and make sure they are correct for two senders. cricket::VideoMediaInfo info; - EXPECT_TRUE(channel_->GetStats(&info)); + EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info)); ASSERT_EQ(2U, info.senders.size()); EXPECT_EQ(NumRtpPackets(), info.senders[0].packets_sent + info.senders[1].packets_sent); - EXPECT_EQ(1U, info.senders[0].ssrcs.size()); - EXPECT_EQ(1234U, info.senders[0].ssrcs[0]); - EXPECT_EQ(DefaultCodec().width, info.senders[0].frame_width); - EXPECT_EQ(DefaultCodec().height, info.senders[0].frame_height); - EXPECT_EQ(1U, info.senders[1].ssrcs.size()); - EXPECT_EQ(5678U, info.senders[1].ssrcs[0]); - EXPECT_EQ(1024, info.senders[1].frame_width); - EXPECT_EQ(768, info.senders[1].frame_height); + EXPECT_EQ(1U, info.senders[0].ssrcs().size()); + EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); + EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width); + EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height); + EXPECT_EQ(1U, info.senders[1].ssrcs().size()); + EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); + EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); + EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); // The capturer must be unregistered here as it runs out of it's scope next. EXPECT_TRUE(channel_->SetCapturer(5678, NULL)); } - // Test that we can set the bandwidth to auto or a specific value. + // Test that we can set the bandwidth. void SetSendBandwidth() { - EXPECT_TRUE(channel_->SetSendBandwidth(true, -1)); - EXPECT_TRUE(channel_->SetSendBandwidth(true, 128 * 1024)); - EXPECT_TRUE(channel_->SetSendBandwidth(false, -1)); - EXPECT_TRUE(channel_->SetSendBandwidth(false, 128 * 1024)); + EXPECT_TRUE(channel_->SetStartSendBandwidth(64 * 1024)); + EXPECT_TRUE(channel_->SetMaxSendBandwidth(-1)); // <= 0 means unlimited. + EXPECT_TRUE(channel_->SetMaxSendBandwidth(128 * 1024)); } // Test that we can set the SSRC for the default send source. void SetSendSsrc() { @@ -973,7 +985,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->SetRender(true)); EXPECT_EQ(0, renderer_.num_rendered_frames()); - channel_->OnPacketReceived(&packet1); + channel_->OnPacketReceived(&packet1, talk_base::PacketTime()); SetRendererAsDefault(); EXPECT_TRUE(SendFrame()); EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout); @@ -1000,7 +1012,8 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_GE(2, NumRtpPackets()); uint32 ssrc = 0; size_t last_packet = NumRtpPackets() - 1; - talk_base::scoped_ptr p(GetRtpPacket(last_packet)); + talk_base::scoped_ptr + p(GetRtpPacket(static_cast(last_packet))); ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); EXPECT_EQ(kSsrc, ssrc); @@ -1017,7 +1030,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); last_packet = NumRtpPackets() - 1; - p.reset(GetRtpPacket(last_packet)); + p.reset(GetRtpPacket(static_cast(last_packet))); ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); EXPECT_EQ(789u, ssrc); } @@ -1165,8 +1178,14 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(channel_->SetRenderer(kSsrc, &renderer1)); EXPECT_TRUE(SendFrame()); - EXPECT_FRAME_ON_RENDERER_WAIT( + // Because the default channel is used, RemoveRecvStream above is not going + // to delete the channel. As a result the engine will continue to receive + // and decode the 3 frames sent above. So it is possible we will receive + // some (e.g. 1) of these 3 frames after the renderer is set again. + EXPECT_GT_FRAME_ON_RENDERER_WAIT( renderer1, 2, DefaultCodec().width, DefaultCodec().height, kTimeout); + // Detach |renderer1| before exit as there might be frames come late. + EXPECT_TRUE(channel_->SetRenderer(kSsrc, NULL)); } // Tests the behavior of incoming streams in a conference scenario. @@ -1208,9 +1227,11 @@ class VideoMediaChannelTest : public testing::Test, // Tests that we can add and remove capturers and frames are sent out properly void AddRemoveCapturer() { - const cricket::VideoCodec codec(DefaultCodec()); + cricket::VideoCodec codec = DefaultCodec(); + codec.width = 320; + codec.height = 240; const int time_between_send = TimeBetweenSend(codec); - EXPECT_TRUE(SetDefaultCodec()); + EXPECT_TRUE(SetOneCodec(codec)); EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->SetRender(true)); EXPECT_EQ(0, renderer_.num_rendered_frames()); @@ -1219,8 +1240,9 @@ class VideoMediaChannelTest : public testing::Test, talk_base::scoped_ptr capturer( new cricket::FakeVideoCapturer); capturer->SetScreencast(true); - cricket::VideoFormat format(1024, 768, - cricket::VideoFormat::FpsToInterval(30), 0); + cricket::VideoFormat format(480, 360, + cricket::VideoFormat::FpsToInterval(30), + cricket::FOURCC_I420); EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); // All capturers start generating frames with the same timestamp. ViE does // not allow the same timestamp to be used. Capture one frame before @@ -1277,27 +1299,21 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_FRAME_WAIT(1, 640, 400, kTimeout); // Remove the capturer. EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); + // Wait for one black frame for removing the capturer. + EXPECT_FRAME_WAIT(2, 640, 400, kTimeout); + // No capturer was added, so this RemoveCapturer should // fail. EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL)); - // Wait for frames to stop flowing. talk_base::Thread::Current()->ProcessMessages(300); - int num_frames = renderer_.num_rendered_frames(); - // Wait to make sure no more frames are sent - WAIT(renderer_.num_rendered_frames() != num_frames, 300); // Verify no more frames were sent. - EXPECT_EQ(num_frames, renderer_.num_rendered_frames()); + EXPECT_EQ(2, renderer_.num_rendered_frames()); } // Tests that we can add and remove capturer as unique sources. void AddRemoveCapturerMultipleSources() { // WebRTC implementation will drop frames if pushed to quickly. Wait the // interval time to avoid that. - const cricket::VideoFormat send_format( - 1024, - 768, - cricket::VideoFormat::FpsToInterval(30), - 0); // WebRTC implementation will drop frames if pushed to quickly. Wait the // interval time to avoid that. // Set up the stream associated with the engine. @@ -1340,11 +1356,17 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->SetRender(true)); // Test capturer associated with engine. - EXPECT_TRUE(capturer1->CaptureCustomFrame(1024, 768, cricket::FOURCC_I420)); - EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, 1024, 768, kTimeout); + const int kTestWidth = 160; + const int kTestHeight = 120; + EXPECT_TRUE(capturer1->CaptureCustomFrame( + kTestWidth, kTestHeight, cricket::FOURCC_I420)); + EXPECT_FRAME_ON_RENDERER_WAIT( + renderer1, 1, kTestWidth, kTestHeight, kTimeout); // Capture a frame with additional capturer2, frames should be received - EXPECT_TRUE(capturer2->CaptureCustomFrame(1024, 768, cricket::FOURCC_I420)); - EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, 1024, 768, kTimeout); + EXPECT_TRUE(capturer2->CaptureCustomFrame( + kTestWidth, kTestHeight, cricket::FOURCC_I420)); + EXPECT_FRAME_ON_RENDERER_WAIT( + renderer2, 1, kTestWidth, kTestHeight, kTimeout); // Successfully remove the capturer. EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); // Fail to re-remove the capturer. @@ -1373,10 +1395,8 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_EQ(0, renderer.num_rendered_frames()); EXPECT_TRUE(SendFrame()); - EXPECT_TRUE_WAIT(renderer.num_rendered_frames() >= 1 && - codec.width == renderer.width() && - codec.height == renderer.height(), kTimeout); - EXPECT_EQ(0, renderer.errors()); + EXPECT_GT_FRAME_ON_RENDERER_WAIT( + renderer, 1, codec.width, codec.height, kTimeout); // Registering an external capturer is currently the same as screen casting // (update the test when this changes). @@ -1394,9 +1414,8 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight, cricket::FOURCC_ARGB)); EXPECT_TRUE(capturer->CaptureFrame()); - EXPECT_TRUE_WAIT(renderer.num_rendered_frames() >= 2 && - kScaledWidth == renderer.width() && - kScaledHeight == renderer.height(), kTimeout); + EXPECT_GT_FRAME_ON_RENDERER_WAIT( + renderer, 2, kScaledWidth, kScaledHeight, kTimeout); EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); }