FreeCalypso > hg > themwi-rtp-lib
annotate src/twjit_in.c @ 12:323957bebd53
twjit: smarter counting of underruns
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Jul 2024 02:47:21 +0000 |
parents | 4f82b9c07ddb |
children | ec50018cc4ea |
rev | line source |
---|---|
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5
1bb26347e253
twjit: split into separate base/in/out modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
2 * Themyscira Wireless jitter buffer implementation: RTP input processing. |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdint.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdbool.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <arpa/inet.h> /* for network byte order functions */ |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <osmocom/core/linuxlist.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <osmocom/core/msgb.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/timer.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/core/utils.h> |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
10
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
15 #include <themwi/rtp/twjit.h> |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
10
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
17 struct rtp_basic_hdr { |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
18 uint8_t v_p_x_cc; |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
19 uint8_t m_pt; |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
20 uint16_t seq; |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
21 uint32_t tstamp; |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
22 uint32_t ssrc; |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
23 }; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
25 /* raw analytics on the Rx packet stream */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
26 |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
27 static void analytics_init(struct twrtp_jibuf_inst *twjit, uint16_t rx_seq) |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 { |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
29 struct twrtp_jibuf_rr_info *rri = &twjit->rr_info; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
30 |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
31 rri->rx_packets = 1; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
32 rri->base_seq = rx_seq; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
33 rri->max_seq_ext = rx_seq; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
34 rri->expected_pkt = 1; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
35 rri->jitter_accum = 0; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
36 } |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
37 |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
38 static void analytics_cont(struct twrtp_jibuf_inst *twjit, uint16_t rx_seq, |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
39 uint32_t rx_ts, struct timespec *now) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
40 { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
41 struct twrtp_jibuf_rr_info *rri = &twjit->rr_info; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
42 uint16_t seq_ext_lo = rri->max_seq_ext; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
43 uint16_t seq_ext_hi = rri->max_seq_ext >> 16; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
44 int16_t seq_delta = (int16_t)(rx_seq - twjit->last_seq); |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
45 int16_t seq_delta2 = (int16_t)(rx_seq - seq_ext_lo); |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
46 int32_t ts_delta = (int32_t)(rx_ts - twjit->last_ts); |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
47 struct timespec time_delta; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
48 uint32_t time_delta_tsu; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
49 int32_t jitter_new, ts_delta_clamp; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
51 /* analytics for our own stats */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
52 if (seq_delta < 0) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
53 twjit->stats.seq_backwards++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
54 else if (seq_delta == 0) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
55 twjit->stats.seq_repeats++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
56 else if (seq_delta == 1) { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
57 if (ts_delta != twjit->ts_quantum) { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
58 if (ts_delta > 0 && (ts_delta % twjit->ts_quantum) == 0) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
59 twjit->stats.intentional_gaps++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
60 else |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
61 twjit->stats.ts_resets++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
62 } |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
63 } else |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
64 twjit->stats.seq_skips++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
65 |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
66 /* analytics for RTCP RR: packet counts */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
67 rri->rx_packets++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
68 if (seq_delta2 > 0) { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
69 if (rx_seq < seq_ext_lo) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
70 seq_ext_hi++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
71 seq_ext_lo = rx_seq; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
72 rri->max_seq_ext = ((uint32_t) seq_ext_hi << 16) | seq_ext_lo; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
73 rri->expected_pkt = rri->max_seq_ext - rri->base_seq + 1; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
74 } |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
75 |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
76 /* time-of-arrival analytics */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
77 time_delta.tv_sec = now->tv_sec - twjit->last_arrival.tv_sec; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
78 time_delta.tv_nsec = now->tv_nsec - twjit->last_arrival.tv_nsec; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
79 if (time_delta.tv_nsec < 0) { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
80 time_delta.tv_sec--; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
81 time_delta.tv_nsec += 1000000000; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
82 } |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
83 /* to avoid overflows in downstream math, clamp to 1 hour */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
84 if (time_delta.tv_sec >= 3600) { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
85 time_delta.tv_sec = 3600; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
86 time_delta.tv_nsec = 0; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
87 } |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
88 /* convert to RTP timestamp units */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
89 time_delta_tsu = time_delta.tv_sec * twjit->ts_units_per_sec + |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
90 time_delta.tv_nsec / twjit->ns_to_ts_units; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
91 twjit->last_arrival_delta = time_delta_tsu; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
92 /* jitter calculation for RTCP RR */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
93 ts_delta_clamp = twjit->ts_units_per_sec * 3600; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
94 if (ts_delta > ts_delta_clamp) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
95 ts_delta = ts_delta_clamp; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
96 else if (ts_delta < -ts_delta_clamp) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
97 ts_delta = -ts_delta_clamp; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
98 jitter_new = time_delta_tsu - ts_delta; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
99 if (jitter_new < 0) |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
100 jitter_new = -jitter_new; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
101 rri->jitter_accum += jitter_new - ((rri->jitter_accum + 8) >> 4); |
11
4f82b9c07ddb
twjit: update to stats
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
102 if (jitter_new > twjit->stats.jitter_max) |
4f82b9c07ddb
twjit: update to stats
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
103 twjit->stats.jitter_max = jitter_new; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
106 /* actual twjit input logic */ |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
107 |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 static void |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 init_subbuf_first_packet(struct twrtp_jibuf_inst *twjit, struct msgb *msg, |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
110 uint32_t rx_ssrc, uint32_t rx_ts) |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 struct twrtp_jibuf_sub *sb = &twjit->sb[twjit->write_sb]; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 OSMO_ASSERT(llist_empty(&sb->queue)); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 OSMO_ASSERT(sb->depth == 0); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 /* all good, proceed */ |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 sb->ssrc = rx_ssrc; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 sb->head_ts = rx_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 msgb_enqueue(&sb->queue, msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 sb->depth = 1; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 memcpy(&sb->conf, twjit->ext_config, sizeof(struct twrtp_jibuf_config)); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 sb->drop_int_count = 0; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 enum input_decision { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 INPUT_CONTINUE, |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 INPUT_TOO_OLD, |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 INPUT_RESET, |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 }; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 static enum input_decision |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 check_input_for_subbuf(struct twrtp_jibuf_inst *twjit, bool starting, |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
133 uint32_t rx_ssrc, uint32_t rx_ts) |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 struct twrtp_jibuf_sub *sb = &twjit->sb[twjit->write_sb]; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 int32_t ts_delta; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 if (rx_ssrc != sb->ssrc) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 return INPUT_RESET; |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
140 sb->delta_ms = twjit->last_arrival_delta / twjit->ts_units_per_ms; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 ts_delta = (int32_t)(rx_ts - sb->head_ts); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if (ts_delta < 0) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 return INPUT_TOO_OLD; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 if (ts_delta % twjit->ts_quantum) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 return INPUT_RESET; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 if (starting) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 if (sb->conf.start_max_delta && |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 sb->delta_ms > sb->conf.start_max_delta) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 return INPUT_RESET; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } else { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 uint32_t fwd = ts_delta / twjit->ts_quantum; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 |
8
95f6c8ce33b0
twjit: prep for rework of time delta handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
153 if (fwd >= (uint32_t) sb->conf.max_future_sec * |
95f6c8ce33b0
twjit: prep for rework of time delta handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
154 twjit->quanta_per_sec) |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 return INPUT_RESET; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return INPUT_CONTINUE; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 static void toss_write_queue(struct twrtp_jibuf_inst *twjit) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 struct twrtp_jibuf_sub *sb = &twjit->sb[twjit->write_sb]; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 msgb_queue_free(&sb->queue); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 sb->depth = 0; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 static void insert_pkt_write_sb(struct twrtp_jibuf_inst *twjit, |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 struct msgb *new_msg, uint32_t rx_ts) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 struct twrtp_jibuf_sub *sb = &twjit->sb[twjit->write_sb]; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 uint32_t ts_delta = rx_ts - sb->head_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 uint32_t ins_depth = ts_delta / twjit->ts_quantum; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 struct msgb *old_msg; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 uint32_t old_ts_delta; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 /* are we increasing total depth, and can we do simple tail append? */ |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 if (ins_depth >= sb->depth) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 msgb_enqueue(&sb->queue, new_msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 sb->depth = ins_depth + 1; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 /* nope - do it the hard way */ |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 llist_for_each_entry(old_msg, &sb->queue, list) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 old_ts_delta = old_msg->cb[0] - sb->head_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 if (old_ts_delta == ts_delta) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 /* two packets with the same timestamp! */ |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 twjit->stats.duplicate_ts++; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 msgb_free(new_msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 if (old_ts_delta > ts_delta) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 break; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 llist_add_tail(&new_msg->list, &old_msg->list); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 static void trim_starting_sb(struct twrtp_jibuf_inst *twjit) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 struct twrtp_jibuf_sub *sb = &twjit->sb[twjit->write_sb]; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 struct msgb *msg; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 uint32_t msg_ts, ts_adv, quantum_adv; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 while (sb->depth > sb->conf.bd_start) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 msg = msgb_dequeue(&sb->queue); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 OSMO_ASSERT(msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 msgb_free(msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 OSMO_ASSERT(!llist_empty(&sb->queue)); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 msg = llist_entry(sb->queue.next, struct msgb, list); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 msg_ts = msg->cb[0]; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 ts_adv = msg_ts - sb->head_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 quantum_adv = ts_adv / twjit->ts_quantum; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 OSMO_ASSERT(sb->depth > quantum_adv); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 sb->head_ts = msg_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 sb->depth -= quantum_adv; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 void twrtp_jibuf_input(struct twrtp_jibuf_inst *twjit, struct msgb *msg) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 { |
12
323957bebd53
twjit: smarter counting of underruns
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
221 bool got_previous_input = twjit->got_first_packet; |
10
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
222 struct rtp_basic_hdr *rtph; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 uint32_t rx_ssrc, rx_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 uint16_t rx_seq; |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
225 struct timespec now; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 enum input_decision id; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 |
10
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
228 if (msg->len < sizeof(struct rtp_basic_hdr)) { |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
229 inv_packet: twjit->stats.bad_packets++; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 msgb_free(msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 } |
10
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
233 rtph = (struct rtp_basic_hdr *)msg->data; |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
234 if ((rtph->v_p_x_cc & 0xC0) != 0x80) /* version field */ |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
235 goto inv_packet; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 rx_ssrc = ntohl(rtph->ssrc); |
10
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
237 rx_ts = ntohl(rtph->tstamp); |
e60df79cbe9f
twjit: eliminate dependency on libosmo-netif
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
238 rx_seq = ntohs(rtph->seq); |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
239 osmo_clock_gettime(CLOCK_MONOTONIC, &now); |
12
323957bebd53
twjit: smarter counting of underruns
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
240 if (!got_previous_input) { |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
241 analytics_init(twjit, rx_seq); |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
242 twjit->got_first_packet = true; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
243 } else if (rx_ssrc != twjit->last_ssrc) { |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
244 twjit->stats.ssrc_changes++; |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
245 analytics_init(twjit, rx_seq); |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
246 } else |
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
247 analytics_cont(twjit, rx_seq, rx_ts, &now); |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 twjit->last_ssrc = rx_ssrc; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 twjit->last_seq = rx_seq; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 twjit->last_ts = rx_ts; |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
251 memcpy(&twjit->last_arrival, &now, sizeof(struct timespec)); |
11
4f82b9c07ddb
twjit: update to stats
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
252 twjit->stats.rx_packets++; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 msg->cb[0] = rx_ts; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 switch (twjit->state) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 case TWJIT_STATE_EMPTY: |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 /* first packet into totally empty buffer */ |
12
323957bebd53
twjit: smarter counting of underruns
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
258 if (got_previous_input) |
323957bebd53
twjit: smarter counting of underruns
Mychaela Falconia <falcon@freecalypso.org>
parents:
11
diff
changeset
|
259 twjit->stats.underruns++; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 twjit->state = TWJIT_STATE_HUNT; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 twjit->write_sb = 0; |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
262 init_subbuf_first_packet(twjit, msg, rx_ssrc, rx_ts); |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 case TWJIT_STATE_HUNT: |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 case TWJIT_STATE_HANDOVER: |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
266 id = check_input_for_subbuf(twjit, true, rx_ssrc, rx_ts); |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 if (id == INPUT_TOO_OLD) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 msgb_free(msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 if (id == INPUT_RESET) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 toss_write_queue(twjit); |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
273 init_subbuf_first_packet(twjit, msg, rx_ssrc, rx_ts); |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 insert_pkt_write_sb(twjit, msg, rx_ts); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 trim_starting_sb(twjit); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 case TWJIT_STATE_FLOWING: |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
280 id = check_input_for_subbuf(twjit, false, rx_ssrc, rx_ts); |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 if (id == INPUT_TOO_OLD) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 twjit->stats.too_old++; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 msgb_free(msg); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 if (id == INPUT_RESET) { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 twjit->state = TWJIT_STATE_HANDOVER; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 twjit->write_sb = !twjit->write_sb; |
9
117fa99ff871
twjit: implement proper analytics
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
289 init_subbuf_first_packet(twjit, msg, rx_ssrc, rx_ts); |
11
4f82b9c07ddb
twjit: update to stats
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
290 twjit->stats.handovers_in++; |
3
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 insert_pkt_write_sb(twjit, msg, rx_ts); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 return; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 default: |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 OSMO_ASSERT(0); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 } |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 } |