Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
72c3df5e
提交
72c3df5e
authored
12月 02, 2014
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-6891 FS-6713 #comment revert
1b612fec
上级
b9c25eae
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
111 行删除
+45
-111
switch_core_io.c
src/switch_core_io.c
+1
-1
switch_ivr_async.c
src/switch_ivr_async.c
+44
-110
没有找到文件。
src/switch_core_io.c
浏览文件 @
72c3df5e
...
@@ -1414,7 +1414,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
...
@@ -1414,7 +1414,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
switch_time_t
tdiff
=
diff
;
switch_time_t
tdiff
=
diff
;
while
(
tdiff
>
1
)
{
while
(
tdiff
>
1
)
{
switch_buffer_write
(
bp
->
raw_
write
_buffer
,
fill_data
,
len
);
switch_buffer_write
(
bp
->
raw_
read
_buffer
,
fill_data
,
len
);
tdiff
--
;
tdiff
--
;
}
}
}
}
...
...
src/switch_ivr_async.c
浏览文件 @
72c3df5e
...
@@ -1043,20 +1043,8 @@ struct record_helper {
...
@@ -1043,20 +1043,8 @@ struct record_helper {
switch_time_t
last_write_time
;
switch_time_t
last_write_time
;
switch_bool_t
hangup_on_error
;
switch_bool_t
hangup_on_error
;
switch_codec_implementation_t
read_impl
;
switch_codec_implementation_t
read_impl
;
switch_bool_t
speech_detected
;
const
char
*
completion_cause
;
};
};
/**
* Set the recording completion cause. The cause can only be set once, to minimize the logic in the record_callback.
* [The completion_cause strings are essentially those of an MRCP Recorder resource.]
*/
static
void
set_completion_cause
(
struct
record_helper
*
rh
,
const
char
*
completion_cause
)
{
if
(
!
rh
->
completion_cause
)
{
rh
->
completion_cause
=
completion_cause
;
}
}
static
switch_bool_t
is_silence_frame
(
switch_frame_t
*
frame
,
int
silence_threshold
,
switch_codec_implementation_t
*
codec_impl
)
static
switch_bool_t
is_silence_frame
(
switch_frame_t
*
frame
,
int
silence_threshold
,
switch_codec_implementation_t
*
codec_impl
)
{
{
...
@@ -1084,30 +1072,6 @@ static switch_bool_t is_silence_frame(switch_frame_t *frame, int silence_thresho
...
@@ -1084,30 +1072,6 @@ static switch_bool_t is_silence_frame(switch_frame_t *frame, int silence_thresho
return
is_silence
;
return
is_silence
;
}
}
static
void
send_record_stop_event
(
switch_channel_t
*
channel
,
switch_codec_implementation_t
*
read_impl
,
struct
record_helper
*
rh
)
{
switch_event_t
*
event
;
if
(
rh
->
fh
)
{
switch_channel_set_variable_printf
(
channel
,
"record_samples"
,
"%d"
,
rh
->
fh
->
samples_out
);
if
(
read_impl
->
actual_samples_per_second
)
{
switch_channel_set_variable_printf
(
channel
,
"record_seconds"
,
"%d"
,
rh
->
fh
->
samples_out
/
read_impl
->
actual_samples_per_second
);
switch_channel_set_variable_printf
(
channel
,
"record_ms"
,
"%d"
,
rh
->
fh
->
samples_out
/
(
read_impl
->
actual_samples_per_second
/
1000
));
}
}
if
(
!
zstr
(
rh
->
completion_cause
))
{
switch_channel_set_variable_printf
(
channel
,
"record_completion_cause"
,
"%s"
,
rh
->
completion_cause
);
}
if
(
switch_event_create
(
&
event
,
SWITCH_EVENT_RECORD_STOP
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_channel_event_set_data
(
channel
,
event
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Record-File-Path"
,
rh
->
file
);
if
(
!
zstr
(
rh
->
completion_cause
))
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Record-Completion-Cause"
,
rh
->
completion_cause
);
}
switch_event_fire
(
&
event
);
}
}
static
switch_bool_t
record_callback
(
switch_media_bug_t
*
bug
,
void
*
user_data
,
switch_abc_type_t
type
)
static
switch_bool_t
record_callback
(
switch_media_bug_t
*
bug
,
void
*
user_data
,
switch_abc_type_t
type
)
{
{
...
@@ -1129,8 +1093,6 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
...
@@ -1129,8 +1093,6 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
}
}
rh
->
silence_time
=
switch_micro_time_now
();
rh
->
silence_time
=
switch_micro_time_now
();
rh
->
silence_timeout_ms
=
rh
->
initial_timeout_ms
;
rh
->
silence_timeout_ms
=
rh
->
initial_timeout_ms
;
rh
->
speech_detected
=
SWITCH_FALSE
;
rh
->
completion_cause
=
NULL
;
switch_core_session_get_read_impl
(
session
,
&
rh
->
read_impl
);
switch_core_session_get_read_impl
(
session
,
&
rh
->
read_impl
);
...
@@ -1237,15 +1199,10 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
...
@@ -1237,15 +1199,10 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
while
(
switch_core_media_bug_read
(
bug
,
&
frame
,
SWITCH_TRUE
)
==
SWITCH_STATUS_SUCCESS
)
{
while
(
switch_core_media_bug_read
(
bug
,
&
frame
,
SWITCH_TRUE
)
==
SWITCH_STATUS_SUCCESS
)
{
len
=
(
switch_size_t
)
frame
.
datalen
/
2
;
len
=
(
switch_size_t
)
frame
.
datalen
/
2
;
if
(
len
&&
switch_core_file_write
(
rh
->
fh
,
mask
?
null_data
:
data
,
&
len
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
len
&&
switch_core_file_write
(
rh
->
fh
,
mask
?
null_data
:
data
,
&
len
)
!=
SWITCH_STATUS_SUCCESS
&&
rh
->
hangup_on_error
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Error writing %s
\n
"
,
rh
->
file
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Error writing %s
\n
"
,
rh
->
file
);
/* File write failed */
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER
);
set_completion_cause
(
rh
,
"uri-failure"
);
switch_core_session_reset
(
session
,
SWITCH_TRUE
,
SWITCH_TRUE
);
if
(
rh
->
hangup_on_error
)
{
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER
);
switch_core_session_reset
(
session
,
SWITCH_TRUE
,
SWITCH_TRUE
);
}
send_record_stop_event
(
channel
,
&
read_impl
,
rh
);
return
SWITCH_FALSE
;
return
SWITCH_FALSE
;
}
}
}
}
...
@@ -1256,27 +1213,22 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
...
@@ -1256,27 +1213,22 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Discarding short file %s
\n
"
,
rh
->
file
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Discarding short file %s
\n
"
,
rh
->
file
);
switch_channel_set_variable
(
channel
,
"RECORD_DISCARDED"
,
"true"
);
switch_channel_set_variable
(
channel
,
"RECORD_DISCARDED"
,
"true"
);
switch_file_remove
(
rh
->
file
,
switch_core_session_get_pool
(
session
));
switch_file_remove
(
rh
->
file
,
switch_core_session_get_pool
(
session
));
set_completion_cause
(
rh
,
"input-too-short"
);
}
}
if
(
switch_channel_down_nosig
(
channel
))
{
if
(
read_impl
.
actual_samples_per_second
)
{
/* We got hung up */
switch_channel_set_variable_printf
(
channel
,
"record_seconds"
,
"%d"
,
rh
->
fh
->
samples_out
/
read_impl
.
actual_samples_per_second
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Channel is hung up
\n
"
);
switch_channel_set_variable_printf
(
channel
,
"record_ms"
,
"%d"
,
rh
->
fh
->
samples_out
/
(
read_impl
.
actual_samples_per_second
/
1000
));
if
(
rh
->
speech_detected
)
{
/* Treat it as equivalent with final-silence */
set_completion_cause
(
rh
,
"success-silence"
);
}
else
{
/* Treat it as equivalent with inital-silence timeout */
set_completion_cause
(
rh
,
"no-input-timeout"
);
}
}
else
{
/* Set the completion_cause to maxtime reached, unless it's already set */
set_completion_cause
(
rh
,
"success-maxtime"
);
}
}
switch_channel_set_variable_printf
(
channel
,
"record_samples"
,
"%d"
,
rh
->
fh
->
samples_out
);
}
}
send_record_stop_event
(
channel
,
&
read_impl
,
rh
);
if
(
switch_event_create
(
&
event
,
SWITCH_EVENT_RECORD_STOP
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_channel_event_set_data
(
channel
,
event
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Record-File-Path"
,
rh
->
file
);
switch_event_fire
(
&
event
);
}
switch_channel_execute_on
(
channel
,
SWITCH_RECORD_POST_PROCESS_EXEC_APP_VARIABLE
);
switch_channel_execute_on
(
channel
,
SWITCH_RECORD_POST_PROCESS_EXEC_APP_VARIABLE
);
if
((
var
=
switch_channel_get_variable
(
channel
,
SWITCH_RECORD_POST_PROCESS_EXEC_API_VARIABLE
)))
{
if
((
var
=
switch_channel_get_variable
(
channel
,
SWITCH_RECORD_POST_PROCESS_EXEC_API_VARIABLE
)))
{
...
@@ -1316,65 +1268,47 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
...
@@ -1316,65 +1268,47 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
frame
.
data
=
data
;
frame
.
data
=
data
;
frame
.
buflen
=
SWITCH_RECOMMENDED_BUFFER_SIZE
;
frame
.
buflen
=
SWITCH_RECOMMENDED_BUFFER_SIZE
;
for
(;;)
{
status
=
switch_core_media_bug_read
(
bug
,
&
frame
,
SWITCH_FALSE
);
status
=
switch_core_media_bug_read
(
bug
,
&
frame
,
SWITCH_FALSE
);
if
(
status
==
SWITCH_STATUS_SUCCESS
||
status
==
SWITCH_STATUS_BREAK
)
{
if
(
status
==
SWITCH_STATUS_SUCCESS
||
status
==
SWITCH_STATUS_BREAK
)
{
len
=
(
switch_size_t
)
frame
.
datalen
/
2
;
len
=
(
switch_size_t
)
frame
.
datalen
/
2
;
if
(
len
&&
switch_core_file_write
(
rh
->
fh
,
mask
?
null_data
:
data
,
&
len
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
len
&&
switch_core_file_write
(
rh
->
fh
,
mask
?
null_data
:
data
,
&
len
)
!=
SWITCH_STATUS_SUCCESS
&&
rh
->
hangup_on_error
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Error writing %s
\n
"
,
rh
->
file
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Error writing %s
\n
"
,
rh
->
file
);
/* File write failed */
set_completion_cause
(
rh
,
"uri-failure"
);
if
(
rh
->
hangup_on_error
)
{
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER
);
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER
);
switch_core_session_reset
(
session
,
SWITCH_TRUE
,
SWITCH_TRUE
);
switch_core_session_reset
(
session
,
SWITCH_TRUE
,
SWITCH_TRUE
);
return
SWITCH_FALSE
;
}
}
return
SWITCH_FALSE
;
}
/* check for silence timeout */
/* check for silence timeout */
if
(
rh
->
silence_threshold
)
{
if
(
rh
->
silence_threshold
)
{
switch_codec_implementation_t
read_impl
=
{
0
};
switch_codec_implementation_t
read_impl
=
{
0
};
switch_core_session_get_read_impl
(
session
,
&
read_impl
);
switch_core_session_get_read_impl
(
session
,
&
read_impl
);
if
(
is_silence_frame
(
&
frame
,
rh
->
silence_threshold
,
&
read_impl
))
{
if
(
is_silence_frame
(
&
frame
,
rh
->
silence_threshold
,
&
read_impl
))
{
if
(
!
rh
->
silence_time
)
{
if
(
!
rh
->
silence_time
)
{
/* start of silence */
/* start of silence */
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Start of silence detected
\n
"
);
rh
->
silence_time
=
switch_micro_time_now
();
rh
->
silence_time
=
switch_micro_time_now
();
}
else
{
}
else
{
/* continuing silence */
/* continuing silence */
int
duration_ms
=
(
int
)((
switch_micro_time_now
()
-
rh
->
silence_time
)
/
1000
);
int
duration_ms
=
(
int
)((
switch_micro_time_now
()
-
rh
->
silence_time
)
/
1000
);
if
(
rh
->
silence_timeout_ms
>
0
&&
duration_ms
>=
rh
->
silence_timeout_ms
)
{
if
(
rh
->
silence_timeout_ms
>
0
&&
duration_ms
>=
rh
->
silence_timeout_ms
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Recording file %s timeout: %i >= %i
\n
"
,
rh
->
file
,
duration_ms
,
rh
->
silence_timeout_ms
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Recording file %s timeout: %i >= %i
\n
"
,
rh
->
file
,
duration_ms
,
rh
->
silence_timeout_ms
);
switch_core_media_bug_set_flag
(
bug
,
SMBF_PRUNE
);
if
(
rh
->
speech_detected
)
{
/* Reached final silence timeout */
set_completion_cause
(
rh
,
"success-silence"
);
}
else
{
/* Reached initial silence timeout */
set_completion_cause
(
rh
,
"no-input-timeout"
);
/* Discard the silent file? */
}
}
switch_core_media_bug_set_flag
(
bug
,
SMBF_PRUNE
);
}
}
}
}
else
{
/* not silence */
}
else
{
/* not silence */
if
(
rh
->
silence_time
)
{
if
(
rh
->
silence_time
)
{
/* end of silence */
/* end of silence */
rh
->
silence_time
=
0
;
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"Start of speech detected
\n
"
);
/* switch from initial timeout to final timeout */
rh
->
speech_detected
=
SWITCH_TRUE
;
rh
->
silence_timeout_ms
=
rh
->
final_timeout_ms
;
rh
->
silence_time
=
0
;
}
/* switch from initial timeout to final timeout */
rh
->
silence_timeout_ms
=
rh
->
final_timeout_ms
;
}
}
}
}
}
else
{
}
else
{
/* no silence detection */
break
;
if
(
!
rh
->
speech_detected
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"No silence detection configured; assuming start of speech
\n
"
);
rh
->
speech_detected
=
SWITCH_TRUE
;
}
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论