c api测试程序防止退出时崩溃

This commit is contained in:
xiongziliang 2019-12-23 14:20:49 +08:00
parent 6796d0b592
commit 92bc4fbbb1
5 changed files with 23 additions and 7 deletions

@ -1 +1 @@
Subproject commit e1b29b7fa22e18bb0976a281268c0431a411e7ce
Subproject commit 4d88a395a25e9265c579aa930acdf60796bd4e4c

View File

@ -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便
*/

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
};