Chromium Code Reviews

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet.cc

Issue 1590883002: [rtp_rtcp] rtcp::Remb moved into own file (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
(...skipping 11 matching lines...)
22 22
23 using webrtc::RTCPUtility::PT_APP; 23 using webrtc::RTCPUtility::PT_APP;
24 using webrtc::RTCPUtility::PT_IJ; 24 using webrtc::RTCPUtility::PT_IJ;
25 using webrtc::RTCPUtility::PT_PSFB; 25 using webrtc::RTCPUtility::PT_PSFB;
26 using webrtc::RTCPUtility::PT_RTPFB; 26 using webrtc::RTCPUtility::PT_RTPFB;
27 using webrtc::RTCPUtility::PT_SDES; 27 using webrtc::RTCPUtility::PT_SDES;
28 using webrtc::RTCPUtility::PT_SR; 28 using webrtc::RTCPUtility::PT_SR;
29 using webrtc::RTCPUtility::PT_XR; 29 using webrtc::RTCPUtility::PT_XR;
30 30
31 using webrtc::RTCPUtility::RTCPPacketAPP; 31 using webrtc::RTCPUtility::RTCPPacketAPP;
32 using webrtc::RTCPUtility::RTCPPacketPSFBAPP;
33 using webrtc::RTCPUtility::RTCPPacketPSFBFIR; 32 using webrtc::RTCPUtility::RTCPPacketPSFBFIR;
34 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem; 33 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem;
35 using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem;
36 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; 34 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI;
37 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; 35 using webrtc::RTCPUtility::RTCPPacketReportBlockItem;
38 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; 36 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK;
39 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; 37 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem;
40 using webrtc::RTCPUtility::RTCPPacketSR; 38 using webrtc::RTCPUtility::RTCPPacketSR;
41 using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem; 39 using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem;
42 using webrtc::RTCPUtility::RTCPPacketXR; 40 using webrtc::RTCPUtility::RTCPPacketXR;
43 41
44 namespace webrtc { 42 namespace webrtc {
45 namespace rtcp { 43 namespace rtcp {
(...skipping 10 matching lines...)
56 } 54 }
57 void AssignUWord24(uint8_t* buffer, size_t* offset, uint32_t value) { 55 void AssignUWord24(uint8_t* buffer, size_t* offset, uint32_t value) {
58 ByteWriter<uint32_t, 3>::WriteBigEndian(buffer + *offset, value); 56 ByteWriter<uint32_t, 3>::WriteBigEndian(buffer + *offset, value);
59 *offset += 3; 57 *offset += 3;
60 } 58 }
61 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { 59 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) {
62 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value); 60 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value);
63 *offset += 4; 61 *offset += 4;
64 } 62 }
65 63
66 void ComputeMantissaAnd6bitBase2Exponent(uint32_t input_base10,
67 uint8_t bits_mantissa,
68 uint32_t* mantissa,
69 uint8_t* exp) {
70 // input_base10 = mantissa * 2^exp
71 assert(bits_mantissa <= 32);
72 uint32_t mantissa_max = (1 << bits_mantissa) - 1;
73 uint8_t exponent = 0;
74 for (uint32_t i = 0; i < 64; ++i) {
75 if (input_base10 <= (mantissa_max << i)) {
76 exponent = i;
77 break;
78 }
79 }
80 *exp = exponent;
81 *mantissa = (input_base10 >> exponent);
82 }
83
84 // Sender report (SR) (RFC 3550). 64 // Sender report (SR) (RFC 3550).
85 // 0 1 2 3 65 // 0 1 2 3
86 // 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 66 // 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
87 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 67 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88 // |V=2|P| RC | PT=SR=200 | length | 68 // |V=2|P| RC | PT=SR=200 | length |
89 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 69 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 // | SSRC of sender | 70 // | SSRC of sender |
91 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ 71 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
92 // | NTP timestamp, most significant word | 72 // | NTP timestamp, most significant word |
93 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 73 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
(...skipping 129 matching lines...)
223 const RTCPPacketPSFBFIRItem& fir_item, 203 const RTCPPacketPSFBFIRItem& fir_item,
224 uint8_t* buffer, 204 uint8_t* buffer,
225 size_t* pos) { 205 size_t* pos) {
226 AssignUWord32(buffer, pos, fir.SenderSSRC); 206 AssignUWord32(buffer, pos, fir.SenderSSRC);
227 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0); 207 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0);
228 AssignUWord32(buffer, pos, fir_item.SSRC); 208 AssignUWord32(buffer, pos, fir_item.SSRC);
229 AssignUWord8(buffer, pos, fir_item.CommandSequenceNumber); 209 AssignUWord8(buffer, pos, fir_item.CommandSequenceNumber);
230 AssignUWord24(buffer, pos, 0); 210 AssignUWord24(buffer, pos, 0);
231 } 211 }
232 212
233 // Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb).
234 //
235 // 0 1 2 3
236 // 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
237 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238 // |V=2|P| FMT=15 | PT=206 | length |
239 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240 // | SSRC of packet sender |
241 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 // | SSRC of media source |
243 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244 // | Unique identifier 'R' 'E' 'M' 'B' |
245 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
246 // | Num SSRC | BR Exp | BR Mantissa |
247 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 // | SSRC feedback |
249 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
250 // | ... |
251
252 void CreateRemb(const RTCPPacketPSFBAPP& remb,
253 const RTCPPacketPSFBREMBItem& remb_item,
254 uint8_t* buffer,
255 size_t* pos) {
256 uint32_t mantissa = 0;
257 uint8_t exp = 0;
258 ComputeMantissaAnd6bitBase2Exponent(remb_item.BitRate, 18, &mantissa, &exp);
259
260 AssignUWord32(buffer, pos, remb.SenderSSRC);
261 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0);
262 AssignUWord8(buffer, pos, 'R');
263 AssignUWord8(buffer, pos, 'E');
264 AssignUWord8(buffer, pos, 'M');
265 AssignUWord8(buffer, pos, 'B');
266 AssignUWord8(buffer, pos, remb_item.NumberOfSSRCs);
267 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 16) & 0x03));
268 AssignUWord8(buffer, pos, mantissa >> 8);
269 AssignUWord8(buffer, pos, mantissa);
270 for (uint8_t i = 0; i < remb_item.NumberOfSSRCs; ++i) {
271 AssignUWord32(buffer, pos, remb_item.SSRCs[i]);
272 }
273 }
274
275 // From RFC 3611: RTP Control Protocol Extended Reports (RTCP XR). 213 // From RFC 3611: RTP Control Protocol Extended Reports (RTCP XR).
276 // 214 //
277 // Format for XR packets: 215 // Format for XR packets:
278 // 216 //
279 // 0 1 2 3 217 // 0 1 2 3
280 // 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 218 // 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
281 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 219 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
282 // |V=2|P|reserved | PT=XR=207 | length | 220 // |V=2|P|reserved | PT=XR=207 | length |
283 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 221 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
284 // | SSRC | 222 // | SSRC |
(...skipping 221 matching lines...)
506 while (*index + BlockLength() > max_length) { 444 while (*index + BlockLength() > max_length) {
507 if (!OnBufferFull(packet, index, callback)) 445 if (!OnBufferFull(packet, index, callback))
508 return false; 446 return false;
509 } 447 }
510 const uint8_t kFmt = 4; 448 const uint8_t kFmt = 4;
511 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); 449 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index);
512 CreateFir(fir_, fir_item_, packet, index); 450 CreateFir(fir_, fir_item_, packet, index);
513 return true; 451 return true;
514 } 452 }
515 453
516 bool Remb::Create(uint8_t* packet,
517 size_t* index,
518 size_t max_length,
519 RtcpPacket::PacketReadyCallback* callback) const {
520 while (*index + BlockLength() > max_length) {
521 if (!OnBufferFull(packet, index, callback))
522 return false;
523 }
524 const uint8_t kFmt = 15;
525 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index);
526 CreateRemb(remb_, remb_item_, packet, index);
527 return true;
528 }
529
530 void Remb::AppliesTo(uint32_t ssrc) {
531 if (remb_item_.NumberOfSSRCs >= kMaxNumberOfSsrcs) {
532 LOG(LS_WARNING) << "Max number of REMB feedback SSRCs reached.";
533 return;
534 }
535 remb_item_.SSRCs[remb_item_.NumberOfSSRCs++] = ssrc;
536 }
537
538 bool Xr::Create(uint8_t* packet, 454 bool Xr::Create(uint8_t* packet,
539 size_t* index, 455 size_t* index,
540 size_t max_length, 456 size_t max_length,
541 RtcpPacket::PacketReadyCallback* callback) const { 457 RtcpPacket::PacketReadyCallback* callback) const {
542 while (*index + BlockLength() > max_length) { 458 while (*index + BlockLength() > max_length) {
543 if (!OnBufferFull(packet, index, callback)) 459 if (!OnBufferFull(packet, index, callback))
544 return false; 460 return false;
545 } 461 }
546 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); 462 CreateHeader(0U, PT_XR, HeaderLength(), packet, index);
547 CreateXrHeader(xr_header_, packet, index); 463 CreateXrHeader(xr_header_, packet, index);
(...skipping 77 matching lines...)
625 return length_; 541 return length_;
626 } 542 }
627 543
628 void RawPacket::SetLength(size_t length) { 544 void RawPacket::SetLength(size_t length) {
629 assert(length <= buffer_length_); 545 assert(length <= buffer_length_);
630 length_ = length; 546 length_ = length;
631 } 547 }
632 548
633 } // namespace rtcp 549 } // namespace rtcp
634 } // namespace webrtc 550 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h » ('j') | no next file with comments »

Powered by Google App Engine