srs/trunk/src/app
Haibo Chen(陈海博) 5dc292ce64
NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333)
## 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:

* [AI: Remove support for media transport via
UDP.](755686229f)
* [AI: Add crutial logs for each RTSP
stage.](9c8cbe7bde)
* [AI: Support AAC doec for
RTSP.](7d7cc12bae)
* [AI: Add option --rtsp for
RTSP.](f67414d9ee)
* [AI: Extract SrsRtpVideoBuilder for RTC and
RTSP.](562e76b904)

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-07-11 08:18:40 -04:00
..
srs_app_async_call.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_async_call.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_caster_flv.cpp Codex: Fix potential issues with memory leak. 2025-05-21 11:27:10 -04:00
srs_app_caster_flv.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_config.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_config.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_conn.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_conn.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_coworkers.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_coworkers.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_dash.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_dash.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_dvr.cpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_dvr.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_edge.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_edge.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_empty.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_empty.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_encoder.cpp Transcode: Bugfix: Fix loop transcoding with host. #3516. v6.0.168 v7.0.41 (#4325) 2025-06-04 10:11:58 -04:00
srs_app_encoder.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_ffmpeg.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_ffmpeg.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_forward.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_forward.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_fragment.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_fragment.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_gb28181.cpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_gb28181.hpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_hds.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_hds.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_heartbeat.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_heartbeat.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_hls.cpp rtmp2rtc: Support RTMP-to-WebRTC conversion with HEVC. v7.0.33 (#4289) 2025-05-14 07:49:04 -04:00
srs_app_hls.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_hourglass.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_hourglass.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_api.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_api.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_client.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_client.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_conn.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_conn.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_hooks.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_hooks.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_static.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_static.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_stream.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_http_stream.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_hybrid.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_hybrid.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_ingest.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_ingest.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_latest_version.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_latest_version.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_listener.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_listener.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_log.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_log.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_mpegts_udp.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_mpegts_udp.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_ng_exec.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_ng_exec.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_pithy_print.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_pithy_print.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_process.cpp Typo: "forked" process in log output. v7.0.30 (#4292) 2025-03-21 19:18:11 +08:00
srs_app_process.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_recv_thread.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_recv_thread.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_refer.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_refer.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_reload.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_reload.hpp Update docs link to latest in code. 2025-07-05 09:32:11 -04:00
srs_app_rtc_api.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_api.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_codec.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_codec.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_conn.cpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_rtc_conn.hpp rtc2rtmp: Support RTC-to-RTMP remuxing with HEVC. v7.0.43 (#4349) 2025-07-03 08:24:42 -04:00
srs_app_rtc_dtls.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_dtls.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_network.cpp Debugging: Drop the specified N original SRTP packet for testing NACK. 2025-06-15 10:01:08 -04:00
srs_app_rtc_network.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_queue.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_queue.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_sdp.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtc_sdp.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtc_server.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_server.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtc_source.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtc_source.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtmp_conn.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtmp_conn.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_rtsp_conn.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtsp_conn.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtsp_source.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_rtsp_source.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_security.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_security.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_server.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_server.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_source.cpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_source.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_conn.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_conn.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_listener.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_listener.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_server.cpp Codex: Fix potential issues with memory leak. 2025-05-21 11:27:10 -04:00
srs_app_srt_server.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_source.cpp Update docs link to latest in code. 2025-07-05 09:32:11 -04:00
srs_app_srt_source.hpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_srt_utility.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_srt_utility.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_st.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_st.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_statistic.cpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_statistic.hpp Refine code and add tests for #4289. v7.0.45 (#4412) 2025-07-04 17:26:12 -04:00
srs_app_stream_bridge.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_stream_bridge.hpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_tencentcloud.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_tencentcloud.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_threads.cpp NEW PROTOCOL: Support viewing stream over RTSP. v7.0.47 (#4333) 2025-07-11 08:18:40 -04:00
srs_app_threads.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_utility.cpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_utility.hpp update copyright to 2025. v5.0.218 v6.0.159 v7.0.21 (#4271) 2025-01-14 17:35:18 +08:00
srs_app_uuid.cpp For #2532: Windows: Support CYGWIN64 for SRS (#3255) 2022-11-20 12:29:57 +08:00
srs_app_uuid.hpp API: Use libuuid to generate uuid. v5.0.9 2021-08-06 22:02:46 +08:00