2007-03-29 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2009-02-04 21:20:54 +00:00
|
|
|
* Copyright (C) 2005/2006, 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!!!!
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#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
|
|
|
|
|
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),
|
|
|
|
SSF_WARN_TRANSCODE = (1 << 1)
|
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;
|
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;
|
|
|
|
int thread_running;
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch_thread_rwlock_t *rwlock;
|
|
|
|
|
|
|
|
void *streams[SWITCH_MAX_STREAMS];
|
|
|
|
int stream_count;
|
|
|
|
|
|
|
|
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
|
|
|
void *private_info;
|
|
|
|
switch_queue_t *event_queue;
|
|
|
|
switch_queue_t *message_queue;
|
|
|
|
switch_queue_t *private_event_queue;
|
|
|
|
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;
|
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;
|
2007-03-29 22:34:40 +00:00
|
|
|
struct switch_media_bug *next;
|
|
|
|
};
|
|
|
|
|
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;
|
2007-05-10 16:56:29 +00:00
|
|
|
switch_hash_t *global_vars;
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_hash_t *mime_types;
|
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;
|
|
|
|
switch_mutex_t *throttle_mutex;
|
2007-12-22 00:32:20 +00:00
|
|
|
switch_mutex_t *global_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;
|
|
|
|
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;
|
2007-05-10 16:56:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct switch_runtime runtime;
|
|
|
|
|
2007-03-30 02:20:13 +00:00
|
|
|
void switch_core_sqldb_start(switch_memory_pool_t *pool);
|
|
|
|
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);
|