41 unsigned char g729_filler[] = {
42 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
43 229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
44 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
45 229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
46 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
47 229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
48 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
49 229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
50 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
51 229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
52 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
53 229, 127, 79, 96, 207, 82, 216, 110, 245, 81,
54 114, 170, 250, 103, 54, 211, 203, 194, 94, 64,
55 229, 127, 79, 96, 207, 82, 216, 110, 245, 81
60 memcpy(data, g729_filler, len);
72 int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0, tap_only = 0;
74 unsigned int flag = 0;
126 for(i = 0; i < 2; i++) {
142 need_codec = perfect = 0;
242 for (bp = session->
bugs; bp; bp = bp->
next) {
259 if ((*frame)->codec && (*frame)->codec->implementation &&
260 (*frame)->codec->implementation->encoded_bytes_per_packet &&
261 (*frame)->datalen != (*frame)->codec->implementation->encoded_bytes_per_packet) {
285 codec_impl = *(*frame)->codec->implementation;
303 for (bp = session->
bugs; bp; bp = bp->
next) {
318 if (bp->
ready && (*frame)->codec && (*frame)->codec->implementation && (*frame)->codec->implementation->encoded_bytes_per_packet) {
325 tmp_frame.
codec = (*frame)->codec;
326 tmp_frame.
datalen = (*frame)->codec->implementation->encoded_bytes_per_packet;
327 tmp_frame.
samples = (*frame)->codec->implementation->samples_per_packet;
328 tmp_frame.
channels = (*frame)->codec->implementation->number_of_channels;
329 tmp_frame.
data = data;
356 }
else if (session->
bugs && !need_codec) {
362 if (!session->
bugs && !session->
plc) {
364 unsigned int other_session_bugs = 0;
369 other_session_bugs = 1;
375 if (!other_session_bugs) {
420 if (read_frame->
codec || (is_cng && session->
plc)) {
442 if (!session->
bugs) {
463 if (!session->
bugs) {
467 if (!do_bugs)
goto done;
488 codec = read_frame->
codec;
652 for (bp = session->
bugs; bp; bp = bp->
next) {
703 for (bp = session->
bugs; bp; bp = bp->
next) {
727 int bytes = read_frame->
datalen;
728 uint32_t datalen = 0;
731 memcpy(data, read_frame->
data, read_frame->
datalen);
764 short *data = read_frame->
data;
781 (uint32_t) bytes, (uint32_t) (*frame)->datalen);
793 enc_frame = read_frame;
883 for (bp = session->
bugs; bp; bp = bp->
next) {
1010 char str[2] = { dtmf->
digit,
'\0' };
1052 for(p = digits; p && *p; p++) {
1068 if (new_dtmf.
digit !=
'w' && new_dtmf.
digit !=
'W') {
1091 char str[2] = { new_dtmf.
digit,
'\0' };
1105 if (dtmf->
digit ==
'w') {
1107 }
else if (dtmf->
digit ==
'W') {
1136 if (
zstr(dtmf_string)) {
1140 if (*dtmf_string ==
'~') {
1150 if (strlen(dtmf_string) > 99) {
1168 for (i = 0; i < argc; i++) {
1171 if ((p = strchr(argv[i],
'@'))) {
1179 for (p = argv[i]; p && *p; p++) {
1183 if (dtmf.
digit !=
'w' && dtmf.
digit !=
'W') {
1204 dur_total += dtmf.
duration + (250 * rate_mult);
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
switch_frame_t dummy_cng_frame
#define SWITCH_BUFFER_START_FRAMES
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_thread_rwlock_t * bug_rwlock
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
switch_send_dtmf_hook_t send_dtmf
switch_core_session_message_types_t message_id
switch_size_t switch_buffer_read(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen)
Read data from a switch_buffer_t up to the ammount of datalen if it is available. Remove read data fr...
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
const char * switch_channel_get_partner_uuid(switch_channel_t *channel)
switch_status_t switch_buffer_create_dynamic(_Out_ switch_buffer_t **buffer, _In_ switch_size_t blocksize, _In_ switch_size_t start_len, _In_ switch_size_t max_len)
Allocate a new dynamic switch_buffer.
switch_frame_t enc_read_frame
uint32_t switch_io_flag_t
switch_io_send_dtmf_t send_dtmf
switch_read_frame_hook_t read_frame
switch_io_read_frame_t read_frame
#define SWITCH_RECOMMENDED_BUFFER_SIZE
switch_mutex_t * codec_read_mutex
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
struct switch_io_event_hook_send_dtmf * next
switch_status_t switch_core_codec_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
Encode data using a codec handle.
switch_status_t switch_ivr_broadcast(const char *uuid, const char *path, switch_media_flag_t flags)
Signal the session to broadcast audio.
switch_kill_channel_hook_t kill_channel
uint32_t decoded_bytes_per_packet
switch_codec_t * read_codec
Representation of an event.
switch_frame_t * cur_frame
switch_io_routines_t * io_routines
switch_status_t switch_core_codec_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
Decode data using a codec handle.
#define SWITCH_RESAMPLE_QUALITY
switch_codec_implementation_t read_impl
const char * switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup, int idx)
Retrieve a variable from a given channel.
struct switch_io_event_hook_read_frame * next
#define switch_core_session_get_name(_s)
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_size_t switch_buffer_write(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen) const void *data, _In_ switch_size_t datalen)
Write data into a switch_buffer_t up to the length of datalen.
struct switch_runtime runtime
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
A message object designed to allow unlike technologies to exchange data.
uint32_t switch_core_max_dtmf_duration(uint32_t duration)
uint32_t switch_unmerge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels)
#define is_dtmf(key)
determine if a character is a valid DTMF key
switch_status_t switch_core_codec_reset(switch_codec_t *codec)
switch_io_event_hooks_t event_hooks
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
uint32_t switch_core_min_dtmf_duration(uint32_t duration)
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
SWITCH_BEGIN_EXTERN_C switch_plc_state_t * switch_plc_init(switch_plc_state_t *s)
const switch_codec_implementation_t * implementation
void switch_os_yield(void)
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
uint32_t switch_core_media_bug_prune(switch_core_session_t *session)
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
switch_channel_t * channel
switch_audio_resampler_t * read_resampler
switch_codec_interface_t * codec_interface
switch_frame_flag_t flags
switch_recv_dtmf_hook_t recv_dtmf
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
int switch_plc_rx(switch_plc_state_t *s, int16_t amp[], int len)
uint32_t actual_samples_per_second
void switch_core_gen_encoded_silence(unsigned char *data, const switch_codec_implementation_t *read_impl, switch_size_t len)
switch_status_t switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
static char * SIG_NAMES[]
switch_media_bug_t * bugs
switch_mutex_t * resample_mutex
An abstraction of a data frame.
struct switch_io_event_hook_kill_channel * next
void switch_cond_next(void)
#define switch_core_session_get_partner(_session, _partner)
switch_status_t switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
int microseconds_per_packet
switch_buffer_t * raw_read_buffer
Node in which to store custom read frame channel callback hooks.
#define switch_core_session_receive_message(_session, _message)
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
switch_status_t switch_channel_dtmf_lock(switch_channel_t *channel)
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
uint32_t switch_channel_test_cap(switch_channel_t *channel, switch_channel_cap_t cap)
switch_frame_t raw_read_frame
void switch_mux_channels(int16_t *data, switch_size_t samples, uint32_t orig_channels, uint32_t channels)
switch_status_t switch_core_session_perform_kill_channel(switch_core_session_t *session, const char *file, const char *func, int line, switch_signal_t sig)
uint32_t switch_core_default_dtmf_duration(uint32_t duration)
uint32_t samples_per_packet
#define switch_channel_down(_channel)
#define switch_channel_set_callstate(channel, state)
uint8_t number_of_channels
uint32_t samples_per_second
switch_status_t
Common return values.
Node in which to store custom send dtmf channel callback hooks.
switch_status_t switch_core_session_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
switch_payload_t ianacode
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
#define switch_channel_set_flag(_c, _f)
switch_status_t switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string)
Send DTMF to a session.
switch_signal_t
Signals to send to channels.
struct switch_io_event_hook_recv_dtmf * next
Node in which to store custom kill channel callback hooks.
const char * interface_name
switch_io_kill_channel_t kill_channel
int switch_plc_fillin(switch_plc_state_t *s, int16_t amp[], int len)
time_t switch_epoch_time_now(time_t *t)
Get the current epoch time.
switch_ivr_dmachine_t * dmachine[2]
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_stristr(const char *instr, const char *str)
A table of settings and callbacks that define a paticular implementation of a codec.
switch_channel_callstate_t switch_channel_get_callstate(switch_channel_t *channel)
switch_endpoint_interface_t * endpoint_interface
uint32_t switch_core_media_bug_test_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag)
Test for the existance of a flag on an media bug.
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
switch_status_t switch_core_session_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
void switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Clear given flag(s) from a channel.
#define switch_channel_set_variable(_channel, _var, _val)
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
Node in which to store custom recv dtmf channel callback hooks.
#define SWITCH_BUFFER_BLOCK_FRAMES
switch_size_t switch_buffer_inuse(_In_ switch_buffer_t *buffer)
Get the in use amount of a switch_buffer_t.
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_status_t switch_core_session_recv_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
#define SWITCH_READ_ACCEPTABLE(status)
#define switch_resample_create(_n, _fr, _tr, _ts, _q, _c)
uint32_t switch_resample_process(switch_audio_resampler_t *resampler, int16_t *src, uint32_t srclen)
Resample one float buffer into another using specifications of a given handle.
uint32_t read_frame_count
switch_status_t switch_channel_dtmf_unlock(switch_channel_t *channel)