From 66aaad78059f01195d61acad5ab8c112fc4a5318 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 13 Jul 2020 13:52:23 +0800 Subject: [PATCH] Log: Refine context --- trunk/src/app/srs_app_http_api.cpp | 5 ++++- trunk/src/app/srs_app_rtc_api.cpp | 8 ++++---- trunk/src/protocol/srs_service_log.cpp | 10 ++++++++++ trunk/src/protocol/srs_service_log.hpp | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 194b3af97..420b9b8ae 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1699,7 +1699,10 @@ void SrsHttpApi::remark(int64_t* in, int64_t* out) srs_error_t SrsHttpApi::do_cycle() { srs_error_t err = srs_success; - + + // Create context for API. + _srs_context->set_id(_srs_context->generate_id()); + srs_trace("API server client, ip=%s:%d", ip.c_str(), port); // initialize parser diff --git a/trunk/src/app/srs_app_rtc_api.cpp b/trunk/src/app/srs_app_rtc_api.cpp index e3923d4e9..1760e4a55 100644 --- a/trunk/src/app/srs_app_rtc_api.cpp +++ b/trunk/src/app/srs_app_rtc_api.cpp @@ -210,8 +210,8 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe srs_trace("RTC username=%s, offer=%dB, answer=%dB", session->username().c_str(), remote_sdp_str.length(), local_sdp_str.length()); - srs_trace("RTC offer: %s", srs_string_replace(remote_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); - srs_trace("RTC answer: %s", srs_string_replace(local_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); + srs_trace("RTC remote offer: %s", srs_string_replace(remote_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); + srs_trace("RTC local answer: %s", srs_string_replace(local_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); return err; } @@ -563,8 +563,8 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt srs_trace("RTC username=%s, offer=%dB, answer=%dB", session->username().c_str(), remote_sdp_str.length(), local_sdp_str.length()); - srs_trace("RTC offer: %s", srs_string_replace(remote_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); - srs_trace("RTC answer: %s", srs_string_replace(local_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); + srs_trace("RTC remote offer: %s", srs_string_replace(remote_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); + srs_trace("RTC local answer: %s", srs_string_replace(local_sdp_str.c_str(), "\r\n", "\\r\\n").c_str()); return err; } diff --git a/trunk/src/protocol/srs_service_log.cpp b/trunk/src/protocol/srs_service_log.cpp index 9d2384adc..b251ff310 100644 --- a/trunk/src/protocol/srs_service_log.cpp +++ b/trunk/src/protocol/srs_service_log.cpp @@ -77,6 +77,16 @@ void SrsThreadContext::clear_cid() } } +impl_SrsContextRestore::impl_SrsContextRestore(SrsContextId cid) +{ + cid_ = cid; +} + +impl_SrsContextRestore::~impl_SrsContextRestore() +{ + _srs_context->set_id(cid_); +} + // LCOV_EXCL_START SrsConsoleLog::SrsConsoleLog(SrsLogLevel l, bool u) { diff --git a/trunk/src/protocol/srs_service_log.hpp b/trunk/src/protocol/srs_service_log.hpp index b441dc3db..539599c42 100644 --- a/trunk/src/protocol/srs_service_log.hpp +++ b/trunk/src/protocol/srs_service_log.hpp @@ -49,6 +49,20 @@ public: virtual void clear_cid(); }; +// The context restore stores the context and restore it when done. +// Usage: +// SrsContextRestore(_srs_context->get_id()); +#define SrsContextRestore(cid) \ + impl_SrsContextRestore _context_restore_instance(cid) +class impl_SrsContextRestore +{ +private: + SrsContextId cid_; +public: + impl_SrsContextRestore(SrsContextId cid); + virtual ~impl_SrsContextRestore(); +}; + // The basic console log, which write log to console. class SrsConsoleLog : public ISrsLog {