OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 class TestPacketSender : public transport::PacketSender { | 55 class TestPacketSender : public transport::PacketSender { |
56 public: | 56 public: |
57 TestPacketSender() : number_of_rtp_packets_(0), number_of_rtcp_packets_(0) {} | 57 TestPacketSender() : number_of_rtp_packets_(0), number_of_rtcp_packets_(0) {} |
58 | 58 |
59 // A singular packet implies a RTCP packet. | 59 // A singular packet implies a RTCP packet. |
60 virtual bool SendPacket(transport::PacketRef packet, | 60 virtual bool SendPacket(transport::PacketRef packet, |
61 const base::Closure& cb) OVERRIDE { | 61 const base::Closure& cb) OVERRIDE { |
62 if (Rtcp::IsRtcpPacket(&packet->data[0], packet->data.size())) { | 62 if (Rtcp::IsRtcpPacket(&packet->data[0], packet->data.size())) { |
63 ++number_of_rtcp_packets_; | 63 ++number_of_rtcp_packets_; |
64 } else { | 64 } else { |
| 65 // Check that at least one RTCP packet was sent before the first RTP |
| 66 // packet. This confirms that the receiver will have the necessary lip |
| 67 // sync info before it has to calculate the playout time of the first |
| 68 // frame. |
| 69 if (number_of_rtp_packets_ == 0) |
| 70 EXPECT_LE(1, number_of_rtcp_packets_); |
65 ++number_of_rtp_packets_; | 71 ++number_of_rtp_packets_; |
66 } | 72 } |
67 return true; | 73 return true; |
68 } | 74 } |
69 | 75 |
70 int number_of_rtp_packets() const { return number_of_rtp_packets_; } | 76 int number_of_rtp_packets() const { return number_of_rtp_packets_; } |
71 | 77 |
72 int number_of_rtcp_packets() const { return number_of_rtcp_packets_; } | 78 int number_of_rtcp_packets() const { return number_of_rtcp_packets_; } |
73 | 79 |
74 private: | 80 private: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 128 } |
123 | 129 |
124 virtual ~VideoSenderTest() {} | 130 virtual ~VideoSenderTest() {} |
125 | 131 |
126 virtual void TearDown() OVERRIDE { | 132 virtual void TearDown() OVERRIDE { |
127 video_sender_.reset(); | 133 video_sender_.reset(); |
128 task_runner_->RunTasks(); | 134 task_runner_->RunTasks(); |
129 } | 135 } |
130 | 136 |
131 static void UpdateCastTransportStatus(transport::CastTransportStatus status) { | 137 static void UpdateCastTransportStatus(transport::CastTransportStatus status) { |
132 EXPECT_EQ(status, transport::TRANSPORT_VIDEO_INITIALIZED); | 138 EXPECT_EQ(transport::TRANSPORT_VIDEO_INITIALIZED, status); |
133 } | 139 } |
134 | 140 |
135 void InitEncoder(bool external) { | 141 void InitEncoder(bool external) { |
136 VideoSenderConfig video_config; | 142 VideoSenderConfig video_config; |
137 video_config.rtp_config.ssrc = 1; | 143 video_config.rtp_config.ssrc = 1; |
138 video_config.incoming_feedback_ssrc = 2; | 144 video_config.incoming_feedback_ssrc = 2; |
139 video_config.rtcp_c_name = "video_test@10.1.1.1"; | 145 video_config.rtcp_c_name = "video_test@10.1.1.1"; |
140 video_config.rtp_config.payload_type = 127; | 146 video_config.rtp_config.payload_type = 127; |
141 video_config.use_external_encoder = external; | 147 video_config.use_external_encoder = external; |
142 video_config.width = kWidth; | 148 video_config.width = kWidth; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 192 |
187 void RunTasks(int during_ms) { | 193 void RunTasks(int during_ms) { |
188 for (int i = 0; i < during_ms; ++i) { | 194 for (int i = 0; i < during_ms; ++i) { |
189 // Call process the timers every 1 ms. | 195 // Call process the timers every 1 ms. |
190 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(1)); | 196 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(1)); |
191 task_runner_->RunTasks(); | 197 task_runner_->RunTasks(); |
192 } | 198 } |
193 } | 199 } |
194 | 200 |
195 void InitializationResult(CastInitializationStatus result) { | 201 void InitializationResult(CastInitializationStatus result) { |
196 EXPECT_EQ(result, STATUS_VIDEO_INITIALIZED); | 202 EXPECT_EQ(STATUS_VIDEO_INITIALIZED, result); |
197 } | 203 } |
198 | 204 |
199 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. | 205 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. |
200 TestPacketSender transport_; | 206 TestPacketSender transport_; |
201 scoped_ptr<transport::CastTransportSenderImpl> transport_sender_; | 207 scoped_ptr<transport::CastTransportSenderImpl> transport_sender_; |
202 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 208 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
203 scoped_ptr<PeerVideoSender> video_sender_; | 209 scoped_ptr<PeerVideoSender> video_sender_; |
204 scoped_refptr<CastEnvironment> cast_environment_; | 210 scoped_refptr<CastEnvironment> cast_environment_; |
205 | 211 |
206 DISALLOW_COPY_AND_ASSIGN(VideoSenderTest); | 212 DISALLOW_COPY_AND_ASSIGN(VideoSenderTest); |
207 }; | 213 }; |
208 | 214 |
209 TEST_F(VideoSenderTest, BuiltInEncoder) { | 215 TEST_F(VideoSenderTest, BuiltInEncoder) { |
210 InitEncoder(false); | 216 InitEncoder(false); |
211 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); | 217 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); |
212 | 218 |
213 const base::TimeTicks capture_time = testing_clock_->NowTicks(); | 219 const base::TimeTicks capture_time = testing_clock_->NowTicks(); |
214 video_sender_->InsertRawVideoFrame(video_frame, capture_time); | 220 video_sender_->InsertRawVideoFrame(video_frame, capture_time); |
215 | 221 |
216 task_runner_->RunTasks(); | 222 task_runner_->RunTasks(); |
217 EXPECT_GE( | 223 EXPECT_LE(1, transport_.number_of_rtp_packets()); |
218 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets(), | 224 EXPECT_LE(1, transport_.number_of_rtcp_packets()); |
219 1); | |
220 } | 225 } |
221 | 226 |
222 TEST_F(VideoSenderTest, ExternalEncoder) { | 227 TEST_F(VideoSenderTest, ExternalEncoder) { |
223 InitEncoder(true); | 228 InitEncoder(true); |
224 task_runner_->RunTasks(); | 229 task_runner_->RunTasks(); |
225 | 230 |
226 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); | 231 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); |
227 | 232 |
228 const base::TimeTicks capture_time = testing_clock_->NowTicks(); | 233 const base::TimeTicks capture_time = testing_clock_->NowTicks(); |
229 video_sender_->InsertRawVideoFrame(video_frame, capture_time); | 234 video_sender_->InsertRawVideoFrame(video_frame, capture_time); |
(...skipping 11 matching lines...) Expand all Loading... |
241 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); | 246 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); |
242 | 247 |
243 const base::TimeTicks capture_time = testing_clock_->NowTicks(); | 248 const base::TimeTicks capture_time = testing_clock_->NowTicks(); |
244 video_sender_->InsertRawVideoFrame(video_frame, capture_time); | 249 video_sender_->InsertRawVideoFrame(video_frame, capture_time); |
245 | 250 |
246 // Make sure that we send at least one RTCP packet. | 251 // Make sure that we send at least one RTCP packet. |
247 base::TimeDelta max_rtcp_timeout = | 252 base::TimeDelta max_rtcp_timeout = |
248 base::TimeDelta::FromMilliseconds(1 + kDefaultRtcpIntervalMs * 3 / 2); | 253 base::TimeDelta::FromMilliseconds(1 + kDefaultRtcpIntervalMs * 3 / 2); |
249 | 254 |
250 RunTasks(max_rtcp_timeout.InMilliseconds()); | 255 RunTasks(max_rtcp_timeout.InMilliseconds()); |
251 EXPECT_GE(transport_.number_of_rtp_packets(), 1); | 256 EXPECT_LE(1, transport_.number_of_rtp_packets()); |
252 // Don't send RTCP prior to receiving an ACK. | 257 EXPECT_LE(1, transport_.number_of_rtcp_packets()); |
253 EXPECT_GE(transport_.number_of_rtcp_packets(), 0); | |
254 // Build Cast msg and expect RTCP packet. | 258 // Build Cast msg and expect RTCP packet. |
255 RtcpCastMessage cast_feedback(1); | 259 RtcpCastMessage cast_feedback(1); |
256 cast_feedback.media_ssrc_ = 2; | 260 cast_feedback.media_ssrc_ = 2; |
257 cast_feedback.ack_frame_id_ = 0; | 261 cast_feedback.ack_frame_id_ = 0; |
258 video_sender_->OnReceivedCastFeedback(cast_feedback); | 262 video_sender_->OnReceivedCastFeedback(cast_feedback); |
259 RunTasks(max_rtcp_timeout.InMilliseconds()); | 263 RunTasks(max_rtcp_timeout.InMilliseconds()); |
260 EXPECT_GE(transport_.number_of_rtcp_packets(), 1); | 264 EXPECT_LE(1, transport_.number_of_rtcp_packets()); |
261 } | 265 } |
262 | 266 |
263 TEST_F(VideoSenderTest, ResendTimer) { | 267 TEST_F(VideoSenderTest, ResendTimer) { |
264 InitEncoder(false); | 268 InitEncoder(false); |
265 | 269 |
266 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); | 270 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); |
267 | 271 |
268 const base::TimeTicks capture_time = testing_clock_->NowTicks(); | 272 const base::TimeTicks capture_time = testing_clock_->NowTicks(); |
269 video_sender_->InsertRawVideoFrame(video_frame, capture_time); | 273 video_sender_->InsertRawVideoFrame(video_frame, capture_time); |
270 | 274 |
271 // ACK the key frame. | 275 // ACK the key frame. |
272 RtcpCastMessage cast_feedback(1); | 276 RtcpCastMessage cast_feedback(1); |
273 cast_feedback.media_ssrc_ = 2; | 277 cast_feedback.media_ssrc_ = 2; |
274 cast_feedback.ack_frame_id_ = 0; | 278 cast_feedback.ack_frame_id_ = 0; |
275 video_sender_->OnReceivedCastFeedback(cast_feedback); | 279 video_sender_->OnReceivedCastFeedback(cast_feedback); |
276 | 280 |
277 video_frame = GetNewVideoFrame(); | 281 video_frame = GetNewVideoFrame(); |
278 video_sender_->InsertRawVideoFrame(video_frame, capture_time); | 282 video_sender_->InsertRawVideoFrame(video_frame, capture_time); |
279 | 283 |
280 base::TimeDelta max_resend_timeout = | 284 base::TimeDelta max_resend_timeout = |
281 base::TimeDelta::FromMilliseconds(1 + kDefaultRtpMaxDelayMs); | 285 base::TimeDelta::FromMilliseconds(1 + kDefaultRtpMaxDelayMs); |
282 | 286 |
283 // Make sure that we do a re-send. | 287 // Make sure that we do a re-send. |
284 RunTasks(max_resend_timeout.InMilliseconds()); | 288 RunTasks(max_resend_timeout.InMilliseconds()); |
285 // Should have sent at least 3 packets. | 289 // Should have sent at least 3 packets. |
286 EXPECT_GE( | 290 EXPECT_LE( |
287 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets(), | 291 3, |
288 3); | 292 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets()); |
289 } | 293 } |
290 | 294 |
291 TEST_F(VideoSenderTest, LogAckReceivedEvent) { | 295 TEST_F(VideoSenderTest, LogAckReceivedEvent) { |
292 InitEncoder(false); | 296 InitEncoder(false); |
293 SimpleEventSubscriber event_subscriber; | 297 SimpleEventSubscriber event_subscriber; |
294 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber); | 298 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber); |
295 | 299 |
296 int num_frames = 10; | 300 int num_frames = 10; |
297 for (int i = 0; i < num_frames; i++) { | 301 for (int i = 0; i < num_frames; i++) { |
298 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); | 302 scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 350 } |
347 | 351 |
348 EXPECT_EQ(number_of_packets_sent + size_of_frame0, | 352 EXPECT_EQ(number_of_packets_sent + size_of_frame0, |
349 transport_.number_of_rtp_packets()); | 353 transport_.number_of_rtp_packets()); |
350 | 354 |
351 // Start acking and make sure we're back to steady-state. | 355 // Start acking and make sure we're back to steady-state. |
352 RtcpCastMessage cast_feedback(1); | 356 RtcpCastMessage cast_feedback(1); |
353 cast_feedback.media_ssrc_ = 2; | 357 cast_feedback.media_ssrc_ = 2; |
354 cast_feedback.ack_frame_id_ = 0; | 358 cast_feedback.ack_frame_id_ = 0; |
355 video_sender_->OnReceivedCastFeedback(cast_feedback); | 359 video_sender_->OnReceivedCastFeedback(cast_feedback); |
356 EXPECT_GE( | 360 EXPECT_LE( |
357 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets(), | 361 4, |
358 4); | 362 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets()); |
359 | 363 |
360 // Empty the pipeline. | 364 // Empty the pipeline. |
361 RunTasks(100); | 365 RunTasks(100); |
362 // Should have sent at least 7 packets. | 366 // Should have sent at least 7 packets. |
363 EXPECT_GE( | 367 EXPECT_LE( |
364 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets(), | 368 7, |
365 7); | 369 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets()); |
366 } | 370 } |
367 | 371 |
368 } // namespace cast | 372 } // namespace cast |
369 } // namespace media | 373 } // namespace media |
OLD | NEW |