diff --git a/server/main.cpp b/server/main.cpp index 763de656..40126969 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -336,6 +336,7 @@ int start_main(int argc,char *argv[]) { } unInstallWebApi(); unInstallWebHook(); + Recorder::stopAll(); //休眠1秒再退出,防止资源释放顺序错误 InfoL << "程序退出中,请等待..."; sleep(1); diff --git a/src/Record/Recorder.cpp b/src/Record/Recorder.cpp index 36cb8121..ed9dabae 100644 --- a/src/Record/Recorder.cpp +++ b/src/Record/Recorder.cpp @@ -206,6 +206,11 @@ public: _recorder_map.erase(getRecorderKey(vhost, app, stream_id)); } + void stopAll(){ + lock_guard lck(_recorder_mtx); + _recorder_map.clear(); + } + private: MediaSourceWatcher(){ NoticeCenter::Instance().addListener(this,Broadcast::kBroadcastMediaChanged,[this](BroadcastMediaChangedArgs){ @@ -352,4 +357,9 @@ void Recorder::stopRecord(Recorder::type type, const string &vhost, const string } } +void Recorder::stopAll() { + MediaSourceWatcher::Instance().stopAll(); + MediaSourceWatcher::Instance().stopAll(); +} + } /* namespace mediakit */ diff --git a/src/Record/Recorder.h b/src/Record/Recorder.h index b170e77a..a18e7bbd 100644 --- a/src/Record/Recorder.h +++ b/src/Record/Recorder.h @@ -56,6 +56,7 @@ public: static status getRecordStatus(type type, const string &vhost, const string &app, const string &stream_id); static int startRecord(type type, const string &vhost, const string &app, const string &stream_id,bool waitForRecord, bool continueRecord); static void stopRecord(type type, const string &vhost, const string &app, const string &stream_id); + static void stopAll(); private: Recorder() = delete; ~Recorder() = delete; diff --git a/tests/test_server.cpp b/tests/test_server.cpp index 6c9d6bf7..27c9c86c 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -354,6 +354,7 @@ int main(int argc,char *argv[]) { signal(SIGHUP, [](int) { loadIniConfig(); }); sem.wait(); + Recorder::stopAll(); lock_guard lck(s_mtxFlvRecorder); s_mapFlvRecorder.clear(); return 0;