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
bdc1f0cd
Commit
bdc1f0cd
authored
Oct 26, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
规范SdpAttr成员变量命名
parent
c5561228
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
68 行增加
和
69 行删除
+68
-69
src/Rtsp/Rtsp.cpp
+5
-5
src/Rtsp/Rtsp.h
+6
-6
src/Rtsp/RtspMediaSource.h
+23
-9
src/Rtsp/RtspPlayer.cpp
+10
-14
src/Rtsp/RtspPlayerImp.h
+1
-1
src/Rtsp/RtspSession.cpp
+16
-16
src/Rtsp/RtspSession.h
+1
-1
src/Rtsp/RtspToRtmpMediaSource.h
+5
-16
src/RtspMuxer/RtspDemuxer.cpp
+1
-1
没有找到文件。
src/Rtsp/Rtsp.cpp
查看文件 @
bdc1f0cd
...
...
@@ -110,13 +110,13 @@ void SdpAttr::load(const string &sdp) {
for
(
auto
&
pr
:
_track_map
)
{
auto
&
track
=
*
pr
.
second
;
if
(
pr
.
first
==
""
)
{
track
.
type
=
TrackTitle
;
track
.
_
type
=
TrackTitle
;
}
else
if
(
pr
.
first
==
"video"
)
{
track
.
type
=
TrackVideo
;
track
.
_
type
=
TrackVideo
;
}
else
if
(
pr
.
first
==
"audio"
)
{
track
.
type
=
TrackAudio
;
track
.
_
type
=
TrackAudio
;
}
else
{
track
.
type
=
TrackInvalid
;
track
.
_
type
=
TrackInvalid
;
}
auto
it
=
track
.
_attr
.
find
(
"range"
);
...
...
@@ -165,7 +165,7 @@ bool SdpAttr::available() const {
SdpTrack
::
Ptr
SdpAttr
::
getTrack
(
TrackType
type
)
const
{
for
(
auto
&
pr
:
_track_map
){
if
(
pr
.
second
->
type
==
type
){
if
(
pr
.
second
->
_
type
==
type
){
return
pr
.
second
;
}
}
...
...
src/Rtsp/Rtsp.h
查看文件 @
bdc1f0cd
...
...
@@ -63,13 +63,13 @@ public:
string
_fmtp
;
string
_control
;
string
_control_surffix
;
TrackType
type
;
TrackType
_
type
;
public
:
uint8_t
interleaved
=
0
;
bool
inited
=
false
;
uint32_t
ssrc
=
0
;
uint16_t
seq
=
0
;
uint32_t
timeS
tamp
=
0
;
uint8_t
_
interleaved
=
0
;
bool
_
inited
=
false
;
uint32_t
_
ssrc
=
0
;
uint16_t
_
seq
=
0
;
uint32_t
_time_s
tamp
=
0
;
};
class
SdpAttr
{
public
:
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
bdc1f0cd
...
...
@@ -71,31 +71,45 @@ public:
}
virtual
uint32_t
getSsrc
(
TrackType
trackType
)
{
return
_mapTracks
[
trackType
].
ssrc
;
auto
track
=
_sdpAttr
.
getTrack
(
trackType
);
if
(
!
track
){
return
0
;
}
return
track
->
_ssrc
;
}
virtual
uint16_t
getSeqence
(
TrackType
trackType
)
{
return
_mapTracks
[
trackType
].
seq
;
auto
track
=
_sdpAttr
.
getTrack
(
trackType
);
if
(
!
track
){
return
0
;
}
return
track
->
_seq
;
}
virtual
uint32_t
getTimestamp
(
TrackType
trackType
)
{
return
_mapTracks
[
trackType
].
timeStamp
;
auto
track
=
_sdpAttr
.
getTrack
(
trackType
);
if
(
!
track
){
return
0
;
}
return
track
->
_time_stamp
;
}
virtual
void
onGetSDP
(
const
string
&
sdp
)
{
//派生类设置该媒体源媒体描述信息
_strSdp
=
sdp
;
_sdpAttr
.
load
(
sdp
);
regist
();
}
void
onWrite
(
const
RtpPacket
::
Ptr
&
rtppt
,
bool
keyPos
)
override
{
auto
&
trackRef
=
_mapTracks
[
rtppt
->
type
];
trackRef
.
seq
=
rtppt
->
sequence
;
trackRef
.
timeStamp
=
rtppt
->
timeStamp
;
trackRef
.
ssrc
=
rtppt
->
ssrc
;
trackRef
.
type
=
rtppt
->
type
;
auto
track
=
_sdpAttr
.
getTrack
(
rtppt
->
type
);
if
(
track
){
track
->
_seq
=
rtppt
->
sequence
;
track
->
_time_stamp
=
rtppt
->
timeStamp
;
track
->
_ssrc
=
rtppt
->
ssrc
;
}
_pRing
->
write
(
rtppt
,
keyPos
);
}
protected
:
unordered_map
<
int
,
SdpTrack
>
_mapTracks
;
SdpAttr
_sdpAttr
;
string
_strSdp
;
//媒体描述信息
RingType
::
Ptr
_pRing
;
//rtp环形缓冲
};
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
bdc1f0cd
...
...
@@ -287,10 +287,6 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
}
CLEAR_ARR
(
_aui32SsrcErrorCnt
)
for
(
auto
&
track
:
_aTrackInfo
)
{
track
->
ssrc
=
0
;
}
sendSetup
(
0
);
}
//发送SETUP命令
...
...
@@ -302,7 +298,7 @@ bool RtspPlayer::sendSetup(unsigned int trackIndex) {
switch
(
_eType
)
{
case
RTP_TCP
:
{
StrCaseMap
header
;
header
[
"Transport"
]
=
StrPrinter
<<
"RTP/AVP/TCP;unicast;interleaved="
<<
track
->
type
*
2
<<
"-"
<<
track
->
type
*
2
+
1
;
header
[
"Transport"
]
=
StrPrinter
<<
"RTP/AVP/TCP;unicast;interleaved="
<<
track
->
_type
*
2
<<
"-"
<<
track
->
_
type
*
2
+
1
;
return
sendRtspRequest
(
"SETUP"
,
baseUrl
,
header
);
}
break
;
...
...
@@ -352,7 +348,7 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int uiTrackIndex)
if
(
_eType
==
RTP_TCP
)
{
string
interleaved
=
FindField
(
FindField
((
strTransport
+
";"
).
c_str
(),
"interleaved="
,
";"
).
c_str
(),
NULL
,
"-"
);
_aTrackInfo
[
uiTrackIndex
]
->
interleaved
=
atoi
(
interleaved
.
c_str
());
_aTrackInfo
[
uiTrackIndex
]
->
_
interleaved
=
atoi
(
interleaved
.
c_str
());
}
else
{
const
char
*
strPos
=
(
_eType
==
RTP_MULTICAST
?
"port="
:
"server_port="
)
;
auto
port_str
=
FindField
((
strTransport
+
";"
).
c_str
(),
strPos
,
";"
);
...
...
@@ -589,7 +585,7 @@ bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned in
auto
&
track
=
_aTrackInfo
[
iTrackidx
];
auto
pt_ptr
=
_pktPool
.
obtain
();
auto
&
rtppt
=*
pt_ptr
;
rtppt
.
interleaved
=
track
->
interleaved
;
rtppt
.
interleaved
=
track
->
_
interleaved
;
rtppt
.
length
=
uiLen
+
4
;
rtppt
.
mark
=
pucData
[
1
]
>>
7
;
...
...
@@ -603,15 +599,15 @@ bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned in
//ssrc
memcpy
(
&
rtppt
.
ssrc
,
pucData
+
8
,
4
);
//内存对齐
rtppt
.
ssrc
=
ntohl
(
rtppt
.
ssrc
);
rtppt
.
type
=
track
->
type
;
if
(
track
->
ssrc
==
0
)
{
track
->
ssrc
=
rtppt
.
ssrc
;
rtppt
.
type
=
track
->
_
type
;
if
(
track
->
_
ssrc
==
0
)
{
track
->
_
ssrc
=
rtppt
.
ssrc
;
//保存SSRC
}
else
if
(
track
->
ssrc
!=
rtppt
.
ssrc
)
{
}
else
if
(
track
->
_
ssrc
!=
rtppt
.
ssrc
)
{
//ssrc错误
WarnL
<<
"ssrc错误"
;
if
(
_aui32SsrcErrorCnt
[
iTrackidx
]
++
>
10
)
{
track
->
ssrc
=
rtppt
.
ssrc
;
track
->
_
ssrc
=
rtppt
.
ssrc
;
WarnL
<<
"ssrc更换!"
;
}
return
false
;
...
...
@@ -815,7 +811,7 @@ int RtspPlayer::getTrackIndexByControlSuffix(const string &controlSuffix) const{
}
int
RtspPlayer
::
getTrackIndexByInterleaved
(
int
interleaved
)
const
{
for
(
unsigned
int
i
=
0
;
i
<
_aTrackInfo
.
size
();
i
++
)
{
if
(
_aTrackInfo
[
i
]
->
interleaved
==
interleaved
)
{
if
(
_aTrackInfo
[
i
]
->
_
interleaved
==
interleaved
)
{
return
i
;
}
}
...
...
@@ -824,7 +820,7 @@ int RtspPlayer::getTrackIndexByInterleaved(int interleaved) const{
int
RtspPlayer
::
getTrackIndexByTrackType
(
TrackType
trackType
)
const
{
for
(
unsigned
int
i
=
0
;
i
<
_aTrackInfo
.
size
();
i
++
)
{
if
(
_aTrackInfo
[
i
]
->
type
==
trackType
)
{
if
(
_aTrackInfo
[
i
]
->
_
type
==
trackType
)
{
return
i
;
}
}
...
...
src/Rtsp/RtspPlayerImp.h
查看文件 @
bdc1f0cd
...
...
@@ -67,7 +67,7 @@ private:
if
(
_pRtspMediaSrc
){
_pRtspMediaSrc
->
onGetSDP
(
sdp
);
}
_parser
.
reset
(
new
RtspDemuxer
(
sdp
));
_parser
.
reset
(
new
RtspDemuxer
(
sdp
Attr
));
return
true
;
}
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
rtppt
,
const
SdpTrack
::
Ptr
&
track
)
override
{
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
bdc1f0cd
...
...
@@ -512,11 +512,11 @@ bool RtspSession::handleReq_Setup() {
return
false
;
}
SdpTrack
::
Ptr
&
trackRef
=
_aTrackInfo
[
trackIdx
];
if
(
trackRef
->
inited
)
{
if
(
trackRef
->
_
inited
)
{
//已经初始化过该Track
return
false
;
}
trackRef
->
inited
=
true
;
//现在初始化
trackRef
->
_
inited
=
true
;
//现在初始化
auto
strongRing
=
_pWeakRing
.
lock
();
if
(
!
strongRing
)
{
...
...
@@ -562,9 +562,9 @@ bool RtspSession::handleReq_Setup() {
"x-Dynamic-Rate: 1
\r\n\r\n
"
,
_iCseq
,
SERVER_NAME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
trackRef
->
type
*
2
,
trackRef
->
type
*
2
+
1
,
printSSRC
(
trackRef
->
ssrc
).
data
(),
dateHeader
().
data
(),
trackRef
->
_
type
*
2
,
trackRef
->
_
type
*
2
+
1
,
printSSRC
(
trackRef
->
_
ssrc
).
data
(),
_strSession
.
data
());
SocketHelper
::
send
(
_pcBuf
,
iLen
);
}
...
...
@@ -609,7 +609,7 @@ bool RtspSession::handleReq_Setup() {
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
strClientPort
.
data
(),
pSockRtp
->
get_local_port
(),
pSockRtcp
->
get_local_port
(),
printSSRC
(
trackRef
->
ssrc
).
data
(),
printSSRC
(
trackRef
->
_
ssrc
).
data
(),
_strSession
.
data
());
SocketHelper
::
send
(
_pcBuf
,
n
);
}
...
...
@@ -630,7 +630,7 @@ bool RtspSession::handleReq_Setup() {
strongSelf
->
safeShutdown
();
});
}
int
iSrvPort
=
_pBrdcaster
->
getPort
(
trackRef
->
type
);
int
iSrvPort
=
_pBrdcaster
->
getPort
(
trackRef
->
_
type
);
//我们用trackIdx区分rtp和rtcp包
auto
pSockRtcp
=
UDPServer
::
Instance
().
getSock
(
get_local_ip
().
data
(),
2
*
trackIdx
+
1
,
iSrvPort
+
1
);
if
(
!
pSockRtcp
)
{
...
...
@@ -652,7 +652,7 @@ bool RtspSession::handleReq_Setup() {
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
_pBrdcaster
->
getIP
().
data
(),
get_local_ip
().
data
(),
iSrvPort
,
pSockRtcp
->
get_local_port
(),
udpTTL
,
printSSRC
(
trackRef
->
ssrc
).
data
(),
udpTTL
,
printSSRC
(
trackRef
->
_
ssrc
).
data
(),
_strSession
.
data
());
SocketHelper
::
send
(
_pcBuf
,
n
);
}
...
...
@@ -733,9 +733,9 @@ bool RtspSession::handleReq_Play() {
}
for
(
auto
&
track
:
_aTrackInfo
){
track
->
ssrc
=
pMediaSrc
->
getSsrc
(
track
->
type
);
track
->
seq
=
pMediaSrc
->
getSeqence
(
track
->
type
);
track
->
timeStamp
=
pMediaSrc
->
getTimestamp
(
track
->
type
);
track
->
_ssrc
=
pMediaSrc
->
getSsrc
(
track
->
_
type
);
track
->
_seq
=
pMediaSrc
->
getSeqence
(
track
->
_
type
);
track
->
_time_stamp
=
pMediaSrc
->
getTimestamp
(
track
->
_
type
);
}
}
_bFirstPlay
=
false
;
...
...
@@ -749,12 +749,12 @@ bool RtspSession::handleReq_Play() {
dateHeader
().
data
(),
_strSession
.
data
(),
iStamp
/
1000.0
);
for
(
auto
&
track
:
_aTrackInfo
){
if
(
track
->
inited
==
false
)
{
if
(
track
->
_
inited
==
false
)
{
//还有track没有setup
shutdown
();
return
;
}
iLen
+=
sprintf
(
_pcBuf
+
iLen
,
"url=%s/%s;seq=%d;rtptime=%u,"
,
_strUrl
.
data
(),
track
->
_control_surffix
.
data
(),
track
->
seq
,
track
->
timeS
tamp
);
iLen
+=
sprintf
(
_pcBuf
+
iLen
,
"url=%s/%s;seq=%d;rtptime=%u,"
,
_strUrl
.
data
(),
track
->
_control_surffix
.
data
(),
track
->
_seq
,
track
->
_time_s
tamp
);
}
iLen
-=
1
;
...
...
@@ -904,9 +904,9 @@ inline bool RtspSession::findStream() {
_pMediaSrc
=
pMediaSrc
;
for
(
auto
&
track
:
_aTrackInfo
){
track
->
ssrc
=
pMediaSrc
->
getSsrc
(
track
->
type
);
track
->
seq
=
pMediaSrc
->
getSeqence
(
track
->
type
);
track
->
timeStamp
=
pMediaSrc
->
getTimestamp
(
track
->
type
);
track
->
_ssrc
=
pMediaSrc
->
getSsrc
(
track
->
_
type
);
track
->
_seq
=
pMediaSrc
->
getSeqence
(
track
->
_
type
);
track
->
_time_stamp
=
pMediaSrc
->
getTimestamp
(
track
->
_
type
);
}
return
true
;
}
...
...
src/Rtsp/RtspSession.h
查看文件 @
bdc1f0cd
...
...
@@ -118,7 +118,7 @@ private:
}
inline
int
getTrackIndexByTrackType
(
TrackType
type
)
{
for
(
unsigned
int
i
=
0
;
i
<
_aTrackInfo
.
size
();
i
++
)
{
if
(
type
==
_aTrackInfo
[
i
]
->
type
)
{
if
(
type
==
_aTrackInfo
[
i
]
->
_
type
)
{
return
i
;
}
}
...
...
src/Rtsp/RtspToRtmpMediaSource.h
查看文件 @
bdc1f0cd
...
...
@@ -49,8 +49,9 @@ public:
virtual
~
RtspToRtmpMediaSource
();
virtual
void
onGetSDP
(
const
string
&
strSdp
)
override
{
RtspMediaSource
::
onGetSDP
(
strSdp
);
try
{
_pParser
.
reset
(
new
RtspDemuxer
(
strSdp
));
_pParser
.
reset
(
new
RtspDemuxer
(
_sdpAttr
));
_pRecorder
.
reset
(
new
MediaRecorder
(
getVhost
(),
getApp
(),
getId
(),
_pParser
,
_bEnableHls
,
_bEnableMp4
));
//todo(xzl) 修复此处
// _pParser->setOnAudioCB( std::bind(&RtspToRtmpMediaSource::onGetAAC, this, placeholders::_1));
...
...
@@ -59,7 +60,6 @@ public:
}
catch
(
exception
&
ex
)
{
WarnL
<<
ex
.
what
();
}
RtspMediaSource
::
onGetSDP
(
strSdp
);
}
virtual
void
onWrite
(
const
RtpPacket
::
Ptr
&
pRtppkt
,
bool
bKeyPos
)
override
{
if
(
_pParser
)
{
...
...
@@ -73,20 +73,9 @@ public:
}
void
updateTimeStamp
(
uint32_t
uiStamp
)
{
for
(
auto
&
pr
:
_mapTracks
)
{
switch
(
pr
.
second
.
type
)
{
case
TrackAudio
:
{
//todo(xzl) 修复此处
// pr.second.timeStamp = uiStamp * (_pParser->getAudioSampleRate() / 1000.0);
}
break
;
case
TrackVideo
:
{
pr
.
second
.
timeStamp
=
uiStamp
*
90
;
}
break
;
default
:
break
;
}
auto
tracks
=
_sdpAttr
.
getAvailableTrack
();
for
(
auto
&
track
:
tracks
)
{
track
->
_time_stamp
=
uiStamp
*
(
track
->
_samplerate
/
1000
.
0
);
}
}
...
...
src/RtspMuxer/RtspDemuxer.cpp
查看文件 @
bdc1f0cd
...
...
@@ -61,7 +61,7 @@ RtspDemuxer::RtspDemuxer(const SdpAttr &attr) {
void
RtspDemuxer
::
loadSdp
(
const
SdpAttr
&
attr
)
{
auto
tracks
=
attr
.
getAvailableTrack
();
for
(
auto
&
track
:
tracks
){
switch
(
track
->
type
)
{
switch
(
track
->
_
type
)
{
case
TrackVideo
:
{
makeVideoTrack
(
track
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论