Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
0b0ade4c
提交
0b0ade4c
authored
2月 15, 2017
作者:
José Luis Millán
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rtp: RtpDataCounter and RateCalculator
上级
d3593be8
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
192 行增加
和
0 行删除
+192
-0
RtpDataCounter.h
worker/include/RTC/RtpDataCounter.h
+102
-0
mediasoup-worker.gyp
worker/mediasoup-worker.gyp
+3
-0
RtpDataCounter.cpp
worker/src/RTC/RtpDataCounter.cpp
+87
-0
没有找到文件。
worker/include/RTC/RtpDataCounter.h
0 → 100644
浏览文件 @
0b0ade4c
#ifndef MS_RTC_RTP_DATA_COUNTER_H
#define MS_RTC_RTP_DATA_COUNTER_H
#include "common.h"
#include "DepLibUV.h"
#include "RTC/RtpPacket.h"
namespace
RTC
{
// It is considered that the time source increases monotonically.
// ie: the current timestamp can never be minor than a timestamp in the past.
class
RateCalculator
{
public
:
static
constexpr
float
kBpsScale
=
8000
.
0
f
;
static
constexpr
float
kbpsScale
=
1000
.
0
f
;
static
constexpr
size_t
defaultWindowSize
=
1000
;
public
:
RateCalculator
(
size_t
windowSize
=
defaultWindowSize
,
float
scale
=
kBpsScale
);
void
Update
(
size_t
count
,
uint64_t
now
);
uint32_t
GetRate
(
uint64_t
now
);
private
:
void
RemoveOldData
(
uint64_t
now
);
void
Reset
(
uint64_t
oldestTime
);
private
:
struct
BufferItem
{
size_t
count
=
0
;
};
private
:
std
::
unique_ptr
<
BufferItem
[]
>
buffer
;
// Time (in milliseconds) for oldest item in the time window.
uint64_t
oldestTime
=
0
;
// Index for the oldest item in the time window.
uint32_t
oldestIndex
=
0
;
// Total count in the time window.
size_t
totalCount
=
0
;
// Window Size (in milliseconds).
size_t
windowSize
=
defaultWindowSize
;
// Scale in which the rate is represented.
const
float
scale
=
kBpsScale
;
};
class
RtpDataCounter
{
public
:
void
Update
(
RTC
::
RtpPacket
*
packet
);
uint32_t
GetRate
(
uint64_t
now
);
size_t
GetPacketCount
();
size_t
GetBytes
();
private
:
RateCalculator
rate
;
size_t
packets
=
0
;
size_t
bytes
=
0
;
};
/* Inline instance methods. */
inline
RateCalculator
::
RateCalculator
(
size_t
windowSize
,
float
scale
)
:
windowSize
(
windowSize
),
scale
(
scale
)
{
uint64_t
now
=
DepLibUV
::
GetTime
();
this
->
Reset
(
now
-
windowSize
);
}
inline
void
RateCalculator
::
Reset
(
uint64_t
oldestTime
)
{
this
->
buffer
.
reset
(
new
BufferItem
[
windowSize
]);
this
->
totalCount
=
0
;
this
->
oldestIndex
=
0
;
this
->
oldestTime
=
oldestTime
;
}
inline
size_t
RtpDataCounter
::
GetPacketCount
()
{
return
this
->
packets
;
}
inline
uint32_t
RtpDataCounter
::
GetRate
(
uint64_t
now
)
{
return
this
->
rate
.
GetRate
(
now
);
}
inline
size_t
RtpDataCounter
::
GetBytes
()
{
return
this
->
bytes
;
}
}
#endif
worker/mediasoup-worker.gyp
浏览文件 @
0b0ade4c
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
'src/RTC/RtpStream.cpp',
'src/RTC/RtpStream.cpp',
'src/RTC/RtpStreamRecv.cpp',
'src/RTC/RtpStreamRecv.cpp',
'src/RTC/RtpStreamSend.cpp',
'src/RTC/RtpStreamSend.cpp',
'src/RTC/RtpDataCounter.cpp',
'src/RTC/SrtpSession.cpp',
'src/RTC/SrtpSession.cpp',
'src/RTC/StunMessage.cpp',
'src/RTC/StunMessage.cpp',
'src/RTC/TcpConnection.cpp',
'src/RTC/TcpConnection.cpp',
...
@@ -114,6 +115,7 @@
...
@@ -114,6 +115,7 @@
'include/RTC/RtpStream.h',
'include/RTC/RtpStream.h',
'include/RTC/RtpStreamRecv.h',
'include/RTC/RtpStreamRecv.h',
'include/RTC/RtpStreamSend.h',
'include/RTC/RtpStreamSend.h',
'include/RTC/RtpDataCounter.h',
'include/RTC/SrtpSession.h',
'include/RTC/SrtpSession.h',
'include/RTC/StunMessage.h',
'include/RTC/StunMessage.h',
'include/RTC/TcpConnection.h',
'include/RTC/TcpConnection.h',
...
@@ -238,6 +240,7 @@
...
@@ -238,6 +240,7 @@
'test/test-nack.cpp',
'test/test-nack.cpp',
'test/test-rtp.cpp',
'test/test-rtp.cpp',
'test/test-rtcp.cpp',
'test/test-rtcp.cpp',
'test/test-bitrate.cpp',
# C++ include files
# C++ include files
'test/catch.hpp',
'test/catch.hpp',
'test/helpers.h'
'test/helpers.h'
...
...
worker/src/RTC/RtpDataCounter.cpp
0 → 100644
浏览文件 @
0b0ade4c
#define MS_CLASS "RTC::RtpDataCounter"
// #define MS_LOG_DEV
#include "RTC/RtpDataCounter.h"
#include "Logger.h"
namespace
RTC
{
void
RateCalculator
::
Update
(
size_t
size
,
uint64_t
now
)
{
MS_TRACE
();
// Ignore too old data. Should never happen.
if
(
now
<
this
->
oldestTime
)
return
;
this
->
RemoveOldData
(
now
);
// Set data in the index before the oldest index.
uint32_t
offset
=
this
->
windowSize
-
1
;
uint32_t
index
=
this
->
oldestIndex
+
offset
;
if
(
index
>=
this
->
windowSize
)
index
-=
this
->
windowSize
;
this
->
buffer
[
index
].
count
+=
size
;
this
->
totalCount
+=
size
;
}
uint32_t
RateCalculator
::
GetRate
(
uint64_t
now
)
{
MS_TRACE
();
this
->
RemoveOldData
(
now
);
int64_t
nominalWindowSize
=
now
-
this
->
oldestTime
;
float
scale
=
this
->
scale
/
nominalWindowSize
;
return
static_cast
<
uint32_t
>
(
this
->
totalCount
*
scale
+
0.5
f
);
}
void
RateCalculator
::
RemoveOldData
(
uint64_t
now
)
{
MS_TRACE
();
uint64_t
newOldestTime
=
now
-
this
->
windowSize
;
// Should never happen.
if
(
newOldestTime
<
this
->
oldestTime
)
{
return
;
}
// We are in the same time unit (ms) as the last entry.
if
(
newOldestTime
==
this
->
oldestTime
)
{
return
;
}
// A whole window size time has elapsed since last entry. Reset the buffer.
if
(
newOldestTime
>
this
->
oldestTime
+
this
->
windowSize
)
{
this
->
Reset
(
newOldestTime
);
return
;
}
while
(
this
->
oldestTime
<
newOldestTime
)
{
const
BufferItem
&
oldestItem
=
buffer
[
this
->
oldestIndex
];
this
->
totalCount
-=
oldestItem
.
count
;
this
->
buffer
[
this
->
oldestIndex
]
=
BufferItem
();
if
(
++
this
->
oldestIndex
>=
this
->
windowSize
)
this
->
oldestIndex
=
0
;
++
this
->
oldestTime
;
}
this
->
oldestTime
=
newOldestTime
;
}
void
RtpDataCounter
::
Update
(
RTC
::
RtpPacket
*
packet
)
{
uint64_t
now
=
DepLibUV
::
GetTime
();
this
->
packets
++
;
this
->
bytes
+=
packet
->
GetSize
();
this
->
rate
.
Update
(
packet
->
GetSize
(),
now
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论