mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
支持ssl加密的Rtsp服务器
This commit is contained in:
parent
70c3e97f14
commit
84e0e83366
@ -155,11 +155,8 @@ void HttpSession::onRecvContent(const char *data,uint64_t len) {
|
||||
}
|
||||
|
||||
void HttpSession::onRecv(const Buffer::Ptr &pBuf) {
|
||||
onRecv(pBuf->data(),pBuf->size());
|
||||
}
|
||||
void HttpSession::onRecv(const char *data,int size){
|
||||
_ticker.resetTime();
|
||||
input(data,size);
|
||||
input(pBuf->data(),pBuf->size());
|
||||
}
|
||||
|
||||
void HttpSession::onError(const SockException& err) {
|
||||
|
@ -60,8 +60,6 @@ public:
|
||||
|
||||
static string urlDecode(const string &str);
|
||||
protected:
|
||||
//用于HttpsSession调用
|
||||
void onRecv(const char *data,int size);
|
||||
//FlvMuxer override
|
||||
void onWrite(const Buffer::Ptr &data) override ;
|
||||
void onWrite(const char *data,int len) override;
|
||||
|
@ -35,49 +35,41 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpsSession: public HttpSession {
|
||||
template<typename TcpSessionType>
|
||||
class TcpSessionWithSSL: public TcpSessionType {
|
||||
public:
|
||||
HttpsSession(const std::shared_ptr<ThreadPool> &pTh, const Socket::Ptr &pSock):
|
||||
HttpSession(pTh,pSock){
|
||||
TcpSessionWithSSL(const std::shared_ptr<ThreadPool> &pTh, const Socket::Ptr &pSock):
|
||||
TcpSessionType(pTh,pSock){
|
||||
_sslBox.setOnEncData([&](const char *data, uint32_t len){
|
||||
#if defined(__GNUC__) && (__GNUC__ < 5)
|
||||
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){
|
||||
#if defined(__GNUC__) && (__GNUC__ < 5)
|
||||
public_onRecv(data,len);
|
||||
#else//defined(__GNUC__) && (__GNUC__ < 5)
|
||||
HttpSession::onRecv(data,len);
|
||||
#endif//defined(__GNUC__) && (__GNUC__ < 5)
|
||||
});
|
||||
}
|
||||
virtual ~HttpsSession(){
|
||||
virtual ~TcpSessionWithSSL(){
|
||||
//_sslBox.shutdown();
|
||||
}
|
||||
void onRecv(const Buffer::Ptr &pBuf) override{
|
||||
TimeTicker();
|
||||
_sslBox.onRecv(pBuf->data(), pBuf->size());
|
||||
}
|
||||
#if defined(__GNUC__) && (__GNUC__ < 5)
|
||||
|
||||
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){
|
||||
HttpSession::onRecv(data,len);
|
||||
TcpSessionType::onRecv(TcpSessionType::obtainBuffer(data,len));
|
||||
}
|
||||
#endif//defined(__GNUC__) && (__GNUC__ < 5)
|
||||
protected:
|
||||
virtual int send(const Buffer::Ptr &buf) override{
|
||||
TimeTicker();
|
||||
_sslBox.onSend(buf->data(), buf->size());
|
||||
return buf->size();
|
||||
}
|
||||
private:
|
||||
SSL_Box _sslBox;
|
||||
};
|
||||
|
||||
typedef TcpSessionWithSSL<HttpSession> HttpsSession;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "RtspSplitter.h"
|
||||
#include "RtpReceiver.h"
|
||||
#include "RtspToRtmpMediaSource.h"
|
||||
#include "Http/HttpsSession.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
@ -105,6 +106,9 @@ protected:
|
||||
void onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx) override;
|
||||
//MediaSourceEvent override
|
||||
bool close() override ;
|
||||
|
||||
//TcpSession override
|
||||
int send(const Buffer::Ptr &pkt) override;
|
||||
private:
|
||||
bool handleReq_Options(const Parser &parser); //处理options方法
|
||||
bool handleReq_Describe(const Parser &parser); //处理describe方法
|
||||
@ -146,7 +150,6 @@ private:
|
||||
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 StrCaseMap &header = StrCaseMap(), const string &sdp = "",const char *protocol = "RTSP/1.0");
|
||||
int send(const Buffer::Ptr &pkt) override;
|
||||
private:
|
||||
Ticker _ticker;
|
||||
int _iCseq = 0;
|
||||
@ -195,6 +198,11 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* 支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问
|
||||
*/
|
||||
typedef TcpSessionWithSSL<RtspSession> RtspSessionWithSSL;
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
#endif /* SESSION_RTSPSESSION_H_ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
|
||||
@ -235,12 +235,18 @@ int main(int argc,char *argv[]) {
|
||||
shellSrv->start<ShellSession>(shellPort);
|
||||
rtspSrv->start<RtspSession>(rtspPort);//默认554
|
||||
rtmpSrv->start<RtmpSession>(rtmpPort);//默认1935
|
||||
httpSrv->start<HttpSession>(httpPort);//默认80
|
||||
//http服务器,支持websocket
|
||||
httpSrv->start<EchoWebSocketSession>(httpPort);//默认80
|
||||
|
||||
#ifdef ENABLE_OPENSSL
|
||||
//如果支持ssl,还可以开启https服务器
|
||||
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
|
||||
|
||||
NoticeCenter::Instance().addListener(ReloadConfigTag,Broadcast::kBroadcastReloadConfig,[&](BroadcastReloadConfigArgs){
|
||||
|
Loading…
Reference in New Issue
Block a user