Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Compiled binary
belacoder
belacoder.o

# Test binaries
tests/test_balancer
tests/test_integration

# Object files
*.o

# Editor files
*.swp
*~
57 changes: 54 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
VERSION=$(shell git rev-parse --short HEAD)
CFLAGS=`pkg-config gstreamer-1.0 gstreamer-app-1.0 srt --cflags` -O2 -Wall -DVERSION=\"$(VERSION)\"
CFLAGS=`pkg-config gstreamer-1.0 gstreamer-app-1.0 srt --cflags` -O2 -Wall -DVERSION=\"$(VERSION)\" \
-I$(SRCDIR) -I$(SRCDIR)/core -I$(SRCDIR)/io -I$(SRCDIR)/net -I$(SRCDIR)/gst
LDFLAGS=`pkg-config gstreamer-1.0 gstreamer-app-1.0 srt --libs` -ldl

# Test configuration
TEST_CFLAGS=`pkg-config cmocka --cflags` $(CFLAGS) -g
TEST_LDFLAGS=`pkg-config cmocka --libs` $(LDFLAGS)

# Source directory
SRCDIR = src
TESTDIR = tests

# Object files
OBJS = $(SRCDIR)/belacoder.o \
$(SRCDIR)/io/cli_options.o \
$(SRCDIR)/io/pipeline_loader.o \
$(SRCDIR)/net/srt_client.o \
$(SRCDIR)/gst/encoder_control.o \
$(SRCDIR)/gst/overlay_ui.o \
$(SRCDIR)/core/balancer_runner.o \
$(SRCDIR)/core/bitrate_control.o \
$(SRCDIR)/core/config.o \
$(SRCDIR)/core/balancer_adaptive.o \
$(SRCDIR)/core/balancer_fixed.o \
$(SRCDIR)/core/balancer_aimd.o \
$(SRCDIR)/core/balancer_registry.o \
camlink_workaround/camlink.o

# Test object files (exclude main)
TEST_OBJS = $(filter-out $(SRCDIR)/belacoder.o, $(OBJS))

all: submodule belacoder

submodule:
git submodule init
git submodule update

belacoder: belacoder.o camlink_workaround/camlink.o
belacoder: $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)

# Compile source files (matches subdirectories too)
$(SRCDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@

# Test targets
test: submodule test_balancer test_integration

test_balancer: $(TESTDIR)/test_balancer.o $(TEST_OBJS)
$(CC) $(TEST_CFLAGS) $^ -o $(TESTDIR)/$@ $(TEST_LDFLAGS)
./$(TESTDIR)/$@

test_integration: $(TESTDIR)/test_integration.o $(TEST_OBJS)
$(CC) $(TEST_CFLAGS) $^ -o $(TESTDIR)/$@ $(TEST_LDFLAGS)
./$(TESTDIR)/$@

$(TESTDIR)/%.o: $(TESTDIR)/%.c
$(CC) $(TEST_CFLAGS) -c $< -o $@

clean:
rm -f belacoder *.o camlink_workaround/*.o
rm -f belacoder \
$(SRCDIR)/*.o $(SRCDIR)/core/*.o $(SRCDIR)/io/*.o $(SRCDIR)/net/*.o $(SRCDIR)/gst/*.o \
$(TESTDIR)/*.o $(TESTDIR)/test_balancer $(TESTDIR)/test_integration camlink_workaround/*.o

.PHONY: all submodule clean test test_balancer test_integration

67 changes: 55 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ The Makefile uses `pkg-config` to locate GStreamer and libsrt. Ensure both are i
pkg-config --modversion gstreamer-1.0 gstreamer-app-1.0 srt
```

### Testing

belacoder includes integration tests that verify module behavior without requiring actual hardware:

```bash
# Install cmocka (test framework)
sudo apt-get install libcmocka-dev

# Run all tests
make test
```

Tests verify:
- Balancer algorithm behavior (adaptive, fixed, AIMD)
- Config loading and reload
- Bitrate bounds enforcement
- Network condition responses

See [docs/architecture.md](docs/architecture.md) for details on the modular architecture and testing approach.


Usage
-----
Expand All @@ -147,31 +167,54 @@ Syntax: belacoder PIPELINE_FILE ADDR PORT [options]

Options:
-v Print the version and exit
-c <config file> Configuration file (INI format, recommended)
-d <delay> Audio-video delay in milliseconds
-s <streamid> SRT stream ID
-l <latency> SRT latency in milliseconds (default: 2000)
-r Reduced SRT packet size (6 TS packets instead of 7)
-b <bitrate file> Bitrate settings file, see below
-b <bitrate file> Bitrate settings file (legacy, use -c instead)
-a <algorithm> Bitrate balancer algorithm (overrides config)

Bitrate settings file syntax:
MIN BITRATE (bps)
MAX BITRATE (bps)
---
Example for 500 Kbps – 6000 Kbps:
Config file example (belacoder.conf):
[general]
min_bitrate = 500 # Kbps
max_bitrate = 6000 # Kbps (6 Mbps)
balancer = adaptive # Algorithm: adaptive, fixed, aimd

printf "500000\n6000000" > bitrate_file
[srt]
latency = 2000 # ms

[adaptive]
incr_step = 30 # Bitrate increase step (Kbps)
decr_step = 100 # Bitrate decrease step (Kbps)
incr_interval = 500 # Min interval between increases (ms)
decr_interval = 200 # Min interval between decreases (ms)

---
Send SIGHUP to reload the bitrate settings while running.
Send SIGHUP to reload configuration while running:
kill -HUP $(pidof belacoder)
```

Where:

* `PIPELINE_FILE` is a text file containing the GStreamer pipeline to use. See the `pipeline` directory for ready-made pipelines.
* `ADDR` is the hostname or IP address of the SRT listener to stream to (only applicable when the GStreamer sink is `appsink name=appsink`).
* `PORT` is the port of the SRT listener to stream to (only applicable when the GStreamer sink is `appsink name=appsink`).
* `-d <delay>` is the optional delay in milliseconds to add to the audio stream relative to the video (when using the GStreamer pipelines supplied with belacoder).
* `-b <bitrate file>` is an optional argument for setting the minimum and maximum **video** bitrate (when using the GStreamer pipelines supplied with belacoder). These settings are reloaded from the file and applied when a SIGHUP signal is received.
* `ADDR` is the hostname or IP address of the SRT listener to stream to.
* `PORT` is the port of the SRT listener to stream to.
* `-c <config file>` is the recommended way to configure bitrate bounds and algorithm settings. See `belacoder.conf.example` for a full example.
* `-d <delay>` is the optional delay in milliseconds to add to the audio stream relative to the video.
* `-b <bitrate file>` is the legacy way to set bitrate bounds (use `-c` instead for new deployments).

### Balancer Algorithms

belacoder supports multiple bitrate control algorithms:

| Algorithm | Description | Best For |
|-----------|-------------|----------|
| **adaptive** (default) | RTT and buffer-based control with graduated response | Most use cases, variable networks |
| **fixed** | Constant bitrate, no adaptation | Stable networks, testing |
| **aimd** | TCP-style Additive Increase Multiplicative Decrease | Fair bandwidth sharing |

Select via config file or override with `-a <algorithm>`.


GStreamer Pipelines
Expand Down
Loading