FreeCalypso > hg > themwi-rtp-lib
annotate src/twjit.c @ 5:1bb26347e253
twjit: split into separate base/in/out modules
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 05 Jul 2024 21:24:56 +0000 |
parents | d10ea5dc61b3 |
children | 668b84c52094 |
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 * |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 twrtp_jibuf_create(void *ctx, uint16_t quantum_ms, uint32_t quantum_ts_inc, |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 struct twrtp_jibuf_config *config) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 struct twrtp_jibuf_inst *twjit; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 twjit = talloc_zero(ctx, struct twrtp_jibuf_inst); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (!twjit) |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return NULL; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 twjit->ext_config = config; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 twjit->ts_quantum = quantum_ts_inc; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 twjit->quanta_per_sec = 1000 / quantum_ms; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 twjit->state = TWJIT_STATE_EMPTY; |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 INIT_LLIST_HEAD(&twjit->sb[0].queue); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 INIT_LLIST_HEAD(&twjit->sb[1].queue); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return twjit; |
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 |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 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
|
48 { |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 msgb_queue_free(&twjit->sb[0].queue); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 msgb_queue_free(&twjit->sb[1].queue); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 talloc_free(twjit); |
d10ea5dc61b3
twjit: initial import from previous work repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |