test_rtcp_packet_builder.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // A very simple packet builder class for building RTCP packets.
  5. // Used for testing only.
  6. #ifndef MEDIA_CAST_TEST_TEST_RTCP_PACKET_BUILDER_H_
  7. #define MEDIA_CAST_TEST_TEST_RTCP_PACKET_BUILDER_H_
  8. #include <stdint.h>
  9. #include <vector>
  10. #include "base/big_endian.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "media/cast/net/cast_transport_defines.h"
  13. #include "media/cast/net/rtcp/rtcp_defines.h"
  14. namespace media {
  15. namespace cast {
  16. // These values are arbitrary only for the purpose of testing.
  17. namespace {
  18. // Sender report.
  19. static const uint32_t kNtpHigh = 0x01020304;
  20. static const uint32_t kNtpLow = 0x05060708;
  21. static const uint32_t kRtpTimestamp = 0x10203040;
  22. static const uint32_t kSendPacketCount = 987;
  23. static const uint32_t kSendOctetCount = 87654;
  24. // Report block.
  25. static const int kLoss = 0x01000123;
  26. static const int kExtendedMax = 0x15678;
  27. static const int kTestJitter = 0x10203;
  28. static const uint32_t kLastSr = 0x34561234;
  29. static const uint32_t kDelayLastSr = 1000;
  30. // DLRR block.
  31. static const int kLastRr = 0x34561234;
  32. static const int kDelayLastRr = 1000;
  33. // NACK.
  34. static const int kMissingPacket = 34567;
  35. // CAST.
  36. static const uint32_t kAckFrameId = 17;
  37. static const uint32_t kLostFrameId = 18;
  38. static const uint32_t kFrameIdWithLostPackets = 19;
  39. static const int kLostPacketId1 = 3;
  40. static const int kLostPacketId2 = 5;
  41. static const int kLostPacketId3 = 12;
  42. static const uint8_t kFeedbackSeq = 1;
  43. } // namespace
  44. class TestRtcpPacketBuilder {
  45. public:
  46. TestRtcpPacketBuilder();
  47. TestRtcpPacketBuilder(const TestRtcpPacketBuilder&) = delete;
  48. TestRtcpPacketBuilder& operator=(const TestRtcpPacketBuilder&) = delete;
  49. void AddSr(uint32_t remote_ssrc, int number_of_report_blocks);
  50. void AddSrWithNtp(uint32_t remote_ssrc,
  51. uint32_t ntp_high,
  52. uint32_t ntp_low,
  53. uint32_t rtp_timestamp);
  54. void AddRr(uint32_t remote_ssrc, int number_of_report_blocks);
  55. void AddRb(uint32_t rtp_ssrc);
  56. void AddXrHeader(uint32_t remote_ssrc);
  57. void AddXrDlrrBlock(uint32_t remote_ssrc);
  58. void AddXrExtendedDlrrBlock(uint32_t remote_ssrc);
  59. void AddXrRrtrBlock();
  60. void AddXrUnknownBlock();
  61. void AddUnknownBlock();
  62. void AddNack(uint32_t remote_ssrc, uint32_t local_ssrc);
  63. void AddSendReportRequest(uint32_t remote_ssrc, uint32_t local_ssrc);
  64. void AddCast(uint32_t remote_ssrc,
  65. uint32_t local_ssrc,
  66. base::TimeDelta target_delay);
  67. void AddCst2(const std::vector<FrameId>& later_received_frames);
  68. void AddErrorCst2(); // With wrong identifier.
  69. void AddPli(uint32_t remote_ssrc, uint32_t local_ssrc);
  70. void AddReceiverLog(uint32_t remote_ssrc);
  71. void AddReceiverFrameLog(uint32_t rtp_timestamp,
  72. int num_events,
  73. uint32_t event_timesamp_base);
  74. void AddReceiverEventLog(uint16_t event_data,
  75. CastLoggingEvent event,
  76. uint16_t event_timesamp_delta);
  77. std::unique_ptr<Packet> GetPacket();
  78. const uint8_t* Data();
  79. int Length() { return kMaxIpPacketSize - big_endian_writer_.remaining(); }
  80. base::BigEndianReader* Reader();
  81. private:
  82. void AddRtcpHeader(int payload, int format_or_count);
  83. void PatchLengthField();
  84. // Where the length field of the current packet is.
  85. // Note: 0 is not a legal value, it is used for "uninitialized".
  86. uint8_t buffer_[kMaxIpPacketSize];
  87. raw_ptr<char> ptr_of_length_;
  88. base::BigEndianWriter big_endian_writer_;
  89. base::BigEndianReader big_endian_reader_;
  90. };
  91. } // namespace cast
  92. } // namespace media
  93. #endif // MEDIA_CAST_TEST_TEST_RTCP_PACKET_BUILDER_H_