Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc |
| index 29cde65b1289b4151edaa030276176c55c009f5b..8d6900c9bd6e2770217def34ce42066e8cbc99a7 100644 |
| --- a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc |
| +++ b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc |
| @@ -17,7 +17,6 @@ |
| #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h" |
| -// RFC 5109 |
| namespace webrtc { |
| FecReceiver* FecReceiver::Create(RtpData* callback) { |
| @@ -25,18 +24,14 @@ FecReceiver* FecReceiver::Create(RtpData* callback) { |
| } |
| FecReceiverImpl::FecReceiverImpl(RtpData* callback) |
| - : recovered_packet_callback_(callback), |
| - fec_(new ForwardErrorCorrection()) {} |
| + : recovered_packet_callback_(callback) {} |
| FecReceiverImpl::~FecReceiverImpl() { |
| - while (!received_packet_list_.empty()) { |
| - delete received_packet_list_.front(); |
| - received_packet_list_.pop_front(); |
| - } |
| - if (fec_ != NULL) { |
| - fec_->ResetState(&recovered_packet_list_); |
| - delete fec_; |
| + while (!received_packets_.empty()) { |
| + delete received_packets_.front(); |
| + received_packets_.pop_front(); |
| } |
| + fec_.ResetState(&recovered_packets_); |
| } |
| FecPacketCounter FecReceiverImpl::GetPacketCounter() const { |
| @@ -76,7 +71,8 @@ int32_t FecReceiverImpl::AddReceivedRedPacket( |
| const RTPHeader& header, const uint8_t* incoming_rtp_packet, |
| size_t packet_length, uint8_t ulpfec_payload_type) { |
| rtc::CritScope cs(&crit_sect_); |
| - uint8_t REDHeaderLength = 1; |
| + |
| + uint8_t red_header_length = 1; |
| size_t payload_data_length = packet_length - header.headerLength; |
| if (payload_data_length == 0) { |
| @@ -84,31 +80,27 @@ int32_t FecReceiverImpl::AddReceivedRedPacket( |
| return -1; |
| } |
| - // Add to list without RED header, aka a virtual RTP packet |
| - // we remove the RED header |
| - |
| + // Remove RED header of incoming packet and store as a virtual RTP packet. |
| std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet( |
| new ForwardErrorCorrection::ReceivedPacket()); |
| received_packet->pkt = new ForwardErrorCorrection::Packet(); |
| - // get payload type from RED header |
| - uint8_t payload_type = |
| - incoming_rtp_packet[header.headerLength] & 0x7f; |
| - |
| + // Get payload type from RED header and sequence number from RTP header. |
| + uint8_t payload_type = incoming_rtp_packet[header.headerLength] & 0x7f; |
| received_packet->is_fec = payload_type == ulpfec_payload_type; |
| received_packet->seq_num = header.sequenceNumber; |
| - uint16_t blockLength = 0; |
| + uint16_t block_length = 0; |
| if (incoming_rtp_packet[header.headerLength] & 0x80) { |
| - // f bit set in RED header |
| - REDHeaderLength = 4; |
| - if (payload_data_length < REDHeaderLength + 1u) { |
| + // f bit set in RED header, i.e. there are more than one RED header blocks. |
| + red_header_length = 4; |
| + if (payload_data_length < red_header_length + 1u) { |
| LOG(LS_WARNING) << "Corrupt/truncated FEC packet."; |
| return -1; |
| } |
| uint16_t timestamp_offset = |
| - (incoming_rtp_packet[header.headerLength + 1]) << 8; |
| + incoming_rtp_packet[header.headerLength + 1] << 8; |
| timestamp_offset += |
| incoming_rtp_packet[header.headerLength + 2]; |
| timestamp_offset = timestamp_offset >> 2; |
| @@ -117,18 +109,17 @@ int32_t FecReceiverImpl::AddReceivedRedPacket( |
| return -1; |
| } |
| - blockLength = |
| - (0x03 & incoming_rtp_packet[header.headerLength + 2]) << 8; |
| - blockLength += (incoming_rtp_packet[header.headerLength + 3]); |
| + block_length = (0x3 & incoming_rtp_packet[header.headerLength + 2]) << 8; |
| + block_length += incoming_rtp_packet[header.headerLength + 3]; |
|
stefan-webrtc
2016/07/20 09:29:19
remove extra space after +=
brandtr
2016/07/21 09:03:58
Done.
|
| - // check next RED header |
| + // Check next RED header block. |
| if (incoming_rtp_packet[header.headerLength + 4] & 0x80) { |
| LOG(LS_WARNING) << "More than 2 blocks in packet not supported."; |
| return -1; |
| } |
| // Check that the packet is long enough to contain data in the following |
| // block. |
| - if (blockLength > payload_data_length - (REDHeaderLength + 1)) { |
| + if (block_length > payload_data_length - (red_header_length + 1)) { |
| LOG(LS_WARNING) << "Block length longer than packet."; |
| return -1; |
| } |
| @@ -137,92 +128,89 @@ int32_t FecReceiverImpl::AddReceivedRedPacket( |
| std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> |
| second_received_packet; |
| - if (blockLength > 0) { |
| - // handle block length, split into 2 packets |
| - REDHeaderLength = 5; |
| + if (block_length > 0) { |
| + // Handle block length, split into two packets. |
| + red_header_length = 5; |
| - // copy the RTP header |
| + // Copy RTP header. |
| memcpy(received_packet->pkt->data, incoming_rtp_packet, |
| header.headerLength); |
| - // replace the RED payload type |
| - received_packet->pkt->data[1] &= 0x80; // reset the payload |
| - received_packet->pkt->data[1] += |
| - payload_type; // set the media payload type |
| + // Set payload type. |
| + received_packet->pkt->data[1] &= 0x80; // reset RED payload type |
|
danilchap
2016/07/19 14:55:32
fix comment here and next line: Uppercase 1st lett
brandtr
2016/07/21 09:03:58
Done.
|
| + received_packet->pkt->data[1] += payload_type; // set media payload type |
| - // copy the payload data |
| + // Copy payload data. |
| memcpy( |
| received_packet->pkt->data + header.headerLength, |
| - incoming_rtp_packet + header.headerLength + REDHeaderLength, |
| - blockLength); |
| + incoming_rtp_packet + header.headerLength + red_header_length, |
| + block_length); |
| + received_packet->pkt->length = block_length; |
| - received_packet->pkt->length = blockLength; |
| - |
| - second_received_packet.reset(new ForwardErrorCorrection::ReceivedPacket()); |
| - second_received_packet->pkt = new ForwardErrorCorrection::Packet(); |
| + second_received_packet.reset(new ForwardErrorCorrection::ReceivedPacket); |
| + second_received_packet->pkt = new ForwardErrorCorrection::Packet; |
| second_received_packet->is_fec = true; |
| second_received_packet->seq_num = header.sequenceNumber; |
| ++packet_counter_.num_fec_packets; |
| - // copy the FEC payload data |
| + // Copy FEC payload data. |
| memcpy(second_received_packet->pkt->data, |
| incoming_rtp_packet + header.headerLength + |
| - REDHeaderLength + blockLength, |
| - payload_data_length - REDHeaderLength - blockLength); |
| + red_header_length + block_length, |
| + payload_data_length - red_header_length - block_length); |
| second_received_packet->pkt->length = |
| - payload_data_length - REDHeaderLength - blockLength; |
| + payload_data_length - red_header_length - block_length; |
| } else if (received_packet->is_fec) { |
| ++packet_counter_.num_fec_packets; |
| // everything behind the RED header |
| memcpy( |
| received_packet->pkt->data, |
| - incoming_rtp_packet + header.headerLength + REDHeaderLength, |
| - payload_data_length - REDHeaderLength); |
| - received_packet->pkt->length = payload_data_length - REDHeaderLength; |
| + incoming_rtp_packet + header.headerLength + red_header_length, |
| + payload_data_length - red_header_length); |
| + received_packet->pkt->length = payload_data_length - red_header_length; |
| received_packet->ssrc = |
| ByteReader<uint32_t>::ReadBigEndian(&incoming_rtp_packet[8]); |
| } else { |
| - // copy the RTP header |
| - memcpy(received_packet->pkt->data, incoming_rtp_packet, |
| + // Copy RTP header. |
| + memcpy(received_packet->pkt->data, |
| + incoming_rtp_packet, |
| header.headerLength); |
| - // replace the RED payload type |
| - received_packet->pkt->data[1] &= 0x80; // reset the payload |
| - received_packet->pkt->data[1] += |
| - payload_type; // set the media payload type |
| + // Set payload type. |
| + received_packet->pkt->data[1] &= 0x80; // reset RED payload type |
|
danilchap
2016/07/19 14:55:32
fix this 2 comments too.
brandtr
2016/07/21 09:03:58
Done.
|
| + received_packet->pkt->data[1] += payload_type; // set media payload type |
| - // copy the media payload data |
| + // Copy payload data. |
| memcpy( |
| received_packet->pkt->data + header.headerLength, |
| - incoming_rtp_packet + header.headerLength + REDHeaderLength, |
| - payload_data_length - REDHeaderLength); |
| - |
| + incoming_rtp_packet + header.headerLength + red_header_length, |
| + payload_data_length - red_header_length); |
| received_packet->pkt->length = |
| - header.headerLength + payload_data_length - REDHeaderLength; |
| + header.headerLength + payload_data_length - red_header_length; |
| } |
| if (received_packet->pkt->length == 0) { |
| return 0; |
| } |
| - received_packet_list_.push_back(received_packet.release()); |
| + received_packets_.push_back(received_packet.release()); |
| if (second_received_packet) { |
| - received_packet_list_.push_back(second_received_packet.release()); |
| + received_packets_.push_back(second_received_packet.release()); |
| } |
| return 0; |
| } |
| int32_t FecReceiverImpl::ProcessReceivedFec() { |
| crit_sect_.Enter(); |
| - if (!received_packet_list_.empty()) { |
| + if (!received_packets_.empty()) { |
| // Send received media packet to VCM. |
| - if (!received_packet_list_.front()->is_fec) { |
| + if (!received_packets_.front()->is_fec) { |
| ForwardErrorCorrection::Packet* packet = |
| - received_packet_list_.front()->pkt; |
| + received_packets_.front()->pkt; |
| crit_sect_.Leave(); |
| if (!recovered_packet_callback_->OnRecoveredPacket(packet->data, |
| packet->length)) { |
| @@ -230,14 +218,14 @@ int32_t FecReceiverImpl::ProcessReceivedFec() { |
| } |
| crit_sect_.Enter(); |
| } |
| - if (fec_->DecodeFec(&received_packet_list_, &recovered_packet_list_) != 0) { |
| + if (fec_.DecodeFec(&received_packets_, &recovered_packets_) != 0) { |
| crit_sect_.Leave(); |
| return -1; |
| } |
| - RTC_DCHECK(received_packet_list_.empty()); |
| + RTC_DCHECK(received_packets_.empty()); |
| } |
| // Send any recovered media packets to VCM. |
| - for(auto* recovered_packet : recovered_packet_list_) { |
| + for (auto* recovered_packet : recovered_packets_) { |
| if (recovered_packet->returned) { |
| // Already sent to the VCM and the jitter buffer. |
| continue; |