Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
5e4911ff
提交
5e4911ff
authored
3月 19, 2011
作者:
Moises Silva
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mod_portaudio: added XML parsing and CLI commands for configuration of streams
上级
b05965c8
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
154 行增加
和
14 行删除
+154
-14
mod_portaudio.c
src/mod/endpoints/mod_portaudio/mod_portaudio.c
+152
-12
pablio.h
src/mod/endpoints/mod_portaudio/pablio.h
+2
-2
没有找到文件。
src/mod/endpoints/mod_portaudio/mod_portaudio.c
浏览文件 @
5e4911ff
...
...
@@ -45,6 +45,8 @@
#define MY_EVENT_ERROR_AUDIO_DEV "portaudio::audio_dev_error"
#define SWITCH_PA_CALL_ID_VARIABLE "pa_call_id"
#define MIN_STREAM_SAMPLE_RATE 8000
SWITCH_MODULE_LOAD_FUNCTION
(
mod_portaudio_load
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_portaudio_shutdown
);
//SWITCH_MODULE_RUNTIME_FUNCTION(mod_portaudio_runtime);
...
...
@@ -98,6 +100,18 @@ struct private_object {
typedef
struct
private_object
private_t
;
struct
audio_stream
{
int
indev
;
int
outdev
;
PABLIO_Stream
*
stream
;
switch_timer_t
write_timer
;
struct
audio_stream
*
next
;
};
typedef
struct
audio_stream
audio_stream_t
;
/* Audio stream that can be shared across endpoints */
typedef
struct
_shared_audio_stream_t
{
/*! Friendly name for this stream */
char
name
[
255
];
/*! Sampling rate */
int
sample_rate
;
/*! Buffer packetization (and therefore timing) */
...
...
@@ -106,21 +120,24 @@ struct audio_stream {
int
indev
;
/*! The PA output device */
int
outdev
;
/*! How many channels to create (for both indev and outdev) */
int
channels
;
/*! The io stream helper to buffer audio */
PABLIO_Stream
*
stream
;
/*! How often to write */
switch_timer_t
write_timer
;
/*! Next stream */
struct
audio_stream
*
next
;
};
typedef
struct
audio_stream
audio_stream_t
;
}
shared_audio_stream_t
;
/* Endpoint that can be called via portaudio/endpoint/<endpoint-name> */
typedef
struct
_audio_endpoint
{
/*! Friendly name for this endpoint */
char
name
[
255
];
typedef
struct
audio_endpoint
{
/*! Input stream for this endpoint */
audio_stream_t
*
in_stream
;
shared_
audio_stream_t
*
in_stream
;
/*! Output stream for this endpoint */
audio_stream_t
*
out_stream
;
shared_
audio_stream_t
*
out_stream
;
/*! Channel index within the input stream where we get the audio for this endpoint */
int
inchan
;
...
...
@@ -161,6 +178,10 @@ static struct {
unsigned
char
cngbuf
[
SWITCH_RECOMMENDED_BUFFER_SIZE
];
private_t
*
call_list
;
audio_stream_t
*
stream_list
;
/*! Streams that can be used by multiple endpoints at the same time */
switch_hash_t
*
sh_streams
;
/*! Endpoints configured */
switch_hash_t
*
endpoints
;
int
ring_interval
;
GFLAGS
flags
;
switch_timer_t
read_timer
;
...
...
@@ -994,12 +1015,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load)
memset
(
&
globals
,
0
,
sizeof
(
globals
));
switch_core_hash_init
(
&
globals
.
call_hash
,
module_pool
);
switch_core_hash_init
(
&
globals
.
sh_streams
,
module_pool
);
switch_core_hash_init
(
&
globals
.
endpoints
,
module_pool
);
switch_mutex_init
(
&
globals
.
device_lock
,
SWITCH_MUTEX_NESTED
,
module_pool
);
switch_mutex_init
(
&
globals
.
pvt_lock
,
SWITCH_MUTEX_NESTED
,
module_pool
);
switch_mutex_init
(
&
globals
.
streams_lock
,
SWITCH_MUTEX_NESTED
,
module_pool
);
switch_mutex_init
(
&
globals
.
flag_mutex
,
SWITCH_MUTEX_NESTED
,
module_pool
);
switch_mutex_init
(
&
globals
.
pa_mutex
,
SWITCH_MUTEX_NESTED
,
module_pool
);
globals
.
codecs_inited
=
0
;
globals
.
codecs_inited
=
0
;
globals
.
read_frame
.
data
=
globals
.
databuf
;
globals
.
read_frame
.
buflen
=
sizeof
(
globals
.
databuf
);
globals
.
cng_frame
.
data
=
globals
.
cngbuf
;
...
...
@@ -1078,16 +1101,106 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load)
switch_console_set_complete
(
"add pa play"
);
switch_console_set_complete
(
"add pa playdev"
);
switch_console_set_complete
(
"add pa looptest"
);
switch_console_set_complete
(
"add pa shstreams"
);
/* indicate that the module should continue to be loaded */
return
SWITCH_STATUS_SUCCESS
;
}
static
int
check_device
(
char
*
devstr
,
int
check_input
)
{
int
devval
;
if
(
devstr
[
0
]
==
'#'
)
{
devval
=
get_dev_by_number
(
devstr
+
1
,
check_input
);
}
else
{
devval
=
get_dev_by_name
(
devstr
,
check_input
);
}
return
devval
;
}
static
switch_status_t
load_streams
(
switch_xml_t
streams
)
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
switch_xml_t
param
,
mystream
;
for
(
mystream
=
switch_xml_child
(
streams
,
"stream"
);
mystream
;
mystream
=
mystream
->
next
)
{
shared_audio_stream_t
*
stream
=
NULL
;
int
devval
=
-
1
;
char
*
stream_name
=
(
char
*
)
switch_xml_attr_soft
(
mystream
,
"name"
);
/* check if that stream name is not already used */
stream
=
switch_core_hash_find
(
globals
.
sh_streams
,
stream_name
);
if
(
stream
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"A stream with name '%s' already exists
\n
"
,
stream_name
);
continue
;
}
stream
=
switch_core_alloc
(
module_pool
,
sizeof
(
*
stream
));
if
(
!
stream
)
{
continue
;
}
stream
->
indev
=
-
1
;
stream
->
outdev
=
-
1
;
switch_snprintf
(
stream
->
name
,
sizeof
(
stream
->
name
),
"%s"
,
stream_name
);
for
(
param
=
switch_xml_child
(
mystream
,
"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 stream '%s' parameter %s = %s
\n
"
,
stream_name
,
var
,
val
);
if
(
!
strcmp
(
var
,
"indev"
))
{
devval
=
check_device
(
val
,
1
);
if
(
devval
<
0
)
{
stream
->
indev
=
-
1
;
continue
;
}
stream
->
indev
=
devval
;
}
else
if
(
!
strcmp
(
var
,
"outdev"
))
{
devval
=
check_device
(
val
,
0
);
if
(
devval
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid outdev specified for stream '%s'
\n
"
,
stream_name
);
stream
->
outdev
=
-
1
;
continue
;
}
stream
->
outdev
=
devval
;
}
else
if
(
!
strcmp
(
var
,
"sample-rate"
))
{
stream
->
sample_rate
=
atoi
(
val
);
if
(
stream
->
sample_rate
<
MIN_STREAM_SAMPLE_RATE
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid sample rate specified for stream '%s', forcing to 8000
\n
"
,
stream_name
);
stream
->
sample_rate
=
MIN_STREAM_SAMPLE_RATE
;
}
}
else
if
(
!
strcmp
(
var
,
"codec-ms"
))
{
int
tmp
=
atoi
(
val
);
if
(
switch_check_interval
(
stream
->
sample_rate
,
tmp
))
{
stream
->
codec_ms
=
tmp
;
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"codec-ms must be multiple of 10 and less than %d, Using default of 20
\n
"
,
SWITCH_MAX_INTERVAL
);
}
}
else
if
(
!
strcmp
(
var
,
"channels"
))
{
stream
->
channels
=
atoi
(
val
);
if
(
stream
->
channels
<
1
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid number of channels specified for stream '%s', forcing to 1
\n
"
,
stream_name
);
stream
->
channels
=
1
;
}
}
}
if
(
stream
->
indev
<
0
&&
stream
->
outdev
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"You need at least one device for stream '%s'
\n
"
,
stream_name
);
continue
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Created stream '%s', sample-rate = %d, codec-ms = %d
\n
"
,
stream
->
name
,
stream
->
sample_rate
,
stream
->
codec_ms
);
switch_core_hash_insert
(
globals
.
sh_streams
,
stream
->
name
,
stream
);
}
return
status
;
}
static
switch_status_t
load_config
(
void
)
{
char
*
cf
=
"portaudio.conf"
;
switch_xml_t
cfg
,
xml
,
settings
,
param
;
switch_xml_t
cfg
,
xml
,
settings
,
streams
,
param
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
if
(
!
(
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
...
...
@@ -1182,6 +1295,10 @@ static switch_status_t load_config(void)
}
}
if
((
streams
=
switch_xml_child
(
cfg
,
"streams"
)))
{
load_streams
(
streams
);
}
if
(
!
globals
.
dialplan
)
{
set_global_dialplan
(
"XML"
);
}
...
...
@@ -1246,6 +1363,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown)
Pa_Terminate
();
switch_core_hash_destroy
(
&
globals
.
call_hash
);
switch_core_hash_destroy
(
&
globals
.
sh_streams
);
switch_core_hash_destroy
(
&
globals
.
endpoints
);
switch_event_free_subclass
(
MY_EVENT_RINGING
);
switch_event_free_subclass
(
MY_EVENT_MAKE_CALL
);
...
...
@@ -1744,12 +1863,12 @@ static audio_stream_t *create_audio_stream(int indev, int outdev)
switch_event_t
*
event
;
audio_stream_t
*
stream
;
stream
=
malloc
(
sizeof
(
audio_stream_t
));
stream
=
malloc
(
sizeof
(
*
stream
));
if
(
stream
==
NULL
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Unable to alloc memory
\n
"
);
return
NULL
;
}
memset
(
stream
,
0
,
sizeof
(
audio_stream_t
));
memset
(
stream
,
0
,
sizeof
(
*
stream
));
stream
->
next
=
NULL
;
stream
->
stream
=
NULL
;
stream
->
indev
=
indev
;
...
...
@@ -1840,6 +1959,24 @@ static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
list_shared_streams
(
char
**
argv
,
int
argc
,
switch_stream_handle_t
*
stream
)
{
switch_hash_index_t
*
hi
;
int
cnt
=
0
;
for
(
hi
=
switch_hash_first
(
NULL
,
globals
.
sh_streams
);
hi
;
hi
=
switch_hash_next
(
hi
))
{
const
void
*
var
;
void
*
val
;
shared_audio_stream_t
*
s
=
NULL
;
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
s
=
val
;
stream
->
write_function
(
stream
,
"%s> outdev: %d, indev: %d, sample-rate: %d, codec-ms: %d, channels: %d
\n
"
,
s
->
name
,
s
->
indev
,
s
->
outdev
,
s
->
sample_rate
,
s
->
codec_ms
,
s
->
channels
);
cnt
++
;
}
stream
->
write_function
(
stream
,
"Total streams: %d
\n
"
,
cnt
);
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
close_streams
(
char
**
argv
,
int
argc
,
switch_stream_handle_t
*
stream
)
{
if
(
globals
.
call_list
)
{
...
...
@@ -2409,6 +2546,7 @@ SWITCH_STANDARD_API(pa_cmd)
"pa playdev #<num> [ringtest|<filename>] [seconds] [no_close]
\n
"
"pa ringfile [filename]
\n
"
"pa looptest
\n
"
"pa shstreams
\n
"
"--------------------------------------------------------------------------------
\n
"
;
...
...
@@ -2533,6 +2671,8 @@ SWITCH_STANDARD_API(pa_cmd)
func
=
looptest
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"ringfile"
))
{
func
=
set_ringfile
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"shstreams"
))
{
func
=
list_shared_streams
;
}
else
{
stream
->
write_function
(
stream
,
"Unknown Command or not enough args [%s]
\n
"
,
argv
[
0
]);
}
...
...
src/mod/endpoints/mod_portaudio/pablio.h
浏览文件 @
5e4911ff
...
...
@@ -65,8 +65,8 @@ typedef struct {
int
do_dual
;
int
has_in
;
int
has_out
;
PaUtilRingBuffer
inFIFOs
[
2
];
PaUtilRingBuffer
outFIFOs
[
2
];
PaUtilRingBuffer
inFIFOs
[
MAX_IO_CHANNELS
];
PaUtilRingBuffer
outFIFOs
[
MAX_IO_CHANNELS
];
int
channelCount
;
}
PABLIO_Stream
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论