Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
631e689e
提交
631e689e
authored
4月 07, 2007
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge 1
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@4876
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
2bc59bff
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
208 行增加
和
191 行删除
+208
-191
libdingaling.c
libs/libdingaling/src/libdingaling.c
+19
-23
mod_dingaling.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
+97
-80
switch_rtp.c
src/switch_rtp.c
+92
-88
没有找到文件。
libs/libdingaling/src/libdingaling.c
浏览文件 @
631e689e
...
@@ -731,6 +731,8 @@ static int on_presence(void *user_data, ikspak *pak)
...
@@ -731,6 +731,8 @@ static int on_presence(void *user_data, ikspak *pak)
struct
ldl_buffer
*
buffer
;
struct
ldl_buffer
*
buffer
;
ldl_signal_t
dl_signal
=
LDL_SIGNAL_PRESENCE_IN
;
ldl_signal_t
dl_signal
=
LDL_SIGNAL_PRESENCE_IN
;
if
(
type
&&
*
type
)
{
if
(
type
&&
*
type
)
{
if
(
!
strcasecmp
(
type
,
"unavailable"
))
{
if
(
!
strcasecmp
(
type
,
"unavailable"
))
{
dl_signal
=
LDL_SIGNAL_PRESENCE_OUT
;
dl_signal
=
LDL_SIGNAL_PRESENCE_OUT
;
...
@@ -754,6 +756,7 @@ static int on_presence(void *user_data, ikspak *pak)
...
@@ -754,6 +756,7 @@ static int on_presence(void *user_data, ikspak *pak)
*
resource
++
=
'\0'
;
*
resource
++
=
'\0'
;
}
}
if
(
!
apr_hash_get
(
handle
->
sub_hash
,
from
,
APR_HASH_KEY_STRING
))
{
if
(
!
apr_hash_get
(
handle
->
sub_hash
,
from
,
APR_HASH_KEY_STRING
))
{
iks
*
msg
;
iks
*
msg
;
apr_hash_set
(
handle
->
sub_hash
,
apr_pstrdup
(
handle
->
pool
,
from
),
APR_HASH_KEY_STRING
,
&
marker
);
apr_hash_set
(
handle
->
sub_hash
,
apr_pstrdup
(
handle
->
pool
,
from
),
APR_HASH_KEY_STRING
,
&
marker
);
...
@@ -766,6 +769,8 @@ static int on_presence(void *user_data, ikspak *pak)
...
@@ -766,6 +769,8 @@ static int on_presence(void *user_data, ikspak *pak)
apr_cpystrn
(
buffer
->
buf
,
from
,
buffer
->
len
);
apr_cpystrn
(
buffer
->
buf
,
from
,
buffer
->
len
);
fflush
(
stderr
);
fflush
(
stderr
);
buffer
->
hit
=
1
;
buffer
->
hit
=
1
;
}
else
{
printf
(
"DAMMIT Lookup %s
\n
"
,
from
);
}
}
if
(
handle
->
session_callback
)
{
if
(
handle
->
session_callback
)
{
...
@@ -1953,42 +1958,33 @@ char *ldl_handle_probe(ldl_handle_t *handle, char *id, char *from, char *buf, un
...
@@ -1953,42 +1958,33 @@ char *ldl_handle_probe(ldl_handle_t *handle, char *id, char *from, char *buf, un
iks
*
pres
,
*
msg
;
iks
*
pres
,
*
msg
;
char
*
lid
=
NULL
,
*
low_id
=
NULL
;
char
*
lid
=
NULL
,
*
low_id
=
NULL
;
struct
ldl_buffer
buffer
;
struct
ldl_buffer
buffer
;
apr_
time_t
started
;
time_t
started
;
unsigned
int
elapsed
;
unsigned
int
elapsed
;
char
*
notice
=
"Call Me!"
;
char
*
notice
=
"Call Me!"
;
int
again
=
0
;
int
next
=
0
;
buffer
.
buf
=
buf
;
buffer
.
buf
=
buf
;
buffer
.
len
=
len
;
buffer
.
len
=
len
;
buffer
.
hit
=
0
;
buffer
.
hit
=
0
;
pres
=
iks_new
(
"presence"
);
iks_insert_attrib
(
pres
,
"type"
,
"probe"
);
iks_insert_attrib
(
pres
,
"from"
,
from
);
iks_insert_attrib
(
pres
,
"to"
,
id
);
apr_hash_set
(
handle
->
probe_hash
,
id
,
APR_HASH_KEY_STRING
,
&
buffer
);
apr_hash_set
(
handle
->
probe_hash
,
id
,
APR_HASH_KEY_STRING
,
&
buffer
);
msg
=
iks_make_s10n
(
IKS_TYPE_SUBSCRIBE
,
id
,
notice
);
msg
=
iks_make_s10n
(
IKS_TYPE_SUBSCRIBE
,
id
,
notice
);
iks_insert_attrib
(
msg
,
"from"
,
from
);
iks_insert_attrib
(
msg
,
"from"
,
from
);
apr_queue_push
(
handle
->
queue
,
msg
);
apr_queue_push
(
handle
->
queue
,
msg
);
msg
=
iks_make_s10n
(
IKS_TYPE_SUBSCRIBED
,
id
,
notice
);
iks_insert_attrib
(
msg
,
"from"
,
from
);
apr_queue_push
(
handle
->
queue
,
msg
);
apr_queue_push
(
handle
->
queue
,
pres
);
//schedule_packet(handle, next_id(), pres, LDL_RETRY);
started
=
apr_time_now
(
);
started
=
time
(
NULL
);
for
(;;)
{
for
(;;)
{
elapsed
=
(
unsigned
int
)((
apr_time_now
()
-
started
)
/
1000
);
elapsed
=
time
(
NULL
)
-
started
;
if
(
elapsed
>
5000
&&
!
again
)
{
if
(
elapsed
==
next
)
{
msg
=
iks_make_s10n
(
IKS_TYPE_SUBSCRIBE
,
id
,
notice
);
pres
=
iks_new
(
"presence"
);
iks_insert_attrib
(
msg
,
"from"
,
from
);
iks_insert_attrib
(
pres
,
"type"
,
"probe"
);
apr_queue_push
(
handle
->
queue
,
msg
);
iks_insert_attrib
(
pres
,
"from"
,
from
);
again
++
;
iks_insert_attrib
(
pres
,
"to"
,
id
);
apr_queue_push
(
handle
->
queue
,
pres
);
next
+=
5
;
}
}
if
(
elapsed
>
10000
)
{
if
(
elapsed
>
=
17
)
{
break
;
break
;
}
}
if
(
buffer
.
hit
)
{
if
(
buffer
.
hit
)
{
...
...
src/mod/endpoints/mod_dingaling/mod_dingaling.c
浏览文件 @
631e689e
...
@@ -851,7 +851,6 @@ static int activate_rtp(struct private_object *tech_pvt)
...
@@ -851,7 +851,6 @@ static int activate_rtp(struct private_object *tech_pvt)
tech_pvt
->
local_port
,
tech_pvt
->
remote_ip
,
tech_pvt
->
remote_port
);
tech_pvt
->
local_port
,
tech_pvt
->
remote_ip
,
tech_pvt
->
remote_port
);
flags
=
SWITCH_RTP_FLAG_GOOGLEHACK
|
SWITCH_RTP_FLAG_AUTOADJ
|
SWITCH_RTP_FLAG_RAW_WRITE
|
SWITCH_RTP_FLAG_AUTO_CNG
;
flags
=
SWITCH_RTP_FLAG_GOOGLEHACK
|
SWITCH_RTP_FLAG_AUTOADJ
|
SWITCH_RTP_FLAG_RAW_WRITE
|
SWITCH_RTP_FLAG_AUTO_CNG
;
//flags = SWITCH_RTP_FLAG_AUTOADJ;
if
(
switch_test_flag
(
tech_pvt
->
profile
,
TFLAG_TIMER
))
{
if
(
switch_test_flag
(
tech_pvt
->
profile
,
TFLAG_TIMER
))
{
flags
|=
SWITCH_RTP_FLAG_USE_TIMER
;
flags
|=
SWITCH_RTP_FLAG_USE_TIMER
;
...
@@ -874,7 +873,11 @@ static int activate_rtp(struct private_object *tech_pvt)
...
@@ -874,7 +873,11 @@ static int activate_rtp(struct private_object *tech_pvt)
uint8_t
inb
=
switch_test_flag
(
tech_pvt
,
TFLAG_OUTBOUND
)
?
0
:
1
;
uint8_t
inb
=
switch_test_flag
(
tech_pvt
,
TFLAG_OUTBOUND
)
?
0
:
1
;
switch_rtp_activate_ice
(
tech_pvt
->
rtp_session
,
tech_pvt
->
remote_user
,
tech_pvt
->
local_user
);
switch_rtp_activate_ice
(
tech_pvt
->
rtp_session
,
tech_pvt
->
remote_user
,
tech_pvt
->
local_user
);
if
((
vad_in
&&
inb
)
||
(
vad_out
&&
!
inb
))
{
if
((
vad_in
&&
inb
)
||
(
vad_out
&&
!
inb
))
{
switch_rtp_enable_vad
(
tech_pvt
->
rtp_session
,
tech_pvt
->
session
,
&
tech_pvt
->
read_codec
,
SWITCH_VAD_FLAG_TALKING
);
if
(
switch_rtp_enable_vad
(
tech_pvt
->
rtp_session
,
tech_pvt
->
session
,
&
tech_pvt
->
read_codec
,
SWITCH_VAD_FLAG_TALKING
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"VAD ERROR %s
\n
"
,
err
);
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER
);
return
0
;
}
switch_set_flag_locked
(
tech_pvt
,
TFLAG_VAD
);
switch_set_flag_locked
(
tech_pvt
,
TFLAG_VAD
);
}
}
switch_rtp_set_cng_pt
(
tech_pvt
->
rtp_session
,
13
);
switch_rtp_set_cng_pt
(
tech_pvt
->
rtp_session
,
13
);
...
@@ -1065,7 +1068,8 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
...
@@ -1065,7 +1068,8 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
while
(
!
(
switch_test_flag
(
tech_pvt
,
TFLAG_CODEC_READY
)
&&
while
(
!
(
switch_test_flag
(
tech_pvt
,
TFLAG_CODEC_READY
)
&&
switch_test_flag
(
tech_pvt
,
TFLAG_RTP_READY
)
&&
switch_test_flag
(
tech_pvt
,
TFLAG_RTP_READY
)
&&
switch_test_flag
(
tech_pvt
,
TFLAG_ANSWER
)
&&
switch_test_flag
(
tech_pvt
,
TFLAG_TRANSPORT_ACCEPT
)
switch_test_flag
(
tech_pvt
,
TFLAG_ANSWER
)
&&
switch_test_flag
(
tech_pvt
,
TFLAG_TRANSPORT_ACCEPT
)
&&
tech_pvt
->
remote_ip
&&
tech_pvt
->
remote_port
&&
switch_test_flag
(
tech_pvt
,
TFLAG_TRANSPORT
)))
{
&&
switch_test_flag
(
tech_pvt
,
TFLAG_TRANSPORT
)))
{
now
=
switch_time_now
();
now
=
switch_time_now
();
elapsed
=
(
unsigned
int
)
((
now
-
started
)
/
1000
);
elapsed
=
(
unsigned
int
)
((
now
-
started
)
/
1000
);
...
@@ -1329,89 +1333,101 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *d
...
@@ -1329,89 +1333,101 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *d
static
switch_status_t
channel_read_frame
(
switch_core_session_t
*
session
,
switch_frame_t
**
frame
,
int
timeout
,
switch_io_flag_t
flags
,
int
stream_id
)
static
switch_status_t
channel_read_frame
(
switch_core_session_t
*
session
,
switch_frame_t
**
frame
,
int
timeout
,
switch_io_flag_t
flags
,
int
stream_id
)
{
{
struct
private_object
*
tech_pvt
=
NULL
;
struct
private_object
*
tech_pvt
=
NULL
;
uint32_t
bytes
=
0
;
switch_size_t
samples
=
0
,
frames
=
0
,
ms
=
0
;
switch_channel_t
*
channel
=
NULL
;
switch_channel_t
*
channel
=
NULL
;
switch_payload_t
payload
=
0
;
int
payload
=
0
;
switch_status_t
status
;
channel
=
switch_core_session_get_channel
(
session
);
channel
=
switch_core_session_get_channel
(
session
);
assert
(
channel
!=
NULL
);
assert
(
channel
!=
NULL
);
tech_pvt
=
switch_core_session_get_private
(
session
);
tech_pvt
=
(
struct
private_object
*
)
switch_core_session_get_private
(
session
);
assert
(
tech_pvt
!=
NULL
);
assert
(
tech_pvt
!=
NULL
);
while
(
!
(
tech_pvt
->
read_codec
.
implementation
&&
switch_rtp_ready
(
tech_pvt
->
rtp_session
)))
{
if
(
!
tech_pvt
->
rtp_session
)
{
if
(
switch_channel_ready
(
channel
))
{
return
SWITCH_STATUS_FALSE
;
switch_yield
(
10000
);
}
else
{
return
SWITCH_STATUS_GENERR
;
}
}
if
(
switch_test_flag
(
tech_pvt
,
TFLAG_BYE
))
{
//terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
return
SWITCH_STATUS_FALSE
;
}
}
tech_pvt
->
read_frame
.
datalen
=
0
;
tech_pvt
->
read_frame
.
datalen
=
0
;
switch_set_flag_locked
(
tech_pvt
,
TFLAG_READING
);
switch_set_flag_locked
(
tech_pvt
,
TFLAG_READING
);
bytes
=
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
;
#if 0
samples
=
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
;
if (tech_pvt->last_read) {
ms
=
tech_pvt
->
read_codec
.
implementation
->
microseconds_per_frame
;
elapsed = (unsigned int) ((switch_time_now() - tech_pvt->last_read) / 1000);
if (elapsed > 60000) {
return SWITCH_STATUS_TIMEOUT;
}
}
#endif
if
(
switch_test_flag
(
tech_pvt
,
TFLAG_IO
))
{
switch_status_t
status
;
assert
(
tech_pvt
->
rtp_session
!=
NULL
);
tech_pvt
->
read_frame
.
datalen
=
0
;
tech_pvt
->
read_frame
.
datalen
=
0
;
while
(
!
switch_test_flag
(
tech_pvt
,
TFLAG_BYE
)
&&
switch_test_flag
(
tech_pvt
,
TFLAG_IO
)
while
(
switch_test_flag
(
tech_pvt
,
TFLAG_IO
)
&&
tech_pvt
->
read_frame
.
datalen
==
0
)
{
&&
tech_pvt
->
read_frame
.
datalen
==
0
)
{
tech_pvt
->
read_frame
.
flags
=
SFF_NONE
;
tech_pvt
->
read_frame
.
flags
=
0
;
status
=
switch_rtp_zerocopy_read_frame
(
tech_pvt
->
rtp_session
,
&
tech_pvt
->
read_frame
);
status
=
switch_rtp_zerocopy_read_frame
(
tech_pvt
->
rtp_session
,
&
tech_pvt
->
read_frame
);
if
(
status
!=
SWITCH_STATUS_SUCCESS
&&
status
!=
SWITCH_STATUS_BREAK
)
{
if
(
status
!=
SWITCH_STATUS_SUCCESS
&&
status
!=
SWITCH_STATUS_BREAK
)
{
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
payload
=
tech_pvt
->
read_frame
.
payload
;
payload
=
tech_pvt
->
read_frame
.
payload
;
#if 0
elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
if (timeout > -1) {
if (elapsed >= (unsigned int) timeout) {
return SWITCH_STATUS_BREAK;
}
}
elapsed = (unsigned int) ((switch_time_now() - last_act) / 1000);
if (elapsed >= hard_timeout) {
return SWITCH_STATUS_BREAK;
}
#endif
if
(
switch_rtp_has_dtmf
(
tech_pvt
->
rtp_session
))
{
if
(
switch_rtp_has_dtmf
(
tech_pvt
->
rtp_session
))
{
char
dtmf
[
128
];
char
dtmf
[
128
];
switch_rtp_dequeue_dtmf
(
tech_pvt
->
rtp_session
,
dtmf
,
sizeof
(
dtmf
));
switch_rtp_dequeue_dtmf
(
tech_pvt
->
rtp_session
,
dtmf
,
sizeof
(
dtmf
));
switch_channel_queue_dtmf
(
channel
,
dtmf
);
switch_channel_queue_dtmf
(
channel
,
dtmf
);
switch_set_flag_locked
(
tech_pvt
,
TFLAG_DTMF
);
}
}
if
(
switch_test_flag
(
tech_pvt
,
TFLAG_DTMF
))
{
switch_clear_flag_locked
(
tech_pvt
,
TFLAG_DTMF
);
return
SWITCH_STATUS_BREAK
;
}
if
(
switch_test_flag
(
&
tech_pvt
->
read_frame
,
SFF_CNG
))
{
tech_pvt
->
read_frame
.
datalen
=
tech_pvt
->
last_read
?
tech_pvt
->
last_read
:
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
;
}
if
(
tech_pvt
->
read_frame
.
datalen
>
0
)
{
if
(
tech_pvt
->
read_frame
.
datalen
>
0
)
{
size_t
bytes
=
0
;
int
frames
=
1
;
if
(
!
switch_test_flag
((
&
tech_pvt
->
read_frame
),
SFF_CNG
))
{
if
(
!
switch_test_flag
((
&
tech_pvt
->
read_frame
),
SFF_CNG
))
{
if
(
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
&&
bytes
)
{
if
((
bytes
=
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
))
{
bytes
=
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
;
frames
=
(
tech_pvt
->
read_frame
.
datalen
/
bytes
);
frames
=
(
tech_pvt
->
read_frame
.
datalen
/
bytes
);
}
else
{
frames
=
1
;
}
}
samples
=
frames
*
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
;
tech_pvt
->
read_frame
.
samples
=
(
int
)
(
frames
*
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
);
ms
=
frames
*
tech_pvt
->
read_codec
.
implementation
->
microseconds_per_frame
;
tech_pvt
->
timestamp_recv
+=
(
int32_t
)
samples
;
tech_pvt
->
read_frame
.
samples
=
(
int
)
samples
;
tech_pvt
->
last_read
=
tech_pvt
->
read_frame
.
datalen
;
}
}
break
;
break
;
}
}
switch_yield
(
1000
);
}
}
}
switch_clear_flag_locked
(
tech_pvt
,
TFLAG_READING
);
switch_clear_flag_locked
(
tech_pvt
,
TFLAG_READING
);
if
(
tech_pvt
->
read_frame
.
datalen
==
0
)
{
*
frame
=
NULL
;
return
SWITCH_STATUS_GENERR
;
}
*
frame
=
&
tech_pvt
->
read_frame
;
*
frame
=
&
tech_pvt
->
read_frame
;
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
@@ -1422,45 +1438,46 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
...
@@ -1422,45 +1438,46 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
int
bytes
=
0
,
samples
=
0
,
frames
=
0
;
int
bytes
=
0
,
samples
=
0
,
frames
=
0
;
channel
=
switch_core_session_get_channel
(
session
);
channel
=
switch_core_session_get_channel
(
session
);
assert
(
channel
!=
NULL
);
assert
(
channel
!=
NULL
);
tech_pvt
=
switch_core_session_get_private
(
session
);
tech_pvt
=
(
struct
private_object
*
)
switch_core_session_get_private
(
session
);
assert
(
tech_pvt
!=
NULL
);
assert
(
tech_pvt
!=
NULL
);
if
(
!
tech_pvt
->
rtp_session
)
{
while
(
!
(
tech_pvt
->
read_codec
.
implementation
&&
switch_rtp_ready
(
tech_pvt
->
rtp_session
)))
{
return
SWITCH_STATUS_FALSE
;
if
(
switch_channel_ready
(
channel
))
{
switch_yield
(
10000
);
}
else
{
return
SWITCH_STATUS_GENERR
;
}
}
if
(
!
switch_test_flag
(
tech_pvt
,
TFLAG_RTP_READY
))
{
return
SWITCH_STATUS_SUCCESS
;
}
}
if
(
!
switch_test_flag
(
tech_pvt
,
TFLAG_IO
))
{
if
(
switch_test_flag
(
tech_pvt
,
TFLAG_BYE
))
{
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_FALSE
;
}
}
switch_set_flag_locked
(
tech_pvt
,
TFLAG_WRITING
);
switch_set_flag_locked
(
tech_pvt
,
TFLAG_WRITING
);
if
(
!
switch_test_flag
(
frame
,
SFF_CNG
))
{
if
(
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
)
{
if
(
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
)
{
bytes
=
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
;
bytes
=
tech_pvt
->
read_codec
.
implementation
->
encoded_bytes_per_frame
;
frames
=
((
int
)
frame
->
datalen
/
bytes
);
frames
=
((
int
)
frame
->
datalen
/
bytes
);
}
else
{
}
else
frames
=
1
;
frames
=
1
;
}
samples
=
frames
*
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
;
samples
=
frames
*
tech_pvt
->
read_codec
.
implementation
->
samples_per_frame
;
tech_pvt
->
timestamp_send
+=
samples
;
if
(
switch_rtp_write_frame
(
tech_pvt
->
rtp_session
,
frame
,
0
)
<
0
)
{
terminate_session
(
&
session
,
__LINE__
,
SWITCH_CAUSE_NORMAL_CLEARING
);
return
SWITCH_STATUS_FALSE
;
}
}
#if 0
printf("%s %s->%s send %d bytes %d samples in %d frames ts=%d\n",
switch_channel_get_name(channel),
tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, tech_pvt->timestamp_send);
#endif
tech_pvt
->
timestamp_send
+=
samples
;
//switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send);
switch_rtp_write_frame
(
tech_pvt
->
rtp_session
,
frame
,
0
);
switch_clear_flag_locked
(
tech_pvt
,
TFLAG_WRITING
);
switch_clear_flag_locked
(
tech_pvt
,
TFLAG_WRITING
);
return
status
;
return
status
;
}
}
...
...
src/switch_rtp.c
浏览文件 @
631e689e
...
@@ -772,7 +772,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
...
@@ -772,7 +772,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
return
-
1
;
return
-
1
;
}
}
if
(
!
bytes
&&
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_BREAK
))
{
if
(
!
bytes
&&
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_BREAK
))
{
switch_clear_flag_locked
(
rtp_session
,
SWITCH_RTP_FLAG_BREAK
);
switch_clear_flag_locked
(
rtp_session
,
SWITCH_RTP_FLAG_BREAK
);
...
@@ -787,22 +786,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
...
@@ -787,22 +786,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if
(
bytes
<
0
)
{
if
(
bytes
<
0
)
{
return
(
int
)
bytes
;
return
(
int
)
bytes
;
}
else
if
(
bytes
>
0
&&
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_SECURE
))
{
int
sbytes
=
(
int
)
bytes
;
err_status_t
stat
;
stat
=
srtp_unprotect
(
rtp_session
->
recv_ctx
,
&
rtp_session
->
recv_msg
.
header
,
&
sbytes
);
if
(
stat
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"error: srtp unprotection failed with code %d%s
\n
"
,
stat
,
stat
==
err_status_replay_fail
?
" (replay check failed)"
:
stat
==
err_status_auth_fail
?
" (auth check failed)"
:
""
);
return
-
1
;
}
bytes
=
sbytes
;
}
if
(
bytes
&&
rtp_session
->
cng_pt
&&
rtp_session
->
recv_msg
.
header
.
pt
==
rtp_session
->
cng_pt
)
{
continue
;
}
}
if
(
rtp_session
->
timer
.
interval
)
{
if
(
rtp_session
->
timer
.
interval
)
{
...
@@ -818,24 +801,61 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
...
@@ -818,24 +801,61 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
}
}
}
}
if
(
check
)
{
if
(
check
)
{
do_2833
(
rtp_session
);
do_2833
(
rtp_session
);
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_USE_TIMER
))
{
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_USE_TIMER
))
{
uint8_t
*
data
=
(
uint8_t
*
)
rtp_session
->
recv_msg
.
body
;
/* We're late! We're Late! */
/* We're late! We're Late! */
if
(
!
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_NOBLOCK
)
&&
status
==
SWITCH_STATUS_BREAK
)
{
if
(
!
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_NOBLOCK
)
&&
status
==
SWITCH_STATUS_BREAK
)
{
switch_yield
(
1000
);
switch_yield
(
1000
);
continue
;
continue
;
}
}
memset
(
&
rtp_session
->
recv_msg
,
0
,
SWITCH_RTP_CNG_PAYLOAD
);
rtp_session
->
recv_msg
.
header
.
pt
=
SWITCH_RTP_CNG_PAYLOAD
;
memset
(
data
,
0
,
2
);
data
[
0
]
=
65
;
rtp_session
->
recv_msg
.
header
.
pt
=
(
uint32_t
)
rtp_session
->
cng_pt
?
rtp_session
->
cng_pt
:
SWITCH_RTP_CNG_PAYLOAD
;
*
flags
|=
SFF_CNG
;
*
flags
|=
SFF_CNG
;
/* Return a CNG frame */
*
payload_type
=
rtp_session
->
recv_msg
.
header
.
pt
;
*
payload_type
=
SWITCH_RTP_CNG_PAYLOAD
;
return
2
+
rtp_header_len
;
return
SWITCH_RTP_CNG_PAYLOAD
+
rtp_header_len
;
}
}
if
(
bytes
&&
rtp_session
->
recv_msg
.
header
.
version
!=
2
)
{
uint8_t
*
data
=
(
uint8_t
*
)
rtp_session
->
recv_msg
.
body
;
if
(
rtp_session
->
recv_msg
.
header
.
version
==
0
&&
rtp_session
->
ice_user
)
{
handle_ice
(
rtp_session
,
(
void
*
)
&
rtp_session
->
recv_msg
,
bytes
);
}
if
(
rtp_session
->
invalid_handler
)
{
rtp_session
->
invalid_handler
(
rtp_session
,
rtp_session
->
sock
,
(
void
*
)
&
rtp_session
->
recv_msg
,
bytes
,
rtp_session
->
from_addr
);
}
}
memset
(
data
,
0
,
2
);
data
[
0
]
=
65
;
rtp_session
->
recv_msg
.
header
.
pt
=
(
uint32_t
)
rtp_session
->
cng_pt
?
rtp_session
->
cng_pt
:
SWITCH_RTP_CNG_PAYLOAD
;
*
flags
|=
SFF_CNG
;
*
payload_type
=
rtp_session
->
recv_msg
.
header
.
pt
;
return
2
+
rtp_header_len
;
}
if
(
bytes
&&
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_SECURE
))
{
int
sbytes
=
(
int
)
bytes
;
err_status_t
stat
;
stat
=
srtp_unprotect
(
rtp_session
->
recv_ctx
,
&
rtp_session
->
recv_msg
.
header
,
&
sbytes
);
if
(
stat
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"error: srtp unprotection failed with code %d%s
\n
"
,
stat
,
stat
==
err_status_replay_fail
?
" (replay check failed)"
:
stat
==
err_status_auth_fail
?
" (auth check failed)"
:
""
);
return
-
1
;
}
bytes
=
sbytes
;
}
}
if
(
status
==
SWITCH_STATUS_BREAK
||
bytes
==
0
)
{
if
(
status
==
SWITCH_STATUS_BREAK
||
bytes
==
0
)
{
...
@@ -847,9 +867,9 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
...
@@ -847,9 +867,9 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
}
}
if
(
rtp_session
->
recv_msg
.
header
.
version
)
{
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_AUTOADJ
)
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_AUTOADJ
)
&&
switch_sockaddr_get_port
(
rtp_session
->
from_addr
))
{
&&
switch_sockaddr_get_port
(
rtp_session
->
from_addr
))
{
char
*
tx_host
;
char
*
tx_host
;
char
*
old_host
;
char
*
old_host
;
char
bufa
[
30
],
bufb
[
30
];
char
bufa
[
30
],
bufb
[
30
];
...
@@ -870,24 +890,20 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
...
@@ -870,24 +890,20 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
}
}
switch_clear_flag_locked
(
rtp_session
,
SWITCH_RTP_FLAG_AUTOADJ
);
switch_clear_flag_locked
(
rtp_session
,
SWITCH_RTP_FLAG_AUTOADJ
);
}
}
if
(
bytes
&&
rtp_session
->
cng_pt
&&
rtp_session
->
recv_msg
.
header
.
pt
==
rtp_session
->
cng_pt
)
{
continue
;
}
}
if
(
rtp_session
->
recv_msg
.
header
.
version
==
2
)
{
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_GOOGLEHACK
)
&&
rtp_session
->
recv_msg
.
header
.
pt
==
102
)
{
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_GOOGLEHACK
)
&&
rtp_session
->
recv_msg
.
header
.
pt
==
102
)
{
rtp_session
->
recv_msg
.
header
.
pt
=
97
;
rtp_session
->
recv_msg
.
header
.
pt
=
97
;
}
}
rtp_session
->
rseq
=
ntohs
((
uint16_t
)
rtp_session
->
recv_msg
.
header
.
seq
);
rtp_session
->
rseq
=
ntohs
((
uint16_t
)
rtp_session
->
recv_msg
.
header
.
seq
);
rtp_session
->
rpayload
=
(
switch_payload_t
)
rtp_session
->
recv_msg
.
header
.
pt
;
rtp_session
->
rpayload
=
(
switch_payload_t
)
rtp_session
->
recv_msg
.
header
.
pt
;
}
else
{
if
(
rtp_session
->
recv_msg
.
header
.
version
==
0
&&
rtp_session
->
ice_user
)
{
handle_ice
(
rtp_session
,
(
void
*
)
&
rtp_session
->
recv_msg
,
bytes
);
}
if
(
rtp_session
->
invalid_handler
)
{
rtp_session
->
invalid_handler
(
rtp_session
,
rtp_session
->
sock
,
(
void
*
)
&
rtp_session
->
recv_msg
,
bytes
,
rtp_session
->
from_addr
);
}
return
0
;
}
/* RFC2833 ... TBD try harder to honor the duration etc. */
/* RFC2833 ... TBD try harder to honor the duration etc. */
if
(
!
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_PASS_RFC2833
)
if
(
!
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_PASS_RFC2833
)
...
@@ -925,7 +941,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
...
@@ -925,7 +941,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
}
}
continue
;
continue
;
}
}
break
;
break
;
...
@@ -1182,12 +1197,11 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
...
@@ -1182,12 +1197,11 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
}
}
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_VAD
)
&&
if
(
switch_test_flag
(
rtp_session
,
SWITCH_RTP_FLAG_VAD
)
&&
rtp_session
->
recv_msg
.
header
.
pt
==
rtp_session
->
vad_data
.
read_codec
->
implementation
->
ianacode
&&
rtp_session
->
recv_msg
.
header
.
pt
==
rtp_session
->
vad_data
.
read_codec
->
implementation
->
ianacode
)
{
((
datalen
==
rtp_session
->
vad_data
.
read_codec
->
implementation
->
encoded_bytes_per_frame
)
||
(
datalen
>
SWITCH_RTP_CNG_PAYLOAD
&&
rtp_session
->
vad_data
.
read_codec
->
implementation
->
encoded_bytes_per_frame
==
0
)))
{
int16_t
decoded
[
SWITCH_RECOMMENDED_BUFFER_SIZE
/
sizeof
(
int16_t
)]
=
{
0
};
int16_t
decoded
[
SWITCH_RECOMMENDED_BUFFER_SIZE
/
sizeof
(
int16_t
)];
uint32_t
rate
=
0
;
uint32_t
rate
;
uint32_t
flags
=
0
;
uint32_t
flags
;
uint32_t
len
=
sizeof
(
decoded
);
uint32_t
len
=
sizeof
(
decoded
);
time_t
now
=
time
(
NULL
);
time_t
now
=
time
(
NULL
);
send
=
0
;
send
=
0
;
...
@@ -1206,6 +1220,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
...
@@ -1206,6 +1220,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
rtp_session
->
vad_data
.
read_codec
->
implementation
->
samples_per_second
,
rtp_session
->
vad_data
.
read_codec
->
implementation
->
samples_per_second
,
decoded
,
&
len
,
&
rate
,
&
flags
)
==
SWITCH_STATUS_SUCCESS
)
{
decoded
,
&
len
,
&
rate
,
&
flags
)
==
SWITCH_STATUS_SUCCESS
)
{
uint32_t
energy
=
0
;
uint32_t
energy
=
0
;
uint32_t
x
,
y
=
0
,
z
=
len
/
sizeof
(
int16_t
);
uint32_t
x
,
y
=
0
,
z
=
len
/
sizeof
(
int16_t
);
uint32_t
score
=
0
;
uint32_t
score
=
0
;
...
@@ -1274,35 +1289,23 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
...
@@ -1274,35 +1289,23 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
if
(
switch_test_flag
(
&
rtp_session
->
vad_data
,
SWITCH_VAD_FLAG_TALKING
))
{
if
(
switch_test_flag
(
&
rtp_session
->
vad_data
,
SWITCH_VAD_FLAG_TALKING
))
{
send
=
1
;
send
=
1
;
}
else
{
if
(
switch_test_flag
(
&
rtp_session
->
vad_data
,
SWITCH_VAD_FLAG_CNG
)
&&
++
rtp_session
->
vad_data
.
cng_count
>=
rtp_session
->
vad_data
.
cng_freq
)
{
rtp_session
->
send_msg
.
header
.
pt
=
SWITCH_RTP_CNG_PAYLOAD
;
memset
(
rtp_session
->
send_msg
.
body
,
255
,
SWITCH_RTP_CNG_PAYLOAD
);
/* rtp_session->send_msg.header.ts = htonl(rtp_session->vad_data.ts);
* rtp_session->vad_data.ts++;
*/
bytes
=
SWITCH_RTP_CNG_PAYLOAD
;
send
=
1
;
rtp_session
->
vad_data
.
cng_count
=
0
;
}
}
}
}
}
}
else
{
}
else
{
return
SWITCH_STATUS_GENERR
;
return
SWITCH_STATUS_GENERR
;
}
}
}
}
rtp_session
->
last_write_ts
=
ntohl
(
send_msg
->
header
.
ts
);
rtp_session
->
last_write_ssrc
=
ntohl
(
send_msg
->
header
.
ssrc
);
rtp_session
->
last_write_seq
=
rtp_session
->
seq
;
if
(
rtp_session
->
last_write_seq
<=
rtp_session
->
dtmf_data
.
out_digit_seq
)
{
if
(
rtp_session
->
last_write_seq
>
0
&&
rtp_session
->
last_write_seq
<=
rtp_session
->
dtmf_data
.
out_digit_seq
)
{
send
=
0
;
send
=
0
;
}
}
if
(
send
)
{
if
(
send
)
{
rtp_session
->
last_write_ts
=
ntohl
(
send_msg
->
header
.
ts
);
rtp_session
->
last_write_ssrc
=
ntohl
(
send_msg
->
header
.
ssrc
);
rtp_session
->
last_write_seq
=
rtp_session
->
seq
;
if
(
rtp_session
->
timer
.
interval
)
{
if
(
rtp_session
->
timer
.
interval
)
{
switch_core_timer_check
(
&
rtp_session
->
timer
);
switch_core_timer_check
(
&
rtp_session
->
timer
);
rtp_session
->
last_write_samplecount
=
rtp_session
->
timer
.
samplecount
;
rtp_session
->
last_write_samplecount
=
rtp_session
->
timer
.
samplecount
;
...
@@ -1360,7 +1363,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session,
...
@@ -1360,7 +1363,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session,
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Can't load codec?
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Can't load codec?
\n
"
);
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Activate VAD codec %s %dms
\n
"
,
codec
->
implementation
->
iananame
,
codec
->
implementation
->
microseconds_per_frame
/
1000
);
rtp_session
->
vad_data
.
diff_level
=
400
;
rtp_session
->
vad_data
.
diff_level
=
400
;
rtp_session
->
vad_data
.
hangunder
=
15
;
rtp_session
->
vad_data
.
hangunder
=
15
;
rtp_session
->
vad_data
.
hangover
=
40
;
rtp_session
->
vad_data
.
hangover
=
40
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论