OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 RTC_DCHECK_EQ(block_length_32bits, | 38 RTC_DCHECK_EQ(block_length_32bits, |
39 ByteReader<uint16_t>::ReadBigEndian(&buffer[2])); | 39 ByteReader<uint16_t>::ReadBigEndian(&buffer[2])); |
40 if (block_length_32bits % 3 != 0) { | 40 if (block_length_32bits % 3 != 0) { |
41 LOG(LS_WARNING) << "Invalid size for dlrr block."; | 41 LOG(LS_WARNING) << "Invalid size for dlrr block."; |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 size_t blocks_count = block_length_32bits / 3; | 45 size_t blocks_count = block_length_32bits / 3; |
46 const uint8_t* read_at = buffer + kBlockHeaderLength; | 46 const uint8_t* read_at = buffer + kBlockHeaderLength; |
47 sub_blocks_.resize(blocks_count); | 47 sub_blocks_.resize(blocks_count); |
48 for (SubBlock& sub_block : sub_blocks_) { | 48 for (ReceiveTimeInfo& sub_block : sub_blocks_) { |
49 sub_block.ssrc = ByteReader<uint32_t>::ReadBigEndian(&read_at[0]); | 49 sub_block.ssrc = ByteReader<uint32_t>::ReadBigEndian(&read_at[0]); |
50 sub_block.last_rr = ByteReader<uint32_t>::ReadBigEndian(&read_at[4]); | 50 sub_block.last_rr = ByteReader<uint32_t>::ReadBigEndian(&read_at[4]); |
51 sub_block.delay_since_last_rr = | 51 sub_block.delay_since_last_rr = |
52 ByteReader<uint32_t>::ReadBigEndian(&read_at[8]); | 52 ByteReader<uint32_t>::ReadBigEndian(&read_at[8]); |
53 read_at += kSubBlockLength; | 53 read_at += kSubBlockLength; |
54 } | 54 } |
55 return true; | 55 return true; |
56 } | 56 } |
57 | 57 |
58 size_t Dlrr::BlockLength() const { | 58 size_t Dlrr::BlockLength() const { |
59 if (sub_blocks_.empty()) | 59 if (sub_blocks_.empty()) |
60 return 0; | 60 return 0; |
61 return kBlockHeaderLength + kSubBlockLength * sub_blocks_.size(); | 61 return kBlockHeaderLength + kSubBlockLength * sub_blocks_.size(); |
62 } | 62 } |
63 | 63 |
64 void Dlrr::Create(uint8_t* buffer) const { | 64 void Dlrr::Create(uint8_t* buffer) const { |
65 if (sub_blocks_.empty()) // No subblocks, no need to write header either. | 65 if (sub_blocks_.empty()) // No subblocks, no need to write header either. |
66 return; | 66 return; |
67 // Create block header. | 67 // Create block header. |
68 const uint8_t kReserved = 0; | 68 const uint8_t kReserved = 0; |
69 buffer[0] = kBlockType; | 69 buffer[0] = kBlockType; |
70 buffer[1] = kReserved; | 70 buffer[1] = kReserved; |
71 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], 3 * sub_blocks_.size()); | 71 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], 3 * sub_blocks_.size()); |
72 // Create sub blocks. | 72 // Create sub blocks. |
73 uint8_t* write_at = buffer + kBlockHeaderLength; | 73 uint8_t* write_at = buffer + kBlockHeaderLength; |
74 for (const SubBlock& sub_block : sub_blocks_) { | 74 for (const ReceiveTimeInfo& sub_block : sub_blocks_) { |
75 ByteWriter<uint32_t>::WriteBigEndian(&write_at[0], sub_block.ssrc); | 75 ByteWriter<uint32_t>::WriteBigEndian(&write_at[0], sub_block.ssrc); |
76 ByteWriter<uint32_t>::WriteBigEndian(&write_at[4], sub_block.last_rr); | 76 ByteWriter<uint32_t>::WriteBigEndian(&write_at[4], sub_block.last_rr); |
77 ByteWriter<uint32_t>::WriteBigEndian(&write_at[8], | 77 ByteWriter<uint32_t>::WriteBigEndian(&write_at[8], |
78 sub_block.delay_since_last_rr); | 78 sub_block.delay_since_last_rr); |
79 write_at += kSubBlockLength; | 79 write_at += kSubBlockLength; |
80 } | 80 } |
81 RTC_DCHECK_EQ(buffer + BlockLength(), write_at); | 81 RTC_DCHECK_EQ(buffer + BlockLength(), write_at); |
82 } | 82 } |
83 | 83 |
| 84 bool Dlrr::WithDlrrItem(const ReceiveTimeInfo& block) { |
| 85 if (sub_blocks_.size() >= kMaxNumberOfDlrrItems) { |
| 86 LOG(LS_WARNING) << "Max DLRR items reached."; |
| 87 return false; |
| 88 } |
| 89 sub_blocks_.push_back(block); |
| 90 return true; |
| 91 } |
| 92 |
84 bool Dlrr::WithDlrrItem(uint32_t ssrc, | 93 bool Dlrr::WithDlrrItem(uint32_t ssrc, |
85 uint32_t last_rr, | 94 uint32_t last_rr, |
86 uint32_t delay_last_rr) { | 95 uint32_t delay_last_rr) { |
87 if (sub_blocks_.size() >= kMaxNumberOfDlrrItems) { | 96 ReceiveTimeInfo block; |
88 LOG(LS_WARNING) << "Max DLRR items reached."; | |
89 return false; | |
90 } | |
91 SubBlock block; | |
92 block.ssrc = ssrc; | 97 block.ssrc = ssrc; |
93 block.last_rr = last_rr; | 98 block.last_rr = last_rr; |
94 block.delay_since_last_rr = delay_last_rr; | 99 block.delay_since_last_rr = delay_last_rr; |
95 sub_blocks_.push_back(block); | 100 return WithDlrrItem(block); |
96 return true; | |
97 } | 101 } |
98 | |
99 } // namespace rtcp | 102 } // namespace rtcp |
100 } // namespace webrtc | 103 } // namespace webrtc |
OLD | NEW |