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
23074048
Commit
23074048
authored
6 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善rtsp相关代码逻辑
parent
c1e91620
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
79 行增加
和
123 行删除
+79
-123
src/RTP/AACRtpCodec.cpp
+6
-6
src/RTP/AACRtpCodec.h
+1
-10
src/RTP/H264RtpCodec.cpp
+5
-5
src/RTP/H264RtpCodec.h
+1
-9
src/RTP/RtpCodec.cpp
+16
-11
src/RTP/RtpCodec.h
+24
-23
src/Rtsp/RtspEncoder.h
+26
-59
没有找到文件。
src/RTP/AACRtpCodec.cpp
查看文件 @
23074048
...
...
@@ -9,12 +9,12 @@ AACRtpEncoder::AACRtpEncoder(uint32_t ui32Ssrc,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
:
Rtp
Encoder
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
Rtp
Info
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
),
AACRtpDecoder
(
ui32SampleRate
){
}
void
AACRtpEncoder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
...
...
This diff is collapsed.
Click to expand it.
src/RTP/AACRtpCodec.h
查看文件 @
23074048
...
...
@@ -45,7 +45,7 @@ private:
/**
* aac adts转rtp类
*/
class
AACRtpEncoder
:
public
RtpEncoder
{
class
AACRtpEncoder
:
public
AACRtpDecoder
,
public
RtpInfo
{
public
:
/**
* @param ui32Ssrc ssrc
...
...
@@ -67,15 +67,6 @@ public:
* @param key_pos 此参数内部强制转换为false,请忽略之
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
=
false
)
override
;
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
}
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
private
:
void
makeAACRtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
private
:
...
...
This diff is collapsed.
Click to expand it.
src/RTP/H264RtpCodec.cpp
查看文件 @
23074048
...
...
@@ -109,11 +109,11 @@ H264RtpEncoder::H264RtpEncoder(uint32_t ui32Ssrc,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
:
Rtp
Encoder
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
Rtp
Info
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
}
void
H264RtpEncoder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
...
...
This diff is collapsed.
Click to expand it.
src/RTP/H264RtpCodec.h
查看文件 @
23074048
...
...
@@ -44,7 +44,7 @@ private:
/**
* 264 rtp打包类
*/
class
H264RtpEncoder
:
public
RtpEncoder
{
class
H264RtpEncoder
:
public
H264RtpDecoder
,
public
RtpInfo
{
public
:
/**
...
...
@@ -67,14 +67,6 @@ public:
* @param key_pos
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
override
;
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;
}
CodecId
getCodecId
()
const
override
{
return
CodecH264
;
}
private
:
void
makeH264Rtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
private
:
...
...
This diff is collapsed.
Click to expand it.
src/RTP/RtpCodec.cpp
查看文件 @
23074048
...
...
@@ -3,16 +3,21 @@
//
#include "RtpCodec.h"
#include "AACRtpCodec.h"
#include "H264RtpCodec.h"
RtpEncoder
::
RtpEncoder
(
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
:
RtpInfo
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
RtpCodec
::
Ptr
RtpCodec
::
getRtpCodec
(
CodecId
codecId
,
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
{
switch
(
codecId
){
case
CodecH264
:
return
std
::
make_shared
<
H264RtpEncoder
>
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
);
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpEncoder
>
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
);
default
:
return
nullptr
;
}
}
This diff is collapsed.
Click to expand it.
src/RTP/RtpCodec.h
查看文件 @
23074048
...
...
@@ -14,9 +14,18 @@ using namespace std;
using
namespace
ZL
::
Util
;
using
namespace
ZL
::
Player
;
class
RtpPacket
{
class
RtpPacket
:
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
RtpPacket
>
Ptr
;
TrackType
getTrackType
()
const
{
return
type
;
}
CodecId
getCodecId
()
const
{
return
CodecInvalid
;
}
public
:
uint8_t
interleaved
;
uint8_t
PT
;
bool
mark
;
...
...
@@ -71,10 +80,13 @@ public:
typedef
std
::
shared_ptr
<
RtpInfo
>
Ptr
;
RtpInfo
(
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
{
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
{
if
(
ui32Ssrc
==
0
){
ui32Ssrc
=
((
uint64_t
)
this
)
&
0xFFFFFFFF
;
}
m_ui32Ssrc
=
ui32Ssrc
;
m_ui32SampleRate
=
ui32SampleRate
;
m_ui32MtuSize
=
ui32MtuSize
;
...
...
@@ -130,29 +142,18 @@ public:
typedef
std
::
shared_ptr
<
RtpCodec
>
Ptr
;
RtpCodec
(){}
virtual
~
RtpCodec
(){}
};
class
RtpEncoder
:
public
RtpInfo
,
public
RtpCodec
{
public
:
typedef
std
::
shared_ptr
<
RtpEncoder
>
Ptr
;
/**
* @param ui32Ssrc ssrc
* @param ui32MtuSize mtu大小
* @param ui32SampleRate 采样率,强制为90000
* @param ui8PlayloadType pt类型
* @param ui8Interleaved rtsp interleaved
*/
RtpEncoder
(
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
=
1400
,
uint32_t
ui32SampleRate
=
90000
,
uint8_t
ui8PlayloadType
=
96
,
uint8_t
ui8Interleaved
=
TrackVideo
*
2
);
~
RtpEncoder
()
{}
static
Ptr
getRtpCodec
(
CodecId
codecId
,
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
);
};
#endif //ZLMEDIAKIT_RTPCODEC_H
This diff is collapsed.
Click to expand it.
src/Rtsp/RtspEncoder.h
查看文件 @
23074048
...
...
@@ -18,7 +18,10 @@ namespace Rtsp{
class
Sdp
:
public
TrackFormat
,
public
RtpRingInterface
{
public
:
typedef
std
::
shared_ptr
<
Sdp
>
Ptr
;
Sdp
(){}
Sdp
(
uint32_t
sample_rate
,
uint8_t
playload_type
){
_sample_rate
=
sample_rate
;
_playload_type
=
playload_type
;
}
virtual
~
Sdp
(){}
/**
* 获取sdp字符串
...
...
@@ -50,8 +53,6 @@ public:
_encoder
->
inputRtp
(
rtp
,
key_pos
);
}
virtual
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
=
0
;
void
setFrameRing
(
const
FrameRingInterface
::
RingType
::
Ptr
&
ring
)
override
{
if
(
_encoder
){
_encoder
->
setFrameRing
(
ring
);
...
...
@@ -63,8 +64,18 @@ public:
}
}
protected
:
RtpEncoder
::
Ptr
_encoder
;
virtual
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
{
_encoder
=
RtpCodec
::
getRtpCodec
(
getCodecId
(),
ssrc
,
mtu
,
_sample_rate
,
_playload_type
,
getTrackType
()
*
2
);
}
private
:
RtpCodec
::
Ptr
_encoder
;
uint8_t
_playload_type
;
uint32_t
_sample_rate
;
};
/**
...
...
@@ -81,7 +92,7 @@ public:
*/
SdpTitle
(
float
dur_sec
=
0
,
const
map
<
string
,
string
>
&
header
=
map
<
string
,
string
>
(),
int
version
=
0
){
int
version
=
0
)
:
Sdp
(
0
,
0
)
{
_printer
<<
"v="
<<
version
<<
"
\r\n
"
;
if
(
!
header
.
empty
()){
...
...
@@ -106,7 +117,6 @@ public:
string
getSdp
()
const
override
{
return
_printer
;
}
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
override
{}
private
:
_StrPrinter
_printer
;
};
...
...
@@ -130,13 +140,7 @@ public:
const
string
&
pps
,
int
sample_rate
=
90000
,
int
playload_type
=
96
,
int
track_id
=
TrackVideo
,
int
bitrate
=
4000
)
{
_playload_type
=
playload_type
;
_sample_rate
=
sample_rate
;
_track_id
=
track_id
;
int
bitrate
=
4000
)
:
Sdp
(
sample_rate
,
playload_type
)
{
//视频通道
_printer
<<
"m=video 0 RTP/AVP "
<<
playload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
...
...
@@ -160,7 +164,7 @@ public:
memset
(
strTemp
,
0
,
100
);
av_base64_encode
(
strTemp
,
100
,
(
uint8_t
*
)
strPPS
.
data
(),
strPPS
.
size
());
_printer
<<
strTemp
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
track_id
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
getTrackType
()
<<
"
\r\n
"
;
}
string
getSdp
()
const
override
{
...
...
@@ -174,20 +178,8 @@ public:
CodecId
getCodecId
()
const
override
{
return
CodecH264
;
}
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
override
{
_encoder
=
std
::
make_shared
<
H264RtpEncoder
>
(
ssrc
,
mtu
,
_sample_rate
,
_playload_type
,
_track_id
*
2
);
}
private
:
_StrPrinter
_printer
;
int
_playload_type
;
int
_sample_rate
;
int
_track_id
;
};
...
...
@@ -208,13 +200,7 @@ public:
SdpAAC
(
const
string
&
aac_cfg
,
int
sample_rate
,
int
playload_type
=
98
,
int
track_id
=
TrackAudio
,
int
bitrate
=
128
){
_playload_type
=
playload_type
;
_sample_rate
=
sample_rate
;
_track_id
=
track_id
;
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
"
;
...
...
@@ -224,7 +210,7 @@ public:
_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="
<<
track_id
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
getTrackType
()
<<
"
\r\n
"
;
}
string
getSdp
()
const
override
{
...
...
@@ -237,31 +223,8 @@ public:
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
override
{
_encoder
=
std
::
make_shared
<
AACRtpEncoder
>
(
ssrc
,
mtu
,
_sample_rate
,
_playload_type
,
_track_id
*
2
);
}
void
setFrameRing
(
const
FrameRingInterface
::
RingType
::
Ptr
&
ring
)
override
{
if
(
_encoder
){
_encoder
->
setFrameRing
(
ring
);
}
}
void
setRtpRing
(
const
RtpRingInterface
::
RingType
::
Ptr
&
ring
)
override
{
if
(
_encoder
){
_encoder
->
setRtpRing
(
ring
);
}
}
private
:
_StrPrinter
_printer
;
int
_playload_type
;
int
_sample_rate
;
int
_track_id
;
};
/**
...
...
@@ -329,7 +292,11 @@ public:
* @param key_pos 是否为关键帧的第一个rtp包
*/
void
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
=
true
)
override
{
_rtpRing
->
write
(
rtp
,
key_pos
);
auto
it
=
_sdp_map
.
find
(
rtp
->
getTrackType
());
if
(
it
==
_sdp_map
.
end
()){
return
;
}
it
->
second
->
inputRtp
(
rtp
,
key_pos
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论