Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
319d3661
提交
319d3661
authored
4月 27, 2007
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@5030
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
e90d0380
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
267 行增加
和
226 行删除
+267
-226
mod_alsa.c
src/mod/endpoints/mod_alsa/mod_alsa.c
+180
-226
sofia.c
src/mod/endpoints/mod_sofia/sofia.c
+8
-0
mod_xml_rpc.c
src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
+79
-0
没有找到文件。
src/mod/endpoints/mod_alsa/mod_alsa.c
浏览文件 @
319d3661
...
...
@@ -26,7 +26,7 @@
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* mod_
portaudio.c -- PortAudio
Endpoint Module
* mod_
alsa.c -- Alsa
Endpoint Module
*
*/
#include <switch.h>
...
...
@@ -99,6 +99,7 @@ static struct {
char
*
ring_file
;
char
*
hold_file
;
char
*
timer_name
;
char
*
device_name
;
int
call_id
;
switch_hash_t
*
call_hash
;
switch_mutex_t
*
device_lock
;
...
...
@@ -108,7 +109,7 @@ static struct {
int
codec_ms
;
snd_pcm_t
*
audio_stream_in
;
snd_pcm_t
*
audio_stream_out
;
snd_pcm_t
*
ring_stream
;
switch_codec_t
read_codec
;
switch_codec_t
write_codec
;
...
...
@@ -127,33 +128,31 @@ static struct {
#define PA_SLAVE 0
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
)
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
)
//;
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_device_name
,
globals
.
device_name
)
//;
#define is_master(t) switch_test_flag(t, TFLAG_MASTER)
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
,
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
(
unsigned
int
samplerate
,
int
codec_ms
);
static
switch_status_t
engage_ring_device
(
unsigned
int
sample_rate
,
int
channels
);
static
void
deactivate_ring_device
(
void
);
static
switch_status_t
load_config
(
void
);
static
switch_status_t
pa_cmd
(
char
*
dest
,
switch_core_session_t
*
session
,
switch_stream_handle_t
*
stream
);
static
switch_status_t
padep
(
char
*
dest
,
switch_core_session_t
*
session
,
switch_stream_handle_t
*
stream
);
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
(
unsigned
int
samplerate
,
int
codec_ms
);
static
switch_status_t
load_config
(
void
);
static
switch_status_t
pa_cmd
(
char
*
dest
,
switch_core_session_t
*
session
,
switch_stream_handle_t
*
stream
);
/*
...
...
@@ -161,7 +160,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
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.
*/
static
switch_status_t
channel_on_init
(
switch_core_session_t
*
session
)
static
switch_status_t
channel_on_init
(
switch_core_session_t
*
session
)
{
switch_channel_t
*
channel
;
private_t
*
tech_pvt
=
NULL
;
...
...
@@ -224,7 +223,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
globals
.
read_codec
.
implementation
->
samples_per_second
,
SWITCH_FILE_FLAG_READ
|
SWITCH_FILE_DATA_SHORT
,
NULL
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
engage_
ring_
device
(
fh
.
samplerate
,
fh
.
channels
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
engage_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
);
...
...
@@ -265,7 +264,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
if
(
olen
==
0
)
{
break
;
}
snd_pcm_writei
(
globals
.
ring_stream
,
abuf
,
(
int
)
olen
);
snd_pcm_writei
(
globals
.
audio_stream_out
,
abuf
,
(
int
)
olen
);
}
}
}
...
...
@@ -277,7 +276,6 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
}
if
(
ring_file
)
{
deactivate_ring_device
();
switch_core_file_close
(
&
fh
);
switch_core_codec_destroy
(
&
tech_pvt
->
write_codec
);
switch_core_timer_destroy
(
&
tech_pvt
->
timer
);
...
...
@@ -335,27 +333,22 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
static
void
deactivate_audio_device
(
void
)
{
switch_mutex_lock
(
globals
.
device_lock
);
if
(
globals
.
audio_stream_in
)
{
snd_pcm_drain
(
globals
.
audio_stream_in
);
snd_pcm_close
(
globals
.
audio_stream_in
);
globals
.
audio_stream_in
=
NULL
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Close IN stream
\n
"
);
}
if
(
globals
.
audio_stream_out
)
{
snd_pcm_drain
(
globals
.
audio_stream_out
);
snd_pcm_close
(
globals
.
audio_stream_out
);
globals
.
audio_stream_out
=
NULL
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Close OUT stream
\n
"
);
}
switch_mutex_unlock
(
globals
.
device_lock
);
}
static
void
deactivate_ring_device
(
void
)
{
switch_mutex_lock
(
globals
.
device_lock
);
if
(
globals
.
ring_stream
)
{
snd_pcm_close
(
globals
.
ring_stream
);
globals
.
ring_stream
=
NULL
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"DONE
\n
"
);
}
...
...
@@ -423,8 +416,7 @@ static void remove_pvt(private_t * tech_pvt)
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
();
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"No more channels
\n
"
);
}
switch_mutex_unlock
(
globals
.
pvt_lock
);
...
...
@@ -638,11 +630,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
}
switch_mutex_lock
(
globals
.
device_lock
);
if
((
samples
=
snd_pcm_readi
(
globals
.
audio_stream_in
,
globals
.
read_frame
.
data
,
globals
.
read_codec
.
implementation
->
samples_per_frame
))
!=
0
)
{
globals
.
read_frame
.
datalen
=
samples
/
2
;
globals
.
read_frame
.
samples
=
globals
.
read_frame
.
datalen
/
2
;
if
((
samples
=
snd_pcm_readi
(
globals
.
audio_stream_in
,
globals
.
read_frame
.
data
,
globals
.
read_codec
.
implementation
->
samples_per_frame
))
>
0
)
{
globals
.
read_frame
.
datalen
=
samples
*
2
;
globals
.
read_frame
.
samples
=
samples
;
switch_core_timer_check
(
&
globals
.
timer
);
globals
.
read_frame
.
timestamp
=
globals
.
timer
.
samplecount
;
...
...
@@ -734,52 +724,12 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_api_interface_t
send_dtmf_interface
=
{
/*.interface_name */
"padtmf"
,
/*.desc */
"DEPRICATED (see 'pa')"
,
/*.function */
padep
,
/*.syntax */
"DEPRICATED (see 'pa')"
,
/*.next */
NULL
};
static
switch_api_interface_t
answer_call_interface
=
{
/*.interface_name */
"paoffhook"
,
/*.desc */
"DEPRICATED (see 'pa')"
,
/*.function */
padep
,
/*.syntax */
"DEPRICATED (see 'pa')"
,
/*.next */
&
send_dtmf_interface
};
static
switch_api_interface_t
channel_info_interface
=
{
/*.interface_name */
"painfo"
,
/*.desc */
"DEPRICATED (see 'pa')"
,
/*.function */
padep
,
/*.syntax */
"DEPRICATED (see 'pa')"
,
/*.next */
&
answer_call_interface
};
static
switch_api_interface_t
channel_hup_interface
=
{
/*.interface_name */
"pahup"
,
/*.desc */
"DEPRICATED (see 'pa')"
,
/*.function */
padep
,
/*.syntax */
"DEPRICATED (see 'pa')"
,
/*.next */
&
channel_info_interface
};
static
switch_api_interface_t
channel_call_interface
=
{
/*.interface_name */
"pacall"
,
/*.desc */
"DEPRICATED (see 'pa')"
,
/*.function */
padep
,
/*.syntax */
"DEPRICATED (see 'pa')"
,
/*.next */
&
channel_hup_interface
};
static
switch_api_interface_t
channel_api_interface
=
{
/*.interface_name */
"
p
a"
,
/*.interface_name */
"
als
a"
,
/*.desc */
"Alsa"
,
/*.function */
pa_cmd
,
/*.syntax */
"<command> [<args>]"
,
/*.next */
&
channel_call_interface
/*.next */
};
static
const
switch_state_handler_table_t
channel_event_handlers
=
{
...
...
@@ -947,6 +897,8 @@ static switch_status_t load_config(void)
set_global_hold_file
(
val
);
}
else
if
(
!
strcmp
(
var
,
"timer-name"
))
{
set_global_timer_name
(
val
);
}
else
if
(
!
strcmp
(
var
,
"device-name"
))
{
set_global_device_name
(
val
);
}
else
if
(
!
strcmp
(
var
,
"sample-rate"
))
{
globals
.
sample_rate
=
atoi
(
val
);
}
else
if
(
!
strcmp
(
var
,
"codec-ms"
))
{
...
...
@@ -965,6 +917,10 @@ static switch_status_t load_config(void)
set_global_dialplan
(
"default"
);
}
if
(
!
globals
.
device_name
)
{
set_global_device_name
(
"default"
);
}
if
(
!
globals
.
sample_rate
)
{
globals
.
sample_rate
=
8000
;
}
...
...
@@ -988,6 +944,8 @@ static switch_status_t load_config(void)
SWITCH_MOD_DECLARE
(
switch_status_t
)
switch_module_shutdown
(
void
)
{
deactivate_audio_device
();
if
(
globals
.
read_codec
.
implementation
)
{
switch_core_codec_destroy
(
&
globals
.
read_codec
);
}
...
...
@@ -1005,7 +963,7 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
{
int
err
=
0
;
snd_pcm_hw_params_t
*
hw_params
=
NULL
;
char
*
device
=
"default"
;
char
*
device
=
globals
.
device_name
;
if
(
globals
.
audio_stream_in
&&
globals
.
audio_stream_out
)
{
return
SWITCH_STATUS_SUCCESS
;
...
...
@@ -1121,13 +1079,13 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
hw_params
=
NULL
;
if
((
err
=
snd_pcm_open
(
&
globals
.
audio_stream_in
,
device
,
SND_PCM_STREAM_CAPTURE
,
0
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot open audio device %s (%s)
\n
"
,
device
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_hw_params_malloc
(
&
hw_params
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot allocate hardware parameter structure (%s)
\n
"
,
snd_strerror
(
err
));
...
...
@@ -1164,152 +1122,71 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
goto
fail
;
}
if
((
err
=
snd_pcm_hw_params
(
globals
.
audio_stream_in
,
hw_params
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set p
arameters
(%s)
\n
"
,
if
((
err
=
snd_pcm_hw_params
_set_period_time
(
globals
.
audio_stream_in
,
hw_params
,
globals
.
read_codec
.
implementation
->
microseconds_per_frame
,
0
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set p
eriod time
(%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
(
hw_params
)
{
snd_pcm_hw_params_free
(
hw_params
);
hw_params
=
NULL
;
}
if
((
err
=
snd_pcm_prepare
(
globals
.
audio_stream_out
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot prepare audio interface for use (%s)
\n
"
,
if
((
err
=
snd_pcm_hw_params_set_period_size
(
globals
.
audio_stream_in
,
hw_params
,
globals
.
read_codec
.
implementation
->
samples_per_frame
,
0
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set period size (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_
prepare
(
globals
.
audio_stream_in
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot
prepare audio interface for use
(%s)
\n
"
,
if
((
err
=
snd_pcm_
hw_params
(
globals
.
audio_stream_in
,
hw_params
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot
set parameters
(%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
return
SWITCH_STATUS_SUCCESS
;
fail
:
if
(
hw_params
)
{
snd_pcm_hw_params_free
(
hw_params
);
hw_params
=
NULL
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
if
(
globals
.
audio_stream_in
)
{
snd_pcm_close
(
globals
.
audio_stream_in
);
}
if
(
globals
.
audio_stream_out
)
{
snd_pcm_close
(
globals
.
audio_stream_out
);
}
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
;
}
static
switch_status_t
engage_ring_device
(
unsigned
int
sample_rate
,
int
channels
)
{
int
err
=
0
;
snd_pcm_hw_params_t
*
hw_params
;
char
*
device
=
"default"
;
if
(
globals
.
ring_stream
)
{
return
SWITCH_STATUS_SUCCESS
;
}
if
(
!
sample_rate
)
{
sample_rate
=
globals
.
sample_rate
;
}
switch_mutex_lock
(
globals
.
device_lock
);
/* LOCKED ************************************************************************************************** */
if
((
err
=
snd_pcm_open
(
&
globals
.
ring_stream
,
device
,
SND_PCM_STREAM_PLAYBACK
,
0
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot open audio device %s (%s)
\n
"
,
device
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_hw_params_malloc
(
&
hw_params
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot allocate hardware parameter structure (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_hw_params_any
(
globals
.
ring_stream
,
hw_params
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot initialize hardware parameter structure (%s)
\n
"
,
if
((
err
=
snd_pcm_prepare
(
globals
.
audio_stream_out
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot prepare audio interface for use (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_
hw_params_set_access
(
globals
.
ring_stream
,
hw_params
,
SND_PCM_ACCESS_RW_INTERLEAVED
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot s
et access typ
e (%s)
\n
"
,
if
((
err
=
snd_pcm_
start
(
globals
.
audio_stream_out
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot s
tart audio interface for us
e (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_
hw_params_set_format
(
globals
.
ring_stream
,
hw_params
,
SND_PCM_FORMAT_S16_LE
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot
set sample format
(%s)
\n
"
,
if
((
err
=
snd_pcm_
prepare
(
globals
.
audio_stream_in
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot
prepare audio interface for use
(%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_
hw_params_set_rate_near
(
globals
.
ring_stream
,
hw_params
,
&
sample_rate
,
0
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot s
et sample rat
e (%s)
\n
"
,
if
((
err
=
snd_pcm_
start
(
globals
.
audio_stream_in
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot s
tart audio interface for us
e (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
if
((
err
=
snd_pcm_hw_params_set_channels
(
globals
.
ring_stream
,
hw_params
,
1
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set channel count (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
return
SWITCH_STATUS_SUCCESS
;
if
((
err
=
snd_pcm_hw_params
(
globals
.
ring_stream
,
hw_params
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set parameters (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
fail
:
if
(
hw_params
)
{
snd_pcm_hw_params_free
(
hw_params
);
hw_params
=
NULL
;
}
if
((
err
=
snd_pcm_prepare
(
globals
.
ring_stream
))
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot prepare audio interface for use (%s)
\n
"
,
snd_strerror
(
err
));
goto
fail
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
return
SWITCH_STATUS_SUCCESS
;
fail
:
switch_mutex_unlock
(
globals
.
device_lock
);
if
(
hw_params
)
{
snd_pcm_hw_params_free
(
hw_params
);
hw_params
=
NULL
;
if
(
globals
.
audio_stream_in
)
{
snd_pcm_close
(
globals
.
audio_stream_in
);
}
if
(
globals
.
ring_stream
)
{
snd_pcm_close
(
globals
.
ring_stream
);
if
(
globals
.
audio_stream_out
)
{
snd_pcm_close
(
globals
.
audio_stream_out
);
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Can't open audio device!
\n
"
);
...
...
@@ -1317,6 +1194,9 @@ static switch_status_t engage_ring_device(unsigned int sample_rate, int channels
switch_core_codec_destroy
(
&
globals
.
write_codec
);
return
SWITCH_STATUS_FALSE
;
}
static
switch_status_t
dtmf_call
(
char
**
argv
,
int
argc
,
switch_stream_handle_t
*
stream
)
...
...
@@ -1636,12 +1516,6 @@ static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
padep
(
char
*
cmd
,
switch_core_session_t
*
isession
,
switch_stream_handle_t
*
stream
)
{
stream
->
write_function
(
stream
,
"This command no longer exists (try 'pa help')
\n
"
);
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
pa_cmd
(
char
*
cmd
,
switch_core_session_t
*
isession
,
switch_stream_handle_t
*
stream
)
{
char
*
argv
[
1024
]
=
{
0
};
...
...
@@ -1650,23 +1524,67 @@ static switch_status_t pa_cmd(char *cmd, switch_core_session_t *isession, switch
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
pa_command_t
func
=
NULL
;
int
lead
=
1
,
devval
=
0
;
char
*
wcmd
=
NULL
,
*
action
=
NULL
;
char
cmd_buf
[
1024
]
=
""
;
const
char
*
usage_string
=
"USAGE:
\n
"
"--------------------------------------------------------------------------------
\n
"
"
p
a help
\n
"
"
p
a dump
\n
"
"
p
a call <dest> [<dialplan> <cid_name> <cid_num> <rate>]
\n
"
"
p
a answer [<call_id>]
\n
"
"
p
a hangup [<call_id>]
\n
"
"
p
a list
\n
"
"
p
a switch [<call_id>|none]
\n
"
"
p
a dtmf <digit string>
\n
"
"
p
a flags [on|off] [ear] [mouth]
\n
"
"
als
a help
\n
"
"
als
a dump
\n
"
"
als
a call <dest> [<dialplan> <cid_name> <cid_num> <rate>]
\n
"
"
als
a answer [<call_id>]
\n
"
"
als
a hangup [<call_id>]
\n
"
"
als
a list
\n
"
"
als
a switch [<call_id>|none]
\n
"
"
als
a dtmf <digit string>
\n
"
"
als
a flags [on|off] [ear] [mouth]
\n
"
"--------------------------------------------------------------------------------
\n
"
;
if
(
stream
->
event
)
{
#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
;
}
}
if
(
!
(
mycmd
=
strdup
(
cmd
)))
{
status
=
SWITCH_STATUS_MEMERR
;
...
...
@@ -1713,6 +1631,42 @@ static switch_status_t pa_cmd(char *cmd, switch_core_session_t *isession, switch
done
:
if
(
stream
->
event
)
{
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>"
"<td><input name=action type=submit value=
\"
3
\"
></td></tr>
\n
"
"<tr><td><input name=action type=submit value=
\"
4
\"
></td>"
"<td><input name=action type=submit value=
\"
5
\"
></td>"
"<td><input name=action type=submit value=
\"
6
\"
></td></tr>
\n
"
"<tr><td><input name=action type=submit value=
\"
7
\"
></td>"
"<td><input name=action type=submit value=
\"
8
\"
></td>"
"<td><input name=action type=submit value=
\"
9
\"
></td></tr>
\n
"
"<tr><td><input name=action type=submit value=
\"
*
\"
></td>"
"<td><input name=action type=submit value=
\"
0
\"
></td>"
"<td><input name=action type=submit value=
\"
#
\"
></td></tr>
\n
"
"</table>"
"</form><br></center></td></tr></table>
\n
"
);
}
switch_safe_free
(
mycmd
);
return
status
;
...
...
src/mod/endpoints/mod_sofia/sofia.c
浏览文件 @
319d3661
...
...
@@ -254,11 +254,15 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
profile
->
s_root
=
su_root_create
(
NULL
);
profile
->
home
=
su_home_new
(
sizeof
(
*
profile
->
home
));
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Creating agent for %s
\n
"
,
profile
->
name
);
profile
->
nua
=
nua_create
(
profile
->
s_root
,
/* Event loop */
sofia_event_callback
,
/* Callback for processing events */
profile
,
/* Additional data to pass to callback */
NUTAG_URL
(
profile
->
bindurl
),
NTATAG_UDP_MTU
(
65536
),
TAG_END
());
/* Last tag should always finish the sequence */
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Created agent for %s
\n
"
,
profile
->
name
);
nua_set_params
(
profile
->
nua
,
//NUTAG_EARLY_MEDIA(1),
NUTAG_AUTOANSWER
(
0
),
...
...
@@ -275,6 +279,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
TAG_IF
((
profile
->
pflags
&
PFLAG_PRESENCE
),
NUTAG_ALLOW_EVENTS
(
"message-summary"
)),
SIPTAG_SUPPORTED_STR
(
"100rel, precondition"
),
SIPTAG_USER_AGENT_STR
(
SOFIA_USER_AGENT
),
TAG_END
());
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Set params for %s
\n
"
,
profile
->
name
);
for
(
node
=
profile
->
aliases
;
node
;
node
=
node
->
next
)
{
node
->
nua
=
nua_create
(
profile
->
s_root
,
/* Event loop */
...
...
@@ -301,6 +306,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
goto
end
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"activated db for %s
\n
"
,
profile
->
name
);
switch_mutex_init
(
&
profile
->
ireg_mutex
,
SWITCH_MUTEX_NESTED
,
profile
->
pool
);
switch_mutex_init
(
&
profile
->
gateway_mutex
,
SWITCH_MUTEX_NESTED
,
profile
->
pool
);
...
...
@@ -332,6 +338,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
sofia_presence_establish_presence
(
profile
);
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Starting thread for %s
\n
"
,
profile
->
name
);
while
(
mod_sofia_globals
.
running
==
1
)
{
if
(
++
ireg_loops
>=
IREG_SECONDS
)
{
sofia_reg_check_expire
(
profile
,
time
(
NULL
));
...
...
src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
浏览文件 @
319d3661
...
...
@@ -169,6 +169,9 @@ abyss_bool HandleHook(TSession * r)
}
if
(
switch_event_create
(
&
stream
.
event
,
SWITCH_EVENT_API
)
==
SWITCH_STATUS_SUCCESS
)
{
const
char
*
const
content_length
=
RequestHeaderValue
(
r
,
"content-length"
);
if
(
r
->
uri
)
switch_event_add_header
(
stream
.
event
,
SWITCH_STACK_BOTTOM
,
"HTTP-URI"
,
"%s"
,
r
->
uri
);
if
(
r
->
query
)
...
...
@@ -187,6 +190,82 @@ abyss_bool HandleHook(TSession * r)
switch_event_add_header
(
stream
.
event
,
SWITCH_STACK_BOTTOM
,
"HTTP-USER"
,
"%s"
,
r
->
user
);
if
(
r
->
port
)
switch_event_add_header
(
stream
.
event
,
SWITCH_STACK_BOTTOM
,
"HTTP-PORT"
,
"%u"
,
r
->
port
);
if
(
r
->
query
||
content_length
)
{
char
*
q
,
*
qd
;
char
*
next
;
char
*
query
=
r
->
query
;
char
*
name
,
*
val
;
char
qbuf
[
8192
]
=
""
;
if
(
r
->
method
==
m_post
&&
content_length
)
{
int
len
=
atoi
(
content_length
);
int
qlen
=
0
;
if
(
len
>
0
)
{
int
succeeded
;
char
*
qp
=
qbuf
;
do
{
int
blen
=
r
->
conn
->
buffersize
-
r
->
conn
->
bufferpos
;
if
((
qlen
+
blen
)
>
len
)
{
blen
=
len
-
qlen
;
}
qlen
+=
blen
;
if
(
qlen
>
sizeof
(
qbuf
)
)
{
break
;
}
memcpy
(
qp
,
r
->
conn
->
buffer
+
r
->
conn
->
bufferpos
,
blen
);
qp
+=
blen
;
if
(
qlen
>=
len
)
{
break
;
}
}
while
((
succeeded
=
ConnRead
(
r
->
conn
,
r
->
server
->
timeout
)));
query
=
qbuf
;
}
}
if
(
query
)
{
switch_event_add_header
(
stream
.
event
,
SWITCH_STACK_BOTTOM
,
"HTTP-QUERY"
,
"%s"
,
query
);
qd
=
strdup
(
query
);
assert
(
qd
!=
NULL
);
q
=
qd
;
next
=
q
;
do
{
char
*
p
;
if
((
next
=
strchr
(
next
,
'&'
)))
{
*
next
++
=
'\0'
;
}
for
(
p
=
q
;
p
&&
*
p
;
p
++
)
{
if
(
*
p
==
'+'
)
{
*
p
=
' '
;
}
}
switch_url_decode
(
q
);
name
=
q
;
if
((
val
=
strchr
(
name
,
'='
)))
{
*
val
++
=
'\0'
;
switch_event_add_header
(
stream
.
event
,
SWITCH_STACK_BOTTOM
,
name
,
"%s"
,
val
);
}
q
=
next
;
}
while
(
q
!=
NULL
);
free
(
qd
);
}
}
}
command
=
r
->
uri
+
5
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论