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

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

Issue 1544983002: [rtp_rtcp] rtcp::SenderReport moved into own file and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added SenderReport::ClearReportBlocks to make SenderReport reusable Created 4 years, 11 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
(Empty)
1 /*
2 * Copyright (c) 2016 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 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16
17 using webrtc::RTCPUtility::RtcpCommonHeader;
18
19 namespace webrtc {
20 namespace rtcp {
21 const uint8_t SenderReport::kPacketType;
22 // Sender report (SR) (RFC 3550).
23 // 0 1 2 3
24 // 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
25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26 // |V=2|P| RC | PT=SR=200 | length |
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 // 0 | SSRC of sender |
29 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
30 // 4 | NTP timestamp, most significant word |
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 // 8 | NTP timestamp, least significant word |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 // 12 | RTP timestamp |
35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 // 16 | sender's packet count |
37 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 // 20 | sender's octet count |
39 // 24 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
40
41 SenderReport::SenderReport()
42 : sender_ssrc_(0),
43 rtp_timestamp_(0),
44 sender_packet_count_(0),
45 sender_octet_count_(0) {}
46
47 bool SenderReport::Parse(const RtcpCommonHeader& header,
48 const uint8_t* payload) {
49 RTC_DCHECK_EQ(header.packet_type, kPacketType);
åsapersson 2016/01/13 14:11:32 RTC_DCHECK_EQ(kPacketType, header.packet_type);
danilchap 2016/01/13 15:54:44 Actually can't use _EQ in this case. While it work
50
51 const uint8_t report_block_count = header.count_or_format;
52 if (header.payload_size_bytes <
53 kSenderBaseLength + report_block_count * ReportBlock::kLength) {
54 LOG(LS_WARNING) << "Packet is too small to contain all the data.";
55 return false;
56 }
57 // Read SenderReport header.
58 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]);
59 uint32_t secs = ByteReader<uint32_t>::ReadBigEndian(&payload[4]);
60 uint32_t frac = ByteReader<uint32_t>::ReadBigEndian(&payload[8]);
61 ntp_.Set(secs, frac);
62 rtp_timestamp_ = ByteReader<uint32_t>::ReadBigEndian(&payload[12]);
63 sender_packet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[16]);
64 sender_octet_count_ = ByteReader<uint32_t>::ReadBigEndian(&payload[20]);
65 report_blocks_.resize(report_block_count);
66 const uint8_t* next_block = payload + kSenderBaseLength;
67 for (ReportBlock& block : report_blocks_) {
68 bool block_parsed = block.Parse(next_block, ReportBlock::kLength);
69 RTC_DCHECK(block_parsed);
70 next_block += ReportBlock::kLength;
71 }
72 // Double check we didn't read beyond provided buffer.
73 RTC_DCHECK_LE(next_block, payload + header.payload_size_bytes);
74 return true;
75 }
76
77 bool SenderReport::Create(uint8_t* packet,
78 size_t* index,
79 size_t max_length,
80 RtcpPacket::PacketReadyCallback* callback) const {
81 while (*index + BlockLength() > max_length) {
82 if (!OnBufferFull(packet, index, callback))
83 return false;
84 }
85 const size_t index_end = *index + BlockLength();
86
87 CreateHeader(report_blocks_.size(), kPacketType, HeaderLength(), packet,
88 index);
89 // Write SenderReport header.
90 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], sender_ssrc_);
91 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], ntp_.seconds());
92 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 8], ntp_.fractions());
93 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 12], rtp_timestamp_);
94 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 16],
95 sender_packet_count_);
96 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 20],
97 sender_octet_count_);
98 *index += kSenderBaseLength;
99 // Write report blocks.
100 for (const ReportBlock& block : report_blocks_) {
101 block.Create(packet + *index);
102 *index += ReportBlock::kLength;
103 }
104 // Ensure bytes written match expected.
105 RTC_DCHECK_EQ(*index, index_end);
106 return true;
107 }
108
109 bool SenderReport::WithReportBlock(const ReportBlock& block) {
110 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) {
111 LOG(LS_WARNING) << "Max report blocks reached.";
112 return false;
113 }
114 report_blocks_.push_back(block);
115 return true;
116 }
117
118 } // namespace rtcp
119 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698