annotate src/twjit.c @ 21:2032201bd034

implement twrtp_endp_bind_ip_port()
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Jul 2024 04:17:18 +0000
parents 58e9719d1a84
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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: main body.
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
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <osmocom/core/linuxlist.h>
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <osmocom/core/msgb.h>
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <osmocom/core/talloc.h>
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <osmocom/core/utils.h>
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <themwi/rtp/twjit.h>
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 void twrtp_jibuf_init_defaults(struct twrtp_jibuf_config *config)
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 memset(config, 0, sizeof(struct twrtp_jibuf_config));
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 config->bd_start = 2; /* smallest allowed */
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 config->bd_hiwat = 3; /* Nstart+1 is practically-useful minimum */
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 config->thinning_int = 17; /* prime number, usually 340 ms */
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 config->max_future_sec = 10; /* 10 s is a long time for voice */
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 /* create and destroy functions */
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct twrtp_jibuf_inst *
15
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
28 twrtp_jibuf_create(void *ctx, struct twrtp_jibuf_config *config)
3
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct twrtp_jibuf_inst *twjit;
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 twjit = talloc_zero(ctx, struct twrtp_jibuf_inst);
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!twjit)
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return NULL;
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 twjit->ext_config = config;
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 twjit->state = TWJIT_STATE_EMPTY;
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 INIT_LLIST_HEAD(&twjit->sb[0].queue);
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 INIT_LLIST_HEAD(&twjit->sb[1].queue);
15
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
40 /* default of 8 kHz clock, 20 ms quantum */
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
41 twrtp_jibuf_set_ts_quant(twjit, 8, 20);
3
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return twjit;
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 void twrtp_jibuf_destroy(struct twrtp_jibuf_inst *twjit)
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 msgb_queue_free(&twjit->sb[0].queue);
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 msgb_queue_free(&twjit->sb[1].queue);
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 talloc_free(twjit);
d10ea5dc61b3 twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
15
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
52
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
53 /* basic housekeeping */
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
54
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
55 void twrtp_jibuf_set_ts_quant(struct twrtp_jibuf_inst *twjit,
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
56 uint16_t clock_khz, uint16_t quantum_ms)
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
57 {
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
58 twjit->ts_quantum = (uint32_t) quantum_ms * clock_khz;
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
59 twjit->quanta_per_sec = 1000 / quantum_ms;
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
60 twjit->ts_units_per_ms = clock_khz;
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
61 twjit->ts_units_per_sec = (uint32_t) clock_khz * 1000;
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
62 twjit->ns_to_ts_units = 1000000 / clock_khz;
355de6301404 twjit: simplify create API, factor out clock & quantum config
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
63 }
16
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
64
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
65 void twrtp_jibuf_reset(struct twrtp_jibuf_inst *twjit)
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
66 {
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
67 msgb_queue_free(&twjit->sb[0].queue);
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
68 msgb_queue_free(&twjit->sb[1].queue);
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
69 twjit->state = TWJIT_STATE_EMPTY;
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
70 twjit->sb[0].depth = 0;
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
71 twjit->sb[1].depth = 0;
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
72 twjit->got_first_packet = false;
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
73 memset(&twjit->stats, 0, sizeof(struct twrtp_jibuf_stats));
58e9719d1a84 twjit: add reset function
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
74 }