Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..43c0a7be5fc71486ac6cce049c9b40e9d4343a4e |
| --- /dev/null |
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.cc |
| @@ -0,0 +1,85 @@ |
| +/* |
| + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
| + |
| +#include "webrtc/base/logging.h" |
| +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| + |
| +namespace webrtc { |
| +namespace rtcp { |
| + |
| +// From RFC 3550, RTP: A Transport Protocol for Real-Time Applications. |
| +// |
| +// RTCP report block (RFC 3550). |
| +// |
| +// 0 1 2 3 |
| +// 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 |
| +// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| +// 0 | SSRC_1 (SSRC of first source) | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 4 | fraction lost | cumulative number of packets lost | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 8 | extended highest sequence number received | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 12 | interarrival jitter | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 16 | last SR (LSR) | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// 20 | delay since last SR (DLSR) | |
| +// 24 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| +ReportBlock::ReportBlock() |
| + : source_ssrc_(0), |
| + fraction_lost_(0), |
| + cumulative_lost_(0), |
| + extended_high_seq_num_(0), |
| + jitter_(0), |
| + last_sr_(0), |
| + delay_since_last_sr_(0) {} |
| + |
| +bool ReportBlock::Parse(const uint8_t* buffer, size_t length) { |
| + if (buffer == nullptr) { |
|
åsapersson
2015/11/12 14:26:25
Can RTC_CHECK be used?
danilchap
2015/11/12 15:30:45
yes, RTC_DCHECK make even more sense
|
| + LOG(LS_ERROR) << "Parsing nullptr can't be valid"; |
| + return false; |
| + } |
| + if (length < ReportBlock::kLength) { |
| + LOG(LS_ERROR) << "Report Block should be 24 bytes long"; |
| + return false; |
| + } |
| + |
| + source_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[0]); |
| + fraction_lost_ = buffer[4]; |
| + cumulative_lost_ = ByteReader<uint32_t, 3>::ReadBigEndian(&buffer[5]); |
| + extended_high_seq_num_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[8]); |
| + jitter_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[12]); |
| + last_sr_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[16]); |
| + delay_since_last_sr_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[20]); |
| + |
| + return true; |
| +} |
| + |
| +size_t ReportBlock::Create(uint8_t* buffer) const { |
| + if (cumulative_lost() >= (1 << 24)) { // Have only 3 bytes to store it. |
| + LOG(LS_WARNING) << "Cumulative lost is too big to fit into Report Block"; |
| + return 0; |
| + } |
| + |
| + ByteWriter<uint32_t>::WriteBigEndian(&buffer[0], source_ssrc()); |
| + ByteWriter<uint8_t>::WriteBigEndian(&buffer[4], fraction_lost()); |
| + ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[5], cumulative_lost()); |
| + ByteWriter<uint32_t>::WriteBigEndian(&buffer[8], extended_high_seq_num()); |
| + ByteWriter<uint32_t>::WriteBigEndian(&buffer[12], jitter()); |
| + ByteWriter<uint32_t>::WriteBigEndian(&buffer[16], last_sr()); |
| + ByteWriter<uint32_t>::WriteBigEndian(&buffer[20], delay_since_last_sr()); |
| + return kLength; |
| +} |
| + |
| +} // namespace rtcp |
| +} // namespace webrtc |