Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.cc

Issue 1825353002: [rtcp] SenderReport::Parse updated not to use RTCPUtility (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
17 using webrtc::RTCPUtility::RtcpCommonHeader;
18 17
19 namespace webrtc { 18 namespace webrtc {
20 namespace rtcp { 19 namespace rtcp {
21 // Sender report (SR) (RFC 3550). 20 // Sender report (SR) (RFC 3550).
22 // 0 1 2 3 21 // 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 22 // 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 23 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25 // |V=2|P| RC | PT=SR=200 | length | 24 // |V=2|P| RC | PT=SR=200 | length |
26 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 // 0 | SSRC of sender | 26 // 0 | SSRC of sender |
28 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ 27 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
29 // 4 | NTP timestamp, most significant word | 28 // 4 | NTP timestamp, most significant word |
30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 // 8 | NTP timestamp, least significant word | 30 // 8 | NTP timestamp, least significant word |
32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 // 12 | RTP timestamp | 32 // 12 | RTP timestamp |
34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 // 16 | sender's packet count | 34 // 16 | sender's packet count |
36 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 // 20 | sender's octet count | 36 // 20 | sender's octet count |
38 // 24 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ 37 // 24 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
39 38
40 SenderReport::SenderReport() 39 SenderReport::SenderReport()
41 : sender_ssrc_(0), 40 : sender_ssrc_(0),
42 rtp_timestamp_(0), 41 rtp_timestamp_(0),
43 sender_packet_count_(0), 42 sender_packet_count_(0),
44 sender_octet_count_(0) {} 43 sender_octet_count_(0) {}
45 44
46 bool SenderReport::Parse(const RtcpCommonHeader& header, 45 bool SenderReport::Parse(const CommonHeader& packet) {
47 const uint8_t* payload) { 46 RTC_DCHECK(packet.type() == kPacketType);
48 RTC_DCHECK(header.packet_type == kPacketType);
49 47
50 const uint8_t report_block_count = header.count_or_format; 48 const uint8_t report_block_count = packet.count();
51 if (header.payload_size_bytes < 49 if (packet.payload_size_bytes() <
52 kSenderBaseLength + report_block_count * ReportBlock::kLength) { 50 kSenderBaseLength + report_block_count * ReportBlock::kLength) {
53 LOG(LS_WARNING) << "Packet is too small to contain all the data."; 51 LOG(LS_WARNING) << "Packet is too small to contain all the data.";
54 return false; 52 return false;
55 } 53 }
56 // Read SenderReport header. 54 // Read SenderReport header.
55 const uint8_t* const payload = packet.payload();
57 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]); 56 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]);
58 uint32_t secs = ByteReader<uint32_t>::ReadBigEndian(&payload[4]); 57 uint32_t secs = ByteReader<uint32_t>::ReadBigEndian(&payload[4]);
59 uint32_t frac = ByteReader<uint32_t>::ReadBigEndian(&payload[8]); 58 uint32_t frac = ByteReader<uint32_t>::ReadBigEndian(&payload[8]);
60 ntp_.Set(secs, frac); 59 ntp_.Set(secs, frac);
61 rtp_timestamp_ = ByteReader<uint32_t>::ReadBigEndian(&payload[12]); 60 rtp_timestamp_ = ByteReader<uint32_t>::ReadBigEndian(&payload[12]);
62 sender_packet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[16]); 61 sender_packet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[16]);
63 sender_octet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[20]); 62 sender_octet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[20]);
64 report_blocks_.resize(report_block_count); 63 report_blocks_.resize(report_block_count);
65 const uint8_t* next_block = payload + kSenderBaseLength; 64 const uint8_t* next_block = payload + kSenderBaseLength;
66 for (ReportBlock& block : report_blocks_) { 65 for (ReportBlock& block : report_blocks_) {
67 bool block_parsed = block.Parse(next_block, ReportBlock::kLength); 66 bool block_parsed = block.Parse(next_block, ReportBlock::kLength);
68 RTC_DCHECK(block_parsed); 67 RTC_DCHECK(block_parsed);
69 next_block += ReportBlock::kLength; 68 next_block += ReportBlock::kLength;
70 } 69 }
71 // Double check we didn't read beyond provided buffer. 70 // Double check we didn't read beyond provided buffer.
72 RTC_DCHECK_LE(next_block, payload + header.payload_size_bytes); 71 RTC_DCHECK_EQ(next_block - payload,
72 static_cast<ptrdiff_t>(packet.payload_size_bytes()));
73 return true; 73 return true;
74 } 74 }
75 75
76 bool SenderReport::Create(uint8_t* packet, 76 bool SenderReport::Create(uint8_t* packet,
77 size_t* index, 77 size_t* index,
78 size_t max_length, 78 size_t max_length,
79 RtcpPacket::PacketReadyCallback* callback) const { 79 RtcpPacket::PacketReadyCallback* callback) const {
80 while (*index + BlockLength() > max_length) { 80 while (*index + BlockLength() > max_length) {
81 if (!OnBufferFull(packet, index, callback)) 81 if (!OnBufferFull(packet, index, callback))
82 return false; 82 return false;
(...skipping 26 matching lines...) Expand all
109 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { 109 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) {
110 LOG(LS_WARNING) << "Max report blocks reached."; 110 LOG(LS_WARNING) << "Max report blocks reached.";
111 return false; 111 return false;
112 } 112 }
113 report_blocks_.push_back(block); 113 report_blocks_.push_back(block);
114 return true; 114 return true;
115 } 115 }
116 116
117 } // namespace rtcp 117 } // namespace rtcp
118 } // namespace webrtc 118 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698