Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
3248e06b
提交
3248e06b
authored
8月 19, 2013
作者:
Moises Silva
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add timer to mod_bert to avoid relying on remote RTP for timing
上级
ef694513
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
25 行删除
+44
-25
mod_bert.c
src/mod/applications/mod_bert/mod_bert.c
+44
-25
没有找到文件。
src/mod/applications/mod_bert/mod_bert.c
浏览文件 @
3248e06b
...
...
@@ -55,6 +55,7 @@ typedef struct {
switch_time_t
timeout
;
FILE
*
input_debug_f
;
FILE
*
output_debug_f
;
switch_timer_t
timer
;
}
bert_t
;
#define bert_increase_milliwatt_index(index) \
...
...
@@ -100,8 +101,11 @@ SWITCH_STANDARD_APP(bert_test_function)
const
char
*
var
=
NULL
;
int
i
=
0
;
int
synced
=
0
;
uint32_t
write_ts
=
0
;
int32_t
timeout_ms
=
0
;
int32_t
interval
=
20
;
int32_t
samples
=
0
;
uint8_t
*
write_samples
=
NULL
;
uint8_t
*
read_samples
=
NULL
;
bert_t
bert
=
{
0
};
memset
(
&
bert
,
0
,
sizeof
(
bert
));
...
...
@@ -161,6 +165,16 @@ SWITCH_STANDARD_APP(bert_test_function)
}
}
/* Setup the timer, so we can send audio at correct time frames even if we do not receive audio */
interval
=
read_impl
.
microseconds_per_packet
/
1000
;
samples
=
switch_samples_per_packet
(
read_impl
.
samples_per_second
,
interval
);
if
(
switch_core_timer_init
(
&
bert
.
timer
,
"soft"
,
interval
,
samples
,
switch_core_session_get_pool
(
session
))
==
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Setup timer success interval: %u samples: %u
\n
"
,
interval
,
samples
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Timer Setup Failed. BERT cannot start!
\n
"
);
goto
done
;
}
bert
.
timeout
=
(
switch_micro_time_now
()
+
(
timeout_ms
*
1000
));
write_frame
.
codec
=
switch_core_session_get_read_codec
(
session
);
...
...
@@ -174,10 +188,32 @@ SWITCH_STANDARD_APP(bert_test_function)
}
switch_channel_set_variable
(
channel
,
BERT_STATS_VAR_SYNC_LOST_CNT
,
"0"
);
switch_channel_set_variable
(
channel
,
BERT_STATS_VAR_SYNC_LOST
,
"false"
);
write_samples
=
write_frame
.
data
;
while
(
switch_channel_ready
(
channel
))
{
uint8_t
*
read_samples
=
NULL
;
uint8_t
*
write_samples
=
NULL
;
switch_core_timer_next
(
&
bert
.
timer
);
/* Write our frame before anything else happens */
for
(
i
=
0
;
i
<
read_impl
.
samples_per_packet
;
i
++
)
{
/* Calculate our next sequence sample to write */
bert
.
sequence_sample
=
ulaw_digital_milliwatt
[
bert
.
milliwatt_index
];
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[%d] 0x%X\n", bert.milliwatt_index, bert.sequence_sample);
bert_increase_milliwatt_index
(
bert
.
milliwatt_index
);
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[%d] 0x%X\n", bert.milliwatt_index, bert.sequence_sample);
write_samples
[
i
]
=
bert
.
sequence_sample
;
}
write_frame
.
datalen
=
read_impl
.
samples_per_packet
;
write_frame
.
samples
=
read_impl
.
samples_per_packet
;
write_frame
.
timestamp
=
bert
.
timer
.
samplecount
;
if
(
bert
.
output_debug_f
)
{
fwrite
(
write_frame
.
data
,
write_frame
.
datalen
,
1
,
bert
.
output_debug_f
);
}
status
=
switch_core_session_write_frame
(
session
,
&
write_frame
,
SWITCH_IO_FLAG_NONE
,
0
);
if
(
!
SWITCH_READ_ACCEPTABLE
(
status
))
{
break
;
}
/* Proceed to read and process the readed frame ... */
status
=
switch_core_session_read_frame
(
session
,
&
read_frame
,
SWITCH_IO_FLAG_NONE
,
0
);
if
(
!
SWITCH_READ_ACCEPTABLE
(
status
))
{
break
;
...
...
@@ -191,6 +227,7 @@ SWITCH_STANDARD_APP(bert_test_function)
if
(
bert
.
hangup_on_error
)
{
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_MEDIA_TIMEOUT
);
}
bert
.
timeout
=
0
;
}
}
...
...
@@ -200,12 +237,11 @@ SWITCH_STANDARD_APP(bert_test_function)
}
if
(
read_frame
->
samples
!=
read_impl
.
samples_per_packet
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"
Only r
ead %d samples, expected %d!
\n
"
,
read_frame
->
samples
,
read_impl
.
samples_per_packet
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"
R
ead %d samples, expected %d!
\n
"
,
read_frame
->
samples
,
read_impl
.
samples_per_packet
);
continue
;
}
read_samples
=
read_frame
->
data
;
write_samples
=
write_frame
.
data
;
if
(
bert
.
input_debug_f
)
{
size_t
ret
=
fwrite
(
read_frame
->
data
,
read_frame
->
datalen
,
1
,
bert
.
input_debug_f
);
if
(
ret
!=
1
)
{
...
...
@@ -262,36 +298,19 @@ SWITCH_STANDARD_APP(bert_test_function)
}
}
/* Calculate our next sequence sample to write */
bert
.
sequence_sample
=
ulaw_digital_milliwatt
[
bert
.
milliwatt_index
];
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[%d] 0x%X\n", bert.milliwatt_index, bert.sequence_sample);
bert_increase_milliwatt_index
(
bert
.
milliwatt_index
);
//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[%d] 0x%X\n", bert.milliwatt_index, bert.sequence_sample);
write_samples
[
i
]
=
bert
.
sequence_sample
;
/* Try to guess what the next sample will be in the milliwatt sequence */
bert
.
predicted_sample
=
ulaw_digital_milliwatt
[
bert
.
milliwatt_prediction_index
];
bert_increase_milliwatt_index
(
bert
.
milliwatt_prediction_index
);
bert
.
processed_samples
++
;
}
write_frame
.
datalen
=
read_frame
->
datalen
;
write_frame
.
samples
=
i
;
write_frame
.
timestamp
=
write_ts
;
if
(
bert
.
output_debug_f
)
{
fwrite
(
write_frame
.
data
,
write_frame
.
datalen
,
1
,
bert
.
output_debug_f
);
}
status
=
switch_core_session_write_frame
(
session
,
&
write_frame
,
SWITCH_IO_FLAG_NONE
,
0
);
if
(
!
SWITCH_READ_ACCEPTABLE
(
status
))
{
break
;
}
write_ts
+=
read_impl
.
samples_per_packet
;
}
done
:
bert_close_debug_streams
(
bert
,
session
);
if
(
bert
.
timer
.
interval
)
{
switch_core_timer_destroy
(
&
bert
.
timer
);
}
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"BERT Test Completed. MaxErr=%f%%
\n
"
,
synced
?
bert
.
max_err_hit
:
bert
.
max_err_ever
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论