Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
6c951c8c
Commit
6c951c8c
authored
Apr 26, 2021
by
xia-chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善rtcp padding相关逻辑
parent
2d8ef45e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
7 行删除
+44
-7
src/Rtcp/Rtcp.cpp
+38
-6
src/Rtcp/Rtcp.h
+6
-1
没有找到文件。
src/Rtcp/Rtcp.cpp
查看文件 @
6c951c8c
...
...
@@ -68,12 +68,26 @@ static void setupHeader(RtcpHeader *rtcp, RtcpType type, size_t report_count, si
rtcp
->
setSize
(
total_bytes
);
}
static
void
setupPadding
(
RtcpHeader
*
rtcp
,
size_t
padding_size
)
{
if
(
padding_size
)
{
rtcp
->
padding
=
1
;
((
uint8_t
*
)
rtcp
)[
rtcp
->
getSize
()
-
1
]
=
padding_size
&
0xFF
;
}
else
{
rtcp
->
padding
=
0
;
}
}
/////////////////////////////////////////////////////////////////////////////
string
RtcpHeader
::
dumpHeader
()
const
{
_StrPrinter
printer
;
printer
<<
"version:"
<<
version
<<
"
\r\n
"
;
if
(
padding
)
{
printer
<<
"padding:"
<<
padding
<<
" "
<<
getPaddingSize
()
<<
"
\r\n
"
;
}
else
{
printer
<<
"padding:"
<<
padding
<<
"
\r\n
"
;
}
switch
((
RtcpType
)
pt
)
{
case
RtcpType
:
:
RTCP_RTPFB
:
{
printer
<<
"report_count:"
<<
rtpfbTypeToStr
((
RTPFBType
)
report_count
)
<<
"
\r\n
"
;
...
...
@@ -132,6 +146,13 @@ size_t RtcpHeader::getSize() const {
return
(
1
+
ntohs
(
length
))
<<
2
;
}
size_t
RtcpHeader
::
getPaddingSize
()
const
{
if
(
!
padding
)
{
return
0
;
}
return
((
uint8_t
*
)
this
)[
getSize
()
-
1
];
}
void
RtcpHeader
::
setSize
(
size_t
size
)
{
//不包含rtcp头的长度
length
=
htons
((
uint16_t
)((
size
>>
2
)
-
1
));
...
...
@@ -226,9 +247,11 @@ Buffer::Ptr RtcpHeader::toBuffer(std::shared_ptr<RtcpHeader> rtcp) {
/////////////////////////////////////////////////////////////////////////////
std
::
shared_ptr
<
RtcpSR
>
RtcpSR
::
create
(
size_t
item_count
)
{
auto
bytes
=
alignSize
(
sizeof
(
RtcpSR
)
-
sizeof
(
ReportItem
)
+
item_count
*
sizeof
(
ReportItem
));
auto
real_size
=
sizeof
(
RtcpSR
)
-
sizeof
(
ReportItem
)
+
item_count
*
sizeof
(
ReportItem
);
auto
bytes
=
alignSize
(
real_size
);
auto
ptr
=
(
RtcpSR
*
)
new
char
[
bytes
];
setupHeader
(
ptr
,
RtcpType
::
RTCP_SR
,
item_count
,
bytes
);
setupPadding
(
ptr
,
bytes
-
real_size
);
return
std
::
shared_ptr
<
RtcpSR
>
(
ptr
,
[](
RtcpSR
*
ptr
)
{
delete
[]
(
char
*
)
ptr
;
});
...
...
@@ -336,9 +359,11 @@ void ReportItem::net2Host() {
/////////////////////////////////////////////////////////////////////////////
std
::
shared_ptr
<
RtcpRR
>
RtcpRR
::
create
(
size_t
item_count
)
{
auto
bytes
=
alignSize
(
sizeof
(
RtcpRR
)
-
sizeof
(
ReportItem
)
+
item_count
*
sizeof
(
ReportItem
));
auto
real_size
=
sizeof
(
RtcpRR
)
-
sizeof
(
ReportItem
)
+
item_count
*
sizeof
(
ReportItem
);
auto
bytes
=
alignSize
(
real_size
);
auto
ptr
=
(
RtcpRR
*
)
new
char
[
bytes
];
setupHeader
(
ptr
,
RtcpType
::
RTCP_RR
,
item_count
,
bytes
);
setupPadding
(
ptr
,
bytes
-
real_size
);
return
std
::
shared_ptr
<
RtcpRR
>
(
ptr
,
[](
RtcpRR
*
ptr
)
{
delete
[]
(
char
*
)
ptr
;
});
...
...
@@ -413,7 +438,8 @@ std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text)
//统计所有SdesItem对象占用的空间
item_total_size
+=
alignSize
(
SdesItem
::
minSize
()
+
(
0xFF
&
text
.
size
()));
}
auto
bytes
=
alignSize
(
sizeof
(
RtcpSdes
)
-
sizeof
(
SdesItem
)
+
item_total_size
);
auto
real_size
=
sizeof
(
RtcpSdes
)
-
sizeof
(
SdesItem
)
+
item_total_size
;
auto
bytes
=
alignSize
(
real_size
);
auto
ptr
=
(
RtcpSdes
*
)
new
char
[
bytes
];
auto
item_ptr
=
&
ptr
->
items
;
for
(
auto
&
text
:
item_text
)
{
...
...
@@ -424,6 +450,7 @@ std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text)
}
setupHeader
(
ptr
,
RtcpType
::
RTCP_SDES
,
item_text
.
size
(),
bytes
);
setupPadding
(
ptr
,
bytes
-
real_size
);
return
std
::
shared_ptr
<
RtcpSdes
>
(
ptr
,
[](
RtcpSdes
*
ptr
)
{
delete
[]
(
char
*
)
ptr
;
});
...
...
@@ -470,12 +497,14 @@ std::shared_ptr<RtcpFB> RtcpFB::create_l(RtcpType type, int fmt, const void *fci
if
(
!
fci
)
{
fci_len
=
0
;
}
auto
bytes
=
alignSize
(
sizeof
(
RtcpFB
)
+
fci_len
);
auto
real_size
=
sizeof
(
RtcpFB
)
+
fci_len
;
auto
bytes
=
alignSize
(
real_size
);
auto
ptr
=
(
RtcpRR
*
)
new
char
[
bytes
];
if
(
fci
&&
fci_len
)
{
memcpy
(
ptr
+
sizeof
(
RtcpFB
),
fci
,
fci_len
);
}
setupHeader
(
ptr
,
type
,
fmt
,
bytes
);
setupPadding
(
ptr
,
bytes
-
real_size
);
return
std
::
shared_ptr
<
RtcpFB
>
((
RtcpFB
*
)
ptr
,
[](
RtcpFB
*
ptr
)
{
delete
[]
(
char
*
)
ptr
;
});
...
...
@@ -495,7 +524,8 @@ string RtcpFB::dumpString() const {
printer
<<
"ssrc:"
<<
ssrc
<<
"
\r\n
"
;
printer
<<
"ssrc_media:"
<<
ssrc_media
<<
"
\r\n
"
;
auto
fci_data
=
(
uint8_t
*
)
&
ssrc_media
+
sizeof
(
ssrc_media
);
auto
fci_len
=
getSize
()
-
sizeof
(
RtcpFB
);
auto
fci_len
=
(
ssize_t
)
getSize
()
-
getPaddingSize
()
-
sizeof
(
RtcpFB
);
CHECK
(
fci_len
>=
0
);
switch
((
RtcpType
)
pt
)
{
case
RtcpType
:
:
RTCP_PSFB
:
{
switch
((
PSFBType
)
report_count
)
{
...
...
@@ -568,9 +598,11 @@ void RtcpFB::net2Host(size_t size) {
std
::
shared_ptr
<
RtcpBye
>
RtcpBye
::
create
(
const
std
::
vector
<
uint32_t
>
&
ssrcs
,
const
string
&
reason
)
{
assert
(
reason
.
size
()
<=
0xFF
);
auto
bytes
=
alignSize
(
sizeof
(
RtcpHeader
)
+
sizeof
(
uint32_t
)
*
ssrcs
.
size
()
+
1
+
reason
.
size
());
auto
real_size
=
sizeof
(
RtcpHeader
)
+
sizeof
(
uint32_t
)
*
ssrcs
.
size
()
+
1
+
reason
.
size
();
auto
bytes
=
alignSize
(
real_size
);
auto
ptr
=
(
RtcpBye
*
)
new
char
[
bytes
];
setupHeader
(
ptr
,
RtcpType
::
RTCP_BYE
,
ssrcs
.
size
(),
bytes
);
setupPadding
(
ptr
,
bytes
-
real_size
);
auto
*
ssrc_ptr
=
&
(((
RtcpBye
*
)
ptr
)
->
ssrc
);
for
(
auto
ssrc
:
ssrcs
)
{
...
...
src/Rtcp/Rtcp.h
查看文件 @
6c951c8c
...
...
@@ -172,7 +172,7 @@ public:
#else
//reception report count
uint32_t
report_count
:
5
;
//padding,
固定为0
//padding,
末尾是否有追加填充
uint32_t
padding
:
1
;
//版本号,固定为2
uint32_t
version
:
2
;
...
...
@@ -213,6 +213,11 @@ public:
size_t
getSize
()
const
;
/**
* 后面追加padding数据长度
*/
size_t
getPaddingSize
()
const
;
/**
* 设置rtcp length字段
* @param size rtcp总长度,单位字节
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论