From 33047ddc94409827be9917857b9706c2b4b8af70 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 4 Dec 2019 19:15:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E9=80=80=E5=87=BA=E5=89=8D?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E4=B8=80=E5=88=87=E5=BD=95=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.cpp | 1 + src/Record/Recorder.cpp | 10 ++++++++++ src/Record/Recorder.h | 1 + tests/test_server.cpp | 1 + 4 files changed, 13 insertions(+) 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;