TFLAG_CLEAR = (1 << 10)
} TFLAGS;
-struct private_object {
+struct loopback_private_object {
unsigned int flags;
switch_mutex_t *flag_mutex;
switch_mutex_t *mutex;
switch_core_session_t *session;
switch_channel_t *channel;
switch_core_session_t *other_session;
- struct private_object *other_tech_pvt;
+ struct loopback_private_object *other_tech_pvt;
switch_channel_t *other_channel;
switch_codec_t read_codec;
switch_codec_t write_codec;
int first_cng;
};
-typedef struct private_object private_t;
+typedef struct loopback_private_object loopback_private_t;
static struct {
int debug;
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
-static void clear_queue(private_t *tech_pvt)
+static void clear_queue(loopback_private_t *tech_pvt)
{
void *pop;
}
-static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, switch_codec_t *codec)
+static switch_status_t tech_init(loopback_private_t *tech_pvt, switch_core_session_t *session, switch_codec_t *codec)
{
const char *iananame = "L16";
uint32_t rate = 8000;
static switch_status_t channel_on_init(switch_core_session_t *session)
{
switch_channel_t *channel, *b_channel;
- private_t *tech_pvt = NULL, *b_tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL, *b_tech_pvt = NULL;
switch_core_session_t *b_session;
char name[128];
switch_caller_profile_t *caller_profile;
switch_core_session_add_stream(b_session, NULL);
b_channel = switch_core_session_get_channel(b_session);
- b_tech_pvt = (private_t *) switch_core_session_alloc(b_session, sizeof(*b_tech_pvt));
+ b_tech_pvt = (loopback_private_t *) switch_core_session_alloc(b_session, sizeof(*b_tech_pvt));
switch_snprintf(name, sizeof(name), "loopback/%s-b", tech_pvt->caller_profile->destination_number);
switch_channel_set_name(b_channel, name);
b_tech_pvt->caller_profile = caller_profile;
switch_channel_set_state(b_channel, CS_INIT);
+ switch_mutex_lock(tech_pvt->mutex);
tech_pvt->other_session = b_session;
tech_pvt->other_tech_pvt = b_tech_pvt;
tech_pvt->other_channel = b_channel;
+ switch_mutex_unlock(tech_pvt->mutex);
//b_tech_pvt->other_session = session;
//b_tech_pvt->other_tech_pvt = tech_pvt;
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
goto end;
}
- } else if ((tech_pvt->other_session = switch_core_session_locate(tech_pvt->other_uuid))) {
- tech_pvt->other_tech_pvt = switch_core_session_get_private(tech_pvt->other_session);
- tech_pvt->other_channel = switch_core_session_get_channel(tech_pvt->other_session);
+ } else {
+ switch_mutex_lock(tech_pvt->mutex);
+ if ((tech_pvt->other_session = switch_core_session_locate(tech_pvt->other_uuid))) {
+ tech_pvt->other_tech_pvt = switch_core_session_get_private(tech_pvt->other_session);
+ tech_pvt->other_channel = switch_core_session_get_channel(tech_pvt->other_session);
+ }
+ switch_mutex_unlock(tech_pvt->mutex);
}
if (!tech_pvt->other_session) {
return SWITCH_STATUS_SUCCESS;
}
-static void do_reset(private_t *tech_pvt)
+static void do_reset(loopback_private_t *tech_pvt)
{
switch_clear_flag_locked(tech_pvt, TFLAG_WRITE);
static switch_status_t channel_on_routing(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
const char *app, *arg;
channel = switch_core_session_get_channel(session);
static switch_status_t channel_on_execute(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
switch_caller_extension_t *exten;
int bow = 0;
static switch_status_t channel_on_destroy(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
void *pop;
switch_event_t *vars;
static switch_status_t channel_on_hangup(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_LINKED);
switch_mutex_lock(tech_pvt->mutex);
+
if (tech_pvt->other_tech_pvt) {
switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);
+ if (tech_pvt->other_tech_pvt->session && tech_pvt->other_tech_pvt->session != tech_pvt->other_session) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "OTHER SESSION MISMATCH????\n");
+ tech_pvt->other_session = tech_pvt->other_tech_pvt->session;
+ }
tech_pvt->other_tech_pvt = NULL;
}
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
static switch_status_t channel_on_exchange_media(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
static switch_status_t channel_on_reset(switch_core_session_t *session)
{
- private_t *tech_pvt = (private_t *) switch_core_session_get_private(session);
+ loopback_private_t *tech_pvt = (loopback_private_t *) switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
do_reset(tech_pvt);
static switch_status_t channel_on_consume_media(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
{
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
tech_pvt = switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_t *mutex = NULL;
void *pop = NULL;
while (a_uuid && (sp = switch_core_session_locate(a_uuid))) {
if (switch_core_session_check_interface(sp, loopback_endpoint_interface)) {
- private_t *tech_pvt;
+ loopback_private_t *tech_pvt;
switch_channel_t *spchan = switch_core_session_get_channel(sp);
switch_channel_wait_for_state_or_greater(spchan, channel, CS_ROUTING);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
channel = switch_core_session_get_channel(session);
static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
{
switch_channel_t *channel;
- private_t *tech_pvt;
+ loopback_private_t *tech_pvt;
int done = 1, pass = 0;
channel = switch_core_session_get_channel(session);
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_state_t state = switch_channel_get_state(channel);
- private_t *tech_pvt = NULL;
+ loopback_private_t *tech_pvt = NULL;
if (state == CS_EXECUTE) {
}
if ((*new_session = switch_core_session_request(loopback_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, flags, pool)) != 0) {
- private_t *tech_pvt;
+ loopback_private_t *tech_pvt;
switch_channel_t *channel;
switch_caller_profile_t *caller_profile;
switch_event_t *clone = NULL;
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
+ if ((tech_pvt = (loopback_private_t *) switch_core_session_alloc(*new_session, sizeof(loopback_private_t))) != 0) {
channel = switch_core_session_get_channel(*new_session);
switch_snprintf(name, sizeof(name), "loopback/%s-a", outbound_profile->destination_number);
switch_channel_set_name(channel, name);