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
5f511eb2
Commit
5f511eb2
authored
Oct 30, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成部分265 rtp编码功能
parent
86c37b8c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
90 行增加
和
29 行删除
+90
-29
src/Extension/Factory.cpp
+16
-1
src/Extension/H265.h
+53
-4
src/RtspMuxer/H265RtpCodec.cpp
+20
-23
src/RtspMuxer/H265RtpCodec.h
+1
-1
没有找到文件。
src/Extension/Factory.cpp
查看文件 @
5f511eb2
...
...
@@ -48,6 +48,19 @@ Sdp::Ptr Factory::getSdpByTrack(const Track::Ptr &track) {
return
std
::
make_shared
<
H264Sdp
>
(
h264Track
->
getSps
(),
h264Track
->
getPps
());
}
case
CodecH265
:{
H265Track
::
Ptr
h265Track
=
dynamic_pointer_cast
<
H265Track
>
(
track
);
if
(
!
h265Track
){
WarnL
<<
"该Track不是H265Track类型"
;
return
nullptr
;
}
if
(
!
h265Track
->
ready
()){
WarnL
<<
"该Track未准备好"
;
return
nullptr
;
}
return
std
::
make_shared
<
H265Sdp
>
(
h265Track
->
getSps
(),
h265Track
->
getPps
());
}
case
CodecAAC
:{
AACTrack
::
Ptr
aacTrack
=
dynamic_pointer_cast
<
AACTrack
>
(
track
);
if
(
!
aacTrack
){
...
...
@@ -115,7 +128,9 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
if
(
3
!=
sscanf
(
track
->
_fmtp
.
c_str
(),
"%d sprop-sps=%127[^;]; sprop-pps=%127[^;]"
,
&
pt
,
sprop_sps
,
sprop_pps
))
{
return
std
::
make_shared
<
H265Track
>
();
}
return
std
::
make_shared
<
H265Track
>
(
""
,
sprop_sps
,
sprop_pps
,
0
,
0
,
0
);
auto
sps
=
decodeBase64
(
sprop_sps
);
auto
pps
=
decodeBase64
(
sprop_pps
);
return
std
::
make_shared
<
H265Track
>
(
""
,
sps
,
pps
,
0
,
0
,
0
);
}
...
...
src/Extension/H265.h
查看文件 @
5f511eb2
...
...
@@ -29,6 +29,7 @@
#include "Frame.h"
#include "Track.h"
#include "RtspMuxer/RtspSdp.h"
namespace
mediakit
{
...
...
@@ -228,7 +229,7 @@ public:
}
bool
ready
()
override
{
return
!
_sps
.
empty
()
&&
!
_pps
.
empty
()
&&
!
_vps
.
empty
()
;
return
!
_sps
.
empty
()
&&
!
_pps
.
empty
();
}
...
...
@@ -251,7 +252,7 @@ public:
_vpsFrame
=
insertFrame
;
}
_vpsFrame
->
timeStamp
=
frame
->
stamp
();
VideoTrack
::
inputFrame
(
_vpsFrame
);
//
VideoTrack::inputFrame(_vpsFrame);
}
if
(
!
_sps
.
empty
())
{
if
(
!
_spsFrame
)
{
...
...
@@ -264,7 +265,7 @@ public:
_spsFrame
=
insertFrame
;
}
_spsFrame
->
timeStamp
=
frame
->
stamp
();
VideoTrack
::
inputFrame
(
_spsFrame
);
//
VideoTrack::inputFrame(_spsFrame);
}
if
(
!
_pps
.
empty
())
{
...
...
@@ -278,7 +279,7 @@ public:
_ppsFrame
=
insertFrame
;
}
_ppsFrame
->
timeStamp
=
frame
->
stamp
();
VideoTrack
::
inputFrame
(
_ppsFrame
);
//
VideoTrack::inputFrame(_ppsFrame);
}
VideoTrack
::
inputFrame
(
frame
);
return
;
...
...
@@ -289,17 +290,20 @@ public:
case
H265Frame
:
:
NAL_VPS
:
{
//vps
_vps
=
string
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
());
VideoTrack
::
inputFrame
(
frame
);
}
break
;
case
H265Frame
:
:
NAL_SPS
:
{
//sps
_sps
=
string
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
());
VideoTrack
::
inputFrame
(
frame
);
}
break
;
case
H265Frame
:
:
NAL_PPS
:
{
//pps
_pps
=
string
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
());
VideoTrack
::
inputFrame
(
frame
);
}
break
;
...
...
@@ -341,6 +345,51 @@ private:
};
/**
* h265类型sdp
*/
class
H265Sdp
:
public
Sdp
{
public
:
/**
*
* @param sps 265 sps,不带0x00000001头
* @param pps 265 pps,不带0x00000001头
* @param playload_type rtp playload type 默认96
* @param bitrate 比特率
*/
H265Sdp
(
const
string
&
strSPS
,
const
string
&
strPPS
,
int
playload_type
=
96
,
int
bitrate
=
4000
)
:
Sdp
(
90000
,
playload_type
)
{
//视频通道
_printer
<<
"m=video 0 RTP/AVP "
<<
playload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
playload_type
<<
" H265/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=fmtp:"
<<
playload_type
<<
" sprop-sps="
;
_printer
<<
encodeBase64
(
strSPS
)
<<
"; "
;
_printer
<<
"sprop-pps="
;
_printer
<<
encodeBase64
(
strPPS
)
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
getTrackType
()
<<
"
\r\n
"
;
}
string
getSdp
()
const
override
{
return
_printer
;
}
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;
}
CodecId
getCodecId
()
const
override
{
return
CodecH265
;
}
private
:
_StrPrinter
_printer
;
};
}
//namespace mediakit
...
...
src/RtspMuxer/H265RtpCodec.cpp
查看文件 @
5f511eb2
...
...
@@ -129,7 +129,7 @@ bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
_h265frame
->
buffer
.
append
((
char
*
)
frame
+
3
,
length
-
3
);
return
false
;
}
default
:
// 4.4.1. Single NAL Unit Packets (p24)
//a full frame
_h265frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
...
...
@@ -146,6 +146,7 @@ bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
void
H265RtpDecoder
::
onGetH265
(
const
H265Frame
::
Ptr
&
frame
)
{
//写入环形缓存
auto
lastSeq
=
_h265frame
->
sequence
;
DebugL
<<
(
int
)
frame
->
type
;
RtpCodec
::
inputFrame
(
frame
);
_h265frame
=
obtainFrame
();
_h265frame
->
sequence
=
lastSeq
;
...
...
@@ -170,49 +171,47 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) {
RtpCodec
::
inputFrame
(
frame
);
GET_CONFIG_AND_REGISTER
(
uint32_t
,
cycleMS
,
Rtp
::
kCycleMS
);
auto
pcData
=
frame
->
data
()
+
frame
->
prefixSize
();
uint8_t
*
pcData
=
(
uint8_t
*
)
frame
->
data
()
+
frame
->
prefixSize
();
auto
uiStamp
=
frame
->
stamp
();
auto
iLen
=
frame
->
size
()
-
frame
->
prefixSize
();
unsigned
char
naluType
=
H265_TYPE
(
pcData
[
0
]);
//获取NALU的5bit 帧类型
uiStamp
%=
cycleMS
;
int
iSize
=
_ui32MtuSize
-
3
;
if
(
iLen
>
iSize
)
{
//超过MTU
const
unsigned
char
s_e_Start
=
1
<<
7
;
const
unsigned
char
s_e_Mid
=
0x00
;
const
unsigned
char
s_e_End
=
1
<<
6
;
WarnL
<<
(
int
)
naluType
;
int
maxSize
=
_ui32MtuSize
-
3
;
if
(
iLen
>
maxSize
)
{
//超过MTU
//获取帧头数据,1byte
unsigned
char
naluType
=
H265_TYPE
(
pcData
[
0
]);
//获取NALU的5bit 帧类型
unsigned
char
s_e_type
=
naluType
;
unsigned
char
s_e_type
;
bool
bFirst
=
true
;
bool
mark
=
false
;
int
nOffset
=
2
;
while
(
!
mark
)
{
if
(
iLen
<
nOffset
+
i
Size
)
{
//是否拆分结束
i
Size
=
iLen
-
nOffset
;
if
(
iLen
<
nOffset
+
max
Size
)
{
//是否拆分结束
max
Size
=
iLen
-
nOffset
;
mark
=
true
;
s_e_type
=
s_e_End
+
naluType
;
s_e_type
=
1
<<
7
|
naluType
;
}
else
{
if
(
bFirst
==
true
)
{
s_e_type
=
s_e_Start
+
naluType
;
s_e_type
=
1
<<
6
|
naluType
;
bFirst
=
false
;
}
else
{
s_e_type
=
s_e_Mid
+
naluType
;
s_e_type
=
naluType
;
}
}
//FU type
_aucSectionBuf
[
0
]
=
49
<<
1
;
_aucSectionBuf
[
1
]
=
1
;
_aucSectionBuf
[
2
]
=
s_e_type
;
memcpy
(
_aucSectionBuf
+
3
,
(
unsigned
char
*
)
pcData
+
nOffset
,
i
Size
);
nOffset
+=
i
Size
;
makeH265Rtp
(
_aucSectionBuf
,
i
Size
+
3
,
mark
,
uiStamp
);
memcpy
(
_aucSectionBuf
+
3
,
pcData
+
nOffset
,
max
Size
);
nOffset
+=
max
Size
;
makeH265Rtp
(
naluType
,
_aucSectionBuf
,
max
Size
+
3
,
mark
,
uiStamp
);
}
}
else
{
makeH265Rtp
(
pcData
,
iLen
,
true
,
uiStamp
);
makeH265Rtp
(
naluType
,
pcData
,
iLen
,
true
,
uiStamp
);
}
}
void
H265RtpEncoder
::
makeH265Rtp
(
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
void
H265RtpEncoder
::
makeH265Rtp
(
int
nal_type
,
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
uint16_t
ui16RtpLen
=
len
+
12
;
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
...
...
@@ -242,9 +241,7 @@ void H265RtpEncoder::makeH265Rtp(const void* data, unsigned int len, bool mark,
rtppkt
->
ssrc
=
_ui32Ssrc
;
rtppkt
->
type
=
TrackVideo
;
rtppkt
->
offset
=
16
;
uint8_t
type
=
H265_TYPE
(((
uint8_t
*
)
(
data
))[
0
]);
RtpCodec
::
inputRtp
(
rtppkt
,
type
==
H265Frame
::
isKeyFrame
(
type
));
RtpCodec
::
inputRtp
(
rtppkt
,
nal_type
==
H265Frame
::
NAL_VPS
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
}
...
...
src/RtspMuxer/H265RtpCodec.h
查看文件 @
5f511eb2
...
...
@@ -94,7 +94,7 @@ public:
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
private
:
void
makeH265Rtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
void
makeH265Rtp
(
int
nal_type
,
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
private
:
unsigned
char
_aucSectionBuf
[
1600
];
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论