Browse Source

TT#136956 upgrade `block_dtmf` to enum to allow for different modes

Change-Id: I8bfa1cb9067a00958a2a1415b82e01c02deaf758
pull/1430/head
Richard Fuchs 4 years ago
parent
commit
478c2608e8
7 changed files with 48 additions and 16 deletions
  1. +5
    -5
      daemon/call_interfaces.c
  2. +11
    -2
      daemon/codec.c
  3. +15
    -0
      daemon/dtmf.c
  4. +4
    -4
      daemon/redis.c
  5. +7
    -2
      include/call.h
  6. +3
    -0
      include/dtmf.h
  7. +3
    -3
      t/test-transcode.c

+ 5
- 5
daemon/call_interfaces.c View File

@ -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;
}
}
}


+ 11
- 2
daemon/codec.c View File

@ -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;
}


+ 15
- 0
daemon/dtmf.c View File

@ -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;
}

+ 4
- 4
daemon/redis.c View File

@ -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);


+ 7
- 2
include/call.h View File

@ -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;


+ 3
- 0
include/dtmf.h View File

@ -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

+ 3
- 3
t/test-transcode.c View File

@ -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("");


Loading…
Cancel
Save