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 {
namespace
Player
{
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
)
{
string
prefix
=
FindField
(
strUrl
,
NULL
,
"://"
);
...
...
src/Player/PlayerBase.h
查看文件 @
bca084d0
...
...
@@ -51,7 +51,18 @@ public:
RTP_MULTICAST
=
2
,
}
eRtpType
;
static
Ptr
createPlayer
(
const
char
*
strUrl
);
//指定网卡ip
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
(){};
virtual
~
PlayerBase
(){};
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
bca084d0
差异被折叠。
点击展开。
src/Rtsp/RtspPlayer.h
查看文件 @
bca084d0
...
...
@@ -54,9 +54,6 @@ namespace Rtsp {
class
RtspPlayer
:
public
PlayerBase
,
public
TcpClient
{
public
:
typedef
std
::
shared_ptr
<
RtspPlayer
>
Ptr
;
//设置rtp传输类型,可选项有0(tcp,默认)、1(udp)、2(组播)
//设置方法:player[RtspPlayer::kRtpType] = 0/1/2;
static
const
char
kRtpType
[];
RtspPlayer
();
virtual
~
RtspPlayer
(
void
);
...
...
@@ -71,79 +68,38 @@ protected:
float
getProgressTime
()
const
;
void
seekToTime
(
float
fTime
);
private
:
void
_onShutdown
(
const
SockException
&
ex
)
{
WarnL
<<
ex
.
getErrCode
()
<<
" "
<<
ex
.
what
();
m_pPlayTimer
.
reset
();
m_pRtpTimer
.
reset
();
m_pBeatTimer
.
reset
();
onShutdown
(
ex
);
}
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
onShutdown_l
(
const
SockException
&
ex
);
void
onRecvRTP_l
(
const
RtpPacket
::
Ptr
&
pRtppt
,
int
iTrackidx
);
void
onRecvRTP_l
(
const
RtpPacket
::
Ptr
&
pRtppt
,
const
RtspTrack
&
track
);
void
onPlayResult_l
(
const
SockException
&
ex
);
int
getTrackIndex
(
const
string
&
controlSuffix
)
const
;
int
getTrackIndex
(
int
iTrackId
)
const
;
void
play
(
const
char
*
strUrl
,
const
char
*
strUser
,
const
char
*
strPwd
,
eRtpType
eType
);
void
onConnect
(
const
SockException
&
err
)
override
;
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
;
void
onErr
(
const
SockException
&
ex
)
override
;
void
HandleResSETUP
(
const
Parser
&
parser
,
unsigned
int
uiTrackIndex
);
void
HandleResDESCRIBE
(
const
Parser
&
parser
);
void
HandleResPAUSE
(
const
Parser
&
parser
,
bool
bPause
);
void
handleResSETUP
(
const
Parser
&
parser
,
unsigned
int
uiTrackIndex
);
void
handleResDESCRIBE
(
const
Parser
&
parser
);
bool
handleAuthenticationFailure
(
const
string
&
wwwAuthenticateParamsStr
);
void
handleResPAUSE
(
const
Parser
&
parser
,
bool
bPause
);
//发数据给服务器
inline
int
write
(
const
char
*
strMsg
,
...);
inline
int
onProcess
(
const
char
*
strBuf
);
int
onProcess
(
const
char
*
strBuf
);
//生成rtp包结构体
inline
void
splitRtp
(
unsigned
char
*
pucData
,
unsigned
int
uiLen
);
//发送SETUP命令
inline
void
sendSetup
(
unsigned
int
uiTrackIndex
);
inline
void
sendPause
(
bool
bPause
,
float
fTime
);
void
splitRtp
(
unsigned
char
*
pucData
,
unsigned
int
uiLen
);
//处理一个rtp包
inline
bool
HandleOneRtp
(
int
iTrackidx
,
unsigned
char
*
ucData
,
unsigned
int
uiLen
);
bool
sendOptions
();
inline
void
_onRecvRTP
(
const
RtpPacket
::
Ptr
&
pRtppt
,
int
iTrackidx
);
inline
int
getTrackIndex
(
const
string
&
controlSuffix
)
const
{
for
(
unsigned
int
i
=
0
;
i
<
m_uiTrackCnt
;
i
++
)
{
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
;
}
bool
handleOneRtp
(
int
iTrackidx
,
unsigned
char
*
ucData
,
unsigned
int
uiLen
);
//发送SETUP命令
bool
sendSetup
(
unsigned
int
uiTrackIndex
);
bool
sendPause
(
bool
bPause
,
float
fTime
);
bool
sendOptions
();
bool
sendDescribe
();
bool
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
());
private
:
string
m_strUrl
;
unsigned
int
m_uiTrackCnt
=
0
;
RtspTrack
m_aTrackInfo
[
2
];
...
...
@@ -158,7 +114,6 @@ private:
string
m_strSession
;
unsigned
int
m_uiCseq
=
1
;
uint32_t
m_aui32SsrcErrorCnt
[
2
]
=
{
0
,
0
};
string
m_strAuthorization
;
string
m_strContentBase
;
eRtpType
m_eType
=
RTP_TCP
;
/* RTP包排序所用参数 */
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
bca084d0
...
...
@@ -282,7 +282,7 @@ void RtspSession::onAuthFailed(const weak_ptr<RtspSession> &weakSelf,const strin
"CSeq: %d
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"%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
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
realm
.
data
(),
strongSelf
->
m_strNonce
.
data
());
...
...
@@ -293,7 +293,7 @@ void RtspSession::onAuthFailed(const weak_ptr<RtspSession> &weakSelf,const strin
"CSeq: %d
\r\n
"
"Server: %s-%0.2f(build in %s)
\r\n
"
"%s"
"WWW-Authenticate:Basic realm=
\"
%s
\"\r\n\r\n
"
,
"WWW-Authenticate:
Basic realm=
\"
%s
\"\r\n\r\n
"
,
strongSelf
->
m_iCseq
,
SERVER_NAME
,
RTSP_VERSION
,
RTSP_BUILDTIME
,
dateHeader
().
data
(),
realm
.
data
());
...
...
tests/H264Decoder.h
查看文件 @
bca084d0
...
...
@@ -60,9 +60,9 @@ public:
if
(
!
m_pContext
)
{
throw
std
::
runtime_error
(
"创建解码器失败"
);
}
if
(
pCodec
->
capabilities
&
CODEC_CAP_TRUNCATED
)
{
if
(
pCodec
->
capabilities
&
AV_
CODEC_CAP_TRUNCATED
)
{
/* 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
){
throw
std
::
runtime_error
(
"打开编码器失败"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论