Line data Source code
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/tmmbr.h"
12 :
13 : #include "webrtc/base/checks.h"
14 : #include "webrtc/base/logging.h"
15 : #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16 : #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
17 :
18 : namespace webrtc {
19 : namespace rtcp {
20 : constexpr uint8_t Tmmbr::kFeedbackMessageType;
21 : // RFC 4585: Feedback format.
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 0 : bool Tmmbr::Parse(const CommonHeader& packet) {
47 0 : RTC_DCHECK_EQ(packet.type(), kPacketType);
48 0 : RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
49 :
50 0 : if (packet.payload_size_bytes() < kCommonFeedbackLength + TmmbItem::kLength) {
51 0 : LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
52 0 : << " is too small for a TMMBR.";
53 0 : return false;
54 : }
55 0 : size_t items_size_bytes = packet.payload_size_bytes() - kCommonFeedbackLength;
56 0 : if (items_size_bytes % TmmbItem::kLength != 0) {
57 0 : LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
58 0 : << " is not valid for a TMMBR.";
59 0 : return false;
60 : }
61 0 : ParseCommonFeedback(packet.payload());
62 :
63 0 : const uint8_t* next_item = packet.payload() + kCommonFeedbackLength;
64 0 : size_t number_of_items = items_size_bytes / TmmbItem::kLength;
65 0 : items_.resize(number_of_items);
66 0 : for (TmmbItem& item : items_) {
67 0 : if (!item.Parse(next_item))
68 0 : return false;
69 0 : next_item += TmmbItem::kLength;
70 : }
71 0 : return true;
72 : }
73 :
74 0 : void Tmmbr::AddTmmbr(const TmmbItem& item) {
75 0 : items_.push_back(item);
76 0 : }
77 :
78 0 : bool Tmmbr::Create(uint8_t* packet,
79 : size_t* index,
80 : size_t max_length,
81 : RtcpPacket::PacketReadyCallback* callback) const {
82 0 : RTC_DCHECK(!items_.empty());
83 0 : while (*index + BlockLength() > max_length) {
84 0 : if (!OnBufferFull(packet, index, callback))
85 0 : return false;
86 : }
87 0 : const size_t index_end = *index + BlockLength();
88 :
89 0 : CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
90 0 : index);
91 0 : RTC_DCHECK_EQ(0, Rtpfb::media_ssrc());
92 0 : CreateCommonFeedback(packet + *index);
93 0 : *index += kCommonFeedbackLength;
94 0 : for (const TmmbItem& item : items_) {
95 0 : item.Create(packet + *index);
96 0 : *index += TmmbItem::kLength;
97 : }
98 0 : RTC_CHECK_EQ(index_end, *index);
99 0 : return true;
100 : }
101 : } // namespace rtcp
102 : } // namespace webrtc
|