2007-03-29 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2010-02-06 03:38:24 +00:00
|
|
|
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_core.h -- Core Library Private Data (not to be installed into the system)
|
|
|
|
* If the last line didn't make sense, stop reading this file, go away!,
|
|
|
|
* this file does not exist!!!!
|
|
|
|
*
|
|
|
|
*/
|
2010-12-10 23:58:24 +00:00
|
|
|
#define SPANDSP_NO_TIFF 1
|
2010-12-10 23:47:24 +00:00
|
|
|
#include "spandsp.h"
|
2010-03-10 20:21:34 +00:00
|
|
|
#include "switch_profile.h"
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
#include <switch_private.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* for apr_pool_create and apr_pool_destroy */
|
|
|
|
/* functions only used in this file so not exposed */
|
|
|
|
#include <apr_pools.h>
|
|
|
|
|
|
|
|
/* for apr_hash_make, apr_hash_pool_get, apr_hash_set */
|
|
|
|
/* functions only used in this file so not exposed */
|
|
|
|
#include <apr_hash.h>
|
|
|
|
|
|
|
|
/* for apr_pvsprintf */
|
|
|
|
/* function only used in this file so not exposed */
|
|
|
|
#include <apr_strings.h>
|
|
|
|
|
|
|
|
/* for apr_initialize and apr_terminate */
|
|
|
|
/* function only used in this file so not exposed */
|
|
|
|
#include <apr_general.h>
|
|
|
|
|
|
|
|
#include <apr_portable.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_MLOCKALL
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-03 17:08:46 +00:00
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-23 15:56:23 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
/* setuid, setgid */
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* getgrnam, getpwnam */
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2009-12-28 22:04:50 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
/* #define DEBUG_ALLOC */
|
|
|
|
#define DO_EVENTS
|
|
|
|
|
|
|
|
#define SWITCH_EVENT_QUEUE_LEN 256
|
|
|
|
#define SWITCH_MESSAGE_QUEUE_LEN 256
|
2008-02-11 16:49:07 +00:00
|
|
|
#define SWITCH_SQL_QUEUE_LEN 100000
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
#define SWITCH_BUFFER_BLOCK_FRAMES 25
|
|
|
|
#define SWITCH_BUFFER_START_FRAMES 50
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SSF_NONE = 0,
|
2008-05-13 20:36:23 +00:00
|
|
|
SSF_DESTROYED = (1 << 0),
|
2009-09-14 20:10:58 +00:00
|
|
|
SSF_WARN_TRANSCODE = (1 << 1),
|
2010-05-03 17:29:56 +00:00
|
|
|
SSF_HANGUP = (1 << 2),
|
|
|
|
SSF_THREAD_STARTED = (1 << 3),
|
2010-05-05 21:05:16 +00:00
|
|
|
SSF_THREAD_RUNNING = (1 << 4),
|
|
|
|
SSF_READ_TRANSCODE = (1 << 5),
|
|
|
|
SSF_WRITE_TRANSCODE = (1 << 6),
|
|
|
|
SSF_READ_CODEC_RESET = (1 << 7),
|
|
|
|
SSF_WRITE_CODEC_RESET = (1 << 8)
|
2007-03-29 22:34:40 +00:00
|
|
|
} switch_session_flag_t;
|
|
|
|
|
|
|
|
|
|
|
|
struct switch_core_session {
|
2008-02-25 16:35:19 +00:00
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
switch_thread_t *thread;
|
2009-09-14 20:10:58 +00:00
|
|
|
switch_thread_id_t thread_id;
|
2008-11-13 17:40:25 +00:00
|
|
|
switch_endpoint_interface_t *endpoint_interface;
|
2007-04-22 01:25:02 +00:00
|
|
|
switch_size_t id;
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_session_flag_t flags;
|
|
|
|
switch_channel_t *channel;
|
2008-02-25 16:35:19 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_io_event_hooks_t event_hooks;
|
|
|
|
switch_codec_t *read_codec;
|
2008-07-09 16:44:19 +00:00
|
|
|
switch_codec_t *real_read_codec;
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_codec_t *write_codec;
|
2008-07-09 16:44:19 +00:00
|
|
|
switch_codec_t *real_write_codec;
|
2008-02-09 00:38:23 +00:00
|
|
|
switch_codec_t *video_read_codec;
|
|
|
|
switch_codec_t *video_write_codec;
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2008-10-16 16:34:52 +00:00
|
|
|
switch_codec_implementation_t read_impl;
|
|
|
|
switch_codec_implementation_t write_impl;
|
|
|
|
switch_codec_implementation_t video_read_impl;
|
|
|
|
switch_codec_implementation_t video_write_impl;
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_audio_resampler_t *read_resampler;
|
|
|
|
switch_audio_resampler_t *write_resampler;
|
|
|
|
|
|
|
|
switch_mutex_t *mutex;
|
2008-01-04 00:19:09 +00:00
|
|
|
switch_mutex_t *resample_mutex;
|
2008-11-21 00:09:11 +00:00
|
|
|
switch_mutex_t *codec_read_mutex;
|
|
|
|
switch_mutex_t *codec_write_mutex;
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_thread_cond_t *cond;
|
2010-03-22 16:22:19 +00:00
|
|
|
switch_mutex_t *frame_read_mutex;
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
switch_thread_rwlock_t *rwlock;
|
2010-11-30 21:34:22 +00:00
|
|
|
switch_thread_rwlock_t *io_rwlock;
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
void *streams[SWITCH_MAX_STREAMS];
|
|
|
|
int stream_count;
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
2007-03-29 22:34:40 +00:00
|
|
|
void *private_info;
|
|
|
|
switch_queue_t *event_queue;
|
|
|
|
switch_queue_t *message_queue;
|
|
|
|
switch_queue_t *private_event_queue;
|
2009-12-10 01:29:02 +00:00
|
|
|
switch_queue_t *private_event_queue_pri;
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_thread_rwlock_t *bug_rwlock;
|
|
|
|
switch_media_bug_t *bugs;
|
2007-04-21 01:03:58 +00:00
|
|
|
switch_app_log_t *app_log;
|
2007-04-29 03:42:38 +00:00
|
|
|
uint32_t stack_count;
|
2008-02-25 16:35:19 +00:00
|
|
|
|
|
|
|
switch_buffer_t *raw_write_buffer;
|
|
|
|
switch_frame_t raw_write_frame;
|
|
|
|
switch_frame_t enc_write_frame;
|
|
|
|
uint8_t raw_write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
|
|
|
uint8_t enc_write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
|
|
|
|
|
|
|
switch_buffer_t *raw_read_buffer;
|
|
|
|
switch_frame_t raw_read_frame;
|
|
|
|
switch_frame_t enc_read_frame;
|
|
|
|
uint8_t raw_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
|
|
|
uint8_t enc_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
2008-03-17 23:26:38 +00:00
|
|
|
switch_codec_t bug_codec;
|
2008-10-07 21:03:37 +00:00
|
|
|
uint32_t read_frame_count;
|
|
|
|
uint32_t track_duration;
|
2008-10-21 16:22:38 +00:00
|
|
|
uint32_t track_id;
|
2010-01-20 19:19:48 +00:00
|
|
|
switch_log_level_t loglevel;
|
2010-07-15 06:00:08 +00:00
|
|
|
uint32_t soft_lock;
|
2010-10-07 23:30:07 +00:00
|
|
|
switch_ivr_dmachine_t *dmachine;
|
2010-12-10 23:47:24 +00:00
|
|
|
plc_state_t *plc;
|
2007-03-29 22:34:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct switch_media_bug {
|
|
|
|
switch_buffer_t *raw_write_buffer;
|
|
|
|
switch_buffer_t *raw_read_buffer;
|
2007-06-13 03:09:53 +00:00
|
|
|
switch_frame_t *read_replace_frame_in;
|
|
|
|
switch_frame_t *read_replace_frame_out;
|
|
|
|
switch_frame_t *write_replace_frame_in;
|
|
|
|
switch_frame_t *write_replace_frame_out;
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_media_bug_callback_t callback;
|
|
|
|
switch_mutex_t *read_mutex;
|
|
|
|
switch_mutex_t *write_mutex;
|
|
|
|
switch_core_session_t *session;
|
|
|
|
void *user_data;
|
|
|
|
uint32_t flags;
|
|
|
|
uint8_t ready;
|
2008-02-01 19:20:22 +00:00
|
|
|
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
|
|
|
int16_t tmp[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
2007-05-31 14:42:23 +00:00
|
|
|
time_t stop_time;
|
2008-01-21 17:14:43 +00:00
|
|
|
switch_thread_id_t thread_id;
|
2010-03-02 01:11:15 +00:00
|
|
|
char *function;
|
|
|
|
char *target;
|
2007-03-29 22:34:40 +00:00
|
|
|
struct switch_media_bug *next;
|
|
|
|
};
|
|
|
|
|
2010-10-21 21:18:54 +00:00
|
|
|
typedef enum {
|
|
|
|
DBTYPE_DEFAULT = 0,
|
|
|
|
DBTYPE_MSSQL = 1,
|
|
|
|
} switch_dbtype_t;
|
|
|
|
|
2007-05-10 16:56:29 +00:00
|
|
|
struct switch_runtime {
|
|
|
|
switch_time_t initiated;
|
2008-01-11 00:43:49 +00:00
|
|
|
switch_time_t reference;
|
|
|
|
int64_t offset;
|
2010-05-25 21:54:13 +00:00
|
|
|
switch_event_t *global_vars;
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_hash_t *mime_types;
|
2010-10-08 22:04:22 +00:00
|
|
|
switch_hash_t *ptimes;
|
2007-05-10 16:56:29 +00:00
|
|
|
switch_memory_pool_t *memory_pool;
|
|
|
|
const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS];
|
|
|
|
int state_handler_index;
|
|
|
|
FILE *console;
|
|
|
|
uint8_t running;
|
|
|
|
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
2007-09-29 01:06:08 +00:00
|
|
|
uint32_t flags;
|
2007-10-03 16:44:11 +00:00
|
|
|
switch_time_t timestamp;
|
2009-12-28 22:04:50 +00:00
|
|
|
switch_mutex_t *uuid_mutex;
|
2007-10-03 16:44:11 +00:00
|
|
|
switch_mutex_t *throttle_mutex;
|
2009-03-07 17:45:37 +00:00
|
|
|
switch_mutex_t *session_hash_mutex;
|
2007-12-22 00:32:20 +00:00
|
|
|
switch_mutex_t *global_mutex;
|
2009-02-13 00:32:58 +00:00
|
|
|
switch_mutex_t *global_var_mutex;
|
2007-10-03 16:44:11 +00:00
|
|
|
uint32_t sps_total;
|
|
|
|
int32_t sps;
|
2007-10-04 21:35:50 +00:00
|
|
|
int32_t sps_last;
|
2007-10-04 13:17:56 +00:00
|
|
|
switch_log_level_t hard_log_level;
|
2007-11-05 18:45:26 +00:00
|
|
|
char *mailer_app;
|
|
|
|
char *mailer_app_args;
|
2008-04-18 17:03:34 +00:00
|
|
|
uint32_t max_dtmf_duration;
|
2009-09-16 21:24:22 +00:00
|
|
|
uint32_t min_dtmf_duration;
|
2008-04-18 17:03:34 +00:00
|
|
|
uint32_t default_dtmf_duration;
|
2008-05-06 21:05:38 +00:00
|
|
|
switch_frame_t dummy_cng_frame;
|
|
|
|
char dummy_data[5];
|
2008-07-11 14:35:08 +00:00
|
|
|
switch_bool_t colorize_console;
|
2009-11-17 00:12:54 +00:00
|
|
|
char *odbc_dsn;
|
|
|
|
char *odbc_user;
|
|
|
|
char *odbc_pass;
|
2009-11-20 23:12:07 +00:00
|
|
|
uint32_t debug_level;
|
2010-01-04 19:03:43 +00:00
|
|
|
uint32_t runlevel;
|
2010-01-14 16:02:46 +00:00
|
|
|
uint32_t tipping_point;
|
2010-02-18 20:02:03 +00:00
|
|
|
int32_t timer_affinity;
|
2010-03-10 20:21:34 +00:00
|
|
|
switch_profile_timer_t *profile_timer;
|
|
|
|
double profile_time;
|
|
|
|
double min_idle_time;
|
2010-09-14 21:19:03 +00:00
|
|
|
int sql_buffer_len;
|
|
|
|
int max_sql_buffer_len;
|
2010-10-21 21:18:54 +00:00
|
|
|
switch_dbtype_t odbc_dbtype;
|
2007-05-10 16:56:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct switch_runtime runtime;
|
|
|
|
|
2009-12-30 20:55:04 +00:00
|
|
|
|
|
|
|
struct switch_session_manager {
|
|
|
|
switch_memory_pool_t *memory_pool;
|
|
|
|
switch_hash_t *session_table;
|
|
|
|
uint32_t session_count;
|
|
|
|
uint32_t session_limit;
|
|
|
|
switch_size_t session_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct switch_session_manager session_manager;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 00:12:54 +00:00
|
|
|
switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage);
|
2007-03-30 02:20:13 +00:00
|
|
|
void switch_core_sqldb_stop(void);
|
|
|
|
void switch_core_session_init(switch_memory_pool_t *pool);
|
2007-09-29 01:06:08 +00:00
|
|
|
void switch_core_session_uninit(void);
|
2007-03-30 02:20:13 +00:00
|
|
|
void switch_core_state_machine_init(switch_memory_pool_t *pool);
|
|
|
|
switch_memory_pool_t *switch_core_memory_init(void);
|
2007-09-29 01:06:08 +00:00
|
|
|
void switch_core_memory_stop(void);
|