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
bca084d0
Commit
bca084d0
authored
Jul 02, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtsp播放器代码,支持md5认证
parent
58b58418
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
41 行增加
和
70 行删除
+41
-70
src/Player/PlayerBase.cpp
+5
-0
src/Player/PlayerBase.h
+11
-0
src/Rtsp/RtspPlayer.cpp
+0
-0
src/Rtsp/RtspPlayer.h
+21
-66
src/Rtsp/RtspSession.cpp
+2
-2
tests/H264Decoder.h
+2
-2
没有找到文件。
src/Player/PlayerBase.cpp
查看文件 @
bca084d0
...
@@ -38,6 +38,11 @@ namespace ZL {
...
@@ -38,6 +38,11 @@ namespace ZL {
namespace
Player
{
namespace
Player
{
const
char
PlayerBase
::
kNetAdapter
[]
=
"net_adapter"
;
const
char
PlayerBase
::
kNetAdapter
[]
=
"net_adapter"
;
const
char
PlayerBase
::
kRtpType
[]
=
"rtp_type"
;
const
char
PlayerBase
::
kRtspUser
[]
=
"rtsp_user"
;
const
char
PlayerBase
::
kRtspPwd
[]
=
"rtsp_pwd"
;
const
char
PlayerBase
::
kRtspPwdIsMD5
[]
=
"rtsp_pwd_md5"
;
PlayerBase
::
Ptr
PlayerBase
::
createPlayer
(
const
char
*
strUrl
)
{
PlayerBase
::
Ptr
PlayerBase
::
createPlayer
(
const
char
*
strUrl
)
{
string
prefix
=
FindField
(
strUrl
,
NULL
,
"://"
);
string
prefix
=
FindField
(
strUrl
,
NULL
,
"://"
);
...
...
src/Player/PlayerBase.h
查看文件 @
bca084d0
...
@@ -51,7 +51,18 @@ public:
...
@@ -51,7 +51,18 @@ public:
RTP_MULTICAST
=
2
,
RTP_MULTICAST
=
2
,
}
eRtpType
;
}
eRtpType
;
static
Ptr
createPlayer
(
const
char
*
strUrl
);
static
Ptr
createPlayer
(
const
char
*
strUrl
);
//指定网卡ip
static
const
char
kNetAdapter
[];
static
const
char
kNetAdapter
[];
//设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
//设置方法:player[PlayerBase::kRtpType] = 0/1/2;
static
const
char
kRtpType
[];
//rtsp认证用户名
static
const
char
kRtspUser
[];
//rtsp认证用用户密码,可以是明文也可以是md5,md5密码生成方式 md5(username:realm:password)
static
const
char
kRtspPwd
[];
//rtsp认证用用户密码是否为md5
static
const
char
kRtspPwdIsMD5
[];
PlayerBase
(){};
PlayerBase
(){};
virtual
~
PlayerBase
(){};
virtual
~
PlayerBase
(){};
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
bca084d0
差异被折叠。
点击展开。
src/Rtsp/RtspPlayer.h
查看文件 @
bca084d0
...
@@ -54,9 +54,6 @@ namespace Rtsp {
...
@@ -54,9 +54,6 @@ namespace Rtsp {
class
RtspPlayer
:
public
PlayerBase
,
public
TcpClient
{
class
RtspPlayer
:
public
PlayerBase
,
public
TcpClient
{
public
:
public
:
typedef
std
::
shared_ptr
<
RtspPlayer
>
Ptr
;
typedef
std
::
shared_ptr
<
RtspPlayer
>
Ptr
;
//设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
//设置方法:player[RtspPlayer::kRtpType] = 0/1/2;
static
const
char
kRtpType
[];
RtspPlayer
();
RtspPlayer
();
virtual
~
RtspPlayer
(
void
);
virtual
~
RtspPlayer
(
void
);
...
@@ -71,79 +68,38 @@ protected:
...
@@ -71,79 +68,38 @@ protected:
float
getProgressTime
()
const
;
float
getProgressTime
()
const
;
void
seekToTime
(
float
fTime
);
void
seekToTime
(
float
fTime
);
private
:
private
:
void
_onShutdown
(
const
SockException
&
ex
)
{
void
onShutdown_l
(
const
SockException
&
ex
);
WarnL
<<
ex
.
getErrCode
()
<<
" "
<<
ex
.
what
();
void
onRecvRTP_l
(
const
RtpPacket
::
Ptr
&
pRtppt
,
int
iTrackidx
);
m_pPlayTimer
.
reset
();
void
onRecvRTP_l
(
const
RtpPacket
::
Ptr
&
pRtppt
,
const
RtspTrack
&
track
);
m_pRtpTimer
.
reset
();
void
onPlayResult_l
(
const
SockException
&
ex
);
m_pBeatTimer
.
reset
();
onShutdown
(
ex
);
int
getTrackIndex
(
const
string
&
controlSuffix
)
const
;
}
int
getTrackIndex
(
int
iTrackId
)
const
;
void
_onRecvRTP
(
const
RtpPacket
::
Ptr
&
pRtppt
,
const
RtspTrack
&
track
)
{
m_rtpTicker
.
resetTime
();
onRecvRTP
(
pRtppt
,
track
);
}
void
_onPlayResult
(
const
SockException
&
ex
)
{
WarnL
<<
ex
.
getErrCode
()
<<
" "
<<
ex
.
what
();
m_pPlayTimer
.
reset
();
m_pRtpTimer
.
reset
();
if
(
!
ex
)
{
m_rtpTicker
.
resetTime
();
weak_ptr
<
RtspPlayer
>
weakSelf
=
dynamic_pointer_cast
<
RtspPlayer
>
(
shared_from_this
());
m_pRtpTimer
.
reset
(
new
Timer
(
5
,
[
weakSelf
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
false
;
}
if
(
strongSelf
->
m_rtpTicker
.
elapsedTime
()
>
10000
)
{
//recv rtp timeout!
strongSelf
->
_onShutdown
(
SockException
(
Err_timeout
,
"recv rtp timeout"
));
strongSelf
->
teardown
();
return
false
;
}
return
true
;
}));
}
onPlayResult
(
ex
);
}
void
play
(
const
char
*
strUrl
,
const
char
*
strUser
,
const
char
*
strPwd
,
eRtpType
eType
);
void
play
(
const
char
*
strUrl
,
const
char
*
strUser
,
const
char
*
strPwd
,
eRtpType
eType
);
void
onConnect
(
const
SockException
&
err
)
override
;
void
onConnect
(
const
SockException
&
err
)
override
;
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
;
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
;
void
onErr
(
const
SockException
&
ex
)
override
;
void
onErr
(
const
SockException
&
ex
)
override
;
void
HandleResSETUP
(
const
Parser
&
parser
,
unsigned
int
uiTrackIndex
);
void
handleResSETUP
(
const
Parser
&
parser
,
unsigned
int
uiTrackIndex
);
void
HandleResDESCRIBE
(
const
Parser
&
parser
);
void
handleResDESCRIBE
(
const
Parser
&
parser
);
void
HandleResPAUSE
(
const
Parser
&
parser
,
bool
bPause
);
bool
handleAuthenticationFailure
(
const
string
&
wwwAuthenticateParamsStr
);
void
handleResPAUSE
(
const
Parser
&
parser
,
bool
bPause
);
//发数据给服务器
//发数据给服务器
inline
int
write
(
const
char
*
strMsg
,
...);
int
onProcess
(
const
char
*
strBuf
);
inline
int
onProcess
(
const
char
*
strBuf
);
//生成rtp包结构体
//生成rtp包结构体
inline
void
splitRtp
(
unsigned
char
*
pucData
,
unsigned
int
uiLen
);
void
splitRtp
(
unsigned
char
*
pucData
,
unsigned
int
uiLen
);
//处理一个rtp包
bool
handleOneRtp
(
int
iTrackidx
,
unsigned
char
*
ucData
,
unsigned
int
uiLen
);
//发送SETUP命令
//发送SETUP命令
inline
void
sendSetup
(
unsigned
int
uiTrackIndex
);
bool
sendSetup
(
unsigned
int
uiTrackIndex
);
inline
void
sendPause
(
bool
bPause
,
float
fTime
);
bool
sendPause
(
bool
bPause
,
float
fTime
);
//处理一个rtp包
inline
bool
HandleOneRtp
(
int
iTrackidx
,
unsigned
char
*
ucData
,
unsigned
int
uiLen
);
bool
sendOptions
();
bool
sendOptions
();
inline
void
_onRecvRTP
(
const
RtpPacket
::
Ptr
&
pRtppt
,
int
iTrackidx
);
bool
sendDescribe
();
inline
int
getTrackIndex
(
const
string
&
controlSuffix
)
const
{
bool
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
());
for
(
unsigned
int
i
=
0
;
i
<
m_uiTrackCnt
;
i
++
)
{
private
:
if
(
m_aTrackInfo
[
i
].
controlSuffix
==
controlSuffix
)
{
return
i
;
}
}
return
-
1
;
}
inline
int
getTrackIndex
(
int
iTrackId
)
const
{
for
(
unsigned
int
i
=
0
;
i
<
m_uiTrackCnt
;
i
++
)
{
if
(
m_aTrackInfo
[
i
].
trackId
==
iTrackId
)
{
return
i
;
}
}
return
-
1
;
}
string
m_strUrl
;
string
m_strUrl
;
unsigned
int
m_uiTrackCnt
=
0
;
unsigned
int
m_uiTrackCnt
=
0
;
RtspTrack
m_aTrackInfo
[
2
];
RtspTrack
m_aTrackInfo
[
2
];
...
@@ -158,7 +114,6 @@ private:
...
@@ -158,7 +114,6 @@ private:
string
m_strSession
;
string
m_strSession
;
unsigned
int
m_uiCseq
=
1
;
unsigned
int
m_uiCseq
=
1
;
uint32_t
m_aui32SsrcErrorCnt
[
2
]
=
{
0
,
0
};
uint32_t
m_aui32SsrcErrorCnt
[
2
]
=
{
0
,
0
};
string
m_strAuthorization
;
string
m_strContentBase
;
string
m_strContentBase
;
eRtpType
m_eType
=
RTP_TCP
;
eRtpType
m_eType
=
RTP_TCP
;
/* RTP包排序所用参数 */
/* RTP包排序所用参数 */
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
bca084d0
...
@@ -282,7 +282,7 @@ void RtspSession::onAuthFailed(const weak_ptr<RtspSession> &weakSelf,const strin
...
@@ -282,7 +282,7 @@ void RtspSession::onAuthFailed(const weak_ptr<RtspSession> &weakSelf,const strin
"CSeq: %d
\r\n
"
"CSeq: %d
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"%s"
"%s"
"WWW-Authenticate:Digest realm=
\"
%s
\"
,nonce=
\"
%s
\"\r\n\r\n
"
,
"WWW-Authenticate:
Digest realm=
\"
%s
\"
,nonce=
\"
%s
\"\r\n\r\n
"
,
strongSelf
->
m_iCseq
,
SERVER_NAME
,
strongSelf
->
m_iCseq
,
SERVER_NAME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
realm
.
data
(),
strongSelf
->
m_strNonce
.
data
());
dateHeader
().
data
(),
realm
.
data
(),
strongSelf
->
m_strNonce
.
data
());
...
@@ -293,7 +293,7 @@ void RtspSession::onAuthFailed(const weak_ptr<RtspSession> &weakSelf,const strin
...
@@ -293,7 +293,7 @@ void RtspSession::onAuthFailed(const weak_ptr<RtspSession> &weakSelf,const strin
"CSeq: %d
\r\n
"
"CSeq: %d
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"%s"
"%s"
"WWW-Authenticate:Basic realm=
\"
%s
\"\r\n\r\n
"
,
"WWW-Authenticate:
Basic realm=
\"
%s
\"\r\n\r\n
"
,
strongSelf
->
m_iCseq
,
SERVER_NAME
,
strongSelf
->
m_iCseq
,
SERVER_NAME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
realm
.
data
());
dateHeader
().
data
(),
realm
.
data
());
...
...
tests/H264Decoder.h
查看文件 @
bca084d0
...
@@ -60,9 +60,9 @@ public:
...
@@ -60,9 +60,9 @@ public:
if
(
!
m_pContext
)
{
if
(
!
m_pContext
)
{
throw
std
::
runtime_error
(
"创建解码器失败"
);
throw
std
::
runtime_error
(
"创建解码器失败"
);
}
}
if
(
pCodec
->
capabilities
&
CODEC_CAP_TRUNCATED
)
{
if
(
pCodec
->
capabilities
&
AV_
CODEC_CAP_TRUNCATED
)
{
/* we do not send complete frames */
/* we do not send complete frames */
m_pContext
->
flags
|=
CODEC_FLAG_TRUNCATED
;
m_pContext
->
flags
|=
AV_
CODEC_FLAG_TRUNCATED
;
}
}
if
(
avcodec_open2
(
m_pContext
.
get
(),
pCodec
,
NULL
)
<
0
){
if
(
avcodec_open2
(
m_pContext
.
get
(),
pCodec
,
NULL
)
<
0
){
throw
std
::
runtime_error
(
"打开编码器失败"
);
throw
std
::
runtime_error
(
"打开编码器失败"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论