From ac868852e475eef1a6e12414abae9a725d4ef898 Mon Sep 17 00:00:00 2001 From: Winlin Date: Wed, 1 Oct 2025 21:25:39 -0400 Subject: [PATCH] SRT: Support configurable default_streamid option. v6.0.180 (#4515) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new default_streamid configuration option for the SRT server to allow customization of the default streamid used when SRT clients connect without setting the SRTO_STREAMID socket option. When SRT clients (like VLC) connect without properly setting the SRTO_STREAMID socket option, SRS previously used a hardcoded default value of "#!::r=live/livestream,m=publish". This caused conflicts when: 1. A publisher connects without setting streamid (uses default publish mode) 2. A player tries to connect without setting streamid (also uses default publish mode) 3. The player gets a "Stream already exists or busy" error because both are trying to publish Start SRS with default stream id as viewer: ```bash ./objs/srs -c conf/srt.vlc.conf ``` Publish SRT stream by FFmpeg: ```bash ffmpeg -re -i ./doc/source.flv -c copy -pes_payload_size 0 -f mpegts \ 'srt://127.0.0.1:10080?streamid=#!::r=live/livestream,m=publish' ``` Play SRT stream by ffplay: ```bash ffplay 'srt://127.0.0.1:10080?streamid=#!::r=live/livestream,m=request' ``` Play SRT stream by VLC: ``` ✅ Correct - Use simple URL without streamid parameter: srt://127.0.0.1:10080 ❌ Wrong - VLC doesn't support streamid parameter: srt://127.0.0.1:10080?streamid=#!::r=live/livestream,m=request ``` --- Co-authored-by: OSSRS-AI --- trunk/conf/full.conf | 6 ++++ trunk/conf/srt.conf | 1 + trunk/conf/srt.vlc.conf | 54 ++++++++++++++++++++++++++++ trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_config.cpp | 20 ++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_srt_conn.cpp | 2 +- trunk/src/core/srs_core_version6.hpp | 2 +- 8 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 trunk/conf/srt.vlc.conf diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index a84309c22..dededaa4e 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -338,6 +338,12 @@ srt_server { # Overwrite by env SRS_SRT_SERVER_DEFAULT_APP # default: live default_app live; + # Default streamid when client doesn't provide one. + # This is used when SRT client connects without setting SRTO_STREAMID socket option. + # The streamid format follows SRT standard: #!::r=app/stream,m=publish|request + # Overwrite by env SRS_SRT_SERVER_DEFAULT_STREAMID + # default: #!::r=live/livestream,m=publish + default_streamid "#!::r=live/livestream,m=publish"; # The peerlatency is set by the sender side and will notify the receiver side. # Overwrite by env SRS_SRT_SERVER_PEERLATENCY # default: 0 diff --git a/trunk/conf/srt.conf b/trunk/conf/srt.conf index 582bc0056..cc394c446 100644 --- a/trunk/conf/srt.conf +++ b/trunk/conf/srt.conf @@ -28,6 +28,7 @@ srt_server { tlpktdrop off; sendbuf 2000000; recvbuf 2000000; + default_streamid "#!::r=live/livestream,m=publish"; } # @doc https://github.com/ossrs/srs/issues/1147#issuecomment-577607026 diff --git a/trunk/conf/srt.vlc.conf b/trunk/conf/srt.vlc.conf new file mode 100644 index 000000000..e5fc21aa7 --- /dev/null +++ b/trunk/conf/srt.vlc.conf @@ -0,0 +1,54 @@ +# SRT config. + +listen 1935; +max_connections 1000; +daemon off; +srs_log_tank console; + +http_api { + enabled on; + listen 1985; +} + +http_server { + enabled on; + listen 8080; + dir ./objs/nginx/html; +} + +srt_server { + enabled on; + listen 10080; + maxbw 1000000000; + connect_timeout 4000; + peerlatency 0; + recvlatency 0; + latency 0; + tsbpdmode off; + tlpktdrop off; + sendbuf 2000000; + recvbuf 2000000; + default_streamid "#!::r=live/livestream,m=request"; +} + +# @doc https://github.com/ossrs/srs/issues/1147#issuecomment-577607026 +vhost __defaultVhost__ { + srt { + enabled on; + srt_to_rtmp on; + } + + http_remux { + enabled on; + mount [vhost]/[app]/[stream].flv; + } +} + +# For SRT to use vhost. +vhost srs.srt.com.cn { +} + +stats { + network 0; + disk sda sdb xvda xvdb; +} diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 73db6d868..556240464 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 6.0 Changelog +* v6.0, 2025-10-01, SRT: Support configurable default_streamid option. v6.0.180 * v6.0, 2025-09-27, For Edge, only support RTMP or HTTP-FLV. v6.0.179 (#4512) * v6.0, 2025-09-20, Fix WHIP with transcoding bug. v6.0.178 (#4495) * v6.0, 2025-09-15, RTC2RTMP: Fix sequence number wraparound assertion crashes. v6.0.177 (#4491) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 3cafa5604..96132d7cd 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2399,7 +2399,8 @@ srs_error_t SrsConfig::check_normal_config() && n != "peerlatency" && n != "connect_timeout" && n != "peer_idle_timeout" && n != "sendbuf" && n != "recvbuf" && n != "payloadsize" && n != "default_app" && n != "sei_filter" && n != "mix_correct" - && n != "tlpktdrop" && n != "tsbpdmode" && n != "passphrase" && n != "pbkeylen") { + && n != "tlpktdrop" && n != "tsbpdmode" && n != "passphrase" && n != "pbkeylen" + && n != "default_streamid") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_server.%s", n.c_str()); } } @@ -8254,6 +8255,23 @@ string SrsConfig::get_default_app_name() return conf->arg0(); } +string SrsConfig::get_srt_default_streamid() +{ + SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.default_streamid"); // SRS_SRT_SERVER_DEFAULT_STREAMID + + static string DEFAULT = "#!::r=live/livestream,m=publish"; + SrsConfDirective* conf = root->get("srt_server"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("default_streamid"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + return conf->arg0(); +} + SrsConfDirective* SrsConfig::get_srt(std::string vhost) { SrsConfDirective* conf = get_vhost(vhost); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index bfb87445f..04844318b 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -708,6 +708,8 @@ public: virtual int get_srto_pbkeylen(); // Get the default app. virtual std::string get_default_app_name(); + // Get the default streamid when client doesn't provide one. + virtual std::string get_srt_default_streamid(); private: SrsConfDirective* get_srt(std::string vhost); public: diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index 594190155..dc403ed38 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -261,7 +261,7 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() // If streamid empty, using default streamid instead. if (streamid.empty()) { - streamid = "#!::r=live/livestream,m=publish"; + streamid = _srs_config->get_srt_default_streamid(); srs_warn("srt get empty streamid, using default streamid %s instead", streamid.c_str()); } diff --git a/trunk/src/core/srs_core_version6.hpp b/trunk/src/core/srs_core_version6.hpp index 2152ad512..ebe08aa2f 100644 --- a/trunk/src/core/srs_core_version6.hpp +++ b/trunk/src/core/srs_core_version6.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 6 #define VERSION_MINOR 0 -#define VERSION_REVISION 179 +#define VERSION_REVISION 180 #endif