From 6ff3ac1db8b357e50cd6631e3f7cb0caf2aff986 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Thu, 20 Nov 2014 14:14:49 +0000 Subject: [PATCH] Fix problems if first packet into NetEq is rejected This CL fixes the problem described in issue 4021. In summary, of the very first packet coming in to NetEq gets rejected because the RTP payload type is unknown, subsequent GetAudio calls would trigger asserts (in debug builds). The problem was that the first_packet_ variable was reset and new_codec_ was set, even though the packet was discarded further down the line. Now, these variables are modified after the packet has been verified. BUG=4021 R=tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/29089004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7724 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/neteq/neteq_impl.cc | 16 +++++++++++----- .../audio_coding/neteq/neteq_impl_unittest.cc | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc index f3d1a4f6b8..7e8af3c9b7 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -458,8 +458,10 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, bool update_sample_rate_and_channels = false; // Reinitialize NetEq if it's needed (changed SSRC or first call). if ((main_header.ssrc != ssrc_) || first_packet_) { + // Note: |first_packet_| will be cleared further down in this method, once + // the packet has been successfully inserted into the packet buffer. + rtcp_.Init(main_header.sequenceNumber); - first_packet_ = false; // Flush the packet buffer and DTMF buffer. packet_buffer_->Flush(); @@ -475,13 +477,10 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, timestamp_ = main_header.timestamp; current_rtp_payload_type_ = main_header.payloadType; - // Set MCU to update codec on next SignalMCU call. - new_codec_ = true; - // Reset timestamp scaling. timestamp_scaler_->Reset(); - // Triger an update of sampling rate and the number of channels. + // Trigger an update of sampling rate and the number of channels. update_sample_rate_and_channels = true; } @@ -612,6 +611,13 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, PacketBuffer::DeleteAllPackets(&packet_list); return kOtherError; } + + if (first_packet_) { + first_packet_ = false; + // Update the codec on the next GetAudio call. + new_codec_ = true; + } + if (current_rtp_payload_type_ != 0xFF) { const DecoderDatabase::DecoderInfo* dec_info = decoder_database_->GetDecoderInfo(current_rtp_payload_type_); diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc index efe122cc48..56ea425441 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc @@ -589,8 +589,7 @@ TEST_F(NetEqImplTest, ReorderedPacket) { // This test verifies that NetEq can handle the situation where the first // incoming packet is rejected. -// Disabled due to https://code.google.com/p/webrtc/issues/detail?id=4021. -TEST_F(NetEqImplTest, DISABLED_FirstPacketUnknown) { +TEST_F(NetEqImplTest, FirstPacketUnknown) { UseNoMocks(); CreateInstance();