| Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc
|
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..59c809e154cbf6cc313a29f9f4d6483aa533785f
|
| --- /dev/null
|
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc
|
| @@ -0,0 +1,117 @@
|
| +/*
|
| + * Copyright (c) 2016 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/remb.h"
|
| +
|
| +#include "webrtc/base/logging.h"
|
| +#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
|
| +
|
| +using webrtc::RTCPUtility::PT_PSFB;
|
| +using webrtc::RTCPUtility::RTCPPacketPSFBAPP;
|
| +using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem;
|
| +
|
| +namespace webrtc {
|
| +namespace rtcp {
|
| +namespace {
|
| +const uint32_t kUnusedMediaSourceSsrc0 = 0;
|
| +
|
| +void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) {
|
| + buffer[(*offset)++] = value;
|
| +}
|
| +
|
| +void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) {
|
| + ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value);
|
| + *offset += 4;
|
| +}
|
| +
|
| +void ComputeMantissaAnd6bitBase2Exponent(uint32_t input_base10,
|
| + uint8_t bits_mantissa,
|
| + uint32_t* mantissa,
|
| + uint8_t* exp) {
|
| + // input_base10 = mantissa * 2^exp
|
| + assert(bits_mantissa <= 32);
|
| + uint32_t mantissa_max = (1 << bits_mantissa) - 1;
|
| + uint8_t exponent = 0;
|
| + for (uint32_t i = 0; i < 64; ++i) {
|
| + if (input_base10 <= (mantissa_max << i)) {
|
| + exponent = i;
|
| + break;
|
| + }
|
| + }
|
| + *exp = exponent;
|
| + *mantissa = (input_base10 >> exponent);
|
| +}
|
| +
|
| +// Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb).
|
| +//
|
| +// 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
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// |V=2|P| FMT=15 | PT=206 | length |
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// | SSRC of packet sender |
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// | SSRC of media source |
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// | Unique identifier 'R' 'E' 'M' 'B' |
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// | Num SSRC | BR Exp | BR Mantissa |
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// | SSRC feedback |
|
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| +// | ... |
|
| +void CreateRemb(const RTCPPacketPSFBAPP& remb,
|
| + const RTCPPacketPSFBREMBItem& remb_item,
|
| + uint8_t* buffer,
|
| + size_t* pos) {
|
| + uint32_t mantissa = 0;
|
| + uint8_t exp = 0;
|
| + ComputeMantissaAnd6bitBase2Exponent(remb_item.BitRate, 18, &mantissa, &exp);
|
| +
|
| + AssignUWord32(buffer, pos, remb.SenderSSRC);
|
| + AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0);
|
| + AssignUWord8(buffer, pos, 'R');
|
| + AssignUWord8(buffer, pos, 'E');
|
| + AssignUWord8(buffer, pos, 'M');
|
| + AssignUWord8(buffer, pos, 'B');
|
| + AssignUWord8(buffer, pos, remb_item.NumberOfSSRCs);
|
| + AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 16) & 0x03));
|
| + AssignUWord8(buffer, pos, mantissa >> 8);
|
| + AssignUWord8(buffer, pos, mantissa);
|
| + for (uint8_t i = 0; i < remb_item.NumberOfSSRCs; ++i) {
|
| + AssignUWord32(buffer, pos, remb_item.SSRCs[i]);
|
| + }
|
| +}
|
| +} // namespace
|
| +
|
| +bool Remb::Create(uint8_t* packet,
|
| + size_t* index,
|
| + size_t max_length,
|
| + RtcpPacket::PacketReadyCallback* callback) const {
|
| + while (*index + BlockLength() > max_length) {
|
| + if (!OnBufferFull(packet, index, callback))
|
| + return false;
|
| + }
|
| + const uint8_t kFmt = 15;
|
| + CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index);
|
| + CreateRemb(remb_, remb_item_, packet, index);
|
| + return true;
|
| +}
|
| +
|
| +void Remb::AppliesTo(uint32_t ssrc) {
|
| + if (remb_item_.NumberOfSSRCs >= kMaxNumberOfSsrcs) {
|
| + LOG(LS_WARNING) << "Max number of REMB feedback SSRCs reached.";
|
| + return;
|
| + }
|
| + remb_item_.SSRCs[remb_item_.NumberOfSSRCs++] = ssrc;
|
| +}
|
| +
|
| +} // namespace rtcp
|
| +} // namespace webrtc
|
|
|