| OLD | NEW |
| (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/tmmb_item.h" |
| 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 15 |
| 16 namespace webrtc { |
| 17 namespace rtcp { |
| 18 TmmbItem::TmmbItem(uint32_t ssrc, uint32_t bitrate_bps, uint16_t overhead) |
| 19 : ssrc_(ssrc), bitrate_bps_(bitrate_bps), packet_overhead_(overhead) { |
| 20 RTC_DCHECK_LE(overhead, 0x1ffu); |
| 21 } |
| 22 |
| 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 // 0 | SSRC | |
| 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 // 4 | MxTBR Exp | MxTBR Mantissa |Measured Overhead| |
| 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 void TmmbItem::Parse(const uint8_t* buffer) { |
| 31 ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[0]); |
| 32 // Read 4 bytes into 1 block. |
| 33 uint32_t compact = ByteReader<uint32_t>::ReadBigEndian(&buffer[4]); |
| 34 // Split 1 block into 3 components. |
| 35 uint8_t exponent = compact >> 26; // 6 bits. |
| 36 uint32_t mantissa = (compact >> 9) & 0x1ffff; // 17 bits. |
| 37 uint16_t overhead = compact & 0x1ff; // 9 bits. |
| 38 // Combine 3 components into 2 values. |
| 39 bitrate_bps_ = (mantissa << exponent); |
| 40 packet_overhead_ = overhead; |
| 41 } |
| 42 |
| 43 void TmmbItem::Create(uint8_t* buffer) const { |
| 44 const uint32_t kMaxMantissa = 0x1ffff; // 17 bits. |
| 45 uint32_t mantissa = bitrate_bps_; |
| 46 uint32_t exponent = 0; |
| 47 while (mantissa > kMaxMantissa) { |
| 48 mantissa >>= 1; |
| 49 ++exponent; |
| 50 } |
| 51 |
| 52 ByteWriter<uint32_t>::WriteBigEndian(&buffer[0], ssrc_); |
| 53 uint32_t compact = (exponent << 26) | (mantissa << 9) | packet_overhead_; |
| 54 ByteWriter<uint32_t>::WriteBigEndian(&buffer[4], compact); |
| 55 } |
| 56 |
| 57 void TmmbItem::set_packet_overhead(uint16_t overhead) { |
| 58 RTC_DCHECK_LE(overhead, 0x1ffu); |
| 59 packet_overhead_ = overhead; |
| 60 } |
| 61 } // namespace rtcp |
| 62 } // namespace webrtc |
| OLD | NEW |