test(smoke): add live srs forward smoke script

This commit is contained in:
2026-03-11 14:47:21 +08:00
parent f59abb2a32
commit 058226fea2
2 changed files with 323 additions and 165 deletions
+90 -165
View File
@@ -4,201 +4,126 @@
**OPTIONAL / NON-BLOCKING**
This document provides optional interoperability checks for SRS (Simple Realtime Server). These checks are not mandatory for acceptance. If the SRS environment is unavailable, skip these tests without failing the mandatory acceptance criteria.
Use these checks when you want to verify RTMP interoperability or a real cvmmap-to-SRS forward path. They are not part of the mandatory acceptance matrix.
---
## Covered Paths
## Purpose
Validate RTMP streaming interoperability with SRS, specifically for:
- RTMP H.264 publishing and playback
- Enhanced RTMP HEVC (H.265) via [Enhanced RTMP spec](https://github.com/veovera/enhanced-rtmp)
- Low-latency streaming configurations
---
- Synthetic RTMP smoke using `rtmp_output_tester`
- Live cvmmap ingest -> FFmpeg encoder -> RTMP -> SRS HTTP-FLV forward
## Prerequisites
- Docker (recommended) or SRS built from source
- FFmpeg or the project streaming binary
- Optional: ffplay, VLC for playback verification
- Project built under `./build`
- Local SRS checkout at `~/Code/srs`, or override `SRS_ROOT`
- `ffprobe`, `ffmpeg`, and `curl` available in `PATH`
- For the live test, a running cvmmap producer. Pass the URI explicitly.
---
## Reproducible Test: Synthetic RTMP Matrix
## Quick Start (Docker)
This is the fast interoperability smoke for the RTMP sink implementations:
```bash
# Run SRS with RTMP support
docker run --rm -it -p 1935:1935 -p 8080:8080 ossrs/srs:6 \
./objs/srs -c conf/rtmp.conf
# For HEVC support, use hevc.flv.conf or hevc.ts.conf
docker run --rm -it -p 1935:1935 -p 8080:8080 ossrs/srs:6 \
./objs/srs -c conf/hevc.flv.conf
cmake -B build -S .
cmake --build build
./scripts/rtmp_srs_smoke.sh
```
---
## Smoke Commands
### 1. Basic RTMP H.264 Stream Test
Useful overrides:
```bash
# Publish test stream to SRS
ffmpeg -re -f lavfi -i testsrc=duration=60:size=1280x720:rate=30 \
-f lavfi -i sine=frequency=1000:duration=60 \
-pix_fmt yuv420p -c:v libx264 -preset fast -b:v 3000k \
-c:a aac -b:a 128k -f flv rtmp://localhost/live/smoke_test
ENCODER_DEVICE=nvidia ./scripts/rtmp_srs_smoke.sh
SRS_ROOT=~/Code/srs ./scripts/rtmp_srs_smoke.sh
```
What it verifies:
- `libavformat` RTMP output with `h264`
- `ffmpeg_process` RTMP output with `h264`
- `libavformat` RTMP output with `h265`
- `ffmpeg_process` RTMP output with `h265`
- Pullback from SRS HTTP-FLV with `ffprobe`
## Reproducible Test: Live cvmmap Forward
This is the end-to-end live test for a real cvmmap source:
```bash
# Playback verification
ffplay rtmp://localhost/live/smoke_test
cmake -B build -S .
cmake --build build
./scripts/live_srs_forward_smoke.sh 'cvmmap://zed@/tmp/cvmmap'
```
### 2. Enhanced RTMP HEVC (H.265) Test
The script defaults to:
**Prerequisites:**
- SRS 6.0.4+ with HEVC configuration
- FFmpeg 6.0+ with libx265 and enhanced RTMP support (or use `ossrs/srs:encoder` Docker image)
- `CODEC=h264`
- `ENCODER_BACKEND=ffmpeg`
- `ENCODER_DEVICE=nvidia`
- `RTMP_TRANSPORT=libavformat`
- `RTMP_MODE=enhanced`
- `INGEST_MAX_FRAMES=120`
- `STREAM_NAME=<instance>_live`, derived from `INPUT_URI`
Useful overrides:
```bash
# Publish HEVC stream (Enhanced RTMP)
ffmpeg -re -f lavfi -i testsrc=duration=60:size=1280x720:rate=30 \
-f lavfi -i sine=frequency=1000:duration=60 \
-pix_fmt yuv420p -c:v libx265 -preset fast -b:v 2000k \
-c:a aac -b:a 128k -f flv rtmp://localhost/live/smoke_hevc
# Alternative using project binary (if HEVC enabled)
# ./cvmmap-streamer --output rtmp://localhost/live/smoke_hevc --codec hevc
INPUT_URI='cvmmap://zed@/tmp/cvmmap' ./scripts/live_srs_forward_smoke.sh
./scripts/live_srs_forward_smoke.sh 'cvmmap://front_cam@/tmp/cvmmap' front_cam_smoke
ENCODER_DEVICE=software ./scripts/live_srs_forward_smoke.sh 'cvmmap://zed@/tmp/cvmmap'
STREAM_NAME=zed_test INGEST_MAX_FRAMES=300 ./scripts/live_srs_forward_smoke.sh 'cvmmap://zed@/tmp/cvmmap'
SRS_ROOT=~/Code/srs ./scripts/live_srs_forward_smoke.sh 'cvmmap://zed@/tmp/cvmmap'
```
```bash
# Playback HEVC stream
ffplay rtmp://localhost/live/smoke_hevc
What it does:
1. Reuses a healthy local SRS instance if one is already listening on `127.0.0.1:1985`
2. Otherwise starts SRS from `~/Code/srs`
3. Writes a temporary SRS config with:
- `daemon off`
- `max_connections` reduced to avoid the common local `ulimit -n 1024` failure
4. Publishes the cvmmap stream to `rtmp://127.0.0.1/live/<stream>`
5. Verifies the forwarded HTTP-FLV mount at `http://127.0.0.1:8080/live/<stream>.flv`
6. Attempts to decode a short sample through `ffmpeg`
7. Stores logs and probe output under `build/live_srs_forward_smoke_*`
Expected success signals:
- The script exits `0`
- `ffprobe_httpflv.log` reports the expected codec and dimensions
- `streamer.log` shows `RTMP_OUTPUT_READY`
- `streamer.log` ends with `PIPELINE_METRICS` and `RTMP_OUTPUT_METRICS`
The HTTP-FLV probe is the authoritative pass/fail signal. The optional `ffmpeg` decode sample is best-effort because a very short bounded publish can disappear before the second client attaches.
## Example Live Result
For a ZED source running at `cvmmap://zed@/tmp/cvmmap`, the successful forward probe looked like:
```text
index=0
codec_name=h264
width=1280
height=720
avg_frame_rate=30/1
```
### 3. Low-Latency Configuration
## Artifacts
For minimal latency with SRS, use this configuration snippet:
Both smoke scripts write evidence under `build/`:
```bash
# rtmp.conf with low-latency settings
listen 1935;
chunk_size 128;
vhost __defaultVhost__ {
# Disable merged-read for lower latency
publish {
mr off;
mr_latency 100;
}
play {
# Disable GOP cache for lower latency (may cause startup delay)
gop_cache off;
# Reduce queue length
queue_length 5;
# Enable TCP_NODELAY
tcp_nodelay on;
# Reduce merged-write latency
mw_latency 100;
mw_msgs 1;
}
}
```
**Caveats for low-latency mode:**
- `gop_cache off` means players wait for next I-frame (startup delay)
- Lower `mw_latency` increases CPU usage
- Network jitter may cause more visible artifacts
---
## HEVC Compatibility Notes
### Enhanced RTMP (Standard)
SRS 6.0+ supports HEVC via the [Enhanced RTMP](https://github.com/veovera/enhanced-rtmp) specification:
- Uses FourCC `hvc1` for HEVC
- Supported by FFmpeg 6.0+ without patches
- Supported by OBS 29+
### Domestic HEVC Extension
Some older systems use the domestic HEVC FLV extension (code 12):
- Requires patched FFmpeg for some versions
- SRS supports both formats but prefers Enhanced RTMP
- When using FFmpeg 4.x/5.x, you may need the [runner365 patch](https://github.com/runner365/ffmpeg_rtmp_h265)
**Recommendation:** Use FFmpeg 6.0+ or the `ossrs/srs:encoder` Docker image to avoid compatibility issues.
---
## Environment Variable Overrides
SRS supports environment variable configuration:
```bash
# Override listen port
docker run --rm -it -p 1935:1935 -e SRS_LISTEN=1935 ossrs/srs:6 \
./objs/srs -c conf/rtmp.conf
# Enable low latency for all vhosts
docker run --rm -it -p 1935:1935 \
-e SRS_VHOST_PUBLISH_MR=off \
-e SRS_VHOST_PLAY_GOP_CACHE=off \
-e SRS_VHOST_PLAY_MW_LATENCY=100 \
ossrs/srs:6 \
./objs/srs -c conf/rtmp.conf
```
---
## Health Check
```bash
# Check SRS HTTP API (if enabled)
curl http://localhost:8080/api/v1/versions
# Check stream statistics
curl http://localhost:8080/api/v1/streams
```
---
## Missing Server Environment Behavior
If SRS is not available or the Docker container fails to start:
1. **SKIP** - Do not fail mandatory acceptance
2. **Log** - Document the environment issue
3. **Continue** - Proceed with other tests
Example skip condition:
```bash
if ! docker run --rm -p 1935:1935 ossrs/srs:6 true 2>/dev/null; then
echo "SRS environment unavailable - skipping smoke tests"
exit 0
fi
```
---
- `srs-smoke.log`
- `live_srs_forward_smoke_*/streamer.log`
- `live_srs_forward_smoke_*/ffprobe_httpflv.log`
- `live_srs_forward_smoke_*/ffmpeg_decode_httpflv.log`
- `live_srs_forward_smoke_*/srs_api_streams.json`
## Troubleshooting
| Issue | Solution |
|-------|----------|
| Connection refused | Check port 1935 is not in use; verify SRS started |
| Stream not found | Verify app/stream name matches; check SRS logs |
| HEVC playback fails | Ensure player supports HEVC (Chrome 105+, ffplay, VLC 3.0+) |
| High latency | Disable gop_cache, reduce mw_latency/mr_latency |
| Artifacts in stream | Check encoder settings; verify network stability |
---
| Issue | Cause | Action |
|-------|-------|--------|
| SRS exits immediately | `max_connections` too high for local `ulimit` | Use the script-generated config or raise `ulimit -n` |
| HTTP-FLV never mounts | Publish failed or source is idle | Check `streamer.log` and confirm the cvmmap URI is active |
| NVENC unavailable | FFmpeg cannot open `h264_nvenc` / `hevc_nvenc` | Set `ENCODER_DEVICE=software` |
| RTMP probe hangs | Live RTMP playback probe can block on some builds | Use the HTTP-FLV verification path; this is what the script treats as authoritative |
## References