OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/ulpfec_receiver_impl.h" | 11 #include "webrtc/modules/rtp_rtcp/source/ulpfec_receiver_impl.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h" | 19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h" |
20 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 UlpfecReceiver* UlpfecReceiver::Create(RecoveredPacketReceiver* callback) { | 24 UlpfecReceiver* UlpfecReceiver::Create(uint32_t ssrc, |
25 return new UlpfecReceiverImpl(callback); | 25 RecoveredPacketReceiver* callback) { |
26 return new UlpfecReceiverImpl(ssrc, callback); | |
26 } | 27 } |
27 | 28 |
28 UlpfecReceiverImpl::UlpfecReceiverImpl(RecoveredPacketReceiver* callback) | 29 UlpfecReceiverImpl::UlpfecReceiverImpl(uint32_t ssrc, |
29 : recovered_packet_callback_(callback), | 30 RecoveredPacketReceiver* callback) |
30 fec_(ForwardErrorCorrection::CreateUlpfec()) {} | 31 : ssrc_(ssrc), |
32 recovered_packet_callback_(callback), | |
33 fec_(ForwardErrorCorrection::CreateUlpfec(ssrc_)) {} | |
31 | 34 |
32 UlpfecReceiverImpl::~UlpfecReceiverImpl() { | 35 UlpfecReceiverImpl::~UlpfecReceiverImpl() { |
33 received_packets_.clear(); | 36 received_packets_.clear(); |
34 fec_->ResetState(&recovered_packets_); | 37 fec_->ResetState(&recovered_packets_); |
35 } | 38 } |
36 | 39 |
37 FecPacketCounter UlpfecReceiverImpl::GetPacketCounter() const { | 40 FecPacketCounter UlpfecReceiverImpl::GetPacketCounter() const { |
38 rtc::CritScope cs(&crit_sect_); | 41 rtc::CritScope cs(&crit_sect_); |
39 return packet_counter_; | 42 return packet_counter_; |
40 } | 43 } |
(...skipping 24 matching lines...) Expand all Loading... | |
65 // block is the redundancy. | 68 // block is the redundancy. |
66 // | 69 // |
67 // block length: 10 bits Length in bytes of the corresponding data | 70 // block length: 10 bits Length in bytes of the corresponding data |
68 // block excluding header. | 71 // block excluding header. |
69 | 72 |
70 int32_t UlpfecReceiverImpl::AddReceivedRedPacket( | 73 int32_t UlpfecReceiverImpl::AddReceivedRedPacket( |
71 const RTPHeader& header, | 74 const RTPHeader& header, |
72 const uint8_t* incoming_rtp_packet, | 75 const uint8_t* incoming_rtp_packet, |
73 size_t packet_length, | 76 size_t packet_length, |
74 uint8_t ulpfec_payload_type) { | 77 uint8_t ulpfec_payload_type) { |
78 if (header.ssrc != ssrc_) { | |
79 LOG(LS_INFO) | |
holmer
2017/06/28 13:53:06
Should this be a warning?
brandtr_google
2017/06/28 14:01:56
I was thinking that could be a bit spammy. If we r
holmer
2017/06/29 10:50:11
But we don't expect to ever do that, right? I'd wa
brandtr
2017/06/30 08:24:40
Right, this should never happen. Updating the logg
| |
80 << "Received RED packet with different SSRC than expected; dropping."; | |
81 return -1; | |
82 } | |
83 | |
75 rtc::CritScope cs(&crit_sect_); | 84 rtc::CritScope cs(&crit_sect_); |
76 | 85 |
77 uint8_t red_header_length = 1; | 86 uint8_t red_header_length = 1; |
78 size_t payload_data_length = packet_length - header.headerLength; | 87 size_t payload_data_length = packet_length - header.headerLength; |
79 | 88 |
80 if (payload_data_length == 0) { | 89 if (payload_data_length == 0) { |
81 LOG(LS_WARNING) << "Corrupt/truncated FEC packet."; | 90 LOG(LS_WARNING) << "Corrupt/truncated FEC packet."; |
82 return -1; | 91 return -1; |
83 } | 92 } |
84 | 93 |
85 // Remove RED header of incoming packet and store as a virtual RTP packet. | 94 // Remove RED header of incoming packet and store as a virtual RTP packet. |
86 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet( | 95 std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet( |
87 new ForwardErrorCorrection::ReceivedPacket()); | 96 new ForwardErrorCorrection::ReceivedPacket()); |
88 received_packet->pkt = new ForwardErrorCorrection::Packet(); | 97 received_packet->pkt = new ForwardErrorCorrection::Packet(); |
89 | 98 |
90 // Get payload type from RED header and sequence number from RTP header. | 99 // Get payload type from RED header and sequence number from RTP header. |
91 uint8_t payload_type = incoming_rtp_packet[header.headerLength] & 0x7f; | 100 uint8_t payload_type = incoming_rtp_packet[header.headerLength] & 0x7f; |
92 received_packet->is_fec = payload_type == ulpfec_payload_type; | 101 received_packet->is_fec = payload_type == ulpfec_payload_type; |
102 received_packet->ssrc = header.ssrc; | |
93 received_packet->seq_num = header.sequenceNumber; | 103 received_packet->seq_num = header.sequenceNumber; |
94 | 104 |
95 uint16_t block_length = 0; | 105 uint16_t block_length = 0; |
96 if (incoming_rtp_packet[header.headerLength] & 0x80) { | 106 if (incoming_rtp_packet[header.headerLength] & 0x80) { |
97 // f bit set in RED header, i.e. there are more than one RED header blocks. | 107 // f bit set in RED header, i.e. there are more than one RED header blocks. |
98 red_header_length = 4; | 108 red_header_length = 4; |
99 if (payload_data_length < red_header_length + 1u) { | 109 if (payload_data_length < red_header_length + 1u) { |
100 LOG(LS_WARNING) << "Corrupt/truncated FEC packet."; | 110 LOG(LS_WARNING) << "Corrupt/truncated FEC packet."; |
101 return -1; | 111 return -1; |
102 } | 112 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 // Copy payload data. | 158 // Copy payload data. |
149 memcpy(received_packet->pkt->data + header.headerLength, | 159 memcpy(received_packet->pkt->data + header.headerLength, |
150 incoming_rtp_packet + header.headerLength + red_header_length, | 160 incoming_rtp_packet + header.headerLength + red_header_length, |
151 block_length); | 161 block_length); |
152 received_packet->pkt->length = block_length; | 162 received_packet->pkt->length = block_length; |
153 | 163 |
154 second_received_packet.reset(new ForwardErrorCorrection::ReceivedPacket); | 164 second_received_packet.reset(new ForwardErrorCorrection::ReceivedPacket); |
155 second_received_packet->pkt = new ForwardErrorCorrection::Packet; | 165 second_received_packet->pkt = new ForwardErrorCorrection::Packet; |
156 | 166 |
157 second_received_packet->is_fec = true; | 167 second_received_packet->is_fec = true; |
168 second_received_packet->ssrc = header.ssrc; | |
158 second_received_packet->seq_num = header.sequenceNumber; | 169 second_received_packet->seq_num = header.sequenceNumber; |
159 ++packet_counter_.num_fec_packets; | 170 ++packet_counter_.num_fec_packets; |
160 | 171 |
161 // Copy FEC payload data. | 172 // Copy FEC payload data. |
162 memcpy(second_received_packet->pkt->data, | 173 memcpy(second_received_packet->pkt->data, |
163 incoming_rtp_packet + header.headerLength + red_header_length + | 174 incoming_rtp_packet + header.headerLength + red_header_length + |
164 block_length, | 175 block_length, |
165 payload_data_length - red_header_length - block_length); | 176 payload_data_length - red_header_length - block_length); |
166 | 177 |
167 second_received_packet->pkt->length = | 178 second_received_packet->pkt->length = |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 recovered_packet_callback_->OnRecoveredPacket(packet->data, | 245 recovered_packet_callback_->OnRecoveredPacket(packet->data, |
235 packet->length); | 246 packet->length); |
236 crit_sect_.Enter(); | 247 crit_sect_.Enter(); |
237 recovered_packet->returned = true; | 248 recovered_packet->returned = true; |
238 } | 249 } |
239 crit_sect_.Leave(); | 250 crit_sect_.Leave(); |
240 return 0; | 251 return 0; |
241 } | 252 } |
242 | 253 |
243 } // namespace webrtc | 254 } // namespace webrtc |
OLD | NEW |