mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
流量汇报事件添加客户端ip和端口参数
This commit is contained in:
parent
ead8b5a89c
commit
7e25537957
@ -162,11 +162,15 @@ typedef struct {
|
|||||||
* @param total_bytes 耗费上下行总流量,单位字节数
|
* @param total_bytes 耗费上下行总流量,单位字节数
|
||||||
* @param total_seconds 本次tcp会话时长,单位秒
|
* @param total_seconds 本次tcp会话时长,单位秒
|
||||||
* @param is_player 客户端是否为播放器
|
* @param is_player 客户端是否为播放器
|
||||||
|
* @param peer_ip 客户端ip
|
||||||
|
* @param peer_port 客户端端口号
|
||||||
*/
|
*/
|
||||||
void (API_CALL *on_mk_flow_report)(const mk_media_info url_info,
|
void (API_CALL *on_mk_flow_report)(const mk_media_info url_info,
|
||||||
uint64_t total_bytes,
|
uint64_t total_bytes,
|
||||||
uint64_t total_seconds,
|
uint64_t total_seconds,
|
||||||
int is_player);
|
int is_player,
|
||||||
|
const char *peer_ip,
|
||||||
|
uint16_t peer_port);
|
||||||
} mk_events;
|
} mk_events;
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,7 +151,9 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||||||
s_events.on_mk_flow_report((mk_media_info) &args,
|
s_events.on_mk_flow_report((mk_media_info) &args,
|
||||||
totalBytes,
|
totalBytes,
|
||||||
totalDuration,
|
totalDuration,
|
||||||
isPlayer);
|
isPlayer,
|
||||||
|
peerIP.c_str(),
|
||||||
|
peerPort);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -372,19 +372,23 @@ void API_CALL on_mk_shell_login(const char *user_name,
|
|||||||
* @param total_bytes 耗费上下行总流量,单位字节数
|
* @param total_bytes 耗费上下行总流量,单位字节数
|
||||||
* @param total_seconds 本次tcp会话时长,单位秒
|
* @param total_seconds 本次tcp会话时长,单位秒
|
||||||
* @param is_player 客户端是否为播放器
|
* @param is_player 客户端是否为播放器
|
||||||
|
* @param peer_ip 客户端ip
|
||||||
|
* @param peer_port 客户端端口号
|
||||||
*/
|
*/
|
||||||
void API_CALL on_mk_flow_report(const mk_media_info url_info,
|
void API_CALL on_mk_flow_report(const mk_media_info url_info,
|
||||||
uint64_t total_bytes,
|
uint64_t total_bytes,
|
||||||
uint64_t total_seconds,
|
uint64_t total_seconds,
|
||||||
int is_player) {
|
int is_player,
|
||||||
|
const char *peer_ip,
|
||||||
|
uint16_t peer_port) {
|
||||||
log_printf(LOG_LEV,"%s/%s/%s/%s, url params: %s,"
|
log_printf(LOG_LEV,"%s/%s/%s/%s, url params: %s,"
|
||||||
"total_bytes: %d, total_seconds: %d, is_player: %d",
|
"total_bytes: %d, total_seconds: %d, is_player: %d, peer_ip:%s, peer_port:%d",
|
||||||
mk_media_info_get_schema(url_info),
|
mk_media_info_get_schema(url_info),
|
||||||
mk_media_info_get_vhost(url_info),
|
mk_media_info_get_vhost(url_info),
|
||||||
mk_media_info_get_app(url_info),
|
mk_media_info_get_app(url_info),
|
||||||
mk_media_info_get_stream(url_info),
|
mk_media_info_get_stream(url_info),
|
||||||
mk_media_info_get_params(url_info),
|
mk_media_info_get_params(url_info),
|
||||||
(int)total_bytes, (int)total_seconds, (int)is_player);
|
(int)total_bytes, (int)total_seconds, (int)is_player,peer_ip, (int)peer_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flag = 1;
|
static int flag = 1;
|
||||||
|
@ -269,13 +269,15 @@ void installWebHook(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastFlowReport,[](BroadcastFlowReportArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastFlowReport,[](BroadcastFlowReportArgs){
|
||||||
if(!hook_enable || args._param_strs == hook_adminparams || hook_flowreport.empty()){
|
if(!hook_enable || args._param_strs == hook_adminparams || hook_flowreport.empty() || peerIP == "127.0.0.1"){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto body = make_json(args);
|
auto body = make_json(args);
|
||||||
body["totalBytes"] = (Json::UInt64)totalBytes;
|
body["totalBytes"] = (Json::UInt64)totalBytes;
|
||||||
body["duration"] = (Json::UInt64)totalDuration;
|
body["duration"] = (Json::UInt64)totalDuration;
|
||||||
body["player"] = isPlayer;
|
body["player"] = isPlayer;
|
||||||
|
body["ip"] = peerIP;
|
||||||
|
body["port"] = peerPort;
|
||||||
//执行hook
|
//执行hook
|
||||||
do_http_hook(hook_flowreport,body, nullptr);
|
do_http_hook(hook_flowreport,body, nullptr);
|
||||||
});
|
});
|
||||||
|
@ -127,7 +127,7 @@ extern const string kBroadcastShellLogin;
|
|||||||
|
|
||||||
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
||||||
extern const string kBroadcastFlowReport;
|
extern const string kBroadcastFlowReport;
|
||||||
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer
|
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, const string &peerIP,const uint16_t &peerPort
|
||||||
|
|
||||||
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||||
extern const string kBroadcastNotFoundStream;
|
extern const string kBroadcastNotFoundStream;
|
||||||
|
@ -378,8 +378,11 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_hls = mediaInfo._schema == HLS_SCHEMA;
|
bool is_hls = mediaInfo._schema == HLS_SCHEMA;
|
||||||
|
string peer_ip = sender.get_peer_ip();
|
||||||
|
uint16_t peer_port = sender.get_peer_port();
|
||||||
|
|
||||||
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
|
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
|
||||||
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, mediaInfo]
|
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, mediaInfo, peer_ip, peer_port]
|
||||||
(const string &errMsg, const string &cookie_path_in, int cookieLifeSecond) {
|
(const string &errMsg, const string &cookie_path_in, int cookieLifeSecond) {
|
||||||
HttpServerCookie::Ptr cookie;
|
HttpServerCookie::Ptr cookie;
|
||||||
if (cookieLifeSecond) {
|
if (cookieLifeSecond) {
|
||||||
@ -402,7 +405,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
|||||||
attachment._is_hls = is_hls;
|
attachment._is_hls = is_hls;
|
||||||
if(is_hls){
|
if(is_hls){
|
||||||
//hls相关信息
|
//hls相关信息
|
||||||
attachment._hls_data = std::make_shared<HlsCookieData>(mediaInfo);
|
attachment._hls_data = std::make_shared<HlsCookieData>(mediaInfo, peer_ip, peer_port);
|
||||||
//hls未查找MediaSource
|
//hls未查找MediaSource
|
||||||
attachment._have_find_media_source = false;
|
attachment._have_find_media_source = false;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ void HttpSession::onError(const SockException& err) {
|
|||||||
|
|
||||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, _ticker.createdTime()/1000, true);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, _ticker.createdTime()/1000, true, get_peer_ip(), get_peer_port());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
HlsCookieData::HlsCookieData(const MediaInfo &info) {
|
HlsCookieData::HlsCookieData(const MediaInfo &info, const string &peer_ip, uint16_t peer_port) {
|
||||||
_info = info;
|
_info = info;
|
||||||
|
_peer_ip = peer_ip;
|
||||||
|
_peer_port = peer_port;
|
||||||
_added = std::make_shared<bool>(false);
|
_added = std::make_shared<bool>(false);
|
||||||
addReaderCount();
|
addReaderCount();
|
||||||
}
|
}
|
||||||
@ -61,7 +63,7 @@ HlsCookieData::~HlsCookieData() {
|
|||||||
WarnL << "HLS播放器(" << _info._vhost << "/" << _info._app << "/" << _info._streamid << ")断开,播放时间:" << duration;
|
WarnL << "HLS播放器(" << _info._vhost << "/" << _info._app << "/" << _info._streamid << ")断开,播放时间:" << duration;
|
||||||
GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold);
|
GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold);
|
||||||
if (_bytes > iFlowThreshold * 1024) {
|
if (_bytes > iFlowThreshold * 1024) {
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, _bytes, duration, true);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, _bytes, duration, true, _peer_ip, _peer_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ private:
|
|||||||
class HlsCookieData{
|
class HlsCookieData{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<HlsCookieData> Ptr;
|
typedef std::shared_ptr<HlsCookieData> Ptr;
|
||||||
HlsCookieData(const MediaInfo &info);
|
HlsCookieData(const MediaInfo &info, const string &peer_ip, uint16_t peer_port);
|
||||||
~HlsCookieData();
|
~HlsCookieData();
|
||||||
void addByteUsage(uint64_t bytes);
|
void addByteUsage(uint64_t bytes);
|
||||||
private:
|
private:
|
||||||
@ -100,6 +100,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
uint64_t _bytes = 0;
|
uint64_t _bytes = 0;
|
||||||
MediaInfo _info;
|
MediaInfo _info;
|
||||||
|
string _peer_ip;
|
||||||
|
uint16_t _peer_port;
|
||||||
std::shared_ptr<bool> _added;
|
std::shared_ptr<bool> _added;
|
||||||
weak_ptr<HlsMediaSource> _src;
|
weak_ptr<HlsMediaSource> _src;
|
||||||
Ticker _ticker;
|
Ticker _ticker;
|
||||||
|
@ -55,7 +55,7 @@ void RtmpSession::onError(const SockException& err) {
|
|||||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||||
|
|
||||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, _ticker.createdTime()/1000, isPlayer);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, _ticker.createdTime()/1000, isPlayer, get_peer_ip(), get_peer_port());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void RtspSession::onError(const SockException& err) {
|
|||||||
//流量统计事件广播
|
//流量统计事件广播
|
||||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, _ticker.createdTime()/1000, isPlayer);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, _ticker.createdTime()/1000, isPlayer, get_peer_ip(), get_peer_port());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user