comparison src/twjit.c @ 15:355de6301404

twjit: simplify create API, factor out clock & quantum config
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Jul 2024 21:31:16 +0000
parents 95f6c8ce33b0
children 58e9719d1a84
comparison
equal deleted inserted replaced
14:073b8c7b361f 15:355de6301404
23 } 23 }
24 24
25 /* create and destroy functions */ 25 /* create and destroy functions */
26 26
27 struct twrtp_jibuf_inst * 27 struct twrtp_jibuf_inst *
28 twrtp_jibuf_create(void *ctx, uint16_t quantum_ms, uint16_t clock_khz, 28 twrtp_jibuf_create(void *ctx, struct twrtp_jibuf_config *config)
29 struct twrtp_jibuf_config *config)
30 { 29 {
31 struct twrtp_jibuf_inst *twjit; 30 struct twrtp_jibuf_inst *twjit;
32 31
33 twjit = talloc_zero(ctx, struct twrtp_jibuf_inst); 32 twjit = talloc_zero(ctx, struct twrtp_jibuf_inst);
34 if (!twjit) 33 if (!twjit)
35 return NULL; 34 return NULL;
36 35
37 twjit->ext_config = config; 36 twjit->ext_config = config;
38 twjit->ts_quantum = (uint32_t)quantum_ms * clock_khz;
39 twjit->quanta_per_sec = 1000 / quantum_ms;
40 twjit->ts_units_per_ms = clock_khz;
41 twjit->ts_units_per_sec = (uint32_t) clock_khz * 1000;
42 twjit->ns_to_ts_units = 1000000 / clock_khz;
43 twjit->state = TWJIT_STATE_EMPTY; 37 twjit->state = TWJIT_STATE_EMPTY;
44 INIT_LLIST_HEAD(&twjit->sb[0].queue); 38 INIT_LLIST_HEAD(&twjit->sb[0].queue);
45 INIT_LLIST_HEAD(&twjit->sb[1].queue); 39 INIT_LLIST_HEAD(&twjit->sb[1].queue);
40 /* default of 8 kHz clock, 20 ms quantum */
41 twrtp_jibuf_set_ts_quant(twjit, 8, 20);
46 42
47 return twjit; 43 return twjit;
48 } 44 }
49 45
50 void twrtp_jibuf_destroy(struct twrtp_jibuf_inst *twjit) 46 void twrtp_jibuf_destroy(struct twrtp_jibuf_inst *twjit)
51 { 47 {
52 msgb_queue_free(&twjit->sb[0].queue); 48 msgb_queue_free(&twjit->sb[0].queue);
53 msgb_queue_free(&twjit->sb[1].queue); 49 msgb_queue_free(&twjit->sb[1].queue);
54 talloc_free(twjit); 50 talloc_free(twjit);
55 } 51 }
52
53 /* basic housekeeping */
54
55 void twrtp_jibuf_set_ts_quant(struct twrtp_jibuf_inst *twjit,
56 uint16_t clock_khz, uint16_t quantum_ms)
57 {
58 twjit->ts_quantum = (uint32_t) quantum_ms * clock_khz;
59 twjit->quanta_per_sec = 1000 / quantum_ms;
60 twjit->ts_units_per_ms = clock_khz;
61 twjit->ts_units_per_sec = (uint32_t) clock_khz * 1000;
62 twjit->ns_to_ts_units = 1000000 / clock_khz;
63 }