Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
9aab1831
提交
9aab1831
authored
12月 16, 2005
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix pa
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@162
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
89cfca15
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
64 行增加
和
22 行删除
+64
-22
mod_portaudio.c
src/mod/mod_portaudio/mod_portaudio.c
+52
-21
switch_core.c
src/switch_core.c
+12
-1
没有找到文件。
src/mod/mod_portaudio/mod_portaudio.c
浏览文件 @
9aab1831
...
@@ -45,6 +45,7 @@ static switch_memory_pool *module_pool;
...
@@ -45,6 +45,7 @@ static switch_memory_pool *module_pool;
//static int running = 1;
//static int running = 1;
#define SAMPLE_TYPE paInt16
#define SAMPLE_TYPE paInt16
//#define SAMPLE_TYPE paFloat32
typedef
short
SAMPLE
;
typedef
short
SAMPLE
;
typedef
enum
{
typedef
enum
{
...
@@ -73,6 +74,7 @@ static struct {
...
@@ -73,6 +74,7 @@ static struct {
int
outdev
;
int
outdev
;
int
call_id
;
int
call_id
;
switch_hash
*
call_hash
;
switch_hash
*
call_hash
;
switch_mutex_t
*
device_lock
;
}
globals
;
}
globals
;
struct
private_object
{
struct
private_object
{
...
@@ -178,6 +180,20 @@ static switch_status channel_on_execute(switch_core_session *session)
...
@@ -178,6 +180,20 @@ static switch_status channel_on_execute(switch_core_session *session)
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
static
void
deactivate_audio_device
(
struct
private_object
*
tech_pvt
)
{
switch_mutex_lock
(
globals
.
device_lock
);
if
(
tech_pvt
->
audio_in
)
{
CloseAudioStream
(
tech_pvt
->
audio_in
);
tech_pvt
->
audio_in
=
NULL
;
}
if
(
tech_pvt
->
audio_out
)
{
CloseAudioStream
(
tech_pvt
->
audio_out
);
tech_pvt
->
audio_out
=
NULL
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
}
static
switch_status
channel_on_hangup
(
switch_core_session
*
session
)
static
switch_status
channel_on_hangup
(
switch_core_session
*
session
)
{
{
switch_channel
*
channel
=
NULL
;
switch_channel
*
channel
=
NULL
;
...
@@ -195,8 +211,7 @@ static switch_status channel_on_hangup(switch_core_session *session)
...
@@ -195,8 +211,7 @@ static switch_status channel_on_hangup(switch_core_session *session)
switch_core_codec_destroy
(
&
tech_pvt
->
read_codec
);
switch_core_codec_destroy
(
&
tech_pvt
->
read_codec
);
switch_core_codec_destroy
(
&
tech_pvt
->
write_codec
);
switch_core_codec_destroy
(
&
tech_pvt
->
write_codec
);
CloseAudioStream
(
tech_pvt
->
audio_in
);
deactivate_audio_device
(
tech_pvt
);
CloseAudioStream
(
tech_pvt
->
audio_out
);
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"%s CHANNEL HANGUP
\n
"
,
switch_channel_get_name
(
channel
));
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"%s CHANNEL HANGUP
\n
"
,
switch_channel_get_name
(
channel
));
...
@@ -215,6 +230,9 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig)
...
@@ -215,6 +230,9 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig)
assert
(
tech_pvt
!=
NULL
);
assert
(
tech_pvt
!=
NULL
);
switch_clear_flag
(
tech_pvt
,
TFLAG_IO
);
switch_clear_flag
(
tech_pvt
,
TFLAG_IO
);
deactivate_audio_device
(
tech_pvt
);
switch_channel_hangup
(
channel
);
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"%s CHANNEL KILL
\n
"
,
switch_channel_get_name
(
channel
));
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"%s CHANNEL KILL
\n
"
,
switch_channel_get_name
(
channel
));
...
@@ -290,7 +308,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
...
@@ -290,7 +308,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
caller_profile
=
switch_caller_profile_clone
(
*
new_session
,
outbound_profile
);
caller_profile
=
switch_caller_profile_clone
(
*
new_session
,
outbound_profile
);
switch_channel_set_caller_profile
(
channel
,
caller_profile
);
switch_channel_set_caller_profile
(
channel
,
caller_profile
);
tech_pvt
->
caller_profile
=
caller_profile
;
tech_pvt
->
caller_profile
=
caller_profile
;
snprintf
(
name
,
sizeof
(
name
),
"PortAudio/%s-%04x"
,
caller_profile
->
destination_number
,
rand
()
&
0xffff
);
snprintf
(
name
,
sizeof
(
name
),
"PortAudio/%s-%04x"
,
caller_profile
->
destination_number
?
caller_profile
->
destination_number
:
modname
,
rand
()
&
0xffff
);
switch_channel_set_name
(
channel
,
name
);
switch_channel_set_name
(
channel
,
name
);
}
else
{
}
else
{
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Doh! no caller profile
\n
"
);
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Doh! no caller profile
\n
"
);
...
@@ -357,6 +375,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
...
@@ -357,6 +375,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
switch_channel
*
channel
=
NULL
;
switch_channel
*
channel
=
NULL
;
struct
private_object
*
tech_pvt
=
NULL
;
struct
private_object
*
tech_pvt
=
NULL
;
int
samples
;
int
samples
;
switch_status
status
=
SWITCH_STATUS_FALSE
;
channel
=
switch_core_session_get_channel
(
session
);
channel
=
switch_core_session_get_channel
(
session
);
assert
(
channel
!=
NULL
);
assert
(
channel
!=
NULL
);
...
@@ -367,23 +387,25 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
...
@@ -367,23 +387,25 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
if
((
samples
=
ReadAudioStream
(
tech_pvt
->
audio_in
,
tech_pvt
->
read_frame
.
data
,
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
)))
{
switch_mutex_lock
(
globals
.
device_lock
);
if
(
tech_pvt
->
audio_in
&&
(
samples
=
ReadAudioStream
(
tech_pvt
->
audio_in
,
tech_pvt
->
read_frame
.
data
,
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
)))
{
tech_pvt
->
read_frame
.
datalen
=
samples
*
2
;
tech_pvt
->
read_frame
.
datalen
=
samples
*
2
;
tech_pvt
->
read_frame
.
samples
=
samples
;
tech_pvt
->
read_frame
.
samples
=
samples
;
*
frame
=
&
tech_pvt
->
read_frame
;
*
frame
=
&
tech_pvt
->
read_frame
;
return
SWITCH_STATUS_SUCCESS
;
status
=
SWITCH_STATUS_SUCCESS
;
}
}
switch_mutex_unlock
(
globals
.
device_lock
);
return
status
;
return
SWITCH_STATUS_FALSE
;
}
}
static
switch_status
channel_write_frame
(
switch_core_session
*
session
,
switch_frame
*
frame
,
int
timeout
,
switch_io_flag
flags
)
static
switch_status
channel_write_frame
(
switch_core_session
*
session
,
switch_frame
*
frame
,
int
timeout
,
switch_io_flag
flags
)
{
{
switch_channel
*
channel
=
NULL
;
switch_channel
*
channel
=
NULL
;
struct
private_object
*
tech_pvt
=
NULL
;
struct
private_object
*
tech_pvt
=
NULL
;
//switch_frame *pframe;
switch_status
status
=
SWITCH_STATUS_FALSE
;
channel
=
switch_core_session_get_channel
(
session
);
channel
=
switch_core_session_get_channel
(
session
);
assert
(
channel
!=
NULL
);
assert
(
channel
!=
NULL
);
...
@@ -394,10 +416,14 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
...
@@ -394,10 +416,14 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
WriteAudioStream
(
tech_pvt
->
audio_out
,
(
short
*
)
frame
->
data
,
(
int
)(
frame
->
datalen
/
sizeof
(
SAMPLE
)));
switch_mutex_lock
(
globals
.
device_lock
);
//XXX send voice
if
(
tech_pvt
->
audio_out
)
{
WriteAudioStream
(
tech_pvt
->
audio_out
,
(
short
*
)
frame
->
data
,
(
int
)(
frame
->
datalen
/
sizeof
(
SAMPLE
)));
status
=
SWITCH_STATUS_SUCCESS
;
}
switch_mutex_unlock
(
globals
.
device_lock
);
return
SWITCH_STATUS_SUCCESS
;
return
status
;
}
}
...
@@ -503,7 +529,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
...
@@ -503,7 +529,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
Pa_Initialize
();
Pa_Initialize
();
load_config
();
load_config
();
switch_core_hash_init
(
&
globals
.
call_hash
,
module_pool
);
switch_core_hash_init
(
&
globals
.
call_hash
,
module_pool
);
switch_mutex_init
(
&
globals
.
device_lock
,
SWITCH_MUTEX_NESTED
,
module_pool
);
dump_info
();
dump_info
();
if
(
switch_event_reserve_subclass
(
MY_EVENT_RINGING
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_event_reserve_subclass
(
MY_EVENT_RINGING
)
!=
SWITCH_STATUS_SUCCESS
)
{
...
@@ -552,7 +579,7 @@ static switch_status load_config(void)
...
@@ -552,7 +579,7 @@ static switch_status load_config(void)
if
(
*
val
==
'#'
)
{
if
(
*
val
==
'#'
)
{
globals
.
outdev
=
atoi
(
val
+
1
);
globals
.
outdev
=
atoi
(
val
+
1
);
}
else
{
}
else
{
globals
.
outdev
=
get_dev_by_name
(
val
,
1
);
globals
.
outdev
=
get_dev_by_name
(
val
,
0
);
}
}
}
}
}
}
...
@@ -703,14 +730,18 @@ static switch_status engage_device(struct private_object *tech_pvt)
...
@@ -703,14 +730,18 @@ static switch_status engage_device(struct private_object *tech_pvt)
tech_pvt
->
indev
=
globals
.
indev
;
tech_pvt
->
indev
=
globals
.
indev
;
tech_pvt
->
outdev
=
globals
.
outdev
;
tech_pvt
->
outdev
=
globals
.
outdev
;
switch_mutex_lock
(
globals
.
device_lock
);
if
((
tech_pvt
->
err
=
OpenAudioStream
(
&
tech_pvt
->
audio_in
,
sample_rate
,
SAMPLE_TYPE
,
PABLIO_READ
|
PABLIO_MONO
,
tech_pvt
->
indev
,
-
1
))
==
paNoError
)
{
if
((
tech_pvt
->
err
=
OpenAudioStream
(
&
tech_pvt
->
audio_in
,
sample_rate
,
SAMPLE_TYPE
,
PABLIO_READ
|
PABLIO_MONO
,
tech_pvt
->
indev
,
-
1
))
==
paNoError
)
{
if
((
tech_pvt
->
err
=
OpenAudioStream
(
&
tech_pvt
->
audio_out
,
sample_rate
,
SAMPLE_TYPE
,
PABLIO_WRITE
|
PABLIO_MONO
,
-
1
,
tech_pvt
->
outdev
))
!=
paNoError
)
{
if
((
tech_pvt
->
err
=
OpenAudioStream
(
&
tech_pvt
->
audio_out
,
sample_rate
,
SAMPLE_TYPE
,
PABLIO_WRITE
|
PABLIO_MONO
,
-
1
,
tech_pvt
->
outdev
))
!=
paNoError
)
{
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Can't open audio out
!
\n
"
);
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Can't open audio out
[%d]!
\n
"
,
tech_pvt
->
outdev
);
CloseAudioStream
(
tech_pvt
->
audio_in
);
CloseAudioStream
(
tech_pvt
->
audio_in
);
tech_pvt
->
audio_in
=
NULL
;
}
}
}
else
{
}
else
{
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Can't open audio in
!
\n
"
);
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Can't open audio in
[%d]!
\n
"
,
tech_pvt
->
indev
);
}
}
switch_mutex_unlock
(
globals
.
device_lock
);
if
(
tech_pvt
->
err
==
paNoError
)
{
if
(
tech_pvt
->
err
==
paNoError
)
{
snprintf
(
tech_pvt
->
call_id
,
sizeof
(
tech_pvt
->
call_id
),
"%d"
,
globals
.
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_hash_insert
(
globals
.
call_hash
,
tech_pvt
->
call_id
,
tech_pvt
);
...
@@ -759,7 +790,7 @@ static switch_status place_call(char *dest, char *out, size_t outlen)
...
@@ -759,7 +790,7 @@ static switch_status place_call(char *dest, char *out, size_t outlen)
dest
)))
{
dest
)))
{
char
name
[
128
];
char
name
[
128
];
switch_channel_set_caller_profile
(
channel
,
tech_pvt
->
caller_profile
);
switch_channel_set_caller_profile
(
channel
,
tech_pvt
->
caller_profile
);
snprintf
(
name
,
sizeof
(
name
),
"PortAudio/%s-%04x"
,
tech_pvt
->
caller_profile
->
destination_number
,
rand
()
&
0xffff
);
snprintf
(
name
,
sizeof
(
name
),
"PortAudio/%s-%04x"
,
tech_pvt
->
caller_profile
->
destination_number
?
tech_pvt
->
caller_profile
->
destination_number
:
modname
,
rand
()
&
0xffff
);
switch_channel_set_name
(
channel
,
name
);
switch_channel_set_name
(
channel
,
name
);
}
}
tech_pvt
->
session
=
session
;
tech_pvt
->
session
=
session
;
...
@@ -866,10 +897,10 @@ static void print_info(struct private_object *tech_pvt, char *out, size_t outlen
...
@@ -866,10 +897,10 @@ static void print_info(struct private_object *tech_pvt, char *out, size_t outlen
snprintf
(
out
,
outlen
,
"CALL %s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
,
snprintf
(
out
,
outlen
,
"CALL %s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
,
tech_pvt
->
call_id
,
tech_pvt
->
call_id
,
tech_pvt
->
caller_profile
->
caller_id_name
,
tech_pvt
->
caller_profile
->
caller_id_name
?
tech_pvt
->
caller_profile
->
caller_id_name
:
"n/a"
,
tech_pvt
->
caller_profile
->
caller_id_number
,
tech_pvt
->
caller_profile
->
caller_id_number
?
tech_pvt
->
caller_profile
->
caller_id_number
:
"n/a"
,
tech_pvt
->
caller_profile
->
destination_number
,
tech_pvt
->
caller_profile
->
destination_number
?
tech_pvt
->
caller_profile
->
destination_number
:
"n/a"
,
switch_channel_get_name
(
channel
));
switch_channel_get_name
(
channel
));
}
}
...
...
src/switch_core.c
浏览文件 @
9aab1831
...
@@ -104,6 +104,14 @@ static int handle_SIGPIPE(int sig)
...
@@ -104,6 +104,14 @@ static int handle_SIGPIPE(int sig)
return
0
;
return
0
;
}
}
#ifdef TRAP_BUS
static
int
handle_SIGBUS
(
int
sig
)
{
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Sig BUS!
\n
"
);
return
0
;
}
#endif
/* no ctl-c mofo */
/* no ctl-c mofo */
static
int
handle_SIGINT
(
int
sig
)
static
int
handle_SIGINT
(
int
sig
)
{
{
...
@@ -1083,7 +1091,7 @@ static void switch_core_standard_on_ring(switch_core_session *session)
...
@@ -1083,7 +1091,7 @@ static void switch_core_standard_on_ring(switch_core_session *session)
switch_channel_set_state
(
session
->
channel
,
CS_HANGUP
);
switch_channel_set_state
(
session
->
channel
,
CS_HANGUP
);
}
else
{
}
else
{
if
(
!
(
dialplan_interface
=
loadable_module_get_dialplan_interface
(
caller_profile
->
dialplan
)))
{
if
(
!
(
dialplan_interface
=
loadable_module_get_dialplan_interface
(
caller_profile
->
dialplan
)))
{
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Can't get dialplan
%s
!
\n
"
,
caller_profile
->
dialplan
);
switch_console_printf
(
SWITCH_CHANNEL_CONSOLE
,
"Can't get dialplan
[%s]
!
\n
"
,
caller_profile
->
dialplan
);
switch_channel_set_state
(
session
->
channel
,
CS_HANGUP
);
switch_channel_set_state
(
session
->
channel
,
CS_HANGUP
);
}
else
{
}
else
{
if
((
extension
=
dialplan_interface
->
hunt_function
(
session
)))
{
if
((
extension
=
dialplan_interface
->
hunt_function
(
session
)))
{
...
@@ -1547,6 +1555,9 @@ SWITCH_DECLARE(switch_status) switch_core_init(void)
...
@@ -1547,6 +1555,9 @@ SWITCH_DECLARE(switch_status) switch_core_init(void)
(
void
)
signal
(
SIGINT
,(
void
*
)
handle_SIGINT
);
(
void
)
signal
(
SIGINT
,(
void
*
)
handle_SIGINT
);
#ifdef SIGPIPE
#ifdef SIGPIPE
(
void
)
signal
(
SIGPIPE
,(
void
*
)
handle_SIGPIPE
);
(
void
)
signal
(
SIGPIPE
,(
void
*
)
handle_SIGPIPE
);
#endif
#ifdef TRAP_BUS
(
void
)
signal
(
SIGBUS
,(
void
*
)
handle_SIGBUS
);
#endif
#endif
time
(
&
runtime
.
initiated
);
time
(
&
runtime
.
initiated
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论