2006-01-03 22:13:59 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* 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
|
2007-08-03 03:33:50 +00:00
|
|
|
* the License. You may obtain a copy of the License `
|
2006-01-03 22:13:59 +00:00
|
|
|
* 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
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* mod_portaudio.c -- PortAudio Endpoint Module
|
|
|
|
*
|
|
|
|
*/
|
2007-06-21 22:36:04 +00:00
|
|
|
#include "switch.h"
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "pablio.h"
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define MY_EVENT_RINGING "portaudio::ringing"
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load);
|
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_portaudio, mod_portaudio_load, mod_portaudio_shutdown, NULL);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
static switch_memory_pool_t *module_pool = NULL;
|
2007-06-20 07:15:53 +00:00
|
|
|
static switch_endpoint_interface_t *channel_endpoint_interface;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
#define SAMPLE_TYPE paInt16
|
2007-06-21 22:36:04 +00:00
|
|
|
typedef int16_t SAMPLE;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
typedef switch_status_t (*pa_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-01-23 16:06:25 +00:00
|
|
|
typedef enum {
|
2007-03-29 22:31:56 +00:00
|
|
|
GFLAG_NONE = 0,
|
|
|
|
GFLAG_EAR = (1 << 0),
|
|
|
|
GFLAG_MOUTH = (1 << 1),
|
|
|
|
GFLAG_RING = (1 << 2)
|
2007-01-23 16:06:25 +00:00
|
|
|
} GFLAGS;
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
typedef enum {
|
|
|
|
TFLAG_IO = (1 << 0),
|
|
|
|
TFLAG_INBOUND = (1 << 1),
|
|
|
|
TFLAG_OUTBOUND = (1 << 2),
|
|
|
|
TFLAG_DTMF = (1 << 3),
|
|
|
|
TFLAG_VOICE = (1 << 4),
|
|
|
|
TFLAG_HANGUP = (1 << 5),
|
|
|
|
TFLAG_LINEAR = (1 << 6),
|
2007-01-17 19:10:03 +00:00
|
|
|
TFLAG_ANSWER = (1 << 7),
|
|
|
|
TFLAG_HUP = (1 << 8),
|
|
|
|
TFLAG_MASTER = (1 << 9)
|
2006-01-03 22:13:59 +00:00
|
|
|
} TFLAGS;
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
struct private_object {
|
|
|
|
unsigned int flags;
|
|
|
|
switch_core_session_t *session;
|
|
|
|
switch_caller_profile_t *caller_profile;
|
|
|
|
char call_id[50];
|
2007-03-29 22:31:56 +00:00
|
|
|
int sample_rate;
|
|
|
|
int codec_ms;
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_mutex_t *flag_mutex;
|
2007-03-29 22:31:56 +00:00
|
|
|
char *hold_file;
|
|
|
|
switch_file_handle_t fh;
|
|
|
|
switch_file_handle_t *hfh;
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_frame_t hold_frame;
|
2007-03-29 22:31:56 +00:00
|
|
|
unsigned char holdbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_codec_t write_codec;
|
2007-03-29 22:31:56 +00:00
|
|
|
struct private_object *next;
|
2007-01-17 19:10:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct private_object private_t;
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
static struct {
|
|
|
|
int debug;
|
|
|
|
int port;
|
|
|
|
char *cid_name;
|
|
|
|
char *cid_num;
|
|
|
|
char *dialplan;
|
2007-03-29 22:31:56 +00:00
|
|
|
char *ring_file;
|
|
|
|
char *hold_file;
|
|
|
|
char *timer_name;
|
2007-01-17 19:10:03 +00:00
|
|
|
int ringdev;
|
2006-01-03 22:13:59 +00:00
|
|
|
int indev;
|
|
|
|
int outdev;
|
|
|
|
int call_id;
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_hash_t *call_hash;
|
2006-01-03 22:13:59 +00:00
|
|
|
switch_mutex_t *device_lock;
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_mutex_t *pvt_lock;
|
2007-01-31 17:12:42 +00:00
|
|
|
switch_mutex_t *flag_mutex;
|
2006-01-03 22:13:59 +00:00
|
|
|
int sample_rate;
|
2007-01-17 19:10:03 +00:00
|
|
|
int codec_ms;
|
|
|
|
PABLIO_Stream *audio_stream;
|
|
|
|
PABLIO_Stream *ring_stream;
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_codec_t read_codec;
|
|
|
|
switch_codec_t write_codec;
|
|
|
|
switch_frame_t read_frame;
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_frame_t cng_frame;
|
2007-03-09 23:51:52 +00:00
|
|
|
unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
|
|
|
unsigned char cngbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *call_list;
|
|
|
|
int ring_interval;
|
|
|
|
GFLAGS flags;
|
|
|
|
switch_timer_t timer;
|
2007-01-17 19:10:03 +00:00
|
|
|
} globals;
|
|
|
|
|
|
|
|
|
|
|
|
#define PA_MASTER 1
|
|
|
|
#define PA_SLAVE 0
|
|
|
|
|
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan);
|
|
|
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name);
|
|
|
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num);
|
|
|
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ring_file, globals.ring_file);
|
|
|
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_hold_file, globals.hold_file);
|
|
|
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_timer_name, globals.timer_name);
|
2007-01-17 19:10:03 +00:00
|
|
|
#define is_master(t) switch_test_flag(t, TFLAG_MASTER)
|
2007-10-17 14:59:17 +00:00
|
|
|
|
|
|
|
static void add_pvt(private_t * tech_pvt, int master);
|
|
|
|
static void remove_pvt(private_t * tech_pvt);
|
|
|
|
static switch_status_t channel_on_init(switch_core_session_t *session);
|
|
|
|
static switch_status_t channel_on_hangup(switch_core_session_t *session);
|
|
|
|
static switch_status_t channel_on_ring(switch_core_session_t *session);
|
|
|
|
static switch_status_t channel_on_loopback(switch_core_session_t *session);
|
|
|
|
static switch_status_t channel_on_transmit(switch_core_session_t *session);
|
|
|
|
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
|
|
|
|
switch_caller_profile_t *outbound_profile,
|
|
|
|
switch_core_session_t **new_session, switch_memory_pool_t **pool);
|
|
|
|
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
|
|
|
|
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
|
|
|
|
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
|
|
|
|
static switch_status_t engage_device(int samplerate, int codec_ms);
|
|
|
|
static switch_status_t engage_ring_device(int sample_rate, int channels);
|
|
|
|
static void deactivate_ring_device(void);
|
|
|
|
static int dump_info(void);
|
|
|
|
static switch_status_t load_config(void);
|
|
|
|
static int get_dev_by_name(char *name, int in);
|
|
|
|
static int get_dev_by_number(int number, int in);
|
|
|
|
static switch_status_t pa_cmd(const char *dest, switch_core_session_t *session, switch_stream_handle_t *stream);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
State methods they get called when the state changes to the specific state
|
|
|
|
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
|
|
|
|
so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
|
|
|
|
*/
|
2007-10-17 14:59:17 +00:00
|
|
|
static switch_status_t channel_on_init(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-05-01 17:20:30 +00:00
|
|
|
switch_time_t last;
|
2007-01-17 19:10:03 +00:00
|
|
|
int waitsec = globals.ring_interval * 1000000;
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_file_handle_t fh = { 0 };
|
|
|
|
char *val, *ring_file = NULL, *hold_file = NULL;
|
|
|
|
int16_t abuf[2048];
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
2006-01-03 22:13:59 +00:00
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-10-03 16:44:11 +00:00
|
|
|
last = switch_timestamp_now() - waitsec;
|
2006-05-01 17:20:30 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-08 01:30:52 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if ((val = switch_channel_get_variable(channel, "pa_hold_file"))) {
|
|
|
|
hold_file = val;
|
|
|
|
} else {
|
|
|
|
hold_file = globals.hold_file;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (hold_file) {
|
|
|
|
tech_pvt->hold_file = switch_core_session_strdup(session, hold_file);
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2006-05-01 17:20:30 +00:00
|
|
|
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
|
|
|
|
2006-12-11 17:52:53 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT %d %d\n",
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_channel_get_name(channel), switch_channel_get_state(channel), switch_test_flag(tech_pvt, TFLAG_ANSWER));
|
2006-12-11 17:52:53 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
|
|
|
add_pvt(tech_pvt, PA_SLAVE);
|
|
|
|
|
|
|
|
ring_file = globals.ring_file;
|
|
|
|
if ((val = switch_channel_get_variable(channel, "pa_ring_file"))) {
|
|
|
|
ring_file = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_test_flag((&globals), GFLAG_RING)) {
|
|
|
|
ring_file = NULL;
|
|
|
|
}
|
|
|
|
switch_set_flag_locked((&globals), GFLAG_RING);
|
|
|
|
if (ring_file) {
|
|
|
|
if (switch_core_file_open(&fh,
|
|
|
|
ring_file,
|
2007-03-15 01:58:41 +00:00
|
|
|
globals.read_codec.implementation->number_of_channels,
|
|
|
|
globals.read_codec.implementation->samples_per_second,
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
|
2007-03-29 22:31:56 +00:00
|
|
|
|
|
|
|
if (engage_ring_device(fh.samplerate, fh.channels) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ring Error!\n");
|
|
|
|
switch_core_file_close(&fh);
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
} else {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open %s, disabling ring file!\n", ring_file);
|
2007-03-29 22:31:56 +00:00
|
|
|
ring_file = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-01 17:20:30 +00:00
|
|
|
|
2007-02-13 15:47:15 +00:00
|
|
|
switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
|
|
|
|
switch_channel_mark_ring_ready(channel);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-05-01 17:20:30 +00:00
|
|
|
while (switch_channel_get_state(channel) == CS_INIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
|
2007-07-05 18:52:19 +00:00
|
|
|
switch_size_t olen = globals.timer.samples;
|
|
|
|
|
2007-10-03 16:44:11 +00:00
|
|
|
if (switch_timestamp_now() - last >= waitsec) {
|
2006-05-01 17:20:30 +00:00
|
|
|
char buf[512];
|
|
|
|
switch_event_t *event;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-05-01 17:20:30 +00:00
|
|
|
snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id);
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) {
|
2006-12-11 17:52:53 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", "%s", buf);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call_id", "%s", tech_pvt->call_id);
|
2006-05-01 17:20:30 +00:00
|
|
|
switch_channel_event_set_data(channel, event);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
}
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", buf);
|
2007-10-03 16:44:11 +00:00
|
|
|
last = switch_timestamp_now();
|
2007-07-05 18:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ring_file) {
|
|
|
|
if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_core_file_close(&fh);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch_core_file_read(&fh, abuf, &olen);
|
|
|
|
if (olen == 0) {
|
2007-03-29 22:31:56 +00:00
|
|
|
unsigned int pos = 0;
|
|
|
|
switch_core_file_seek(&fh, &pos, 0, SEEK_SET);
|
|
|
|
}
|
2007-08-03 03:33:50 +00:00
|
|
|
if (globals.ring_stream) {
|
|
|
|
WriteAudioStream(globals.ring_stream, abuf, (long) olen, &globals.timer);
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
switch_clear_flag_locked((&globals), GFLAG_RING);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ring_file) {
|
|
|
|
deactivate_ring_device();
|
|
|
|
switch_core_file_close(&fh);
|
|
|
|
}
|
2006-05-01 17:20:30 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
|
|
|
|
switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-05-01 17:20:30 +00:00
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_IO);
|
|
|
|
|
|
|
|
/* Move Channel's State Machine to RING */
|
|
|
|
switch_channel_set_state(channel, CS_RING);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_on_ring(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel));
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_on_execute(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
static void deactivate_audio_device(void)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
|
|
|
switch_mutex_lock(globals.device_lock);
|
2007-01-17 19:10:03 +00:00
|
|
|
if (globals.audio_stream) {
|
|
|
|
CloseAudioStream(globals.audio_stream);
|
|
|
|
globals.audio_stream = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_mutex_unlock(globals.device_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void deactivate_ring_device(void)
|
|
|
|
{
|
|
|
|
switch_mutex_lock(globals.device_lock);
|
|
|
|
if (globals.ring_stream) {
|
|
|
|
CloseAudioStream(globals.ring_stream);
|
|
|
|
globals.ring_stream = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
switch_mutex_unlock(globals.device_lock);
|
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
static void add_pvt(private_t * tech_pvt, int master)
|
2007-01-17 19:10:03 +00:00
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *tp;
|
|
|
|
uint8_t in_list = 0;
|
|
|
|
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
|
|
|
|
|
|
|
if (switch_strlen_zero(tech_pvt->call_id)) {
|
|
|
|
snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", ++globals.call_id);
|
|
|
|
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
|
|
|
|
switch_core_session_set_read_codec(tech_pvt->session, &globals.read_codec);
|
|
|
|
switch_core_session_set_write_codec(tech_pvt->session, &globals.write_codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tp = globals.call_list; tp; tp = tp->next) {
|
|
|
|
if (tp == tech_pvt) {
|
|
|
|
in_list = 1;
|
|
|
|
}
|
|
|
|
if (master) {
|
|
|
|
switch_clear_flag_locked(tp, TFLAG_MASTER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (master) {
|
|
|
|
if (!in_list) {
|
|
|
|
tech_pvt->next = globals.call_list;
|
|
|
|
globals.call_list = tech_pvt;
|
|
|
|
}
|
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_MASTER);
|
|
|
|
|
|
|
|
} else if (!in_list) {
|
|
|
|
for (tp = globals.call_list; tp && tp->next; tp = tp->next);
|
|
|
|
if (tp) {
|
|
|
|
tp->next = tech_pvt;
|
|
|
|
} else {
|
|
|
|
globals.call_list = tech_pvt;
|
|
|
|
}
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
static void remove_pvt(private_t * tech_pvt)
|
2007-01-17 19:10:03 +00:00
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *tp, *last = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
2007-03-29 22:31:56 +00:00
|
|
|
for (tp = globals.call_list; tp; tp = tp->next) {
|
|
|
|
switch_clear_flag_locked(tp, TFLAG_MASTER);
|
|
|
|
if (tp == tech_pvt) {
|
|
|
|
if (last) {
|
|
|
|
last->next = tp->next;
|
|
|
|
} else {
|
|
|
|
globals.call_list = tp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last = tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globals.call_list) {
|
|
|
|
switch_set_flag_locked(globals.call_list, TFLAG_MASTER);
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No more channels, deactivating audio\n");
|
|
|
|
deactivate_audio_device();
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-13 02:05:39 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
remove_pvt(tech_pvt);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2006-06-23 16:59:47 +00:00
|
|
|
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_HUP);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (tech_pvt->hfh) {
|
|
|
|
tech_pvt->hfh = NULL;
|
|
|
|
switch_core_file_close(&tech_pvt->fh);
|
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch (sig) {
|
|
|
|
case SWITCH_SIG_KILL:
|
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_HUP);
|
|
|
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-04-11 21:13:44 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-01 01:35:01 +00:00
|
|
|
static switch_status_t channel_on_transmit(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-05-01 01:35:01 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n");
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-01 01:35:01 +00:00
|
|
|
static switch_status_t channel_on_loopback(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2006-05-01 17:20:30 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n");
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2006-04-11 21:13:44 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF ON CALL %s [%s]\n", tech_pvt->call_id, dtmf);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
|
|
|
int samples = 0;
|
2006-04-29 23:43:28 +00:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (!globals.audio_stream) {
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
|
|
|
|
goto cng;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_master(tech_pvt)) {
|
|
|
|
if (tech_pvt->hold_file) {
|
|
|
|
if (!tech_pvt->hfh) {
|
|
|
|
int sample_rate = tech_pvt->sample_rate ? tech_pvt->sample_rate : globals.sample_rate;
|
|
|
|
if (switch_core_file_open(&tech_pvt->fh,
|
|
|
|
tech_pvt->hold_file,
|
2007-03-15 01:58:41 +00:00
|
|
|
globals.read_codec.implementation->number_of_channels,
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.read_codec.implementation->samples_per_second,
|
|
|
|
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
|
|
|
|
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
tech_pvt->hold_file = NULL;
|
|
|
|
goto cng;
|
|
|
|
}
|
|
|
|
|
|
|
|
tech_pvt->hfh = &tech_pvt->fh;
|
|
|
|
tech_pvt->hold_frame.data = tech_pvt->holdbuf;
|
|
|
|
tech_pvt->hold_frame.buflen = sizeof(tech_pvt->holdbuf);
|
|
|
|
tech_pvt->hold_frame.rate = sample_rate;
|
2007-06-22 17:05:51 +00:00
|
|
|
tech_pvt->hold_frame.codec = &globals.write_codec;
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto hold;
|
|
|
|
}
|
2007-10-17 14:59:17 +00:00
|
|
|
cng:
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_yield(globals.read_codec.implementation->microseconds_per_frame);
|
|
|
|
*frame = &globals.cng_frame;
|
2007-01-17 19:10:03 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
hold:
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
{
|
|
|
|
switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
|
2007-06-22 17:05:51 +00:00
|
|
|
if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_core_file_close(&tech_pvt->fh);
|
|
|
|
goto cng;
|
|
|
|
}
|
|
|
|
switch_core_file_read(tech_pvt->hfh, tech_pvt->hold_frame.data, &olen);
|
|
|
|
|
|
|
|
if (olen == 0) {
|
|
|
|
unsigned int pos = 0;
|
|
|
|
switch_core_file_seek(tech_pvt->hfh, &pos, 0, SEEK_SET);
|
|
|
|
goto cng;
|
2007-01-17 19:10:03 +00:00
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
tech_pvt->hold_frame.datalen = (uint32_t) (olen * sizeof(int16_t));
|
|
|
|
tech_pvt->hold_frame.samples = (uint32_t) olen;
|
2007-06-22 17:05:51 +00:00
|
|
|
tech_pvt->hold_frame.timestamp = globals.timer.samplecount;
|
2007-03-29 22:31:56 +00:00
|
|
|
*frame = &tech_pvt->hold_frame;
|
|
|
|
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
switch_mutex_lock(globals.device_lock);
|
2007-01-19 01:23:27 +00:00
|
|
|
|
2007-06-21 22:36:04 +00:00
|
|
|
if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data,
|
|
|
|
globals.read_codec.implementation->samples_per_frame,
|
2007-06-22 17:05:51 +00:00
|
|
|
&globals.timer)) == 0) {
|
2007-07-03 15:12:56 +00:00
|
|
|
switch_mutex_unlock(globals.device_lock);
|
2007-06-21 22:36:04 +00:00
|
|
|
goto cng;
|
|
|
|
} else {
|
2007-01-17 19:10:03 +00:00
|
|
|
globals.read_frame.datalen = samples * 2;
|
|
|
|
globals.read_frame.samples = samples;
|
2007-03-08 01:30:52 +00:00
|
|
|
|
|
|
|
switch_core_timer_check(&globals.timer);
|
|
|
|
globals.read_frame.timestamp = globals.timer.samplecount;
|
2007-01-17 19:10:03 +00:00
|
|
|
*frame = &globals.read_frame;
|
2007-01-23 16:06:25 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!switch_test_flag((&globals), GFLAG_MOUTH)) {
|
|
|
|
memset(globals.read_frame.data, 255, globals.read_frame.datalen);
|
|
|
|
}
|
2007-01-23 16:06:25 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
switch_mutex_unlock(globals.device_lock);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt = NULL;
|
2006-04-29 23:43:28 +00:00
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
2006-01-03 22:13:59 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (!globals.audio_stream) {
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_test_flag(tech_pvt, TFLAG_HUP)) {
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!is_master(tech_pvt) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
if (globals.audio_stream) {
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_test_flag((&globals), GFLAG_EAR)) {
|
2007-06-21 22:36:04 +00:00
|
|
|
WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)),
|
2007-06-22 17:05:51 +00:00
|
|
|
&globals.timer);
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t channel_answer_channel(switch_core_session_t *session)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt;
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-06-08 15:20:46 +00:00
|
|
|
static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
|
|
|
|
{
|
|
|
|
switch_channel_t *channel;
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-06-08 15:20:46 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-06-08 15:20:46 +00:00
|
|
|
tech_pvt = switch_core_session_get_private(session);
|
|
|
|
assert(tech_pvt != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
switch (msg->message_id) {
|
2007-04-16 16:53:30 +00:00
|
|
|
case SWITCH_MESSAGE_INDICATE_ANSWER:
|
|
|
|
channel_answer_channel(session);
|
|
|
|
break;
|
2007-03-29 22:31:56 +00:00
|
|
|
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
2006-06-08 15:20:46 +00:00
|
|
|
{
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n");
|
2006-06-23 16:59:47 +00:00
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_IO);
|
2006-06-08 15:20:46 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-06-08 15:28:42 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2006-06-08 15:20:46 +00:00
|
|
|
}
|
|
|
|
|
2007-06-13 20:40:06 +00:00
|
|
|
static switch_state_handler_table_t channel_event_handlers = {
|
2006-01-20 15:05:05 +00:00
|
|
|
/*.on_init */ channel_on_init,
|
|
|
|
/*.on_ring */ channel_on_ring,
|
|
|
|
/*.on_execute */ channel_on_execute,
|
|
|
|
/*.on_hangup */ channel_on_hangup,
|
|
|
|
/*.on_loopback */ channel_on_loopback,
|
|
|
|
/*.on_transmit */ channel_on_transmit
|
2006-01-03 22:13:59 +00:00
|
|
|
};
|
|
|
|
|
2007-06-13 20:40:06 +00:00
|
|
|
static switch_io_routines_t channel_io_routines = {
|
2006-01-20 15:05:05 +00:00
|
|
|
/*.outgoing_channel */ channel_outgoing_channel,
|
|
|
|
/*.read_frame */ channel_read_frame,
|
|
|
|
/*.write_frame */ channel_write_frame,
|
|
|
|
/*.kill_channel */ channel_kill_channel,
|
|
|
|
/*.waitfor_read */ channel_waitfor_read,
|
|
|
|
/*.waitfor_write */ channel_waitfor_write,
|
2006-06-08 15:28:42 +00:00
|
|
|
/*.send_dtmf */ channel_send_dtmf,
|
2007-03-29 22:31:56 +00:00
|
|
|
/*.receive_message */ channel_receive_message
|
2006-01-03 22:13:59 +00:00
|
|
|
};
|
|
|
|
|
2006-02-20 06:13:56 +00:00
|
|
|
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
|
|
|
|
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
|
|
|
|
*/
|
2007-03-29 22:31:56 +00:00
|
|
|
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
|
|
|
|
switch_caller_profile_t *outbound_profile,
|
2007-03-30 00:15:25 +00:00
|
|
|
switch_core_session_t **new_session, switch_memory_pool_t **pool)
|
2006-02-20 06:13:56 +00:00
|
|
|
{
|
2006-05-01 17:20:30 +00:00
|
|
|
|
2007-06-20 07:15:53 +00:00
|
|
|
if ((*new_session = switch_core_session_request(channel_endpoint_interface, pool)) != 0) {
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt;
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel;
|
|
|
|
switch_caller_profile_t *caller_profile;
|
2006-02-20 06:13:56 +00:00
|
|
|
|
|
|
|
switch_core_session_add_stream(*new_session, NULL);
|
2007-01-23 16:06:25 +00:00
|
|
|
if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
|
2007-03-29 22:31:56 +00:00
|
|
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
2006-06-23 16:59:47 +00:00
|
|
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
2006-02-20 06:13:56 +00:00
|
|
|
channel = switch_core_session_get_channel(*new_session);
|
|
|
|
switch_core_session_set_private(*new_session, tech_pvt);
|
|
|
|
tech_pvt->session = *new_session;
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.flags = GFLAG_EAR | GFLAG_MOUTH;
|
2006-02-20 06:13:56 +00:00
|
|
|
} else {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
|
2006-02-20 06:13:56 +00:00
|
|
|
switch_core_session_destroy(new_session);
|
2007-02-09 20:03:07 +00:00
|
|
|
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
2006-02-20 06:13:56 +00:00
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-02-20 06:13:56 +00:00
|
|
|
if (outbound_profile) {
|
|
|
|
char name[128];
|
2007-03-30 00:13:31 +00:00
|
|
|
char *id = !switch_strlen_zero(outbound_profile->caller_id_number) ? outbound_profile->caller_id_number : "na";
|
2007-01-17 19:10:03 +00:00
|
|
|
snprintf(name, sizeof(name), "PortAudio/%s", id);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-02-20 06:13:56 +00:00
|
|
|
switch_channel_set_name(channel, name);
|
2006-02-22 02:50:33 +00:00
|
|
|
|
|
|
|
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
|
|
|
|
switch_channel_set_caller_profile(channel, caller_profile);
|
|
|
|
tech_pvt->caller_profile = caller_profile;
|
2006-02-20 06:13:56 +00:00
|
|
|
} else {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
|
2006-02-20 06:13:56 +00:00
|
|
|
switch_core_session_destroy(new_session);
|
2007-02-09 20:03:07 +00:00
|
|
|
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
2006-02-20 06:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_channel_set_flag(channel, CF_OUTBOUND);
|
2006-06-23 16:59:47 +00:00
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
2006-02-20 06:13:56 +00:00
|
|
|
switch_channel_set_state(channel, CS_INIT);
|
2007-02-09 20:03:07 +00:00
|
|
|
return SWITCH_CAUSE_SUCCESS;
|
2006-02-20 06:13:56 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 20:03:07 +00:00
|
|
|
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
2006-02-20 06:13:56 +00:00
|
|
|
|
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load)
|
2006-01-20 15:05:05 +00:00
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_status_t status;
|
2007-06-20 07:15:53 +00:00
|
|
|
switch_api_interface_t *api_interface;
|
2007-01-19 01:23:27 +00:00
|
|
|
|
2007-06-20 07:15:53 +00:00
|
|
|
module_pool = pool;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
Pa_Initialize();
|
2007-01-19 01:23:27 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (dump_info()) {
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't find any audio devices!\n");
|
2007-01-19 01:23:27 +00:00
|
|
|
return SWITCH_STATUS_TERM;
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
2007-01-19 01:23:27 +00:00
|
|
|
|
|
|
|
if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
|
2007-03-29 22:31:56 +00:00
|
|
|
return status;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
|
|
|
"Input Device: %d, Output Device: %d, Ring Device: %d Sample Rate: %d MS: %d\n", globals.indev,
|
|
|
|
globals.outdev, globals.ringdev, globals.sample_rate, globals.codec_ms);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
switch_core_hash_init(&globals.call_hash, module_pool);
|
|
|
|
switch_mutex_init(&globals.device_lock, SWITCH_MUTEX_NESTED, module_pool);
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_mutex_init(&globals.pvt_lock, SWITCH_MUTEX_NESTED, module_pool);
|
2007-01-31 17:12:42 +00:00
|
|
|
switch_mutex_init(&globals.flag_mutex, SWITCH_MUTEX_NESTED, module_pool);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
if (switch_event_reserve_subclass(MY_EVENT_RINGING) != SWITCH_STATUS_SUCCESS) {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
globals.read_frame.data = globals.databuf;
|
|
|
|
globals.read_frame.buflen = sizeof(globals.databuf);
|
|
|
|
globals.cng_frame.data = globals.cngbuf;
|
|
|
|
globals.cng_frame.buflen = sizeof(globals.cngbuf);
|
2007-01-19 01:23:27 +00:00
|
|
|
globals.cng_frame.datalen = sizeof(globals.cngbuf);
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_set_flag((&globals.cng_frame), SFF_CNG);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
/* connect my internal structure to the blank pointer passed to me */
|
2007-06-20 07:15:53 +00:00
|
|
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
|
|
|
channel_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
|
2007-06-20 18:53:26 +00:00
|
|
|
channel_endpoint_interface->interface_name = "portaudio";
|
2007-06-20 07:15:53 +00:00
|
|
|
channel_endpoint_interface->io_routines = &channel_io_routines;
|
|
|
|
channel_endpoint_interface->state_handler = &channel_event_handlers;
|
|
|
|
|
|
|
|
SWITCH_ADD_API(api_interface, "pa", "PortAudio", pa_cmd, "<command> [<args>]");
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t load_config(void)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
|
|
|
char *cf = "portaudio.conf";
|
2006-05-10 03:40:52 +00:00
|
|
|
switch_xml_t cfg, xml, settings, param;
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-05-10 15:47:54 +00:00
|
|
|
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_TERM;
|
|
|
|
}
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2007-01-19 01:23:27 +00:00
|
|
|
memset(&globals, 0, sizeof(globals));
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.indev = globals.outdev = globals.ringdev = -1;
|
2007-01-19 01:23:27 +00:00
|
|
|
|
2006-05-10 03:23:05 +00:00
|
|
|
if ((settings = switch_xml_child(cfg, "settings"))) {
|
|
|
|
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
2006-05-17 00:58:21 +00:00
|
|
|
char *var = (char *) switch_xml_attr_soft(param, "name");
|
|
|
|
char *val = (char *) switch_xml_attr_soft(param, "value");
|
2006-05-10 03:23:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
if (!strcmp(var, "debug")) {
|
|
|
|
globals.debug = atoi(val);
|
2007-01-17 19:10:03 +00:00
|
|
|
} else if (!strcmp(var, "ring-interval")) {
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.ring_interval = atoi(val);
|
2007-01-17 19:10:03 +00:00
|
|
|
} else if (!strcmp(var, "ring-file")) {
|
|
|
|
set_global_ring_file(val);
|
|
|
|
} else if (!strcmp(var, "hold-file")) {
|
|
|
|
set_global_hold_file(val);
|
|
|
|
} else if (!strcmp(var, "timer-name")) {
|
|
|
|
set_global_timer_name(val);
|
2006-05-16 17:08:21 +00:00
|
|
|
} else if (!strcmp(var, "sample-rate")) {
|
2006-01-03 22:13:59 +00:00
|
|
|
globals.sample_rate = atoi(val);
|
2007-01-17 19:10:03 +00:00
|
|
|
} else if (!strcmp(var, "codec-ms")) {
|
|
|
|
globals.codec_ms = atoi(val);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (!strcmp(var, "dialplan")) {
|
|
|
|
set_global_dialplan(val);
|
2006-05-16 17:08:21 +00:00
|
|
|
} else if (!strcmp(var, "cid-name")) {
|
2006-01-03 22:13:59 +00:00
|
|
|
set_global_cid_name(val);
|
2006-05-16 17:08:21 +00:00
|
|
|
} else if (!strcmp(var, "cid-num")) {
|
2006-01-03 22:13:59 +00:00
|
|
|
set_global_cid_num(val);
|
|
|
|
} else if (!strcmp(var, "indev")) {
|
|
|
|
if (*val == '#') {
|
2007-01-19 01:23:27 +00:00
|
|
|
globals.indev = get_dev_by_number(atoi(val + 1), 1);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else {
|
|
|
|
globals.indev = get_dev_by_name(val, 1);
|
|
|
|
}
|
|
|
|
} else if (!strcmp(var, "outdev")) {
|
|
|
|
if (*val == '#') {
|
2007-01-19 01:23:27 +00:00
|
|
|
globals.outdev = get_dev_by_number(atoi(val + 1), 0);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else {
|
|
|
|
globals.outdev = get_dev_by_name(val, 0);
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
} else if (!strcmp(var, "ringdev")) {
|
|
|
|
if (*val == '#') {
|
2007-01-19 01:23:27 +00:00
|
|
|
globals.ringdev = get_dev_by_number(atoi(val + 1), 0);
|
2007-01-17 19:10:03 +00:00
|
|
|
} else {
|
|
|
|
globals.ringdev = get_dev_by_name(val, 0);
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!globals.dialplan) {
|
|
|
|
set_global_dialplan("default");
|
|
|
|
}
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
if (!globals.sample_rate) {
|
|
|
|
globals.sample_rate = 8000;
|
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (!globals.codec_ms) {
|
|
|
|
globals.codec_ms = 20;
|
|
|
|
}
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (!globals.ring_interval) {
|
|
|
|
globals.ring_interval = 5;
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
|
|
|
if (!globals.timer_name) {
|
|
|
|
set_global_timer_name("soft");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globals.indev < 0) {
|
|
|
|
globals.indev = get_dev_by_name(NULL, 1);
|
|
|
|
if (globals.indev > -1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Switching to default input device!\n");
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find an input device!\n");
|
|
|
|
status = SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globals.outdev < 0) {
|
|
|
|
globals.outdev = get_dev_by_name(NULL, 0);
|
|
|
|
if (globals.outdev > -1) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Switching to default output device!\n");
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find an input device!\n");
|
|
|
|
status = SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globals.ringdev < 0) {
|
|
|
|
if (globals.outdev > -1) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ring device configured using output device!\n");
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.ringdev = globals.outdev;
|
|
|
|
}
|
|
|
|
}
|
2007-01-19 01:23:27 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_xml_free(xml);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-01-19 01:23:27 +00:00
|
|
|
return status;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-03-01 17:23:02 +00:00
|
|
|
if (globals.read_codec.implementation) {
|
|
|
|
switch_core_codec_destroy(&globals.read_codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globals.write_codec.implementation) {
|
|
|
|
switch_core_codec_destroy(&globals.write_codec);
|
|
|
|
}
|
|
|
|
|
2007-06-22 17:05:51 +00:00
|
|
|
switch_core_timer_destroy(&globals.timer);
|
2006-01-20 15:05:05 +00:00
|
|
|
Pa_Terminate();
|
2007-09-29 01:06:08 +00:00
|
|
|
switch_core_hash_destroy(&globals.call_hash);
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-19 01:23:27 +00:00
|
|
|
static int get_dev_by_number(int number, int in)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
int numDevices = Pa_GetDeviceCount();
|
2007-01-19 01:23:27 +00:00
|
|
|
const PaDeviceInfo *pdi;
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (number > -1 && number < numDevices && (pdi = Pa_GetDeviceInfo(number))) {
|
|
|
|
if (in && pdi->maxInputChannels) {
|
|
|
|
return number;
|
|
|
|
} else if (!in && pdi->maxOutputChannels) {
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2007-01-19 01:23:27 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
static int get_dev_by_name(char *name, int in)
|
|
|
|
{
|
2006-01-20 15:05:05 +00:00
|
|
|
int i;
|
|
|
|
int numDevices;
|
|
|
|
const PaDeviceInfo *pdi;
|
2007-01-17 19:10:03 +00:00
|
|
|
numDevices = Pa_GetDeviceCount();
|
2006-01-20 15:05:05 +00:00
|
|
|
|
|
|
|
if (numDevices < 0) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
|
2006-01-20 15:05:05 +00:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numDevices; i++) {
|
2007-03-29 22:31:56 +00:00
|
|
|
int match = 0;
|
2006-01-20 15:05:05 +00:00
|
|
|
pdi = Pa_GetDeviceInfo(i);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (switch_strlen_zero(name)) {
|
2007-03-29 22:31:56 +00:00
|
|
|
match = 1;
|
|
|
|
} else if (strstr(pdi->name, name)) {
|
|
|
|
match = 1;
|
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (match) {
|
2006-01-20 15:05:05 +00:00
|
|
|
if (in && pdi->maxInputChannels) {
|
2006-01-03 22:13:59 +00:00
|
|
|
return i;
|
|
|
|
} else if (!in && pdi->maxOutputChannels) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_strlen_zero(name)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
return get_dev_by_name(NULL, in);
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
/*******************************************************************/
|
2007-03-30 00:13:31 +00:00
|
|
|
static void PrintSupportedStandardSampleRates(const PaStreamParameters * inputParameters, const PaStreamParameters * outputParameters)
|
2007-01-17 19:10:03 +00:00
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
int i, printCount, cr = 7;
|
|
|
|
PaError err;
|
|
|
|
static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
|
2007-10-17 14:59:17 +00:00
|
|
|
44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1
|
2007-03-29 22:31:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
printCount = cr;
|
|
|
|
for (i = 0; standardSampleRates[i] > 0; i++) {
|
|
|
|
err = Pa_IsFormatSupported(inputParameters, outputParameters, standardSampleRates[i]);
|
|
|
|
if (err == paFormatIsSupported) {
|
|
|
|
if (printCount == cr) {
|
|
|
|
printCount = 0;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "\n\t%0.2f", standardSampleRates[i]);
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, ", %0.2f", standardSampleRates[i]);
|
|
|
|
}
|
|
|
|
printCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!printCount) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, " None\n");
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "\n");
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
|
2007-02-16 16:19:39 +00:00
|
|
|
static switch_status_t devlist(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
int i, numDevices;
|
|
|
|
const PaDeviceInfo *deviceInfo;
|
|
|
|
|
|
|
|
numDevices = Pa_GetDeviceCount();
|
|
|
|
if (numDevices < 0) {
|
2007-02-16 16:19:39 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < numDevices; i++) {
|
|
|
|
deviceInfo = Pa_GetDeviceInfo(i);
|
2007-03-30 00:13:31 +00:00
|
|
|
stream->write_function(stream, "%d;%s;%d;%d\n", i, deviceInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
|
2007-02-16 16:19:39 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-02-16 16:19:39 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
static int dump_info(void)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
int i, numDevices, defaultDisplayed;
|
|
|
|
const PaDeviceInfo *deviceInfo;
|
|
|
|
PaStreamParameters inputParameters, outputParameters;
|
|
|
|
PaError err;
|
|
|
|
const char *line = "--------------------------------------------------------------------------------\n";
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
|
2007-03-30 00:13:31 +00:00
|
|
|
"PortAudio version number = %d\nPortAudio version text = '%s'\n", Pa_GetVersion(), Pa_GetVersionText());
|
2007-02-16 16:19:39 +00:00
|
|
|
if (globals.audio_stream) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "ERROR: Cannot use this command this while a call is in progress\n");
|
2007-02-16 16:19:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
|
|
|
numDevices = Pa_GetDeviceCount();
|
|
|
|
if (numDevices < 0) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
|
2007-03-29 22:31:56 +00:00
|
|
|
err = numDevices;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Number of devices = %d\n", numDevices);
|
|
|
|
for (i = 0; i < numDevices; i++) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s", line);
|
|
|
|
deviceInfo = Pa_GetDeviceInfo(i);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Device #%d ", i);
|
|
|
|
|
|
|
|
/* Mark global and API specific default devices */
|
|
|
|
defaultDisplayed = 0;
|
|
|
|
if (i == Pa_GetDefaultInputDevice()) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default Input");
|
|
|
|
defaultDisplayed = 1;
|
|
|
|
|
|
|
|
} else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) {
|
|
|
|
|
|
|
|
const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default %s Input", hostInfo->name);
|
|
|
|
defaultDisplayed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == Pa_GetDefaultOutputDevice()) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default Output");
|
|
|
|
defaultDisplayed = 1;
|
|
|
|
|
|
|
|
} else if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultOutputDevice) {
|
|
|
|
|
|
|
|
const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "**Default %s Output", hostInfo->name);
|
|
|
|
defaultDisplayed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defaultDisplayed) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "** | ");
|
|
|
|
}
|
|
|
|
/* print device info fields */
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Name: %s\n", deviceInfo->name);
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Host: %s | ", Pa_GetHostApiInfo(deviceInfo->hostApi)->name);
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "inputs: %d | ", deviceInfo->maxInputChannels);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "outputs: %d | ", deviceInfo->maxOutputChannels);
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Default rate: %8.2f\n", deviceInfo->defaultSampleRate);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
|
|
|
/* poll for standard sample rates */
|
|
|
|
inputParameters.device = i;
|
|
|
|
inputParameters.channelCount = deviceInfo->maxInputChannels;
|
|
|
|
inputParameters.sampleFormat = paInt16;
|
|
|
|
inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
|
|
|
|
inputParameters.hostApiSpecificStreamInfo = NULL;
|
|
|
|
|
|
|
|
outputParameters.device = i;
|
|
|
|
outputParameters.channelCount = deviceInfo->maxOutputChannels;
|
|
|
|
outputParameters.sampleFormat = paInt16;
|
|
|
|
outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
|
|
|
|
outputParameters.hostApiSpecificStreamInfo = NULL;
|
|
|
|
|
|
|
|
if (inputParameters.channelCount > 0) {
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "half-duplex 16 bit %d channel input rates:", inputParameters.channelCount);
|
2007-03-29 22:31:56 +00:00
|
|
|
PrintSupportedStandardSampleRates(&inputParameters, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputParameters.channelCount > 0) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "half-duplex 16 bit %d channel output rates:", outputParameters.channelCount);
|
2007-03-29 22:31:56 +00:00
|
|
|
PrintSupportedStandardSampleRates(NULL, &outputParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputParameters.channelCount > 0 && outputParameters.channelCount > 0) {
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
|
2007-03-30 00:15:25 +00:00
|
|
|
"full-duplex 16 bit %d channel input, %d channel output rates:", inputParameters.channelCount,
|
|
|
|
outputParameters.channelCount);
|
2007-03-29 22:31:56 +00:00
|
|
|
PrintSupportedStandardSampleRates(&inputParameters, &outputParameters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s", line);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
error:
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "An error occured while using the portaudio stream\n");
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error number: %d\n", err);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error message: %s\n", Pa_GetErrorText(err));
|
|
|
|
return err;
|
2007-01-17 19:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t engage_device(int sample_rate, int codec_ms)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
PaStreamParameters inputParameters, outputParameters;
|
2006-01-20 15:05:05 +00:00
|
|
|
PaError err;
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!globals.audio_stream) {
|
|
|
|
if (!sample_rate) {
|
|
|
|
sample_rate = globals.sample_rate;
|
|
|
|
}
|
|
|
|
if (!codec_ms) {
|
|
|
|
codec_ms = globals.codec_ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_core_codec_init(&globals.read_codec,
|
|
|
|
"L16",
|
2007-03-30 00:15:25 +00:00
|
|
|
NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
|
|
|
NULL) != SWITCH_STATUS_SUCCESS) {
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
} else {
|
|
|
|
if (switch_core_codec_init(&globals.write_codec,
|
|
|
|
"L16",
|
|
|
|
NULL,
|
2007-03-30 00:15:25 +00:00
|
|
|
sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
|
|
|
NULL) != SWITCH_STATUS_SUCCESS) {
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
|
|
|
|
switch_core_codec_destroy(&globals.read_codec);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-08 01:30:52 +00:00
|
|
|
if (switch_core_timer_init(&globals.timer,
|
2007-03-30 00:15:25 +00:00
|
|
|
globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_frame,
|
|
|
|
module_pool) != SWITCH_STATUS_SUCCESS) {
|
2007-03-08 01:30:52 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
|
|
|
|
switch_core_codec_destroy(&globals.read_codec);
|
|
|
|
switch_core_codec_destroy(&globals.write_codec);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.read_frame.rate = sample_rate;
|
|
|
|
globals.read_frame.codec = &globals.read_codec;
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_mutex_lock(globals.device_lock);
|
|
|
|
/* LOCKED ************************************************************************************************** */
|
|
|
|
inputParameters.device = globals.indev;
|
|
|
|
inputParameters.channelCount = 1;
|
|
|
|
inputParameters.sampleFormat = SAMPLE_TYPE;
|
|
|
|
inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
|
|
|
|
inputParameters.hostApiSpecificStreamInfo = NULL;
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
outputParameters.device = globals.outdev;
|
|
|
|
outputParameters.channelCount = 1;
|
|
|
|
outputParameters.sampleFormat = SAMPLE_TYPE;
|
|
|
|
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
|
|
|
|
outputParameters.hostApiSpecificStreamInfo = NULL;
|
2007-06-22 17:05:51 +00:00
|
|
|
err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
|
|
|
|
globals.read_codec.implementation->samples_per_frame);
|
2007-03-29 22:31:56 +00:00
|
|
|
/* UNLOCKED ************************************************************************************************* */
|
|
|
|
switch_mutex_unlock(globals.device_lock);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (err != paNoError) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n");
|
|
|
|
switch_core_codec_destroy(&globals.read_codec);
|
|
|
|
switch_core_codec_destroy(&globals.write_codec);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
static switch_status_t engage_ring_device(int sample_rate, int channels)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
PaStreamParameters outputParameters;
|
2007-01-17 19:10:03 +00:00
|
|
|
PaError err;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!globals.ring_stream) {
|
|
|
|
if (!sample_rate) {
|
|
|
|
sample_rate = globals.sample_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_mutex_lock(globals.device_lock);
|
|
|
|
/* LOCKED ************************************************************************************************** */
|
|
|
|
outputParameters.device = globals.ringdev;
|
|
|
|
outputParameters.channelCount = channels;
|
|
|
|
outputParameters.sampleFormat = SAMPLE_TYPE;
|
|
|
|
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
|
|
|
|
outputParameters.hostApiSpecificStreamInfo = NULL;
|
2007-06-22 17:05:51 +00:00
|
|
|
err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff,
|
|
|
|
globals.read_codec.implementation->samples_per_frame);
|
2007-03-29 22:31:56 +00:00
|
|
|
/* UNLOCKED ************************************************************************************************* */
|
|
|
|
switch_mutex_unlock(globals.device_lock);
|
|
|
|
|
|
|
|
|
|
|
|
if (err != paNoError) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open ring device!\n");
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Engage ring device! rate: %d channels %d\n", sample_rate, channels);
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-01-17 19:10:03 +00:00
|
|
|
}
|
2006-01-20 00:41:30 +00:00
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
char *dtmf = argv[0];
|
|
|
|
|
|
|
|
if (switch_strlen_zero(dtmf)) {
|
|
|
|
stream->write_function(stream, "No DTMF Supplied!\n");
|
|
|
|
} else {
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
|
|
|
if (globals.call_list) {
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
|
|
|
|
switch_channel_queue_dtmf(channel, dtmf);
|
|
|
|
}
|
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-01-17 19:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t switch_call(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *tp, *tech_pvt = NULL;
|
|
|
|
char *callid = argv[0];
|
|
|
|
uint8_t one_call = 0;
|
|
|
|
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
|
|
|
if (switch_strlen_zero(callid)) {
|
|
|
|
if (globals.call_list) {
|
|
|
|
if (globals.call_list->next) {
|
|
|
|
tech_pvt = globals.call_list->next;
|
|
|
|
} else {
|
|
|
|
tech_pvt = globals.call_list;
|
|
|
|
one_call = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(callid, "none")) {
|
|
|
|
for (tp = globals.call_list; tp; tp = tp->next) {
|
|
|
|
switch_clear_flag_locked(tp, TFLAG_MASTER);
|
|
|
|
}
|
|
|
|
stream->write_function(stream, "OK\n");
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
tech_pvt = switch_core_hash_find(globals.call_hash, callid);
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
if (tech_pvt) {
|
2007-03-29 22:31:56 +00:00
|
|
|
if (tech_pvt == globals.call_list && !tech_pvt->next) {
|
|
|
|
one_call = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!one_call) {
|
|
|
|
remove_pvt(tech_pvt);
|
|
|
|
}
|
|
|
|
add_pvt(tech_pvt, PA_MASTER);
|
|
|
|
stream->write_function(stream, "OK\n");
|
2006-01-20 15:05:05 +00:00
|
|
|
} else {
|
2007-01-17 19:10:03 +00:00
|
|
|
stream->write_function(stream, "NO SUCH CALL\n");
|
2006-01-20 15:05:05 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
done:
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t hangup_call(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *tech_pvt;
|
|
|
|
char *callid = argv[0];
|
|
|
|
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
|
|
|
if (switch_strlen_zero(callid)) {
|
|
|
|
tech_pvt = globals.call_list;
|
|
|
|
} else {
|
|
|
|
tech_pvt = switch_core_hash_find(globals.call_hash, callid);
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
if (tech_pvt) {
|
2007-03-12 20:16:44 +00:00
|
|
|
switch_channel_hangup(switch_core_session_get_channel(tech_pvt->session), SWITCH_CAUSE_NORMAL_CLEARING);
|
2007-01-17 19:10:03 +00:00
|
|
|
stream->write_function(stream, "OK\n");
|
2006-01-20 15:05:05 +00:00
|
|
|
} else {
|
2007-01-17 19:10:03 +00:00
|
|
|
stream->write_function(stream, "NO SUCH CALL\n");
|
2006-01-20 15:05:05 +00:00
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t answer_call(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *tp;
|
|
|
|
int x = 0;
|
|
|
|
char *callid = argv[0];
|
|
|
|
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(callid)) {
|
|
|
|
if ((tp = switch_core_hash_find(globals.call_hash, callid))) {
|
|
|
|
if (switch_test_flag(tp, TFLAG_ANSWER)) {
|
|
|
|
stream->write_function(stream, "CALL ALREADY ANSWERED\n");
|
|
|
|
} else {
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(tp->session);
|
|
|
|
switch_set_flag_locked(tp, TFLAG_ANSWER);
|
|
|
|
switch_channel_answer(channel);
|
|
|
|
add_pvt(tp, PA_MASTER);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->write_function(stream, "NO SUCH CALL\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tp = globals.call_list; tp; tp = tp->next) {
|
|
|
|
if (!switch_test_flag(tp, TFLAG_ANSWER)) {
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(tp->session);
|
|
|
|
switch_set_flag_locked(tp, TFLAG_ANSWER);
|
|
|
|
switch_channel_answer(channel);
|
|
|
|
add_pvt(tp, PA_MASTER);
|
|
|
|
x++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-17 14:59:17 +00:00
|
|
|
done:
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
|
|
|
|
|
|
|
stream->write_function(stream, "Answered %d channels.\n", x);
|
2007-01-17 19:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-01-23 16:06:25 +00:00
|
|
|
static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
char *action = argv[0];
|
|
|
|
char *flag_str = argv[1];
|
|
|
|
GFLAGS flags = GFLAG_NONE;
|
|
|
|
char *p;
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
goto desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 1; x < argc; x++) {
|
|
|
|
flag_str = argv[x];
|
|
|
|
for (p = flag_str; *p; p++) {
|
|
|
|
*p = (char) tolower(*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(flag_str, "ear")) {
|
|
|
|
flags |= GFLAG_EAR;
|
|
|
|
}
|
|
|
|
if (strstr(flag_str, "mouth")) {
|
|
|
|
flags |= GFLAG_MOUTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(action, "on")) {
|
|
|
|
if (flags & GFLAG_EAR) {
|
|
|
|
switch_set_flag((&globals), GFLAG_EAR);
|
|
|
|
}
|
|
|
|
if (flags & GFLAG_MOUTH) {
|
|
|
|
switch_set_flag((&globals), GFLAG_MOUTH);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(action, "off")) {
|
|
|
|
if (flags & GFLAG_EAR) {
|
|
|
|
switch_clear_flag((&globals), GFLAG_EAR);
|
|
|
|
}
|
|
|
|
if (flags & GFLAG_MOUTH) {
|
|
|
|
switch_clear_flag((&globals), GFLAG_MOUTH);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
desc:
|
2007-03-29 22:31:56 +00:00
|
|
|
x = 0;
|
|
|
|
stream->write_function(stream, "FLAGS: ");
|
|
|
|
if (switch_test_flag((&globals), GFLAG_EAR)) {
|
|
|
|
stream->write_function(stream, "ear");
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
if (switch_test_flag((&globals), GFLAG_MOUTH)) {
|
|
|
|
stream->write_function(stream, "%smouth", x ? "|" : "");
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
if (!x) {
|
|
|
|
stream->write_function(stream, "none");
|
|
|
|
}
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
bad:
|
2007-03-29 22:31:56 +00:00
|
|
|
stream->write_function(stream, "Usage: flags [on|off] <flags>\n");
|
2007-10-17 14:59:17 +00:00
|
|
|
done:
|
2007-03-29 22:31:56 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-01-23 16:06:25 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
static switch_status_t list_calls(char **argv, int argc, switch_stream_handle_t *stream)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
private_t *tp;
|
|
|
|
int x = 0;
|
|
|
|
char *cid_name = "n/a";
|
|
|
|
char *cid_num = "n/a";
|
|
|
|
|
|
|
|
switch_mutex_lock(globals.pvt_lock);
|
|
|
|
for (tp = globals.call_list; tp; tp = tp->next) {
|
2007-01-19 01:45:58 +00:00
|
|
|
switch_channel_t *channel;
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_caller_profile_t *profile;
|
|
|
|
x++;
|
|
|
|
channel = switch_core_session_get_channel(tp->session);
|
|
|
|
|
|
|
|
if ((profile = switch_channel_get_caller_profile(channel))) {
|
|
|
|
if (profile->originatee_caller_profile) {
|
|
|
|
cid_name = "Outbound Call";
|
|
|
|
cid_num = profile->originatee_caller_profile->destination_number;
|
|
|
|
} else {
|
|
|
|
cid_name = profile->caller_id_name;
|
|
|
|
cid_num = profile->caller_id_number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->write_function(stream, "%s %s [%s (%s)] %s\n", tp->call_id, switch_channel_get_name(channel),
|
|
|
|
cid_name, cid_num, switch_test_flag(tp, TFLAG_MASTER) ? "active" : "hold");
|
|
|
|
}
|
|
|
|
switch_mutex_unlock(globals.pvt_lock);
|
|
|
|
|
|
|
|
stream->write_function(stream, "\n%d call%s\n", x, x == 1 ? "" : "s");
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2007-01-17 19:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t *stream)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_core_session_t *session;
|
2007-01-17 19:10:03 +00:00
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
2007-03-29 22:31:56 +00:00
|
|
|
char *dest = NULL;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-01-17 19:10:03 +00:00
|
|
|
if (!argv[0]) {
|
|
|
|
stream->write_function(stream, "FAIL:Usage: call <dest>\n");
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2006-07-26 20:12:49 +00:00
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
dest = argv[0];
|
2006-07-26 20:12:49 +00:00
|
|
|
|
2007-06-20 07:15:53 +00:00
|
|
|
if ((session = switch_core_session_request(channel_endpoint_interface, NULL)) != 0) {
|
2007-01-17 19:10:03 +00:00
|
|
|
private_t *tech_pvt;
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_channel_t *channel;
|
2007-03-29 22:31:56 +00:00
|
|
|
char *dialplan = globals.dialplan;
|
|
|
|
char *cid_name = globals.cid_name;
|
|
|
|
char *cid_num = globals.cid_num;
|
2007-01-19 01:45:58 +00:00
|
|
|
|
|
|
|
switch_core_session_add_stream(session, NULL);
|
|
|
|
if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) {
|
|
|
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
|
|
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
switch_core_session_set_private(session, tech_pvt);
|
|
|
|
tech_pvt->session = session;
|
2007-03-29 22:31:56 +00:00
|
|
|
globals.flags = GFLAG_EAR | GFLAG_MOUTH;
|
2007-01-19 01:45:58 +00:00
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
|
|
|
|
switch_core_session_destroy(&session);
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(argv[1])) {
|
2007-03-29 22:31:56 +00:00
|
|
|
dialplan = argv[1];
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!switch_strlen_zero(argv[2])) {
|
|
|
|
cid_num = argv[2];
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!switch_strlen_zero(argv[3])) {
|
|
|
|
cid_name = argv[3];
|
|
|
|
}
|
2007-01-17 19:10:03 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!switch_strlen_zero(argv[4])) {
|
|
|
|
tech_pvt->sample_rate = atoi(argv[4]);
|
|
|
|
}
|
2007-10-03 01:10:29 +00:00
|
|
|
|
|
|
|
if (!switch_strlen_zero(argv[5])) {
|
2007-03-29 22:31:56 +00:00
|
|
|
tech_pvt->codec_ms = atoi(argv[5]);
|
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-03-01 22:55:28 +00:00
|
|
|
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
|
2007-08-28 22:44:02 +00:00
|
|
|
NULL, dialplan, cid_name, cid_num,
|
|
|
|
NULL, NULL, NULL, NULL, modname, NULL,
|
2007-03-30 00:15:25 +00:00
|
|
|
dest)) != 0) {
|
2006-01-03 22:13:59 +00:00
|
|
|
char name[128];
|
2007-03-30 00:15:25 +00:00
|
|
|
snprintf(name, sizeof(name), "PortAudio/%s",
|
|
|
|
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
|
2006-01-03 22:13:59 +00:00
|
|
|
switch_channel_set_name(channel, name);
|
2006-02-22 02:50:33 +00:00
|
|
|
|
|
|
|
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
tech_pvt->session = session;
|
2007-01-17 19:10:03 +00:00
|
|
|
if ((status = engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms)) == SWITCH_STATUS_SUCCESS) {
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
|
|
|
|
switch_channel_mark_answered(channel);
|
2006-01-03 22:13:59 +00:00
|
|
|
switch_channel_set_state(channel, CS_INIT);
|
2007-05-11 00:27:55 +00:00
|
|
|
if (switch_core_session_thread_launch(tech_pvt->session) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
|
|
|
|
switch_core_session_destroy(&session);
|
|
|
|
stream->write_function(stream, "FAIL:Thread Error!\n");
|
|
|
|
} else {
|
|
|
|
add_pvt(tech_pvt, PA_MASTER);
|
|
|
|
stream->write_function(stream, "SUCCESS:%s:%s\n", tech_pvt->call_id, switch_core_session_get_uuid(tech_pvt->session));
|
|
|
|
}
|
2006-10-08 07:11:42 +00:00
|
|
|
} else {
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_core_session_destroy(&session);
|
2007-01-17 19:10:03 +00:00
|
|
|
stream->write_function(stream, "FAIL:Device Error!\n");
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-05-12 21:36:15 +00:00
|
|
|
SWITCH_STANDARD_API(pa_cmd)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
char *argv[1024] = { 0 };
|
|
|
|
int argc = 0;
|
|
|
|
char *mycmd = NULL, *devname = NULL;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
pa_command_t func = NULL;
|
|
|
|
int lead = 1, devval = 0;
|
2007-05-01 00:37:10 +00:00
|
|
|
char *wcmd = NULL, *action = NULL;
|
|
|
|
char cmd_buf[1024] = "";
|
2007-05-01 01:26:30 +00:00
|
|
|
char *http = NULL;
|
2007-05-01 00:37:10 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
const char *usage_string = "USAGE:\n"
|
|
|
|
"--------------------------------------------------------------------------------\n"
|
|
|
|
"pa help\n"
|
|
|
|
"pa dump\n"
|
|
|
|
"pa call <dest> [<dialplan> <cid_name> <cid_num> <rate>]\n"
|
|
|
|
"pa answer [<call_id>]\n"
|
|
|
|
"pa hangup [<call_id>]\n"
|
|
|
|
"pa list\n"
|
|
|
|
"pa switch [<call_id>|none]\n"
|
|
|
|
"pa dtmf <digit string>\n"
|
|
|
|
"pa flags [on|off] [ear] [mouth]\n"
|
2007-02-16 16:19:39 +00:00
|
|
|
"pa devlist\n"
|
|
|
|
"pa indev [#<num>|<partial name>\n"
|
|
|
|
"pa outdev [#<num>|<partial name>\n"
|
2007-03-30 00:13:31 +00:00
|
|
|
"pa ringdev [#<num>|<partial name>\n" "--------------------------------------------------------------------------------\n";
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-05-01 00:37:10 +00:00
|
|
|
if (stream->event) {
|
2007-05-01 01:26:30 +00:00
|
|
|
http = switch_event_get_header(stream->event, "http-host");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (http) {
|
2007-05-01 00:37:10 +00:00
|
|
|
#if 0
|
|
|
|
switch_event_header_t *hp;
|
|
|
|
stream->write_function(stream, "<pre>");
|
|
|
|
for (hp = stream->event->headers; hp; hp = hp->next) {
|
|
|
|
stream->write_function(stream, "[%s]=[%s]\n", hp->name, hp->value);
|
|
|
|
}
|
|
|
|
stream->write_function(stream, "</pre>");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wcmd = switch_str_nil(switch_event_get_header(stream->event, "wcmd"));
|
|
|
|
action = switch_event_get_header(stream->event, "action");
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
if (strlen(action) == 1) {
|
|
|
|
snprintf(cmd_buf, sizeof(cmd_buf), "dtmf %s", action);
|
|
|
|
cmd = cmd_buf;
|
|
|
|
} else if (!strcmp(action, "mute")) {
|
|
|
|
snprintf(cmd_buf, sizeof(cmd_buf), "flags off mouth");
|
|
|
|
cmd = cmd_buf;
|
|
|
|
} else if (!strcmp(action, "unmute")) {
|
|
|
|
snprintf(cmd_buf, sizeof(cmd_buf), "flags on mouth");
|
|
|
|
cmd = cmd_buf;
|
|
|
|
} else if (!strcmp(action, "switch")) {
|
|
|
|
snprintf(cmd_buf, sizeof(cmd_buf), "switch %s", wcmd);
|
|
|
|
cmd = cmd_buf;
|
|
|
|
} else if (!strcmp(action, "call")) {
|
|
|
|
snprintf(cmd_buf, sizeof(cmd_buf), "call %s", wcmd);
|
|
|
|
cmd = cmd_buf;
|
|
|
|
} else if (!strcmp(action, "hangup") || !strcmp(action, "list") || !strcmp(action, "answer")) {
|
|
|
|
cmd = action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(cmd)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (switch_strlen_zero(cmd)) {
|
|
|
|
stream->write_function(stream, "%s", usage_string);
|
|
|
|
goto done;
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(mycmd = strdup(cmd))) {
|
|
|
|
status = SWITCH_STATUS_MEMERR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
|
|
|
stream->write_function(stream, "%s", usage_string);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(argv[0], "call")) {
|
|
|
|
func = place_call;
|
|
|
|
} else if (!strcasecmp(argv[0], "help")) {
|
|
|
|
stream->write_function(stream, "%s", usage_string);
|
|
|
|
goto done;
|
|
|
|
} else if (!strcasecmp(argv[0], "devlist")) {
|
2007-02-16 16:19:39 +00:00
|
|
|
func = devlist;
|
2007-03-29 22:31:56 +00:00
|
|
|
} else if (!strcasecmp(argv[0], "dump")) {
|
|
|
|
dump_info();
|
|
|
|
goto done;
|
|
|
|
} else if (!strcasecmp(argv[0], "list")) {
|
|
|
|
func = list_calls;
|
|
|
|
} else if (!strcasecmp(argv[0], "flags")) {
|
|
|
|
func = do_flags;
|
|
|
|
} else if (!strcasecmp(argv[0], "hangup")) {
|
|
|
|
func = hangup_call;
|
|
|
|
} else if (!strcasecmp(argv[0], "answer")) {
|
|
|
|
func = answer_call;
|
|
|
|
} else if (!strcasecmp(argv[0], "switch")) {
|
|
|
|
func = switch_call;
|
|
|
|
} else if (!strcasecmp(argv[0], "dtmf")) {
|
|
|
|
func = dtmf_call;
|
2007-02-16 16:19:39 +00:00
|
|
|
} else if (argv[1] && !strcmp(argv[0], "indev")) {
|
|
|
|
if (*argv[1] == '#') {
|
|
|
|
devval = get_dev_by_number(atoi(argv[1] + 1), 1);
|
|
|
|
} else {
|
|
|
|
devval = get_dev_by_name(argv[1], 1);
|
|
|
|
}
|
|
|
|
devname = "indev";
|
|
|
|
if (devval > 0) {
|
|
|
|
globals.indev = devval;
|
|
|
|
}
|
|
|
|
} else if (argv[1] && !strcmp(argv[0], "outdev")) {
|
|
|
|
if (*argv[1] == '#') {
|
|
|
|
devval = get_dev_by_number(atoi(argv[1] + 1), 0);
|
|
|
|
} else {
|
|
|
|
devval = get_dev_by_name(argv[1], 0);
|
|
|
|
}
|
|
|
|
devname = "outdev";
|
2007-03-29 22:31:56 +00:00
|
|
|
if (devval > 0) {
|
2007-02-16 16:19:39 +00:00
|
|
|
globals.outdev = devval;
|
|
|
|
}
|
|
|
|
} else if (argv[1] && !strcmp(argv[0], "ringdev")) {
|
|
|
|
if (*argv[1] == '#') {
|
|
|
|
devval = get_dev_by_number(atoi(argv[1] + 1), 0);
|
|
|
|
} else {
|
|
|
|
devval = get_dev_by_name(argv[1], 0);
|
|
|
|
}
|
|
|
|
devname = "ringdev";
|
|
|
|
if (devval > 0) {
|
|
|
|
globals.ringdev = devval;
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (func) {
|
2007-05-02 03:07:14 +00:00
|
|
|
if (http) {
|
2007-05-01 01:04:07 +00:00
|
|
|
stream->write_function(stream, "<pre>");
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
status = func(&argv[lead], argc - lead, stream);
|
2007-05-02 03:07:14 +00:00
|
|
|
if (http) {
|
2007-05-01 01:04:07 +00:00
|
|
|
stream->write_function(stream, "\n\n</pre>");
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
} else {
|
2007-02-16 16:19:39 +00:00
|
|
|
if (devname) {
|
|
|
|
if (devval > 0) {
|
|
|
|
stream->write_function(stream, "%s set to %d\n", devname, devval);
|
|
|
|
} else {
|
|
|
|
stream->write_function(stream, "%s not set (invalid value)\n", devname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->write_function(stream, "Unknown Command [%s]\n", argv[0]);
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-10-17 14:59:17 +00:00
|
|
|
done:
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-05-01 01:26:30 +00:00
|
|
|
if (http) {
|
2007-05-01 00:37:10 +00:00
|
|
|
|
|
|
|
stream->write_function(stream,
|
|
|
|
"<br><br><table align=center><tr><td><center><form method=post>\n"
|
|
|
|
"<input type=text name=wcmd size=40><br><br>\n"
|
|
|
|
|
|
|
|
"<input name=action type=submit value=\"call\"> "
|
|
|
|
"<input name=action type=submit value=\"hangup\"> "
|
|
|
|
"<input name=action type=submit value=\"list\"> "
|
|
|
|
"<input name=action type=submit value=\"switch\"> "
|
|
|
|
"<input name=action type=submit value=\"mute\"> "
|
|
|
|
"<input name=action type=submit value=\"unmute\"> "
|
|
|
|
"<input name=action type=submit value=\"answer\"> <br><br>"
|
|
|
|
"<table border=1>\n"
|
|
|
|
"<tr><td><input name=action type=submit value=\"1\"></td>"
|
|
|
|
"<td><input name=action type=submit value=\"2\"></td>"
|
2007-05-01 01:11:46 +00:00
|
|
|
"<td><input name=action type=submit value=\"3\"></td>\n"
|
|
|
|
"<td><input name=action type=submit value=\"A\"></td></tr>\n"
|
2007-05-01 00:37:10 +00:00
|
|
|
|
|
|
|
"<tr><td><input name=action type=submit value=\"4\"></td>"
|
|
|
|
"<td><input name=action type=submit value=\"5\"></td>"
|
2007-05-01 01:11:46 +00:00
|
|
|
"<td><input name=action type=submit value=\"6\"></td>\n"
|
|
|
|
"<td><input name=action type=submit value=\"B\"></td></tr>\n"
|
2007-05-01 00:37:10 +00:00
|
|
|
|
|
|
|
"<tr><td><input name=action type=submit value=\"7\"></td>"
|
|
|
|
"<td><input name=action type=submit value=\"8\"></td>"
|
2007-05-01 01:11:46 +00:00
|
|
|
"<td><input name=action type=submit value=\"9\"></td>\n"
|
|
|
|
"<td><input name=action type=submit value=\"C\"></td></tr>\n"
|
|
|
|
|
2007-05-01 00:37:10 +00:00
|
|
|
"<tr><td><input name=action type=submit value=\"*\"></td>"
|
|
|
|
"<td><input name=action type=submit value=\"0\"></td>"
|
2007-05-01 01:11:46 +00:00
|
|
|
"<td><input name=action type=submit value=\"#\"></td>\n"
|
|
|
|
"<td><input name=action type=submit value=\"D\"></td></tr>\n"
|
2007-05-01 00:37:10 +00:00
|
|
|
"</table>"
|
|
|
|
|
|
|
|
"</form><br></center></td></tr></table>\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_safe_free(mycmd);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
return status;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 22:30:48 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2007-02-09 02:36:03 +00:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 22:30:48 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|