diff options
Diffstat (limited to 'media/cast/video_sender/video_sender_unittest.cc')
-rw-r--r-- | media/cast/video_sender/video_sender_unittest.cc | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/media/cast/video_sender/video_sender_unittest.cc b/media/cast/video_sender/video_sender_unittest.cc index 46a11380d1..8c56602a68 100644 --- a/media/cast/video_sender/video_sender_unittest.cc +++ b/media/cast/video_sender/video_sender_unittest.cc @@ -7,10 +7,12 @@ #include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "base/test/simple_test_tick_clock.h" +#include "media/base/video_frame.h" #include "media/cast/cast_environment.h" #include "media/cast/pacing/mock_paced_packet_sender.h" #include "media/cast/pacing/paced_sender.h" #include "media/cast/test/fake_task_runner.h" +#include "media/cast/test/video_utility.h" #include "media/cast/video_sender/mock_video_encoder_controller.h" #include "media/cast/video_sender/video_sender.h" #include "testing/gmock/include/gmock/gmock.h" @@ -19,11 +21,17 @@ namespace media { namespace cast { +namespace { static const int64 kStartMillisecond = GG_INT64_C(12345678900000); static const uint8 kPixelValue = 123; +static const int kWidth = 320; +static const int kHeight = 240; +} using testing::_; +using testing::AtLeast; +namespace { class PeerVideoSender : public VideoSender { public: PeerVideoSender(scoped_refptr<CastEnvironment> cast_environment, @@ -35,17 +43,7 @@ class PeerVideoSender : public VideoSender { } using VideoSender::OnReceivedCastFeedback; }; - -static void ReleaseVideoFrame(const I420VideoFrame* frame) { - delete [] frame->y_plane.data; - delete [] frame->u_plane.data; - delete [] frame->v_plane.data; - delete frame; -} - -static void ReleaseEncodedFrame(const EncodedVideoFrame* frame) { - // Do nothing. -} +} // namespace class VideoSenderTest : public ::testing::Test { protected: @@ -62,8 +60,8 @@ class VideoSenderTest : public ::testing::Test { video_config.incoming_feedback_ssrc = 2; video_config.rtp_payload_type = 127; video_config.use_external_encoder = external; - video_config.width = 320; - video_config.height = 240; + video_config.width = kWidth; + video_config.height = kHeight; video_config.max_bitrate = 5000000; video_config.min_bitrate = 1000000; video_config.start_bitrate = 1000000; @@ -85,32 +83,16 @@ class VideoSenderTest : public ::testing::Test { virtual void SetUp() { task_runner_ = new test::FakeTaskRunner(&testing_clock_); cast_environment_ = new CastEnvironment(&testing_clock_, task_runner_, - task_runner_, task_runner_, task_runner_, task_runner_); + task_runner_, task_runner_, task_runner_, task_runner_, + GetDefaultCastLoggingConfig()); } - I420VideoFrame* AllocateNewVideoFrame() { - I420VideoFrame* video_frame = new I420VideoFrame(); - video_frame->width = 320; - video_frame->height = 240; - - video_frame->y_plane.stride = video_frame->width; - video_frame->y_plane.length = video_frame->width; - video_frame->y_plane.data = - new uint8[video_frame->width * video_frame->height]; - memset(video_frame->y_plane.data, kPixelValue, - video_frame->width * video_frame->height); - video_frame->u_plane.stride = video_frame->width / 2; - video_frame->u_plane.length = video_frame->width / 2; - video_frame->u_plane.data = - new uint8[video_frame->width * video_frame->height / 4]; - memset(video_frame->u_plane.data, kPixelValue, - video_frame->width * video_frame->height / 4); - video_frame->v_plane.stride = video_frame->width / 2; - video_frame->v_plane.length = video_frame->width / 2; - video_frame->v_plane.data = - new uint8[video_frame->width * video_frame->height / 4]; - memset(video_frame->v_plane.data, kPixelValue, - video_frame->width * video_frame->height / 4); + scoped_refptr<media::VideoFrame> GetNewVideoFrame() { + gfx::Size size(kWidth, kHeight); + scoped_refptr<media::VideoFrame> video_frame = + media::VideoFrame::CreateFrame(VideoFrame::I420, size, gfx::Rect(size), + size, base::TimeDelta()); + PopulateVideoFrame(video_frame, kPixelValue); return video_frame; } @@ -126,11 +108,11 @@ TEST_F(VideoSenderTest, BuiltInEncoder) { EXPECT_CALL(mock_transport_, SendPackets(_)).Times(1); InitEncoder(false); - I420VideoFrame* video_frame = AllocateNewVideoFrame(); + scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); base::TimeTicks capture_time; video_sender_->InsertRawVideoFrame(video_frame, capture_time, - base::Bind(&ReleaseVideoFrame, video_frame)); + base::Bind(base::DoNothing)); task_runner_->RunTasks(); } @@ -150,12 +132,27 @@ TEST_F(VideoSenderTest, ExternalEncoder) { video_frame.data.insert(video_frame.data.begin(), 1000, kPixelValue); video_sender_->InsertCodedVideoFrame(&video_frame, capture_time, - base::Bind(&ReleaseEncodedFrame, &video_frame)); + base::Bind(base::DoNothing)); } TEST_F(VideoSenderTest, RtcpTimer) { + EXPECT_CALL(mock_transport_, SendPackets(_)).Times(AtLeast(1)); EXPECT_CALL(mock_transport_, SendRtcpPacket(_)).Times(1); - InitEncoder(false); + EXPECT_CALL(mock_video_encoder_controller_, + SkipNextFrame(false)).Times(AtLeast(1)); + InitEncoder(true); + + EncodedVideoFrame video_frame; + base::TimeTicks capture_time; + + video_frame.codec = kVp8; + video_frame.key_frame = true; + video_frame.frame_id = 0; + video_frame.last_referenced_frame_id = 0; + video_frame.data.insert(video_frame.data.begin(), 1000, kPixelValue); + + video_sender_->InsertCodedVideoFrame(&video_frame, capture_time, + base::Bind(base::DoNothing)); // Make sure that we send at least one RTCP packet. base::TimeDelta max_rtcp_timeout = @@ -171,11 +168,11 @@ TEST_F(VideoSenderTest, ResendTimer) { InitEncoder(false); - I420VideoFrame* video_frame = AllocateNewVideoFrame(); + scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); base::TimeTicks capture_time; video_sender_->InsertRawVideoFrame(video_frame, capture_time, - base::Bind(&ReleaseVideoFrame, video_frame)); + base::Bind(base::DoNothing)); task_runner_->RunTasks(); @@ -185,9 +182,9 @@ TEST_F(VideoSenderTest, ResendTimer) { cast_feedback.ack_frame_id_ = 0; video_sender_->OnReceivedCastFeedback(cast_feedback); - video_frame = AllocateNewVideoFrame(); + video_frame = GetNewVideoFrame(); video_sender_->InsertRawVideoFrame(video_frame, capture_time, - base::Bind(&ReleaseVideoFrame, video_frame)); + base::Bind(base::DoNothing)); task_runner_->RunTasks(); |