Skip to content

NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 #4333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 91 commits into from
Jul 11, 2025

Conversation

duiniuluantanqin
Copy link
Member

@duiniuluantanqin duiniuluantanqin commented Apr 21, 2025

Introduce

This PR adds support for viewing streams via the RTSP protocol. Note that it only supports viewing streams, not publishing streams via RTSP.

Currently, only publishing via RTMP is supported, which is then converted to RTSP. Further work is needed to support publishing RTC/SRT streams and converting them to RTSP.

Usage

Build and run SRS with RTSP support:

cd srs/trunk && ./configure --rtsp=on && make -j16
./objs/srs -c conf/rtsp.conf

Push stream via RTMP by FFmpeg:

ffmpeg -re -i doc/source.flv -c copy -f flv rtmp://localhost/live/livestream

View the stream via RTSP protocol, try UDP first, then use TCP:

ffplay -i rtsp://localhost:8554/live/livestream

Or specify the transport protocol with TCP:

ffplay -rtsp_transport tcp -i rtsp://localhost:8554/live/livestream

Unit Test

Run utest for RTSP:

./configure --utest=on & make utest -j16
./objs/srs_utest

Regression Test

You need to start SRS for regression testing.

./objs/srs -c conf/regression-test-for-clion.conf

Then run regression tests for RTSP.

cd srs/trunk/3rdparty/srs-bench
go test ./srs -mod=vendor -v -count=1 -run=TestRtmpPublish_RtspPlay

Blackbox Test

For blackbox testing, SRS will be started by utest, so there is no need to start SRS manually.

cd srs/trunk/3rdparty/srs-bench
go test ./blackbox -mod=vendor -v -count=1 -run=TestFast_RtmpPublish_RtspPlay_Basic

UDP Transport

As UDP requires port allocation, this PR doesn't support delivering media stream via UDP transport, so it will fail if you try to use UDP as transport:

ffplay -rtsp_transport udp -i rtsp://localhost:8554/live/livestream

[rtsp @ 0x7fbc99a14880] method SETUP failed: 461 Unsupported Transport
rtsp://localhost:8554/live/livestream: Protocol not supported

[2025-07-05 21:30:52.738][WARN][14916][7d7gf623][35] RTSP: setup failed: code=2057
(RtspTransportNotSupported) : UDP transport not supported, only TCP/interleaved mode is supported

There are no plans to support UDP transport for RTSP. In the real world, UDP is rarely used; the vast majority of RTSP traffic uses TCP.

Play Before Publish

RTSP supports audio with AAC and OPUS codecs, which is significantly different from RTMP or WebRTC.

RTSP uses commands to exchange SDP and specify the audio track to play, unlike WHEP or HTTP-FLV, which use the query string of the URL. RTSP depends on the player’s behavior, making it very difficult to use and describe.

Considering the feature that allows playing the stream before publishing it, it requires generating some default parameters in the SDP. For OPUS, the sample rate is 48 kHz with 2 channels, while AAC is more complex, especially regarding the sample rate, which may be 44.1 kHz, 32 kHz, or 48 kHz.

Therefore, for RTSP, we cannot support play-then-publish. Instead, there must already be a stream when playing it, so that the audio codec is determined.

Opus Codec

No Opus codec support for RTSP, because for RTC2RTSP, it always converts RTC to RTMP frames, then converts them to RTSP packets. Therefore, the audio codec is always AAC after converting RTC to RTMP.

This means the bridge architecture needs some changes. We need a new bridge that binds to the target protocol. For example, RTC2RTMP converts the audio codec, but RTC2RTSP keeps the original audio codec.

Furthermore, the RTC2RTMP bridge should also support bypassing the Opus codec if we use enhanced-RTMP, which supports the Opus audio codec. I think it should be configurable to either transcode or bypass the audio codec. However, this is not relevant to RTSP.

AI Contributor

Below commits are contributed by AI:


Co-authored-by: Jacob Su [email protected]

@winlinvip winlinvip changed the title 支持RTSP拉流 Supports RTSP streaming. Apr 21, 2025
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Apr 21, 2025
@duiniuluantanqin duiniuluantanqin changed the title Supports RTSP streaming. Support for RTSP stream pulling. Apr 21, 2025
@duiniuluantanqin duiniuluantanqin marked this pull request as draft April 21, 2025 03:01
@duiniuluantanqin duiniuluantanqin marked this pull request as ready for review April 21, 2025 07:00
@duiniuluantanqin duiniuluantanqin requested review from Copilot, winlinvip, suzp1984 and xiaozhihong and removed request for Copilot April 21, 2025 07:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for RTSP stream pulling by introducing a new RTSP protocol stack and connection type, updating server setup and configuration, and extending SDP processing.

  • Added unit tests in the configuration suite to verify RTSP server environment variables.
  • Introduced a new RTSP protocol stack header and corresponding connection implementation (SrsRtspConn).
  • Updated server initialization, heartbeat reporting, and configuration handling to incorporate RTSP endpoints.

Reviewed Changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
trunk/src/utest/srs_utest_config.cpp Added unit test for RTSP configuration environment variables.
trunk/src/protocol/srs_protocol_rtsp_stack.hpp Introduced RTSP protocol stack definitions and constants.
trunk/src/app/srs_app_server.hpp & .cpp Added RTSP listener initialization, management, and integration into connection dispatching.
trunk/src/app/srs_app_rtsp.hpp Defined SrsRtspConn and related RTSP connection functionality.
trunk/src/app/srs_app_rtc_sdp.hpp & .cpp Extended SDP encoding to include RTSP control attributes.
trunk/src/app/srs_app_rtc_conn.hpp Updated do_send_packet to be virtual for proper RTSP connection overrides.
trunk/src/app/srs_app_latest_version.cpp, srs_app_heartbeat.cpp, srs_app_config.hpp & .cpp Integrated RTSP feature flags and configuration adjustments.
Files not reviewed (2)
  • trunk/conf/rtsp.conf: Language not supported
  • trunk/configure: Language not supported

@winlinvip winlinvip changed the title NEW PROTOCOL: Support viewing stream over RTSP NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 Jul 11, 2025
@winlinvip winlinvip added the RefinedByAI Refined by AI/GPT. label Jul 11, 2025
@winlinvip winlinvip merged commit 5dc292c into ossrs:develop Jul 11, 2025
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RefinedByAI Refined by AI/GPT. TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants