From f81170b48fd43fa4463d5cddd2815aaae6f30217 Mon Sep 17 00:00:00 2001 From: Per Kjellander Date: Thu, 11 Oct 2018 13:06:15 +0200 Subject: [PATCH] Add error logs to RtpPacketHistory::GetBestFittingPacket when no packet is found. Make sure nullptr is returned if the packet is not in history. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:9863 Change-Id: I9658b1b271071a4bd38f062ed68c60cc04c63123 Reviewed-on: https://webrtc-review.googlesource.com/c/105300 Commit-Queue: Erik Språng Reviewed-by: Erik Språng Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#25114} --- modules/rtp_rtcp/source/rtp_packet_history.cc | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/rtp_rtcp/source/rtp_packet_history.cc b/modules/rtp_rtcp/source/rtp_packet_history.cc index e1374feb57..211077bf36 100644 --- a/modules/rtp_rtcp/source/rtp_packet_history.cc +++ b/modules/rtp_rtcp/source/rtp_packet_history.cc @@ -97,6 +97,15 @@ void RtpPacketHistory::PutRtpPacket(std::unique_ptr packet, const uint16_t rtp_seq_no = packet->SequenceNumber(); StoredPacket& stored_packet = packet_history_[rtp_seq_no]; RTC_DCHECK(stored_packet.packet == nullptr); + if (stored_packet.packet) { + // It is an error if this happen. But it can happen if the sequence numbers + // for some reason restart without that the history has been reset. + auto size_iterator = packet_size_.find(stored_packet.packet->size()); + if (size_iterator != packet_size_.end() && + size_iterator->second == stored_packet.packet->SequenceNumber()) { + packet_size_.erase(size_iterator); + } + } stored_packet.packet = std::move(packet); if (stored_packet.packet->capture_time_ms() <= 0) { @@ -209,8 +218,19 @@ std::unique_ptr RtpPacketHistory::GetBestFittingPacket( const uint16_t seq_no = upper_bound_diff < lower_bound_diff ? size_iter_upper->second : size_iter_lower->second; - RtpPacketToSend* best_packet = - packet_history_.find(seq_no)->second.packet.get(); + auto history_it = packet_history_.find(seq_no); + if (history_it == packet_history_.end()) { + RTC_LOG(LS_ERROR) << "Can't find packet in history with seq_no" << seq_no; + RTC_DCHECK(false); + return nullptr; + } + if (!history_it->second.packet) { + RTC_LOG(LS_ERROR) << "Packet pointer is null in history for seq_no" + << seq_no; + RTC_DCHECK(false); + return nullptr; + } + RtpPacketToSend* best_packet = history_it->second.packet.get(); return absl::make_unique(*best_packet); }