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
212a761e
Commit
212a761e
authored
Dec 17, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtsp相关代码
parent
0c5cd624
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
18 行删除
+23
-18
src/Rtsp/RtspPlayer.cpp
+21
-18
src/Rtsp/RtspPlayer.h
+2
-0
没有找到文件。
src/Rtsp/RtspPlayer.cpp
查看文件 @
212a761e
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include <cmath>
#include <cmath>
#include <stdarg.h>
#include <stdarg.h>
#include <algorithm>
#include <algorithm>
#include <iomanip>
#include "Common/config.h"
#include "Common/config.h"
#include "RtspPlayer.h"
#include "RtspPlayer.h"
...
@@ -234,15 +235,11 @@ bool RtspPlayer::sendSetup(unsigned int trackIndex) {
...
@@ -234,15 +235,11 @@ bool RtspPlayer::sendSetup(unsigned int trackIndex) {
auto
baseUrl
=
_strContentBase
+
"/"
+
track
->
_control_surffix
;
auto
baseUrl
=
_strContentBase
+
"/"
+
track
->
_control_surffix
;
switch
(
_eType
)
{
switch
(
_eType
)
{
case
RTP_TCP
:
{
case
RTP_TCP
:
{
StrCaseMap
header
;
return
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"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
;
break
;
case
RTP_MULTICAST
:
{
case
RTP_MULTICAST
:
{
StrCaseMap
header
;
return
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"Transport"
,
"Transport: RTP/AVP;multicast"
});
header
[
"Transport"
]
=
"Transport: RTP/AVP;multicast"
;
return
sendRtspRequest
(
"SETUP"
,
baseUrl
,
header
);
}
}
break
;
break
;
case
RTP_UDP
:
{
case
RTP_UDP
:
{
...
@@ -252,9 +249,7 @@ bool RtspPlayer::sendSetup(unsigned int trackIndex) {
...
@@ -252,9 +249,7 @@ bool RtspPlayer::sendSetup(unsigned int trackIndex) {
throw
std
::
runtime_error
(
"open udp sock err"
);
throw
std
::
runtime_error
(
"open udp sock err"
);
}
}
int
port
=
_apUdpSock
[
trackIndex
]
->
get_local_port
();
int
port
=
_apUdpSock
[
trackIndex
]
->
get_local_port
();
StrCaseMap
header
;
return
sendRtspRequest
(
"SETUP"
,
baseUrl
,{
"Transport"
,
StrPrinter
<<
"RTP/AVP;unicast;client_port="
<<
port
<<
"-"
<<
port
+
1
});
header
[
"Transport"
]
=
StrPrinter
<<
"RTP/AVP;unicast;client_port="
<<
port
<<
"-"
<<
port
+
1
;
return
sendRtspRequest
(
"SETUP"
,
baseUrl
,
header
);
}
}
break
;
break
;
default
:
default
:
...
@@ -364,9 +359,7 @@ bool RtspPlayer::sendOptions() {
...
@@ -364,9 +359,7 @@ bool RtspPlayer::sendOptions() {
bool
RtspPlayer
::
sendDescribe
()
{
bool
RtspPlayer
::
sendDescribe
()
{
//发送DESCRIBE命令后处理函数:handleResDESCRIBE
//发送DESCRIBE命令后处理函数:handleResDESCRIBE
_onHandshake
=
std
::
bind
(
&
RtspPlayer
::
handleResDESCRIBE
,
this
,
placeholders
::
_1
);
_onHandshake
=
std
::
bind
(
&
RtspPlayer
::
handleResDESCRIBE
,
this
,
placeholders
::
_1
);
StrCaseMap
header
;
return
sendRtspRequest
(
"DESCRIBE"
,
_strUrl
,{
"Accept"
,
"application/sdp"
});
header
[
"Accept"
]
=
"application/sdp"
;
return
sendRtspRequest
(
"DESCRIBE"
,
_strUrl
,
header
);
}
}
...
@@ -383,12 +376,9 @@ bool RtspPlayer::sendPause(bool bPause,uint32_t seekMS){
...
@@ -383,12 +376,9 @@ bool RtspPlayer::sendPause(bool bPause,uint32_t seekMS){
//开启或暂停rtsp
//开启或暂停rtsp
_onHandshake
=
std
::
bind
(
&
RtspPlayer
::
handleResPAUSE
,
this
,
placeholders
::
_1
,
bPause
);
_onHandshake
=
std
::
bind
(
&
RtspPlayer
::
handleResPAUSE
,
this
,
placeholders
::
_1
,
bPause
);
return
sendRtspRequest
(
bPause
?
"PAUSE"
:
"PLAY"
,
StrCaseMap
header
;
_strContentBase
,
char
buf
[
8
];
{
"Range"
,
StrPrinter
<<
"npt="
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
2
)
<<
seekMS
/
1000.0
<<
"-"
});
sprintf
(
buf
,
"%.2f"
,
seekMS
/
1000.0
);
header
[
"Range"
]
=
StrPrinter
<<
"npt="
<<
buf
<<
"-"
;
return
sendRtspRequest
(
bPause
?
"PAUSE"
:
"PLAY"
,
_strContentBase
,
header
);
}
}
void
RtspPlayer
::
pause
(
bool
bPause
)
{
void
RtspPlayer
::
pause
(
bool
bPause
)
{
sendPause
(
bPause
,
getProgressMilliSecond
());
sendPause
(
bPause
,
getProgressMilliSecond
());
...
@@ -513,6 +503,19 @@ void RtspPlayer::seekToMilliSecond(uint32_t ms) {
...
@@ -513,6 +503,19 @@ void RtspPlayer::seekToMilliSecond(uint32_t ms) {
sendPause
(
false
,
ms
);
sendPause
(
false
,
ms
);
}
}
bool
RtspPlayer
::
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
std
::
initializer_list
<
string
>
&
header
)
{
string
key
;
StrCaseMap
header_map
;
int
i
=
0
;
for
(
auto
&
val
:
header
){
if
(
++
i
%
2
==
0
){
header_map
.
emplace
(
key
,
val
);
}
else
{
key
=
val
;
}
}
return
sendRtspRequest
(
cmd
,
url
,
header_map
);
}
bool
RtspPlayer
::
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header_const
)
{
bool
RtspPlayer
::
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header_const
)
{
auto
header
=
header_const
;
auto
header
=
header_const
;
header
.
emplace
(
"CSeq"
,
StrPrinter
<<
_uiCseq
++
);
header
.
emplace
(
"CSeq"
,
StrPrinter
<<
_uiCseq
++
);
...
...
src/Rtsp/RtspPlayer.h
查看文件 @
212a761e
...
@@ -108,7 +108,9 @@ private:
...
@@ -108,7 +108,9 @@ private:
bool
sendPause
(
bool
bPause
,
uint32_t
ms
);
bool
sendPause
(
bool
bPause
,
uint32_t
ms
);
bool
sendOptions
();
bool
sendOptions
();
bool
sendDescribe
();
bool
sendDescribe
();
bool
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
());
bool
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
());
bool
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
std
::
initializer_list
<
string
>
&
header
);
private
:
private
:
string
_strUrl
;
string
_strUrl
;
SdpAttr
_sdpAttr
;
SdpAttr
_sdpAttr
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论