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
86c37b8c
Commit
86c37b8c
authored
6 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初步完成265 rtp打包
整理代码
parent
00334b97
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
125 行增加
和
132 行删除
+125
-132
src/Extension/AAC.h
+45
-0
src/Extension/H264.h
+63
-0
src/RtspMuxer/H265RtpCodec.cpp
+16
-28
src/RtspMuxer/RtspSdp.h
+1
-104
没有找到文件。
src/Extension/AAC.h
查看文件 @
86c37b8c
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
#include "Frame.h"
#include "Frame.h"
#include "Track.h"
#include "Track.h"
#include "RtspMuxer/RtspSdp.h"
namespace
mediakit
{
namespace
mediakit
{
...
@@ -259,6 +261,49 @@ private:
...
@@ -259,6 +261,49 @@ private:
};
};
/**
* aac类型SDP
*/
class
AACSdp
:
public
Sdp
{
public
:
/**
*
* @param aac_cfg aac两个字节的配置描述
* @param sample_rate 音频采样率
* @param playload_type rtp playload type 默认98
* @param bitrate 比特率
*/
AACSdp
(
const
string
&
aac_cfg
,
int
sample_rate
,
int
playload_type
=
98
,
int
bitrate
=
128
)
:
Sdp
(
sample_rate
,
playload_type
){
_printer
<<
"m=audio 0 RTP/AVP "
<<
playload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
playload_type
<<
" MPEG4-GENERIC/"
<<
sample_rate
<<
"
\r\n
"
;
char
configStr
[
32
]
=
{
0
};
snprintf
(
configStr
,
sizeof
(
configStr
),
"%02X%02X"
,
(
uint8_t
)
aac_cfg
[
0
],
(
uint8_t
)
aac_cfg
[
1
]);
_printer
<<
"a=fmtp:"
<<
playload_type
<<
" streamtype=5;profile-level-id=1;mode=AAC-hbr;"
<<
"sizelength=13;indexlength=3;indexdeltalength=3;config="
<<
configStr
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
getTrackType
()
<<
"
\r\n
"
;
}
string
getSdp
()
const
override
{
return
_printer
;
}
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
}
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
private
:
_StrPrinter
_printer
;
};
}
//namespace mediakit
}
//namespace mediakit
...
...
This diff is collapsed.
Click to expand it.
src/Extension/H264.h
查看文件 @
86c37b8c
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
#include "Frame.h"
#include "Frame.h"
#include "Track.h"
#include "Track.h"
#include "RtspMuxer/RtspSdp.h"
#define H264_TYPE(v) ((uint8_t)(v) & 0x1F)
#define H264_TYPE(v) ((uint8_t)(v) & 0x1F)
...
@@ -283,6 +285,67 @@ private:
...
@@ -283,6 +285,67 @@ private:
};
};
/**
* h264类型sdp
*/
class
H264Sdp
:
public
Sdp
{
public
:
/**
*
* @param sps 264 sps,不带0x00000001头
* @param pps 264 pps,不带0x00000001头
* @param playload_type rtp playload type 默认96
* @param bitrate 比特率
*/
H264Sdp
(
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
<<
" H264/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=fmtp:"
<<
playload_type
<<
" packetization-mode=1;profile-level-id="
;
char
strTemp
[
100
];
uint32_t
profile_level_id
=
0
;
if
(
strSPS
.
length
()
>=
4
)
{
// sanity check
profile_level_id
=
(
uint8_t
(
strSPS
[
1
])
<<
16
)
|
(
uint8_t
(
strSPS
[
2
])
<<
8
)
|
(
uint8_t
(
strSPS
[
3
]));
// profile_idc|constraint_setN_flag|level_idc
}
memset
(
strTemp
,
0
,
100
);
sprintf
(
strTemp
,
"%06X"
,
profile_level_id
);
_printer
<<
strTemp
;
_printer
<<
";sprop-parameter-sets="
;
memset
(
strTemp
,
0
,
100
);
av_base64_encode
(
strTemp
,
100
,
(
uint8_t
*
)
strSPS
.
data
(),
strSPS
.
size
());
_printer
<<
strTemp
<<
","
;
memset
(
strTemp
,
0
,
100
);
av_base64_encode
(
strTemp
,
100
,
(
uint8_t
*
)
strPPS
.
data
(),
strPPS
.
size
());
_printer
<<
strTemp
<<
"
\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
CodecH264
;
}
private
:
_StrPrinter
_printer
;
};
}
//namespace mediakit
}
//namespace mediakit
...
...
This diff is collapsed.
Click to expand it.
src/RtspMuxer/H265RtpCodec.cpp
查看文件 @
86c37b8c
...
@@ -82,15 +82,6 @@ bool H265RtpDecoder::inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) {
...
@@ -82,15 +82,6 @@ bool H265RtpDecoder::inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) {
}
}
bool
H265RtpDecoder
::
decodeRtp
(
const
RtpPacket
::
Ptr
&
rtppack
)
{
bool
H265RtpDecoder
::
decodeRtp
(
const
RtpPacket
::
Ptr
&
rtppack
)
{
/**
* h265帧类型
* Type==1:P/B frame
* Type==5:IDR frame
* Type==6:SEI frame
* Type==7:SPS frame
* Type==8:PPS frame
*/
const
uint8_t
*
frame
=
(
uint8_t
*
)
rtppack
->
payload
+
rtppack
->
offset
;
const
uint8_t
*
frame
=
(
uint8_t
*
)
rtppack
->
payload
+
rtppack
->
offset
;
int
length
=
rtppack
->
length
-
rtppack
->
offset
;
int
length
=
rtppack
->
length
-
rtppack
->
offset
;
int
nal
=
H265_TYPE
(
frame
[
0
]);
int
nal
=
H265_TYPE
(
frame
[
0
]);
...
@@ -184,40 +175,37 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) {
...
@@ -184,40 +175,37 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) {
auto
iLen
=
frame
->
size
()
-
frame
->
prefixSize
();
auto
iLen
=
frame
->
size
()
-
frame
->
prefixSize
();
uiStamp
%=
cycleMS
;
uiStamp
%=
cycleMS
;
int
iSize
=
_ui32MtuSize
-
2
;
int
iSize
=
_ui32MtuSize
-
3
;
if
(
iLen
>
iSize
)
{
//超过MTU
if
(
iLen
>
iSize
)
{
//超过MTU
const
unsigned
char
s_e_
r_Start
=
0x80
;
const
unsigned
char
s_e_
Start
=
1
<<
7
;
const
unsigned
char
s_e_
r_
Mid
=
0x00
;
const
unsigned
char
s_e_Mid
=
0x00
;
const
unsigned
char
s_e_
r_End
=
0x40
;
const
unsigned
char
s_e_
End
=
1
<<
6
;
//获取帧头数据,1byte
//获取帧头数据,1byte
unsigned
char
naluType
=
*
((
unsigned
char
*
)
pcData
)
&
0x1f
;
//获取NALU的5bit 帧类型
unsigned
char
naluType
=
H265_TYPE
(
pcData
[
0
]);
//获取NALU的5bit 帧类型
unsigned
char
s_e_type
=
naluType
;
unsigned
char
nal_ref_idc
=
*
((
unsigned
char
*
)
pcData
)
&
0x60
;
//获取NALU的2bit 帧重要程度 00 可以丢 11不能丢
//nal_ref_idc = 0x60;
//组装FU-A帧头数据 2byte
unsigned
char
f_nri_type
=
nal_ref_idc
+
28
;
//F为0 1bit,nri上面获取到2bit,28为FU-A分片类型5bit
unsigned
char
s_e_r_type
=
naluType
;
bool
bFirst
=
true
;
bool
bFirst
=
true
;
bool
mark
=
false
;
bool
mark
=
false
;
int
nOffset
=
1
;
int
nOffset
=
2
;
while
(
!
mark
)
{
while
(
!
mark
)
{
if
(
iLen
<
nOffset
+
iSize
)
{
//是否拆分结束
if
(
iLen
<
nOffset
+
iSize
)
{
//是否拆分结束
iSize
=
iLen
-
nOffset
;
iSize
=
iLen
-
nOffset
;
mark
=
true
;
mark
=
true
;
s_e_
r_type
=
s_e_r
_End
+
naluType
;
s_e_
type
=
s_e
_End
+
naluType
;
}
else
{
}
else
{
if
(
bFirst
==
true
)
{
if
(
bFirst
==
true
)
{
s_e_
r_type
=
s_e_r
_Start
+
naluType
;
s_e_
type
=
s_e
_Start
+
naluType
;
bFirst
=
false
;
bFirst
=
false
;
}
else
{
}
else
{
s_e_
r_type
=
s_e_r
_Mid
+
naluType
;
s_e_
type
=
s_e
_Mid
+
naluType
;
}
}
}
}
memcpy
(
_aucSectionBuf
,
&
f_nri_type
,
1
);
//FU type
memcpy
(
_aucSectionBuf
+
1
,
&
s_e_r_type
,
1
);
_aucSectionBuf
[
0
]
=
49
<<
1
;
memcpy
(
_aucSectionBuf
+
2
,
(
unsigned
char
*
)
pcData
+
nOffset
,
iSize
);
_aucSectionBuf
[
1
]
=
1
;
_aucSectionBuf
[
2
]
=
s_e_type
;
memcpy
(
_aucSectionBuf
+
3
,
(
unsigned
char
*
)
pcData
+
nOffset
,
iSize
);
nOffset
+=
iSize
;
nOffset
+=
iSize
;
makeH265Rtp
(
_aucSectionBuf
,
iSize
+
2
,
mark
,
uiStamp
);
makeH265Rtp
(
_aucSectionBuf
,
iSize
+
3
,
mark
,
uiStamp
);
}
}
}
else
{
}
else
{
makeH265Rtp
(
pcData
,
iLen
,
true
,
uiStamp
);
makeH265Rtp
(
pcData
,
iLen
,
true
,
uiStamp
);
...
...
This diff is collapsed.
Click to expand it.
src/RtspMuxer/RtspSdp.h
查看文件 @
86c37b8c
...
@@ -26,10 +26,9 @@
...
@@ -26,10 +26,9 @@
#ifndef ZLMEDIAKIT_RTSPSDP_H
#ifndef ZLMEDIAKIT_RTSPSDP_H
#define ZLMEDIAKIT_RTSPSDP_H
#define ZLMEDIAKIT_RTSPSDP_H
#include "RtspMuxer/H264RtpCodec.h"
#include "RtspMuxer/AACRtpCodec.h"
#include "Util/base64.h"
#include "Util/base64.h"
#include "Extension/Track.h"
#include "Extension/Track.h"
#include "RtspMuxer/RtpCodec.h"
namespace
mediakit
{
namespace
mediakit
{
...
@@ -129,108 +128,6 @@ private:
...
@@ -129,108 +128,6 @@ private:
_StrPrinter
_printer
;
_StrPrinter
_printer
;
};
};
/**
* h264类型sdp
*/
class
H264Sdp
:
public
Sdp
{
public
:
/**
*
* @param sps 264 sps,不带0x00000001头
* @param pps 264 pps,不带0x00000001头
* @param playload_type rtp playload type 默认96
* @param bitrate 比特率
*/
H264Sdp
(
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
<<
" H264/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=fmtp:"
<<
playload_type
<<
" packetization-mode=1;profile-level-id="
;
char
strTemp
[
100
];
uint32_t
profile_level_id
=
0
;
if
(
strSPS
.
length
()
>=
4
)
{
// sanity check
profile_level_id
=
(
uint8_t
(
strSPS
[
1
])
<<
16
)
|
(
uint8_t
(
strSPS
[
2
])
<<
8
)
|
(
uint8_t
(
strSPS
[
3
]));
// profile_idc|constraint_setN_flag|level_idc
}
memset
(
strTemp
,
0
,
100
);
sprintf
(
strTemp
,
"%06X"
,
profile_level_id
);
_printer
<<
strTemp
;
_printer
<<
";sprop-parameter-sets="
;
memset
(
strTemp
,
0
,
100
);
av_base64_encode
(
strTemp
,
100
,
(
uint8_t
*
)
strSPS
.
data
(),
strSPS
.
size
());
_printer
<<
strTemp
<<
","
;
memset
(
strTemp
,
0
,
100
);
av_base64_encode
(
strTemp
,
100
,
(
uint8_t
*
)
strPPS
.
data
(),
strPPS
.
size
());
_printer
<<
strTemp
<<
"
\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
CodecH264
;
}
private
:
_StrPrinter
_printer
;
};
/**
* aac类型SDP
*/
class
AACSdp
:
public
Sdp
{
public
:
/**
*
* @param aac_cfg aac两个字节的配置描述
* @param sample_rate 音频采样率
* @param playload_type rtp playload type 默认98
* @param bitrate 比特率
*/
AACSdp
(
const
string
&
aac_cfg
,
int
sample_rate
,
int
playload_type
=
98
,
int
bitrate
=
128
)
:
Sdp
(
sample_rate
,
playload_type
){
_printer
<<
"m=audio 0 RTP/AVP "
<<
playload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
playload_type
<<
" MPEG4-GENERIC/"
<<
sample_rate
<<
"
\r\n
"
;
char
configStr
[
32
]
=
{
0
};
snprintf
(
configStr
,
sizeof
(
configStr
),
"%02X%02X"
,
(
uint8_t
)
aac_cfg
[
0
],
(
uint8_t
)
aac_cfg
[
1
]);
_printer
<<
"a=fmtp:"
<<
playload_type
<<
" streamtype=5;profile-level-id=1;mode=AAC-hbr;"
<<
"sizelength=13;indexlength=3;indexdeltalength=3;config="
<<
configStr
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
getTrackType
()
<<
"
\r\n
"
;
}
string
getSdp
()
const
override
{
return
_printer
;
}
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
}
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
private
:
_StrPrinter
_printer
;
};
}
/* namespace mediakit */
}
/* namespace mediakit */
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论