Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / cast / net / rtcp / test_rtcp_packet_builder.h
blob3fab3b50692aa9ab170c06a64fdf1ac539f9917a
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.
5 // A very simple packet builder class for building RTCP packets.
6 // Used for testing only.
7 #ifndef MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_
8 #define MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_
10 #include "base/big_endian.h"
11 #include "media/cast/cast_config.h"
12 #include "media/cast/net/cast_transport_defines.h"
13 #include "media/cast/net/rtcp/rtcp_defines.h"
15 namespace media {
16 namespace cast {
18 // These values are arbitrary only for the purpose of testing.
20 namespace {
21 // Sender report.
22 static const uint32 kNtpHigh = 0x01020304;
23 static const uint32 kNtpLow = 0x05060708;
24 static const uint32 kRtpTimestamp = 0x10203040;
25 static const uint32 kSendPacketCount = 987;
26 static const uint32 kSendOctetCount = 87654;
28 // Report block.
29 static const int kLoss = 0x01000123;
30 static const int kExtendedMax = 0x15678;
31 static const int kTestJitter = 0x10203;
32 static const uint32 kLastSr = 0x34561234;
33 static const uint32 kDelayLastSr = 1000;
35 // DLRR block.
36 static const int kLastRr = 0x34561234;
37 static const int kDelayLastRr = 1000;
39 // NACK.
40 static const int kMissingPacket = 34567;
42 // CAST.
43 static const uint32 kAckFrameId = 17;
44 static const uint32 kLostFrameId = 18;
45 static const uint32 kFrameIdWithLostPackets = 19;
46 static const int kLostPacketId1 = 3;
47 static const int kLostPacketId2 = 5;
48 static const int kLostPacketId3 = 12;
49 } // namespace
51 class TestRtcpPacketBuilder {
52 public:
53 TestRtcpPacketBuilder();
55 void AddSr(uint32 sender_ssrc, int number_of_report_blocks);
56 void AddSrWithNtp(uint32 sender_ssrc,
57 uint32 ntp_high,
58 uint32 ntp_low,
59 uint32 rtp_timestamp);
60 void AddRr(uint32 sender_ssrc, int number_of_report_blocks);
61 void AddRb(uint32 rtp_ssrc);
63 void AddXrHeader(uint32 sender_ssrc);
64 void AddXrDlrrBlock(uint32 sender_ssrc);
65 void AddXrExtendedDlrrBlock(uint32 sender_ssrc);
66 void AddXrRrtrBlock();
67 void AddXrUnknownBlock();
68 void AddUnknownBlock();
70 void AddNack(uint32 sender_ssrc, uint32 media_ssrc);
71 void AddSendReportRequest(uint32 sender_ssrc, uint32 media_ssrc);
73 void AddCast(uint32 sender_ssrc,
74 uint32 media_ssrc,
75 base::TimeDelta target_delay);
76 void AddReceiverLog(uint32 sender_ssrc);
77 void AddReceiverFrameLog(uint32 rtp_timestamp,
78 int num_events,
79 uint32 event_timesamp_base);
80 void AddReceiverEventLog(uint16 event_data,
81 CastLoggingEvent event,
82 uint16 event_timesamp_delta);
84 scoped_ptr<Packet> GetPacket();
85 const uint8* Data();
86 int Length() { return kMaxIpPacketSize - big_endian_writer_.remaining(); }
87 base::BigEndianReader* Reader();
89 private:
90 void AddRtcpHeader(int payload, int format_or_count);
91 void PatchLengthField();
93 // Where the length field of the current packet is.
94 // Note: 0 is not a legal value, it is used for "uninitialized".
95 uint8 buffer_[kMaxIpPacketSize];
96 char* ptr_of_length_;
97 base::BigEndianWriter big_endian_writer_;
98 base::BigEndianReader big_endian_reader_;
100 DISALLOW_COPY_AND_ASSIGN(TestRtcpPacketBuilder);
103 } // namespace cast
104 } // namespace media
106 #endif // MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_