OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 265 |
266 int OnReceivedPayloadData(const uint8_t* payloadData, | 266 int OnReceivedPayloadData(const uint8_t* payloadData, |
267 const size_t payloadSize, | 267 const size_t payloadSize, |
268 const WebRtcRTPHeader* rtpHeader) override { | 268 const WebRtcRTPHeader* rtpHeader) override { |
269 return 0; | 269 return 0; |
270 } | 270 } |
271 RTCPReceiver* rtcp_receiver_; | 271 RTCPReceiver* rtcp_receiver_; |
272 RTCPHelp::RTCPPacketInformation rtcp_packet_info_; | 272 RTCPHelp::RTCPPacketInformation rtcp_packet_info_; |
273 }; | 273 }; |
274 | 274 |
| 275 namespace { |
| 276 static const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; |
| 277 static const int kMaxPacketLength = 1500; |
| 278 static const uint32_t kMainSsrc = 0x11111111; |
| 279 } |
| 280 |
275 class RtcpSenderTest : public ::testing::Test { | 281 class RtcpSenderTest : public ::testing::Test { |
276 protected: | 282 protected: |
277 static const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; | |
278 | |
279 RtcpSenderTest() | 283 RtcpSenderTest() |
280 : over_use_detector_options_(), | 284 : over_use_detector_options_(), |
281 clock_(1335900000), | 285 clock_(1335900000), |
282 rtp_payload_registry_(new RTPPayloadRegistry( | 286 rtp_payload_registry_(new RTPPayloadRegistry( |
283 RTPPayloadStrategy::CreateStrategy(false))), | 287 RTPPayloadStrategy::CreateStrategy(false))), |
284 remote_bitrate_observer_(), | 288 remote_bitrate_observer_(), |
285 remote_bitrate_estimator_( | 289 remote_bitrate_estimator_( |
286 RemoteBitrateEstimatorFactory().Create( | 290 RemoteBitrateEstimatorFactory().Create( |
287 &remote_bitrate_observer_, | 291 &remote_bitrate_observer_, |
288 &clock_, | 292 &clock_, |
289 kMimdControl, | 293 kMimdControl, |
290 kRemoteBitrateEstimatorMinBitrateBps)), | 294 kRemoteBitrateEstimatorMinBitrateBps)), |
291 receive_statistics_(ReceiveStatistics::Create(&clock_)) { | 295 receive_statistics_(ReceiveStatistics::Create(&clock_)) { |
292 test_transport_ = new TestTransport(); | 296 test_transport_ = new TestTransport(); |
293 | 297 |
294 RtpRtcp::Configuration configuration; | 298 RtpRtcp::Configuration configuration; |
295 configuration.id = 0; | 299 configuration.id = 0; |
296 configuration.audio = false; | 300 configuration.audio = false; |
297 configuration.clock = &clock_; | 301 configuration.clock = &clock_; |
298 configuration.outgoing_transport = test_transport_; | 302 configuration.outgoing_transport = test_transport_; |
299 configuration.remote_bitrate_estimator = remote_bitrate_estimator_.get(); | 303 configuration.remote_bitrate_estimator = remote_bitrate_estimator_.get(); |
300 | 304 |
301 rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration); | 305 rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration); |
302 rtp_receiver_.reset(RtpReceiver::CreateVideoReceiver( | 306 rtp_receiver_.reset(RtpReceiver::CreateVideoReceiver( |
303 0, &clock_, test_transport_, NULL, rtp_payload_registry_.get())); | 307 configuration.id, &clock_, test_transport_, NULL, |
| 308 rtp_payload_registry_.get())); |
304 rtcp_sender_ = | 309 rtcp_sender_ = |
305 new RTCPSender(0, false, &clock_, receive_statistics_.get(), NULL); | 310 new RTCPSender(configuration.id, false, &clock_, |
| 311 receive_statistics_.get(), NULL); |
| 312 rtcp_sender_->SetSSRC(kMainSsrc); |
306 rtcp_receiver_ = | 313 rtcp_receiver_ = |
307 new RTCPReceiver(0, &clock_, false, NULL, NULL, NULL, rtp_rtcp_impl_); | 314 new RTCPReceiver(configuration.id, &clock_, false, NULL, NULL, NULL, |
| 315 rtp_rtcp_impl_); |
| 316 rtcp_receiver_->SetRemoteSSRC(kMainSsrc); |
| 317 |
| 318 std::set<uint32_t> registered_ssrcs; |
| 319 registered_ssrcs.insert(kMainSsrc); |
| 320 rtcp_receiver_->SetSsrcs(kMainSsrc, registered_ssrcs); |
308 test_transport_->SetRTCPReceiver(rtcp_receiver_); | 321 test_transport_->SetRTCPReceiver(rtcp_receiver_); |
309 // Initialize | 322 // Initialize |
310 EXPECT_EQ(0, rtcp_sender_->RegisterSendTransport(test_transport_)); | 323 EXPECT_EQ(0, rtcp_sender_->RegisterSendTransport(test_transport_)); |
311 } | 324 } |
| 325 |
312 ~RtcpSenderTest() { | 326 ~RtcpSenderTest() { |
313 delete rtcp_sender_; | 327 delete rtcp_sender_; |
314 delete rtcp_receiver_; | 328 delete rtcp_receiver_; |
315 delete rtp_rtcp_impl_; | 329 delete rtp_rtcp_impl_; |
316 delete test_transport_; | 330 delete test_transport_; |
317 } | 331 } |
318 | 332 |
319 // Helper function: Incoming RTCP has a specific packet type. | 333 // Helper function: Incoming RTCP has a specific packet type. |
320 bool gotPacketType(RTCPPacketType packet_type) { | 334 bool gotPacketType(RTCPPacketType packet_type) { |
321 return ((test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags) & | 335 return ((test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags) & |
322 packet_type) != 0U; | 336 packet_type) != 0U; |
323 } | 337 } |
324 | 338 |
325 OverUseDetectorOptions over_use_detector_options_; | 339 OverUseDetectorOptions over_use_detector_options_; |
326 SimulatedClock clock_; | 340 SimulatedClock clock_; |
327 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; | 341 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; |
328 rtc::scoped_ptr<RtpReceiver> rtp_receiver_; | 342 rtc::scoped_ptr<RtpReceiver> rtp_receiver_; |
329 ModuleRtpRtcpImpl* rtp_rtcp_impl_; | 343 ModuleRtpRtcpImpl* rtp_rtcp_impl_; |
330 RTCPSender* rtcp_sender_; | 344 RTCPSender* rtcp_sender_; |
331 RTCPReceiver* rtcp_receiver_; | 345 RTCPReceiver* rtcp_receiver_; |
332 TestTransport* test_transport_; | 346 TestTransport* test_transport_; |
333 MockRemoteBitrateObserver remote_bitrate_observer_; | 347 MockRemoteBitrateObserver remote_bitrate_observer_; |
334 rtc::scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; | 348 rtc::scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; |
335 rtc::scoped_ptr<ReceiveStatistics> receive_statistics_; | 349 rtc::scoped_ptr<ReceiveStatistics> receive_statistics_; |
336 | 350 |
337 enum {kMaxPacketLength = 1500}; | |
338 uint8_t packet_[kMaxPacketLength]; | 351 uint8_t packet_[kMaxPacketLength]; |
339 }; | 352 }; |
340 | 353 |
341 TEST_F(RtcpSenderTest, RtcpOff) { | 354 TEST_F(RtcpSenderTest, RtcpOff) { |
342 rtcp_sender_->SetRTCPStatus(kRtcpOff); | 355 rtcp_sender_->SetRTCPStatus(kRtcpOff); |
343 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); | 356 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); |
344 EXPECT_EQ(-1, rtcp_sender_->SendRTCP(feedback_state, kRtcpSr)); | 357 EXPECT_EQ(-1, rtcp_sender_->SendRTCP(feedback_state, kRtcpSr)); |
345 } | 358 } |
346 | 359 |
347 TEST_F(RtcpSenderTest, IJStatus) { | |
348 ASSERT_FALSE(rtcp_sender_->IJ()); | |
349 rtcp_sender_->SetIJStatus(true); | |
350 EXPECT_TRUE(rtcp_sender_->IJ()); | |
351 } | |
352 | |
353 TEST_F(RtcpSenderTest, TestCompound) { | 360 TEST_F(RtcpSenderTest, TestCompound) { |
354 const bool marker_bit = false; | 361 const bool marker_bit = false; |
355 const uint8_t payload_type = 100; | 362 const uint8_t payload_type = 100; |
356 const uint16_t seq_num = 11111; | 363 const uint16_t seq_num = 11111; |
357 const uint32_t timestamp = 1234567; | 364 const uint32_t timestamp = 1234567; |
358 const uint32_t ssrc = 0x11111111; | |
359 size_t packet_length = 0; | 365 size_t packet_length = 0; |
360 CreateRtpPacket(marker_bit, payload_type, seq_num, timestamp, ssrc, packet_, | 366 CreateRtpPacket(marker_bit, payload_type, seq_num, timestamp, kMainSsrc, |
361 &packet_length); | 367 packet_, &packet_length); |
362 EXPECT_EQ(25u, packet_length); | 368 EXPECT_EQ(25u, packet_length); |
363 | 369 |
364 VideoCodec codec_inst; | 370 VideoCodec codec_inst; |
365 strncpy(codec_inst.plName, "VP8", webrtc::kPayloadNameSize - 1); | 371 strncpy(codec_inst.plName, "VP8", webrtc::kPayloadNameSize - 1); |
366 codec_inst.codecType = webrtc::kVideoCodecVP8; | 372 codec_inst.codecType = webrtc::kVideoCodecVP8; |
367 codec_inst.plType = payload_type; | 373 codec_inst.plType = payload_type; |
368 EXPECT_EQ(0, rtp_receiver_->RegisterReceivePayload(codec_inst.plName, | 374 EXPECT_EQ(0, rtp_receiver_->RegisterReceivePayload(codec_inst.plName, |
369 codec_inst.plType, | 375 codec_inst.plType, |
370 90000, | 376 90000, |
371 0, | 377 0, |
372 codec_inst.maxBitrate)); | 378 codec_inst.maxBitrate)); |
373 | 379 |
374 // Make sure RTP packet has been received. | 380 // Make sure RTP packet has been received. |
375 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); | 381 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
376 RTPHeader header; | 382 RTPHeader header; |
377 EXPECT_TRUE(parser->Parse(packet_, packet_length, &header)); | 383 EXPECT_TRUE(parser->Parse(packet_, packet_length, &header)); |
378 PayloadUnion payload_specific; | 384 PayloadUnion payload_specific; |
379 EXPECT_TRUE(rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, | 385 EXPECT_TRUE(rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, |
380 &payload_specific)); | 386 &payload_specific)); |
381 receive_statistics_->IncomingPacket(header, packet_length, false); | 387 receive_statistics_->IncomingPacket(header, packet_length, false); |
382 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, packet_, packet_length, | 388 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, packet_, packet_length, |
383 payload_specific, true)); | 389 payload_specific, true)); |
384 | 390 |
385 rtcp_sender_->SetIJStatus(true); | 391 rtcp_sender_->SetCNAME("Foo"); |
386 rtcp_sender_->SetRTCPStatus(kRtcpCompound); | 392 rtcp_sender_->SetRTCPStatus(kRtcpCompound); |
387 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); | 393 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); |
388 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRr)); | 394 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRr)); |
389 | 395 |
390 // Transmission time offset packet should be received. | 396 // Sdes packet should be received, along with report blocks. |
391 ASSERT_TRUE(test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags & | 397 ASSERT_TRUE(test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags & |
392 kRtcpTransmissionTimeOffset); | 398 kRtcpSdes); |
| 399 EXPECT_GT(test_transport_->rtcp_packet_info_.report_blocks.size(), 0u); |
393 } | 400 } |
394 | 401 |
395 TEST_F(RtcpSenderTest, TestCompound_NoRtpReceived) { | 402 TEST_F(RtcpSenderTest, TestCompound_NoRtpReceived) { |
396 rtcp_sender_->SetIJStatus(true); | 403 rtcp_sender_->SetCNAME("Foo"); |
397 rtcp_sender_->SetRTCPStatus(kRtcpCompound); | 404 rtcp_sender_->SetRTCPStatus(kRtcpCompound); |
398 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); | 405 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); |
399 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRr)); | 406 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRr)); |
400 | 407 |
401 // Transmission time offset packet should not be received. | 408 // Sdes should be received, but no report blocks. |
402 ASSERT_FALSE(test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags & | 409 ASSERT_TRUE(test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags & |
403 kRtcpTransmissionTimeOffset); | 410 kRtcpSdes); |
| 411 EXPECT_EQ(0u, test_transport_->rtcp_packet_info_.report_blocks.size()); |
404 } | 412 } |
405 | 413 |
406 TEST_F(RtcpSenderTest, TestXrReceiverReferenceTime) { | 414 TEST_F(RtcpSenderTest, TestXrReceiverReferenceTime) { |
407 rtcp_sender_->SetRTCPStatus(kRtcpCompound); | 415 rtcp_sender_->SetRTCPStatus(kRtcpCompound); |
408 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); | 416 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); |
409 EXPECT_EQ(0, rtcp_sender_->SetSendingStatus(feedback_state, false)); | 417 EXPECT_EQ(0, rtcp_sender_->SetSendingStatus(feedback_state, false)); |
410 rtcp_sender_->SendRtcpXrReceiverReferenceTime(true); | 418 rtcp_sender_->SendRtcpXrReceiverReferenceTime(true); |
411 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpReport)); | 419 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpReport)); |
412 | 420 |
413 EXPECT_TRUE(test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags & | 421 EXPECT_TRUE(test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags & |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // to put an actual limit here. It's just information that no limit | 480 // to put an actual limit here. It's just information that no limit |
473 // is set, which is kind of the starting assumption. | 481 // is set, which is kind of the starting assumption. |
474 // See http://code.google.com/p/webrtc/issues/detail?id=468 for one | 482 // See http://code.google.com/p/webrtc/issues/detail?id=468 for one |
475 // situation where this caused confusion. | 483 // situation where this caused confusion. |
476 TEST_F(RtcpSenderTest, SendsTmmbnIfSetAndEmpty) { | 484 TEST_F(RtcpSenderTest, SendsTmmbnIfSetAndEmpty) { |
477 rtcp_sender_->SetRTCPStatus(kRtcpCompound); | 485 rtcp_sender_->SetRTCPStatus(kRtcpCompound); |
478 TMMBRSet bounding_set; | 486 TMMBRSet bounding_set; |
479 EXPECT_EQ(0, rtcp_sender_->SetTMMBN(&bounding_set, 3)); | 487 EXPECT_EQ(0, rtcp_sender_->SetTMMBN(&bounding_set, 3)); |
480 ASSERT_EQ(0U, test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags); | 488 ASSERT_EQ(0U, test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags); |
481 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); | 489 RTCPSender::FeedbackState feedback_state = rtp_rtcp_impl_->GetFeedbackState(); |
482 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state,kRtcpSr)); | 490 EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpSr)); |
483 // We now expect the packet to show up in the rtcp_packet_info_ of | 491 // We now expect the packet to show up in the rtcp_packet_info_ of |
484 // test_transport_. | 492 // test_transport_. |
485 ASSERT_NE(0U, test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags); | 493 ASSERT_NE(0U, test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags); |
486 EXPECT_TRUE(gotPacketType(kRtcpTmmbn)); | 494 EXPECT_TRUE(gotPacketType(kRtcpTmmbn)); |
487 TMMBRSet* incoming_set = NULL; | 495 TMMBRSet* incoming_set = NULL; |
488 bool owner = false; | 496 bool owner = false; |
489 // The BoundingSet function returns the number of members of the | 497 // The BoundingSet function returns the number of members of the |
490 // bounding set, and touches the incoming set only if there's > 1. | 498 // bounding set, and touches the incoming set only if there's > 1. |
491 EXPECT_EQ(0, test_transport_->rtcp_receiver_->BoundingSet(owner, | 499 EXPECT_EQ(0, test_transport_->rtcp_receiver_->BoundingSet(owner, |
492 incoming_set)); | 500 incoming_set)); |
(...skipping 14 matching lines...) Expand all Loading... |
507 // test_transport_. | 515 // test_transport_. |
508 ASSERT_NE(0U, test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags); | 516 ASSERT_NE(0U, test_transport_->rtcp_packet_info_.rtcpPacketTypeFlags); |
509 EXPECT_TRUE(gotPacketType(kRtcpTmmbn)); | 517 EXPECT_TRUE(gotPacketType(kRtcpTmmbn)); |
510 TMMBRSet incoming_set; | 518 TMMBRSet incoming_set; |
511 bool owner = false; | 519 bool owner = false; |
512 // We expect 1 member of the incoming set. | 520 // We expect 1 member of the incoming set. |
513 EXPECT_EQ(1, test_transport_->rtcp_receiver_->BoundingSet(owner, | 521 EXPECT_EQ(1, test_transport_->rtcp_receiver_->BoundingSet(owner, |
514 &incoming_set)); | 522 &incoming_set)); |
515 EXPECT_EQ(kSourceSsrc, incoming_set.Ssrc(0)); | 523 EXPECT_EQ(kSourceSsrc, incoming_set.Ssrc(0)); |
516 } | 524 } |
| 525 |
517 } // namespace webrtc | 526 } // namespace webrtc |
OLD | NEW |