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
a19f6767
Commit
a19f6767
authored
Feb 21, 2021
by
xia-chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容一些rtsp流 #735
parent
19f3b1bd
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
25 行增加
和
29 行删除
+25
-29
src/Rtsp/Rtsp.cpp
+8
-2
src/Rtsp/Rtsp.h
+1
-1
src/Rtsp/RtspPlayer.cpp
+5
-8
src/Rtsp/RtspPusher.cpp
+4
-7
src/Rtsp/RtspSession.cpp
+6
-10
src/Rtsp/RtspSession.h
+1
-1
没有找到文件。
src/Rtsp/Rtsp.cpp
查看文件 @
a19f6767
...
...
@@ -86,6 +86,14 @@ string SdpTrack::getName() const{
}
}
string
SdpTrack
::
getControlUrl
(
const
string
&
base_url
)
const
{
if
(
_control
.
find
(
"://"
)
!=
string
::
npos
)
{
//以rtsp://开头
return
_control
;
}
return
base_url
+
"/"
+
_control
;
}
string
SdpTrack
::
toString
()
const
{
_StrPrinter
_printer
;
switch
(
_type
){
...
...
@@ -246,8 +254,6 @@ void SdpParser::load(const string &sdp) {
it
=
track
.
_attr
.
find
(
"control"
);
if
(
it
!=
track
.
_attr
.
end
())
{
track
.
_control
=
it
->
second
;
auto
surffix
=
string
(
"/"
)
+
track
.
_control
;
track
.
_control_surffix
=
surffix
.
substr
(
1
+
surffix
.
rfind
(
'/'
));
}
}
}
...
...
src/Rtsp/Rtsp.h
查看文件 @
a19f6767
...
...
@@ -213,6 +213,7 @@ public:
string
toString
()
const
;
string
getName
()
const
;
string
getControlUrl
(
const
string
&
base_url
)
const
;
public
:
int
_pt
;
...
...
@@ -222,7 +223,6 @@ public:
string
_codec
;
string
_fmtp
;
string
_control
;
string
_control_surffix
;
public
:
bool
_inited
=
false
;
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
a19f6767
...
...
@@ -226,23 +226,20 @@ void RtspPlayer::createUdpSockIfNecessary(int track_idx){
void
RtspPlayer
::
sendSetup
(
unsigned
int
track_idx
)
{
_on_response
=
std
::
bind
(
&
RtspPlayer
::
handleResSETUP
,
this
,
placeholders
::
_1
,
track_idx
);
auto
&
track
=
_sdp_track
[
track_idx
];
auto
baseUrl
=
_content_base
+
"/"
+
track
->
_control_surffix
;
if
(
track
->
_control
.
find
(
"://"
)
!=
string
::
npos
)
{
baseUrl
=
track
->
_control
;
}
auto
control_url
=
track
->
getControlUrl
(
_content_base
);
switch
(
_rtp_type
)
{
case
Rtsp
:
:
RTP_TCP
:
{
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"Transport"
,
StrPrinter
<<
"RTP/AVP/TCP;unicast;interleaved="
<<
track
->
_type
*
2
<<
"-"
<<
track
->
_type
*
2
+
1
});
sendRtspRequest
(
"SETUP"
,
control_url
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP/TCP;unicast;interleaved="
<<
track
->
_type
*
2
<<
"-"
<<
track
->
_type
*
2
+
1
});
}
break
;
case
Rtsp
:
:
RTP_MULTICAST
:
{
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"Transport"
,
"RTP/AVP;multicast"
});
sendRtspRequest
(
"SETUP"
,
control_url
,
{
"Transport"
,
"RTP/AVP;multicast"
});
}
break
;
case
Rtsp
:
:
RTP_UDP
:
{
createUdpSockIfNecessary
(
track_idx
);
sendRtspRequest
(
"SETUP"
,
baseU
rl
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP;unicast;client_port="
sendRtspRequest
(
"SETUP"
,
control_u
rl
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP;unicast;client_port="
<<
_rtp_sock
[
track_idx
]
->
get_local_port
()
<<
"-"
<<
_rtcp_sock
[
track_idx
]
->
get_local_port
()});
}
...
...
src/Rtsp/RtspPusher.cpp
查看文件 @
a19f6767
...
...
@@ -261,21 +261,18 @@ void RtspPusher::createUdpSockIfNecessary(int track_idx){
void
RtspPusher
::
sendSetup
(
unsigned
int
track_idx
)
{
_on_res_func
=
std
::
bind
(
&
RtspPusher
::
handleResSetup
,
this
,
placeholders
::
_1
,
track_idx
);
auto
&
track
=
_track_vec
[
track_idx
];
auto
base_url
=
_content_base
+
"/"
+
track
->
_control_surffix
;
if
(
track
->
_control
.
find
(
"://"
)
!=
string
::
npos
)
{
base_url
=
track
->
_control
;
}
auto
control_url
=
track
->
getControlUrl
(
_content_base
);
switch
(
_rtp_type
)
{
case
Rtsp
:
:
RTP_TCP
:
{
sendRtspRequest
(
"SETUP"
,
base
_url
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP/TCP;unicast;interleaved="
<<
track
->
_type
*
2
sendRtspRequest
(
"SETUP"
,
control
_url
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP/TCP;unicast;interleaved="
<<
track
->
_type
*
2
<<
"-"
<<
track
->
_type
*
2
+
1
});
}
break
;
case
Rtsp
:
:
RTP_UDP
:
{
createUdpSockIfNecessary
(
track_idx
);
int
port
=
_rtp_sock
[
track_idx
]
->
get_local_port
();
sendRtspRequest
(
"SETUP"
,
base
_url
,
sendRtspRequest
(
"SETUP"
,
control
_url
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP;unicast;client_port="
<<
port
<<
"-"
<<
port
+
1
});
}
break
;
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
a19f6767
...
...
@@ -268,7 +268,7 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
shutdown
(
SockException
(
Err_shutdown
,
"track not setuped"
));
return
;
}
rtp_info
<<
"url="
<<
_content_base
<<
"/"
<<
track
->
_control_surffix
<<
","
;
rtp_info
<<
"url="
<<
track
->
getControlUrl
(
_content_base
)
<<
","
;
}
rtp_info
.
pop_back
();
...
...
@@ -614,11 +614,7 @@ void RtspSession::send_SessionNotFound() {
void
RtspSession
::
handleReq_Setup
(
const
Parser
&
parser
)
{
//处理setup命令,该函数可能进入多次
auto
controlSuffix
=
split
(
parser
.
FullUrl
(),
"/"
).
back
();
if
(
controlSuffix
.
front
()
==
'/'
){
controlSuffix
=
controlSuffix
.
substr
(
1
);
}
int
trackIdx
=
getTrackIndexByControlSuffix
(
controlSuffix
);
int
trackIdx
=
getTrackIndexByControlUrl
(
parser
.
Url
());
SdpTrack
::
Ptr
&
trackRef
=
_sdp_track
[
trackIdx
];
if
(
trackRef
->
_inited
)
{
//已经初始化过该Track
...
...
@@ -796,7 +792,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
track
->
_seq
=
play_src
->
getSeqence
(
track
->
_type
);
track
->
_time_stamp
=
play_src
->
getTimeStamp
(
track
->
_type
);
rtp_info
<<
"url="
<<
_content_base
<<
"/"
<<
track
->
_control_surffix
<<
";"
rtp_info
<<
"url="
<<
track
->
getControlUrl
(
_content_base
)
<<
";"
<<
"seq="
<<
track
->
_seq
<<
";"
<<
"rtptime="
<<
(
int
)
(
track
->
_time_stamp
*
(
track
->
_samplerate
/
1000
))
<<
","
;
}
...
...
@@ -1068,16 +1064,16 @@ int RtspSession::getTrackIndexByTrackType(TrackType type) {
throw
SockException
(
Err_shutdown
,
StrPrinter
<<
"no such track with type:"
<<
(
int
)
type
);
}
int
RtspSession
::
getTrackIndexByControl
Suffix
(
const
string
&
controlSuffix
)
{
int
RtspSession
::
getTrackIndexByControl
Url
(
const
string
&
control_url
)
{
for
(
unsigned
int
i
=
0
;
i
<
_sdp_track
.
size
();
i
++
)
{
if
(
control
Suffix
==
_sdp_track
[
i
]
->
_control_surffix
)
{
if
(
control
_url
==
_sdp_track
[
i
]
->
getControlUrl
(
_content_base
)
)
{
return
i
;
}
}
if
(
_sdp_track
.
size
()
==
1
){
return
0
;
}
throw
SockException
(
Err_shutdown
,
StrPrinter
<<
"no such track with
suffix:"
<<
controlSuffix
);
throw
SockException
(
Err_shutdown
,
StrPrinter
<<
"no such track with
control url:"
<<
control_url
);
}
int
RtspSession
::
getTrackIndexByInterleaved
(
int
interleaved
){
...
...
src/Rtsp/RtspSession.h
查看文件 @
a19f6767
...
...
@@ -132,7 +132,7 @@ private:
void
send_NotAcceptable
();
//获取track下标
int
getTrackIndexByTrackType
(
TrackType
type
);
int
getTrackIndexByControl
Suffix
(
const
string
&
control_suffix
);
int
getTrackIndexByControl
Url
(
const
string
&
control_url
);
int
getTrackIndexByInterleaved
(
int
interleaved
);
//一般用于接收udp打洞包,也用于rtsp推流
void
onRcvPeerUdpData
(
int
interleaved
,
const
Buffer
::
Ptr
&
buf
,
const
struct
sockaddr
&
addr
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论