Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc

Issue 2303283002: Introduce helpers to RtpSender to propagate RtpPacketToSend. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include <memory> 11 #include <memory>
12 #include <vector> 12 #include <vector>
13 13
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/base/buffer.h" 16 #include "webrtc/base/buffer.h"
17 #include "webrtc/base/rate_limiter.h" 17 #include "webrtc/base/rate_limiter.h"
18 #include "webrtc/call/mock/mock_rtc_event_log.h" 18 #include "webrtc/call/mock/mock_rtc_event_log.h"
19 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" 19 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
20 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
23 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" 23 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
24 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" 24 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
25 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
26 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" 27 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h"
26 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" 28 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h"
27 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
28 #include "webrtc/system_wrappers/include/stl_util.h" 30 #include "webrtc/system_wrappers/include/stl_util.h"
29 #include "webrtc/test/mock_transport.h" 31 #include "webrtc/test/mock_transport.h"
30 #include "webrtc/typedefs.h" 32 #include "webrtc/typedefs.h"
31 33
32 namespace webrtc { 34 namespace webrtc {
33 35
34 namespace { 36 namespace {
(...skipping 11 matching lines...) Expand all
46 const uint16_t kTransportSequenceNumber = 0xaabbu; 48 const uint16_t kTransportSequenceNumber = 0xaabbu;
47 const uint8_t kAudioLevelExtensionId = 9; 49 const uint8_t kAudioLevelExtensionId = 9;
48 const int kAudioPayload = 103; 50 const int kAudioPayload = 103;
49 const uint64_t kStartTime = 123456789; 51 const uint64_t kStartTime = 123456789;
50 const size_t kMaxPaddingSize = 224u; 52 const size_t kMaxPaddingSize = 224u;
51 const int kVideoRotationExtensionId = 5; 53 const int kVideoRotationExtensionId = 5;
52 const VideoRotation kRotation = kVideoRotation_270; 54 const VideoRotation kRotation = kVideoRotation_270;
53 const size_t kGenericHeaderLength = 1; 55 const size_t kGenericHeaderLength = 1;
54 const uint8_t kPayloadData[] = {47, 11, 32, 93, 89}; 56 const uint8_t kPayloadData[] = {47, 11, 32, 93, 89};
55 57
56 using testing::_; 58 using ::testing::_;
59 using ::testing::ElementsAreArray;
57 60
58 const uint8_t* GetPayloadData(const RTPHeader& rtp_header, 61 const uint8_t* GetPayloadData(const RTPHeader& rtp_header,
59 const uint8_t* packet) { 62 const uint8_t* packet) {
60 return packet + rtp_header.headerLength; 63 return packet + rtp_header.headerLength;
61 } 64 }
62 65
63 size_t GetPayloadDataLength(const RTPHeader& rtp_header, 66 size_t GetPayloadDataLength(const RTPHeader& rtp_header,
64 const size_t packet_length) { 67 const size_t packet_length) {
65 return packet_length - rtp_header.headerLength - rtp_header.paddingLength; 68 return packet_length - rtp_header.headerLength - rtp_header.paddingLength;
66 } 69 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 367
365 EXPECT_TRUE(rtp_sender_->ActivateCVORtpHeaderExtension()); 368 EXPECT_TRUE(rtp_sender_->ActivateCVORtpHeaderExtension());
366 EXPECT_EQ( 369 EXPECT_EQ(
367 RtpUtility::Word32Align(kRtpOneByteHeaderLength + kVideoRotationLength), 370 RtpUtility::Word32Align(kRtpOneByteHeaderLength + kVideoRotationLength),
368 rtp_sender_->RtpHeaderExtensionLength()); 371 rtp_sender_->RtpHeaderExtensionLength());
369 EXPECT_EQ( 372 EXPECT_EQ(
370 0, rtp_sender_->DeregisterRtpHeaderExtension(kRtpExtensionVideoRotation)); 373 0, rtp_sender_->DeregisterRtpHeaderExtension(kRtpExtensionVideoRotation));
371 EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionLength()); 374 EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionLength());
372 } 375 }
373 376
377 TEST_F(RtpSenderTestWithoutPacer, AllocatePacketSetCsrc) {
378 // Configure rtp_sender with csrc.
379 std::vector<uint32_t> csrcs;
380 csrcs.push_back(0x23456789);
381 rtp_sender_->SetCsrcs(csrcs);
382
383 auto packet = rtp_sender_->AllocatePacket();
384
385 ASSERT_TRUE(packet);
386 EXPECT_EQ(rtp_sender_->SSRC(), packet->Ssrc());
387 EXPECT_EQ(csrcs, packet->Csrcs());
388 }
389
390 TEST_F(RtpSenderTestWithoutPacer, AllocatePacketReserveExtensions) {
391 // Configure rtp_sender with extensions.
392 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
393 kRtpExtensionTransmissionTimeOffset,
394 kTransmissionTimeOffsetExtensionId));
395 ASSERT_EQ(
396 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime,
397 kAbsoluteSendTimeExtensionId));
398 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAudioLevel,
399 kAudioLevelExtensionId));
400 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
401 kRtpExtensionTransportSequenceNumber,
402 kTransportSequenceNumberExtensionId));
403 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
404 kRtpExtensionVideoRotation, kVideoRotationExtensionId));
405
406 auto packet = rtp_sender_->AllocatePacket();
407
408 ASSERT_TRUE(packet);
409 // Preallocate BWE extensions RtpSender set itself.
410 EXPECT_TRUE(packet->HasExtension<TransmissionOffset>());
411 EXPECT_TRUE(packet->HasExtension<AbsoluteSendTime>());
412 EXPECT_TRUE(packet->HasExtension<TransportSequenceNumber>());
413 // Do not allocate media specific extensions.
414 EXPECT_FALSE(packet->HasExtension<AudioLevel>());
415 EXPECT_FALSE(packet->HasExtension<VideoOrientation>());
416 }
417
418 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberAdvanceSequenceNumber) {
419 auto packet = rtp_sender_->AllocatePacket();
420 ASSERT_TRUE(packet);
421 const uint16_t sequence_number = rtp_sender_->SequenceNumber();
422
423 EXPECT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
424
425 EXPECT_EQ(sequence_number, packet->SequenceNumber());
426 EXPECT_EQ(sequence_number + 1, rtp_sender_->SequenceNumber());
427 }
428
429 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberFailsOnNotSending) {
430 auto packet = rtp_sender_->AllocatePacket();
431 ASSERT_TRUE(packet);
432
433 rtp_sender_->SetSendingMediaStatus(false);
434 EXPECT_FALSE(rtp_sender_->AssignSequenceNumber(packet.get()));
435 }
436
437 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberMayAllowPadding) {
438 constexpr size_t kPaddingSize = 100;
439 auto packet = rtp_sender_->AllocatePacket();
440 ASSERT_TRUE(packet);
441
442 ASSERT_FALSE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
443 packet->SetMarker(false);
444 ASSERT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
445 // Packet without marker bit doesn't allow padding.
446 EXPECT_FALSE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
447
448 packet->SetMarker(true);
449 ASSERT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
450 // Packet with marker bit allows send padding.
451 EXPECT_TRUE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
452 }
453
454 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberSetPaddingTimestamps) {
455 constexpr size_t kPaddingSize = 100;
456 auto packet = rtp_sender_->AllocatePacket();
457 ASSERT_TRUE(packet);
458 packet->SetMarker(true);
459 packet->SetTimestamp(kTimestamp);
460
461 ASSERT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
462 ASSERT_TRUE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
463
464 ASSERT_EQ(1u, transport_.sent_packets_.size());
465 // Parse the padding packet and verify it's timestamp.
sprang_webrtc 2016/09/02 13:56:44 nit: s/it's/its
466 RtpPacketToSend padding_packet(nullptr);
467 ASSERT_TRUE(padding_packet.Parse(transport_.sent_packets_[0]->data(),
468 transport_.sent_packets_[0]->size()));
469 EXPECT_EQ(kTimestamp, padding_packet.Timestamp());
470 }
471
374 TEST_F(RtpSenderTestWithoutPacer, BuildRTPPacket) { 472 TEST_F(RtpSenderTestWithoutPacer, BuildRTPPacket) {
375 size_t length = static_cast<size_t>(rtp_sender_->BuildRtpHeader( 473 size_t length = static_cast<size_t>(rtp_sender_->BuildRtpHeader(
376 packet_, kPayload, kMarkerBit, kTimestamp, 0)); 474 packet_, kPayload, kMarkerBit, kTimestamp, 0));
377 ASSERT_EQ(kRtpHeaderSize, length); 475 ASSERT_EQ(kRtpHeaderSize, length);
378 476
379 // Verify 477 // Verify
380 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length); 478 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
381 webrtc::RTPHeader rtp_header; 479 webrtc::RTPHeader rtp_header;
382 480
383 const bool valid_rtp_header = rtp_parser.Parse(&rtp_header, nullptr); 481 const bool valid_rtp_header = rtp_parser.Parse(&rtp_header, nullptr);
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 0)); 1803 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 0));
1706 EXPECT_EQ(kVideoRotation_90, 1804 EXPECT_EQ(kVideoRotation_90,
1707 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 1)); 1805 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 1));
1708 EXPECT_EQ(kVideoRotation_180, 1806 EXPECT_EQ(kVideoRotation_180,
1709 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 2)); 1807 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 2));
1710 EXPECT_EQ(kVideoRotation_270, 1808 EXPECT_EQ(kVideoRotation_270,
1711 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 3)); 1809 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 3));
1712 } 1810 }
1713 1811
1714 } // namespace webrtc 1812 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698