mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 20:47:08 +08:00
简化事件参数
This commit is contained in:
parent
5886a38a9f
commit
e663ddd9a6
@ -147,11 +147,11 @@ void FFmpegSource::findAsync(int maxWaitMS, const function<void(const MediaSourc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bRegist ||
|
if (!bRegist ||
|
||||||
schema != strongSelf->_media_info._schema ||
|
sender.getSchema() != strongSelf->_media_info._schema ||
|
||||||
vhost != strongSelf->_media_info._vhost ||
|
sender.getVhost() != strongSelf->_media_info._vhost ||
|
||||||
app != strongSelf->_media_info._app ||
|
sender.getApp() != strongSelf->_media_info._app ||
|
||||||
stream != strongSelf->_media_info._streamid){
|
sender.getId() != strongSelf->_media_info._streamid) {
|
||||||
//不是自己感兴趣的事件,忽略之
|
//不是自己感兴趣的事件,忽略之
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -341,10 +341,10 @@ void installWebHook(){
|
|||||||
}
|
}
|
||||||
ArgsType body;
|
ArgsType body;
|
||||||
body["regist"] = bRegist;
|
body["regist"] = bRegist;
|
||||||
body["schema"] = schema;
|
body["schema"] = sender.getSchema();
|
||||||
body["vhost"] = vhost;
|
body["vhost"] = sender.getVhost();
|
||||||
body["app"] = app;
|
body["app"] = sender.getApp();
|
||||||
body["stream"] = stream;
|
body["stream"] = sender.getId();
|
||||||
//执行hook
|
//执行hook
|
||||||
do_http_hook(hook_stream_chaned,body, nullptr);
|
do_http_hook(hook_stream_chaned,body, nullptr);
|
||||||
});
|
});
|
||||||
|
@ -86,12 +86,7 @@ void MediaSource::setTrackSource(const std::weak_ptr<TrackSource> &track_src) {
|
|||||||
if (!strongPtr) {
|
if (!strongPtr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaResetTracks,
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaResetTracks, *this);
|
||||||
_strSchema,
|
|
||||||
_strVhost,
|
|
||||||
_strApp,
|
|
||||||
_strId,
|
|
||||||
*this);
|
|
||||||
},false);
|
},false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +223,11 @@ void findAsync_l(const MediaInfo &info,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bRegist || schema != info._schema || vhost != info._vhost || app != info._app ||stream != info._streamid){
|
if (!bRegist ||
|
||||||
|
sender.getSchema() != info._schema ||
|
||||||
|
sender.getVhost() != info._vhost ||
|
||||||
|
sender.getApp() != info._app ||
|
||||||
|
sender.getId() != info._streamid) {
|
||||||
//不是自己感兴趣的事件,忽略之
|
//不是自己感兴趣的事件,忽略之
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -312,13 +311,7 @@ void MediaSource::regist() {
|
|||||||
if (!strongPtr) {
|
if (!strongPtr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaChanged,
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaChanged, true, *this);
|
||||||
true,
|
|
||||||
_strSchema,
|
|
||||||
_strVhost,
|
|
||||||
_strApp,
|
|
||||||
_strId,
|
|
||||||
*this);
|
|
||||||
},false);
|
},false);
|
||||||
}
|
}
|
||||||
bool MediaSource::unregist() {
|
bool MediaSource::unregist() {
|
||||||
@ -341,13 +334,7 @@ bool MediaSource::unregist() {
|
|||||||
}
|
}
|
||||||
void MediaSource::unregisted(){
|
void MediaSource::unregisted(){
|
||||||
InfoL << "" << _strSchema << " " << _strVhost << " " << _strApp << " " << _strId;
|
InfoL << "" << _strSchema << " " << _strVhost << " " << _strApp << " " << _strId;
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaChanged,
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaChanged, false, *this);
|
||||||
false,
|
|
||||||
_strSchema,
|
|
||||||
_strVhost,
|
|
||||||
_strApp,
|
|
||||||
_strId,
|
|
||||||
*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ namespace Broadcast {
|
|||||||
|
|
||||||
//注册或反注册MediaSource事件广播
|
//注册或反注册MediaSource事件广播
|
||||||
extern const string kBroadcastMediaChanged;
|
extern const string kBroadcastMediaChanged;
|
||||||
#define BroadcastMediaChangedArgs const bool &bRegist, const string &schema,const string &vhost,const string &app,const string &stream,MediaSource &sender
|
#define BroadcastMediaChangedArgs const bool &bRegist, MediaSource &sender
|
||||||
|
|
||||||
//MediaSource重置Track事件
|
//MediaSource重置Track事件
|
||||||
extern const string kBroadcastMediaResetTracks;
|
extern const string kBroadcastMediaResetTracks;
|
||||||
#define BroadcastMediaResetTracksArgs const string &schema,const string &vhost,const string &app,const string &stream,MediaSource &sender
|
#define BroadcastMediaResetTracksArgs MediaSource &sender
|
||||||
|
|
||||||
//录制mp4文件成功后广播
|
//录制mp4文件成功后广播
|
||||||
extern const string kBroadcastRecordMP4;
|
extern const string kBroadcastRecordMP4;
|
||||||
|
@ -221,13 +221,13 @@ private:
|
|||||||
_notice_center = NoticeCenter::Instance().shared_from_this();
|
_notice_center = NoticeCenter::Instance().shared_from_this();
|
||||||
_notice_center->addListener(this,Broadcast::kBroadcastMediaChanged,[this](BroadcastMediaChangedArgs){
|
_notice_center->addListener(this,Broadcast::kBroadcastMediaChanged,[this](BroadcastMediaChangedArgs){
|
||||||
if(bRegist){
|
if(bRegist){
|
||||||
onRegist(schema,vhost,app,stream,sender);
|
onRegist(sender);
|
||||||
}else{
|
}else{
|
||||||
onUnRegist(schema,vhost,app,stream,sender);
|
onUnRegist(sender);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_notice_center->addListener(this,Broadcast::kBroadcastMediaResetTracks,[this](BroadcastMediaResetTracksArgs){
|
_notice_center->addListener(this,Broadcast::kBroadcastMediaResetTracks,[this](BroadcastMediaResetTracksArgs){
|
||||||
onRegist(schema,vhost,app,stream,sender);
|
onRegist(sender);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,8 +236,8 @@ private:
|
|||||||
_notice_center->delListener(this,Broadcast::kBroadcastMediaResetTracks);
|
_notice_center->delListener(this,Broadcast::kBroadcastMediaResetTracks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRegist(const string &schema,const string &vhost,const string &app,const string &stream,MediaSource &sender){
|
void onRegist(MediaSource &sender){
|
||||||
auto key = getRecorderKey(vhost,app,stream);
|
auto key = getRecorderKey(sender.getVhost(),sender.getApp(),sender.getId());
|
||||||
lock_guard<decltype(_recorder_mtx)> lck(_recorder_mtx);
|
lock_guard<decltype(_recorder_mtx)> lck(_recorder_mtx);
|
||||||
auto it = _recorder_map.find(key);
|
auto it = _recorder_map.find(key);
|
||||||
if(it == _recorder_map.end()){
|
if(it == _recorder_map.end()){
|
||||||
@ -245,20 +245,20 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!it->second->isRecording() || it->second->getSchema() == schema){
|
if(!it->second->isRecording() || it->second->getSchema() == sender.getSchema()){
|
||||||
// 绑定的协议一致或者并未正在录制则替换tracks
|
// 绑定的协议一致或者并未正在录制则替换tracks
|
||||||
auto tracks = sender.getTracks(true);
|
auto tracks = sender.getTracks(true);
|
||||||
if (!tracks.empty()) {
|
if (!tracks.empty()) {
|
||||||
it->second->attachTracks(std::move(tracks),schema);
|
it->second->attachTracks(std::move(tracks),sender.getSchema());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUnRegist(const string &schema,const string &vhost,const string &app,const string &stream,MediaSource &sender){
|
void onUnRegist(MediaSource &sender){
|
||||||
auto key = getRecorderKey(vhost,app,stream);
|
auto key = getRecorderKey(sender.getVhost(),sender.getApp(),sender.getId());
|
||||||
lock_guard<decltype(_recorder_mtx)> lck(_recorder_mtx);
|
lock_guard<decltype(_recorder_mtx)> lck(_recorder_mtx);
|
||||||
auto it = _recorder_map.find(key);
|
auto it = _recorder_map.find(key);
|
||||||
if(it == _recorder_map.end() || it->second->getSchema() != schema){
|
if(it == _recorder_map.end() || it->second->getSchema() != sender.getSchema()){
|
||||||
// 录像记录不存在或绑定的协议不一致
|
// 录像记录不存在或绑定的协议不一致
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +99,8 @@ int domain(const string &playUrl, const string &pushUrl) {
|
|||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaChanged,
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaChanged,
|
||||||
[pushUrl,poller](BroadcastMediaChangedArgs) {
|
[pushUrl,poller](BroadcastMediaChangedArgs) {
|
||||||
//媒体源"app/stream"已经注册,这时方可新建一个RtmpPusher对象并绑定该媒体源
|
//媒体源"app/stream"已经注册,这时方可新建一个RtmpPusher对象并绑定该媒体源
|
||||||
if(bRegist && pushUrl.find(schema) == 0){
|
if(bRegist && pushUrl.find(sender.getSchema()) == 0){
|
||||||
createPusher(poller,schema,vhost,app, stream, pushUrl);
|
createPusher(poller,sender.getSchema(),sender.getVhost(),sender.getApp(), sender.getId(), pushUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -178,23 +178,23 @@ void initEventListener() {
|
|||||||
|
|
||||||
//监听rtsp、rtmp源注册或注销事件;此处用于测试rtmp保存为flv录像,保存在http根目录下
|
//监听rtsp、rtmp源注册或注销事件;此处用于测试rtmp保存为flv录像,保存在http根目录下
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaChanged, [](BroadcastMediaChangedArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaChanged, [](BroadcastMediaChangedArgs) {
|
||||||
if (schema == RTMP_SCHEMA && app == "live") {
|
if (sender.getSchema() == RTMP_SCHEMA && sender.getApp() == "live") {
|
||||||
lock_guard<mutex> lck(s_mtxFlvRecorder);
|
lock_guard<mutex> lck(s_mtxFlvRecorder);
|
||||||
if (bRegist) {
|
if (bRegist) {
|
||||||
DebugL << "开始录制RTMP:" << schema << " " << vhost << " " << app << " " << stream;
|
DebugL << "开始录制RTMP:" << sender.getSchema() << " " << sender.getVhost() << " " << sender.getApp() << " " << sender.getId();
|
||||||
GET_CONFIG(string, http_root, Http::kRootPath);
|
GET_CONFIG(string, http_root, Http::kRootPath);
|
||||||
auto path =
|
auto path =
|
||||||
http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv";
|
http_root + "/" + sender.getVhost() + "/" + sender.getApp() + "/" + sender.getId() + "_" + to_string(time(NULL)) + ".flv";
|
||||||
FlvRecorder::Ptr recorder(new FlvRecorder);
|
FlvRecorder::Ptr recorder(new FlvRecorder);
|
||||||
try {
|
try {
|
||||||
recorder->startRecord(EventPollerPool::Instance().getPoller(),
|
recorder->startRecord(EventPollerPool::Instance().getPoller(),
|
||||||
dynamic_pointer_cast<RtmpMediaSource>(sender.shared_from_this()), path);
|
dynamic_pointer_cast<RtmpMediaSource>(sender.shared_from_this()), path);
|
||||||
s_mapFlvRecorder[vhost + "/" + app + "/" + stream] = recorder;
|
s_mapFlvRecorder[sender.getVhost() + "/" + sender.getApp() + "/" + sender.getId()] = recorder;
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
WarnL << ex.what();
|
WarnL << ex.what();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s_mapFlvRecorder.erase(vhost + "/" + app + "/" + stream);
|
s_mapFlvRecorder.erase(sender.getVhost() + "/" + sender.getApp() + "/" + sender.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user