Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
e4b24e84
提交
e4b24e84
authored
3月 19, 2011
作者:
Moises Silva
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mod_portaudio: XML parsing of endpoints
上级
5e4911ff
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
160 行增加
和
3 行删除
+160
-3
mod_portaudio.c
src/mod/endpoints/mod_portaudio/mod_portaudio.c
+160
-3
没有找到文件。
src/mod/endpoints/mod_portaudio/mod_portaudio.c
浏览文件 @
e4b24e84
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
* Contributor(s):
* Contributor(s):
*
*
* Anthony Minessale II <anthm@freeswitch.org>
* Anthony Minessale II <anthm@freeswitch.org>
* Moises Silva <moises.silva@gmail.com> (Multiple endpoints work sponsored by Comrex Corporation)
*
*
*
*
* mod_portaudio.c -- PortAudio Endpoint Module
* mod_portaudio.c -- PortAudio Endpoint Module
...
@@ -1102,6 +1103,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load)
...
@@ -1102,6 +1103,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load)
switch_console_set_complete
(
"add pa playdev"
);
switch_console_set_complete
(
"add pa playdev"
);
switch_console_set_complete
(
"add pa looptest"
);
switch_console_set_complete
(
"add pa looptest"
);
switch_console_set_complete
(
"add pa shstreams"
);
switch_console_set_complete
(
"add pa shstreams"
);
switch_console_set_complete
(
"add pa endpoints"
);
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
...
@@ -1122,11 +1124,17 @@ static switch_status_t load_streams(switch_xml_t streams)
...
@@ -1122,11 +1124,17 @@ static switch_status_t load_streams(switch_xml_t streams)
{
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
switch_xml_t
param
,
mystream
;
switch_xml_t
param
,
mystream
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Loading streams ...
\n
"
);
for
(
mystream
=
switch_xml_child
(
streams
,
"stream"
);
mystream
;
mystream
=
mystream
->
next
)
{
for
(
mystream
=
switch_xml_child
(
streams
,
"stream"
);
mystream
;
mystream
=
mystream
->
next
)
{
shared_audio_stream_t
*
stream
=
NULL
;
shared_audio_stream_t
*
stream
=
NULL
;
int
devval
=
-
1
;
int
devval
=
-
1
;
char
*
stream_name
=
(
char
*
)
switch_xml_attr_soft
(
mystream
,
"name"
);
char
*
stream_name
=
(
char
*
)
switch_xml_attr_soft
(
mystream
,
"name"
);
if
(
!
stream_name
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Missing stream name attribute, skipping ...
\n
"
);
continue
;
}
/* check if that stream name is not already used */
/* check if that stream name is not already used */
stream
=
switch_core_hash_find
(
globals
.
sh_streams
,
stream_name
);
stream
=
switch_core_hash_find
(
globals
.
sh_streams
,
stream_name
);
if
(
stream
)
{
if
(
stream
)
{
...
@@ -1140,6 +1148,7 @@ static switch_status_t load_streams(switch_xml_t streams)
...
@@ -1140,6 +1148,7 @@ static switch_status_t load_streams(switch_xml_t streams)
}
}
stream
->
indev
=
-
1
;
stream
->
indev
=
-
1
;
stream
->
outdev
=
-
1
;
stream
->
outdev
=
-
1
;
stream
->
sample_rate
=
globals
.
sample_rate
;
switch_snprintf
(
stream
->
name
,
sizeof
(
stream
->
name
),
"%s"
,
stream_name
);
switch_snprintf
(
stream
->
name
,
sizeof
(
stream
->
name
),
"%s"
,
stream_name
);
for
(
param
=
switch_xml_child
(
mystream
,
"param"
);
param
;
param
=
param
->
next
)
{
for
(
param
=
switch_xml_child
(
mystream
,
"param"
);
param
;
param
=
param
->
next
)
{
char
*
var
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"name"
);
char
*
var
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"name"
);
...
@@ -1148,6 +1157,8 @@ static switch_status_t load_streams(switch_xml_t streams)
...
@@ -1148,6 +1157,8 @@ static switch_status_t load_streams(switch_xml_t streams)
if
(
!
strcmp
(
var
,
"indev"
))
{
if
(
!
strcmp
(
var
,
"indev"
))
{
devval
=
check_device
(
val
,
1
);
devval
=
check_device
(
val
,
1
);
if
(
devval
<
0
)
{
if
(
devval
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid indev specified for stream '%s'
\n
"
,
stream_name
);
stream
->
indev
=
-
1
;
stream
->
indev
=
-
1
;
continue
;
continue
;
}
}
...
@@ -1178,7 +1189,7 @@ static switch_status_t load_streams(switch_xml_t streams)
...
@@ -1178,7 +1189,7 @@ static switch_status_t load_streams(switch_xml_t streams)
}
}
}
else
if
(
!
strcmp
(
var
,
"channels"
))
{
}
else
if
(
!
strcmp
(
var
,
"channels"
))
{
stream
->
channels
=
atoi
(
val
);
stream
->
channels
=
atoi
(
val
);
if
(
stream
->
channels
<
1
)
{
if
(
stream
->
channels
<
1
||
stream
->
channels
>
MAX_IO_CHANNELS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid number of channels specified for stream '%s', forcing to 1
\n
"
,
stream_name
);
"Invalid number of channels specified for stream '%s', forcing to 1
\n
"
,
stream_name
);
stream
->
channels
=
1
;
stream
->
channels
=
1
;
...
@@ -1197,10 +1208,130 @@ static switch_status_t load_streams(switch_xml_t streams)
...
@@ -1197,10 +1208,130 @@ static switch_status_t load_streams(switch_xml_t streams)
return
status
;
return
status
;
}
}
static
int
check_stream_compat
(
shared_audio_stream_t
*
in_stream
,
shared_audio_stream_t
*
out_stream
)
{
if
(
!
in_stream
||
!
out_stream
)
{
/* nothing to be compatible with */
return
0
;
}
if
(
in_stream
->
sample_rate
!=
out_stream
->
sample_rate
)
{
return
-
1
;
}
if
(
in_stream
->
codec_ms
!=
out_stream
->
codec_ms
)
{
return
-
1
;
}
return
0
;
}
static
shared_audio_stream_t
*
check_stream
(
char
*
streamstr
,
int
check_input
,
int
*
chanindex
)
{
shared_audio_stream_t
*
stream
=
NULL
;
int
cnum
=
0
;
char
stream_name
[
255
];
char
*
chan
=
NULL
;
*
chanindex
=
-
1
;
switch_snprintf
(
stream_name
,
sizeof
(
stream_name
),
"%s"
,
streamstr
);
chan
=
strchr
(
stream_name
,
':'
);
if
(
!
chan
)
{
return
NULL
;
}
*
chan
=
0
;
chan
++
;
cnum
=
atoi
(
chan
);
stream
=
switch_core_hash_find
(
globals
.
sh_streams
,
stream_name
);
if
(
!
stream
)
{
return
NULL
;
}
if
(
cnum
<
0
||
cnum
>
stream
->
channels
)
{
return
NULL
;
}
*
chanindex
=
cnum
;
return
stream
;
}
static
switch_status_t
load_endpoints
(
switch_xml_t
endpoints
)
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
switch_xml_t
param
,
myendpoint
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Loading endpoints ...
\n
"
);
for
(
myendpoint
=
switch_xml_child
(
endpoints
,
"endpoint"
);
myendpoint
;
myendpoint
=
myendpoint
->
next
)
{
audio_endpoint_t
*
endpoint
=
NULL
;
shared_audio_stream_t
*
stream
=
NULL
;
char
*
endpoint_name
=
(
char
*
)
switch_xml_attr_soft
(
myendpoint
,
"name"
);
if
(
!
endpoint_name
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Missing endpoint name attribute, skipping ...
\n
"
);
continue
;
}
/* check if that endpoint name is not already used */
endpoint
=
switch_core_hash_find
(
globals
.
endpoints
,
endpoint_name
);
if
(
endpoint
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"An endpoint with name '%s' already exists
\n
"
,
endpoint_name
);
continue
;
}
endpoint
=
switch_core_alloc
(
module_pool
,
sizeof
(
*
endpoint
));
if
(
!
endpoint
)
{
continue
;
}
endpoint
->
inchan
=
-
1
;
endpoint
->
outchan
=
-
1
;
switch_snprintf
(
endpoint
->
name
,
sizeof
(
endpoint
->
name
),
"%s"
,
endpoint_name
);
for
(
param
=
switch_xml_child
(
myendpoint
,
"param"
);
param
;
param
=
param
->
next
)
{
char
*
var
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"name"
);
char
*
val
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"value"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Parsing endpoint '%s' parameter %s = %s
\n
"
,
endpoint_name
,
var
,
val
);
if
(
!
strcmp
(
var
,
"instream"
))
{
stream
=
check_stream
(
val
,
1
,
&
endpoint
->
inchan
)
;
if
(
!
stream
)
{
endpoint
->
in_stream
=
NULL
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid instream specified for endpoint '%s'
\n
"
,
endpoint_name
);
continue
;
}
endpoint
->
in_stream
=
stream
;
}
else
if
(
!
strcmp
(
var
,
"outstream"
))
{
stream
=
check_stream
(
val
,
0
,
&
endpoint
->
outchan
);
if
(
!
stream
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid outstream specified for endpoint '%s'
\n
"
,
endpoint_name
);
endpoint
->
out_stream
=
NULL
;
continue
;
}
endpoint
->
out_stream
=
stream
;
}
}
if
(
!
endpoint
->
in_stream
&&
!
endpoint
->
out_stream
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"You need at least one stream for endpoint '%s'
\n
"
,
endpoint_name
);
continue
;
}
if
(
check_stream_compat
(
endpoint
->
in_stream
,
endpoint
->
out_stream
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Incomatible input and output streams for endpoint '%s'
\n
"
,
endpoint_name
);
continue
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Created endpoint '%s', instream = %s, outstream = %s
\n
"
,
endpoint
->
name
,
endpoint
->
in_stream
?
endpoint
->
in_stream
->
name
:
"(none)"
,
endpoint
->
out_stream
?
endpoint
->
out_stream
->
name
:
"(none)"
);
switch_core_hash_insert
(
globals
.
endpoints
,
endpoint
->
name
,
endpoint
);
}
return
status
;
}
static
switch_status_t
load_config
(
void
)
static
switch_status_t
load_config
(
void
)
{
{
char
*
cf
=
"portaudio.conf"
;
char
*
cf
=
"portaudio.conf"
;
switch_xml_t
cfg
,
xml
,
settings
,
streams
,
param
;
switch_xml_t
cfg
,
xml
,
settings
,
streams
,
endpoints
,
param
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
if
(
!
(
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
if
(
!
(
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
...
@@ -1299,6 +1430,10 @@ static switch_status_t load_config(void)
...
@@ -1299,6 +1430,10 @@ static switch_status_t load_config(void)
load_streams
(
streams
);
load_streams
(
streams
);
}
}
if
((
endpoints
=
switch_xml_child
(
cfg
,
"endpoints"
)))
{
load_endpoints
(
endpoints
);
}
if
(
!
globals
.
dialplan
)
{
if
(
!
globals
.
dialplan
)
{
set_global_dialplan
(
"XML"
);
set_global_dialplan
(
"XML"
);
}
}
...
@@ -1969,7 +2104,7 @@ static switch_status_t list_shared_streams(char **argv, int argc, switch_stream_
...
@@ -1969,7 +2104,7 @@ static switch_status_t list_shared_streams(char **argv, int argc, switch_stream_
shared_audio_stream_t
*
s
=
NULL
;
shared_audio_stream_t
*
s
=
NULL
;
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
s
=
val
;
s
=
val
;
stream
->
write_function
(
stream
,
"%s>
outdev: %d, in
dev: %d, sample-rate: %d, codec-ms: %d, channels: %d
\n
"
,
stream
->
write_function
(
stream
,
"%s>
indev: %d, out
dev: %d, sample-rate: %d, codec-ms: %d, channels: %d
\n
"
,
s
->
name
,
s
->
indev
,
s
->
outdev
,
s
->
sample_rate
,
s
->
codec_ms
,
s
->
channels
);
s
->
name
,
s
->
indev
,
s
->
outdev
,
s
->
sample_rate
,
s
->
codec_ms
,
s
->
channels
);
cnt
++
;
cnt
++
;
}
}
...
@@ -1977,6 +2112,25 @@ static switch_status_t list_shared_streams(char **argv, int argc, switch_stream_
...
@@ -1977,6 +2112,25 @@ static switch_status_t list_shared_streams(char **argv, int argc, switch_stream_
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
static
switch_status_t
list_endpoints
(
char
**
argv
,
int
argc
,
switch_stream_handle_t
*
stream
)
{
switch_hash_index_t
*
hi
;
int
cnt
=
0
;
for
(
hi
=
switch_hash_first
(
NULL
,
globals
.
endpoints
);
hi
;
hi
=
switch_hash_next
(
hi
))
{
const
void
*
var
;
void
*
val
;
audio_endpoint_t
*
e
=
NULL
;
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
e
=
val
;
stream
->
write_function
(
stream
,
"%s> instream: %s, outstream: %s
\n
"
,
e
->
name
,
e
->
in_stream
?
e
->
in_stream
->
name
:
"(none)"
,
e
->
out_stream
?
e
->
out_stream
->
name
:
"(none)"
);
cnt
++
;
}
stream
->
write_function
(
stream
,
"Total endpoints: %d
\n
"
,
cnt
);
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
close_streams
(
char
**
argv
,
int
argc
,
switch_stream_handle_t
*
stream
)
static
switch_status_t
close_streams
(
char
**
argv
,
int
argc
,
switch_stream_handle_t
*
stream
)
{
{
if
(
globals
.
call_list
)
{
if
(
globals
.
call_list
)
{
...
@@ -2547,6 +2701,7 @@ SWITCH_STANDARD_API(pa_cmd)
...
@@ -2547,6 +2701,7 @@ SWITCH_STANDARD_API(pa_cmd)
"pa ringfile [filename]
\n
"
"pa ringfile [filename]
\n
"
"pa looptest
\n
"
"pa looptest
\n
"
"pa shstreams
\n
"
"pa shstreams
\n
"
"pa endpoints
\n
"
"--------------------------------------------------------------------------------
\n
"
;
"--------------------------------------------------------------------------------
\n
"
;
...
@@ -2673,6 +2828,8 @@ SWITCH_STANDARD_API(pa_cmd)
...
@@ -2673,6 +2828,8 @@ SWITCH_STANDARD_API(pa_cmd)
func
=
set_ringfile
;
func
=
set_ringfile
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"shstreams"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"shstreams"
))
{
func
=
list_shared_streams
;
func
=
list_shared_streams
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"endpoints"
))
{
func
=
list_endpoints
;
}
else
{
}
else
{
stream
->
write_function
(
stream
,
"Unknown Command or not enough args [%s]
\n
"
,
argv
[
0
]);
stream
->
write_function
(
stream
,
"Unknown Command or not enough args [%s]
\n
"
,
argv
[
0
]);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论