Skip to content

Commit c51fbe1

Browse files
committed
[*] add opus coder
1 parent 8daea90 commit c51fbe1

File tree

10 files changed

+579
-74
lines changed

10 files changed

+579
-74
lines changed

Cargo.lock

Lines changed: 11 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ tokio-stream = "0.1"
117117
audiopus = "0.3.0-rc.0"
118118
derive_builder = "0.20"
119119
wayland-client = "0.31"
120-
job_scheduler_ng = "2.4"
121120
fast_image_resize = "5.3"
122121
wayland-protocols = "0.32"
123122
wayland-protocols-wlr = "0.3"

lib/wrtc/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@ http.workspace = true
1212
bytes.workspace = true
1313
anyhow.workspace = true
1414
webrtc.workspace = true
15-
chrono.workspace = true
16-
fdk-aac.workspace = true
1715
bytesio.workspace = true
1816
indexmap.workspace = true
1917
audiopus.workspace = true
2018
byteorder.workspace = true
2119
thiserror.workspace = true
2220
derive_setters.workspace = true
23-
job_scheduler_ng.workspace = true
2421
tokio = { workspace = true, features = ["full"] }
2522
cutil = { workspace = true, features = ["crypto"] }
26-
serde = { workspace = true, features = ["derive", "rc"] }
23+
serde = { workspace = true, features = ["derive"] }
2724

2825
[dev-dependencies]
26+
image.workspace = true
27+
hound.workspace = true
2928
env_logger.workspace = true
3029
serde_json.workspace = true
30+
31+
[target.'cfg(target_os = "linux")'.dev-dependencies]
32+
video-encoder = { workspace = true, features = ["x264"] }
33+
34+
[target.'cfg(target_os = "windows")'.dev-dependencies]
35+
video-encoder = { workspace = true, features = ["ffmpeg"] }

lib/wrtc/examples/README.md

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,54 @@
1-
A WebRTC server implementation that streams H264 video files to WHEP clients.
1+
# WRTC Examples
22

3-
### Basic Usage
3+
This directory contains example programs demonstrating various features of the wrtc library.
44

5-
```bash
6-
# Run with default settings (creates test file if needed)
7-
cargo run --example whep_demo
8-
```
5+
## Opus Codec Demo
96

10-
### Advanced Usage
7+
The `opus_demo.rs` example demonstrates how to use the Opus audio codec for encoding and decoding audio data.
118

12-
```bash
13-
# With custom H264 file
14-
H264_FILE_PATH=/path/to/your/video.h264 cargo run --example whep_demo
15-
16-
# With custom settings
17-
WRTC_SERVER_ADDRESS=0.0.0.0:9090 \
18-
H264_FPS=25 \
19-
WRTC_APP_NAME=live \
20-
WRTC_STREAM_NAME=my_stream \
21-
cargo run --example whep_demo
22-
```
9+
### Features
2310

24-
### Environment Variables
11+
- Reads WAV audio files
12+
- Encodes audio data using Opus codec
13+
- Decodes encoded audio back to PCM
14+
- Writes decoded audio to new WAV file
15+
- Shows compression ratio statistics
16+
- Comprehensive logging with env_logger
2517

26-
- `WRTC_SERVER_ADDRESS`: Server bind address (default: `127.0.0.1:8080`)
27-
- `H264_FILE_PATH`: Path to H264 file (default: `./test_video.h264`)
28-
- `H264_FPS`: Frames per second for playback (default: `30`)
29-
- `WRTC_APP_NAME`: WebRTC app name (default: `live`)
30-
- `WRTC_STREAM_NAME`: WebRTC stream name (default: `test_stream`)
18+
### Usage
3119

3220
```bash
33-
RUST_LOG=debug WRTC_SERVER_ADDRESS=0.0.0.0:9090 H264_FILE_PATH=/home/blue/Code/rust/wayshot/lib/wrtc/data/test.h264 cargo run --example whep_demo
21+
# Run with default logging (info level)
22+
cargo run --example opus_demo
23+
24+
# Run with debug logging for detailed frame information
25+
RUST_LOG=debug cargo run --example opus_demo
26+
27+
# Run with only warnings and errors
28+
RUST_LOG=warn cargo run --example opus_demo
29+
30+
# Run with custom log filtering
31+
RUST_LOG=opus_demo=debug cargo run --example opus_demo
3432
```
33+
34+
### What it does
35+
36+
1. **Reads** `data/test.wav` (48kHz, stereo, 5 seconds)
37+
2. **Encodes** audio to Opus packets (250 frames)
38+
3. **Decodes** Opus packets back to audio
39+
4. **Saves** result to `/tmp/opus-coder.wav`
40+
5. **Shows** compression statistics (~31:1 compression ratio)
41+
42+
### Dependencies
43+
44+
- `hound` - WAV file I/O
45+
- `env_logger` - Structured logging
46+
- `log` - Logging facade
47+
- `wrtc::opus` - Opus codec implementation
48+
49+
### Log Levels
50+
51+
- **INFO**: Basic progress information (default)
52+
- **DEBUG**: Detailed frame-by-frame encoding/decoding info
53+
- **WARN**: Error messages for failed operations
54+
- **ERROR**: Critical errors that stop execution

0 commit comments

Comments
 (0)