| OLD | NEW |
| 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/remb.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.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 { |
| 20 constexpr uint8_t Remb::kFeedbackMessageType; |
| 21 // Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb). | 21 // Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb). |
| 22 // | 22 // |
| 23 // 0 1 2 3 | 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 | 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 // |V=2|P| FMT=15 | PT=206 | length | | 26 // |V=2|P| FMT=15 | PT=206 | length | |
| 27 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 27 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
| 28 // 0 | SSRC of packet sender | | 28 // 0 | SSRC of packet sender | |
| 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 // 4 | Unused = 0 | | 30 // 4 | Unused = 0 | |
| 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 32 // 8 | Unique identifier 'R' 'E' 'M' 'B' | | 32 // 8 | Unique identifier 'R' 'E' 'M' 'B' | |
| 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 34 // 12 | Num SSRC | BR Exp | BR Mantissa | | 34 // 12 | Num SSRC | BR Exp | BR Mantissa | |
| 35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 36 // 16 | SSRC feedback | | 36 // 16 | SSRC feedback | |
| 37 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 37 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 38 // : ... : | 38 // : ... : |
| 39 bool Remb::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { | 39 bool Remb::Parse(const CommonHeader& packet) { |
| 40 RTC_DCHECK(header.packet_type == kPacketType); | 40 RTC_DCHECK(packet.type() == kPacketType); |
| 41 RTC_DCHECK(header.count_or_format == kFeedbackMessageType); | 41 RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType); |
| 42 | 42 |
| 43 if (header.payload_size_bytes < 16) { | 43 if (packet.payload_size_bytes() < 16) { |
| 44 LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes | 44 LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes() |
| 45 << " is too small for Remb packet."; | 45 << " is too small for Remb packet."; |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 const uint8_t* const payload = packet.payload(); |
| 48 if (kUniqueIdentifier != ByteReader<uint32_t>::ReadBigEndian(&payload[8])) { | 49 if (kUniqueIdentifier != ByteReader<uint32_t>::ReadBigEndian(&payload[8])) { |
| 49 LOG(LS_WARNING) << "REMB identifier not found, not a REMB packet."; | 50 LOG(LS_WARNING) << "REMB identifier not found, not a REMB packet."; |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 52 uint8_t number_of_ssrcs = payload[12]; | 53 uint8_t number_of_ssrcs = payload[12]; |
| 53 if (header.payload_size_bytes != | 54 if (packet.payload_size_bytes() != |
| 54 kCommonFeedbackLength + (2 + number_of_ssrcs) * 4) { | 55 kCommonFeedbackLength + (2 + number_of_ssrcs) * 4) { |
| 55 LOG(LS_WARNING) << "Payload size " << header.payload_size_bytes | 56 LOG(LS_WARNING) << "Payload size " << packet.payload_size_bytes() |
| 56 << " does not match " << number_of_ssrcs << " ssrcs."; | 57 << " does not match " << number_of_ssrcs << " ssrcs."; |
| 57 return false; | 58 return false; |
| 58 } | 59 } |
| 59 | 60 |
| 60 ParseCommonFeedback(payload); | 61 ParseCommonFeedback(payload); |
| 61 uint8_t exponenta = payload[13] >> 2; | 62 uint8_t exponenta = payload[13] >> 2; |
| 62 uint32_t mantissa = (static_cast<uint32_t>(payload[13] & 0x03) << 16) | | 63 uint64_t mantissa = (static_cast<uint32_t>(payload[13] & 0x03) << 16) | |
| 63 ByteReader<uint16_t>::ReadBigEndian(&payload[14]); | 64 ByteReader<uint16_t>::ReadBigEndian(&payload[14]); |
| 64 bitrate_bps_ = (mantissa << exponenta); | 65 bitrate_bps_ = (mantissa << exponenta); |
| 66 bool shift_overflow = (bitrate_bps_ >> exponenta) != mantissa; |
| 67 if (shift_overflow) { |
| 68 LOG(LS_ERROR) << "Invalid remb bitrate value : " << mantissa |
| 69 << "*2^" << static_cast<int>(exponenta); |
| 70 return false; |
| 71 } |
| 65 | 72 |
| 66 const uint8_t* next_ssrc = payload + 16; | 73 const uint8_t* next_ssrc = payload + 16; |
| 67 ssrcs_.clear(); | 74 ssrcs_.clear(); |
| 68 ssrcs_.reserve(number_of_ssrcs); | 75 ssrcs_.reserve(number_of_ssrcs); |
| 69 for (uint8_t i = 0; i < number_of_ssrcs; ++i) { | 76 for (uint8_t i = 0; i < number_of_ssrcs; ++i) { |
| 70 ssrcs_.push_back(ByteReader<uint32_t>::ReadBigEndian(next_ssrc)); | 77 ssrcs_.push_back(ByteReader<uint32_t>::ReadBigEndian(next_ssrc)); |
| 71 next_ssrc += sizeof(uint32_t); | 78 next_ssrc += sizeof(uint32_t); |
| 72 } | 79 } |
| 73 | 80 |
| 74 return true; | 81 return true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 104 size_t index_end = *index + BlockLength(); | 111 size_t index_end = *index + BlockLength(); |
| 105 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, | 112 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, |
| 106 index); | 113 index); |
| 107 RTC_DCHECK_EQ(0u, Psfb::media_ssrc()); | 114 RTC_DCHECK_EQ(0u, Psfb::media_ssrc()); |
| 108 CreateCommonFeedback(packet + *index); | 115 CreateCommonFeedback(packet + *index); |
| 109 *index += kCommonFeedbackLength; | 116 *index += kCommonFeedbackLength; |
| 110 | 117 |
| 111 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, kUniqueIdentifier); | 118 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, kUniqueIdentifier); |
| 112 *index += sizeof(uint32_t); | 119 *index += sizeof(uint32_t); |
| 113 const uint32_t kMaxMantissa = 0x3ffff; // 18 bits. | 120 const uint32_t kMaxMantissa = 0x3ffff; // 18 bits. |
| 114 uint32_t mantissa = bitrate_bps_; | 121 uint64_t mantissa = bitrate_bps_; |
| 115 uint8_t exponenta = 0; | 122 uint8_t exponenta = 0; |
| 116 while (mantissa > kMaxMantissa) { | 123 while (mantissa > kMaxMantissa) { |
| 117 mantissa >>= 1; | 124 mantissa >>= 1; |
| 118 ++exponenta; | 125 ++exponenta; |
| 119 } | 126 } |
| 120 packet[(*index)++] = ssrcs_.size(); | 127 packet[(*index)++] = ssrcs_.size(); |
| 121 packet[(*index)++] = (exponenta << 2) | (mantissa >> 16); | 128 packet[(*index)++] = (exponenta << 2) | (mantissa >> 16); |
| 122 ByteWriter<uint16_t>::WriteBigEndian(packet + *index, mantissa & 0xffff); | 129 ByteWriter<uint16_t>::WriteBigEndian(packet + *index, mantissa & 0xffff); |
| 123 *index += sizeof(uint16_t); | 130 *index += sizeof(uint16_t); |
| 124 | 131 |
| 125 for (uint32_t ssrc : ssrcs_) { | 132 for (uint32_t ssrc : ssrcs_) { |
| 126 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, ssrc); | 133 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, ssrc); |
| 127 *index += sizeof(uint32_t); | 134 *index += sizeof(uint32_t); |
| 128 } | 135 } |
| 129 RTC_DCHECK_EQ(index_end, *index); | 136 RTC_DCHECK_EQ(index_end, *index); |
| 130 return true; | 137 return true; |
| 131 } | 138 } |
| 132 } // namespace rtcp | 139 } // namespace rtcp |
| 133 } // namespace webrtc | 140 } // namespace webrtc |
| OLD | NEW |