Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
82394b37
提交
82394b37
authored
12月 01, 2010
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add switch_ivr_insert_file to insert one file into another at an arbitrary sample point
上级
a669f76f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
157 行增加
和
0 行删除
+157
-0
switch_ivr.h
src/include/switch_ivr.h
+1
-0
switch_ivr.c
src/switch_ivr.c
+156
-0
没有找到文件。
src/include/switch_ivr.h
浏览文件 @
82394b37
...
@@ -878,6 +878,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_realm(switch_ivr_dmachin
...
@@ -878,6 +878,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_realm(switch_ivr_dmachin
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_get_file_handle
(
switch_core_session_t
*
session
,
switch_file_handle_t
**
fh
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_get_file_handle
(
switch_core_session_t
*
session
,
switch_file_handle_t
**
fh
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_release_file_handle
(
switch_core_session_t
*
session
,
switch_file_handle_t
**
fh
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_release_file_handle
(
switch_core_session_t
*
session
,
switch_file_handle_t
**
fh
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_process_fh
(
switch_core_session_t
*
session
,
const
char
*
cmd
,
switch_file_handle_t
*
fhp
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_process_fh
(
switch_core_session_t
*
session
,
const
char
*
cmd
,
switch_file_handle_t
*
fhp
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_insert_file
(
switch_core_session_t
*
session
,
const
char
*
file
,
const
char
*
insert_file
,
switch_size_t
sample_point
);
/** @} */
/** @} */
...
...
src/switch_ivr.c
浏览文件 @
82394b37
...
@@ -2681,6 +2681,162 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_process_fh(switch_core_session_t *ses
...
@@ -2681,6 +2681,162 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_process_fh(switch_core_session_t *ses
}
}
#define START_SAMPLES 32768
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_insert_file
(
switch_core_session_t
*
session
,
const
char
*
file
,
const
char
*
insert_file
,
switch_size_t
sample_point
)
{
switch_file_handle_t
orig_fh
=
{
0
};
switch_file_handle_t
new_fh
=
{
0
};
switch_codec_implementation_t
read_impl
=
{
0
};
char
*
tmp_file
;
switch_uuid_t
uuid
;
char
uuid_str
[
SWITCH_UUID_FORMATTED_LENGTH
+
1
];
int16_t
*
abuf
=
NULL
;
switch_size_t
olen
=
0
;
int
asis
=
0
;
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_size_t
sample_count
=
0
;
uint32_t
pos
=
0
;
char
*
ext
;
switch_uuid_get
(
&
uuid
);
switch_uuid_format
(
uuid_str
,
&
uuid
);
if
((
ext
=
strrchr
(
file
,
'.'
)))
{
ext
++
;
}
else
{
ext
=
"wav"
;
}
tmp_file
=
switch_core_session_sprintf
(
session
,
"%s%smsg_%s.%s"
,
SWITCH_GLOBAL_dirs
.
temp_dir
,
SWITCH_PATH_SEPARATOR
,
uuid_str
,
ext
);
switch_core_session_get_read_impl
(
session
,
&
read_impl
);
new_fh
.
channels
=
read_impl
.
number_of_channels
;
new_fh
.
native_rate
=
read_impl
.
actual_samples_per_second
;
if
(
switch_core_file_open
(
&
new_fh
,
tmp_file
,
new_fh
.
channels
,
read_impl
.
actual_samples_per_second
,
SWITCH_FILE_FLAG_WRITE
|
SWITCH_FILE_DATA_SHORT
,
NULL
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Failed to open file %s
\n
"
,
tmp_file
);
goto
end
;
}
if
(
switch_core_file_open
(
&
orig_fh
,
file
,
new_fh
.
channels
,
read_impl
.
actual_samples_per_second
,
SWITCH_FILE_FLAG_READ
|
SWITCH_FILE_DATA_SHORT
,
NULL
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Failed to open file %s
\n
"
,
file
);
goto
end
;
}
switch_zmalloc
(
abuf
,
START_SAMPLES
*
sizeof
(
*
abuf
));
if
(
switch_test_flag
((
&
orig_fh
),
SWITCH_FILE_NATIVE
))
{
asis
=
1
;
}
while
(
switch_channel_ready
(
channel
))
{
olen
=
START_SAMPLES
;
if
(
!
asis
)
{
olen
/=
2
;
}
if
((
sample_count
+
olen
)
>
sample_point
)
{
olen
=
sample_point
-
sample_count
;
}
if
(
!
olen
||
switch_core_file_read
(
&
orig_fh
,
abuf
,
&
olen
)
!=
SWITCH_STATUS_SUCCESS
||
!
olen
)
{
break
;
}
sample_count
+=
olen
;
switch_core_file_write
(
&
new_fh
,
abuf
,
&
olen
);
}
switch_core_file_close
(
&
orig_fh
);
if
(
switch_core_file_open
(
&
orig_fh
,
insert_file
,
new_fh
.
channels
,
read_impl
.
actual_samples_per_second
,
SWITCH_FILE_FLAG_READ
|
SWITCH_FILE_DATA_SHORT
,
NULL
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Failed to open file %s
\n
"
,
file
);
goto
end
;
}
while
(
switch_channel_ready
(
channel
))
{
olen
=
START_SAMPLES
;
if
(
!
asis
)
{
olen
/=
2
;
}
if
(
switch_core_file_read
(
&
orig_fh
,
abuf
,
&
olen
)
!=
SWITCH_STATUS_SUCCESS
||
!
olen
)
{
break
;
}
sample_count
+=
olen
;
switch_core_file_write
(
&
new_fh
,
abuf
,
&
olen
);
}
switch_core_file_close
(
&
orig_fh
);
if
(
switch_core_file_open
(
&
orig_fh
,
file
,
new_fh
.
channels
,
read_impl
.
actual_samples_per_second
,
SWITCH_FILE_FLAG_READ
|
SWITCH_FILE_DATA_SHORT
,
NULL
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Failed to open file %s
\n
"
,
file
);
goto
end
;
}
pos
=
0
;
switch_core_file_seek
(
&
orig_fh
,
&
pos
,
sample_point
,
SEEK_SET
);
while
(
switch_channel_ready
(
channel
))
{
olen
=
START_SAMPLES
;
if
(
!
asis
)
{
olen
/=
2
;
}
if
(
switch_core_file_read
(
&
orig_fh
,
abuf
,
&
olen
)
!=
SWITCH_STATUS_SUCCESS
||
!
olen
)
{
break
;
}
sample_count
+=
olen
;
switch_core_file_write
(
&
new_fh
,
abuf
,
&
olen
);
}
end
:
if
(
switch_test_flag
((
&
orig_fh
),
SWITCH_FILE_OPEN
))
{
switch_core_file_close
(
&
orig_fh
);
}
if
(
switch_test_flag
((
&
new_fh
),
SWITCH_FILE_OPEN
))
{
switch_core_file_close
(
&
new_fh
);
}
switch_file_rename
(
tmp_file
,
file
,
switch_core_session_get_pool
(
session
));
unlink
(
tmp_file
);
switch_safe_free
(
abuf
);
return
SWITCH_STATUS_SUCCESS
;
}
/* For Emacs:
/* For Emacs:
* Local Variables:
* Local Variables:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论