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
bd8ad2ea
Unverified
Commit
bd8ad2ea
authored
Jul 29, 2023
by
夏楚
Committed by
GitHub
Jul 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化enhanced-rtmp解析性能 (#2717)
parent
00b3c518
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
52 行增加
和
21 行删除
+52
-21
src/Rtmp/Rtmp.cpp
+46
-21
src/Rtmp/Rtmp.h
+6
-0
没有找到文件。
src/Rtmp/Rtmp.cpp
查看文件 @
bd8ad2ea
...
@@ -257,50 +257,75 @@ void RtmpHandshake::random_generate(char *bytes, int size) {
...
@@ -257,50 +257,75 @@ void RtmpHandshake::random_generate(char *bytes, int size) {
}
}
}
}
#pragma pack(push, 1)
struct
RtmpVideoHeaderEnhanced
{
#if __BYTE_ORDER == __BIG_ENDIAN
uint8_t
enhanced
:
1
;
uint8_t
frame_type
:
3
;
uint8_t
pkt_type
:
4
;
uint32_t
fourcc
;
#else
uint8_t
pkt_type
:
4
;
uint8_t
frame_type
:
3
;
uint8_t
enhanced
:
1
;
uint32_t
fourcc
;
#endif
};
struct
RtmpVideoHeaderClassic
{
#if __BYTE_ORDER == __BIG_ENDIAN
uint8_t
frame_type
:
4
;
uint8_t
codec_id
:
4
;
uint8_t
h264_pkt_type
;
#else
uint8_t
codec_id
:
4
;
uint8_t
frame_type
:
4
;
uint8_t
h264_pkt_type
;
#endif
};
#pragma pack(pop)
CodecId
parseVideoRtmpPacket
(
const
uint8_t
*
data
,
size_t
size
,
RtmpPacketInfo
*
info
)
{
CodecId
parseVideoRtmpPacket
(
const
uint8_t
*
data
,
size_t
size
,
RtmpPacketInfo
*
info
)
{
RtmpPacketInfo
save
;
RtmpPacketInfo
save
;
info
=
info
?
info
:
&
save
;
info
=
info
?
info
:
&
save
;
info
->
codec
=
CodecInvalid
;
info
->
codec
=
CodecInvalid
;
CHECK
(
size
>
0
);
CHECK
(
size
>
0
);
if
(
data
[
0
]
>>
7
)
{
RtmpVideoHeaderEnhanced
*
enhanced_header
=
(
RtmpVideoHeaderEnhanced
*
)
data
;
if
(
enhanced_header
->
enhanced
)
{
// IsExHeader == 1
// IsExHeader == 1
CHECK
(
size
>=
5
,
"Invalid rtmp buffer size: "
,
size
);
CHECK
(
size
>=
5
,
"Invalid rtmp buffer size: "
,
size
);
info
->
is_enhanced
=
true
;
info
->
is_enhanced
=
true
;
info
->
video
.
frame_type
=
(
RtmpFrameType
)((
data
[
0
]
>>
4
)
&
0x07
);
info
->
video
.
frame_type
=
(
RtmpFrameType
)(
enhanced_header
->
frame_type
);
info
->
video
.
pkt_type
=
(
RtmpPacketType
)(
data
[
0
]
&
0x0f
);
info
->
video
.
pkt_type
=
(
RtmpPacketType
)(
enhanced_header
->
pkt_type
);
if
(
memcmp
(
data
+
1
,
"av01"
,
4
)
==
0
)
{
// AV1
switch
(
ntohl
(
enhanced_header
->
fourcc
))
{
info
->
codec
=
CodecAV1
;
case
fourcc_av1
:
info
->
codec
=
CodecAV1
;
break
;
}
else
if
(
memcmp
(
data
+
1
,
"vp09"
,
4
)
==
0
)
{
case
fourcc_vp9
:
info
->
codec
=
CodecVP9
;
break
;
// VP9
case
fourcc_hevc
:
info
->
codec
=
CodecH265
;
break
;
info
->
codec
=
CodecVP9
;
default:
WarnL
<<
"Rtmp video codec not supported: "
<<
std
::
string
((
char
*
)
data
+
1
,
4
);
}
else
if
(
memcmp
(
data
+
1
,
"hvc1"
,
4
)
==
0
)
{
// HEVC(H265)
info
->
codec
=
CodecH265
;
}
else
{
WarnL
<<
"Rtmp video codec not supported: "
<<
std
::
string
((
char
*
)
data
+
1
,
4
);
}
}
}
else
{
}
else
{
// IsExHeader == 0
// IsExHeader == 0
RtmpVideoHeaderClassic
*
classic_header
=
(
RtmpVideoHeaderClassic
*
)
data
;
info
->
is_enhanced
=
false
;
info
->
is_enhanced
=
false
;
info
->
video
.
frame_type
=
(
RtmpFrameType
)(
data
[
0
]
>>
4
);
info
->
video
.
frame_type
=
(
RtmpFrameType
)(
classic_header
->
frame_type
);
auto
rtmp_codec
=
(
RtmpVideoCodec
)(
data
[
0
]
&
0x0f
);
switch
((
RtmpVideoCodec
)(
classic_header
->
codec_id
))
{
switch
(
rtmp_codec
)
{
case
RtmpVideoCodec
:
:
h264
:
{
case
RtmpVideoCodec
:
:
h264
:
{
CHECK
(
size
>=
1
,
"Invalid rtmp buffer size: "
,
size
);
CHECK
(
size
>=
1
,
"Invalid rtmp buffer size: "
,
size
);
info
->
codec
=
CodecH264
;
info
->
codec
=
CodecH264
;
info
->
video
.
h264_pkt_type
=
(
RtmpH264PacketType
)
data
[
1
]
;
info
->
video
.
h264_pkt_type
=
(
RtmpH264PacketType
)
classic_header
->
h264_pkt_type
;
break
;
break
;
}
}
case
RtmpVideoCodec
:
:
h265
:
{
case
RtmpVideoCodec
:
:
h265
:
{
CHECK
(
size
>=
1
,
"Invalid rtmp buffer size: "
,
size
);
CHECK
(
size
>=
1
,
"Invalid rtmp buffer size: "
,
size
);
info
->
codec
=
CodecH265
;
info
->
codec
=
CodecH265
;
info
->
video
.
h264_pkt_type
=
(
RtmpH264PacketType
)
data
[
1
]
;
info
->
video
.
h264_pkt_type
=
(
RtmpH264PacketType
)
classic_header
->
h264_pkt_type
;
break
;
break
;
}
}
default
:
WarnL
<<
"Rtmp video codec not supported: "
<<
(
int
)
rtmp_codec
;
break
;
default:
WarnL
<<
"Rtmp video codec not supported: "
<<
(
int
)
classic_header
->
codec_id
;
break
;
}
}
}
}
return
info
->
codec
;
return
info
->
codec
;
...
...
src/Rtmp/Rtmp.h
查看文件 @
bd8ad2ea
...
@@ -357,6 +357,12 @@ struct RtmpPacketInfo {
...
@@ -357,6 +357,12 @@ struct RtmpPacketInfo {
};
};
};
};
// https://github.com/veovera/enhanced-rtmp
// https://github.com/veovera/enhanced-rtmp
// 增强型rtmp FourCC
static
constexpr
uint32_t
fourcc_vp9
=
'
vp09
'
;
static
constexpr
uint32_t
fourcc_av1
=
'
av01
'
;
static
constexpr
uint32_t
fourcc_hevc
=
'
hvc1
'
;
CodecId
parseVideoRtmpPacket
(
const
uint8_t
*
data
,
size_t
size
,
RtmpPacketInfo
*
info
=
nullptr
);
CodecId
parseVideoRtmpPacket
(
const
uint8_t
*
data
,
size_t
size
,
RtmpPacketInfo
*
info
=
nullptr
);
}
//namespace mediakit
}
//namespace mediakit
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论