From 3dc7b405ca7b65b633a7cd120074c456a5b28f62 Mon Sep 17 00:00:00 2001 From: OSSRS-AI Date: Sun, 26 Oct 2025 20:17:32 -0400 Subject: [PATCH] AI: HTTP-FLV: Enforce minimum 10ms sleep to prevent CPU busy-wait when mw_latency=0. v7.0.110 (#3963) --- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_http_stream.cpp | 7 +++++++ trunk/src/core/srs_core_version7.hpp | 2 +- trunk/src/utest/srs_utest_manual_protocol2.cpp | 2 +- trunk/src/utest/srs_utest_workflow_http_conn.cpp | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 0050a902f..721ee3ed1 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 7.0 Changelog +* v7.0, 2025-10-27, AI: HTTP-FLV: Enforce minimum 10ms sleep to prevent CPU busy-wait when mw_latency=0. v7.0.110 (#3963) * v7.0, 2025-10-26, AI: Edge: Fix stream names with dots being incorrectly truncated in source URL generation. v7.0.109 (#4011) * v7.0, 2025-10-26, AI: HTTPS: Handle SSL_ERROR_ZERO_RETURN as graceful connection closure. v7.0.108 (#4036) * v7.0, 2025-10-26, AI: API: Add clients field to on_play/on_stop webhooks and total field to HTTP API. v7.0.107 (#4147) diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 883d97aa1..4e141e4c2 100644 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -851,6 +851,13 @@ srs_error_t SrsLiveStream::do_serve_http(SrsLiveSource *source, ISrsLiveConsumer } srs_utime_t mw_sleep = config_->get_mw_sleep(req_->vhost_); + + // For HTTP FLV, we must wait for some milliseconds to avoid the spin. + // See https://github.com/ossrs/srs/issues/3963 for more details. + if (mw_sleep == 0) { + mw_sleep = 10 * SRS_UTIME_MILLISECONDS; + } + srs_trace("FLV %s, encoder=%s, mw_sleep=%dms, cache=%d, msgs=%d, dinm=%d, guess_av=%d/%d/%d", entry_->pattern.c_str(), enc_desc.c_str(), srsu2msi(mw_sleep), enc->has_cache(), msgs.max_, drop_if_not_match, has_audio, has_video, guess_has_av); diff --git a/trunk/src/core/srs_core_version7.hpp b/trunk/src/core/srs_core_version7.hpp index 310f76167..585f8671d 100644 --- a/trunk/src/core/srs_core_version7.hpp +++ b/trunk/src/core/srs_core_version7.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 7 #define VERSION_MINOR 0 -#define VERSION_REVISION 109 +#define VERSION_REVISION 110 #endif \ No newline at end of file diff --git a/trunk/src/utest/srs_utest_manual_protocol2.cpp b/trunk/src/utest/srs_utest_manual_protocol2.cpp index 5341bdc92..179280e90 100644 --- a/trunk/src/utest/srs_utest_manual_protocol2.cpp +++ b/trunk/src/utest/srs_utest_manual_protocol2.cpp @@ -5009,7 +5009,7 @@ VOID TEST(ProtocolKbpsTest, StreamIdentifyWithDotsInName_Issue4011) // Case 3: Different streams with same prefix should be different std::string backup1 = srs_net_url_encode_sid("", "live", "test.backup.stream"); std::string backup2 = srs_net_url_encode_sid("", "live", "test.backup.stream2"); - EXPECT_STRNE(backup1.c_str(), backup2.c_str()); // Should be different + EXPECT_STRNE(backup1.c_str(), backup2.c_str()); // Should be different // Case 4: The intended behavior - stripping ONLY known extensions // These should work correctly (strip .flv and .m3u8) diff --git a/trunk/src/utest/srs_utest_workflow_http_conn.cpp b/trunk/src/utest/srs_utest_workflow_http_conn.cpp index 8b31e665e..c72edf8cb 100644 --- a/trunk/src/utest/srs_utest_workflow_http_conn.cpp +++ b/trunk/src/utest/srs_utest_workflow_http_conn.cpp @@ -184,7 +184,7 @@ VOID TEST(BasicWorkflowHttpConnTest, ManuallyVerifyForHttpStream) live_stream->hooks_ = mock_hooks.get(); // Do not wait for utest, consume messages immediately. Remove this when HTTP stream use cond signal. - mock_config->mw_sleep_ = 0; + mock_config->mw_sleep_ = 100; // 0.1ms mock_entry->enabled = true; mock_entry->pattern = "/live/livestream.flv";