Skip to content

Commit a748027

Browse files
committed
pcaputil: Use pcap wall-clock gap when RTP timestamps understate pause
When the marker bit indicates a new talkspurt, RTP timestamps may not reflect the actual pause duration (e.g. during hold). If the pcap wall-clock gap exceeds the RTP timestamp gap by more than 150ms (a jitter buffer to tolerate clock drift and network jitter), substitute the wall-clock gap so silence is filled correctly.
1 parent afed3d8 commit a748027

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

pjsip-apps/src/samples/pcaputil.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ static void pcap2wav(const struct args *args)
488488
const pj_int64_t wallclock_gap =
489489
(pj_int64_t)(pkt1.packet_ts.u64 - pkt0.packet_ts.u64) * param.info.clock_rate;
490490
ts_discontinuity = ts_gap_s - max_marker_gap_diff >= wallclock_gap;
491+
/* When the RTP marker bit is set (start of a talkspurt after
492+
* silence/hold), RTP timestamps may not reflect the actual pause
493+
* duration. If the real wall-clock gap (from pcap timestamps)
494+
* exceeds the RTP timestamp gap by more than 150ms (a jitter
495+
* buffer to tolerate clock drift and network jitter), use the
496+
* wall-clock gap instead so that silence is correctly filled.
497+
*
498+
* Comparison (avoiding division):
499+
* ts_gap/clock_rate + 150ms < pcap_ns_gap / 1e9
500+
* => ts_gap * 1e9 + 150ms * clock_rate * 1e9 < pcap_ns_gap * clock_rate
501+
*/
502+
if (ts_gap_s + min_marker_gap_diff < wallclock_gap) {
503+
ts_gap = wallclock_gap / 1000000000;
504+
}
491505
} else {
492506
ts_discontinuity = PJ_FALSE;
493507
}

0 commit comments

Comments
 (0)