Fixing Issue 218
Taking care of the case when the raw waiting times vector from NetEQ is zero length. Also adding a new unittest to cover this case. BUG=http://code.google.com/p/webrtc/issues/detail?id=218 TEST=AcmNetEqTest.TestZeroLengthWaitingTimesVector Review URL: http://webrtc-codereview.appspot.com/349003 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1370 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
caf39f335f
commit
d4e8c0b3ff
@ -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<size_t>(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<int>(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<int>(sum / size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user