mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
c api测试程序防止退出时崩溃
This commit is contained in:
parent
6796d0b592
commit
92bc4fbbb1
@ -1 +1 @@
|
||||
Subproject commit e1b29b7fa22e18bb0976a281268c0431a411e7ce
|
||||
Subproject commit 4d88a395a25e9265c579aa930acdf60796bd4e4c
|
@ -71,6 +71,11 @@ typedef struct {
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg);
|
||||
|
||||
/**
|
||||
* 关闭所有服务器,请在main函数退出时调用
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_stop_all_server();
|
||||
|
||||
/**
|
||||
* 基础类型参数版本的mk_env_init,为了方便其他语言调用
|
||||
*/
|
||||
|
@ -62,6 +62,14 @@ API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
|
||||
cfg->ssl_pwd);
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_stop_all_server(){
|
||||
CLEAR_ARR(rtsp_server);
|
||||
CLEAR_ARR(rtmp_server);
|
||||
CLEAR_ARR(http_server);
|
||||
udpRtpServer = nullptr;
|
||||
tcpRtpServer = nullptr;
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_env_init1( int thread_num,
|
||||
int log_level,
|
||||
int ini_is_path,
|
||||
|
@ -11,11 +11,11 @@ int main(int argc,char *argv[]){
|
||||
mk_rtsp_server_start(554,false);
|
||||
mk_rtmp_server_start(1935,false);
|
||||
mk_rtp_server_start(10000);
|
||||
|
||||
static bool flag = true;
|
||||
signal(SIGINT, [](int) { flag = false; });// 设置退出信号
|
||||
|
||||
while (flag){
|
||||
sleep(1);
|
||||
}
|
||||
mk_stop_all_server();
|
||||
return 0;
|
||||
}
|
@ -217,21 +217,23 @@ public:
|
||||
|
||||
private:
|
||||
MediaSourceWatcher(){
|
||||
NoticeCenter::Instance().addListener(this,Broadcast::kBroadcastMediaChanged,[this](BroadcastMediaChangedArgs){
|
||||
//保存NoticeCenter的强引用,防止在MediaSourceWatcher单例释放前释放NoticeCenter单例
|
||||
_notice_center = NoticeCenter::Instance().shared_from_this();
|
||||
_notice_center->addListener(this,Broadcast::kBroadcastMediaChanged,[this](BroadcastMediaChangedArgs){
|
||||
if(bRegist){
|
||||
onRegist(schema,vhost,app,stream,sender);
|
||||
}else{
|
||||
onUnRegist(schema,vhost,app,stream,sender);
|
||||
}
|
||||
});
|
||||
NoticeCenter::Instance().addListener(this,Broadcast::kBroadcastMediaResetTracks,[this](BroadcastMediaResetTracksArgs){
|
||||
_notice_center->addListener(this,Broadcast::kBroadcastMediaResetTracks,[this](BroadcastMediaResetTracksArgs){
|
||||
onRegist(schema,vhost,app,stream,sender);
|
||||
});
|
||||
}
|
||||
|
||||
~MediaSourceWatcher(){
|
||||
NoticeCenter::Instance().delListener(this,Broadcast::kBroadcastMediaChanged);
|
||||
NoticeCenter::Instance().delListener(this,Broadcast::kBroadcastMediaResetTracks);
|
||||
_notice_center->delListener(this,Broadcast::kBroadcastMediaChanged);
|
||||
_notice_center->delListener(this,Broadcast::kBroadcastMediaResetTracks);
|
||||
}
|
||||
|
||||
void onRegist(const string &schema,const string &vhost,const string &app,const string &stream,MediaSource &sender){
|
||||
@ -320,6 +322,7 @@ private:
|
||||
}
|
||||
private:
|
||||
recursive_mutex _recorder_mtx;
|
||||
NoticeCenter::Ptr _notice_center;
|
||||
unordered_map<string, RecorderHelper::Ptr> _recorder_map;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user