mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-03 17:27:33 +08:00
TcpSession/UdpSession统一为Session类
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "Util/util.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "MediaSource.h"
|
||||
#include "Common/config.h"
|
||||
#include "Record/MP4Reader.h"
|
||||
|
||||
@@ -181,7 +181,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
|
||||
}
|
||||
|
||||
//拦截hls的播放请求
|
||||
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender){
|
||||
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,Session &sender){
|
||||
//访问的hls.m3u8结尾,我们转换成kBroadcastMediaPlayed事件
|
||||
Broadcast::AuthInvoker auth_invoker = [invoker](const string &err) {
|
||||
//cookie有效期为kHlsCookieSecond
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
* 4、cookie中记录的url参数是否跟本次url参数一致,如果一致直接返回客户端错误码
|
||||
* 5、触发kBroadcastHttpAccess事件
|
||||
*/
|
||||
static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
|
||||
static void canAccessPath(Session &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
|
||||
const function<void(const string &err_msg, const HttpServerCookie::Ptr &cookie)> &callback) {
|
||||
//获取用户唯一id
|
||||
auto uid = parser.Params();
|
||||
@@ -353,7 +353,7 @@ static string pathCat(const string &a, const string &b){
|
||||
* @param file_path 文件绝对路径
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
||||
static void accessFile(Session &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
||||
bool is_hls = end_with(file_path, kHlsSuffix);
|
||||
if (!is_hls && !File::fileExist(file_path.data())) {
|
||||
//文件不存在且不是hls,那么直接返回404
|
||||
@@ -366,7 +366,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
||||
replace(const_cast<string &>(media_info._streamid), kHlsSuffix, "");
|
||||
}
|
||||
|
||||
weak_ptr<TcpSession> weakSession = sender.shared_from_this();
|
||||
weak_ptr<Session> weakSession = sender.shared_from_this();
|
||||
//判断是否有权限访问该文件
|
||||
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
|
||||
auto strongSession = weakSession.lock();
|
||||
@@ -456,7 +456,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
||||
});
|
||||
}
|
||||
|
||||
static string getFilePath(const Parser &parser,const MediaInfo &media_info, TcpSession &sender){
|
||||
static string getFilePath(const Parser &parser,const MediaInfo &media_info, Session &sender){
|
||||
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
||||
GET_CONFIG(string, rootPath, Http::kRootPath);
|
||||
GET_CONFIG_FUNC(StrCaseMap, virtualPathMap, Http::kVirtualPath, [](const string &str) {
|
||||
@@ -491,7 +491,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, TcpS
|
||||
* @param parser http请求
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const HttpFileManager::invoker &cb) {
|
||||
void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFileManager::invoker &cb) {
|
||||
auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl();
|
||||
MediaInfo media_info(fullUrl);
|
||||
auto file_path = getFilePath(parser, media_info, sender);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "HttpBody.h"
|
||||
#include "HttpCookie.h"
|
||||
#include "Common/Parser.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "Util/function_traits.h"
|
||||
|
||||
namespace mediakit {
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
* @param parser http请求
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
static void onAccessPath(toolkit::TcpSession &sender, Parser &parser, const invoker &cb);
|
||||
static void onAccessPath(toolkit::Session &sender, Parser &parser, const invoker &cb);
|
||||
|
||||
/**
|
||||
* 获取mime值
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
|
||||
HttpSession::HttpSession(const Socket::Ptr &pSock) : Session(pSock) {
|
||||
TraceP(this);
|
||||
GET_CONFIG(uint32_t,keep_alive_sec,Http::kKeepAliveSecond);
|
||||
pSock->setSendTimeOutSecond(keep_alive_sec);
|
||||
@@ -440,7 +440,7 @@ class AsyncSenderData {
|
||||
public:
|
||||
friend class AsyncSender;
|
||||
typedef std::shared_ptr<AsyncSenderData> Ptr;
|
||||
AsyncSenderData(const TcpSession::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
|
||||
AsyncSenderData(const Session::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
|
||||
_session = dynamic_pointer_cast<HttpSession>(session);
|
||||
_body = body;
|
||||
_close_when_complete = close_when_complete;
|
||||
@@ -675,7 +675,7 @@ std::string HttpSession::get_peer_ip() {
|
||||
if(!forwarded_ip_header.empty() && !_parser.getHeader()[forwarded_ip_header].empty()){
|
||||
return _parser.getHeader()[forwarded_ip_header];
|
||||
}
|
||||
return TcpSession::get_peer_ip();
|
||||
return Session::get_peer_ip();
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_POST(ssize_t &content_len) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define SRC_HTTP_HTTPSESSION_H_
|
||||
|
||||
#include <functional>
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "Rtmp/RtmpMediaSource.h"
|
||||
#include "Rtmp/FlvMuxer.h"
|
||||
#include "HttpRequestSplitter.h"
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpSession: public toolkit::TcpSession,
|
||||
class HttpSession: public toolkit::Session,
|
||||
public FlvMuxer,
|
||||
public HttpRequestSplitter,
|
||||
public WebSocketSplitter {
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
std::function<bool (const char *data,size_t len) > _contentCallBack;
|
||||
};
|
||||
|
||||
using HttpsSession = toolkit::TcpSessionWithSSL<HttpSession>;
|
||||
using HttpsSession = toolkit::SessionWithSSL<HttpSession>;
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
|
||||
@@ -27,18 +27,18 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* 该类实现了TcpSession派生类发送数据的截取
|
||||
* 该类实现了Session派生类发送数据的截取
|
||||
* 目的是发送业务数据前进行websocket协议的打包
|
||||
*/
|
||||
template <typename TcpSessionType>
|
||||
class TcpSessionTypeImp : public TcpSessionType, public SendInterceptor{
|
||||
template <typename SessionType>
|
||||
class SessionTypeImp : public SessionType, public SendInterceptor{
|
||||
public:
|
||||
typedef std::shared_ptr<TcpSessionTypeImp> Ptr;
|
||||
using Ptr = std::shared_ptr<SessionTypeImp>;
|
||||
|
||||
TcpSessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
|
||||
TcpSessionType(pSock), _identifier(parent.getIdentifier()) {}
|
||||
SessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
|
||||
SessionType(pSock), _identifier(parent.getIdentifier()) {}
|
||||
|
||||
~TcpSessionTypeImp() {}
|
||||
~SessionTypeImp() = default;
|
||||
|
||||
/**
|
||||
* 设置发送数据截取回调函数
|
||||
@@ -58,7 +58,7 @@ protected:
|
||||
if (_beforeSendCB) {
|
||||
return _beforeSendCB(buf);
|
||||
}
|
||||
return TcpSessionType::send(std::move(buf));
|
||||
return SessionType::send(std::move(buf));
|
||||
}
|
||||
|
||||
std::string getIdentifier() const override {
|
||||
@@ -70,12 +70,12 @@ private:
|
||||
onBeforeSendCB _beforeSendCB;
|
||||
};
|
||||
|
||||
template <typename TcpSessionType>
|
||||
class TcpSessionCreator {
|
||||
template <typename SessionType>
|
||||
class SessionCreator {
|
||||
public:
|
||||
//返回的TcpSession必须派生于SendInterceptor,可以返回null
|
||||
toolkit::TcpSession::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
|
||||
return std::make_shared<TcpSessionTypeImp<TcpSessionType> >(header,parent,pSock);
|
||||
//返回的Session必须派生于SendInterceptor,可以返回null
|
||||
toolkit::Session::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
|
||||
return std::make_shared<SessionTypeImp<SessionType> >(header,parent,pSock);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,15 +228,15 @@ private:
|
||||
std::string _payload_cache;
|
||||
std::string _payload_section;
|
||||
std::weak_ptr<toolkit::Server> _weak_server;
|
||||
toolkit::TcpSession::Ptr _session;
|
||||
toolkit::Session::Ptr _session;
|
||||
Creator _creator;
|
||||
};
|
||||
|
||||
|
||||
template<typename TcpSessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
|
||||
class WebSocketSession : public WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>{
|
||||
template<typename SessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
|
||||
class WebSocketSession : public WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>{
|
||||
public:
|
||||
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>(pSock){}
|
||||
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>(pSock){}
|
||||
virtual ~WebSocketSession(){}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
RtmpSession::RtmpSession(const Socket::Ptr &sock) : TcpSession(sock) {
|
||||
RtmpSession::RtmpSession(const Socket::Ptr &sock) : Session(sock) {
|
||||
DebugP(this);
|
||||
GET_CONFIG(uint32_t,keep_alive_sec,Rtmp::kKeepAliveSecond);
|
||||
sock->setSendTimeOutSecond(keep_alive_sec);
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
#include "RtmpMediaSourceImp.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "Common/Stamp.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtmpSession : public toolkit::TcpSession, public RtmpProtocol, public MediaSourceEvent {
|
||||
class RtmpSession : public toolkit::Session, public RtmpProtocol, public MediaSourceEvent {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<RtmpSession>;
|
||||
|
||||
@@ -109,7 +109,7 @@ private:
|
||||
/**
|
||||
* 支持ssl加密的rtmp服务器
|
||||
*/
|
||||
using RtmpSessionWithSSL = toolkit::TcpSessionWithSSL<RtmpSession>;
|
||||
using RtmpSessionWithSSL = toolkit::SessionWithSSL<RtmpSession>;
|
||||
|
||||
} /* namespace mediakit */
|
||||
#endif /* SRC_RTMP_RTMPSESSION_H_ */
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "RtpSplitter.h"
|
||||
#include "RtpProcess.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
|
||||
@@ -49,7 +49,7 @@ static unordered_map<string, weak_ptr<RtspSession> > g_mapGetter;
|
||||
//对g_mapGetter上锁保护
|
||||
static recursive_mutex g_mtxGetter;
|
||||
|
||||
RtspSession::RtspSession(const Socket::Ptr &sock) : TcpSession(sock) {
|
||||
RtspSession::RtspSession(const Socket::Ptr &sock) : Session(sock) {
|
||||
DebugP(this);
|
||||
GET_CONFIG(uint32_t,keep_alive_sec,Rtsp::kKeepAliveSecond);
|
||||
sock->setSendTimeOutSecond(keep_alive_sec);
|
||||
@@ -1078,7 +1078,7 @@ ssize_t RtspSession::send(Buffer::Ptr pkt){
|
||||
// DebugP(this) << pkt->data();
|
||||
// }
|
||||
_bytes_usage += pkt->size();
|
||||
return TcpSession::send(std::move(pkt));
|
||||
return Session::send(std::move(pkt));
|
||||
}
|
||||
|
||||
bool RtspSession::sendRtspResponse(const string &res_code, const std::initializer_list<string> &header, const string &sdp, const char *protocol) {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
#include "Common/config.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
#include "RtpMultiCaster.h"
|
||||
#include "RtspMediaSource.h"
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
Buffer::Ptr _rtp;
|
||||
};
|
||||
|
||||
class RtspSession : public toolkit::TcpSession, public RtspSplitter, public RtpReceiver, public MediaSourceEvent {
|
||||
class RtspSession : public toolkit::Session, public RtspSplitter, public RtpReceiver, public MediaSourceEvent {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<RtspSession>;
|
||||
using onGetRealm = std::function<void(const std::string &realm)>;
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
RtspSession(const toolkit::Socket::Ptr &sock);
|
||||
virtual ~RtspSession();
|
||||
////TcpSession override////
|
||||
////Session override////
|
||||
void onRecv(const toolkit::Buffer::Ptr &buf) override;
|
||||
void onError(const toolkit::SockException &err) override;
|
||||
void onManager() override;
|
||||
@@ -94,7 +94,7 @@ protected:
|
||||
// 由于支持断连续推,存在OwnerPoller变更的可能
|
||||
toolkit::EventPoller::Ptr getOwnerPoller(MediaSource &sender) override;
|
||||
|
||||
/////TcpSession override////
|
||||
/////Session override////
|
||||
ssize_t send(toolkit::Buffer::Ptr pkt) override;
|
||||
//收到RTCP包回调
|
||||
virtual void onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *data, size_t len);
|
||||
@@ -225,7 +225,7 @@ private:
|
||||
/**
|
||||
* 支持ssl加密的rtsp服务器,可用于诸如亚马逊echo show这样的设备访问
|
||||
*/
|
||||
using RtspSessionWithSSL = toolkit::TcpSessionWithSSL<RtspSession>;
|
||||
using RtspSessionWithSSL = toolkit::SessionWithSSL<RtspSession>;
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ static onceToken s_token([]() {
|
||||
REGIST_CMD(media);
|
||||
}, nullptr);
|
||||
|
||||
ShellSession::ShellSession(const Socket::Ptr &_sock) : TcpSession(_sock) {
|
||||
ShellSession::ShellSession(const Socket::Ptr &_sock) : Session(_sock) {
|
||||
DebugP(this);
|
||||
pleaseInputUser();
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include <functional>
|
||||
#include "Common/config.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class ShellSession: public toolkit::TcpSession {
|
||||
class ShellSession: public toolkit::Session {
|
||||
public:
|
||||
ShellSession(const toolkit::Socket::Ptr &_sock);
|
||||
virtual ~ShellSession();
|
||||
|
||||
Reference in New Issue
Block a user