# HG changeset patch # User Mychaela Falconia # Date 1720301476 0 # Node ID 355de6301404b13b4d02eff00ffb0b8257d8c75c # Parent 073b8c7b361f73541cbd5de1eeda8b2fa78648d9 twjit: simplify create API, factor out clock & quantum config diff -r 073b8c7b361f -r 355de6301404 include/twjit.h --- a/include/twjit.h Sat Jul 06 17:32:26 2024 +0000 +++ b/include/twjit.h Sat Jul 06 21:31:16 2024 +0000 @@ -129,9 +129,18 @@ /* twjit module API functions */ -struct twrtp_jibuf_inst *twrtp_jibuf_create(void *ctx, uint16_t quantum_ms, - uint16_t clock_khz, - struct twrtp_jibuf_config *config); +struct twrtp_jibuf_inst * +twrtp_jibuf_create(void *ctx, struct twrtp_jibuf_config *config); + +/* + * The default timescale is 8 kHz (8000 samples per second), + * and the default quantum duration (packetization interval) is 20 ms. + * The following function can be used to change these fundamental + * parameters; it may be called only right after twrtp_jibuf_create(), + * before any packets are fed to twrtp_jibuf_input(). + */ +void twrtp_jibuf_set_ts_quant(struct twrtp_jibuf_inst *twjit, + uint16_t clock_khz, uint16_t quantum_ms); void twrtp_jibuf_destroy(struct twrtp_jibuf_inst *twjit); diff -r 073b8c7b361f -r 355de6301404 src/twjit.c --- a/src/twjit.c Sat Jul 06 17:32:26 2024 +0000 +++ b/src/twjit.c Sat Jul 06 21:31:16 2024 +0000 @@ -25,8 +25,7 @@ /* create and destroy functions */ struct twrtp_jibuf_inst * -twrtp_jibuf_create(void *ctx, uint16_t quantum_ms, uint16_t clock_khz, - struct twrtp_jibuf_config *config) +twrtp_jibuf_create(void *ctx, struct twrtp_jibuf_config *config) { struct twrtp_jibuf_inst *twjit; @@ -35,14 +34,11 @@ return NULL; twjit->ext_config = config; - twjit->ts_quantum = (uint32_t)quantum_ms * clock_khz; - twjit->quanta_per_sec = 1000 / quantum_ms; - twjit->ts_units_per_ms = clock_khz; - twjit->ts_units_per_sec = (uint32_t) clock_khz * 1000; - twjit->ns_to_ts_units = 1000000 / clock_khz; twjit->state = TWJIT_STATE_EMPTY; INIT_LLIST_HEAD(&twjit->sb[0].queue); INIT_LLIST_HEAD(&twjit->sb[1].queue); + /* default of 8 kHz clock, 20 ms quantum */ + twrtp_jibuf_set_ts_quant(twjit, 8, 20); return twjit; } @@ -53,3 +49,15 @@ msgb_queue_free(&twjit->sb[1].queue); talloc_free(twjit); } + +/* basic housekeeping */ + +void twrtp_jibuf_set_ts_quant(struct twrtp_jibuf_inst *twjit, + uint16_t clock_khz, uint16_t quantum_ms) +{ + twjit->ts_quantum = (uint32_t) quantum_ms * clock_khz; + twjit->quanta_per_sec = 1000 / quantum_ms; + twjit->ts_units_per_ms = clock_khz; + twjit->ts_units_per_sec = (uint32_t) clock_khz * 1000; + twjit->ns_to_ts_units = 1000000 / clock_khz; +}