diff --git a/src/modules/audio_coding/main/source/acm_neteq.cc b/src/modules/audio_coding/main/source/acm_neteq.cc index f41d4dff9..14afcd806 100644 --- a/src/modules/audio_coding/main/source/acm_neteq.cc +++ b/src/modules/audio_coding/main/source/acm_neteq.cc @@ -482,22 +482,31 @@ ACMNetEQ::NetworkStatistics( sort(waiting_times_vec.begin(), waiting_times_vec.end()); size_t size = waiting_times_vec.size(); assert(size == static_cast(waiting_times_len)); - if (size % 2 == 0) + if (size == 0) { - statistics->medianWaitingTimeMs = - (waiting_times_vec[size / 2 - 1] + - waiting_times_vec[size / 2]) / 2; + statistics->meanWaitingTimeMs = -1; + statistics->medianWaitingTimeMs = -1; + statistics->maxWaitingTimeMs = -1; } else { - statistics->medianWaitingTimeMs = waiting_times_vec[size / 2]; + if (size % 2 == 0) + { + statistics->medianWaitingTimeMs = + (waiting_times_vec[size / 2 - 1] + + waiting_times_vec[size / 2]) / 2; + } + else + { + statistics->medianWaitingTimeMs = waiting_times_vec[size / 2]; + } + statistics->maxWaitingTimeMs = waiting_times_vec.back(); + double sum = 0; + for (size_t i = 0; i < size; ++i) { + sum += waiting_times_vec[i]; + } + statistics->meanWaitingTimeMs = static_cast(sum / size); } - statistics->maxWaitingTimeMs = waiting_times_vec.back(); - double sum = 0; - for (size_t i = 0; i < size; ++i) { - sum += waiting_times_vec[i]; - } - statistics->meanWaitingTimeMs = static_cast(sum / size); } else { diff --git a/src/modules/audio_coding/main/source/acm_neteq_unittest.cc b/src/modules/audio_coding/main/source/acm_neteq_unittest.cc index dd05e84db..88029de33 100644 --- a/src/modules/audio_coding/main/source/acm_neteq_unittest.cc +++ b/src/modules/audio_coding/main/source/acm_neteq_unittest.cc @@ -111,10 +111,35 @@ TEST_F(AcmNetEqTest, NetworkStatistics) { EXPECT_EQ(0, stats.currentExpandRate); EXPECT_EQ(0, stats.currentPreemptiveRate); EXPECT_EQ(0, stats.currentAccelerateRate); - EXPECT_EQ(-916, stats.clockDriftPPM); + EXPECT_EQ(-916, stats.clockDriftPPM); // Initial value is slightly off. EXPECT_EQ(300, stats.maxWaitingTimeMs); EXPECT_EQ(159, stats.meanWaitingTimeMs); EXPECT_EQ(160, stats.medianWaitingTimeMs); } +TEST_F(AcmNetEqTest, TestZeroLengthWaitingTimesVector) { + // Insert one packet. + const int kSamples = 10 * 16; + const int kPayloadBytes = kSamples * 2; + int i = 0; + InsertZeroPacket(i, i * kSamples, kPcm16WbPayloadType, 0x1234, false, + kPayloadBytes); + // Do not pull out any data. + + ACMNetworkStatistics stats; + ASSERT_EQ(0, neteq_.NetworkStatistics(&stats)); + EXPECT_EQ(0, stats.currentBufferSize); + EXPECT_EQ(0, stats.preferredBufferSize); + EXPECT_FALSE(stats.jitterPeaksFound); + EXPECT_EQ(0, stats.currentPacketLossRate); + EXPECT_EQ(0, stats.currentDiscardRate); + EXPECT_EQ(0, stats.currentExpandRate); + EXPECT_EQ(0, stats.currentPreemptiveRate); + EXPECT_EQ(0, stats.currentAccelerateRate); + EXPECT_EQ(-916, stats.clockDriftPPM); // Initial value is slightly off. + EXPECT_EQ(-1, stats.maxWaitingTimeMs); + EXPECT_EQ(-1, stats.meanWaitingTimeMs); + EXPECT_EQ(-1, stats.medianWaitingTimeMs); +} + } // namespace diff --git a/src/modules/audio_coding/neteq/automode.c b/src/modules/audio_coding/neteq/automode.c index a38afacd4..da127e06b 100644 --- a/src/modules/audio_coding/neteq/automode.c +++ b/src/modules/audio_coding/neteq/automode.c @@ -729,7 +729,7 @@ int32_t WebRtcNetEQ_AverageIAT(const AutomodeInst_t *inst) { /* Subtract the nominal inter-arrival time 1 = 2^24 in Q24. */ sum_q24 -= (1 << 24); /* - * Multiply with 1000000 / 2^24 = 15625 / 2^18 to get the average. + * Multiply with 1000000 / 2^24 = 15625 / 2^18 to get in parts-per-million. * Shift 7 to Q17 first, then multiply with 15625 and shift another 11. */ return ((sum_q24 >> 7) * 15625) >> 11;