OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
16 | 16 |
17 using webrtc::RTCPUtility::RtcpCommonHeader; | |
18 | |
19 namespace webrtc { | 17 namespace webrtc { |
20 namespace rtcp { | 18 namespace rtcp { |
21 // Sender report (SR) (RFC 3550). | 19 // Sender report (SR) (RFC 3550). |
22 // 0 1 2 3 | 20 // 0 1 2 3 |
23 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | 21 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
24 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 22 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
25 // |V=2|P| RC | PT=SR=200 | length | | 23 // |V=2|P| RC | PT=SR=200 | length | |
26 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 24 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
27 // 0 | SSRC of sender | | 25 // 0 | SSRC of sender | |
28 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 26 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
29 // 4 | NTP timestamp, most significant word | | 27 // 4 | NTP timestamp, most significant word | |
30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
31 // 8 | NTP timestamp, least significant word | | 29 // 8 | NTP timestamp, least significant word | |
32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
33 // 12 | RTP timestamp | | 31 // 12 | RTP timestamp | |
34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
35 // 16 | sender's packet count | | 33 // 16 | sender's packet count | |
36 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
37 // 20 | sender's octet count | | 35 // 20 | sender's octet count | |
38 // 24 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 36 // 24 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
39 | 37 |
40 SenderReport::SenderReport() | 38 SenderReport::SenderReport() |
41 : sender_ssrc_(0), | 39 : sender_ssrc_(0), |
42 rtp_timestamp_(0), | 40 rtp_timestamp_(0), |
43 sender_packet_count_(0), | 41 sender_packet_count_(0), |
44 sender_octet_count_(0) {} | 42 sender_octet_count_(0) {} |
45 | 43 |
46 bool SenderReport::Parse(const RtcpCommonHeader& header, | 44 bool SenderReport::Parse(const CommonHeader& packet) { |
47 const uint8_t* payload) { | 45 RTC_DCHECK(packet.type() == kPacketType); |
48 RTC_DCHECK(header.packet_type == kPacketType); | |
49 | 46 |
50 const uint8_t report_block_count = header.count_or_format; | 47 const uint8_t report_block_count = packet.count(); |
51 if (header.payload_size_bytes < | 48 if (packet.payload_size_bytes() < |
52 kSenderBaseLength + report_block_count * ReportBlock::kLength) { | 49 kSenderBaseLength + report_block_count * ReportBlock::kLength) { |
53 LOG(LS_WARNING) << "Packet is too small to contain all the data."; | 50 LOG(LS_WARNING) << "Packet is too small to contain all the data."; |
54 return false; | 51 return false; |
55 } | 52 } |
56 // Read SenderReport header. | 53 // Read SenderReport header. |
| 54 const uint8_t* const payload = packet.payload(); |
57 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]); | 55 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]); |
58 uint32_t secs = ByteReader<uint32_t>::ReadBigEndian(&payload[4]); | 56 uint32_t secs = ByteReader<uint32_t>::ReadBigEndian(&payload[4]); |
59 uint32_t frac = ByteReader<uint32_t>::ReadBigEndian(&payload[8]); | 57 uint32_t frac = ByteReader<uint32_t>::ReadBigEndian(&payload[8]); |
60 ntp_.Set(secs, frac); | 58 ntp_.Set(secs, frac); |
61 rtp_timestamp_ = ByteReader<uint32_t>::ReadBigEndian(&payload[12]); | 59 rtp_timestamp_ = ByteReader<uint32_t>::ReadBigEndian(&payload[12]); |
62 sender_packet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[16]); | 60 sender_packet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[16]); |
63 sender_octet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[20]); | 61 sender_octet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[20]); |
64 report_blocks_.resize(report_block_count); | 62 report_blocks_.resize(report_block_count); |
65 const uint8_t* next_block = payload + kSenderBaseLength; | 63 const uint8_t* next_block = payload + kSenderBaseLength; |
66 for (ReportBlock& block : report_blocks_) { | 64 for (ReportBlock& block : report_blocks_) { |
67 bool block_parsed = block.Parse(next_block, ReportBlock::kLength); | 65 bool block_parsed = block.Parse(next_block, ReportBlock::kLength); |
68 RTC_DCHECK(block_parsed); | 66 RTC_DCHECK(block_parsed); |
69 next_block += ReportBlock::kLength; | 67 next_block += ReportBlock::kLength; |
70 } | 68 } |
71 // Double check we didn't read beyond provided buffer. | 69 // Double check we didn't read beyond provided buffer. |
72 RTC_DCHECK_LE(next_block, payload + header.payload_size_bytes); | 70 RTC_DCHECK_EQ(next_block - payload, |
| 71 static_cast<ptrdiff_t>(packet.payload_size_bytes())); |
73 return true; | 72 return true; |
74 } | 73 } |
75 | 74 |
76 bool SenderReport::Create(uint8_t* packet, | 75 bool SenderReport::Create(uint8_t* packet, |
77 size_t* index, | 76 size_t* index, |
78 size_t max_length, | 77 size_t max_length, |
79 RtcpPacket::PacketReadyCallback* callback) const { | 78 PacketReadyCallback* callback) const { |
80 while (*index + BlockLength() > max_length) { | 79 while (*index + BlockLength() > max_length) { |
81 if (!OnBufferFull(packet, index, callback)) | 80 if (!OnBufferFull(packet, index, callback)) |
82 return false; | 81 return false; |
83 } | 82 } |
84 const size_t index_end = *index + BlockLength(); | 83 const size_t index_end = *index + BlockLength(); |
85 | 84 |
86 CreateHeader(report_blocks_.size(), kPacketType, HeaderLength(), packet, | 85 CreateHeader(report_blocks_.size(), kPacketType, HeaderLength(), packet, |
87 index); | 86 index); |
88 // Write SenderReport header. | 87 // Write SenderReport header. |
89 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], sender_ssrc_); | 88 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], sender_ssrc_); |
(...skipping 19 matching lines...) Expand all Loading... |
109 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { | 108 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { |
110 LOG(LS_WARNING) << "Max report blocks reached."; | 109 LOG(LS_WARNING) << "Max report blocks reached."; |
111 return false; | 110 return false; |
112 } | 111 } |
113 report_blocks_.push_back(block); | 112 report_blocks_.push_back(block); |
114 return true; | 113 return true; |
115 } | 114 } |
116 | 115 |
117 } // namespace rtcp | 116 } // namespace rtcp |
118 } // namespace webrtc | 117 } // namespace webrtc |
OLD | NEW |