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
ce2122d3
Commit
ce2122d3
authored
Jun 22, 2021
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtmp chunk相关处理代码
parent
510d908b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
13 行删除
+23
-13
src/Rtmp/Rtmp.h
+8
-1
src/Rtmp/RtmpProtocol.cpp
+15
-12
没有找到文件。
src/Rtmp/Rtmp.h
查看文件 @
ce2122d3
...
...
@@ -115,7 +115,14 @@ public:
class
RtmpHeader
{
public
:
uint8_t
flags
;
#if __BYTE_ORDER == __BIG_ENDIAN
uint8_t
fmt
:
2
;
uint8_t
chunk_id
:
6
;
#else
uint8_t
chunk_id
:
6
;
//0、1、2、3分别对应 12、8、4、1长度
uint8_t
fmt
:
2
;
#endif
uint8_t
time_stamp
[
3
];
uint8_t
body_size
[
3
];
uint8_t
type_id
;
...
...
src/Rtmp/RtmpProtocol.cpp
查看文件 @
ce2122d3
...
...
@@ -210,7 +210,8 @@ void RtmpProtocol::sendRtmp(uint8_t type, uint32_t stream_index, const Buffer::P
buffer_header
->
setSize
(
sizeof
(
RtmpHeader
));
//对rtmp头赋值,如果使用整形赋值,在arm android上可能由于数据对齐导致总线错误的问题
RtmpHeader
*
header
=
(
RtmpHeader
*
)
buffer_header
->
data
();
header
->
flags
=
(
chunk_id
&
0x3f
)
|
(
0
<<
6
);
header
->
fmt
=
0
;
header
->
chunk_id
=
chunk_id
;
header
->
type_id
=
type
;
set_be24
(
header
->
time_stamp
,
ext_stamp
?
0xFFFFFF
:
stamp
);
set_be24
(
header
->
body_size
,
(
uint32_t
)
buf
->
size
());
...
...
@@ -232,7 +233,9 @@ void RtmpProtocol::sendRtmp(uint8_t type, uint32_t stream_index, const Buffer::P
BufferRaw
::
Ptr
buffer_flags
=
obtainBuffer
();
buffer_flags
->
setCapacity
(
1
);
buffer_flags
->
setSize
(
1
);
buffer_flags
->
data
()[
0
]
=
(
chunk_id
&
0x3f
)
|
(
3
<<
6
);
header
=
(
RtmpHeader
*
)
buffer_flags
->
data
();
header
->
fmt
=
3
;
header
->
chunk_id
=
chunk_id
;
size_t
offset
=
0
;
size_t
totalSize
=
sizeof
(
RtmpHeader
);
...
...
@@ -523,15 +526,15 @@ const char* RtmpProtocol::handle_C2(const char *data, size_t len) {
return
handle_rtmp
(
data
+
C1_HANDSHARK_SIZE
,
len
-
C1_HANDSHARK_SIZE
);
}
static
const
size_t
HEADER_LENGTH
[]
=
{
12
,
8
,
4
,
1
};
static
const
expr
size_t
HEADER_LENGTH
[]
=
{
12
,
8
,
4
,
1
};
const
char
*
RtmpProtocol
::
handle_rtmp
(
const
char
*
data
,
size_t
len
)
{
auto
ptr
=
data
;
while
(
len
)
{
in
t
offset
=
0
;
uint8_t
flags
=
ptr
[
0
]
;
size_t
header_len
=
HEADER_LENGTH
[
flags
>>
6
];
_now_chunk_id
=
flags
&
0x3f
;
size_
t
offset
=
0
;
auto
header
=
(
RtmpHeader
*
)
ptr
;
auto
header_len
=
HEADER_LENGTH
[
header
->
fmt
];
_now_chunk_id
=
header
->
chunk_id
;
switch
(
_now_chunk_id
)
{
case
0
:
{
//0 值表示二字节形式,并且 ID 范围 64 - 319
...
...
@@ -565,7 +568,7 @@ const char* RtmpProtocol::handle_rtmp(const char *data, size_t len) {
//need more data
return
ptr
;
}
RtmpHeader
&
header
=
*
((
RtmpHeader
*
)
(
ptr
+
offset
)
);
header
=
(
RtmpHeader
*
)
(
ptr
+
offset
);
auto
&
pr
=
_map_chunk_data
[
_now_chunk_id
];
auto
&
now_packet
=
pr
.
first
;
auto
&
last_packet
=
pr
.
second
;
...
...
@@ -583,12 +586,12 @@ const char* RtmpProtocol::handle_rtmp(const char *data, size_t len) {
switch
(
header_len
)
{
case
12
:
chunk_data
.
is_abs_stamp
=
true
;
chunk_data
.
stream_index
=
load_le32
(
header
.
stream_index
);
chunk_data
.
stream_index
=
load_le32
(
header
->
stream_index
);
case
8
:
chunk_data
.
body_size
=
load_be24
(
header
.
body_size
);
chunk_data
.
type_id
=
header
.
type_id
;
chunk_data
.
body_size
=
load_be24
(
header
->
body_size
);
chunk_data
.
type_id
=
header
->
type_id
;
case
4
:
chunk_data
.
ts_field
=
load_be24
(
header
.
time_stamp
);
chunk_data
.
ts_field
=
load_be24
(
header
->
time_stamp
);
}
auto
time_stamp
=
chunk_data
.
ts_field
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论