From 208ec3ff7a644107658e71722caad403eae6f7e1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Jan 2006 18:40:56 +0000 Subject: [PATCH] stream id stuff git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@307 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core.h | 43 ++++++++++-- src/include/switch_module_interfaces.h | 8 +-- src/include/switch_types.h | 10 +-- src/mod/endpoints/mod_exosip/mod_exosip.c | 15 ++-- .../endpoints/mod_exosip/mod_exosip_ccrtp.c | 3 +- src/mod/endpoints/mod_exosip/mod_exosip_ucl.c | 3 +- src/mod/endpoints/mod_iaxchan/mod_iaxchan.c | 14 ++-- src/mod/endpoints/mod_opalchan/mod_opalchan.c | 13 ++-- .../endpoints/mod_portaudio/mod_portaudio.c | 15 ++-- src/mod/endpoints/mod_wanchan/mod_wanchan.c | 9 +-- .../mod_woomerachan/mod_woomerachan.c | 16 +++-- src/switch_core.c | 69 +++++++++++++------ 12 files changed, 144 insertions(+), 74 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index f2e891ce8a..ff97cb9817 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -44,14 +44,15 @@ extern "C" { #include -#define MAX_CORE_THREAD_SESSION_OBJS 128 +#define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128 +#define SWITCH_MAX_STREAMS 128 /*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */ struct switch_core_thread_session { /*! status of the thread */ int running; /*! array of void pointers to pass mutiple data objects */ - void *objs[MAX_CORE_THREAD_SESSION_OBJS]; + void *objs[SWITCH_MAX_CORE_THREAD_SESSION_OBJS]; /*! a pointer to a memory pool if the thread has it's own pool */ switch_memory_pool *pool; }; @@ -227,6 +228,29 @@ SWITCH_DECLARE(void *) switch_core_session_get_private(switch_core_session *sess */ SWITCH_DECLARE(switch_status) switch_core_session_set_private(switch_core_session *session, void *private); +/*! + \brief Add a logical stream to a session + \param session the session to add the stream to + \param private an optional pointer to private data for the new stream + \return the stream id of the new stream + */ +SWITCH_DECLARE(int) switch_core_session_add_stream(switch_core_session *session, void *private); + +/*! + \brief Retreive a logical stream from a session + \param session the session to add the stream to + \param index the index to retrieve + \return the private data (if any) + */ +SWITCH_DECLARE(void *) switch_core_session_get_stream(switch_core_session *session, int index); + +/*! + \brief Determine the number of logical streams a session has + \param session the session to query + \return the total number of logical streams + */ +SWITCH_DECLARE(int) switch_core_session_get_stream_count(switch_core_session *session); + /*! \brief Launch a thread designed to exist within the scope of a given session \param session a session to allocate the thread from @@ -244,9 +268,10 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session * /*! \brief Launch a service thread on a session to drop inbound data \param session the session the launch thread on + \param stream_id which logical media channel to use \param thread_session the thread_session to use */ -SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, switch_core_thread_session *thread_session); +SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, switch_core_thread_session *thread_session, int stream_id); /*! \brief Request an outgoing session spawned from an existing session using a desired endpoing module @@ -273,18 +298,20 @@ SWITCH_DECLARE(switch_status) switch_core_session_answer_channel(switch_core_ses \param session the session to read from \param frame a NULL pointer to a frame to aim at the newly read frame \param timeout number of milliseconds to wait for data + \param stream_id which logical media channel to use \return SWITCH_STATUS_SUCCESS a the frame was read */ -SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, int timeout); +SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, int timeout, int stream_id); /*! \brief Write a frame to a session \param session the session to write to \param frame the frame to write \param timeout number of milliseconds to wait for data + \param stream_id which logical media channel to use \return SWITCH_STATUS_SUCCESS a the frame was written */ -SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, int timeout); +SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, int timeout, int stream_id); /*! \brief Send a signal to a channel @@ -298,17 +325,19 @@ SWITCH_DECLARE(switch_status) switch_core_session_kill_channel(switch_core_sessi \brief Wait for a session to be ready for input \param session session to wait for \param timeout number of milliseconds to wait for data + \param stream_id which logical media channel to use \return SWITCH_STATUS_SUCCESS if data is available for read within timeframe specified */ -SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_session *session, int timeout); +SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_session *session, int timeout, int stream_id); /*! \brief Wait for a session to be ready for output \param session session to wait for \param timeout number of milliseconds to wait for data + \param stream_id which logical media channel to use \return SWITCH_STATUS_SUCCESS if the session is available for write within timeframe specified */ -SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout); +SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout, int stream_id); /*! \brief Send DTMF to a session diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index b1eadf9f79..057da07edc 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -145,15 +145,15 @@ struct switch_io_routines { /*! answers the given session's channel */ switch_status (*answer_channel)(switch_core_session *); /*! read a frame from a session */ - switch_status (*read_frame)(switch_core_session *, switch_frame **, int, switch_io_flag); + switch_status (*read_frame)(switch_core_session *, switch_frame **, int, switch_io_flag, int); /*! write a frame to a session */ - switch_status (*write_frame)(switch_core_session *, switch_frame *, int, switch_io_flag); + switch_status (*write_frame)(switch_core_session *, switch_frame *, int, switch_io_flag, int); /*! send a kill signal to the session's channel */ switch_status (*kill_channel)(switch_core_session *, int); /*! wait for the session's channel to be ready to read audio */ - switch_status (*waitfor_read)(switch_core_session *, int); + switch_status (*waitfor_read)(switch_core_session *, int, int); /*! wait for the session's channel to be ready to write audio */ - switch_status (*waitfor_write)(switch_core_session *, int); + switch_status (*waitfor_write)(switch_core_session *, int, int); /*! send a string of DTMF digits to a session's channel */ switch_status (*send_dtmf)(switch_core_session *, char *); }; diff --git a/src/include/switch_types.h b/src/include/switch_types.h index b44f08bbb2..e1c380706a 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -228,7 +228,7 @@ SWITCH_FILE_DATA_SHORT = (1 << 3) - Read data in shorts SWITCH_FILE_DATA_INT = (1 << 4) - Read data in ints SWITCH_FILE_DATA_FLOAT = (1 << 5) - Read data in floats SWITCH_FILE_DATA_DOUBLE = (1 << 6) - Read data in doubles -SWITCH_FILE_DATA_RAW = (1 << 7) - Read data asis +SWITCH_FILE_DATA_RAW = (1 << 7) - Read data as is */ typedef enum { @@ -329,11 +329,11 @@ typedef switch_caller_extension *(*switch_dialplan_hunt_function)(switch_core_se typedef switch_status (*switch_event_handler)(switch_core_session *); typedef switch_status (*switch_outgoing_channel_hook)(switch_core_session *, switch_caller_profile *, switch_core_session *); typedef switch_status (*switch_answer_channel_hook)(switch_core_session *); -typedef switch_status (*switch_read_frame_hook)(switch_core_session *, switch_frame **, int, switch_io_flag); -typedef switch_status (*switch_write_frame_hook)(switch_core_session *, switch_frame *, int, switch_io_flag); +typedef switch_status (*switch_read_frame_hook)(switch_core_session *, switch_frame **, int, switch_io_flag, int); +typedef switch_status (*switch_write_frame_hook)(switch_core_session *, switch_frame *, int, switch_io_flag, int); typedef switch_status (*switch_kill_channel_hook)(switch_core_session *, int); -typedef switch_status (*switch_waitfor_read_hook)(switch_core_session *, int); -typedef switch_status (*switch_waitfor_write_hook)(switch_core_session *, int); +typedef switch_status (*switch_waitfor_read_hook)(switch_core_session *, int, int); +typedef switch_status (*switch_waitfor_write_hook)(switch_core_session *, int, int); typedef switch_status (*switch_send_dtmf_hook)(switch_core_session *, char *); typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen); diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index 5f798d34f7..611116022b 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -145,8 +145,8 @@ static switch_status exosip_on_hangup(switch_core_session *session); static switch_status exosip_on_loopback(switch_core_session *session); static switch_status exosip_on_transmit(switch_core_session *session); static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); static int config_exosip(int reload); static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload); static switch_status exosip_kill_channel(switch_core_session *session, int sig); @@ -368,6 +368,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc struct private_object *tech_pvt; switch_channel *channel; + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); @@ -520,7 +521,7 @@ static switch_status exosip_answer_channel(switch_core_session *session) } -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) { struct private_object *tech_pvt = NULL; size_t bytes = 0, samples = 0, frames=0, ms=0; @@ -597,7 +598,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram } -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -668,7 +669,7 @@ static switch_status exosip_kill_channel(switch_core_session *session, int sig) } -static switch_status exosip_waitfor_read(switch_core_session *session, int ms) +static switch_status exosip_waitfor_read(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -683,7 +684,7 @@ static switch_status exosip_waitfor_read(switch_core_session *session, int ms) } -static switch_status exosip_waitfor_write(switch_core_session *session, int ms) +static switch_status exosip_waitfor_write(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -779,7 +780,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) switch_codec_interface *codecs[SWITCH_MAX_CODECS]; int num_codecs = 0; - + switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(session); diff --git a/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c b/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c index 4d895ca0fc..751d33c128 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c @@ -369,6 +369,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_channel *channel, *orig_channel; switch_caller_profile *caller_profile, *originator_caller_profile = NULL; + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); @@ -771,7 +772,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) switch_codec_interface *codecs[512]; int num_codecs = 0; - + switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(session); diff --git a/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c b/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c index 54c3b0364c..dca8a34789 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c @@ -385,6 +385,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_channel *channel, *orig_channel; switch_caller_profile *caller_profile, *originator_caller_profile = NULL; + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); @@ -838,7 +839,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) switch_codec_interface *codecs[512]; int num_codecs = 0; - + switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(session); diff --git a/src/mod/endpoints/mod_iaxchan/mod_iaxchan.c b/src/mod/endpoints/mod_iaxchan/mod_iaxchan.c index b86a62598f..6a4deb9fe4 100644 --- a/src/mod/endpoints/mod_iaxchan/mod_iaxchan.c +++ b/src/mod/endpoints/mod_iaxchan/mod_iaxchan.c @@ -325,8 +325,8 @@ static switch_status channel_on_ring(switch_core_session *session); static switch_status channel_on_loopback(switch_core_session *session); static switch_status channel_on_transmit(switch_core_session *session); static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); static switch_status channel_kill_channel(switch_core_session *session, int sig); @@ -490,6 +490,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit switch_caller_profile *caller_profile; unsigned int req = 0, cap = 0; + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); @@ -543,7 +544,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit } -static switch_status channel_waitfor_read(switch_core_session *session, int ms) +static switch_status channel_waitfor_read(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -553,7 +554,7 @@ static switch_status channel_waitfor_read(switch_core_session *session, int ms) return SWITCH_STATUS_SUCCESS; } -static switch_status channel_waitfor_write(switch_core_session *session, int ms) +static switch_status channel_waitfor_write(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -580,7 +581,7 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf) return SWITCH_STATUS_SUCCESS; } -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -613,7 +614,7 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra return SWITCH_STATUS_FALSE; } -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -861,6 +862,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) struct private_object *tech_pvt; switch_channel *channel; + switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(session); diff --git a/src/mod/endpoints/mod_opalchan/mod_opalchan.c b/src/mod/endpoints/mod_opalchan/mod_opalchan.c index 8aae7ecb7d..8b251fa2e7 100644 --- a/src/mod/endpoints/mod_opalchan/mod_opalchan.c +++ b/src/mod/endpoints/mod_opalchan/mod_opalchan.c @@ -66,8 +66,8 @@ static switch_status channel_on_ring(switch_core_session *session); static switch_status channel_on_loopback(switch_core_session *session); static switch_status channel_on_transmit(switch_core_session *session); static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); static switch_status channel_kill_channel(switch_core_session *session, int sig); @@ -184,6 +184,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit switch_channel *channel, *orig_channel; switch_caller_profile *caller_profile, *originator_caller_profile = NULL; + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); @@ -228,7 +229,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit } -static switch_status channel_waitfor_read(switch_core_session *session, int ms) +static switch_status channel_waitfor_read(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -238,7 +239,7 @@ static switch_status channel_waitfor_read(switch_core_session *session, int ms) return SWITCH_STATUS_SUCCESS; } -static switch_status channel_waitfor_write(switch_core_session *session, int ms) +static switch_status channel_waitfor_write(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -249,7 +250,7 @@ static switch_status channel_waitfor_write(switch_core_session *session, int ms) } -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -265,7 +266,7 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra return SWITCH_STATUS_SUCCESS; } -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 51e7ec29bd..b716cca52f 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -107,8 +107,8 @@ static switch_status channel_on_ring(switch_core_session *session); static switch_status channel_on_loopback(switch_core_session *session); static switch_status channel_on_transmit(switch_core_session *session); static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); static switch_status channel_kill_channel(switch_core_session *session, int sig); static switch_status engage_device(struct private_object *tech_pvt); static int dump_info(void); @@ -300,6 +300,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit switch_channel *channel; switch_caller_profile *caller_profile; + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); @@ -334,7 +335,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit } -static switch_status channel_waitfor_read(switch_core_session *session, int ms) +static switch_status channel_waitfor_read(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -344,7 +345,7 @@ static switch_status channel_waitfor_read(switch_core_session *session, int ms) return SWITCH_STATUS_SUCCESS; } -static switch_status channel_waitfor_write(switch_core_session *session, int ms) +static switch_status channel_waitfor_write(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -367,7 +368,7 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf) return SWITCH_STATUS_SUCCESS; } -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -398,7 +399,7 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra return status; } -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -778,6 +779,8 @@ static switch_status place_call(char *dest, char *out, size_t outlen) if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) { struct private_object *tech_pvt; switch_channel *channel; + + switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(session); diff --git a/src/mod/endpoints/mod_wanchan/mod_wanchan.c b/src/mod/endpoints/mod_wanchan/mod_wanchan.c index 3fd8080084..3d2ee40758 100644 --- a/src/mod/endpoints/mod_wanchan/mod_wanchan.c +++ b/src/mod/endpoints/mod_wanchan/mod_wanchan.c @@ -154,8 +154,8 @@ static switch_status wanchan_on_hangup(switch_core_session *session); static switch_status wanchan_on_loopback(switch_core_session *session); static switch_status wanchan_on_transmit(switch_core_session *session); static switch_status wanchan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status wanchan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status wanchan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status wanchan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status wanchan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); @@ -266,7 +266,7 @@ static switch_status wanchan_answer_channel(switch_core_session *session) -static switch_status wanchan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status wanchan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -312,7 +312,7 @@ static switch_status wanchan_read_frame(switch_core_session *session, switch_fra return SWITCH_STATUS_SUCCESS; } -static switch_status wanchan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status wanchan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -466,6 +466,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri char ani2str[4] = ""; //wanpipe_tdm_api_t tdm_api; + switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(session); diff --git a/src/mod/endpoints/mod_woomerachan/mod_woomerachan.c b/src/mod/endpoints/mod_woomerachan/mod_woomerachan.c index 9ecbf59f11..c3403b29d1 100644 --- a/src/mod/endpoints/mod_woomerachan/mod_woomerachan.c +++ b/src/mod/endpoints/mod_woomerachan/mod_woomerachan.c @@ -172,8 +172,8 @@ static switch_status woomerachan_on_ring(switch_core_session *session); static switch_status woomerachan_on_loopback(switch_core_session *session); static switch_status woomerachan_on_transmit(switch_core_session *session); static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); static switch_status woomerachan_kill_channel(switch_core_session *session, int sig); static void tech_destroy(private_object *tech_pvt); static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, char *fmt, ...); @@ -350,7 +350,7 @@ static switch_status woomerachan_outgoing_channel(switch_core_session *session, struct private_object *tech_pvt; switch_channel *channel; - + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); tech_pvt->profile = &default_profile; @@ -388,7 +388,7 @@ static switch_status woomerachan_outgoing_channel(switch_core_session *session, } -static switch_status woomerachan_waitfor_read(switch_core_session *session, int ms) +static switch_status woomerachan_waitfor_read(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -398,7 +398,7 @@ static switch_status woomerachan_waitfor_read(switch_core_session *session, int return switch_socket_waitfor(&tech_pvt->read_poll, ms); } -static switch_status woomerachan_waitfor_write(switch_core_session *session, int ms) +static switch_status woomerachan_waitfor_write(switch_core_session *session, int ms, int stream_id) { struct private_object *tech_pvt = NULL; @@ -409,7 +409,7 @@ static switch_status woomerachan_waitfor_write(switch_core_session *session, int return switch_socket_waitfor(&tech_pvt->write_poll, ms); } -static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -440,7 +440,7 @@ static switch_status woomerachan_read_frame(switch_core_session *session, switch return status; } -static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -1246,6 +1246,8 @@ static void *woomera_thread_run(void *obj) struct private_object *tech_pvt; switch_channel *channel; + switch_core_session_add_stream(session, NULL); + if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); tech_pvt->profile = &default_profile; diff --git a/src/switch_core.c b/src/switch_core.c index fb1f2e0f0e..84c812d420 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -78,6 +78,9 @@ struct switch_core_session { switch_mutex_t *mutex; switch_thread_cond_t *cond; + void *streams[SWITCH_MAX_STREAMS]; + int stream_count; + char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1]; void *private; }; @@ -469,6 +472,7 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj) { switch_core_thread_session *data = obj; switch_core_session *session = data->objs[0]; + int *stream_id = data->objs[1]; switch_channel *channel; switch_frame *read_frame; @@ -478,7 +482,7 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj) while(data->running > 0) { - switch(switch_core_session_read_frame(session, &read_frame, -1)) { + switch(switch_core_session_read_frame(session, &read_frame, -1, *stream_id)) { case SWITCH_STATUS_SUCCESS: break; case SWITCH_STATUS_TIMEOUT: @@ -512,10 +516,11 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session * } } -SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, switch_core_thread_session *thread_session) +SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, switch_core_thread_session *thread_session, int stream_id) { thread_session->running = 1; thread_session->objs[0] = session; + thread_session->objs[1] = &stream_id; switch_core_session_launch_thread(session, switch_core_service_thread, thread_session); } @@ -617,6 +622,23 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_private(switch_core_sessio return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(int) switch_core_session_add_stream(switch_core_session *session, void *private) +{ + session->streams[session->stream_count++] = private; + return session->stream_count - 1; +} + +SWITCH_DECLARE(void *) switch_core_session_get_stream(switch_core_session *session, int index) +{ + return session->streams[index]; +} + + +SWITCH_DECLARE(int) switch_core_session_get_stream_count(switch_core_session *session) +{ + return session->stream_count; +} + SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_session *session, char *endpoint_name, switch_caller_profile *caller_profile, @@ -690,7 +712,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_answer_channel(switch_core_ses return status; } -SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, int timeout) +SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, int timeout, int stream_id) { struct switch_io_event_hook_read_frame *ptr; switch_status status = SWITCH_STATUS_FALSE; @@ -698,9 +720,13 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session if (session->endpoint_interface->io_routines->read_frame) { - if ((status = session->endpoint_interface->io_routines->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP)) == SWITCH_STATUS_SUCCESS) { + if ((status = session->endpoint_interface->io_routines->read_frame(session, + frame, + timeout, + SWITCH_IO_FLAG_NOOP, + stream_id)) == SWITCH_STATUS_SUCCESS) { for (ptr = session->event_hooks.read_frame; ptr ; ptr = ptr->next) { - if ((status = ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP)) != SWITCH_STATUS_SUCCESS) { + if ((status = ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } } @@ -840,14 +866,14 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session return status; } -static switch_status perform_write(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) { +static switch_status perform_write(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { struct switch_io_event_hook_write_frame *ptr; switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->write_frame) { - if ((status = session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags)) == SWITCH_STATUS_SUCCESS) { + if ((status = session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags, stream_id)) == SWITCH_STATUS_SUCCESS) { for (ptr = session->event_hooks.write_frame; ptr ; ptr = ptr->next) { - if ((status = ptr->write_frame(session, frame, timeout, flags)) != SWITCH_STATUS_SUCCESS) { + if ((status = ptr->write_frame(session, frame, timeout, flags, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } } @@ -856,7 +882,7 @@ static switch_status perform_write(switch_core_session *session, switch_frame *f return status; } -SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, int timeout) +SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, int timeout, int stream_id) { switch_status status = SWITCH_STATUS_FALSE; @@ -982,7 +1008,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio break; } - status = perform_write(session, write_frame, timeout, io_flag); + status = perform_write(session, write_frame, timeout, io_flag, stream_id); return status; } else { int used = switch_buffer_inuse(session->raw_write_buffer); @@ -1056,7 +1082,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio write_frame->datalen = session->read_resampler->to_len * 2; write_frame->rate = session->read_resampler->to_rate; } - status = perform_write(session, write_frame, timeout, io_flag); + status = perform_write(session, write_frame, timeout, io_flag, stream_id); } } return status; @@ -1064,7 +1090,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio } } } else { - status = perform_write(session, frame, timeout, io_flag); + status = perform_write(session, frame, timeout, io_flag, stream_id); } return status; } @@ -1088,15 +1114,15 @@ SWITCH_DECLARE(switch_status) switch_core_session_kill_channel(switch_core_sessi } -SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_session *session, int timeout) +SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_session *session, int timeout, int stream_id) { struct switch_io_event_hook_waitfor_read *ptr; switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->waitfor_read) { - if ((status = session->endpoint_interface->io_routines->waitfor_read(session, timeout)) == SWITCH_STATUS_SUCCESS) { + if ((status = session->endpoint_interface->io_routines->waitfor_read(session, timeout, stream_id)) == SWITCH_STATUS_SUCCESS) { for (ptr = session->event_hooks.waitfor_read; ptr ; ptr = ptr->next) { - if ((status = ptr->waitfor_read(session, timeout)) != SWITCH_STATUS_SUCCESS) { + if ((status = ptr->waitfor_read(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } } @@ -1107,15 +1133,15 @@ SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_sessi } -SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout) +SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout, int stream_id) { struct switch_io_event_hook_waitfor_write *ptr; switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->waitfor_write) { - if ((status = session->endpoint_interface->io_routines->waitfor_write(session, timeout)) == SWITCH_STATUS_SUCCESS) { + if ((status = session->endpoint_interface->io_routines->waitfor_write(session, timeout, stream_id)) == SWITCH_STATUS_SUCCESS) { for (ptr = session->event_hooks.waitfor_write; ptr ; ptr = ptr->next) { - if ((status = ptr->waitfor_write(session, timeout)) != SWITCH_STATUS_SUCCESS) { + if ((status = ptr->waitfor_write(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } } @@ -1420,12 +1446,15 @@ static void switch_core_standard_on_loopback(switch_core_session *session) { switch_channel_state state; switch_frame *frame; + int stream_id; switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard LOOPBACK\n"); while ((state = switch_channel_get_state(session->channel)) == CS_LOOPBACK) { - if (switch_core_session_read_frame(session, &frame, -1) == SWITCH_STATUS_SUCCESS) { - switch_core_session_write_frame(session, frame, -1); + for(stream_id = 0; stream_id < session->stream_count; stream_id++) { + if (switch_core_session_read_frame(session, &frame, -1, stream_id) == SWITCH_STATUS_SUCCESS) { + switch_core_session_write_frame(session, frame, -1, stream_id); + } } } }