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

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

Issue 1544403002: [rtp_rtcp] rtcp::Fir cleaned and got Parse function. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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/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;
25
26 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) {
27 buffer[(*offset)++] = value;
28 }
29
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). 22 // Full intra request (FIR) (RFC 5104).
åsapersson 2016/01/21 16:04:35 Move this comment to after line 36.
danilchap 2016/01/21 16:48:12 Done.
41 // 23 //
24 // Common packet format:
25 //
26 // 0 1 2 3
27 // 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
28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 // |V=2|P| FMT | PT | length |
30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 // | SSRC of packet sender |
32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 // | SSRC of media source (unused) = 0 |
34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 // : Feedback Control Information (FCI) :
36 // : :
37 // The Feedback Control Information (FCI) for the Full Intra Request
38 // consists of one or more FCI entries.
42 // FCI: 39 // FCI:
43 // 40 // 0 1 2 3
44 // 0 1 2 3 41 // 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
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 42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 43 // | SSRC |
47 // | SSRC | 44 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 45 // | Seq nr. | Reserved = 0 |
49 // | Seq nr. | Reserved | 46 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47 bool Fir::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
51 void CreateFir(const RTCPPacketPSFBFIR& fir, 48 RTC_CHECK(header.packet_type == kPacketType);
52 const RTCPPacketPSFBFIRItem& fir_item, 49 RTC_CHECK(header.count_or_format == kFeedbackMessageType);
53 uint8_t* buffer, 50
54 size_t* pos) { 51 // The FCI field MUST contain one or more FIR entries.
55 AssignUWord32(buffer, pos, fir.SenderSSRC); 52 if (header.payload_size_bytes < kCommonFeedbackLength + kFciLength) {
56 AssignUWord32(buffer, pos, kUnusedMediaSourceSsrc0); 53 LOG(LS_WARNING) << "Packet is too small to be a valid FIR packet.";
57 AssignUWord32(buffer, pos, fir_item.SSRC); 54 return false;
58 AssignUWord8(buffer, pos, fir_item.CommandSequenceNumber); 55 }
59 AssignUWord24(buffer, pos, 0); 56
57 if ((header.payload_size_bytes - kCommonFeedbackLength) % kFciLength != 0) {
58 LOG(LS_WARNING) << "Invalid size for a valid FIR packet.";
59 return false;
60 }
61
62 ParseCommonFeedback(payload);
63
64 size_t number_of_fci_items =
65 (header.payload_size_bytes - kCommonFeedbackLength) / kFciLength;
66 const uint8_t* next_fci = payload + kCommonFeedbackLength;
67 items_.resize(number_of_fci_items);
68 for (Request& request : items_) {
69 request.ssrc = ByteReader<uint32_t>::ReadBigEndian(next_fci);
70 request.seq_nr = ByteReader<uint8_t>::ReadBigEndian(next_fci + 4);
71 next_fci += kFciLength;
72 }
73 return true;
60 } 74 }
61 } // namespace
62 75
63 bool Fir::Create(uint8_t* packet, 76 bool Fir::Create(uint8_t* packet,
64 size_t* index, 77 size_t* index,
65 size_t max_length, 78 size_t max_length,
66 RtcpPacket::PacketReadyCallback* callback) const { 79 RtcpPacket::PacketReadyCallback* callback) const {
80 RTC_CHECK(!items_.empty());
åsapersson 2016/01/21 16:04:35 maybe use DCHECK?
danilchap 2016/01/21 16:48:12 agree DCHECK is better: this line is more a docume
67 while (*index + BlockLength() > max_length) { 81 while (*index + BlockLength() > max_length) {
68 if (!OnBufferFull(packet, index, callback)) 82 if (!OnBufferFull(packet, index, callback))
69 return false; 83 return false;
70 } 84 }
71 const uint8_t kFmt = 4; 85 size_t index_end = *index + BlockLength();
72 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); 86 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
73 CreateFir(fir_, fir_item_, packet, index); 87 index);
88 RTC_CHECK_EQ(Psfb::media_ssrc(), 0u);
åsapersson 2016/01/21 16:04:35 ditto
danilchap 2016/01/21 16:48:12 Done.
89 CreateCommonFeedback(packet + *index);
90 *index += kCommonFeedbackLength;
91
92 const uint32_t kReserved = 0;
93 for (const Request& request : items_) {
94 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, request.ssrc);
95 ByteWriter<uint8_t>::WriteBigEndian(packet + *index + 4, request.seq_nr);
96 ByteWriter<uint32_t, 3>::WriteBigEndian(packet + *index + 5, kReserved);
97 *index += kFciLength;
98 }
99 RTC_CHECK_EQ(*index, index_end);
åsapersson 2016/01/21 16:04:35 ditto
danilchap 2016/01/21 16:48:12 if *index != index_end I would rather crash right
74 return true; 100 return true;
75 } 101 }
76
77 } // namespace rtcp 102 } // namespace rtcp
78 } // namespace webrtc 103 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698