From 82f1569f2a623942aeafeb59d4bf39a72a89cb8f Mon Sep 17 00:00:00 2001 From: "xialixin@kanzhun.com" Date: Sat, 29 Aug 2020 10:41:12 +0800 Subject: [PATCH] When for traverses the device list, send invite and sleep to other threads to update the list, and the conflicting program exits --- trunk/src/app/srs_app_gb28181_sip.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/trunk/src/app/srs_app_gb28181_sip.cpp b/trunk/src/app/srs_app_gb28181_sip.cpp index 68aa39a92..7137f8117 100644 --- a/trunk/src/app/srs_app_gb28181_sip.cpp +++ b/trunk/src/app/srs_app_gb28181_sip.cpp @@ -163,7 +163,8 @@ srs_error_t SrsGb28181SipSession::do_cycle() if (_register_status == SrsGb28181SipSessionRegisterOk && _alive_status == SrsGb28181SipSessionAliveOk) { - + std::list auto_play_list; + std::map::iterator it; for (it = _device_list.begin(); it != _device_list.end(); it++) { SrsGb28181Device *device = it->second; @@ -191,8 +192,15 @@ srs_error_t SrsGb28181SipSession::do_cycle() //offline or already invite device does not need to send invite if (device->device_status != "ON" || device->invite_status != SrsGb28181SipSessionUnkonw) continue; + + auto_play_list.push_back(chid); + }//end for (it) - + //auto send sip invite and create stream chennal + while(auto_play_list.size() > 0){ + std::string chid = auto_play_list.front(); + auto_play_list.pop_front(); + SrsGb28181StreamChannel ch; ch.set_channel_id(_session_id + "@" + chid); @@ -226,7 +234,7 @@ srs_error_t SrsGb28181SipSession::do_cycle() srs_trace("gb28181: %s clients device=%s send invite code=%d", _session_id.c_str(), chid.c_str(), code); - }//end for (it) + }//end while (auto_play_list.size()) }//end if (config) if (_register_status == SrsGb28181SipSessionRegisterOk && @@ -911,7 +919,7 @@ srs_error_t SrsGb28181SipService::fetch_or_create_sip_session(SrsSipRequest *req if ((sess = fetch(req->sip_auth_id)) != NULL) { *sip_session = sess; return err; - } + } sess = new SrsGb28181SipSession(this, req);; if ((err = sess->serve()) != srs_success) {