Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

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

Issue 1670973002: [rtp_rtcp] rtcp::Tmmbn cleaned and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase & spelling Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/tmmbn.h"
12 12
13 #include "webrtc/base/checks.h"
13 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
15 16
16 using webrtc::RTCPUtility::PT_RTPFB; 17 using webrtc::RTCPUtility::RtcpCommonHeader;
17 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBN;
18 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBRItem;
19 18
20 namespace webrtc { 19 namespace webrtc {
21 namespace rtcp { 20 namespace rtcp {
22 namespace { 21 // RFC 4585: Feedback format.
23 const uint32_t kUnusedMediaSourceSsrc0 = 0; 22 // Common packet format:
24 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { 23 //
25 buffer[(*offset)++] = value; 24 // 0 1 2 3
26 } 25 // 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
27 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { 26 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value); 27 // |V=2|P| FMT | PT | length |
29 *offset += 4; 28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 } 29 // | SSRC of packet sender |
31 30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 void ComputeMantissaAnd6bitBase2Exponent(uint32_t input_base10, 31 // | SSRC of media source (unused) = 0 |
33 uint8_t bits_mantissa, 32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 uint32_t* mantissa, 33 // : Feedback Control Information (FCI) :
35 uint8_t* exp) { 34 // : :
36 // input_base10 = mantissa * 2^exp
37 assert(bits_mantissa <= 32);
38 uint32_t mantissa_max = (1 << bits_mantissa) - 1;
39 uint8_t exponent = 0;
40 for (uint32_t i = 0; i < 64; ++i) {
41 if (input_base10 <= (mantissa_max << i)) {
42 exponent = i;
43 break;
44 }
45 }
46 *exp = exponent;
47 *mantissa = (input_base10 >> exponent);
48 }
49
50 void CreateTmmbrItem(const RTCPPacketRTPFBTMMBRItem& tmmbr_item,
51 uint8_t* buffer,
52 size_t* pos) {
53 uint32_t bitrate_bps = tmmbr_item.MaxTotalMediaBitRate * 1000;
54 uint32_t mantissa = 0;
55 uint8_t exp = 0;
56 ComputeMantissaAnd6bitBase2Exponent(bitrate_bps, 17, &mantissa, &exp);
57
58 AssignUWord32(buffer, pos, tmmbr_item.SSRC);
59 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 15) & 0x03));
60 AssignUWord8(buffer, pos, mantissa >> 7);
61 AssignUWord8(buffer, pos, (mantissa << 1) +
62 ((tmmbr_item.MeasuredOverhead >> 8) & 0x01));
63 AssignUWord8(buffer, pos, tmmbr_item.MeasuredOverhead);
64 }
65
66 // Temporary Maximum Media Stream Bit Rate Notification (TMMBN) (RFC 5104). 35 // Temporary Maximum Media Stream Bit Rate Notification (TMMBN) (RFC 5104).
67 // 36 // The Feedback Control Information (FCI) consists of zero, one, or more
68 // FCI: 37 // TMMBN FCI entries.
69 //
70 // 0 1 2 3 38 // 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 39 // 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 40 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 // | SSRC | 41 // | SSRC |
74 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 // | MxTBR Exp | MxTBR Mantissa |Measured Overhead| 43 // | MxTBR Exp | MxTBR Mantissa |Measured Overhead|
76 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 44 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 bool Tmmbn::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
46 RTC_CHECK(header.packet_type == kPacketType);
47 RTC_CHECK(header.count_or_format == kFeedbackMessageType);
77 48
78 void CreateTmmbn(const RTCPPacketRTPFBTMMBN& tmmbn, 49 if (header.payload_size_bytes < kCommonFeedbackLength) {
79 const std::vector<RTCPPacketRTPFBTMMBRItem>& tmmbn_items, 50 LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
80 uint8_t* buffer, 51 << " is too small for TMMBN.";
81 size_t* pos) {
82 AssignUWord32(buffer, pos, tmmbn.SenderSSRC);
83 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0);
84 for (uint8_t i = 0; i < tmmbn_items.size(); ++i) {
85 CreateTmmbrItem(tmmbn_items[i], buffer, pos);
86 }
87 }
88 } // namespace
89
90 bool Tmmbn::WithTmmbr(uint32_t ssrc, uint32_t bitrate_kbps, uint16_t overhead) {
91 assert(overhead <= 0x1ff);
92 if (tmmbn_items_.size() >= kMaxNumberOfTmmbrs) {
93 LOG(LS_WARNING) << "Max TMMBN size reached.";
94 return false; 52 return false;
95 } 53 }
96 RTCPPacketRTPFBTMMBRItem tmmbn_item; 54 size_t items_size_bytes = header.payload_size_bytes - kCommonFeedbackLength;
97 tmmbn_item.SSRC = ssrc; 55 if (items_size_bytes % TmmbItem::kLength != 0) {
98 tmmbn_item.MaxTotalMediaBitRate = bitrate_kbps; 56 LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
99 tmmbn_item.MeasuredOverhead = overhead; 57 << " is not valid for TMMBN.";
100 tmmbn_items_.push_back(tmmbn_item); 58 return false;
59 }
60 ParseCommonFeedback(payload);
61 const uint8_t* next_item = payload + kCommonFeedbackLength;
62
63 size_t number_of_items = items_size_bytes / TmmbItem::kLength;
64 items_.resize(number_of_items);
65 for (TmmbItem& item : items_) {
66 item.Parse(next_item);
67 next_item += TmmbItem::kLength;
68 }
101 return true; 69 return true;
102 } 70 }
103 71
72 void Tmmbn::WithTmmbr(const TmmbItem& item) {
73 items_.push_back(item);
74 }
75
104 bool Tmmbn::Create(uint8_t* packet, 76 bool Tmmbn::Create(uint8_t* packet,
105 size_t* index, 77 size_t* index,
106 size_t max_length, 78 size_t max_length,
107 RtcpPacket::PacketReadyCallback* callback) const { 79 RtcpPacket::PacketReadyCallback* callback) const {
108 while (*index + BlockLength() > max_length) { 80 while (*index + BlockLength() > max_length) {
109 if (!OnBufferFull(packet, index, callback)) 81 if (!OnBufferFull(packet, index, callback))
110 return false; 82 return false;
111 } 83 }
112 const uint8_t kFmt = 4; 84 const size_t index_end = *index + BlockLength();
113 CreateHeader(kFmt, PT_RTPFB, HeaderLength(), packet, index); 85
114 CreateTmmbn(tmmbn_, tmmbn_items_, packet, index); 86 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
87 index);
88 RTC_DCHECK_EQ(0u, Rtpfb::media_ssrc());
89 CreateCommonFeedback(packet + *index);
90 *index += kCommonFeedbackLength;
91 for (const TmmbItem& item : items_) {
92 item.Create(packet + *index);
93 *index += TmmbItem::kLength;
94 }
95 RTC_CHECK_EQ(index_end, *index);
115 return true; 96 return true;
116 } 97 }
117
118 } // namespace rtcp 98 } // namespace rtcp
119 } // namespace webrtc 99 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698