Skip to content

Commit 0d1480a

Browse files
committed
Move proxy from ossrs/proxy repo to proxy directory
Move the SRS proxy server code from the standalone repository https://github.com/ossrs/proxy into the proxy/ directory of the main SRS repo. Also update build instructions in origin-cluster.md.
1 parent a86cd7c commit 0d1480a

37 files changed

+7961
-6
lines changed

.augment-guidelines

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ architecture:
1313

1414
origin_cluster:
1515
v6_mesh: "DEPRECATED - C++ MESH mode, RTMP only"
16-
v7_proxy: "RECOMMENDED - Go-based proxy (https://github.com/ossrs/srsx/tree/main/cmd/proxy-go), all protocols, better scaling"
16+
v7_proxy: "RECOMMENDED - Go-based [proxy](./proxy/cmd/proxy-go), all protocols, better scaling"
1717

1818
codebase_structure:
1919
dirs: "trunk/src/{main,core,kernel,protocol,app}"

proxy/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea
2+
.claude
3+
.vscode
4+
5+
srs-proxy
6+
.go-formarted
7+
8+
# For AI to ignore these files.
9+
.env
10+
docs/ignore-worklog.md

proxy/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 ossrs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

proxy/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: all build test fmt clean run
2+
3+
all: build
4+
5+
build: fmt ./srs-proxy
6+
7+
./srs-proxy: cmd/proxy-go/*.go internal/**/*.go
8+
go build -o srs-proxy ./cmd/proxy-go
9+
10+
test:
11+
go test ./...
12+
13+
fmt: ./.go-formarted
14+
15+
./.go-formarted: cmd/proxy-go/*.go internal/**/*.go
16+
touch .go-formarted
17+
go fmt ./...
18+
19+
clean:
20+
rm -f srs-proxy .go-formarted
21+
22+
run: fmt
23+
go run ./cmd/proxy-go

proxy/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
# Proxy
1+
# SRSX
22

3-
Migrated to below repositoties:
3+
SRSX is the next generation of SRS (Simple Realtime Server), a media server toolkit that includes multiple programs. Currently includes a common proxy server (`cmd/proxy-go`) for any media servers with RTMP/SRT/HLS/HTTP-FLV and WebRTC/WHIP/WHEP protocols support. More programs like `cmd/origin-go` will be added in the future.
44

5-
* [srsx/cmd/proxy-go](https://github.com/ossrs/srsx/tree/main/cmd/proxy-go) An common proxy server for any media servers with RTMP/SRT/HLS/HTTP-FLV and WebRTC/WHIP/WHEP protocols support.
5+
## Usage
66

7+
This project is managed by AI. By default we use Kiro (Amazon Q) CLI, but you can use any other AI tools that read code and docs as context. Setup your AI code tool and ask questions like:
8+
9+
- How to use this project?
10+
- How to run the proxy server?
11+
- How to build an Origin Cluster for production?
12+
13+
You can not only use AI to show you the usage of this project, but also use AI to guide you to learn the details of this project, to understand the design and protocols, to learn each documents in docs directory.
14+
15+
## AI Guidelines
16+
17+
- AI assistants should ignore [docs/ignore-worklog.md](docs/ignore-worklog.md) as it's a personal work log that may contain misleading information, hallucinations, or falsehoods. Never rely on this file as a reference.
18+
- For usage of proxy server and end to end test it, you should load [docs/proxy-usage.md](docs/proxy-usage.md). This is the first step for new users to learn how to use this project. It provides a general and overall view of the proxy server, including practical usage examples and end-to-end testing procedures.
19+
- For proxy full usage to build an Origin Cluster for SRS media server, please load [docs/proxy-origin-cluster.md](docs/proxy-origin-cluster.md). This is an advanced topic about how to use the proxy server to build the SRS Origin Cluster. Users should read this document to learn more details and architectures about proxy and Origin Cluster.
20+
- For proxy server: To understand proxy system design, you should load the [docs/proxy-design.md](docs/proxy-design.md). To understand the proxy protocol details, you should load the [docs/proxy-protocol.md](docs/proxy-protocol.md). To understand how load balance works, you should load [docs/proxy-load-balancer.md](docs/proxy-load-balancer.md). To understand the code structure and packages, you should load [docs/proxy-files.md](docs/proxy-files.md).
21+
22+
William Yang<br/>
23+
June 23, 2025

proxy/cmd/proxy-go/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2025 Winlin
2+
//
3+
// SPDX-License-Identifier: MIT
4+
package main
5+
6+
import (
7+
"context"
8+
"os"
9+
10+
"proxy/internal/bootstrap"
11+
)
12+
13+
func main() {
14+
bs := bootstrap.NewBootstrap()
15+
if err := bs.Start(context.Background()); err != nil {
16+
os.Exit(-1)
17+
}
18+
}

proxy/docs/proxy-design.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Design
2+
3+
## Overview
4+
5+
**proxy-go** is a stateless media streaming proxy with built-in load balancing that enables building scalable origin clusters. The proxy itself acts as the load balancer, routing streams from clients to backend origin servers.
6+
7+
```
8+
Client → Proxy (with Load Balancer) → Backend Origin Servers
9+
```
10+
11+
Since the proxy is stateless, you can deploy multiple proxies behind a load balancer (like AWS NLB) for horizontal scaling:
12+
13+
```
14+
Client → AWS NLB → Proxy Servers → Backend Origin Servers
15+
```
16+
17+
## Deployment Modes
18+
19+
### Single Proxy Mode
20+
21+
**Use case**: Moderate amount of streams requiring multiple origin servers (each stream has few viewers). The total stream count is manageable by a single proxy server. Uses memory-based load balancing (no Redis needed).
22+
23+
**Architecture**:
24+
25+
```
26+
+--------------------+
27+
+-------+ Origin Server A +
28+
+ +--------------------+
29+
+
30+
+-----------------------+ + +--------------------+
31+
+ Proxy Server +------+-------+ Origin Server B +
32+
+ (Memory LB) + + +--------------------+
33+
+-----------------------+ +
34+
+ +--------------------+
35+
+-------+ Origin Server C +
36+
+--------------------+
37+
```
38+
39+
### Multi-Proxy Mode (Scalable)
40+
41+
**Use case**: When a single proxy becomes a bottleneck. Supports a large number of streams across many origin servers, with limited viewers per stream. Redis is required for state synchronization between proxies.
42+
43+
**Architecture**:
44+
45+
```
46+
+-----------------------+
47+
+---+ Proxy Server A +------+
48+
+-----------------+ | +-----------+-----------+ +
49+
| AWS NLB +--+ | +
50+
+-----------------+ | (Redis Sync) + Origin Servers
51+
| +-----------+-----------+ +
52+
+---+ Proxy Server B +------+
53+
+-----------------------+
54+
```
55+
56+
### Complete Cluster (Edge + Proxy + Origins)
57+
58+
**Use case**: Very large deployments with both numerous streams AND numerous viewers. Edge servers aggregate upstream connections - fetching one stream from upstream to serve multiple viewers, dramatically reducing load on proxy and origin servers.
59+
60+
**Architecture**:
61+
62+
```
63+
Edge Servers → Proxy Servers → Origin Servers
64+
(Proxy + Cache) (Proxy) (SRS/Media)
65+
```
66+
67+
> **Note**: Future edge servers will be implemented as proxy servers with caching enabled, creating a unified architecture where the same codebase serves both proxy and edge roles. The edge cache aggregates viewer connections, so thousands of viewers can watch the same stream while only requesting it once from upstream.

proxy/docs/proxy-files.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Codebase Structure
2+
3+
This document provides an overview of the Go codebase organization.
4+
5+
## Directory Structure
6+
7+
```
8+
/
9+
├── cmd/proxy-go/
10+
│ └── main.go # Application entry point
11+
└── internal/
12+
├── debug/ # Go profiling support
13+
├── env/ # Configuration management
14+
├── errors/ # Error handling with stack traces
15+
├── lb/ # Load balancer (memory/Redis)
16+
├── logger/ # Logging and request tracing
17+
├── protocol/ # Protocol servers (RTMP, HTTP, WebRTC, SRT, API)
18+
├── rtmp/ # RTMP protocol implementation
19+
├── signal/ # Graceful shutdown handling
20+
├── sync/ # Concurrency utilities
21+
├── utils/ # Common utilities
22+
└── version/ # Version information
23+
```
24+
25+
## Internal Packages
26+
27+
### debug
28+
Go profiling support via pprof, controlled by `GO_PPROF` environment variable.
29+
30+
### env
31+
Configuration management using environment variables. Loads `.env` file and provides defaults for all server settings.
32+
33+
### errors
34+
Enhanced error handling with stack traces. Provides error wrapping and root cause extraction.
35+
36+
### lb
37+
Load balancer system supporting both single-proxy (memory-based) and multi-proxy (Redis-based) deployments.
38+
- `lb.go` - Core interfaces and types
39+
- `mem.go` - Memory-based load balancer
40+
- `redis.go` - Redis-based load balancer
41+
- `debug.go` - Default backend for testing
42+
43+
### logger
44+
Structured logging with context-based request tracing. Provides log levels: Verbose, Debug, Warning, Error.
45+
46+
### protocol
47+
Protocol server implementations for all supported streaming protocols:
48+
- `rtmp.go` - RTMP protocol stack
49+
- `http.go` - HTTP streaming (HLS, HTTP-FLV, HTTP-TS)
50+
- `rtc.go` - WebRTC server (WHIP/WHEP)
51+
- `srt.go` - SRT server
52+
- `api.go` - HTTP API server
53+
54+
### rtmp
55+
Low-level RTMP protocol implementation including handshake and AMF0 serialization.
56+
57+
### signal
58+
Graceful shutdown coordination. Catches SIGINT/SIGTERM and implements timeout-based shutdown.
59+
60+
### sync
61+
Thread-safe generic Map wrapper around `sync.Map` for connection tracking and caching.
62+
63+
### utils
64+
Common utility functions for HTTP responses, JSON marshaling, and parsing.
65+
66+
### version
67+
Version information and server identification.

0 commit comments

Comments
 (0)