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
29410687
Commit
29410687
authored
Dec 27, 2020
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtsp客户端代码
parent
bc125e65
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
43 行增加
和
30 行删除
+43
-30
src/Common/Parser.cpp
+7
-3
src/Rtsp/RtpReceiver.cpp
+5
-2
src/Rtsp/RtpReceiver.h
+5
-4
src/Rtsp/RtspPlayer.cpp
+26
-21
没有找到文件。
src/Common/Parser.cpp
查看文件 @
29410687
...
@@ -137,9 +137,13 @@ StrCaseMap Parser::parseArgs(const string &str, const char *pair_delim, const ch
...
@@ -137,9 +137,13 @@ StrCaseMap Parser::parseArgs(const string &str, const char *pair_delim, const ch
StrCaseMap
ret
;
StrCaseMap
ret
;
auto
arg_vec
=
split
(
str
,
pair_delim
);
auto
arg_vec
=
split
(
str
,
pair_delim
);
for
(
string
&
key_val
:
arg_vec
)
{
for
(
string
&
key_val
:
arg_vec
)
{
auto
key
=
FindField
(
key_val
.
data
(),
NULL
,
key_delim
);
auto
key
=
trim
(
FindField
(
key_val
.
data
(),
NULL
,
key_delim
));
auto
val
=
FindField
(
key_val
.
data
(),
key_delim
,
NULL
);
if
(
!
key
.
empty
())
{
ret
.
emplace_force
(
trim
(
key
),
trim
(
val
));
auto
val
=
trim
(
FindField
(
key_val
.
data
(),
key_delim
,
NULL
));
ret
.
emplace_force
(
key
,
val
);
}
else
{
ret
.
emplace_force
(
key_val
,
""
);
}
}
}
return
ret
;
return
ret
;
}
}
...
...
src/Rtsp/RtpReceiver.cpp
查看文件 @
29410687
...
@@ -152,13 +152,16 @@ void RtpReceiver::setPoolSize(int size) {
...
@@ -152,13 +152,16 @@ void RtpReceiver::setPoolSize(int size) {
_rtp_pool
.
setSize
(
size
);
_rtp_pool
.
setSize
(
size
);
}
}
int
RtpReceiver
::
getJitterSize
(
int
track_index
){
int
RtpReceiver
::
getJitterSize
(
int
track_index
)
const
{
return
_rtp_sortor
[
track_index
].
getJitterSize
();
return
_rtp_sortor
[
track_index
].
getJitterSize
();
}
}
int
RtpReceiver
::
getCycleCount
(
int
track_index
){
int
RtpReceiver
::
getCycleCount
(
int
track_index
)
const
{
return
_rtp_sortor
[
track_index
].
getCycleCount
();
return
_rtp_sortor
[
track_index
].
getCycleCount
();
}
}
uint32_t
RtpReceiver
::
getSSRC
(
int
track_index
)
const
{
return
_ssrc
[
track_index
];
}
}
//namespace mediakit
}
//namespace mediakit
src/Rtsp/RtpReceiver.h
查看文件 @
29410687
...
@@ -44,14 +44,14 @@ public:
...
@@ -44,14 +44,14 @@ public:
/**
/**
* 获取排序缓存长度
* 获取排序缓存长度
*/
*/
int
getJitterSize
()
{
int
getJitterSize
()
const
{
return
_rtp_sort_cache_map
.
size
();
return
_rtp_sort_cache_map
.
size
();
}
}
/**
/**
* 获取seq回环次数
* 获取seq回环次数
*/
*/
int
getCycleCount
()
{
int
getCycleCount
()
const
{
return
_seq_cycle_count
;
return
_seq_cycle_count
;
}
}
...
@@ -184,8 +184,9 @@ protected:
...
@@ -184,8 +184,9 @@ protected:
void
clear
();
void
clear
();
void
setPoolSize
(
int
size
);
void
setPoolSize
(
int
size
);
int
getJitterSize
(
int
track_index
);
int
getJitterSize
(
int
track_index
)
const
;
int
getCycleCount
(
int
track_index
);
int
getCycleCount
(
int
track_index
)
const
;
uint32_t
getSSRC
(
int
track_index
)
const
;
private
:
private
:
uint32_t
_ssrc
[
2
]
=
{
0
,
0
};
uint32_t
_ssrc
[
2
]
=
{
0
,
0
};
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
29410687
...
@@ -252,40 +252,43 @@ void RtspPlayer::sendSetup(unsigned int track_idx) {
...
@@ -252,40 +252,43 @@ void RtspPlayer::sendSetup(unsigned int track_idx) {
void
RtspPlayer
::
handleResSETUP
(
const
Parser
&
parser
,
unsigned
int
track_idx
)
{
void
RtspPlayer
::
handleResSETUP
(
const
Parser
&
parser
,
unsigned
int
track_idx
)
{
if
(
parser
.
Url
()
!=
"200"
)
{
if
(
parser
.
Url
()
!=
"200"
)
{
throw
std
::
runtime_error
(
throw
std
::
runtime_error
(
StrPrinter
<<
"SETUP:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
);
StrPrinter
<<
"SETUP:"
<<
parser
.
Url
()
<<
" "
<<
parser
.
Tail
()
<<
endl
);
}
}
if
(
track_idx
==
0
)
{
if
(
track_idx
==
0
)
{
_session_id
=
parser
[
"Session"
];
_session_id
=
parser
[
"Session"
];
_session_id
.
append
(
";"
);
_session_id
=
FindField
(
_session_id
.
data
(),
nullptr
,
";"
);
}
}
auto
strTransport
=
parser
[
"Transport"
];
auto
strTransport
=
parser
[
"Transport"
];
if
(
strTransport
.
find
(
"TCP"
)
!=
string
::
npos
||
strTransport
.
find
(
"interleaved"
)
!=
string
::
npos
)
{
if
(
strTransport
.
find
(
"TCP"
)
!=
string
::
npos
||
strTransport
.
find
(
"interleaved"
)
!=
string
::
npos
)
{
_rtp_type
=
Rtsp
::
RTP_TCP
;
_rtp_type
=
Rtsp
::
RTP_TCP
;
}
else
if
(
strTransport
.
find
(
"multicast"
)
!=
string
::
npos
)
{
}
else
if
(
strTransport
.
find
(
"multicast"
)
!=
string
::
npos
)
{
_rtp_type
=
Rtsp
::
RTP_MULTICAST
;
_rtp_type
=
Rtsp
::
RTP_MULTICAST
;
}
else
{
}
else
{
_rtp_type
=
Rtsp
::
RTP_UDP
;
_rtp_type
=
Rtsp
::
RTP_UDP
;
}
}
auto
transport_map
=
Parser
::
parseArgs
(
strTransport
,
";"
,
"="
);
RtspSplitter
::
enableRecvRtp
(
_rtp_type
==
Rtsp
::
RTP_TCP
);
RtspSplitter
::
enableRecvRtp
(
_rtp_type
==
Rtsp
::
RTP_TCP
);
string
ssrc
=
transport_map
[
"ssrc"
];
if
(
!
ssrc
.
empty
()){
sscanf
(
ssrc
.
data
(),
"%x"
,
&
_sdp_track
[
track_idx
]
->
_ssrc
);
}
else
{
_sdp_track
[
track_idx
]
->
_ssrc
=
0
;
}
if
(
_rtp_type
==
Rtsp
::
RTP_TCP
)
{
if
(
_rtp_type
==
Rtsp
::
RTP_TCP
)
{
string
interleaved
=
FindField
(
FindField
((
strTransport
+
";"
).
data
(),
"interleaved="
,
";"
).
data
(),
NULL
,
"-"
)
;
int
interleaved_rtp
,
interleaved_rtcp
;
_sdp_track
[
track_idx
]
->
_interleaved
=
atoi
(
interleaved
.
data
()
);
sscanf
(
transport_map
[
"interleaved"
].
data
(),
"%d-%d"
,
&
interleaved_rtp
,
&
interleaved_rtcp
);
}
else
{
_sdp_track
[
track_idx
]
->
_interleaved
=
interleaved_rtp
;
const
char
*
strPos
=
(
_rtp_type
==
Rtsp
::
RTP_MULTICAST
?
"port="
:
"server_port="
)
;
}
else
{
auto
port_str
=
FindField
((
strTransport
+
";"
).
data
(),
strPos
,
";"
)
;
auto
port_str
=
transport_map
[(
_rtp_type
==
Rtsp
::
RTP_MULTICAST
?
"port"
:
"server_port"
)]
;
uint16_t
rtp_port
=
atoi
(
FindField
(
port_str
.
data
(),
NULL
,
"-"
).
data
())
;
int
rtp_port
,
rtcp_port
;
uint16_t
rtcp_port
=
atoi
(
FindField
(
port_str
.
data
(),
"-"
,
NULL
).
data
()
);
sscanf
(
port_str
.
data
(),
"%d-%d"
,
&
rtp_port
,
&
rtcp_port
);
auto
&
pRtpSockRef
=
_rtp_sock
[
track_idx
];
auto
&
pRtpSockRef
=
_rtp_sock
[
track_idx
];
auto
&
pRtcpSockRef
=
_rtcp_sock
[
track_idx
];
auto
&
pRtcpSockRef
=
_rtcp_sock
[
track_idx
];
if
(
_rtp_type
==
Rtsp
::
RTP_MULTICAST
)
{
if
(
_rtp_type
==
Rtsp
::
RTP_MULTICAST
)
{
//udp组播
//udp组播
auto
multiAddr
=
FindField
((
strTransport
+
";"
).
data
(),
"destination="
,
";"
)
;
auto
multiAddr
=
transport_map
[
"destination"
]
;
pRtpSockRef
=
createSocket
();
pRtpSockRef
=
createSocket
();
if
(
!
pRtpSockRef
->
bindUdpSock
(
rtp_port
,
multiAddr
.
data
()))
{
if
(
!
pRtpSockRef
->
bindUdpSock
(
rtp_port
,
multiAddr
.
data
()))
{
pRtpSockRef
.
reset
();
pRtpSockRef
.
reset
();
...
@@ -383,7 +386,7 @@ void RtspPlayer::sendKeepAlive(){
...
@@ -383,7 +386,7 @@ void RtspPlayer::sendKeepAlive(){
_on_response
=
[
this
](
const
Parser
&
parser
){};
_on_response
=
[
this
](
const
Parser
&
parser
){};
if
(
_supported_cmd
.
find
(
"GET_PARAMETER"
)
!=
_supported_cmd
.
end
()){
if
(
_supported_cmd
.
find
(
"GET_PARAMETER"
)
!=
_supported_cmd
.
end
()){
//支持GET_PARAMETER,用此命令保活
//支持GET_PARAMETER,用此命令保活
sendRtspRequest
(
"GET_PARAMETER"
,
_
play_url
);
sendRtspRequest
(
"GET_PARAMETER"
,
_
content_base
);
}
else
{
}
else
{
//不支持GET_PARAMETER,用OPTIONS命令保活
//不支持GET_PARAMETER,用OPTIONS命令保活
sendRtspRequest
(
"OPTIONS"
,
_play_url
);
sendRtspRequest
(
"OPTIONS"
,
_play_url
);
...
@@ -557,11 +560,13 @@ void RtspPlayer::sendReceiverReport(bool over_tcp, int track_idx){
...
@@ -557,11 +560,13 @@ void RtspPlayer::sendReceiverReport(bool over_tcp, int track_idx){
pui8Rtcp_RR
[
2
]
=
0x00
;
pui8Rtcp_RR
[
2
]
=
0x00
;
pui8Rtcp_RR
[
3
]
=
0x07
;
/* length in words - 1 */
pui8Rtcp_RR
[
3
]
=
0x07
;
/* length in words - 1 */
uint32_t
ssrc
=
htonl
(
track
->
_ssrc
+
1
);
auto
track_ssrc
=
track
->
_ssrc
?
track
->
_ssrc
:
getSSRC
(
track_idx
);
// our own SSRC: we use the server's SSRC + 1 to avoid conflicts
// our own SSRC: we use the server's SSRC + 1 to avoid conflicts
uint32_t
ssrc
=
htonl
(
track_ssrc
+
1
);
memcpy
(
&
pui8Rtcp_RR
[
4
],
&
ssrc
,
4
);
memcpy
(
&
pui8Rtcp_RR
[
4
],
&
ssrc
,
4
);
ssrc
=
htonl
(
track
->
_ssrc
);
// server SSRC
// server SSRC
ssrc
=
htonl
(
track_ssrc
);
memcpy
(
&
pui8Rtcp_RR
[
8
],
&
ssrc
,
4
);
memcpy
(
&
pui8Rtcp_RR
[
8
],
&
ssrc
,
4
);
//FIXME: 8 bits of fraction, 24 bits of total packets lost
//FIXME: 8 bits of fraction, 24 bits of total packets lost
...
@@ -579,7 +584,7 @@ void RtspPlayer::sendReceiverReport(bool over_tcp, int track_idx){
...
@@ -579,7 +584,7 @@ void RtspPlayer::sendReceiverReport(bool over_tcp, int track_idx){
uint32_t
jitter
=
htonl
(
getJitterSize
(
track_idx
));
uint32_t
jitter
=
htonl
(
getJitterSize
(
track_idx
));
//FIXME: jitter
//FIXME: jitter
memcpy
(
pui8Rtcp_RR
+
20
,
&
jitter
,
4
);
memcpy
(
pui8Rtcp_RR
+
20
,
&
jitter
,
4
);
/* last SR timestamp */
/* last SR timestamp */
memcpy
(
pui8Rtcp_RR
+
24
,
&
counter
.
lastTimeStamp
,
4
);
memcpy
(
pui8Rtcp_RR
+
24
,
&
counter
.
lastTimeStamp
,
4
);
uint32_t
msInc
=
htonl
(
ntohl
(
counter
.
timeStamp
)
-
ntohl
(
counter
.
lastTimeStamp
));
uint32_t
msInc
=
htonl
(
ntohl
(
counter
.
timeStamp
)
-
ntohl
(
counter
.
lastTimeStamp
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论