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
d0d73098
Commit
d0d73098
authored
Jul 11, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善rtsp播放器推流udp端口创建机制
parent
6518398a
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
47 行增加
和
26 行删除
+47
-26
src/Rtsp/RtspPlayer.cpp
+26
-14
src/Rtsp/RtspPlayer.h
+1
-0
src/Rtsp/RtspPusher.cpp
+18
-12
src/Rtsp/RtspPusher.h
+2
-0
没有找到文件。
src/Rtsp/RtspPlayer.cpp
查看文件 @
d0d73098
...
...
@@ -232,6 +232,29 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
sendSetup
(
0
);
}
//有必须的情况下创建udp端口
void
RtspPlayer
::
createUdpSockIfNecessary
(
int
track_idx
){
auto
&
rtpSockRef
=
_apRtpSock
[
track_idx
];
auto
&
rtcpSockRef
=
_apRtcpSock
[
track_idx
];
if
(
!
rtpSockRef
){
rtpSockRef
.
reset
(
new
Socket
(
getPoller
()));
if
(
!
rtpSockRef
->
bindUdpSock
(
0
,
get_local_ip
().
data
()))
{
rtpSockRef
.
reset
();
throw
std
::
runtime_error
(
"open rtp sock failed"
);
}
}
if
(
!
rtcpSockRef
){
rtcpSockRef
.
reset
(
new
Socket
(
getPoller
()));
if
(
!
rtcpSockRef
->
bindUdpSock
(
rtpSockRef
->
get_local_port
()
+
1
,
get_local_ip
().
data
()))
{
rtcpSockRef
.
reset
();
throw
std
::
runtime_error
(
"open rtcp sock failed"
);
}
}
}
//发送SETUP命令
void
RtspPlayer
::
sendSetup
(
unsigned
int
trackIndex
)
{
_onHandshake
=
std
::
bind
(
&
RtspPlayer
::
handleResSETUP
,
this
,
placeholders
::
_1
,
trackIndex
);
...
...
@@ -247,16 +270,7 @@ void RtspPlayer::sendSetup(unsigned int trackIndex) {
}
break
;
case
Rtsp
:
:
RTP_UDP
:
{
_apRtpSock
[
trackIndex
].
reset
(
new
Socket
(
getPoller
()));
if
(
!
_apRtpSock
[
trackIndex
]
->
bindUdpSock
(
0
,
get_local_ip
().
data
()))
{
_apRtpSock
[
trackIndex
].
reset
();
throw
std
::
runtime_error
(
"open rtp sock err"
);
}
_apRtcpSock
[
trackIndex
].
reset
(
new
Socket
(
getPoller
()));
if
(
!
_apRtcpSock
[
trackIndex
]
->
bindUdpSock
(
_apRtpSock
[
trackIndex
]
->
get_local_port
()
+
1
,
get_local_ip
().
data
()))
{
_apRtcpSock
[
trackIndex
].
reset
();
throw
std
::
runtime_error
(
"open rtcp sock err"
);
}
createUdpSockIfNecessary
(
trackIndex
);
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"Transport"
,
StrPrinter
<<
"RTP/AVP;unicast;client_port="
<<
_apRtpSock
[
trackIndex
]
->
get_local_port
()
<<
"-"
...
...
@@ -314,10 +328,8 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int uiTrackIndex)
SockUtil
::
joinMultiAddr
(
fd
,
multiAddr
.
data
(),
get_local_ip
().
data
());
}
}
else
{
if
(
!
pRtpSockRef
||
!
pRtcpSockRef
){
throw
std
::
runtime_error
(
"udp socket not created yet when rtp over udp"
);
}
//udp单播
createUdpSockIfNecessary
(
uiTrackIndex
);
//udp单播
struct
sockaddr_in
rtpto
;
rtpto
.
sin_port
=
ntohs
(
rtp_port
);
rtpto
.
sin_family
=
AF_INET
;
...
...
src/Rtsp/RtspPlayer.h
查看文件 @
d0d73098
...
...
@@ -120,6 +120,7 @@ private:
void
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
());
void
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
std
::
initializer_list
<
string
>
&
header
);
void
sendReceiverReport
(
bool
overTcp
,
int
iTrackIndex
);
void
createUdpSockIfNecessary
(
int
track_idx
);
private
:
string
_strUrl
;
SdpParser
_sdpParser
;
...
...
src/Rtsp/RtspPusher.cpp
查看文件 @
d0d73098
...
...
@@ -242,6 +242,19 @@ bool RtspPusher::handleAuthenticationFailure(const string ¶msStr) {
return
false
;
}
//有必须的情况下创建udp端口
void
RtspPusher
::
createUdpSockIfNecessary
(
int
track_idx
){
auto
&
rtpSockRef
=
_apUdpSock
[
track_idx
];
if
(
!
rtpSockRef
){
rtpSockRef
.
reset
(
new
Socket
(
getPoller
()));
if
(
!
rtpSockRef
->
bindUdpSock
(
0
,
get_local_ip
().
data
()))
{
rtpSockRef
.
reset
();
throw
std
::
runtime_error
(
"open rtp sock failed"
);
}
}
}
void
RtspPusher
::
sendSetup
(
unsigned
int
trackIndex
)
{
_onHandshake
=
std
::
bind
(
&
RtspPusher
::
handleResSetup
,
this
,
placeholders
::
_1
,
trackIndex
);
auto
&
track
=
_aTrackInfo
[
trackIndex
];
...
...
@@ -252,11 +265,7 @@ void RtspPusher::sendSetup(unsigned int trackIndex) {
}
break
;
case
Rtsp
:
:
RTP_UDP
:
{
_apUdpSock
[
trackIndex
].
reset
(
new
Socket
(
getPoller
()));
if
(
!
_apUdpSock
[
trackIndex
]
->
bindUdpSock
(
0
,
get_local_ip
().
data
()))
{
_apUdpSock
[
trackIndex
].
reset
();
throw
std
::
runtime_error
(
"open udp sock err"
);
}
createUdpSockIfNecessary
(
trackIndex
);
int
port
=
_apUdpSock
[
trackIndex
]
->
get_local_port
();
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"Transport"
,
StrPrinter
<<
"RTP/AVP;unicast;client_port="
<<
port
<<
"-"
<<
port
+
1
});
}
...
...
@@ -266,6 +275,7 @@ void RtspPusher::sendSetup(unsigned int trackIndex) {
}
}
void
RtspPusher
::
handleResSetup
(
const
Parser
&
parser
,
unsigned
int
uiTrackIndex
)
{
if
(
parser
.
Url
()
!=
"200"
)
{
throw
std
::
runtime_error
(
...
...
@@ -278,7 +288,7 @@ void RtspPusher::handleResSetup(const Parser &parser, unsigned int uiTrackIndex)
}
auto
strTransport
=
parser
[
"Transport"
];
if
(
strTransport
.
find
(
"TCP"
)
!=
string
::
npos
){
if
(
strTransport
.
find
(
"TCP"
)
!=
string
::
npos
||
strTransport
.
find
(
"interleaved"
)
!=
string
::
npos
){
_eType
=
Rtsp
::
RTP_TCP
;
string
interleaved
=
FindField
(
FindField
((
strTransport
+
";"
).
data
(),
"interleaved="
,
";"
).
data
(),
NULL
,
"-"
);
_aTrackInfo
[
uiTrackIndex
]
->
_interleaved
=
atoi
(
interleaved
.
data
());
...
...
@@ -286,19 +296,15 @@ void RtspPusher::handleResSetup(const Parser &parser, unsigned int uiTrackIndex)
throw
std
::
runtime_error
(
"SETUP rtsp pusher can not support multicast!"
);
}
else
{
_eType
=
Rtsp
::
RTP_UDP
;
createUdpSockIfNecessary
(
uiTrackIndex
);
const
char
*
strPos
=
"server_port="
;
auto
port_str
=
FindField
((
strTransport
+
";"
).
data
(),
strPos
,
";"
);
uint16_t
port
=
atoi
(
FindField
(
port_str
.
data
(),
NULL
,
"-"
).
data
());
auto
&
pUdpSockRef
=
_apUdpSock
[
uiTrackIndex
];
if
(
!
pUdpSockRef
){
pUdpSockRef
.
reset
(
new
Socket
(
getPoller
()));
}
struct
sockaddr_in
rtpto
;
rtpto
.
sin_port
=
ntohs
(
port
);
rtpto
.
sin_family
=
AF_INET
;
rtpto
.
sin_addr
.
s_addr
=
inet_addr
(
get_peer_ip
().
data
());
pUdpSockRef
->
setSendPeerAddr
((
struct
sockaddr
*
)
&
(
rtpto
));
_apUdpSock
[
uiTrackIndex
]
->
setSendPeerAddr
((
struct
sockaddr
*
)
&
(
rtpto
));
}
RtspSplitter
::
enableRecvRtp
(
_eType
==
Rtsp
::
RTP_TCP
);
...
...
src/Rtsp/RtspPusher.h
查看文件 @
d0d73098
...
...
@@ -65,6 +65,8 @@ private:
void
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
)
;
void
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
(),
const
string
&
sdp
=
""
);
void
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
std
::
initializer_list
<
string
>
&
header
,
const
string
&
sdp
=
""
);
void
createUdpSockIfNecessary
(
int
track_idx
);
private
:
//rtsp鉴权相关
string
_rtspMd5Nonce
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论