Skip to content

Commit 3663a8e

Browse files
Proxy: Refactor server APIs and expand RTMP test coverage. v7.0.147 (#4672)
This PR refactors the Go proxy server internals and significantly expands RTMP/proxy verification coverage. - Rename internal/protocol to internal/server to better describe the package responsibility. - Refactor proxy server constructors and types toward cleaner exported interfaces: - NewRTMPServer - NewWebRTCServer - NewHTTPAPIServer - NewHTTPStreamServer - NewSystemAPI - Expose RTMP protocol interfaces for better testability: - Handshake - Protocol - Message - AMF0 public interfaces such as Amf0Any, Amf0Number, Amf0String, Amf0Object, etc. - Add RTMP unit tests covering AMF0, handshake, protocol messages, packet encoding/decoding, and API examples. - Add generated RTMP fakes for interface-based tests. - Add proxy E2E scripts for: - multi-origin memory load-balancer routing - Redis multi-proxy routing - RTMP transmuxing verification across RTMP, HTTP-FLV, HLS, and optional WebRTC WHEP - Update OpenClaw/SRSBot development docs and memory to reflect the new package layout, new verification scripts, and unsupported origin/edge development scope. --------- Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
1 parent d869643 commit 3663a8e

23 files changed

Lines changed: 4059 additions & 277 deletions

.openclaw/memory/srs-codebase-map.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ The next-generation server (`cmd/` + `internal/`) is written in Go and maintaine
215215

216216
`internal/bootstrap` — Server startup and lifecycle orchestration. Sets up logging context, signal handlers, loads environment, installs force-quit timer, optionally starts pprof, initializes the load balancer (memory or Redis based on `PROXY_LOAD_BALANCER_TYPE`), then starts all six servers sequentially (RTMP, WebRTC, HTTP API, SRT, System API, HTTP Stream) and blocks until context is cancelled. Deferred `Close()` on each server ensures graceful shutdown.
217217

218-
`internal/protocol` — Protocol proxy servers. Each server accepts client connections, parses just enough of the protocol to extract the stream URL, picks a backend via the load balancer, and proxies traffic bidirectionally. Contains five proxy servers: (1) **RTMP proxy** (`rtmp.go`) — TCP listener, simple handshake, parses connect/publish/play to get stream URL, bidirectional RTMP message copying, stateless. (2) **HTTP stream proxy** (`http.go`) — serves static files, proxies HTTP-FLV/TS via reverse-proxy, proxies HLS m3u8 with `spbhid` rewriting so TS segment requests route to the same backend. (3) **WebRTC proxy** (`rtc.go`) — two-phase: WHIP/WHEP signaling (SDP rewrite to replace backend UDP port with proxy's) + UDP media transport (identifies connections by STUN ufrag, supports address migration), stateful. (4) **SRT proxy** (`srt.go`) — intercepts SRT 4-step handshake locally, parses stream ID on handshake 2, replays full handshake with backend, then proxies UDP bidirectionally, stateful per-connection. (5) **HTTP API + System API** (`api.go`) — HTTP API delegates WHIP/WHEP to WebRTC server; System API provides `/api/v1/srs/register` where backend SRS C++ servers register themselves so the load balancer knows about them.
218+
`internal/server` — Proxy server implementations. Each server accepts client connections, parses just enough of the protocol to extract the stream URL, picks a backend via the load balancer, and proxies traffic bidirectionally. Contains five proxy servers: (1) **RTMP proxy** (`rtmp.go`) — TCP listener, simple handshake, parses connect/publish/play to get stream URL, bidirectional RTMP message copying, stateless. (2) **HTTP stream proxy** (`http.go`) — serves static files, proxies HTTP-FLV/TS via reverse-proxy, proxies HLS m3u8 with `spbhid` rewriting so TS segment requests route to the same backend. (3) **WebRTC proxy** (`rtc.go`) — two-phase: WHIP/WHEP signaling (SDP rewrite to replace backend UDP port with proxy's) + UDP media transport (identifies connections by STUN ufrag, supports address migration), stateful. (4) **SRT proxy** (`srt.go`) — intercepts SRT 4-step handshake locally, parses stream ID on handshake 2, replays full handshake with backend, then proxies UDP bidirectionally, stateful per-connection. (5) **HTTP API + System API** (`api.go`) — HTTP API delegates WHIP/WHEP to WebRTC server; System API provides `/api/v1/srs/register` where backend SRS C++ servers register themselves so the load balancer knows about them.
219219

220220
`internal/rtmp` — RTMP protocol implementation (parsing, not proxying). Full RTMP chunk stream and message protocol: simple handshake (C0/C1/C2), chunk stream reader/writer with all four format types, extended timestamp, message reassembly from chunks. Defines all RTMP message types, chunk stream IDs, and command names. Packet types include ConnectApp, CreateStream, Publish, Play, Call, SetChunkSize, WindowAcknowledgementSize, SetPeerBandwidth, UserControl. Uses Go generics (`ExpectPacket[T]`) to read until a specific packet type arrives. Also includes full AMF0 encoder/decoder supporting Number, Boolean, String, Object, Null, Undefined, EcmaArray, StrictArray, Date, LongString — with ordered key-value maps, auto-type-discovery, and safe type converters.
221221

@@ -301,6 +301,9 @@ The knowledge base (`memory/srs-*.md`) captures William's knowledge about SRS
301301
- `proxy-load-balancer.md` — Load balancer design: memory vs Redis implementations, stream-to-server mapping, server health via heartbeats, protocol-specific state
302302
- `proxy-origin-cluster.md` — Origin cluster tutorial: build proxy + SRS, configure multi-origin with proxy, stream publishing and playback verification
303303

304+
**Next-Generation Server API Examples** — Executable API documentation:
305+
- `internal/rtmp/example_test.go` — RTMP API examples: AMF0, handshake, and protocol workflow
306+
304307
## Testing and Verification Structure
305308

306309
How to verify SRS works correctly.
@@ -343,6 +346,13 @@ How to verify SRS works correctly.
343346
- Reconnecting Load Test
344347
- Janus
345348

349+
`.openclaw/skills/srs-develop/scripts/` — Go proxy verification scripts:
350+
- `proxy-utest.sh` — Runs Go proxy unit tests with optional coverage.
351+
- `proxy-e2e-test.sh` — Single-origin RTMP proxy E2E test.
352+
- `proxy-e2e-cluster-test.sh` — Multi-origin memory load-balancer E2E test.
353+
- `proxy-e2e-redis-test.sh` — Multi-proxy Redis load-balancer E2E test.
354+
- `proxy-e2e-transmux-test.sh` — RTMP publish through proxy, then verify RTMP, HTTP-FLV, HLS, and WebRTC playback.
355+
346356
**Summary: The Key Differences**
347357

348358
| | Unit Tests | Black-box | E2E | Benchmark |

.openclaw/memory/srs-overview.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ Which underlying transport (TCP or UDP) each protocol uses in SRS:
127127
- **RTSP** — TCP. SRS only supports TCP transport (no UDP/RTP interleaved).
128128
- **GB28181** — TCP. PS stream over TCP.
129129

130+
Related transport protocols that are important in the media industry but **not supported by SRS or Oryx**:
131+
132+
- **RIST** — UDP. Reliable Internet Stream Transport. Similar to SRT: a reliable, low-latency media transport over UDP, with retransmission and encryption options.
133+
- **MoQ** — UDP/QUIC. Media over QUIC. An IETF effort for low-latency media ingest and delivery over QUIC, usually over UDP and optionally through WebTransport.
134+
- **WebTransport** — UDP/QUIC, HTTP/3-based. A browser and network transport API/protocol that can carry media data, and one possible substrate for MoQ.
135+
130136
## Most Common Usage
131137

132138
The simplest way to use SRS: publish an RTMP stream and play it.
@@ -292,4 +298,3 @@ Config files are in the `conf/` folder. Key files:
292298
- Other files exist for specific features like clustering, DVR, or different protocols.
293299

294300
SRS also supports configuration via environment variables. This is especially useful for Docker and cloud-native deployments — you can set environment variables in YAML files or other platforms without needing a separate config file. It's convenient to copy and paste, making documentation clearer. In the SRS docs, environment variables are often used to show how to run SRS with different configurations.
295-

.openclaw/skills/srs-develop/SKILL.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: srs-develop
3-
description: Develop, modify, debug, and maintain the next-generation SRS media server written in Go — including the proxy, origin, and edge servers. This is the AI-maintained successor to the first-generation C++ SRS server. Use for all development tasks, for example, adding features, fixing bugs, refactoring code, understanding code architecture, reviewing changes, and writing tests for the Go codebase. NOT for end-user support, usage questions, configuration help, or learning how to use SRS — use the srs-support skill for those. Only activate when the task is explicitly about developing or modifying the Go SRS codebase.
3+
description: Develop, modify, debug, and maintain the next-generation SRS media server written in Go. This is the AI-maintained successor to the first-generation C++ SRS server. Currently, planned changes are supported for the Go proxy server only; the next-generation Go origin and edge server workflows are not yet supported. Use for all development tasks, for example, adding features, fixing bugs, refactoring code, understanding code architecture, reviewing changes, and writing tests for the Go codebase. NOT for end-user support, usage questions, configuration help, or learning how to use SRS — use the srs-support skill for those. Only activate when the task is explicitly about developing or modifying the Go SRS codebase.
44
---
55

66
# SRS Development
@@ -100,7 +100,7 @@ Do NOT attempt unsupported tasks.
100100
| Service | Route To | Status |
101101
|---|---|---|
102102
| **Proxy server** |[Proxy Server](#proxy-server) | ✅ Supported |
103-
| **Origin server** |[Origin Server](#origin-server) | ✅ Supported |
103+
| **Origin server** |[Origin Server](#origin-server) | ❌ Not yet supported |
104104
| **Edge server** |[Edge Server](#edge-server) | ❌ Not yet supported |
105105

106106
**If the routed service is not yet supported**, stop and tell the user:
@@ -143,17 +143,30 @@ Only after the user confirms the routing do you proceed to Step 2.
143143
```
144144
bash scripts/proxy-utest.sh --coverage
145145
```
146-
4. Run the proxy E2E test (starts proxy + SRS origin, publishes RTMP, verifies playback):
146+
4. Run the proxy E2E tests:
147+
- Single-origin RTMP proxy test (starts proxy + one SRS origin, publishes RTMP, verifies playback):
147148
```
148149
bash scripts/proxy-e2e-test.sh
149150
```
151+
- Multi-origin cluster routing test (starts proxy + two SRS origins, publishes multiple streams, verifies streams are assigned to different origins):
152+
```
153+
bash scripts/proxy-e2e-cluster-test.sh
154+
```
155+
- Redis multi-proxy routing test (requires local Redis; starts two proxy instances with Redis LB, publishes through one proxy, verifies playback through the other):
156+
```
157+
bash scripts/proxy-e2e-redis-test.sh
158+
```
159+
- RTMP transmuxing test (starts proxy + one SRS origin, publishes RTMP, verifies RTMP/HTTP-FLV/HLS playback, and verifies WebRTC WHEP playback when `PROXY_TRANSMUX_TEST_RTC=on`):
160+
```
161+
bash scripts/proxy-e2e-transmux-test.sh
162+
```
150163
5. If any tests fail, fix the issues and re-run until all tests pass.
151164

152165
All script paths are relative to this skill's directory.
153166

154167
### Origin Server
155168

156-
*(workflow steps to be defined)*
169+
**Not yet supported.** This refers to the next-generation Go origin server workflow. The first-generation C++ origin server still exists, but it is in maintenance mode and only bug fixes are accepted there.
157170

158171
### Edge Server
159172

0 commit comments

Comments
 (0)