• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  *
10  */
11 
12 #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_DLRR_H_
13 #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_DLRR_H_
14 
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 #include <vector>
19 
20 namespace webrtc {
21 namespace rtcp {
22 struct ReceiveTimeInfo {
23   // RFC 3611 4.5
ReceiveTimeInfoReceiveTimeInfo24   ReceiveTimeInfo() : ssrc(0), last_rr(0), delay_since_last_rr(0) {}
ReceiveTimeInfoReceiveTimeInfo25   ReceiveTimeInfo(uint32_t ssrc, uint32_t last_rr, uint32_t delay)
26       : ssrc(ssrc), last_rr(last_rr), delay_since_last_rr(delay) {}
27 
28   uint32_t ssrc;
29   uint32_t last_rr;
30   uint32_t delay_since_last_rr;
31 };
32 
33 inline bool operator==(const ReceiveTimeInfo& lhs, const ReceiveTimeInfo& rhs) {
34   return lhs.ssrc == rhs.ssrc && lhs.last_rr == rhs.last_rr &&
35          lhs.delay_since_last_rr == rhs.delay_since_last_rr;
36 }
37 
38 inline bool operator!=(const ReceiveTimeInfo& lhs, const ReceiveTimeInfo& rhs) {
39   return !(lhs == rhs);
40 }
41 
42 // DLRR Report Block: Delay since the Last Receiver Report (RFC 3611).
43 class Dlrr {
44  public:
45   static const uint8_t kBlockType = 5;
46 
47   Dlrr();
48   Dlrr(const Dlrr& other);
49   ~Dlrr();
50 
51   Dlrr& operator=(const Dlrr& other) = default;
52 
53   // Dlrr without items treated same as no dlrr block.
54   explicit operator bool() const { return !sub_blocks_.empty(); }
55 
56   // Second parameter is value read from block header,
57   // i.e. size of block in 32bits excluding block header itself.
58   bool Parse(const uint8_t* buffer, uint16_t block_length_32bits);
59 
60   size_t BlockLength() const;
61   // Fills buffer with the Dlrr.
62   // Consumes BlockLength() bytes.
63   void Create(uint8_t* buffer) const;
64 
ClearItems()65   void ClearItems() { sub_blocks_.clear(); }
AddDlrrItem(const ReceiveTimeInfo & time_info)66   void AddDlrrItem(const ReceiveTimeInfo& time_info) {
67     sub_blocks_.push_back(time_info);
68   }
69 
sub_blocks()70   const std::vector<ReceiveTimeInfo>& sub_blocks() const { return sub_blocks_; }
71 
72  private:
73   static const size_t kBlockHeaderLength = 4;
74   static const size_t kSubBlockLength = 12;
75 
76   std::vector<ReceiveTimeInfo> sub_blocks_;
77 };
78 }  // namespace rtcp
79 }  // namespace webrtc
80 #endif  // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_DLRR_H_
81