优化事件触发器性能

This commit is contained in:
xiongziliang 2020-04-02 10:32:16 +08:00
parent 205c894eb0
commit f1914ca67f

View File

@ -49,9 +49,14 @@ public:
return _channel; return _channel;
} }
void setCallBack(on_mk_media_close cb, void *user_data){ void setOnClose(on_mk_media_close cb, void *user_data){
_cb = cb; _on_close = cb;
_user_data = user_data; _on_close_data = user_data;
}
void setOnSeek(on_mk_media_seek cb, void *user_data){
_on_seek = cb;
_on_seek_data = user_data;
} }
protected: protected:
// 通知其停止推流 // 通知其停止推流
@ -60,31 +65,45 @@ protected:
//非强制关闭且正有人在观看该视频 //非强制关闭且正有人在观看该视频
return false; return false;
} }
if(!_cb){ if(!_on_close){
//未设置回调,没法关闭 //未设置回调,没法关闭
WarnL << "请使用mk_media_set_on_close函数设置回调函数!"; WarnL << "请使用mk_media_set_on_close函数设置回调函数!";
return false; return false;
} }
//请在回调中调用mk_media_release函数释放资源,否则MediaSource::close()操作不会生效 //请在回调中调用mk_media_release函数释放资源,否则MediaSource::close()操作不会生效
_cb(_user_data); _on_close(_on_close_data);
WarnL << "close media:" << sender.getSchema() << "/" << sender.getVhost() << "/" << sender.getApp() << "/" << sender.getId() << " " << force; WarnL << "close media:" << sender.getSchema() << "/" << sender.getVhost() << "/" << sender.getApp() << "/" << sender.getId() << " " << force;
return true; return true;
} }
bool seekTo(MediaSource &sender,uint32_t ui32Stamp){
if(!_on_seek){
return false;
}
return _on_seek(_on_seek_data);
}
// 观看总人数 // 观看总人数
int totalReaderCount(MediaSource &sender) override{ int totalReaderCount(MediaSource &sender) override{
return _channel->totalReaderCount(); return _channel->totalReaderCount();
} }
private: private:
DevChannel::Ptr _channel; DevChannel::Ptr _channel;
on_mk_media_close _cb; on_mk_media_close _on_close;
void *_user_data; on_mk_media_seek _on_seek;
void *_on_seek_data;
void *_on_close_data;
}; };
API_EXPORT void API_CALL mk_media_set_on_close(mk_media ctx, on_mk_media_close cb, void *user_data){ API_EXPORT void API_CALL mk_media_set_on_close(mk_media ctx, on_mk_media_close cb, void *user_data){
assert(ctx); assert(ctx);
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
(*obj)->setCallBack(cb,user_data); (*obj)->setOnClose(cb, user_data);
}
API_EXPORT void API_CALL mk_media_set_on_seek(mk_media ctx, on_mk_media_seek cb, void *user_data){
assert(ctx);
MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx;
(*obj)->setOnSeek(cb, user_data);
} }
API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx){ API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx){