From 89c0748234b0065e5947bc87ee8e3d43fcad8135 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 23 Jun 2020 17:39:16 +0800 Subject: [PATCH] Fix the empty cid issue --- trunk/src/main/srs_main_server.cpp | 3 +++ trunk/src/protocol/srs_service_st.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 55e002f37..3a73b7b55 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -212,6 +212,9 @@ srs_error_t do_main(int argc, char** argv) } int main(int argc, char** argv) { + // For background context id. + _srs_context->generate_id(); + srs_error_t err = do_main(argc, argv); if (err != srs_success) { diff --git a/trunk/src/protocol/srs_service_st.cpp b/trunk/src/protocol/srs_service_st.cpp index d1558b2aa..f902d5056 100644 --- a/trunk/src/protocol/srs_service_st.cpp +++ b/trunk/src/protocol/srs_service_st.cpp @@ -69,11 +69,20 @@ srs_error_t srs_st_init() if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { return srs_error_new(ERROR_ST_SET_EPOLL, "st enable st failed, current is %s", st_get_eventsys_name()); } + + // Before ST init, we might have already inited the background cid. + string cid = _srs_context->get_id(); + if (cid.empty()) { + cid = _srs_context->generate_id(); + } int r0 = 0; if((r0 = st_init()) != 0){ return srs_error_new(ERROR_ST_INITIALIZE, "st initialize failed, r0=%d", r0); } + + // Switch to the background cid. + _srs_context->set_id(cid); srs_trace("st_init success, use %s", st_get_eventsys_name()); return srs_success;