summaryrefslogtreecommitdiff
path: root/media/cast/rtcp/test_rtcp_packet_builder.h
blob: 8c5479ff484926590d35b0b41b9882f1c88d2b70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// A very simple packet builder class for building RTCP packets.
// Used for testing only.
#ifndef MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_
#define MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_

#include "media/cast/rtcp/rtcp_defines.h"
#include "net/base/big_endian.h"

namespace media {
namespace cast {

// These values are arbitrary only for the purpose of testing.

// Sender report.
static const int kNtpHigh = 0x01020304;
static const int kNtpLow = 0x05060708;
static const int kRtpTimestamp = 0x10203;
static const int kSendPacketCount = 987;
static const int kSendOctetCount = 87654;

// Report block.
static const int kLoss = 0x01000123;
static const int kExtendedMax = 0x15678;
static const int kJitter = 0x10203;
static const int kLastSr = 0x34561234;
static const int kDelayLastSr = 1000;

// DLRR block.
static const int kLastRr = 0x34561234;
static const int kDelayLastRr = 1000;

// REMB.
static const int kRembBitrate = 52428;

// RPSI.
static const int kPayloadtype = 126;
static const uint64 kPictureId = 0x1234567890;

// NACK.
static const int kMissingPacket = 34567;

// CAST.
static const int kAckFrameId = 17;
static const int kLostFrameId = 18;
static const int kFrameIdWithLostPackets = 19;
static const int kLostPacketId1 = 3;
static const int kLostPacketId2 = 5;
static const int kLostPacketId3 = 12;

class TestRtcpPacketBuilder {
 public:
  TestRtcpPacketBuilder();

  void AddSr(uint32 sender_ssrc, int number_of_report_blocks);
  void AddSrWithNtp(uint32 sender_ssrc, uint32 ntp_high, uint32 ntp_low,
                    uint32 rtp_timestamp);
  void AddRr(uint32 sender_ssrc, int number_of_report_blocks);
  void AddRb(uint32 rtp_ssrc);
  void AddSdesCname(uint32 sender_ssrc, const std::string& c_name);

  void AddXrHeader(uint32 sender_ssrc);
  void AddXrDlrrBlock(uint32 sender_ssrc);
  void AddXrExtendedDlrrBlock(uint32 sender_ssrc);
  void AddXrRrtrBlock();
  void AddXrUnknownBlock();

  void AddNack(uint32 sender_ssrc, uint32 media_ssrc);
  void AddSendReportRequest(uint32 sender_ssrc, uint32 media_ssrc);

  void AddPli(uint32 sender_ssrc, uint32 media_ssrc);
  void AddRpsi(uint32 sender_ssrc, uint32 media_ssrc);
  void AddRemb(uint32 sender_ssrc, uint32 media_ssrc);
  void AddCast(uint32 sender_ssrc, uint32 media_ssrc);

  const uint8* Packet();
  int Length() { return kIpPacketSize - big_endian_writer_.remaining(); }

 private:
  void AddRtcpHeader(int payload, int format_or_count);
  void PatchLengthField();

  // Where the length field of the current packet is.
  // Note: 0 is not a legal value, it is used for "uninitialized".
  uint8 buffer_[kIpPacketSize];
  char* ptr_of_length_;
  net::BigEndianWriter big_endian_writer_;
};

}  // namespace cast
}  // namespace media

#endif //  MEDIA_CAST_RTCP_TEST_RTCP_PACKET_BUILDER_H_