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
12e1068a
Commit
12e1068a
authored
Aug 01, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/xiongziliang/ZLMediaKit
into zqsong
parents
69098612
e13ae419
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
30 行删除
+24
-30
src/Extension/H264.h
+1
-5
src/Extension/H264Rtmp.cpp
+0
-1
src/Extension/H264Rtp.cpp
+22
-24
src/Extension/H264Rtp.h
+1
-0
没有找到文件。
src/Extension/H264.h
查看文件 @
12e1068a
...
@@ -80,13 +80,11 @@ public:
...
@@ -80,13 +80,11 @@ public:
}
}
bool
keyFrame
()
const
override
{
bool
keyFrame
()
const
override
{
return
type
==
NAL_IDR
;
return
H264_TYPE
(
buffer
[
iPrefixSize
])
==
H264Frame
::
NAL_IDR
;
}
}
public
:
public
:
uint16_t
sequence
;
uint32_t
timeStamp
;
uint32_t
timeStamp
;
uint32_t
ptsStamp
=
0
;
uint32_t
ptsStamp
=
0
;
unsigned
char
type
;
string
buffer
;
string
buffer
;
uint32_t
iPrefixSize
=
4
;
uint32_t
iPrefixSize
=
4
;
};
};
...
@@ -326,7 +324,6 @@ private:
...
@@ -326,7 +324,6 @@ private:
if
(
!
_sps
.
empty
()){
if
(
!
_sps
.
empty
()){
auto
spsFrame
=
std
::
make_shared
<
H264Frame
>
();
auto
spsFrame
=
std
::
make_shared
<
H264Frame
>
();
spsFrame
->
type
=
H264Frame
::
NAL_SPS
;
spsFrame
->
iPrefixSize
=
4
;
spsFrame
->
iPrefixSize
=
4
;
spsFrame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
spsFrame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
spsFrame
->
buffer
.
append
(
_sps
);
spsFrame
->
buffer
.
append
(
_sps
);
...
@@ -336,7 +333,6 @@ private:
...
@@ -336,7 +333,6 @@ private:
if
(
!
_pps
.
empty
()){
if
(
!
_pps
.
empty
()){
auto
ppsFrame
=
std
::
make_shared
<
H264Frame
>
();
auto
ppsFrame
=
std
::
make_shared
<
H264Frame
>
();
ppsFrame
->
type
=
H264Frame
::
NAL_PPS
;
ppsFrame
->
iPrefixSize
=
4
;
ppsFrame
->
iPrefixSize
=
4
;
ppsFrame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
ppsFrame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
ppsFrame
->
buffer
.
append
(
_pps
);
ppsFrame
->
buffer
.
append
(
_pps
);
...
...
src/Extension/H264Rtmp.cpp
查看文件 @
12e1068a
...
@@ -80,7 +80,6 @@ bool H264RtmpDecoder::decodeRtmp(const RtmpPacket::Ptr &pkt) {
...
@@ -80,7 +80,6 @@ bool H264RtmpDecoder::decodeRtmp(const RtmpPacket::Ptr &pkt) {
inline
void
H264RtmpDecoder
::
onGetH264
(
const
char
*
pcData
,
int
iLen
,
uint32_t
dts
,
uint32_t
pts
)
{
inline
void
H264RtmpDecoder
::
onGetH264
(
const
char
*
pcData
,
int
iLen
,
uint32_t
dts
,
uint32_t
pts
)
{
#if 1
#if 1
_h264frame
->
type
=
H264_TYPE
(
pcData
[
0
]);
_h264frame
->
timeStamp
=
dts
;
_h264frame
->
timeStamp
=
dts
;
_h264frame
->
ptsStamp
=
pts
;
_h264frame
->
ptsStamp
=
pts
;
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
//添加264头
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
//添加264头
...
...
src/Extension/H264Rtp.cpp
查看文件 @
12e1068a
...
@@ -100,12 +100,10 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
...
@@ -100,12 +100,10 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
//a full frame
//a full frame
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
,
length
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
,
length
);
_h264frame
->
type
=
nal
.
type
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
sequence
=
rtppack
->
sequence
;
auto
key
=
_h264frame
->
keyFrame
();
auto
isIDR
=
_h264frame
->
type
==
H264Frame
::
NAL_IDR
;
onGetH264
(
_h264frame
);
onGetH264
(
_h264frame
);
return
(
isIDR
);
//i frame
return
(
key
);
//i frame
}
}
switch
(
nal
.
type
){
switch
(
nal
.
type
){
...
@@ -131,9 +129,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
...
@@ -131,9 +129,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
MakeNalu
(
ptr
[
0
],
nal
);
MakeNalu
(
ptr
[
0
],
nal
);
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
append
((
char
*
)
ptr
,
len
);
_h264frame
->
buffer
.
append
((
char
*
)
ptr
,
len
);
_h264frame
->
type
=
nal
.
type
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
sequence
=
rtppack
->
sequence
;
if
(
nal
.
type
==
H264Frame
::
NAL_IDR
){
if
(
nal
.
type
==
H264Frame
::
NAL_IDR
){
haveIDR
=
true
;
haveIDR
=
true
;
}
}
...
@@ -148,35 +144,39 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
...
@@ -148,35 +144,39 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
//FU-A
//FU-A
FU
fu
;
FU
fu
;
MakeFU
(
frame
[
1
],
fu
);
MakeFU
(
frame
[
1
],
fu
);
if
(
fu
.
S
==
1
)
{
if
(
fu
.
S
)
{
//
FU-A start
//
该帧的第一个rtp包
char
tmp
=
(
nal
.
forbidden_zero_bit
<<
7
|
nal
.
nal_ref_idc
<<
5
|
fu
.
type
);
char
tmp
=
(
nal
.
forbidden_zero_bit
<<
7
|
nal
.
nal_ref_idc
<<
5
|
fu
.
type
);
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
push_back
(
tmp
);
_h264frame
->
buffer
.
push_back
(
tmp
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
type
=
fu
.
type
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
sequence
=
rtppack
->
sequence
;
//该函数return时,保存下当前sequence,以便下次对比seq是否连续
return
(
_h264frame
->
type
==
H264Frame
::
NAL_IDR
);
//i frame
_lastSeq
=
rtppack
->
sequence
;
return
_h264frame
->
keyFrame
();
}
}
if
(
rtppack
->
sequence
!=
(
uint16_t
)(
_h264frame
->
sequence
+
1
))
{
if
(
rtppack
->
sequence
!=
_lastSeq
+
1
&&
rtppack
->
sequence
!=
0
)
{
//中间的或末尾的rtp包,其seq必须连续(如果回环了则判定为连续),否则说明rtp丢包,那么该帧不完整,必须得丢弃
_h264frame
->
buffer
.
clear
();
_h264frame
->
buffer
.
clear
();
WarnL
<<
"
丢包,帧废弃:"
<<
rtppack
->
sequence
<<
","
<<
_h264frame
->
sequence
;
WarnL
<<
"
rtp sequence不连续: "
<<
rtppack
->
sequence
<<
" != "
<<
_lastSeq
<<
" + 1,该帧被废弃"
;
return
false
;
return
false
;
}
}
_h264frame
->
sequence
=
rtppack
->
sequence
;
if
(
fu
.
E
==
1
)
{
if
(
!
fu
.
E
)
{
//
FU-A end
//
该帧的中间rtp包
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
//该函数return时,保存下当前sequence,以便下次对比seq是否连续
auto
isIDR
=
_h264frame
->
type
==
H264Frame
::
NAL_IDR
;
_lastSeq
=
rtppack
->
sequence
;
onGetH264
(
_h264frame
);
return
false
;
return
isIDR
;
}
}
//FU-A mid
//该帧最后一个rtp包
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
return
false
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
auto
key
=
_h264frame
->
keyFrame
();
onGetH264
(
_h264frame
);
return
key
;
}
}
default
:
{
default
:
{
...
@@ -195,10 +195,8 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
...
@@ -195,10 +195,8 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
void
H264RtpDecoder
::
onGetH264
(
const
H264Frame
::
Ptr
&
frame
)
{
void
H264RtpDecoder
::
onGetH264
(
const
H264Frame
::
Ptr
&
frame
)
{
//写入环形缓存
//写入环形缓存
auto
lastSeq
=
_h264frame
->
sequence
;
RtpCodec
::
inputFrame
(
frame
);
RtpCodec
::
inputFrame
(
frame
);
_h264frame
=
obtainFrame
();
_h264frame
=
obtainFrame
();
_h264frame
->
sequence
=
lastSeq
;
}
}
...
...
src/Extension/H264Rtp.h
查看文件 @
12e1068a
...
@@ -64,6 +64,7 @@ private:
...
@@ -64,6 +64,7 @@ private:
H264Frame
::
Ptr
obtainFrame
();
H264Frame
::
Ptr
obtainFrame
();
private
:
private
:
H264Frame
::
Ptr
_h264frame
;
H264Frame
::
Ptr
_h264frame
;
int
_lastSeq
=
0
;
};
};
/**
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论