mirror of
https://github.com/ossrs/srs.git
synced 2026-10-24 09:59:20 +03:00
Adds `srs-integ`, a black-box integration suite for the SRS media server, and fixes the SRS bugs it found: over 120 of them, in every protocol. The suite tests SRS from outside the process, only through what a client, an operator or a callback server can see, so a rewritten server could pass the same cases. The suite now has about 1,450 cases (1,353 main and 99 timer), with no known bugs left: every bug a case found is fixed in this PR. It also removes some unused features, adds env support for a few more directives, and changes a few hook and API fields. ## srs-integ suite `cmd/integ` is a Go module of its own, `srs-integ`, separate from the root `srsx` module. It imports nothing from the repository. - **Run:** `make integ` makes the test media, then runs the cases in two `go test` processes at once: the main cases and the `TestTimer_` cases. `make integ-unit` runs the unit tests of the clients and analyzers, and `bin/srs-integ` gives `probe`, `publish` and `prepare` from the command line. - **Server adapter:** each server is `objs/srs -e`, configured only by env vars, on ports from `SRS_INTEG_PORTS` (14000-14999 in the Port Plan). Most cases share a Common server, split into 4 shards. Cases that need other settings run on variant servers, and groups share these where they can. - **Case classes:** Fast (≤100ms), Normal (≤500ms) and Timer (≤10s, only in `TestTimer_` groups). A case that runs over its limit fails. `KnownBug` marks a case that fails because of an SRS bug, and the case fails once the bug is fixed, so the mark can't go stale. - **Clients and analyzers written for the suite:** RTMP and RTMPS (both handshakes, any chunk size, enhanced RTMP, malformed input), FLV, TS, AAC/MP3, MP4, HLS (TS, fMP4, AES-128, SAMPLE-AES) and DASH. Each one fills a shared stream report: codecs, picture size, sequence headers, keyframes, timestamps and A/V sync. - **Clients built on libraries:** WebRTC WHIP/WHEP on pion (UDP and TCP, NACK/RTX/TWCC recorder, raw DTLS sessions), SRT on gosrt, RTSP on gortsplib, and a GB28181 PS-over-RTP publisher with no SIP. - **Test media:** generated from `doc/source.flv` by `make integ-prepare` and never committed. The files cover H.264, HEVC, VP9, AV1, AAC, Opus, MP3 and G.711, in FLV, MP4 and TS. A manifest keeps the media from being made again when nothing changed. - **Feature coverage:** the HTTP API, HTTPS API and exporter, reload, heartbeat, RTMP, RTMPS, HTTP-FLV, HTTP-TS, HTTP AAC and MP3, HTTPS, HLS, DASH, WebRTC, SRT, RTSP, GB28181, the MPEG-TS over UDP caster, every HTTP hook, security rules, forward, edge, the origin cluster, DVR, static files and VOD, signals, the command line and env settings. - **Conversion matrix:** each source (RTMP/RTMPS, WHIP, SRT, GB28181) is played by each player (RTMP, HTTP-FLV, HTTP-TS, MP3, AAC, HLS ts and fMP4, DASH, WHEP, SRT, RTSP) with each codec it can carry. The README has the matrix. - **Scale:** `-integ.scale=N` runs each case N times. A run of about 1,000 cases passes in about 11s. ## SRS bug fixes Every fix has a utest and, where a client can see it, an srs-integ case that failed before the fix. The main ones by area: - **HLS:** fMP4: - The default init file is now listed by its dir. - `hls_entry_prefix` now applies to fMP4 URIs. - MP3 streams now get an audio track in the init file. - Each publish now starts with a discontinuity. - `hls_keys` now encrypts the samples with cbcs. - A segment that fails to open is now dropped. Before, it crashed SRS. Other HLS fixes: key URIs, AES padding, HLS starts again after `hls_dispose`, the ratios, a TS republish, session names, and the `hls_ctx` of another stream's session is now checked as a new session. - **DASH:** the config, the MPD (window, update period, HEVC and MP3 codecs), init files of MP3 and of one-track streams, and dispose. - **WebRTC:** - Keyframes with an SEI, and Sender Reports and their mapping. - Opus timing, G.711, and WHEP SSRCs. - A refused WHIP publisher now frees its stream. - The start and hooks, and WebRTC over TCP. - **SRT:** only the configured latencies are set, as ffmpeg does. Also fixed: HEVC headers and CTS, frame counts, and the listener. - **RTSP:** a republish to a kept player, PLAY without SETUP, unknown methods, closes, DESCRIBE/TEARDOWN, request bodies and `on_stop`. - **GB28181:** - SSRC parsing. - HEVC to RTMP is no longer sent in legacy FLV tags. - A crash on a second media connection. - Latency with no audio, sliced frames, CTS, session lifetime, and the muxer and caster output. - **RTMP and HTTP:** - Timestamps that jump back without time correction no longer stop a player. - The republish param and the publish timeout after a pause. - The no-origin close and the RTMPS port. - HTTP ranges, including MP4 suffix ranges and VOD 416. - Redirects, mounts, unmounts and URL `..`. - CORS, API auth paths, JSONP 400 and 403 answers. - Static files and the request echo. - **Hooks:** - The heartbeat URL's query is now sent. - `on_play` clients and client types, and `on_dvr`. - A client that `on_connect` refused no longer gets `on_close`. - **Other:** DVR (MP4 info frame, audio rate, audio cut), listen ports above 65535, the env vhost check, the UDP caster, process stats, the tcmalloc rate, the encoder loop, the edge failover, STUN, coroutine joins, and the resource manager's fast-id cache (WebRTC and GB lookups never used it). ## Behavior changes - **Hooks:** - `on_publish`, `on_unpublish`, `on_play` and `on_stop` have a new `type` field after `client_id`, such as `rtmp-play` or `hls-play`, the same value as `/api/v1/clients`. - Every protocol now sends `param` with its leading `?`. - HTTP players send their own `http(s)://` tcUrl, and WHIP/WHEP clients send `webrtc://<host>/<app>`. - **API:** `/api/v1/features` adds `srt`, `rtsp`, `gb28181`, `rtc`, `simulator` and `sanitizer`. The `/api/v1/` index lists only the URLs SRS serves. - **Env support:** - The vhost security rules. - The edge protocol. - The origin cluster and coworkers. - The DVR apply filter. - **Timers in seconds:** `hls_dispose`, `dash_dispose`, `dvr_duration`, `queue_length`, `stun_timeout` and the heartbeat `interval` now accept fractions such as `0.5`. A fraction used to be cut to whole seconds, so `0.5` read as 0. - **Removed features:** a config or env var that names one of these, on or off, now makes SRS refuse to start (and `-t` fail) with `<name> is removed`: - HDS, including `--hds=on`. - The FLV POST caster and `asprocess`. - `query_latest_version` and `first_wait_for_qlv`. - The vhost `bandcheck`, `refer` and `atc_auto`. - Edge `token_traverse`. Check clients with the edge's HTTP hooks instead. ## Tests, CI and skills - **CI:** a new `integration-test` job builds `trunk/Dockerfile.test` (now with `--simulator=on`) and runs srs-integ. - It caches the test media. - It runs the main cases and the timer cases as separate steps, each retried on its own. - Limits are scaled by 4 with `-integ.limit-scale=4`. - **Unit tests:** more stable. They use random seeds, the test servers no longer share ports or leak fds, and a gtest listener fails a test that leaves a handler on a global resource manager. - **Skills:** - The `srs-develop` Gate and Full tiers run `make integ`. - `integration-tests.md` explains how to add cases. - The new `internal-audit-for-srs` skill audits each commit blind before review. --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
207 lines
8.7 KiB
Go
207 lines
8.7 KiB
Go
// Copyright (c) 2026 Winlin
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cases
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"srs-integ/internal/check"
|
|
"srs-integ/internal/media"
|
|
"srs-integ/internal/report"
|
|
"srs-integ/internal/rtc"
|
|
"srs-integ/internal/server"
|
|
)
|
|
|
|
// rtcCodec is a stream a WHIP publisher sends: its test file, the codecs it
|
|
// offers and the vcodec it asks for, and what a player reports.
|
|
type rtcCodec struct {
|
|
file string
|
|
video, audio string
|
|
vcodec string
|
|
report string
|
|
profile string
|
|
rate, channel int
|
|
}
|
|
|
|
var (
|
|
rtcHevc = rtcCodec{media.HEVCOpus, "H265", "opus", "hevc", "hevc", "Main", 48000, 2}
|
|
rtcVp9 = rtcCodec{media.VP9Opus, "VP9", "opus", "vp9", "vp9", "0", 48000, 2}
|
|
rtcAv1 = rtcCodec{media.AV1Opus, "AV1", "opus", "av1", "av1", "Main", 48000, 2}
|
|
rtcPcmu = rtcCodec{media.PCMU, "H264", "PCMU", "", "h264", "Baseline", 8000, 1}
|
|
rtcPcma = rtcCodec{media.PCMA, "H264", "PCMA", "", "h264", "Baseline", 8000, 1}
|
|
)
|
|
|
|
// audioReport is the codec of the stream's audio in a report.
|
|
func (r rtcCodec) audioReport() string {
|
|
if r.audio == "opus" {
|
|
return "opus"
|
|
}
|
|
if r.audio == "PCMU" {
|
|
return "pcmu"
|
|
}
|
|
return "pcma"
|
|
}
|
|
|
|
// everyCodec is a player that offers every codec SRS takes.
|
|
var everyCodec = rtc.Every()
|
|
|
|
// rtcCodecs adds the codec cases to TestRtc_Common: each codec SRS takes,
|
|
// published by WHIP and played by WHEP, a player that doesn't offer the
|
|
// stream's codec, and a player that comes before the publisher. SRS never
|
|
// transcodes between WebRTC sessions, so a player gets the stream's codec
|
|
// or is refused.
|
|
func rtcCodecs(t *testing.T) {
|
|
// PublishPlayHevc, PublishPlayVp9 and PublishPlayAv1 publish with
|
|
// vcodec, and PublishPlayPcmu and PublishPlayPcma offer only G.711: a
|
|
// player that offers every codec is answered with the stream's codecs
|
|
// only, and plays them.
|
|
for _, w := range []struct {
|
|
name string
|
|
rtcCodec
|
|
}{{"PublishPlayHevc", rtcHevc}, {"PublishPlayVp9", rtcVp9}, {"PublishPlayAv1", rtcAv1}, {"PublishPlayPcmu", rtcPcmu}, {"PublishPlayPcma", rtcPcma}} {
|
|
check.Case(t, w.name, check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
pub := codecPublisher(c, srs, stream, w.rtcCodec)
|
|
c.CheckEqual(fmt.Sprint(answerCodecs(pub.Answer, "video"), answerCodecs(pub.Answer, "audio")),
|
|
fmt.Sprint([]string{w.video}, []string{w.audio}), "the publisher's answer")
|
|
player := rtcPlayer(c, whepURL(srs, "live", stream), everyCodec)
|
|
c.CheckEqual(fmt.Sprint(answerCodecs(player.Answer, "video"), answerCodecs(player.Answer, "audio")),
|
|
fmt.Sprint([]string{w.video}, []string{w.audio}), "the player's answer")
|
|
sendRTCSamples(c, rtcFileSamples(c, w.file), pub, player)
|
|
checkCodecPlayed(c, w.rtcCodec, waitPlayed(c, player, rtcPlayedUntil))
|
|
})
|
|
}
|
|
|
|
// HevcToAvcOnlyPlayer, Vp9ToAvcOnlyPlayer and Av1ToAvcOnlyPlayer play a
|
|
// stream with a player that offers only H.264: refused with 400, and
|
|
// with vcodec=h264 too, while the same offer with the stream's codec is
|
|
// answered. AvcToPlayerWithoutAvc plays the WHIP file with a player that
|
|
// offers every video codec but H.264.
|
|
for _, w := range []struct {
|
|
name string
|
|
rtcCodec
|
|
}{{"HevcToAvcOnlyPlayer", rtcHevc}, {"Vp9ToAvcOnlyPlayer", rtcVp9}, {"Av1ToAvcOnlyPlayer", rtcAv1}} {
|
|
check.Case(t, w.name, check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
codecPublisher(c, srs, stream, w.rtcCodec)
|
|
offer := rtcOffer(c, false, []string{"H264"}, []string{"opus"})
|
|
rtcRefused(c, whepURL(srs, "live", stream), offer, http.StatusBadRequest)
|
|
rtcRefused(c, whepURL(srs, "live", stream)+"&vcodec=h264", offer, http.StatusBadRequest)
|
|
rtcAnswered(c, whepURL(srs, "live", stream), rtcOffer(c, false, []string{w.video}, []string{"opus"}))
|
|
})
|
|
}
|
|
|
|
check.Case(t, "AvcToPlayerWithoutAvc", check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
rtcPublisher(c, whipURL(srs, "live", stream), nil)
|
|
offer := rtcOffer(c, false, []string{"H265", "VP9", "AV1"}, []string{"opus"})
|
|
rtcRefused(c, whepURL(srs, "live", stream), offer, http.StatusBadRequest)
|
|
rtcAnswered(c, whepURL(srs, "live", stream), rtcOffer(c, false, []string{"H265", "VP9", "AV1", "H264"}, []string{"opus"}))
|
|
})
|
|
|
|
// PcmuToOpusOnlyPlayer and PcmaToOpusOnlyPlayer play a G.711 stream
|
|
// with a player that offers only Opus, and OpusToG711OnlyPlayer the
|
|
// WHIP file with one that offers only G.711: refused with 400, while the
|
|
// stream's audio codec is answered.
|
|
for _, w := range []struct {
|
|
name string
|
|
rtcCodec
|
|
}{{"PcmuToOpusOnlyPlayer", rtcPcmu}, {"PcmaToOpusOnlyPlayer", rtcPcma}} {
|
|
check.Case(t, w.name, check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
codecPublisher(c, srs, stream, w.rtcCodec)
|
|
offer := rtcOffer(c, false, []string{"H264"}, []string{"opus"})
|
|
rtcRefused(c, whepURL(srs, "live", stream), offer, http.StatusBadRequest)
|
|
rtcAnswered(c, whepURL(srs, "live", stream), rtcOffer(c, false, []string{"H264"}, []string{w.audio}))
|
|
})
|
|
}
|
|
|
|
check.Case(t, "OpusToG711OnlyPlayer", check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
rtcPublisher(c, whipURL(srs, "live", stream), nil)
|
|
offer := rtcOffer(c, false, []string{"H264"}, []string{"PCMU", "PCMA"})
|
|
rtcRefused(c, whepURL(srs, "live", stream), offer, http.StatusBadRequest)
|
|
rtcAnswered(c, whepURL(srs, "live", stream), rtcOffer(c, false, []string{"H264"}, []string{"PCMU", "opus"}))
|
|
})
|
|
|
|
// PlayBeforePublishHevc and PlayBeforePublishAv1 play with vcodec
|
|
// before the stream is published: SRS answers that codec, and the
|
|
// player gets the stream once it is published with it.
|
|
for _, w := range []struct {
|
|
name string
|
|
rtcCodec
|
|
}{{"PlayBeforePublishHevc", rtcHevc}, {"PlayBeforePublishAv1", rtcAv1}} {
|
|
check.Case(t, w.name, check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
player := rtcPlayer(c, whepURL(srs, "live", stream)+"&vcodec="+w.vcodec, everyCodec)
|
|
c.CheckEqual(fmt.Sprint(answerCodecs(player.Answer, "video")), fmt.Sprint([]string{w.video}), "the player's video")
|
|
pub := codecPublisher(c, srs, stream, w.rtcCodec)
|
|
sendRTCSamples(c, rtcFileSamples(c, w.file), pub, player)
|
|
checkCodecPlayed(c, w.rtcCodec, waitPlayed(c, player, rtcPlayedUntil))
|
|
})
|
|
}
|
|
|
|
// PlayBeforePublishDefault plays with no vcodec before the stream is
|
|
// published: SRS answers H.264, the first codec it has for a stream not
|
|
// yet published.
|
|
check.Case(t, "PlayBeforePublishDefault", check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
stream := streamName(c)
|
|
player := rtcPlayer(c, whepURL(srs, "live", stream), everyCodec)
|
|
c.CheckEqual(fmt.Sprint(answerCodecs(player.Answer, "video"), answerCodecs(player.Answer, "audio")),
|
|
fmt.Sprint([]string{"H264"}, []string{"opus"}), "the player's answer")
|
|
})
|
|
|
|
// PlayBeforePublishVp9 plays with vcodec=vp9 before the stream is
|
|
// published: refused, since SRS has tracks for H.264, HEVC and AV1 only
|
|
// for a stream not yet published, while vcodec=av1 is answered.
|
|
check.Case(t, "PlayBeforePublishVp9", check.Normal, func(c *check.C) {
|
|
srs := server.Common(c)
|
|
offer := rtcOffer(c, false, []string{"VP9", "AV1"}, []string{"opus"})
|
|
rtcRefused(c, whepURL(srs, "live", streamName(c))+"&vcodec=vp9", offer, http.StatusBadRequest)
|
|
rtcAnswered(c, whepURL(srs, "live", streamName(c))+"&vcodec=av1", offer)
|
|
})
|
|
}
|
|
|
|
// codecPublisher publishes a stream by WHIP with a codec: it offers only the
|
|
// codec's video and audio, and asks for its vcodec.
|
|
func codecPublisher(c *check.C, srs *server.Server, stream string, w rtcCodec) *rtc.Publisher {
|
|
c.Helper()
|
|
url := whipURL(srs, "live", stream)
|
|
if w.vcodec != "" {
|
|
url += "&vcodec=" + w.vcodec
|
|
}
|
|
return rtcPublisher(c, url, &rtc.Options{Video: []string{w.video}, Audio: []string{w.audio}})
|
|
}
|
|
|
|
// checkCodecPlayed checks the report of a player of a codec's stream: the
|
|
// video's codec, profile and size with one sequence header from the first
|
|
// frame, the audio's codec, rate and channels, and timestamps that only go
|
|
// forward, without gaps.
|
|
func checkCodecPlayed(c *check.C, w rtcCodec, r *report.Report) {
|
|
c.Helper()
|
|
if !c.Check(r.Video != nil && r.Audio != nil, "no video or audio: %v", r) {
|
|
return
|
|
}
|
|
v, a := r.Video, r.Audio
|
|
c.CheckEqual(v.Codec, w.report, "video codec")
|
|
c.CheckEqual(v.Profile, w.profile, "video profile")
|
|
c.Check(v.Width == 768 && v.Height == 320, "size %vx%v, want 768x320", v.Width, v.Height)
|
|
c.CheckEqual(v.SequenceHeaders, 1, "video sequence headers")
|
|
c.CheckEqual(v.LeadingFrames, 0, "frames before the first keyframe")
|
|
c.CheckEqual(a.Codec, w.audioReport(), "audio codec")
|
|
c.Check(a.SampleRate == w.rate && a.Channels == w.channel, "audio %vHz %vch, want %vHz %vch", a.SampleRate, a.Channels, w.rate, w.channel)
|
|
c.CheckNoError(r.CheckTimestamps(100*time.Millisecond), "timestamps")
|
|
}
|