@@ -320,32 +320,37 @@ class StatsJitter: public Base,
320320
321321 const auto irrelevant_rtp = new RTCInboundRtpStreamStats (" irrelevantRtpId" , Timestamp::Zero ());
322322 irrelevant_rtp->kind = " irrelevant" ;
323- irrelevant_rtp->jitter = 1.0 ;
323+ irrelevant_rtp->jitter = 1 ;
324+ irrelevant_rtp->packets_received = 1 ;
324325 report->AddStats (std::unique_ptr<RTCStats>(irrelevant_rtp));
325326
326327 const auto audio_rtp = new RTCInboundRtpStreamStats (" someAudioRtpId" , Timestamp::Zero ());
327328 audio_rtp->kind = " audio" ;
328329 audio_rtp->jitter = 0.01 ;
330+ audio_rtp->packets_received = 1 ;
329331 report->AddStats (std::unique_ptr<RTCStats>(audio_rtp));
330332
331333 const auto another_audio_rtp = new RTCInboundRtpStreamStats (" anotherRtpId" , Timestamp::Zero ());
332334 another_audio_rtp->kind = " audio" ;
333335 another_audio_rtp->jitter = 0.02 ;
336+ another_audio_rtp->packets_received = 1 ;
334337 report->AddStats (std::unique_ptr<RTCStats>(another_audio_rtp));
335338
336339 const auto video_rtp = new RTCInboundRtpStreamStats (" someVideoRtpId" , Timestamp::Zero ());
337340 video_rtp->kind = " video" ;
338341 video_rtp->jitter = 0.025 ;
342+ video_rtp->packets_received = 1 ;
339343 report->AddStats (std::unique_ptr<RTCStats>(video_rtp));
340344
341345 const auto another_video_rtp = new RTCInboundRtpStreamStats (" anotherVideoRtpId" , Timestamp::Zero ());
342346 another_video_rtp->kind = " video" ;
343347 another_video_rtp->jitter = 0.015 ;
348+ another_video_rtp->packets_received = 1 ;
344349 report->AddStats (std::unique_ptr<RTCStats>(another_video_rtp));
345350
346351 const auto remote_irrelevant_rtp = new RTCRemoteInboundRtpStreamStats (" irrelevantRemoteRtpId" , Timestamp::Zero ());
347352 remote_irrelevant_rtp->kind = " irrelevant" ;
348- remote_irrelevant_rtp->jitter = 1.0 ;
353+ remote_irrelevant_rtp->jitter = 1 ;
349354 report->AddStats (std::unique_ptr<RTCStats>(remote_irrelevant_rtp));
350355
351356 const auto remote_audio_rtp = new RTCRemoteInboundRtpStreamStats (" someRemoteAudioRtpId" , Timestamp::Zero ());
@@ -370,14 +375,38 @@ TEST_F(StatsJitter, audio_and_video)
370375 stats_get_report (stats, &sr);
371376
372377 stats_jitter expected_jitter;
373- expected_jitter.audio .rx = 20 ; // max of [0.01, 0.02] * 1000
378+ expected_jitter.audio .rx = 15 ; // mean of [0.01, 0.02] * 1000
374379 expected_jitter.audio .tx = 30 ;
375- expected_jitter.video .rx = 25 ; // max of [0.025, 0.015] * 1000
380+ expected_jitter.video .rx = 20 ; // mean of [0.025, 0.015] * 1000
376381 expected_jitter.video .tx = 40 ;
377382
378383 EXPECT_EQ (sr.jitter , expected_jitter);
379384}
380385
386+ TEST_F (StatsJitter, zero_packet_rtp)
387+ {
388+ const auto inbound_rtp = new RTCInboundRtpStreamStats (" inboundRtpId" , Timestamp::Zero ());
389+ inbound_rtp->kind = " audio" ;
390+ inbound_rtp->jitter = 0.05 ;
391+ inbound_rtp->packets_received = 1 ;
392+ auto report = RTCStatsReport::Create (Timestamp::Zero ());
393+ report->AddStats (std::unique_ptr<RTCStats>(inbound_rtp));
394+
395+ const auto zero_packets_inbound_rtp = new RTCInboundRtpStreamStats (" zeroInboundRtpId" , Timestamp::Zero ());
396+ zero_packets_inbound_rtp->kind = " audio" ;
397+ zero_packets_inbound_rtp->jitter = 0 ;
398+ report->AddStats (std::unique_ptr<RTCStats>(zero_packets_inbound_rtp));
399+
400+ stats_update (stats, report->ToJson ().c_str ());
401+ stats_get_report (stats, &sr);
402+
403+ stats_jitter expected_jitter;
404+
405+ const auto expected_audio_jitter = 50 ;
406+
407+ EXPECT_EQ (sr.jitter .audio .rx , expected_audio_jitter);
408+ }
409+
381410// ------------------------------------- RTT Tests --------------------------------------
382411class StatsRtt : public Base ,
383412 public ::testing::Test {
0 commit comments