Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
72ec7b59
提交
72ec7b59
authored
4月 23, 2010
作者:
Mathieu Rene
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tweak bridge_early_media to support passthrough codecs
上级
5e4b0400
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
117 行增加
和
58 行删除
+117
-58
switch_ivr_originate.c
src/switch_ivr_originate.c
+117
-58
没有找到文件。
src/switch_ivr_originate.c
浏览文件 @
72ec7b59
...
...
@@ -372,6 +372,38 @@ static switch_bool_t monitor_callback(switch_core_session_t *session, const char
return
SWITCH_FALSE
;
}
static
void
inherit_codec
(
switch_channel_t
*
caller_channel
,
switch_core_session_t
*
session
)
{
const
char
*
var
=
switch_channel_get_variable
(
caller_channel
,
"inherit_codec"
);
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
if
(
switch_true
(
var
))
{
switch_codec_implementation_t
impl
=
{
0
};
switch_codec_implementation_t
video_impl
=
{
0
};
char
tmp
[
128
]
=
""
;
if
(
switch_core_session_get_read_impl
(
session
,
&
impl
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_core_session_get_video_read_impl
(
session
,
&
impl
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%s@%uh@%ui,%s"
,
impl
.
iananame
,
impl
.
samples_per_second
,
impl
.
microseconds_per_packet
/
1000
,
video_impl
.
iananame
);
}
else
{
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%s@%uh@%ui"
,
impl
.
iananame
,
impl
.
samples_per_second
,
impl
.
microseconds_per_packet
/
1000
);
}
switch_channel_set_variable
(
caller_channel
,
"absolute_codec_string"
,
tmp
);
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
caller_channel
),
SWITCH_LOG_DEBUG
,
"Setting codec string on %s to %s
\n
"
,
switch_channel_get_name
(
caller_channel
),
tmp
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
caller_channel
),
SWITCH_LOG_WARNING
,
"Error inheriting codec. Channel %s has no read codec yet.
\n
"
,
switch_channel_get_name
(
channel
));
}
}
}
static
uint8_t
check_channel_status
(
originate_global_t
*
oglobals
,
originate_status_t
*
originate_status
,
uint32_t
len
)
{
...
...
@@ -671,32 +703,7 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
end:
if
(
pindex
>
-
1
&&
caller_channel
&&
switch_channel_ready
(
caller_channel
)
&&
!
switch_channel_media_ready
(
caller_channel
))
{
const
char
*
var
=
switch_channel_get_variable
(
caller_channel
,
"inherit_codec"
);
if
(
switch_true
(
var
))
{
switch_codec_implementation_t
impl
=
{
0
};
switch_codec_implementation_t
video_impl
=
{
0
};
char
tmp
[
128
]
=
""
;
if
(
switch_core_session_get_read_impl
(
originate_status
[
pindex
].
peer_session
,
&
impl
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_core_session_get_video_read_impl
(
originate_status
[
pindex
].
peer_session
,
&
impl
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%s@%uh@%ui,%s"
,
impl
.
iananame
,
impl
.
samples_per_second
,
impl
.
microseconds_per_packet
/
1000
,
video_impl
.
iananame
);
}
else
{
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%s@%uh@%ui"
,
impl
.
iananame
,
impl
.
samples_per_second
,
impl
.
microseconds_per_packet
/
1000
);
}
switch_channel_set_variable
(
caller_channel
,
"absolute_codec_string"
,
tmp
);
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
caller_channel
),
SWITCH_LOG_DEBUG
,
"Setting codec string on %s to %s
\n
"
,
switch_channel_get_name
(
caller_channel
),
tmp
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
originate_status
[
pindex
].
peer_channel
),
SWITCH_LOG_WARNING
,
"Error inheriting codec. Channel %s has no read codec yet.
\n
"
,
switch_channel_get_name
(
originate_status
[
pindex
].
peer_channel
));
}
}
inherit_codec
(
caller_channel
,
originate_status
[
pindex
].
peer_session
);
}
if
(
send_ringback
)
{
...
...
@@ -1051,7 +1058,7 @@ SWITCH_DECLARE(void) switch_process_import(switch_core_session_t *session, switc
}
static
switch_status_t
setup_ringback
(
originate_global_t
*
oglobals
,
static
switch_status_t
setup_ringback
(
originate_global_t
*
oglobals
,
originate_status_t
*
originate_status
,
int
len
,
const
char
*
ringback_data
,
ringback_t
*
ringback
,
switch_frame_t
*
write_frame
,
switch_codec_t
*
write_codec
)
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
...
...
@@ -1061,6 +1068,10 @@ static switch_status_t setup_ringback(originate_global_t *oglobals,
if
(
!
switch_channel_test_flag
(
caller_channel
,
CF_ANSWERED
)
&&
!
switch_channel_test_flag
(
caller_channel
,
CF_EARLY_MEDIA
))
{
if
(
oglobals
->
bridge_early_media
>
-
1
&&
len
==
1
&&
originate_status
[
0
].
peer_session
&&
switch_channel_media_ready
(
originate_status
[
0
].
peer_channel
))
{
inherit_codec
(
caller_channel
,
originate_status
[
0
].
peer_session
);
}
if
((
status
=
switch_channel_pre_answer
(
caller_channel
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
caller_channel
),
SWITCH_LOG_DEBUG
,
"%s Media Establishment Failed.
\n
"
,
switch_channel_get_name
(
caller_channel
));
...
...
@@ -1073,6 +1084,25 @@ static switch_status_t setup_ringback(originate_global_t *oglobals,
if
(
!
(
strrchr
(
ringback_data
,
'.'
)
||
strstr
(
ringback_data
,
SWITCH_URL_SEPARATOR
)))
{
ringback
->
asis
++
;
}
}
else
if
(
oglobals
->
bridge_early_media
>
-
1
&&
zstr
(
ringback_data
)
&&
len
==
1
&&
originate_status
[
0
].
peer_session
)
{
switch_codec_implementation_t
read_impl
=
{
0
},
write_impl
=
{
0
};
if
(
switch_channel_ready
(
originate_status
[
0
].
peer_channel
)
&&
switch_core_session_get_read_impl
(
originate_status
[
0
].
peer_session
,
&
read_impl
)
==
SWITCH_STATUS_SUCCESS
&&
switch_core_session_get_write_impl
(
oglobals
->
session
,
&
write_impl
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
read_impl
.
impl_id
==
write_impl
.
impl_id
&&
read_impl
.
microseconds_per_packet
==
write_impl
.
microseconds_per_packet
&&
read_impl
.
actual_samples_per_second
==
write_impl
.
actual_samples_per_second
)
{
ringback
->
asis
++
;
write_frame
->
codec
=
switch_core_session_get_write_codec
(
originate_status
[
0
].
peer_session
);
write_frame
->
datalen
=
write_frame
->
codec
->
implementation
->
decoded_bytes_per_packet
;
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
caller_channel
),
SWITCH_LOG_DEBUG
,
"bridge_early_media: passthrough enabled
\n
"
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_CHANNEL_LOG
(
caller_channel
),
SWITCH_LOG_DEBUG
,
"bridge_early_media: codecs don't match (%s@%uh@%di / %s@%uh@%di)
\n
"
,
read_impl
.
iananame
,
read_impl
.
actual_samples_per_second
,
read_impl
.
microseconds_per_packet
/
1000
,
write_impl
.
iananame
,
write_impl
.
actual_samples_per_second
,
write_impl
.
microseconds_per_packet
/
1000
);
}
}
}
if
(
!
ringback
->
asis
)
{
...
...
@@ -1553,6 +1583,7 @@ struct early_state {
switch_mutex_t
*
mutex
;
switch_buffer_t
*
buffer
;
int
ready
;
ringback_t
*
ringback
;
};
typedef
struct
early_state
early_state_t
;
...
...
@@ -1591,37 +1622,51 @@ static void *SWITCH_THREAD_FUNC early_thread_run(switch_thread_t *thread, void *
answered
++
;
}
if
(
!
switch_core_codec_ready
((
&
read_codecs
[
i
])))
{
read_codec
=
switch_core_session_get_read_codec
(
session
);
if
(
!
state
->
ringback
->
asis
)
{
if
(
!
switch_core_codec_ready
((
&
read_codecs
[
i
])))
{
read_codec
=
switch_core_session_get_read_codec
(
session
);
if
(
switch_core_codec_init
(
&
read_codecs
[
i
],
"L16"
,
NULL
,
read_codec
->
implementation
->
actual_samples_per_second
,
read_codec
->
implementation
->
microseconds_per_packet
/
1000
,
1
,
SWITCH_CODEC_FLAG_ENCODE
|
SWITCH_CODEC_FLAG_DECODE
,
NULL
,
switch_core_session_get_pool
(
session
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Codec Error!
\n
"
);
}
else
{
switch_core_session_set_read_codec
(
session
,
&
read_codecs
[
i
]);
if
(
switch_core_codec_init
(
&
read_codecs
[
i
],
"L16"
,
NULL
,
read_codec
->
implementation
->
actual_samples_per_second
,
read_codec
->
implementation
->
microseconds_per_packet
/
1000
,
1
,
SWITCH_CODEC_FLAG_ENCODE
|
SWITCH_CODEC_FLAG_DECODE
,
NULL
,
switch_core_session_get_pool
(
session
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Codec Error!
\n
"
);
}
else
{
switch_core_session_set_read_codec
(
session
,
&
read_codecs
[
i
]);
}
}
}
status
=
switch_core_session_read_frame
(
session
,
&
read_frame
,
SWITCH_IO_FLAG_NONE
,
0
);
if
(
SWITCH_READ_ACCEPTABLE
(
status
))
{
data
=
(
int16_t
*
)
read_frame
->
data
;
if
(
datalen
<
read_frame
->
datalen
)
{
datalen
=
read_frame
->
datalen
;
status
=
switch_core_session_read_frame
(
session
,
&
read_frame
,
SWITCH_IO_FLAG_NONE
,
0
);
if
(
SWITCH_READ_ACCEPTABLE
(
status
))
{
data
=
(
int16_t
*
)
read_frame
->
data
;
if
(
datalen
<
read_frame
->
datalen
)
{
datalen
=
read_frame
->
datalen
;
}
for
(
x
=
0
;
x
<
(
int
)
read_frame
->
datalen
/
2
;
x
++
)
{
sample
=
data
[
x
]
+
mux_data
[
x
];
switch_normalize_to_16bit
(
sample
);
mux_data
[
x
]
=
(
int16_t
)
sample
;
}
}
for
(
x
=
0
;
x
<
(
int
)
read_frame
->
datalen
/
2
;
x
++
)
{
sample
=
data
[
x
]
+
mux_data
[
x
]
;
switch_normalize_to_16bit
(
sample
);
mux_data
[
x
]
=
(
int16_t
)
sample
;
}
else
{
status
=
switch_core_session_read_frame
(
session
,
&
read_frame
,
SWITCH_IO_FLAG_NONE
,
0
)
;
if
(
SWITCH_READ_ACCEPTABLE
(
status
))
{
datalen
=
read_frame
->
datalen
;
}
break
;
}
}
}
if
(
datalen
)
{
if
(
state
->
ringback
->
asis
&&
datalen
)
{
uint16_t
flen
=
datalen
;
switch_mutex_lock
(
state
->
mutex
);
switch_buffer_write
(
state
->
buffer
,
&
flen
,
sizeof
(
uint16_t
));
switch_buffer_write
(
state
->
buffer
,
read_frame
->
data
,
datalen
);
switch_mutex_unlock
(
state
->
mutex
);
}
else
if
(
datalen
)
{
switch_mutex_lock
(
state
->
mutex
);
switch_buffer_write
(
state
->
buffer
,
mux_data
,
datalen
);
switch_mutex_unlock
(
state
->
mutex
);
...
...
@@ -2758,9 +2803,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if
(
oglobals
.
ringback_ok
&&
(
oglobals
.
ring_ready
||
oglobals
.
instant_ringback
||
oglobals
.
sending_ringback
>
1
||
oglobals
.
bridge_early_media
>
-
1
))
{
if
(
oglobals
.
ringback_ok
==
1
)
{
switch_status_t
rst
=
setup_ringback
(
&
oglobals
,
ringback_data
,
&
ringback
,
&
write_frame
,
&
write_codec
);
switch_status_t
rst
;
rst
=
setup_ringback
(
&
oglobals
,
originate_status
,
and_argc
,
ringback_data
,
&
ringback
,
&
write_frame
,
&
write_codec
);
if
(
oglobals
.
bridge_early_media
>
-
1
)
{
switch_threadattr_t
*
thd_attr
=
NULL
;
switch_threadattr_create
(
&
thd_attr
,
switch_core_session_get_pool
(
session
));
...
...
@@ -2768,6 +2814,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
early_state
.
oglobals
=
&
oglobals
;
early_state
.
originate_status
=
originate_status
;
early_state
.
ready
=
1
;
early_state
.
ringback
=
&
ringback
;
switch_mutex_init
(
&
early_state
.
mutex
,
SWITCH_MUTEX_NESTED
,
switch_core_session_get_pool
(
session
));
switch_buffer_create_dynamic
(
&
early_state
.
buffer
,
1024
,
1024
,
0
);
switch_thread_create
(
&
oglobals
.
ethread
,
thd_attr
,
early_thread_run
,
&
early_state
,
switch_core_session_get_pool
(
session
));
...
...
@@ -2794,12 +2841,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
continue
;
}
if
(
oglobals
.
bridge_early_media
>
-
1
)
{
if
(
oglobals
.
bridge_early_media
>
-
1
)
{
write_frame
.
datalen
=
0
;
switch_mutex_lock
(
early_state
.
mutex
);
if
(
switch_buffer_inuse
(
early_state
.
buffer
)
>=
write_frame
.
codec
->
implementation
->
decoded_bytes_per_packet
)
{
write_frame
.
datalen
=
switch_buffer_read
(
early_state
.
buffer
,
write_frame
.
data
,
write_frame
.
codec
->
implementation
->
decoded_bytes_per_packet
);
if
(
ringback
.
asis
)
{
uint16_t
mlen
;
switch_size_t
buflen
=
switch_buffer_inuse
(
early_state
.
buffer
);
if
(
buflen
>
sizeof
(
uint16_t
))
{
switch_buffer_peek
(
early_state
.
buffer
,
&
mlen
,
sizeof
(
uint16_t
));
if
(
buflen
>=
(
mlen
+
sizeof
(
uint16_t
)))
{
switch_buffer_toss
(
early_state
.
buffer
,
sizeof
(
uint16_t
));
write_frame
.
datalen
=
switch_buffer_read
(
early_state
.
buffer
,
write_frame
.
data
,
mlen
);
}
}
}
else
{
if
(
switch_buffer_inuse
(
early_state
.
buffer
)
>=
write_frame
.
codec
->
implementation
->
decoded_bytes_per_packet
)
{
write_frame
.
datalen
=
switch_buffer_read
(
early_state
.
buffer
,
write_frame
.
data
,
write_frame
.
codec
->
implementation
->
decoded_bytes_per_packet
);
}
}
switch_mutex_unlock
(
early_state
.
mutex
);
}
else
if
(
ringback
.
fh
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论