1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! What a receive-side jitter buffer discards, for the discard rate of the RFC 3611 VoIP
//! Metrics block (section 4.7.1).
//!
//! RFC 3611 section 4.7.1, discard rate: "The fraction of RTP data packets from the source that
//! have been discarded since the beginning of reception, due to late or early arrival,
//! under-run or overflow at the receiving jitter buffer", "calculated by dividing the total
//! number of packets discarded (excluding duplicate packet discards) by the total number of
//! packets expected". The jitter buffers ([`JitterBufferInterceptor`] and the adaptive one)
//! know what they discard; the XR generator, wire-ward of them, knows what was expected. A
//! [`JitterBufferDiscards`] given to both builders carries the count across.
//!
//! [`JitterBufferInterceptor`]: crate::JitterBufferInterceptor
use ;
use ;
/// The packets each remote stream's jitter buffer discarded, shared by a jitter buffer and the
/// XR generator: give the same handle to [`JitterBufferBuilder::with_discard_count`] (or
/// [`AdaptiveJitterBufferBuilder::with_discard_count`]) and to
/// [`XrReportBuilder::with_jitter_buffer_discards`], and the VoIP Metrics block's discard rate
/// is the buffer's (RFC 3611 section 4.7.1). Without it the generator reports 0, which is
/// true only when nothing in the chain discards.
///
/// Counted per SSRC since the stream was bound: packets that arrived after their turn to be
/// played out had passed, that a full buffer dropped, and that a stream restart (a timestamp
/// discontinuity) dropped unplayed. A second copy of a packet, held or already played out, is
/// not counted ("excluding duplicate packet discards").
///
/// ```
/// use rtci_interceptor::{
/// JitterBufferBuilder, JitterBufferDiscards, Registry, Slot, XrReportBuilder,
/// };
///
/// let discards = JitterBufferDiscards::new();
/// let chain = Registry::new()
/// .with(
/// Slot::ExtendedReports,
/// XrReportBuilder::new().with_jitter_buffer_discards(&discards).build(),
/// )
/// .with(
/// Slot::JitterBuffer,
/// JitterBufferBuilder::new().with_discard_count(&discards).build(),
/// )
/// .build();
/// # let _ = chain;
/// assert_eq!(0, discards.discarded(0x1234));
/// ```
///
/// [`JitterBufferBuilder::with_discard_count`]: crate::JitterBufferBuilder::with_discard_count
/// [`AdaptiveJitterBufferBuilder::with_discard_count`]: crate::AdaptiveJitterBufferBuilder::with_discard_count
/// [`XrReportBuilder::with_jitter_buffer_discards`]: crate::XrReportBuilder::with_jitter_buffer_discards
/// How many of a stream's discarded sequence numbers wait for the XR generator: it takes them
/// at each report (once a second by default), so this is room for far more than one interval.
pub const PENDING_DISCARDS: usize = 4096;
/// How many played-out positions a buffer remembers, to tell a late copy of a packet already
/// played out (a duplicate) from a packet whose turn passed without it (a discard).
pub const PLAYED_OUT_MEMORY: usize = 1024;
/// The positions (sequence numbers, extended or not) a buffer played out most recently.
pub