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/tmmbn.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h" |
12 | 12 |
13 #include "webrtc/base/logging.h" | 13 #include "webrtc/base/logging.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 | 15 |
16 using webrtc::RTCPUtility::PT_RTPFB; | 16 using webrtc::RTCPUtility::PT_RTPFB; |
17 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBN; | 17 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBR; |
18 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBRItem; | 18 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBRItem; |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 namespace rtcp { | 21 namespace rtcp { |
22 namespace { | 22 namespace { |
23 const uint32_t kUnusedMediaSourceSsrc0 = 0; | 23 const uint32_t kUnusedMediaSourceSsrc0 = 0; |
| 24 |
24 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { | 25 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { |
25 buffer[(*offset)++] = value; | 26 buffer[(*offset)++] = value; |
26 } | 27 } |
| 28 |
27 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { | 29 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { |
28 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value); | 30 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value); |
29 *offset += 4; | 31 *offset += 4; |
30 } | 32 } |
31 | 33 |
32 void ComputeMantissaAnd6bitBase2Exponent(uint32_t input_base10, | 34 void ComputeMantissaAnd6bitBase2Exponent(uint32_t input_base10, |
33 uint8_t bits_mantissa, | 35 uint8_t bits_mantissa, |
34 uint32_t* mantissa, | 36 uint32_t* mantissa, |
35 uint8_t* exp) { | 37 uint8_t* exp) { |
36 // input_base10 = mantissa * 2^exp | 38 // input_base10 = mantissa * 2^exp |
(...skipping 19 matching lines...) Expand all Loading... |
56 ComputeMantissaAnd6bitBase2Exponent(bitrate_bps, 17, &mantissa, &exp); | 58 ComputeMantissaAnd6bitBase2Exponent(bitrate_bps, 17, &mantissa, &exp); |
57 | 59 |
58 AssignUWord32(buffer, pos, tmmbr_item.SSRC); | 60 AssignUWord32(buffer, pos, tmmbr_item.SSRC); |
59 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 15) & 0x03)); | 61 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 15) & 0x03)); |
60 AssignUWord8(buffer, pos, mantissa >> 7); | 62 AssignUWord8(buffer, pos, mantissa >> 7); |
61 AssignUWord8(buffer, pos, (mantissa << 1) + | 63 AssignUWord8(buffer, pos, (mantissa << 1) + |
62 ((tmmbr_item.MeasuredOverhead >> 8) & 0x01)); | 64 ((tmmbr_item.MeasuredOverhead >> 8) & 0x01)); |
63 AssignUWord8(buffer, pos, tmmbr_item.MeasuredOverhead); | 65 AssignUWord8(buffer, pos, tmmbr_item.MeasuredOverhead); |
64 } | 66 } |
65 | 67 |
66 // Temporary Maximum Media Stream Bit Rate Notification (TMMBN) (RFC 5104). | 68 // Temporary Maximum Media Stream Bit Rate Request (TMMBR) (RFC 5104). |
67 // | 69 // |
68 // FCI: | 70 // FCI: |
69 // | 71 // |
70 // 0 1 2 3 | 72 // 0 1 2 3 |
71 // 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 | 73 // 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 |
72 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 74 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
73 // | SSRC | | 75 // | SSRC | |
74 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 76 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
75 // | MxTBR Exp | MxTBR Mantissa |Measured Overhead| | 77 // | MxTBR Exp | MxTBR Mantissa |Measured Overhead| |
76 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 78 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
77 | 79 |
78 void CreateTmmbn(const RTCPPacketRTPFBTMMBN& tmmbn, | 80 void CreateTmmbr(const RTCPPacketRTPFBTMMBR& tmmbr, |
79 const std::vector<RTCPPacketRTPFBTMMBRItem>& tmmbn_items, | 81 const RTCPPacketRTPFBTMMBRItem& tmmbr_item, |
80 uint8_t* buffer, | 82 uint8_t* buffer, |
81 size_t* pos) { | 83 size_t* pos) { |
82 AssignUWord32(buffer, pos, tmmbn.SenderSSRC); | 84 AssignUWord32(buffer, pos, tmmbr.SenderSSRC); |
83 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0); | 85 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0); |
84 for (uint8_t i = 0; i < tmmbn_items.size(); ++i) { | 86 CreateTmmbrItem(tmmbr_item, buffer, pos); |
85 CreateTmmbrItem(tmmbn_items[i], buffer, pos); | |
86 } | |
87 } | 87 } |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 bool Tmmbn::WithTmmbr(uint32_t ssrc, uint32_t bitrate_kbps, uint16_t overhead) { | 90 bool Tmmbr::Create(uint8_t* packet, |
91 assert(overhead <= 0x1ff); | |
92 if (tmmbn_items_.size() >= kMaxNumberOfTmmbrs) { | |
93 LOG(LS_WARNING) << "Max TMMBN size reached."; | |
94 return false; | |
95 } | |
96 RTCPPacketRTPFBTMMBRItem tmmbn_item; | |
97 tmmbn_item.SSRC = ssrc; | |
98 tmmbn_item.MaxTotalMediaBitRate = bitrate_kbps; | |
99 tmmbn_item.MeasuredOverhead = overhead; | |
100 tmmbn_items_.push_back(tmmbn_item); | |
101 return true; | |
102 } | |
103 | |
104 bool Tmmbn::Create(uint8_t* packet, | |
105 size_t* index, | 91 size_t* index, |
106 size_t max_length, | 92 size_t max_length, |
107 RtcpPacket::PacketReadyCallback* callback) const { | 93 RtcpPacket::PacketReadyCallback* callback) const { |
108 while (*index + BlockLength() > max_length) { | 94 while (*index + BlockLength() > max_length) { |
109 if (!OnBufferFull(packet, index, callback)) | 95 if (!OnBufferFull(packet, index, callback)) |
110 return false; | 96 return false; |
111 } | 97 } |
112 const uint8_t kFmt = 4; | 98 const uint8_t kFmt = 3; |
113 CreateHeader(kFmt, PT_RTPFB, HeaderLength(), packet, index); | 99 CreateHeader(kFmt, PT_RTPFB, HeaderLength(), packet, index); |
114 CreateTmmbn(tmmbn_, tmmbn_items_, packet, index); | 100 CreateTmmbr(tmmbr_, tmmbr_item_, packet, index); |
115 return true; | 101 return true; |
116 } | 102 } |
117 | 103 |
118 } // namespace rtcp | 104 } // namespace rtcp |
119 } // namespace webrtc | 105 } // namespace webrtc |
OLD | NEW |