2025-08-20 12:09:54 +08:00
|
|
|
# CMake minimum version should be called first
|
|
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
|
|
2022-03-17 16:56:52 +08:00
|
|
|
# Name of the project.
|
|
|
|
|
# Language "C" is required for find_package(Threads).
|
2025-08-20 12:09:54 +08:00
|
|
|
cmake_policy(SET CMP0048 NEW)
|
|
|
|
|
project(srs VERSION 4.0.0 LANGUAGES CXX C)
|
2022-03-17 16:56:52 +08:00
|
|
|
|
|
|
|
|
# For utest required C++11.
|
2022-03-17 08:42:44 +08:00
|
|
|
set (CMAKE_CXX_STANDARD 11)
|
2014-09-26 11:05:45 +08:00
|
|
|
|
2021-07-16 22:29:51 +08:00
|
|
|
###########################################################
|
|
|
|
|
execute_process(
|
2025-10-24 08:38:48 +08:00
|
|
|
COMMAND bash -c "cd ${PROJECT_SOURCE_DIR}/../ && pwd"
|
2021-07-16 22:29:51 +08:00
|
|
|
OUTPUT_VARIABLE SRS_DIR
|
|
|
|
|
)
|
|
|
|
|
string(STRIP ${SRS_DIR} SRS_DIR)
|
|
|
|
|
message("SRS home is ${SRS_DIR}")
|
|
|
|
|
|
2021-07-16 07:29:55 +08:00
|
|
|
###########################################################
|
|
|
|
|
# Start to configure SRS with jobs of number of CPUs.
|
|
|
|
|
include(ProcessorCount)
|
|
|
|
|
ProcessorCount(JOBS)
|
|
|
|
|
|
2021-07-17 19:48:14 +08:00
|
|
|
# We should always configure SRS for switching between branches.
|
|
|
|
|
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
2022-05-23 08:31:57 +08:00
|
|
|
EXECUTE_PROCESS(
|
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.](https://github.com/ossrs/srs/pull/4333/commits/755686229f0d3910f058e6f75993112a68c5f60a)
* [AI: Add crutial logs for each RTSP
stage.](https://github.com/ossrs/srs/pull/4333/commits/9c8cbe7bdefda19087f87fdb5e041a8934e4db1d)
* [AI: Support AAC doec for
RTSP.](https://github.com/ossrs/srs/pull/4333/commits/7d7cc12bae269850011d4757eae635a61de99f36)
* [AI: Add option --rtsp for
RTSP.](https://github.com/ossrs/srs/pull/4333/commits/f67414d9ee98da39cda1f7d47cdf793c0e5a8412)
* [AI: Extract SrsRtpVideoBuilder for RTC and
RTSP.](https://github.com/ossrs/srs/pull/4333/commits/562e76b90469a1b016857eb23b090e8e45b52de3)
---------
Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-07-11 20:18:40 +08:00
|
|
|
COMMAND ./configure --osx --srt=on --gb28181=on --rtsp=on --apm=on --h265=on --hds=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
|
2022-05-23 08:31:57 +08:00
|
|
|
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
|
2021-07-17 19:48:14 +08:00
|
|
|
ELSE ()
|
2022-05-23 08:31:57 +08:00
|
|
|
EXECUTE_PROCESS(
|
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.](https://github.com/ossrs/srs/pull/4333/commits/755686229f0d3910f058e6f75993112a68c5f60a)
* [AI: Add crutial logs for each RTSP
stage.](https://github.com/ossrs/srs/pull/4333/commits/9c8cbe7bdefda19087f87fdb5e041a8934e4db1d)
* [AI: Support AAC doec for
RTSP.](https://github.com/ossrs/srs/pull/4333/commits/7d7cc12bae269850011d4757eae635a61de99f36)
* [AI: Add option --rtsp for
RTSP.](https://github.com/ossrs/srs/pull/4333/commits/f67414d9ee98da39cda1f7d47cdf793c0e5a8412)
* [AI: Extract SrsRtpVideoBuilder for RTC and
RTSP.](https://github.com/ossrs/srs/pull/4333/commits/562e76b90469a1b016857eb23b090e8e45b52de3)
---------
Co-authored-by: Jacob Su <suzp1984@gmail.com>
Co-authored-by: winlin <winlinvip@gmail.com>
2025-07-11 20:18:40 +08:00
|
|
|
COMMAND ./configure --srt=on --gb28181=on --rtsp=on --apm=on --h265=on --hds=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
|
2022-05-23 08:31:57 +08:00
|
|
|
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
|
2021-07-17 19:48:14 +08:00
|
|
|
ENDIF ()
|
2022-05-23 08:31:57 +08:00
|
|
|
if(NOT ret EQUAL 0)
|
|
|
|
|
message(FATAL_ERROR "FAILED: ${ret}")
|
|
|
|
|
endif()
|
2021-07-17 19:48:14 +08:00
|
|
|
|
2021-07-16 22:29:51 +08:00
|
|
|
set(DEPS_LIBS ${SRS_DIR}/objs/st/libst.a
|
|
|
|
|
${SRS_DIR}/objs/openssl/lib/libssl.a
|
|
|
|
|
${SRS_DIR}/objs/openssl/lib/libcrypto.a
|
|
|
|
|
${SRS_DIR}/objs/srtp2/lib/libsrtp2.a
|
|
|
|
|
${SRS_DIR}/objs/ffmpeg/lib/libavcodec.a
|
2021-10-30 12:12:06 +08:00
|
|
|
${SRS_DIR}/objs/ffmpeg/lib/libavutil.a
|
2022-03-17 08:42:44 +08:00
|
|
|
${SRS_DIR}/objs/ffmpeg/lib/libswresample.a
|
Change the hls_aof_ratio to 2.1. v5.0.200 v6.0.101 (#3886)
In pure audio mode, there are no keyframes. Therefore, we can only rely
on the length of the slice to determine whether it should be output.
`hls_aof_ratio` is the coefficient that, once reached, will generate a
new slice.
In scenarios with video, if the `hls_aof_ratio` is too small, for
example 1.2, and the GOP (Group of Pictures) is 10 seconds, then a slice
will definitely be generated at 12 seconds. At this point, if there are
no keyframes, it will cause the next slice to start with a non-keyframe.
A safer coefficient is twice the GOP (Group of Pictures). This way, it
won't trigger incorrectly and prevent the individual transcoding of a ts
segment file.
---------
Co-authored-by: Haibo Chen <495810242@qq.com>
2023-11-19 21:50:11 +08:00
|
|
|
${SRS_DIR}/objs/opus/lib/libopus.a
|
2022-03-17 08:42:44 +08:00
|
|
|
${SRS_DIR}/objs/srt/lib/libsrt.a)
|
2021-07-16 07:29:55 +08:00
|
|
|
foreach(DEPS_LIB ${DEPS_LIBS})
|
|
|
|
|
IF (NOT EXISTS ${DEPS_LIB})
|
2021-07-17 19:48:14 +08:00
|
|
|
MESSAGE(FATAL_ERROR "${DEPS_LIB} not found")
|
2021-07-16 07:29:55 +08:00
|
|
|
ELSE ()
|
|
|
|
|
MESSAGE("${DEPS_LIB} is ok")
|
|
|
|
|
ENDIF ()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
###########################################################
|
2022-03-17 16:56:52 +08:00
|
|
|
# For whole project.
|
2021-07-16 22:29:51 +08:00
|
|
|
INCLUDE_DIRECTORIES(${SRS_DIR}/objs
|
|
|
|
|
${SRS_DIR}/objs/st
|
|
|
|
|
${SRS_DIR}/objs/openssl/include
|
|
|
|
|
${SRS_DIR}/objs/srtp2/include
|
|
|
|
|
${SRS_DIR}/objs/ffmpeg/include
|
2022-03-17 08:42:44 +08:00
|
|
|
${SRS_DIR}/objs/srt/include
|
2021-07-16 22:29:51 +08:00
|
|
|
${SRS_DIR}/src/core
|
|
|
|
|
${SRS_DIR}/src/kernel
|
|
|
|
|
${SRS_DIR}/src/protocol
|
|
|
|
|
${SRS_DIR}/src/app
|
2022-04-16 08:05:30 +08:00
|
|
|
${SRS_DIR}/src/service)
|
2021-07-16 22:29:51 +08:00
|
|
|
|
2022-03-17 16:56:52 +08:00
|
|
|
# Common used sources for SRS and utest.
|
2021-07-16 22:29:51 +08:00
|
|
|
AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/core SOURCE_FILES)
|
|
|
|
|
AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/kernel SOURCE_FILES)
|
|
|
|
|
AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/protocol SOURCE_FILES)
|
|
|
|
|
AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/app SOURCE_FILES)
|
2015-01-20 18:33:04 +08:00
|
|
|
|
2022-11-23 09:24:34 +08:00
|
|
|
ADD_DEFINITIONS("-g -O0 -fsanitize=address -fno-omit-frame-pointer")
|
2014-09-26 11:05:45 +08:00
|
|
|
|
2022-03-17 16:56:52 +08:00
|
|
|
###########################################################
|
|
|
|
|
# Setup SRS project
|
|
|
|
|
|
|
|
|
|
set(SRS_SOURCE_FILES ${SOURCE_FILES})
|
|
|
|
|
list(APPEND SRS_SOURCE_FILES ${SRS_DIR}/src/main/srs_main_server.cpp)
|
|
|
|
|
|
|
|
|
|
ADD_EXECUTABLE(srs ${SRS_SOURCE_FILES})
|
2014-09-26 11:05:45 +08:00
|
|
|
TARGET_LINK_LIBRARIES(srs dl)
|
2021-07-16 07:29:55 +08:00
|
|
|
TARGET_LINK_LIBRARIES(srs ${DEPS_LIBS})
|
2021-10-30 12:12:06 +08:00
|
|
|
TARGET_LINK_LIBRARIES(srs -ldl -pthread)
|
2022-10-21 23:30:43 +08:00
|
|
|
TARGET_LINK_LIBRARIES(srs -rdynamic)
|
2022-11-23 16:43:52 +08:00
|
|
|
TARGET_LINK_LIBRARIES(srs -fsanitize=address -fno-omit-frame-pointer)
|
2014-09-26 11:05:45 +08:00
|
|
|
|
2022-03-17 16:56:52 +08:00
|
|
|
###########################################################
|
|
|
|
|
# For utest.
|
|
|
|
|
# See https://google.github.io/googletest/quickstart-cmake.html
|
|
|
|
|
# See https://stackoverflow.com/a/21479008/17679565
|
|
|
|
|
ADD_SUBDIRECTORY(${SRS_DIR}/3rdparty/gtest-fit gtest-fit)
|
|
|
|
|
INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
|
|
|
|
|
|
|
|
|
INCLUDE_DIRECTORIES(${SRS_DIR}/src/utest)
|
|
|
|
|
set(UTEST_SOURCE_FILES ${SOURCE_FILES})
|
|
|
|
|
AUX_SOURCE_DIRECTORY(${SRS_DIR}/src/utest UTEST_SOURCE_FILES)
|
|
|
|
|
|
|
|
|
|
ADD_EXECUTABLE(utest ${UTEST_SOURCE_FILES})
|
|
|
|
|
TARGET_LINK_LIBRARIES(utest gtest gtest_main)
|
|
|
|
|
TARGET_LINK_LIBRARIES(utest dl)
|
|
|
|
|
TARGET_LINK_LIBRARIES(utest ${DEPS_LIBS})
|
|
|
|
|
TARGET_LINK_LIBRARIES(utest -ldl -pthread)
|
2022-11-23 09:24:34 +08:00
|
|
|
TARGET_LINK_LIBRARIES(utest -fsanitize=address -fno-omit-frame-pointer)
|
2022-03-17 16:56:52 +08:00
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
|
# Done
|
2025-03-21 19:15:05 +08:00
|
|
|
MESSAGE(STATUS "@see https://ossrs.net/lts/zh-cn/docs/v7/doc/ide")
|
2014-10-08 13:53:04 +08:00
|
|
|
|