From 9510b01a295ca6e2d874bb1b3ec8c10e5904abe1 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 7 Dec 2023 13:20:06 -0500 Subject: [PATCH] MT#55283 use typed GQueue for dtmf_events Change-Id: I241190eb84420e8d84b5267d2ba47906ddbd5e6c --- daemon/call.c | 4 ++-- daemon/codec.c | 12 ++++++------ daemon/dtmf.c | 28 +++++++++++++++------------- include/call.h | 4 ++-- include/dtmf.h | 7 ++++--- include/types.h | 3 +++ 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 7b9ac7120..c4b2fba57 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -3855,8 +3855,8 @@ void call_media_free(struct call_media **mdp) { codec_handler_free(&md->t38_handler); t38_gateway_put(&md->t38_gateway); t_queue_clear_full(&md->sdp_attributes, str_free); - g_queue_clear_full(&md->dtmf_recv, dtmf_event_free); - g_queue_clear_full(&md->dtmf_send, dtmf_event_free); + t_queue_clear_full(&md->dtmf_recv, dtmf_event_free); + t_queue_clear_full(&md->dtmf_send, dtmf_event_free); g_hash_table_destroy(md->media_subscribers_ht); g_hash_table_destroy(md->media_subscriptions_ht); g_queue_clear_full(&md->media_subscribers, media_subscription_free); diff --git a/daemon/codec.c b/daemon/codec.c index 77eaa45f1..21de052b7 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -195,7 +195,7 @@ struct codec_ssrc_handler { resample_t dtmf_resampler; format_t dtmf_format; uint64_t dtmf_ts, last_dtmf_event_ts; - GQueue dtmf_events; + dtmf_event_q dtmf_events; struct dtmf_event dtmf_event; // for replacing PCM with DTMF event struct dtmf_event dtmf_state; // state tracker for DTMF actions @@ -2651,12 +2651,12 @@ void codec_add_dtmf_event(struct codec_ssrc_handler *ch, int code, int level, ui if (ch->handler->dtmf_payload_type != -1 || (injected && ch->handler->real_dtmf_payload_type != -1)) { struct dtmf_event *ev = g_slice_alloc(sizeof(*ev)); *ev = new_ev; - g_queue_push_tail(&ch->dtmf_events, ev); + t_queue_push_tail(&ch->dtmf_events, ev); } } uint64_t codec_last_dtmf_event(struct codec_ssrc_handler *ch) { - struct dtmf_event *ev = g_queue_peek_tail(&ch->dtmf_events); + struct dtmf_event *ev = t_queue_peek_tail(&ch->dtmf_events); if (!ev) return 0; return ev->ts; @@ -2989,7 +2989,7 @@ static void delay_frame_manipulate(struct delay_frame *dframe) { uint64_t ts = dframe->ch->encoder ? dframe->ch->encoder->next_pts : dframe->ts; *ev = (struct dtmf_event) { .code = 0, .volume = 0, .ts = ts }; - g_queue_push_tail(&dframe->ch->dtmf_events, ev); + t_queue_push_tail(&dframe->ch->dtmf_events, ev); } } @@ -3026,7 +3026,7 @@ static void delay_frame_manipulate(struct delay_frame *dframe) { *ev = (struct dtmf_event) { .code = dtmf_send->code, .volume = -1 * dtmf_send->volume, .ts = ts }; - g_queue_push_tail(&dframe->ch->dtmf_events, ev); + t_queue_push_tail(&dframe->ch->dtmf_events, ev); } } else { @@ -3916,7 +3916,7 @@ static void __free_ssrc_handler(void *chp) { if (ch->dtmf_dsp) dtmf_rx_free(ch->dtmf_dsp); resample_shutdown(&ch->dtmf_resampler); - g_queue_clear_full(&ch->dtmf_events, dtmf_event_free); + t_queue_clear_full(&ch->dtmf_events, dtmf_event_free); g_queue_clear_full(&ch->silence_events, silence_event_free); dtx_buffer_stop(&ch->dtx_buffer); } diff --git a/daemon/dtmf.c b/daemon/dtmf.c index 443bee7ba..3a2643624 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -146,12 +146,12 @@ static void dtmf_end_event(struct call_media *media, unsigned int event, unsigne struct dtmf_event *ev = g_slice_alloc0(sizeof(*ev)); *ev = (struct dtmf_event) { .code = 0, .ts = ts, .volume = 0 }; - g_queue_push_tail(&media->dtmf_recv, ev); + t_queue_push_tail(&media->dtmf_recv, ev); ev = g_slice_alloc0(sizeof(*ev)); *ev = (struct dtmf_event) { .code = 0, .ts = ts + media->monologue->dtmf_delay * clockrate / 1000, .volume = 0, .block_dtmf = media->monologue->block_dtmf }; - g_queue_push_tail(&media->dtmf_send, ev); + t_queue_push_tail(&media->dtmf_send, ev); if (!dtmf_do_logging(media->call, injected)) return; @@ -227,7 +227,7 @@ static void dtmf_check_trigger(struct call_media *media, char event, uint64_t ts // check delay from previous event // dtmf_lock already held - struct dtmf_event *last_ev = g_queue_peek_tail(&media->dtmf_recv); + struct dtmf_event *last_ev = t_queue_peek_tail(&media->dtmf_recv); if (last_ev) { uint32_t ts_diff = ts - last_ev->ts; uint64_t ts_diff_ms = (uint64_t) ts_diff * 1000 / clockrate; @@ -291,7 +291,7 @@ static void dtmf_check_trigger(struct call_media *media, char event, uint64_t ts // media->dtmf_lock must be held static void dtmf_code_event(struct call_media *media, char event, uint64_t ts, int clockrate, int volume) { - struct dtmf_event *ev = g_queue_peek_tail(&media->dtmf_recv); + struct dtmf_event *ev = t_queue_peek_tail(&media->dtmf_recv); if (ev && ev->code == event) return; @@ -303,19 +303,19 @@ static void dtmf_code_event(struct call_media *media, char event, uint64_t ts, i ev = g_slice_alloc0(sizeof(*ev)); *ev = (struct dtmf_event) { .code = event, .ts = ts, .volume = volume, .rand_code = '0' + (ssl_random() % 10), .index = media->dtmf_count }; - g_queue_push_tail(&media->dtmf_recv, ev); + t_queue_push_tail(&media->dtmf_recv, ev); ev = g_slice_alloc0(sizeof(*ev)); *ev = (struct dtmf_event) { .code = event, .ts = ts + media->monologue->dtmf_delay * clockrate / 1000, .volume = volume, .block_dtmf = media->monologue->block_dtmf }; - g_queue_push_tail(&media->dtmf_send, ev); + t_queue_push_tail(&media->dtmf_send, ev); media->dtmf_count++; } -struct dtmf_event *is_in_dtmf_event(GQueue *events, uint32_t this_ts, int clockrate, unsigned int head, +struct dtmf_event *is_in_dtmf_event(dtmf_event_q *events, uint32_t this_ts, int clockrate, unsigned int head, unsigned int trail) { if (!clockrate) @@ -327,7 +327,7 @@ struct dtmf_event *is_in_dtmf_event(GQueue *events, uint32_t this_ts, int clockr uint32_t end_ts = this_ts - trail * clockrate / 1000; // go backwards through our list of DTMF events - for (GList *l = events->tail; l; l = l->prev) { + for (__auto_type l = events->tail; l; l = l->prev) { struct dtmf_event *ev = l->data; uint32_t ts = ev->ts; // truncate to 32 bits if (ev->code) { @@ -430,23 +430,25 @@ void dtmf_dsp_event(const struct dtmf_event *new_event, struct dtmf_event *cur_e } } -void dtmf_event_free(void *e) { - g_slice_free1(sizeof(struct dtmf_event), e); +void dtmf_event_free(struct dtmf_event *e) { + g_slice_free1(sizeof(*e), e); } // returns: 0 = no DTMF. 1 = DTMF start event. 2 = DTMF in progress. 3 = DTMF end event. -int dtmf_event_payload(str *buf, uint64_t *pts, uint64_t duration, struct dtmf_event *cur_event, GQueue *events) { +int dtmf_event_payload(str *buf, uint64_t *pts, uint64_t duration, struct dtmf_event *cur_event, + dtmf_event_q *events) +{ // do we have a relevant state change? struct dtmf_event prev_event = *cur_event; while (events->length) { - struct dtmf_event *ev = g_queue_peek_head(events); + struct dtmf_event *ev = t_queue_peek_head(events); ilog(LOG_DEBUG, "Next DTMF event starts at %" PRIu64 ". PTS now %" PRIu64, ev->ts, *pts); if (ev->ts > *pts) break; // future event ilog(LOG_DEBUG, "DTMF state change at %" PRIu64 ": %i -> %i, duration %" PRIu64, ev->ts, cur_event->code, ev->code, duration); - g_queue_pop_head(events); + t_queue_pop_head(events); *cur_event = *ev; dtmf_event_free(ev); cur_event->ts = *pts; // canonicalise start TS diff --git a/include/call.h b/include/call.h index 818bbbbfd..94e5a2ceb 100644 --- a/include/call.h +++ b/include/call.h @@ -490,8 +490,8 @@ struct call_media { unsigned long dtmf_ts; /* TS of last processed end event */ unsigned int dtmf_count; // lists are append-only - GQueue dtmf_recv; - GQueue dtmf_send; + dtmf_event_q dtmf_recv; + dtmf_event_q dtmf_send; #ifdef WITH_TRANSCODING encoder_callback_t encoder_callback; diff --git a/include/dtmf.h b/include/dtmf.h index d63f42476..d8bc566ee 100644 --- a/include/dtmf.h +++ b/include/dtmf.h @@ -27,8 +27,8 @@ struct dtmf_event { void dtmf_init(void); int dtmf_event_packet(struct media_packet *, str *, int, uint64_t ts); // 0 = ok, 1 = end event, -1 = error -int dtmf_event_payload(str *, uint64_t *, uint64_t, struct dtmf_event *, GQueue *); -void dtmf_event_free(void *); +int dtmf_event_payload(str *, uint64_t *, uint64_t, struct dtmf_event *, dtmf_event_q *); +void dtmf_event_free(struct dtmf_event *); int dtmf_code_from_char(char); char dtmf_code_to_char(int code); const char *dtmf_inject(struct call_media *media, int code, int volume, int duration, int pause, @@ -39,6 +39,7 @@ void dtmf_dsp_event(const struct dtmf_event *new_event, struct dtmf_event *cur_e enum block_dtmf_mode dtmf_get_block_mode(struct call *call, struct call_monologue *ml); bool is_pcm_dtmf_block_mode(enum block_dtmf_mode mode); bool is_dtmf_replace_mode(enum block_dtmf_mode mode); -struct dtmf_event *is_in_dtmf_event(GQueue *, uint32_t ts, int clockrate, unsigned int head, unsigned int trail); +struct dtmf_event *is_in_dtmf_event(dtmf_event_q *, uint32_t ts, int clockrate, unsigned int head, + unsigned int trail); #endif diff --git a/include/types.h b/include/types.h index 7cd0135da..b2b77d93f 100644 --- a/include/types.h +++ b/include/types.h @@ -34,4 +34,7 @@ TYPED_GQUEUE(packet_stream, struct packet_stream) struct sink_handler; TYPED_GQUEUE(sink_handler, struct sink_handler) +struct dtmf_event; +TYPED_GQUEUE(dtmf_event, struct dtmf_event) + #endif