OLD | NEW |
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/fir.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
16 | 16 |
17 using webrtc::RTCPUtility::PT_PSFB; | 17 using webrtc::RTCPUtility::RtcpCommonHeader; |
18 using webrtc::RTCPUtility::RTCPPacketPSFBFIR; | |
19 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem; | |
20 | 18 |
21 namespace webrtc { | 19 namespace webrtc { |
22 namespace rtcp { | 20 namespace rtcp { |
23 namespace { | 21 // RFC 4585: Feedback format. |
24 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 // 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 bool Fir::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { |
| 47 RTC_CHECK(header.packet_type == kPacketType); |
| 48 RTC_CHECK(header.count_or_format == kFeedbackMessageType); |
25 | 49 |
26 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { | 50 // The FCI field MUST contain one or more FIR entries. |
27 buffer[(*offset)++] = value; | 51 if (header.payload_size_bytes < kCommonFeedbackLength + kFciLength) { |
| 52 LOG(LS_WARNING) << "Packet is too small to be a valid FIR packet."; |
| 53 return false; |
| 54 } |
| 55 |
| 56 if ((header.payload_size_bytes - kCommonFeedbackLength) % kFciLength != 0) { |
| 57 LOG(LS_WARNING) << "Invalid size for a valid FIR packet."; |
| 58 return false; |
| 59 } |
| 60 |
| 61 ParseCommonFeedback(payload); |
| 62 |
| 63 size_t number_of_fci_items = |
| 64 (header.payload_size_bytes - kCommonFeedbackLength) / kFciLength; |
| 65 const uint8_t* next_fci = payload + kCommonFeedbackLength; |
| 66 items_.resize(number_of_fci_items); |
| 67 for (Request& request : items_) { |
| 68 request.ssrc = ByteReader<uint32_t>::ReadBigEndian(next_fci); |
| 69 request.seq_nr = ByteReader<uint8_t>::ReadBigEndian(next_fci + 4); |
| 70 next_fci += kFciLength; |
| 71 } |
| 72 return true; |
28 } | 73 } |
29 | 74 |
30 void AssignUWord24(uint8_t* buffer, size_t* offset, uint32_t value) { | |
31 ByteWriter<uint32_t, 3>::WriteBigEndian(buffer + *offset, value); | |
32 *offset += 3; | |
33 } | |
34 | |
35 void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { | |
36 ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value); | |
37 *offset += 4; | |
38 } | |
39 | |
40 // Full intra request (FIR) (RFC 5104). | |
41 // | |
42 // FCI: | |
43 // | |
44 // 0 1 2 3 | |
45 // 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 | |
46 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
47 // | SSRC | | |
48 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
49 // | Seq nr. | Reserved | | |
50 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
51 void CreateFir(const RTCPPacketPSFBFIR& fir, | |
52 const RTCPPacketPSFBFIRItem& fir_item, | |
53 uint8_t* buffer, | |
54 size_t* pos) { | |
55 AssignUWord32(buffer, pos, fir.SenderSSRC); | |
56 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0); | |
57 AssignUWord32(buffer, pos, fir_item.SSRC); | |
58 AssignUWord8(buffer, pos, fir_item.CommandSequenceNumber); | |
59 AssignUWord24(buffer, pos, 0); | |
60 } | |
61 } // namespace | |
62 | |
63 bool Fir::Create(uint8_t* packet, | 75 bool Fir::Create(uint8_t* packet, |
64 size_t* index, | 76 size_t* index, |
65 size_t max_length, | 77 size_t max_length, |
66 RtcpPacket::PacketReadyCallback* callback) const { | 78 RtcpPacket::PacketReadyCallback* callback) const { |
| 79 RTC_DCHECK(!items_.empty()); |
67 while (*index + BlockLength() > max_length) { | 80 while (*index + BlockLength() > max_length) { |
68 if (!OnBufferFull(packet, index, callback)) | 81 if (!OnBufferFull(packet, index, callback)) |
69 return false; | 82 return false; |
70 } | 83 } |
71 const uint8_t kFmt = 4; | 84 size_t index_end = *index + BlockLength(); |
72 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); | 85 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, |
73 CreateFir(fir_, fir_item_, packet, index); | 86 index); |
| 87 RTC_DCHECK_EQ(Psfb::media_ssrc(), 0u); |
| 88 CreateCommonFeedback(packet + *index); |
| 89 *index += kCommonFeedbackLength; |
| 90 |
| 91 const uint32_t kReserved = 0; |
| 92 for (const Request& request : items_) { |
| 93 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, request.ssrc); |
| 94 ByteWriter<uint8_t>::WriteBigEndian(packet + *index + 4, request.seq_nr); |
| 95 ByteWriter<uint32_t, 3>::WriteBigEndian(packet + *index + 5, kReserved); |
| 96 *index += kFciLength; |
| 97 } |
| 98 RTC_CHECK_EQ(*index, index_end); |
74 return true; | 99 return true; |
75 } | 100 } |
76 | |
77 } // namespace rtcp | 101 } // namespace rtcp |
78 } // namespace webrtc | 102 } // namespace webrtc |
OLD | NEW |