Future Improvements: Code Structure and Testing
Overview
This issue tracks structural improvements and testing additions planned for belacoder.
Refactoring Tasks
1. Consolidate Global Variables into Context Struct
Currently ~15 global variables are used for runtime state. Consolidate into a single context struct:
typedef struct {
GstPipeline *pipeline;
GMainLoop *loop;
GstElement *encoder;
GstElement *overlay;
SRTSOCKET sock;
int quit;
int cur_bitrate;
int min_bitrate;
int max_bitrate;
// ... etc
} BelacoderContext;
Benefits:
- Easier to test (can create isolated contexts)
- Clearer ownership and lifecycle
- Enables future multi-instance support
2. Split into Modules ✅
Break belacoder.c into logical modules:
Completed in PR #7 - Reorganized into src/core/, src/io/, src/net/, src/gst/ with clear module boundaries.
Benefits:
3. Implement Controller Interface for Multi-Algorithm Support ✅
Add runtime selection of bitrate algorithms (see #3):
typedef struct {
const char *name;
void* (*init)(BalancerConfig *config);
BalancerOutput (*step)(void *state, BalancerInput *input);
void (*cleanup)(void *state);
} BalancerAlgorithm;
Completed in PR #7 - Implemented adaptive, fixed, and aimd algorithms with pluggable interface.
Testing Tasks
4. Add Unit Tests for Bitrate Controller ✅
The bitrate controller logic is pure computation and can be tested in isolation:
Completed in PR #7 - 16 cmocka integration tests covering all balancer algorithms and edge cases.
5. Add Integration Test
6. Add Static Analysis to CI
Related Issues
Future Improvements: Code Structure and Testing
Overview
This issue tracks structural improvements and testing additions planned for belacoder.
Refactoring Tasks
1. Consolidate Global Variables into Context Struct
Currently ~15 global variables are used for runtime state. Consolidate into a single context struct:
Benefits:
2. Split into Modules ✅
Break
belacoder.cinto logical modules:bitrate_control.c/bitrate_control.h- Adaptive bitrate algorithmsrt_sender.c/srt_sender.h- SRT socket handling and packet sendinggst_helpers.c/gst_helpers.h- GStreamer pipeline utilitiesmain.c- CLI parsing, initialization, main loopBenefits:
3. Implement Controller Interface for Multi-Algorithm Support ✅
Add runtime selection of bitrate algorithms (see #3):
--balancer=<name>CLI flagfixedoraimd)Testing Tasks
4. Add Unit Tests for Bitrate Controller ✅
The bitrate controller logic is pure computation and can be tested in isolation:
5. Add Integration Test
6. Add Static Analysis to CI
cppcheckorclang-tidyto buildRelated Issues