afbf4c62534af55a04568b49053da3271ddb3258
[platform/framework/web/crosswalk.git] / src / media / cast / net / rtcp / test_rtcp_packet_builder.h
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
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_
9
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"
14
15 namespace media {
16 namespace cast {
17
18 // These values are arbitrary only for the purpose of testing.
19
20 namespace {
21 // Sender report.
22 static const int kNtpHigh = 0x01020304;
23 static const int kNtpLow = 0x05060708;
24 static const int kRtpTimestamp = 0x10203040;
25 static const int kSendPacketCount = 987;
26 static const int kSendOctetCount = 87654;
27
28 // Report block.
29 static const int kLoss = 0x01000123;
30 static const int kExtendedMax = 0x15678;
31 static const int kTestJitter = 0x10203;
32 static const int kLastSr = 0x34561234;
33 static const int kDelayLastSr = 1000;
34
35 // DLRR block.
36 static const int kLastRr = 0x34561234;
37 static const int kDelayLastRr = 1000;
38
39 // NACK.
40 static const int kMissingPacket = 34567;
41
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
50
51 class TestRtcpPacketBuilder {
52  public:
53   TestRtcpPacketBuilder();
54
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);
62
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
69   void AddNack(uint32 sender_ssrc, uint32 media_ssrc);
70   void AddSendReportRequest(uint32 sender_ssrc, uint32 media_ssrc);
71
72   void AddCast(uint32 sender_ssrc,
73                uint32 media_ssrc,
74                base::TimeDelta target_delay);
75   void AddReceiverLog(uint32 sender_ssrc);
76   void AddReceiverFrameLog(uint32 rtp_timestamp,
77                            int num_events,
78                            uint32 event_timesamp_base);
79   void AddReceiverEventLog(uint16 event_data,
80                            CastLoggingEvent event,
81                            uint16 event_timesamp_delta);
82
83   scoped_ptr<Packet> GetPacket();
84   const uint8* Data();
85   int Length() { return kMaxIpPacketSize - big_endian_writer_.remaining(); }
86
87  private:
88   void AddRtcpHeader(int payload, int format_or_count);
89   void PatchLengthField();
90
91   // Where the length field of the current packet is.
92   // Note: 0 is not a legal value, it is used for "uninitialized".
93   uint8 buffer_[kMaxIpPacketSize];
94   char* ptr_of_length_;
95   base::BigEndianWriter big_endian_writer_;
96
97   DISALLOW_COPY_AND_ASSIGN(TestRtcpPacketBuilder);
98 };
99
100 }  // namespace cast
101 }  // namespace media
102
103 #endif  //  MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_