- add sources.
[platform/framework/web/crosswalk.git] / src / media / cast / rtcp / test_rtcp_packet_builder.h
1 // Copyright 2013 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 "media/cast/rtcp/rtcp_defines.h"
11 #include "net/base/big_endian.h"
12
13 namespace media {
14 namespace cast {
15
16 // These values are arbitrary only for the purpose of testing.
17
18 // Sender report.
19 static const int kNtpHigh = 0x01020304;
20 static const int kNtpLow = 0x05060708;
21 static const int kRtpTimestamp = 0x10203;
22 static const int kSendPacketCount = 987;
23 static const int kSendOctetCount = 87654;
24
25 // Report block.
26 static const int kLoss = 0x01000123;
27 static const int kExtendedMax = 0x15678;
28 static const int kJitter = 0x10203;
29 static const int kLastSr = 0x34561234;
30 static const int kDelayLastSr = 1000;
31
32 // DLRR block.
33 static const int kLastRr = 0x34561234;
34 static const int kDelayLastRr = 1000;
35
36 // REMB.
37 static const int kRembBitrate = 52428;
38
39 // RPSI.
40 static const int kPayloadtype = 126;
41 static const uint64 kPictureId = 0x1234567890;
42
43 // NACK.
44 static const int kMissingPacket = 34567;
45
46 // CAST.
47 static const int kAckFrameId = 17;
48 static const int kLostFrameId = 18;
49 static const int kFrameIdWithLostPackets = 19;
50 static const int kLostPacketId1 = 3;
51 static const int kLostPacketId2 = 5;
52 static const int kLostPacketId3 = 12;
53
54 class TestRtcpPacketBuilder {
55  public:
56   TestRtcpPacketBuilder();
57
58   void AddSr(uint32 sender_ssrc, int number_of_report_blocks);
59   void AddSrWithNtp(uint32 sender_ssrc, uint32 ntp_high, uint32 ntp_low,
60                     uint32 rtp_timestamp);
61   void AddRr(uint32 sender_ssrc, int number_of_report_blocks);
62   void AddRb(uint32 rtp_ssrc);
63   void AddSdesCname(uint32 sender_ssrc, const std::string& c_name);
64
65   void AddXrHeader(uint32 sender_ssrc);
66   void AddXrDlrrBlock(uint32 sender_ssrc);
67   void AddXrExtendedDlrrBlock(uint32 sender_ssrc);
68   void AddXrRrtrBlock();
69   void AddXrUnknownBlock();
70
71   void AddNack(uint32 sender_ssrc, uint32 media_ssrc);
72   void AddSendReportRequest(uint32 sender_ssrc, uint32 media_ssrc);
73
74   void AddPli(uint32 sender_ssrc, uint32 media_ssrc);
75   void AddRpsi(uint32 sender_ssrc, uint32 media_ssrc);
76   void AddRemb(uint32 sender_ssrc, uint32 media_ssrc);
77   void AddCast(uint32 sender_ssrc, uint32 media_ssrc);
78
79   const uint8* Packet();
80   int Length() { return kIpPacketSize - big_endian_writer_.remaining(); }
81
82  private:
83   void AddRtcpHeader(int payload, int format_or_count);
84   void PatchLengthField();
85
86   // Where the length field of the current packet is.
87   // Note: 0 is not a legal value, it is used for "uninitialized".
88   uint8 buffer_[kIpPacketSize];
89   char* ptr_of_length_;
90   net::BigEndianWriter big_endian_writer_;
91 };
92
93 }  // namespace cast
94 }  // namespace media
95
96 #endif //  MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_