Browse Source

TT#136956 support DTMF-security=random

Change-Id: I4100c1511be743901d302491238872990f213118
pull/1430/head
Richard Fuchs 4 years ago
parent
commit
9da5a46fcb
9 changed files with 79 additions and 19 deletions
  1. +3
    -1
      README.md
  2. +3
    -0
      daemon/call_interfaces.c
  3. +8
    -0
      daemon/codec.c
  4. +1
    -0
      daemon/dtmf.c
  5. +3
    -1
      include/call.h
  6. +22
    -0
      lib/codeclib.c
  7. +2
    -0
      lib/codeclib.h
  8. +28
    -17
      lib/dtmflib.c
  9. +9
    -0
      lib/dtmflib.h

+ 3
- 1
README.md View File

@ -1524,7 +1524,9 @@ Optionally included keys are:
Used in the `block DTMF` message to select the DTMF blocking mode. The
default mode is `drop` which simply drops DTMF event packets. The other
supported modes are: `silence` which replaces DTMF events with silence
audio; `tone` which replaces DTMF events with a single sine wave tone.
audio; `tone` which replaces DTMF events with a single sine wave tone;
`random` which replaces DTMF events with random other DTMF events (both
in-band DTMF audio tones and RFC event packets).
* `delay-buffer`


+ 3
- 0
daemon/call_interfaces.c View File

@ -1335,6 +1335,9 @@ static void call_ng_main_flags(struct sdp_ng_flags *out, str *key, bencode_item_
case CSH_LOOKUP("tone"):
out->block_dtmf_mode = BLOCK_DTMF_TONE;
break;
case CSH_LOOKUP("random"):
out->block_dtmf_mode = BLOCK_DTMF_RANDOM;
break;
default:
ilog(LOG_WARN, "Unknown 'DTMF-security' flag encountered: '" STR_FORMAT "'",
STR_FMT(&s));


+ 8
- 0
daemon/codec.c View File

@ -2390,6 +2390,14 @@ static void delay_frame_manipulate(struct delay_frame *dframe) {
frame_fill_tone_samples(frame->format, frame->extended_data[0], dframe->ts,
frame->nb_samples, 400, 10, frame->sample_rate, frame->channels);
break;
case BLOCK_DTMF_RANDOM:
if (!media->dtmf_event_state)
media->dtmf_event_state = '0' + (ssl_random() % 10);
frame_fill_dtmf_samples(frame->format, frame->extended_data[0], dframe->ts,
frame->nb_samples, media->dtmf_event_state - '0',
10, frame->sample_rate,
frame->channels);
break;
default:
break;
}


+ 1
- 0
daemon/dtmf.c View File

@ -160,6 +160,7 @@ static void dtmf_code_event(struct call_media *media, char event, uint64_t ts) {
media->dtmf_code = event;
media->dtmf_start = ts;
media->dtmf_end = 0;
media->dtmf_event_state = 0;
}


+ 3
- 1
include/call.h View File

@ -206,7 +206,8 @@ enum block_dtmf_mode {
BLOCK_DTMF___PCM_REPLACE_START = 2,
BLOCK_DTMF_SILENCE = 2,
BLOCK_DTMF_TONE = 3,
BLOCK_DTMF___PCM_REPLACE_END = 3,
BLOCK_DTMF_RANDOM = 4,
BLOCK_DTMF___PCM_REPLACE_END = 4,
};
@ -401,6 +402,7 @@ struct call_media {
uint32_t dtmf_start;
char dtmf_code;
uint32_t dtmf_end;
unsigned int dtmf_event_state;
#ifdef WITH_TRANSCODING
union {
struct {


+ 22
- 0
lib/codeclib.c View File

@ -2656,3 +2656,25 @@ void frame_fill_tone_samples(enum AVSampleFormat fmt, void *samples, unsigned in
break;
}
}
void frame_fill_dtmf_samples(enum AVSampleFormat fmt, void *samples, unsigned int offset, unsigned int num,
unsigned int event, unsigned int volume, unsigned int sample_rate, unsigned int channels)
{
switch (fmt) {
case AV_SAMPLE_FMT_S16:
dtmf_samples_int16_t(samples, offset, num, event, volume, sample_rate, channels);
break;
case AV_SAMPLE_FMT_S32:
dtmf_samples_int32_t(samples, offset, num, event, volume, sample_rate, channels);
break;
case AV_SAMPLE_FMT_DBL:
dtmf_samples_double(samples, offset, num, event, volume, sample_rate, channels);
break;
case AV_SAMPLE_FMT_FLT:
dtmf_samples_float(samples, offset, num, event, volume, sample_rate, channels);
break;
default:
ilog(LOG_ERR | LOG_FLAG_LIMIT, "Unsupported sample format %u", fmt);
break;
}
}

+ 2
- 0
lib/codeclib.h View File

@ -343,6 +343,8 @@ int packet_sequencer_insert(packet_sequencer_t *ps, seq_packet_t *);
void frame_fill_tone_samples(enum AVSampleFormat fmt, void *samples, unsigned int offset, unsigned int num,
unsigned int freq, unsigned int volume, unsigned int sample_rate, unsigned int channels);
void frame_fill_dtmf_samples(enum AVSampleFormat fmt, void *samples, unsigned int offset, unsigned int num,
unsigned int event, unsigned int volume, unsigned int sample_rate, unsigned int channels);
#include "auxlib.h"


+ 28
- 17
lib/dtmflib.c View File

@ -221,24 +221,35 @@ tone_samples_x(int32_t)
tone_samples_x(double)
tone_samples_x(float)
#define dtmf_samples_x(type) \
void dtmf_samples_ ## type(type *samples, unsigned long offset, unsigned long num, unsigned int event, \
unsigned int volume, unsigned int sample_rate, unsigned int channels) \
{ \
const struct dtmf_freq *df; \
\
if (event == 0xff) { \
/* pause - silence samples */ \
memset(samples, 0, num * sizeof(type)); \
return; \
} \
\
if (event >= G_N_ELEMENTS(dtmf_freqs)) { \
ilog(LOG_WARN | LOG_FLAG_LIMIT, "Unsupported DTMF event %u", event); \
memset(samples, 0, num * sizeof(type)); \
return; \
} \
df = &dtmf_freqs[event]; \
\
freq_samples_ ## type(samples, offset, num, df->prim, df->sec, volume, sample_rate, channels); \
} \
dtmf_samples_x(int16_t)
dtmf_samples_x(int32_t)
dtmf_samples_x(double)
dtmf_samples_x(float)
void dtmf_samples_int16_t_mono(void *buf, unsigned long offset, unsigned long num, unsigned int event,
unsigned int volume, unsigned int sample_rate)
{
int16_t *samples = buf;
const struct dtmf_freq *df;
if (event == 0xff) {
// pause - silence samples
memset(samples, 0, num * 2);
return;
}
if (event >= G_N_ELEMENTS(dtmf_freqs)) {
ilog(LOG_WARN | LOG_FLAG_LIMIT, "Unsupported DTMF event %u", event);
memset(buf, 0, num * 2);
return;
}
df = &dtmf_freqs[event];
freq_samples_int16_t(samples, offset, num, df->prim, df->sec, volume, sample_rate, 1);
dtmf_samples_int16_t(buf, offset, num, event, volume, sample_rate, 1);
}

+ 9
- 0
lib/dtmflib.h View File

@ -35,5 +35,14 @@ void tone_samples_double(double *buf, unsigned long offset, unsigned long num, u
void tone_samples_float(float *buf, unsigned long offset, unsigned long num, unsigned int freq,
unsigned int volume, unsigned int sample_rate, unsigned int channels);
void dtmf_samples_int16_t(int16_t *buf, unsigned long offset, unsigned long num, unsigned int event,
unsigned int volume, unsigned int sample_rate, unsigned int channels);
void dtmf_samples_int32_t(int32_t *buf, unsigned long offset, unsigned long num, unsigned int event,
unsigned int volume, unsigned int sample_rate, unsigned int channels);
void dtmf_samples_double(double *buf, unsigned long offset, unsigned long num, unsigned int event,
unsigned int volume, unsigned int sample_rate, unsigned int channels);
void dtmf_samples_float(float *buf, unsigned long offset, unsigned long num, unsigned int event,
unsigned int volume, unsigned int sample_rate, unsigned int channels);
#endif

Loading…
Cancel
Save