mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
流量汇报事件添加id参数
This commit is contained in:
parent
7e25537957
commit
a7a376b3f2
3
.gitignore
vendored
3
.gitignore
vendored
@ -41,3 +41,6 @@
|
|||||||
/Android/.idea/
|
/Android/.idea/
|
||||||
/Android/app/src/main/cpp/libs_export/
|
/Android/app/src/main/cpp/libs_export/
|
||||||
/3rdpart/media-server/.idea/
|
/3rdpart/media-server/.idea/
|
||||||
|
/3rdpart/media-server/.idea/
|
||||||
|
/build/
|
||||||
|
/3rdpart/media-server/.idea/
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 8eaecbd6dd8bed0bee6a61168255653127a20a43
|
Subproject commit ca6ab8b4c406c3c2e91ca0979c843908d1edb4bd
|
@ -278,6 +278,7 @@ void installWebHook(){
|
|||||||
body["player"] = isPlayer;
|
body["player"] = isPlayer;
|
||||||
body["ip"] = peerIP;
|
body["ip"] = peerIP;
|
||||||
body["port"] = peerPort;
|
body["port"] = peerPort;
|
||||||
|
body["id"] = sessionIdentifier;
|
||||||
//执行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, const string &peerIP,const uint16_t &peerPort
|
#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
|
||||||
|
|
||||||
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||||
extern const string kBroadcastNotFoundStream;
|
extern const string kBroadcastNotFoundStream;
|
||||||
|
@ -378,11 +378,12 @@ 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 identifier = sender.getIdentifier();
|
||||||
string peer_ip = sender.get_peer_ip();
|
string peer_ip = sender.get_peer_ip();
|
||||||
uint16_t peer_port = sender.get_peer_port();
|
uint16_t peer_port = sender.get_peer_port();
|
||||||
|
|
||||||
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
|
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
|
||||||
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, mediaInfo, peer_ip, peer_port]
|
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, mediaInfo, identifier, 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) {
|
||||||
@ -405,7 +406,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, peer_ip, peer_port);
|
attachment._hls_data = std::make_shared<HlsCookieData>(mediaInfo, identifier, peer_ip, peer_port);
|
||||||
//hls未查找MediaSource
|
//hls未查找MediaSource
|
||||||
attachment._have_find_media_source = false;
|
attachment._have_find_media_source = false;
|
||||||
}
|
}
|
||||||
|
@ -103,16 +103,18 @@ void HttpSession::onRecv(const Buffer::Ptr &pBuf) {
|
|||||||
|
|
||||||
void HttpSession::onError(const SockException& err) {
|
void HttpSession::onError(const SockException& err) {
|
||||||
if(_is_flv_stream){
|
if(_is_flv_stream){
|
||||||
|
uint64_t duration = _ticker.createdTime()/1000;
|
||||||
//flv播放器
|
//flv播放器
|
||||||
WarnP(this) << "FLV播放器("
|
WarnP(this) << "FLV播放器("
|
||||||
<< _mediaInfo._vhost << "/"
|
<< _mediaInfo._vhost << "/"
|
||||||
<< _mediaInfo._app << "/"
|
<< _mediaInfo._app << "/"
|
||||||
<< _mediaInfo._streamid
|
<< _mediaInfo._streamid
|
||||||
<< ")断开:" << err.what();
|
<< ")断开:" << err.what()
|
||||||
|
<< ",耗时(s):" << duration;
|
||||||
|
|
||||||
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, get_peer_ip(), get_peer_port());
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration , true, getIdentifier(), get_peer_ip(), get_peer_port());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,9 @@
|
|||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
HlsCookieData::HlsCookieData(const MediaInfo &info, const string &peer_ip, uint16_t peer_port) {
|
HlsCookieData::HlsCookieData(const MediaInfo &info, const string &sessionIdentifier, const string &peer_ip, uint16_t peer_port) {
|
||||||
_info = info;
|
_info = info;
|
||||||
|
_sessionIdentifier = sessionIdentifier;
|
||||||
_peer_ip = peer_ip;
|
_peer_ip = peer_ip;
|
||||||
_peer_port = peer_port;
|
_peer_port = peer_port;
|
||||||
_added = std::make_shared<bool>(false);
|
_added = std::make_shared<bool>(false);
|
||||||
@ -59,11 +60,14 @@ HlsCookieData::~HlsCookieData() {
|
|||||||
if (src) {
|
if (src) {
|
||||||
src->modifyReaderCount(false);
|
src->modifyReaderCount(false);
|
||||||
}
|
}
|
||||||
auto duration = (_ticker.createdTime() - _ticker.elapsedTime()) / 1000;
|
uint64_t duration = (_ticker.createdTime() - _ticker.elapsedTime()) / 1000;
|
||||||
WarnL << "HLS播放器(" << _info._vhost << "/" << _info._app << "/" << _info._streamid << ")断开,播放时间:" << duration;
|
WarnL << _sessionIdentifier << "(" << _peer_ip << ":" << _peer_port << ") "
|
||||||
|
<< "HLS播放器(" << _info._vhost << "/" << _info._app << "/" << _info._streamid
|
||||||
|
<< ")断开,耗时(s):" << 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, _peer_ip, _peer_port);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, _bytes, duration, true, _sessionIdentifier, _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, const string &peer_ip, uint16_t peer_port);
|
HlsCookieData(const MediaInfo &info, const string &sessionIdentifier, 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,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
uint64_t _bytes = 0;
|
uint64_t _bytes = 0;
|
||||||
MediaInfo _info;
|
MediaInfo _info;
|
||||||
|
string _sessionIdentifier;
|
||||||
string _peer_ip;
|
string _peer_ip;
|
||||||
uint16_t _peer_port;
|
uint16_t _peer_port;
|
||||||
std::shared_ptr<bool> _added;
|
std::shared_ptr<bool> _added;
|
||||||
|
@ -45,17 +45,19 @@ RtmpSession::~RtmpSession() {
|
|||||||
|
|
||||||
void RtmpSession::onError(const SockException& err) {
|
void RtmpSession::onError(const SockException& err) {
|
||||||
bool isPlayer = !_pPublisherSrc;
|
bool isPlayer = !_pPublisherSrc;
|
||||||
|
uint64_t duration = _ticker.createdTime()/1000;
|
||||||
WarnP(this) << (isPlayer ? "RTMP播放器(" : "RTMP推流器(")
|
WarnP(this) << (isPlayer ? "RTMP播放器(" : "RTMP推流器(")
|
||||||
<< _mediaInfo._vhost << "/"
|
<< _mediaInfo._vhost << "/"
|
||||||
<< _mediaInfo._app << "/"
|
<< _mediaInfo._app << "/"
|
||||||
<< _mediaInfo._streamid
|
<< _mediaInfo._streamid
|
||||||
<< ")断开:" << err.what();
|
<< ")断开:" << err.what()
|
||||||
|
<< ",耗时(s):" << duration;
|
||||||
|
|
||||||
//流量统计事件广播
|
//流量统计事件广播
|
||||||
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, get_peer_ip(), get_peer_port());
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration, isPlayer, getIdentifier(), get_peer_ip(), get_peer_port());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +208,7 @@ void RtmpSession::onCmd_deleteStream(AMFDecoder &dec) {
|
|||||||
status.set("code", "NetStream.Unpublish.Success");
|
status.set("code", "NetStream.Unpublish.Success");
|
||||||
status.set("description", "Stop publishing.");
|
status.set("description", "Stop publishing.");
|
||||||
sendReply("onStatus", nullptr, status);
|
sendReply("onStatus", nullptr, status);
|
||||||
throw std::runtime_error(StrPrinter << "Stop publishing." << endl);
|
throw std::runtime_error(StrPrinter << "Stop publishing" << endl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,11 +86,13 @@ RtspSession::~RtspSession() {
|
|||||||
|
|
||||||
void RtspSession::onError(const SockException& err) {
|
void RtspSession::onError(const SockException& err) {
|
||||||
bool isPlayer = !_pushSrc;
|
bool isPlayer = !_pushSrc;
|
||||||
|
uint64_t duration = _ticker.createdTime()/1000;
|
||||||
WarnP(this) << (isPlayer ? "RTSP播放器(" : "RTSP推流器(")
|
WarnP(this) << (isPlayer ? "RTSP播放器(" : "RTSP推流器(")
|
||||||
<< _mediaInfo._vhost << "/"
|
<< _mediaInfo._vhost << "/"
|
||||||
<< _mediaInfo._app << "/"
|
<< _mediaInfo._app << "/"
|
||||||
<< _mediaInfo._streamid
|
<< _mediaInfo._streamid
|
||||||
<< ")断开:" << err.what();
|
<< ")断开:" << err.what()
|
||||||
|
<< ",耗时(s):" << duration;
|
||||||
|
|
||||||
if (_rtpType == Rtsp::RTP_MULTICAST) {
|
if (_rtpType == Rtsp::RTP_MULTICAST) {
|
||||||
//取消UDP端口监听
|
//取消UDP端口监听
|
||||||
@ -106,7 +108,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, get_peer_ip(), get_peer_port());
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, duration, isPlayer, getIdentifier(), get_peer_ip(), get_peer_port());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user