|
| 1 | +# proxy-go Project Guidelines |
| 2 | + |
| 3 | +## Project Summary |
| 4 | + |
| 5 | +proxy-go is a stateless media streaming proxy with built-in load balancing for building scalable origin clusters. It supports RTMP, SRT, WebRTC (WHIP/WHEP), HLS, and HTTP-FLV protocols. |
| 6 | + |
| 7 | +Key characteristics: |
| 8 | +- Stateless design enables horizontal scaling |
| 9 | +- Built-in load balancer (memory or Redis-based) |
| 10 | +- Protocol handlers for RTMP, WebRTC, SRT, HTTP streaming |
| 11 | +- Backend origin servers register via System API |
| 12 | +- Official solution for SRS Origin Cluster |
| 13 | + |
| 14 | +## Design Overview |
| 15 | + |
| 16 | +See the "Design" section in @README.md for the complete architecture overview, including: |
| 17 | +- Stateless proxy architecture with built-in load balancing |
| 18 | +- Single Proxy Mode (memory-based) |
| 19 | +- Multi-Proxy Mode (Redis sync, AWS NLB) |
| 20 | +- Complete Cluster (Edge + Proxy + Origins) |
| 21 | + |
| 22 | +## Configuration |
| 23 | + |
| 24 | +All configuration via environment variables (`.env` file supported): |
| 25 | + |
| 26 | +### Server Listen Ports (client-facing) |
| 27 | +- `PROXY_RTMP_SERVER=11935` - RTMP media server |
| 28 | +- `PROXY_HTTP_SERVER=18080` - HTTP streaming (HLS, HTTP-FLV) |
| 29 | +- `PROXY_WEBRTC_SERVER=18000` - WebRTC server (UDP) |
| 30 | +- `PROXY_SRT_SERVER=20080` - SRT server (UDP) |
| 31 | +- `PROXY_HTTP_API=11985` - HTTP API (WHIP/WHEP) |
| 32 | +- `PROXY_SYSTEM_API=12025` - System API (origin registration) |
| 33 | + |
| 34 | +### Load Balancer Configuration |
| 35 | +- `PROXY_LOAD_BALANCER_TYPE=memory` - Use "memory" (single proxy) or "redis" (multi-proxy) |
| 36 | +- `PROXY_REDIS_HOST=127.0.0.1` |
| 37 | +- `PROXY_REDIS_PORT=6379` |
| 38 | +- `PROXY_REDIS_PASSWORD=` (empty for no password) |
| 39 | +- `PROXY_REDIS_DB=0` |
| 40 | + |
| 41 | +### Other Settings |
| 42 | +- `PROXY_STATIC_FILES=../srs/trunk/research` - Static web files directory |
| 43 | +- `PROXY_FORCE_QUIT_TIMEOUT=30s` - Force shutdown timeout |
| 44 | +- `PROXY_GRACE_QUIT_TIMEOUT=20s` - Graceful shutdown timeout |
| 45 | + |
| 46 | +## How to Run |
| 47 | + |
| 48 | +When running the project for testing or development, you should: |
| 49 | +1. Build and start the proxy server |
| 50 | +2. Publish a test stream using FFmpeg |
| 51 | +3. Verify the stream is working using ffprobe |
| 52 | + |
| 53 | +### Step 1: Build and Start Proxy Server |
| 54 | + |
| 55 | +```bash |
| 56 | +make && env PROXY_RTMP_SERVER=1935 PROXY_HTTP_SERVER=8080 \ |
| 57 | + PROXY_HTTP_API=1985 PROXY_WEBRTC_SERVER=8000 PROXY_SRT_SERVER=10080 \ |
| 58 | + PROXY_SYSTEM_API=12025 PROXY_LOAD_BALANCER_TYPE=memory ./srs-proxy |
| 59 | +``` |
| 60 | + |
| 61 | +The proxy server should start and listen on the configured ports. |
| 62 | + |
| 63 | +### Step 2: Publish a Test Stream |
| 64 | + |
| 65 | +In a new terminal, publish a test stream using FFmpeg: |
| 66 | + |
| 67 | +```bash |
| 68 | +ffmpeg -stream_loop -1 -re -i ~/git/srs/trunk/doc/source.flv -c copy -f flv rtmp://localhost/live/livestream |
| 69 | +``` |
| 70 | + |
| 71 | +> Note: `-stream_loop -1` makes FFmpeg loop the input file infinitely, ensuring the stream doesn't quit after the file ends. |
| 72 | +
|
| 73 | +### Step 3: Verify Stream with ffprobe |
| 74 | + |
| 75 | +In another terminal, use ffprobe to verify the stream is working: |
| 76 | + |
| 77 | +**Test RTMP stream:** |
| 78 | +```bash |
| 79 | +ffprobe rtmp://localhost/live/livestream |
| 80 | +``` |
| 81 | + |
| 82 | +**Test HTTP-FLV stream:** |
| 83 | +```bash |
| 84 | +ffprobe http://localhost:8080/live/livestream.flv |
| 85 | +``` |
| 86 | + |
| 87 | +Both commands should successfully detect the stream and display video/audio codec information. If ffprobe shows stream details without errors, the proxy is working correctly. |
0 commit comments