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/fir.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 Fir::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 : // Full intra request (FIR) (RFC 5104).
36 : // The Feedback Control Information (FCI) for the Full Intra Request
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 : // | Seq nr. | Reserved = 0 |
45 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 0 : bool Fir::Parse(const CommonHeader& packet) {
47 0 : RTC_DCHECK_EQ(packet.type(), kPacketType);
48 0 : RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
49 :
50 : // The FCI field MUST contain one or more FIR entries.
51 0 : if (packet.payload_size_bytes() < kCommonFeedbackLength + kFciLength) {
52 0 : LOG(LS_WARNING) << "Packet is too small to be a valid FIR packet.";
53 0 : return false;
54 : }
55 :
56 0 : if ((packet.payload_size_bytes() - kCommonFeedbackLength) % kFciLength != 0) {
57 0 : LOG(LS_WARNING) << "Invalid size for a valid FIR packet.";
58 0 : return false;
59 : }
60 :
61 0 : ParseCommonFeedback(packet.payload());
62 :
63 : size_t number_of_fci_items =
64 0 : (packet.payload_size_bytes() - kCommonFeedbackLength) / kFciLength;
65 0 : const uint8_t* next_fci = packet.payload() + kCommonFeedbackLength;
66 0 : items_.resize(number_of_fci_items);
67 0 : for (Request& request : items_) {
68 0 : request.ssrc = ByteReader<uint32_t>::ReadBigEndian(next_fci);
69 0 : request.seq_nr = ByteReader<uint8_t>::ReadBigEndian(next_fci + 4);
70 0 : next_fci += kFciLength;
71 : }
72 0 : return true;
73 : }
74 :
75 0 : bool Fir::Create(uint8_t* packet,
76 : size_t* index,
77 : size_t max_length,
78 : RtcpPacket::PacketReadyCallback* callback) const {
79 0 : RTC_DCHECK(!items_.empty());
80 0 : while (*index + BlockLength() > max_length) {
81 0 : if (!OnBufferFull(packet, index, callback))
82 0 : return false;
83 : }
84 0 : size_t index_end = *index + BlockLength();
85 0 : CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
86 0 : index);
87 0 : RTC_DCHECK_EQ(Psfb::media_ssrc(), 0);
88 0 : CreateCommonFeedback(packet + *index);
89 0 : *index += kCommonFeedbackLength;
90 :
91 0 : constexpr uint32_t kReserved = 0;
92 0 : for (const Request& request : items_) {
93 0 : ByteWriter<uint32_t>::WriteBigEndian(packet + *index, request.ssrc);
94 0 : ByteWriter<uint8_t>::WriteBigEndian(packet + *index + 4, request.seq_nr);
95 0 : ByteWriter<uint32_t, 3>::WriteBigEndian(packet + *index + 5, kReserved);
96 0 : *index += kFciLength;
97 : }
98 0 : RTC_CHECK_EQ(*index, index_end);
99 0 : return true;
100 : }
101 : } // namespace rtcp
102 : } // namespace webrtc
|