diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index d99711fdc..049785037 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2326,11 +2326,11 @@ const char *call_block_dtmf_ng(bencode_item_t *input, bencode_item_t *output) { if (monologue) { ilog(LOG_INFO, "Blocking directional DTMF (tag '" STR_FORMAT_M "')", STR_FMT_M(&monologue->tag)); - monologue->block_dtmf = 1; + monologue->block_dtmf = BLOCK_DTMF_DROP; } else { ilog(LOG_INFO, "Blocking DTMF (entire call)"); - call->block_dtmf = 1; + call->block_dtmf = BLOCK_DTMF_DROP; } return NULL; @@ -2349,15 +2349,15 @@ const char *call_unblock_dtmf_ng(bencode_item_t *input, bencode_item_t *output) if (monologue) { ilog(LOG_INFO, "Unblocking directional DTMF (tag '" STR_FORMAT_M "')", STR_FMT_M(&monologue->tag)); - monologue->block_dtmf = 0; + monologue->block_dtmf = BLOCK_DTMF_OFF; } else { ilog(LOG_INFO, "Unblocking DTMF (entire call)"); - call->block_dtmf = 0; + call->block_dtmf = BLOCK_DTMF_OFF; if (flags.all) { for (GList *l = call->monologues.head; l; l = l->next) { monologue = l->data; - monologue->block_dtmf = 0; + monologue->block_dtmf = BLOCK_DTMF_OFF; } } } diff --git a/daemon/codec.c b/daemon/codec.c index 3df50bd08..34599ba0a 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -1864,7 +1864,12 @@ static int packet_dtmf(struct codec_ssrc_handler *ch, struct codec_ssrc_handler int ret = 0; - if (!mp->call->block_dtmf && !mp->media->monologue->block_dtmf) { + enum block_dtmf_mode block_dtmf = dtmf_get_block_mode(mp->call, mp->media->monologue); + + if (block_dtmf == BLOCK_DTMF_DROP) + { } + else { + // pass through if (__buffer_dtx(input_ch->dtx_buffer, ch, input_ch, packet, mp, packet_dtmf_fwd)) ret = 1; // consumed else @@ -1877,7 +1882,11 @@ static int packet_dtmf_dup(struct codec_ssrc_handler *ch, struct codec_ssrc_hand struct transcode_packet *packet, struct media_packet *mp) { - if (!mp->call->block_dtmf && !mp->media->monologue->block_dtmf) + enum block_dtmf_mode block_dtmf = dtmf_get_block_mode(mp->call, mp->media->monologue); + + if (block_dtmf == BLOCK_DTMF_DROP) + { } + else // pass through packet_dtmf_fwd(ch, input_ch, packet, mp); return 0; } diff --git a/daemon/dtmf.c b/daemon/dtmf.c index 450c21f3b..54c87bb43 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -425,3 +425,18 @@ const char *dtmf_inject(struct call_media *media, int code, int volume, int dura } #endif + + +enum block_dtmf_mode dtmf_get_block_mode(struct call *call, struct call_monologue *ml) { + if (!call) { + if (!ml) + return BLOCK_DTMF_OFF; + call = ml->call; + } + + if (call && call->block_dtmf) + return call->block_dtmf; + if (!ml) + return BLOCK_DTMF_OFF; + return ml->block_dtmf; +} diff --git a/daemon/redis.c b/daemon/redis.c index 2126c06ac..89acfca49 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1422,7 +1422,7 @@ static int redis_tags(struct call *c, struct redis_list *tags, JsonReader *root_ call_str_cpy(c, &ml->label, &s); redis_hash_get_time_t(&ml->deleted, rh, "deleted"); if (!redis_hash_get_int(&ii, rh, "block_dtmf")) - ml->block_dtmf = ii ? 1 : 0; + ml->block_dtmf = ii; if (!redis_hash_get_int(&ii, rh, "block_media")) ml->block_media = ii ? 1 : 0; @@ -1896,7 +1896,7 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign) if (!redis_hash_get_str(&id, &call, "created_from_addr")) sockaddr_parse_any_str(&c->created_from_addr, &id); if (!redis_hash_get_int(&i, &call, "block_dtmf")) - c->block_dtmf = i ? 1 : 0; + c->block_dtmf = i; if (!redis_hash_get_int(&i, &call, "block_media")) c->block_media = i ? 1 : 0; @@ -2216,7 +2216,7 @@ char* redis_encode_json(struct call *c) { JSON_SET_SIMPLE_CSTR("created_from_addr",sockaddr_print_buf(&c->created_from_addr)); JSON_SET_SIMPLE("redis_hosted_db","%u",c->redis_hosted_db); JSON_SET_SIMPLE_STR("recording_metadata",&c->metadata); - JSON_SET_SIMPLE("block_dtmf","%i",c->block_dtmf ? 1 : 0); + JSON_SET_SIMPLE("block_dtmf","%i", c->block_dtmf); JSON_SET_SIMPLE("block_media","%i",c->block_media ? 1 : 0); if ((rec = c->recording)) { @@ -2336,7 +2336,7 @@ char* redis_encode_json(struct call *c) { JSON_SET_SIMPLE("created","%llu",(long long unsigned) ml->created); JSON_SET_SIMPLE("deleted","%llu",(long long unsigned) ml->deleted); - JSON_SET_SIMPLE("block_dtmf","%i",ml->block_dtmf ? 1 : 0); + JSON_SET_SIMPLE("block_dtmf","%i", ml->block_dtmf); JSON_SET_SIMPLE("block_media","%i",ml->block_media ? 1 : 0); if (ml->logical_intf) JSON_SET_SIMPLE_STR("logical_intf", &ml->logical_intf->name); diff --git a/include/call.h b/include/call.h index 7f7258ee0..fbfbda8cc 100644 --- a/include/call.h +++ b/include/call.h @@ -199,6 +199,11 @@ enum { #define MEDIA_SET(p, f) bf_set(&(p)->media_flags, MEDIA_FLAG_ ## f) #define MEDIA_CLEAR(p, f) bf_clear(&(p)->media_flags, MEDIA_FLAG_ ## f) +enum block_dtmf_mode { + BLOCK_DTMF_OFF = 0, + BLOCK_DTMF_DROP = 1, +}; + @@ -443,8 +448,8 @@ struct call_monologue { char *sdp_username; char *sdp_session_name; struct ssrc_hash *ssrc_hash; + enum block_dtmf_mode block_dtmf; - unsigned int block_dtmf:1; unsigned int block_media:1; unsigned int silence_media:1; unsigned int rec_forwarding:1; @@ -538,6 +543,7 @@ struct call { struct call_iterator_entry iterator[NUM_CALL_ITERATORS]; int cpu_affinity; + enum block_dtmf_mode block_dtmf; // ipv4/ipv6 media flags unsigned int is_ipv4_media_offer:1; @@ -546,7 +552,6 @@ struct call { unsigned int is_ipv6_media_answer:1; unsigned int is_call_media_counted:1; - unsigned int block_dtmf:1; unsigned int block_media:1; unsigned int silence_media:1; unsigned int recording_on:1; diff --git a/include/dtmf.h b/include/dtmf.h index 23bcf9164..8f0e19a5c 100644 --- a/include/dtmf.h +++ b/include/dtmf.h @@ -11,6 +11,8 @@ struct media_packet; struct call_media; +struct call; +struct call_monologue; struct dtmf_event { @@ -29,5 +31,6 @@ const char *dtmf_inject(struct call_media *media, int code, int volume, int dura bool dtmf_do_logging(void); void dtmf_dsp_event(const struct dtmf_event *new_event, struct dtmf_event *cur_event, struct call_media *media, int clockrate); +enum block_dtmf_mode dtmf_get_block_mode(struct call *call, struct call_monologue *ml); #endif diff --git a/t/test-transcode.c b/t/test-transcode.c index 28c8942fe..5af2bbb19 100644 --- a/t/test-transcode.c +++ b/t/test-transcode.c @@ -947,7 +947,7 @@ int main(void) { packet_seq(A, 8, PCMA_payload, 1000960, 206, 8, PCMA_payload); packet_seq(A, 8, PCMA_payload, 1001120, 207, 8, PCMA_payload); // enable blocking - call.block_dtmf = 1; + call.block_dtmf = BLOCK_DTMF_DROP; // start with marker packet_seq_exp(A, 101 | 0x80, "\x05\x0a\x00\xa0", 1001280, 208, -1, "", 0); dtmf(""); @@ -1012,7 +1012,7 @@ int main(void) { packet_seq(A, 8, PCMA_payload, 1000960, 206, 0, PCMU_payload); packet_seq(A, 8, PCMA_payload, 1001120, 207, 0, PCMU_payload); // enable blocking - call.block_dtmf = 1; + call.block_dtmf = BLOCK_DTMF_DROP; // start with marker packet_seq_exp(A, 101 | 0x80, "\x05\x0a\x00\xa0", 1001280, 208, -1, "", 0); dtmf(""); @@ -1076,7 +1076,7 @@ int main(void) { packet_seq(A, 0, PCMU_payload, 1000960, 206, 0, PCMU_payload); packet_seq(A, 0, PCMU_payload, 1001120, 207, 0, PCMU_payload); // enable blocking - call.block_dtmf = 1; + call.block_dtmf = BLOCK_DTMF_DROP; // start with marker packet_seq_exp(A, 101 | 0x80, "\x05\x0a\x00\xa0", 1001280, 208, -1, "", 0); dtmf("");