From 908d8a7280eb3eb73a0627342d34e6503bbd0c26 Mon Sep 17 00:00:00 2001 From: Brian West <brian@freeswitch.org> Date: Tue, 22 Dec 2009 21:24:15 +0000 Subject: [PATCH] adding 12kHz and 24kHz git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16026 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_loadable_module.h | 4 ++ src/include/switch_utils.h | 2 +- .../mod_conference/mod_conference.c | 2 +- .../mod_local_stream/mod_local_stream.c | 2 +- src/switch_pcm.c | 63 ++++++++++++++++++- 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/include/switch_loadable_module.h b/src/include/switch_loadable_module.h index f43fdb54d6..c1dac88909 100644 --- a/src/include/switch_loadable_module.h +++ b/src/include/switch_loadable_module.h @@ -339,10 +339,14 @@ static inline int switch_check_interval(uint32_t rate, uint32_t ptime) ptime_div = 2; break; case 32000: + case 24000: case 16000: max_ms = 60; ptime_div = 2; break; + case 12000: + max_ms = 100; + ptime_div = 2; case 8000: max_ms = 120; ptime_div = 2; diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index c72c6d8321..e5790e5fc4 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -92,7 +92,7 @@ static inline switch_bool_t switch_is_moh(const char *s) #define switch_arraylen(_a) (sizeof(_a) / sizeof(_a[0])) #define switch_split(_data, _delim, _array) switch_separate_string(_data, _delim, _array, switch_arraylen(_array)) -#define switch_is_valid_rate(_tmp) (_tmp == 8000 || _tmp == 16000 || _tmp == 32000 || _tmp == 11025 || _tmp == 22050 || _tmp == 44100 || _tmp == 48000) +#define switch_is_valid_rate(_tmp) (_tmp == 8000 || _tmp == 12000 || _tmp == 16000 || _tmp == 24000 || _tmp == 32000 || _tmp == 11025 || _tmp == 22050 || _tmp == 44100 || _tmp == 48000) static inline int switch_string_has_escaped_data(const char *in) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index f038c2bec6..6588ada658 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -5761,7 +5761,7 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_m if (!strcasecmp(var, "rate") && !zstr(val)) { uint32_t tmp = atoi(val); - if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) { + if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) { rate = tmp; } } else if (!strcasecmp(var, "domain") && !zstr(val)) { diff --git a/src/mod/formats/mod_local_stream/mod_local_stream.c b/src/mod/formats/mod_local_stream/mod_local_stream.c index 0ee8258066..226ba8b15b 100644 --- a/src/mod/formats/mod_local_stream/mod_local_stream.c +++ b/src/mod/formats/mod_local_stream/mod_local_stream.c @@ -546,7 +546,7 @@ static void launch_threads(void) if (!strcasecmp(var, "rate")) { int tmp = atoi(val); - if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) { + if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) { source->rate = tmp; } } else if (!strcasecmp(var, "shuffle")) { diff --git a/src/switch_pcm.c b/src/switch_pcm.c index 77f016d4ab..6aae839247 100644 --- a/src/switch_pcm.c +++ b/src/switch_pcm.c @@ -388,6 +388,67 @@ SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load) bpf = bpf * 2; ebpf = ebpf * 2; } + + samples_per_frame = 240; + bytes_per_frame = 480; + ms_per_frame = 20000; + + for (x = 0; x < 5; x++) { + switch_core_codec_add_implementation(pool, codec_interface, + SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */ + 10, /* the IANA code number */ + "L16", /* the IANA code name */ + NULL, /* default fmtp to send (can be overridden by the init function) */ + 12000, /* samples transferred per second */ + 12000, /* actual samples transferred per second */ + 192000, /* bits transferred per second */ + ms_per_frame, /* number of microseconds per frame */ + samples_per_frame, /* number of samples per frame */ + bytes_per_frame, /* number of bytes per frame decompressed */ + bytes_per_frame, /* number of bytes per frame compressed */ + 1, /* number of channels represented */ + 1, /* number of frames per network packet */ + switch_raw_init, /* function to initialize a codec handle using this implementation */ + switch_raw_encode, /* function to encode raw data into encoded data */ + switch_raw_decode, /* function to decode encoded data into raw data */ + switch_raw_destroy); /* deinitalize a codec handle using this implementation */ + + samples_per_frame += 240; + bytes_per_frame += 480; + ms_per_frame += 20000; + + } + + samples_per_frame = 480; + bytes_per_frame = 960; + ms_per_frame = 20000; + + for (x = 0; x < 3; x++) { + switch_core_codec_add_implementation(pool, codec_interface, + SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */ + 10, /* the IANA code number */ + "L16", /* the IANA code name */ + NULL, /* default fmtp to send (can be overridden by the init function) */ + 24000, /* samples transferred per second */ + 24000, /* actual samples transferred per second */ + 384000, /* bits transferred per second */ + ms_per_frame, /* number of microseconds per frame */ + samples_per_frame, /* number of samples per frame */ + bytes_per_frame, /* number of bytes per frame decompressed */ + bytes_per_frame, /* number of bytes per frame compressed */ + 1, /* number of channels represented */ + 1, /* number of frames per network packet */ + switch_raw_init, /* function to initialize a codec handle using this implementation */ + switch_raw_encode, /* function to encode raw data into encoded data */ + switch_raw_decode, /* function to decode encoded data into raw data */ + switch_raw_destroy); /* deinitalize a codec handle using this implementation */ + + samples_per_frame += 480; + bytes_per_frame += 960; + ms_per_frame += 20000; + + } + /* these formats below are for file playing. */ samples_per_frame = 96; @@ -451,8 +512,6 @@ SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load) } - - samples_per_frame = 32; bytes_per_frame = 64; ms_per_frame = 2000;