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

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

Issue 1675583002: [rtp_rtcp] rtcp::Tmmbr cleaned and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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/tmmbr.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.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::RTCPPacketRTPFBTMMBR;
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:
23 //
24 // 0 1 2 3
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
26 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 // |V=2|P| FMT | PT | length |
28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 // | SSRC of packet sender |
30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 // | SSRC of media source (unused) = 0 |
32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 // : Feedback Control Information (FCI) :
34 // : :
35 // Temporary Maximum Media Stream Bit Rate Request (TMMBR) (RFC 5104).
36 // The Feedback Control Information (FCI) for the TMMBR
37 // consists of one or more FCI entries.
38 // FCI:
39 // 0 1 2 3
40 // 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
41 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 // | SSRC |
43 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 // | MxTBR Exp | MxTBR Mantissa |Measured Overhead|
45 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 bool Tmmbr::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
47 RTC_CHECK(header.packet_type == kPacketType);
48 RTC_CHECK(header.count_or_format == kFeedbackMessageType);
24 49
25 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { 50 if (header.payload_size_bytes < kCommonFeedbackLength + TmmbItem::kLength) {
26 buffer[(*offset)++] = value; 51 LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
52 << " is too small for a TMMBR.";
53 return false;
54 }
55 size_t items_size_bytes = header.payload_size_bytes - kCommonFeedbackLength;
56 if (items_size_bytes % TmmbItem::kLength != 0) {
57 LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
58 << " is not valid for a TMMBR.";
59 return false;
60 }
61 ParseCommonFeedback(payload);
62
63 const uint8_t* next_item = payload + kCommonFeedbackLength;
64 size_t number_of_items = items_size_bytes / TmmbItem::kLength;
65 items_.resize(number_of_items);
66 for (TmmbItem& item : items_) {
67 item.Parse(next_item);
68 next_item += TmmbItem::kLength;
69 }
70 return true;
27 } 71 }
28 72
29 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { 73 void Tmmbr::WithTmmbr(const TmmbItem& item) {
30 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value); 74 items_.push_back(item);
31 *offset += 4;
32 } 75 }
33 76
34 void ComputeMantissaAnd6bitBase2Exponent(uint32_t input_base10,
35 uint8_t bits_mantissa,
36 uint32_t* mantissa,
37 uint8_t* exp) {
38 // input_base10 = mantissa * 2^exp
39 assert(bits_mantissa <= 32);
40 uint32_t mantissa_max = (1 << bits_mantissa) - 1;
41 uint8_t exponent = 0;
42 for (uint32_t i = 0; i < 64; ++i) {
43 if (input_base10 <= (mantissa_max << i)) {
44 exponent = i;
45 break;
46 }
47 }
48 *exp = exponent;
49 *mantissa = (input_base10 >> exponent);
50 }
51
52 void CreateTmmbrItem(const RTCPPacketRTPFBTMMBRItem& tmmbr_item,
53 uint8_t* buffer,
54 size_t* pos) {
55 uint32_t bitrate_bps = tmmbr_item.MaxTotalMediaBitRate * 1000;
56 uint32_t mantissa = 0;
57 uint8_t exp = 0;
58 ComputeMantissaAnd6bitBase2Exponent(bitrate_bps, 17, &mantissa, &exp);
59
60 AssignUWord32(buffer, pos, tmmbr_item.SSRC);
61 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 15) & 0x03));
62 AssignUWord8(buffer, pos, mantissa >> 7);
63 AssignUWord8(buffer, pos, (mantissa << 1) +
64 ((tmmbr_item.MeasuredOverhead >> 8) & 0x01));
65 AssignUWord8(buffer, pos, tmmbr_item.MeasuredOverhead);
66 }
67
68 // Temporary Maximum Media Stream Bit Rate Request (TMMBR) (RFC 5104).
69 //
70 // FCI:
71 //
72 // 0 1 2 3
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
74 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 // | SSRC |
76 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 // | MxTBR Exp | MxTBR Mantissa |Measured Overhead|
78 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79
80 void CreateTmmbr(const RTCPPacketRTPFBTMMBR& tmmbr,
81 const RTCPPacketRTPFBTMMBRItem& tmmbr_item,
82 uint8_t* buffer,
83 size_t* pos) {
84 AssignUWord32(buffer, pos, tmmbr.SenderSSRC);
85 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0);
86 CreateTmmbrItem(tmmbr_item, buffer, pos);
87 }
88 } // namespace
89
90 bool Tmmbr::Create(uint8_t* packet, 77 bool Tmmbr::Create(uint8_t* packet,
91 size_t* index, 78 size_t* index,
92 size_t max_length, 79 size_t max_length,
93 RtcpPacket::PacketReadyCallback* callback) const { 80 RtcpPacket::PacketReadyCallback* callback) const {
81 RTC_DCHECK(!items_.empty());
94 while (*index + BlockLength() > max_length) { 82 while (*index + BlockLength() > max_length) {
95 if (!OnBufferFull(packet, index, callback)) 83 if (!OnBufferFull(packet, index, callback))
96 return false; 84 return false;
97 } 85 }
98 const uint8_t kFmt = 3; 86 const size_t index_end = *index + BlockLength();
99 CreateHeader(kFmt, PT_RTPFB, HeaderLength(), packet, index); 87
100 CreateTmmbr(tmmbr_, tmmbr_item_, packet, index); 88 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
89 index);
90 RTC_DCHECK_EQ(0u, Rtpfb::media_ssrc());
91 CreateCommonFeedback(packet + *index);
92 *index += kCommonFeedbackLength;
93 for (const TmmbItem& item : items_) {
94 item.Create(packet + *index);
95 *index += TmmbItem::kLength;
96 }
97 RTC_CHECK_EQ(index_end, *index);
101 return true; 98 return true;
102 } 99 }
103
104 } // namespace rtcp 100 } // namespace rtcp
105 } // namespace webrtc 101 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698