mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 20:47:08 +08:00
完善事件取消监听机制
This commit is contained in:
parent
7bb1b7f670
commit
c454240c83
@ -72,6 +72,16 @@ void MediaSource::findAsync(const MediaInfo &info,
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto onRegist = [listener_tag,weakSession,info,cb,onRegistTimeout](BroadcastMediaChangedArgs) {
|
auto onRegist = [listener_tag,weakSession,info,cb,onRegistTimeout](BroadcastMediaChangedArgs) {
|
||||||
|
auto strongSession = weakSession.lock();
|
||||||
|
if(!strongSession) {
|
||||||
|
//自己已经销毁
|
||||||
|
//取消延时任务,防止多次回调
|
||||||
|
onRegistTimeout->cancel();
|
||||||
|
//取消事件监听
|
||||||
|
NoticeCenter::Instance().delListener(listener_tag,Broadcast::kBroadcastMediaChanged);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!bRegist || schema != info._schema || vhost != info._vhost || app != info._app ||stream != info._streamid){
|
if(!bRegist || schema != info._schema || vhost != info._vhost || app != info._app ||stream != info._streamid){
|
||||||
//不是自己感兴趣的事件,忽略之
|
//不是自己感兴趣的事件,忽略之
|
||||||
return;
|
return;
|
||||||
@ -79,15 +89,11 @@ void MediaSource::findAsync(const MediaInfo &info,
|
|||||||
|
|
||||||
//取消延时任务,防止多次回调
|
//取消延时任务,防止多次回调
|
||||||
onRegistTimeout->cancel();
|
onRegistTimeout->cancel();
|
||||||
|
//取消事件监听
|
||||||
|
NoticeCenter::Instance().delListener(listener_tag,Broadcast::kBroadcastMediaChanged);
|
||||||
|
|
||||||
//播发器请求的流终于注册上了
|
//播发器请求的流终于注册上了,切换到自己的线程再回复
|
||||||
auto strongSession = weakSession.lock();
|
strongSession->async([weakSession,info,cb](){
|
||||||
if(!strongSession) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//切换到自己的线程再回复
|
|
||||||
strongSession->async([listener_tag,weakSession,info,cb](){
|
|
||||||
auto strongSession = weakSession.lock();
|
auto strongSession = weakSession.lock();
|
||||||
if(!strongSession) {
|
if(!strongSession) {
|
||||||
return;
|
return;
|
||||||
@ -95,8 +101,6 @@ void MediaSource::findAsync(const MediaInfo &info,
|
|||||||
DebugL << "收到媒体注册事件,回复播放器:" << info._schema << "/" << info._vhost << "/" << info._app << "/" << info._streamid;
|
DebugL << "收到媒体注册事件,回复播放器:" << info._schema << "/" << info._vhost << "/" << info._app << "/" << info._streamid;
|
||||||
//再找一遍媒体源,一般能找到
|
//再找一遍媒体源,一般能找到
|
||||||
findAsync(info,strongSession,false,cb);
|
findAsync(info,strongSession,false,cb);
|
||||||
//取消事件监听
|
|
||||||
NoticeCenter::Instance().delListener(listener_tag,Broadcast::kBroadcastMediaChanged);
|
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
//监听媒体注册事件
|
//监听媒体注册事件
|
||||||
|
Loading…
Reference in New Issue
Block a user