Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
87f183b7
提交
87f183b7
authored
10月 25, 2017
作者:
José Luis Millán
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #155. RTCP: rely on LibUV timestamp for time calculations
上级
dc69b20c
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
30 行增加
和
55 行删除
+30
-55
RtpStreamSend.hpp
worker/include/RTC/RtpStreamSend.hpp
+1
-1
Utils.hpp
worker/include/Utils.hpp
+8
-14
RtpStreamSend.cpp
worker/src/RTC/RtpStreamSend.cpp
+20
-39
Transport.cpp
worker/src/RTC/Transport.cpp
+1
-1
没有找到文件。
worker/include/RTC/RtpStreamSend.hpp
浏览文件 @
87f183b7
...
@@ -63,7 +63,7 @@ namespace RTC
...
@@ -63,7 +63,7 @@ namespace RTC
using
Buffer
=
std
::
list
<
BufferItem
>
;
using
Buffer
=
std
::
list
<
BufferItem
>
;
Buffer
buffer
;
Buffer
buffer
;
// Stats.
// Stats.
uint32_
t
rtt
{
0
};
floa
t
rtt
{
0
};
// Others.
// Others.
bool
healthy
{
true
};
bool
healthy
{
true
};
...
...
worker/include/Utils.hpp
浏览文件 @
87f183b7
...
@@ -262,7 +262,7 @@ namespace Utils
...
@@ -262,7 +262,7 @@ namespace Utils
// Seconds from Jan 1, 1900 to Jan 1, 1970.
// Seconds from Jan 1, 1900 to Jan 1, 1970.
static
constexpr
uint32_t
UnixNtpOffset
{
0x83AA7E80
};
static
constexpr
uint32_t
UnixNtpOffset
{
0x83AA7E80
};
// NTP fractional unit.
// NTP fractional unit.
static
constexpr
double
NtpFractionalUnit
{
1LL
<<
32
};
static
constexpr
uint64_t
NtpFractionalUnit
{
1LL
<<
32
};
public
:
public
:
struct
Ntp
struct
Ntp
...
@@ -271,26 +271,20 @@ namespace Utils
...
@@ -271,26 +271,20 @@ namespace Utils
uint32_t
fractions
;
uint32_t
fractions
;
};
};
static
void
CurrentTimeNtp
(
Ntp
&
ntp
);
static
Time
::
Ntp
TimeMs2Ntp
(
uint64_t
ms
);
static
void
UnixTime2Ntp
(
struct
timeval
*
unixTime
,
Ntp
&
ntp
);
static
bool
IsNewerTimestamp
(
uint32_t
timestamp
,
uint32_t
prevTimestamp
);
static
bool
IsNewerTimestamp
(
uint32_t
timestamp
,
uint32_t
prevTimestamp
);
static
uint32_t
LatestTimestamp
(
uint32_t
timestamp1
,
uint32_t
timestamp2
);
static
uint32_t
LatestTimestamp
(
uint32_t
timestamp1
,
uint32_t
timestamp2
);
};
};
inline
void
Time
::
CurrentTimeNtp
(
Ntp
&
ntp
)
inline
Time
::
Ntp
Time
::
TimeMs2Ntp
(
uint64_t
ms
)
{
{
struct
timeval
tv
;
Ntp
ntp
;
gettimeofday
(
&
tv
,
nullptr
);
ntp
.
seconds
=
ms
/
1000
;
UnixTime2Ntp
(
&
tv
,
ntp
);
}
inline
void
Time
::
UnixTime2Ntp
(
struct
timeval
*
unixTime
,
Ntp
&
ntp
)
{
ntp
.
seconds
=
unixTime
->
tv_sec
+
UnixNtpOffset
;
ntp
.
fractions
=
ntp
.
fractions
=
static_cast
<
uint32_t
>
(
static_cast
<
double
>
(
unixTime
->
tv_usec
)
*
NtpFractionalUnit
*
1.0e-6
);
static_cast
<
uint32_t
>
(
static_cast
<
double
>
(
ms
%
1000
)
/
1000
*
Utils
::
Time
::
NtpFractionalUnit
);
return
ntp
;
}
}
inline
bool
Time
::
IsNewerTimestamp
(
uint32_t
timestamp
,
uint32_t
prevTimestamp
)
inline
bool
Time
::
IsNewerTimestamp
(
uint32_t
timestamp
,
uint32_t
prevTimestamp
)
...
...
worker/src/RTC/RtpStreamSend.cpp
浏览文件 @
87f183b7
...
@@ -45,7 +45,7 @@ namespace RTC
...
@@ -45,7 +45,7 @@ namespace RTC
Json
::
Value
json
=
RtpStream
::
GetStats
();
Json
::
Value
json
=
RtpStream
::
GetStats
();
json
[
JsonStringType
]
=
Type
;
json
[
JsonStringType
]
=
Type
;
json
[
JsonStringRtt
]
=
Json
::
UInt
{
this
->
rtt
};
json
[
JsonStringRtt
]
=
Json
::
UInt
{
static_cast
<
uint32_t
>
(
this
->
rtt
)
};
return
json
;
return
json
;
}
}
...
@@ -71,20 +71,27 @@ namespace RTC
...
@@ -71,20 +71,27 @@ namespace RTC
/* Calculate RTT. */
/* Calculate RTT. */
// Get the compact NTP representation of the current timestamp.
// Get the NTP representation of the current timestamp.
Utils
::
Time
::
Ntp
nowNtp
{};
uint64_t
now
=
DepLibUV
::
GetTime
();
Utils
::
Time
::
CurrentTimeNtp
(
nowNtp
);
auto
ntp
=
Utils
::
Time
::
TimeMs2Ntp
(
now
);
uint32_t
nowCompactNtp
=
(
nowNtp
.
seconds
&
0x0000FFFF
)
<<
16
;
nowCompactNtp
|=
(
nowNtp
.
fractions
&
0xFFFF0000
)
>>
16
;
// Get the compact NTP representation of the current timestamp.
uint32_t
compactNtp
=
(
ntp
.
seconds
&
0x0000FFFF
)
<<
16
;
compactNtp
|=
(
ntp
.
fractions
&
0xFFFF0000
)
>>
16
;
uint32_t
lastSr
=
report
->
GetLastSenderReport
();
uint32_t
lastSr
=
report
->
GetLastSenderReport
();
uint32_t
dlsr
=
report
->
GetDelaySinceLastSenderReport
();
uint32_t
dlsr
=
report
->
GetDelaySinceLastSenderReport
();
// RTT in 1/2^16 seconds.
uint32_t
rtt
=
nowCompactNtp
-
dlsr
-
lastSr
;
// RTT in 1/2^16 second fractions.
uint32_t
rtt
=
0
;
if
(
compactNtp
>
dlsr
+
lastSr
)
rtt
=
compactNtp
-
dlsr
-
lastSr
;
else
rtt
=
0
;
// RTT in milliseconds.
// RTT in milliseconds.
this
->
rtt
=
(
(
rtt
>>
16
)
*
1000
)
;
this
->
rtt
=
(
rtt
>>
16
)
*
1000
;
this
->
rtt
+=
(
static_cast
<
float
>
(
rtt
&
0x0000FFFF
)
/
65536
)
*
1000
;
this
->
rtt
+=
(
static_cast
<
float
>
(
rtt
&
0x0000FFFF
)
/
65536
)
*
1000
;
this
->
packetsLost
=
report
->
GetTotalLost
();
this
->
packetsLost
=
report
->
GetTotalLost
();
...
@@ -284,38 +291,12 @@ namespace RTC
...
@@ -284,38 +291,12 @@ namespace RTC
report
->
SetOctetCount
(
this
->
transmissionCounter
.
GetBytes
());
report
->
SetOctetCount
(
this
->
transmissionCounter
.
GetBytes
());
// Calculate RTP timestamp diff between now and last received RTP packet.
// Calculate RTP timestamp diff between now and last received RTP packet.
auto
diffMs
=
static_cast
<
uint32_t
>
(
now
-
this
->
maxPacketMs
);
int32_t
diffMs
=
static_cast
<
int32_t
>
(
now
-
this
->
maxPacketMs
);
uint32_t
diffTs
=
diffMs
*
this
->
params
.
clockRate
/
1000
;
int32_t
diffTs
=
diffMs
*
this
->
params
.
clockRate
/
1000
;
// Get the NTP representation of the current timestamp.
Utils
::
Time
::
Ntp
ntp
{};
auto
ntp
=
Utils
::
Time
::
TimeMs2Ntp
(
now
);
struct
timeval
unixTime
{
};
uint64_t
unixTimeMs
;
gettimeofday
(
&
unixTime
,
nullptr
);
// Convert unix time to millisecods.
unixTimeMs
=
unixTime
.
tv_sec
*
1000
+
unixTime
.
tv_usec
/
1000
;
if
(
now
>=
this
->
maxPacketMs
)
{
unixTimeMs
+=
diffMs
;
report
->
SetRtpTs
(
this
->
maxPacketTs
+
diffTs
);
report
->
SetRtpTs
(
this
->
maxPacketTs
+
diffTs
);
}
else
{
unixTimeMs
-=
diffMs
;
report
->
SetRtpTs
(
this
->
maxPacketTs
-
diffTs
);
}
// Convert milliseconds to unix time.
unixTime
.
tv_sec
=
unixTimeMs
/
1000
;
unixTime
.
tv_usec
=
(
unixTimeMs
%
1000
)
*
1000
;
// Convert unix time to NTP.
Utils
::
Time
::
UnixTime2Ntp
(
&
unixTime
,
ntp
);
report
->
SetNtpSec
(
ntp
.
seconds
);
report
->
SetNtpSec
(
ntp
.
seconds
);
report
->
SetNtpFrac
(
ntp
.
fractions
);
report
->
SetNtpFrac
(
ntp
.
fractions
);
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
87f183b7
...
@@ -578,7 +578,7 @@ namespace RTC
...
@@ -578,7 +578,7 @@ namespace RTC
if
(
timer
==
this
->
rtcpTimer
)
if
(
timer
==
this
->
rtcpTimer
)
{
{
uint64_t
interval
=
RTC
::
RTCP
::
MaxVideoIntervalMs
;
uint64_t
interval
=
RTC
::
RTCP
::
MaxVideoIntervalMs
;
uint
32
_t
now
=
DepLibUV
::
GetTime
();
uint
64
_t
now
=
DepLibUV
::
GetTime
();
SendRtcp
(
now
);
SendRtcp
(
now
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论