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

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

Issue 2292883002: Use RtpPacketToSend in RtpSenderAudio (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_audio.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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 368
366 EXPECT_TRUE(rtp_sender_->ActivateCVORtpHeaderExtension()); 369 EXPECT_TRUE(rtp_sender_->ActivateCVORtpHeaderExtension());
367 EXPECT_EQ( 370 EXPECT_EQ(
368 RtpUtility::Word32Align(kRtpOneByteHeaderLength + kVideoRotationLength), 371 RtpUtility::Word32Align(kRtpOneByteHeaderLength + kVideoRotationLength),
369 rtp_sender_->RtpHeaderExtensionLength()); 372 rtp_sender_->RtpHeaderExtensionLength());
370 EXPECT_EQ( 373 EXPECT_EQ(
371 0, rtp_sender_->DeregisterRtpHeaderExtension(kRtpExtensionVideoRotation)); 374 0, rtp_sender_->DeregisterRtpHeaderExtension(kRtpExtensionVideoRotation));
372 EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionLength()); 375 EXPECT_EQ(0u, rtp_sender_->RtpHeaderExtensionLength());
373 } 376 }
374 377
378 TEST_F(RtpSenderTestWithoutPacer, AllocatePacketSetCsrc) {
379 // Configure rtp_sender with an extension and csrc.
380 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
381 kRtpExtensionTransmissionTimeOffset,
382 kTransmissionTimeOffsetExtensionId));
383 std::vector<uint32_t> csrcs;
384 csrcs.push_back(0x23456789);
385 rtp_sender_->SetCsrcs(csrcs);
386
387 auto packet = rtp_sender_->AllocatePacket();
388
389 ASSERT_TRUE(packet);
390 EXPECT_EQ(rtp_sender_->SSRC(), packet->Ssrc());
391 EXPECT_THAT(packet->Csrcs(), ElementsAreArray(csrcs));
392 EXPECT_TRUE(packet->HasExtension<TransmissionOffset>());
393 }
394
395 TEST_F(RtpSenderTestWithoutPacer, AllocatePacketReserveExtensions) {
396 // Configure rtp_sender with extensions.
397 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
398 kRtpExtensionTransmissionTimeOffset,
399 kTransmissionTimeOffsetExtensionId));
400 ASSERT_EQ(
401 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime,
402 kAbsoluteSendTimeExtensionId));
403 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAudioLevel,
404 kAudioLevelExtensionId));
405 ASSERT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension(
406 kRtpExtensionTransportSequenceNumber,
407 kTransportSequenceNumberExtensionId));
408
409 auto packet = rtp_sender_->AllocatePacket();
410
411 ASSERT_TRUE(packet);
412 // Preallocate extensions RtpSender set itself.
413 EXPECT_TRUE(packet->HasExtension<TransmissionOffset>());
414 EXPECT_TRUE(packet->HasExtension<AbsoluteSendTime>());
415 EXPECT_TRUE(packet->HasExtension<TransportSequenceNumber>());
416 // Do not allocate extensions RtpSenderAudio/RtpSenderVideo set.
417 EXPECT_FALSE(packet->HasExtension<AudioLevel>());
418 }
419
420 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberAdvanceSequnceNumber) {
421 const uint16_t sequence_number = rtp_sender_->SequenceNumber();
422 auto packet = rtp_sender_->AllocatePacket();
423 ASSERT_TRUE(packet);
424
425 EXPECT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
426
427 EXPECT_EQ(sequence_number, packet->SequenceNumber());
428 EXPECT_EQ(sequence_number + 1, rtp_sender_->SequenceNumber());
429 }
430
431 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberFailsOnNotSending) {
432 auto packet = rtp_sender_->AllocatePacket();
433 ASSERT_TRUE(packet);
434
435 rtp_sender_->SetSendingMediaStatus(false);
436 EXPECT_FALSE(rtp_sender_->AssignSequenceNumber(packet.get()));
437 }
438
439 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberMayAllowPadding) {
440 constexpr size_t kPaddingSize = 100;
441 auto packet = rtp_sender_->AllocatePacket();
442 ASSERT_TRUE(packet);
443
444 ASSERT_FALSE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
445 packet->SetMarker(false);
446 ASSERT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
447 // Packet without marker bit doesn't allow padding.
448 EXPECT_FALSE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
449
450 packet->SetMarker(true);
451 ASSERT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
452 // Packet with marker bit allows send padding.
453 EXPECT_TRUE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
454 }
455
456 TEST_F(RtpSenderTestWithoutPacer, AssignSequenceNumberSetPaddingTimestamps) {
457 constexpr size_t kPaddingSize = 100;
458 auto packet = rtp_sender_->AllocatePacket();
459 ASSERT_TRUE(packet);
460 packet->SetMarker(true);
461 packet->SetTimestamp(kTimestamp);
462
463 ASSERT_TRUE(rtp_sender_->AssignSequenceNumber(packet.get()));
464 ASSERT_TRUE(rtp_sender_->SendPadData(kPaddingSize, false, 0, 0, -1));
465
466 ASSERT_EQ(1u, transport_.sent_packets_.size());
467 // Parse the padding packet and verify it's timestamp match.
468 RtpPacketToSend padding_packet(nullptr);
469 ASSERT_TRUE(padding_packet.Parse(transport_.sent_packets_[0]->data(),
470 transport_.sent_packets_[0]->size()));
471 EXPECT_EQ(kTimestamp, padding_packet.Timestamp());
472 }
473
375 TEST_F(RtpSenderTestWithoutPacer, BuildRTPPacket) { 474 TEST_F(RtpSenderTestWithoutPacer, BuildRTPPacket) {
376 size_t length = static_cast<size_t>(rtp_sender_->BuildRtpHeader( 475 size_t length = static_cast<size_t>(rtp_sender_->BuildRtpHeader(
377 packet_, kPayload, kMarkerBit, kTimestamp, 0)); 476 packet_, kPayload, kMarkerBit, kTimestamp, 0));
378 ASSERT_EQ(kRtpHeaderSize, length); 477 ASSERT_EQ(kRtpHeaderSize, length);
379 478
380 // Verify 479 // Verify
381 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length); 480 webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet_, length);
382 webrtc::RTPHeader rtp_header; 481 webrtc::RTPHeader rtp_header;
383 482
384 const bool valid_rtp_header = rtp_parser.Parse(&rtp_header, nullptr); 483 const bool valid_rtp_header = rtp_parser.Parse(&rtp_header, nullptr);
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), 1784 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()),
1686 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation); 1785 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation);
1687 1786
1688 // Verify that this packet does have CVO byte. 1787 // Verify that this packet does have CVO byte.
1689 VerifyCVOPacket( 1788 VerifyCVOPacket(
1690 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), 1789 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()),
1691 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1, 1790 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1,
1692 hdr.rotation); 1791 hdr.rotation);
1693 } 1792 }
1694 } // namespace webrtc 1793 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698