diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index fa253693..7d271f8d 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -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) { diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 59107975..3fbf967b 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -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; diff --git a/src/Http/HttpsSession.h b/src/Http/HttpsSession.h index 70e6c173..b05db6bc 100644 --- a/src/Http/HttpsSession.h +++ b/src/Http/HttpsSession.h @@ -35,49 +35,41 @@ using namespace toolkit; namespace mediakit { -class HttpsSession: public HttpSession { +template +class TcpSessionWithSSL: public TcpSessionType { public: - HttpsSession(const std::shared_ptr &pTh, const Socket::Ptr &pSock): - HttpSession(pTh,pSock){ + TcpSessionWithSSL(const std::shared_ptr &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 HttpsSession; /** diff --git a/src/Rtsp/RtspSession.h b/src/Rtsp/RtspSession.h index 9dd6ecfd..05ba91af 100644 --- a/src/Rtsp/RtspSession.h +++ b/src/Rtsp/RtspSession.h @@ -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 &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 RtspSessionWithSSL; + } /* namespace mediakit */ #endif /* SESSION_RTSPSESSION_H_ */ diff --git a/tests/test_server.cpp b/tests/test_server.cpp index e6106e55..ac780c5e 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -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(shellPort); rtspSrv->start(rtspPort);//默认554 rtmpSrv->start(rtmpPort);//默认1935 - httpSrv->start(httpPort);//默认80 + //http服务器,支持websocket + httpSrv->start(httpPort);//默认80 #ifdef ENABLE_OPENSSL //如果支持ssl,还可以开启https服务器 TcpServer::Ptr httpsSrv(new TcpServer()); - httpsSrv->start(httpsPort);//默认443 + //https服务器,支持websocket + httpsSrv->start(httpsPort);//默认443 + + //支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问 + TcpServer::Ptr rtspSSLSrv(new TcpServer()); + rtspSSLSrv->start(rtspPort + 1);//默认555 #endif //ENABLE_OPENSSL NoticeCenter::Instance().addListener(ReloadConfigTag,Broadcast::kBroadcastReloadConfig,[&](BroadcastReloadConfigArgs){