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
84e0e833
Commit
84e0e833
authored
Dec 19, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持ssl加密的Rtsp服务器
parent
70c3e97f
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
29 行增加
和
28 行删除
+29
-28
src/Http/HttpSession.cpp
+1
-4
src/Http/HttpSession.h
+0
-2
src/Http/HttpsSession.h
+10
-18
src/Rtsp/RtspSession.h
+9
-1
tests/test_server.cpp
+9
-3
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
84e0e833
...
@@ -155,11 +155,8 @@ void HttpSession::onRecvContent(const char *data,uint64_t len) {
...
@@ -155,11 +155,8 @@ void HttpSession::onRecvContent(const char *data,uint64_t len) {
}
}
void
HttpSession
::
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
{
void
HttpSession
::
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
{
onRecv
(
pBuf
->
data
(),
pBuf
->
size
());
}
void
HttpSession
::
onRecv
(
const
char
*
data
,
int
size
){
_ticker
.
resetTime
();
_ticker
.
resetTime
();
input
(
data
,
size
);
input
(
pBuf
->
data
(),
pBuf
->
size
()
);
}
}
void
HttpSession
::
onError
(
const
SockException
&
err
)
{
void
HttpSession
::
onError
(
const
SockException
&
err
)
{
...
...
src/Http/HttpSession.h
查看文件 @
84e0e833
...
@@ -60,8 +60,6 @@ public:
...
@@ -60,8 +60,6 @@ public:
static
string
urlDecode
(
const
string
&
str
);
static
string
urlDecode
(
const
string
&
str
);
protected
:
protected
:
//用于HttpsSession调用
void
onRecv
(
const
char
*
data
,
int
size
);
//FlvMuxer override
//FlvMuxer override
void
onWrite
(
const
Buffer
::
Ptr
&
data
)
override
;
void
onWrite
(
const
Buffer
::
Ptr
&
data
)
override
;
void
onWrite
(
const
char
*
data
,
int
len
)
override
;
void
onWrite
(
const
char
*
data
,
int
len
)
override
;
...
...
src/Http/HttpsSession.h
查看文件 @
84e0e833
...
@@ -35,49 +35,41 @@ using namespace toolkit;
...
@@ -35,49 +35,41 @@ using namespace toolkit;
namespace
mediakit
{
namespace
mediakit
{
class
HttpsSession
:
public
HttpSession
{
template
<
typename
TcpSessionType
>
class
TcpSessionWithSSL
:
public
TcpSessionType
{
public
:
public
:
HttpsSession
(
const
std
::
shared_ptr
<
ThreadPool
>
&
pTh
,
const
Socket
::
Ptr
&
pSock
)
:
TcpSessionWithSSL
(
const
std
::
shared_ptr
<
ThreadPool
>
&
pTh
,
const
Socket
::
Ptr
&
pSock
)
:
HttpSession
(
pTh
,
pSock
){
TcpSessionType
(
pTh
,
pSock
){
_sslBox
.
setOnEncData
([
&
](
const
char
*
data
,
uint32_t
len
){
_sslBox
.
setOnEncData
([
&
](
const
char
*
data
,
uint32_t
len
){
#if defined(__GNUC__) && (__GNUC__ < 5)
public_send
(
data
,
len
);
public_send
(
data
,
len
);
#else//defined(__GNUC__) && (__GNUC__ < 5)
HttpSession
::
send
(
obtainBuffer
(
data
,
len
));
#endif//defined(__GNUC__) && (__GNUC__ < 5)
});
});
_sslBox
.
setOnDecData
([
&
](
const
char
*
data
,
uint32_t
len
){
_sslBox
.
setOnDecData
([
&
](
const
char
*
data
,
uint32_t
len
){
#if defined(__GNUC__) && (__GNUC__ < 5)
public_onRecv
(
data
,
len
);
public_onRecv
(
data
,
len
);
#else//defined(__GNUC__) && (__GNUC__ < 5)
HttpSession
::
onRecv
(
data
,
len
);
#endif//defined(__GNUC__) && (__GNUC__ < 5)
});
});
}
}
virtual
~
HttpsSession
(){
virtual
~
TcpSessionWithSSL
(){
//_sslBox.shutdown();
//_sslBox.shutdown();
}
}
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
{
void
onRecv
(
const
Buffer
::
Ptr
&
pBuf
)
override
{
TimeTicker
();
_sslBox
.
onRecv
(
pBuf
->
data
(),
pBuf
->
size
());
_sslBox
.
onRecv
(
pBuf
->
data
(),
pBuf
->
size
());
}
}
#if defined(__GNUC__) && (__GNUC__ < 5)
int
public_send
(
const
char
*
data
,
uint32_t
len
){
int
public_send
(
const
char
*
data
,
uint32_t
len
){
return
HttpSession
::
send
(
obtainBuffer
(
data
,
len
));
return
TcpSessionType
::
send
(
TcpSessionType
::
obtainBuffer
(
data
,
len
));
}
}
void
public_onRecv
(
const
char
*
data
,
uint32_t
len
){
void
public_onRecv
(
const
char
*
data
,
uint32_t
len
){
HttpSession
::
onRecv
(
data
,
len
);
TcpSessionType
::
onRecv
(
TcpSessionType
::
obtainBuffer
(
data
,
len
)
);
}
}
#endif//defined(__GNUC__) && (__GNUC__ < 5)
protected
:
protected
:
virtual
int
send
(
const
Buffer
::
Ptr
&
buf
)
override
{
virtual
int
send
(
const
Buffer
::
Ptr
&
buf
)
override
{
TimeTicker
();
_sslBox
.
onSend
(
buf
->
data
(),
buf
->
size
());
_sslBox
.
onSend
(
buf
->
data
(),
buf
->
size
());
return
buf
->
size
();
return
buf
->
size
();
}
}
private
:
SSL_Box
_sslBox
;
SSL_Box
_sslBox
;
};
};
typedef
TcpSessionWithSSL
<
HttpSession
>
HttpsSession
;
/**
/**
...
...
src/Rtsp/RtspSession.h
查看文件 @
84e0e833
...
@@ -41,6 +41,7 @@
...
@@ -41,6 +41,7 @@
#include "RtspSplitter.h"
#include "RtspSplitter.h"
#include "RtpReceiver.h"
#include "RtpReceiver.h"
#include "RtspToRtmpMediaSource.h"
#include "RtspToRtmpMediaSource.h"
#include "Http/HttpsSession.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
toolkit
;
using
namespace
toolkit
;
...
@@ -105,6 +106,9 @@ protected:
...
@@ -105,6 +106,9 @@ protected:
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtppt
,
int
trackidx
)
override
;
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtppt
,
int
trackidx
)
override
;
//MediaSourceEvent override
//MediaSourceEvent override
bool
close
()
override
;
bool
close
()
override
;
//TcpSession override
int
send
(
const
Buffer
::
Ptr
&
pkt
)
override
;
private
:
private
:
bool
handleReq_Options
(
const
Parser
&
parser
);
//处理options方法
bool
handleReq_Options
(
const
Parser
&
parser
);
//处理options方法
bool
handleReq_Describe
(
const
Parser
&
parser
);
//处理describe方法
bool
handleReq_Describe
(
const
Parser
&
parser
);
//处理describe方法
...
@@ -146,7 +150,6 @@ private:
...
@@ -146,7 +150,6 @@ private:
inline
void
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
);
inline
void
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
);
bool
sendRtspResponse
(
const
string
&
res_code
,
const
std
::
initializer_list
<
string
>
&
header
,
const
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
bool
sendRtspResponse
(
const
string
&
res_code
,
const
std
::
initializer_list
<
string
>
&
header
,
const
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
bool
sendRtspResponse
(
const
string
&
res_code
,
const
StrCaseMap
&
header
=
StrCaseMap
(),
const
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
bool
sendRtspResponse
(
const
string
&
res_code
,
const
StrCaseMap
&
header
=
StrCaseMap
(),
const
string
&
sdp
=
""
,
const
char
*
protocol
=
"RTSP/1.0"
);
int
send
(
const
Buffer
::
Ptr
&
pkt
)
override
;
private
:
private
:
Ticker
_ticker
;
Ticker
_ticker
;
int
_iCseq
=
0
;
int
_iCseq
=
0
;
...
@@ -195,6 +198,11 @@ private:
...
@@ -195,6 +198,11 @@ private:
#endif
#endif
};
};
/**
* 支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问
*/
typedef
TcpSessionWithSSL
<
RtspSession
>
RtspSessionWithSSL
;
}
/* namespace mediakit */
}
/* namespace mediakit */
#endif
/* SESSION_RTSPSESSION_H_ */
#endif
/* SESSION_RTSPSESSION_H_ */
tests/test_server.cpp
查看文件 @
84e0e833
/*
/*
* MIT License
* MIT License
*
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
...
@@ -235,12 +235,18 @@ int main(int argc,char *argv[]) {
...
@@ -235,12 +235,18 @@ int main(int argc,char *argv[]) {
shellSrv
->
start
<
ShellSession
>
(
shellPort
);
shellSrv
->
start
<
ShellSession
>
(
shellPort
);
rtspSrv
->
start
<
RtspSession
>
(
rtspPort
);
//默认554
rtspSrv
->
start
<
RtspSession
>
(
rtspPort
);
//默认554
rtmpSrv
->
start
<
RtmpSession
>
(
rtmpPort
);
//默认1935
rtmpSrv
->
start
<
RtmpSession
>
(
rtmpPort
);
//默认1935
httpSrv
->
start
<
HttpSession
>
(
httpPort
);
//默认80
//http服务器,支持websocket
httpSrv
->
start
<
EchoWebSocketSession
>
(
httpPort
);
//默认80
#ifdef ENABLE_OPENSSL
#ifdef ENABLE_OPENSSL
//如果支持ssl,还可以开启https服务器
//如果支持ssl,还可以开启https服务器
TcpServer
::
Ptr
httpsSrv
(
new
TcpServer
());
TcpServer
::
Ptr
httpsSrv
(
new
TcpServer
());
httpsSrv
->
start
<
HttpsSession
>
(
httpsPort
);
//默认443
//https服务器,支持websocket
httpsSrv
->
start
<
SSLEchoWebSocketSession
>
(
httpsPort
);
//默认443
//支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问
TcpServer
::
Ptr
rtspSSLSrv
(
new
TcpServer
());
rtspSSLSrv
->
start
<
RtspSessionWithSSL
>
(
rtspPort
+
1
);
//默认555
#endif //ENABLE_OPENSSL
#endif //ENABLE_OPENSSL
NoticeCenter
::
Instance
().
addListener
(
ReloadConfigTag
,
Broadcast
::
kBroadcastReloadConfig
,[
&
](
BroadcastReloadConfigArgs
){
NoticeCenter
::
Instance
().
addListener
(
ReloadConfigTag
,
Broadcast
::
kBroadcastReloadConfig
,[
&
](
BroadcastReloadConfigArgs
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论