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

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

Issue 1453083002: rtcp::ReceiverReport moved into own file and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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) 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 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h"
15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
17
18 using webrtc::RTCPUtility::RtcpCommonHeader;
19
20 namespace webrtc {
21 namespace rtcp {
22
23 //
24 // RTCP receiver report (RFC 3550).
25 //
26 // 0 1 2 3
27 // 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
28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 // |V=2|P| RC | PT=RR=201 | length |
30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 // | SSRC of packet sender |
32 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
33 // | report block(s) |
34 // | .... |
35 bool ReceiverReport::Parse(const RTCPUtility::RtcpCommonHeader& header,
36 const uint8_t* payload) {
37 RTC_DCHECK(header.packet_type == kPacketType);
38
39 const uint8_t report_blocks_count = header.count_or_format;
40
41 if (header.payload_size_bytes <
42 kRrBaseLength + report_blocks_count * ReportBlock::kLength) {
43 LOG(LS_WARNING) << "Packet is too small to contain all the data.";
44 return false;
45 }
46
47 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(payload);
48
49 const uint8_t* next_report_block = payload + kRrBaseLength;
50
51 report_blocks_.resize(report_blocks_count);
52 for (ReportBlock& block : report_blocks_) {
53 block.Parse(next_report_block, ReportBlock::kLength);
54 next_report_block += ReportBlock::kLength;
55 }
56
57 RTC_DCHECK_LE(next_report_block, payload + header.payload_size_bytes);
58 return true;
59 }
60
61 bool ReceiverReport::Create(uint8_t* packet,
62 size_t* index,
63 size_t max_length,
64 RtcpPacket::PacketReadyCallback* callback) const {
65 while (*index + BlockLength() > max_length) {
66 if (!OnBufferFull(packet, index, callback))
67 return false;
68 }
69 CreateHeader(report_blocks_.size(), kPacketType, HeaderLength(), packet,
70 index);
71 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, sender_ssrc_);
72 *index += kRrBaseLength;
73 for (const ReportBlock& block : report_blocks_) {
74 block.Create(packet + *index);
75 *index += ReportBlock::kLength;
76 }
77 return true;
78 }
79
80 bool ReceiverReport::WithReportBlock(const ReportBlock& block) {
81 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) {
82 LOG(LS_WARNING) << "Max report blocks reached.";
83 return false;
84 }
85 report_blocks_.push_back(block);
86 return true;
87 }
88
89 } // namespace rtcp
90 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698