mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-04 09:47:33 +08:00
统一事件参数类型
This commit is contained in:
@@ -107,7 +107,7 @@ extern const string kBroadcastShellLogin;
|
||||
|
||||
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
||||
extern const string kBroadcastFlowReport;
|
||||
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, const string &sessionIdentifier, const string &peerIP,const uint16_t &peerPort
|
||||
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, SockInfo &sender
|
||||
|
||||
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||
extern const string kBroadcastNotFoundStream;
|
||||
|
||||
@@ -309,6 +309,39 @@ static bool emitHlsPlayed(const Parser &parser, const MediaInfo &mediaInfo, cons
|
||||
return NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,mediaInfo,mediaAuthInvoker,static_cast<SockInfo &>(sender));
|
||||
}
|
||||
|
||||
class SockInfoImp : public SockInfo{
|
||||
public:
|
||||
typedef std::shared_ptr<SockInfoImp> Ptr;
|
||||
SockInfoImp() = default;
|
||||
~SockInfoImp() override = default;
|
||||
|
||||
const string &get_local_ip() override{
|
||||
return _local_ip;
|
||||
}
|
||||
|
||||
uint16_t get_local_port() override{
|
||||
return _local_port;
|
||||
}
|
||||
|
||||
const string &get_peer_ip() override{
|
||||
return _peer_ip;
|
||||
|
||||
}
|
||||
|
||||
uint16_t get_peer_port() override{
|
||||
return _peer_port;
|
||||
}
|
||||
|
||||
string getIdentifier() const override{
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
string _local_ip;
|
||||
string _peer_ip;
|
||||
string _identifier;
|
||||
uint16_t _local_port;
|
||||
uint16_t _peer_port;
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断http客户端是否有权限访问文件的逻辑步骤
|
||||
@@ -362,12 +395,16 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
||||
}
|
||||
|
||||
bool is_hls = mediaInfo._schema == HLS_SCHEMA;
|
||||
string identifier = sender.getIdentifier();
|
||||
string peer_ip = sender.get_peer_ip();
|
||||
uint16_t peer_port = sender.get_peer_port();
|
||||
|
||||
SockInfoImp::Ptr info = std::make_shared<SockInfoImp>();
|
||||
info->_identifier = sender.getIdentifier();
|
||||
info->_peer_ip = sender.get_peer_ip();
|
||||
info->_peer_port = sender.get_peer_port();
|
||||
info->_local_ip = sender.get_local_ip();
|
||||
info->_local_port = sender.get_local_port();
|
||||
|
||||
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
|
||||
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, mediaInfo, identifier, peer_ip, peer_port]
|
||||
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, mediaInfo, info]
|
||||
(const string &errMsg, const string &cookie_path_in, int cookieLifeSecond) {
|
||||
HttpServerCookie::Ptr cookie;
|
||||
if (cookieLifeSecond) {
|
||||
@@ -390,7 +427,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
||||
attachment._is_hls = is_hls;
|
||||
if(is_hls){
|
||||
//hls相关信息
|
||||
attachment._hls_data = std::make_shared<HlsCookieData>(mediaInfo, identifier, peer_ip, peer_port);
|
||||
attachment._hls_data = std::make_shared<HlsCookieData>(mediaInfo, info);
|
||||
//hls未查找MediaSource
|
||||
attachment._have_find_media_source = false;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ void HttpSession::onError(const SockException& err) {
|
||||
|
||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration , true, getIdentifier(), get_peer_ip(), get_peer_port());
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration , true, static_cast<SockInfo &>(*this));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,9 @@
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
HlsCookieData::HlsCookieData(const MediaInfo &info, const string &sessionIdentifier, const string &peer_ip, uint16_t peer_port) {
|
||||
HlsCookieData::HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockInfo> &sock_info) {
|
||||
_info = info;
|
||||
_sessionIdentifier = sessionIdentifier;
|
||||
_peer_ip = peer_ip;
|
||||
_peer_port = peer_port;
|
||||
_sock_info = sock_info;
|
||||
_added = std::make_shared<bool>(false);
|
||||
addReaderCount();
|
||||
}
|
||||
@@ -45,13 +43,13 @@ HlsCookieData::~HlsCookieData() {
|
||||
src->modifyReaderCount(false);
|
||||
}
|
||||
uint64_t duration = (_ticker.createdTime() - _ticker.elapsedTime()) / 1000;
|
||||
WarnL << _sessionIdentifier << "(" << _peer_ip << ":" << _peer_port << ") "
|
||||
WarnL << _sock_info->getIdentifier() << "(" << _sock_info->get_peer_ip() << ":" << _sock_info->get_peer_port() << ") "
|
||||
<< "HLS播放器(" << _info._vhost << "/" << _info._app << "/" << _info._streamid
|
||||
<< ")断开,耗时(s):" << duration;
|
||||
|
||||
GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold);
|
||||
if (_bytes > iFlowThreshold * 1024) {
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, _bytes, duration, true, _sessionIdentifier, _peer_ip, _peer_port);
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, _bytes, duration, true, static_cast<SockInfo&>(*_sock_info));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
class HlsCookieData{
|
||||
public:
|
||||
typedef std::shared_ptr<HlsCookieData> Ptr;
|
||||
HlsCookieData(const MediaInfo &info, const string &sessionIdentifier, const string &peer_ip, uint16_t peer_port);
|
||||
HlsCookieData(const MediaInfo &info, const std::shared_ptr<SockInfo> &sock_info);
|
||||
~HlsCookieData();
|
||||
void addByteUsage(uint64_t bytes);
|
||||
private:
|
||||
@@ -85,12 +85,10 @@ private:
|
||||
private:
|
||||
uint64_t _bytes = 0;
|
||||
MediaInfo _info;
|
||||
string _sessionIdentifier;
|
||||
string _peer_ip;
|
||||
uint16_t _peer_port;
|
||||
std::shared_ptr<bool> _added;
|
||||
weak_ptr<HlsMediaSource> _src;
|
||||
Ticker _ticker;
|
||||
std::shared_ptr<SockInfo> _sock_info;
|
||||
HlsMediaSource::RingType::RingReader::Ptr _ring_reader;
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ void RtmpSession::onError(const SockException& err) {
|
||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||
|
||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration, isPlayer, getIdentifier(), get_peer_ip(), get_peer_port());
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration, isPlayer, static_cast<SockInfo &>(*this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ void RtspSession::onError(const SockException& err) {
|
||||
//流量统计事件广播
|
||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration, isPlayer, getIdentifier(), get_peer_ip(), get_peer_port());
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration, isPlayer, static_cast<SockInfo &>(*this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user