Hermes
0.7.0
Linux game streaming host
Toggle main menu visibility
Loading...
Searching...
No Matches
video_fec_budget.h
Go to the documentation of this file.
1
5
#pragma once
6
7
#include <algorithm>
8
#include <cstddef>
9
10
namespace
stream {
11
13
constexpr
std::size_t
max_fec_blocks
= 4;
14
16
constexpr
std::size_t
max_fec_block_shards
= 255;
17
35
constexpr
int
large_frame_fec_percentage
(std::size_t data_packets,
int
configured,
int
min_parity) {
36
if
(data_packets == 0 || configured <= 0) {
37
return
0;
38
}
39
// The frame is cut into blocks of a whole number of packets; the last
40
// block can hold one more than the others.
41
const
std::size_t block_data = (data_packets +
max_fec_blocks
- 1) /
max_fec_blocks
+ 1;
42
if
(block_data >=
max_fec_block_shards
) {
43
return
0;
44
}
45
const
std::size_t room =
max_fec_block_shards
- block_data;
46
if
(min_parity > 0 && room <
static_cast<
std::size_t
>
(min_parity)) {
47
return
0;
48
}
49
// parity = ceil(block_data * percentage / 100) stays within `room` while
50
// percentage <= room * 100 / block_data.
51
const
auto
fits =
static_cast<
int
>
(room * 100 / block_data);
52
return
std::min(configured, fits);
53
}
54
55
}
// namespace stream
stream::max_fec_blocks
constexpr std::size_t max_fec_blocks
The video packet header has 2 bits for the FEC block count.
Definition
video_fec_budget.h:13
stream::large_frame_fec_percentage
constexpr int large_frame_fec_percentage(std::size_t data_packets, int configured, int min_parity)
Definition
video_fec_budget.h:35
stream::max_fec_block_shards
constexpr std::size_t max_fec_block_shards
Reed-Solomon over GF(2^8): data and parity shards of one FEC block together.
Definition
video_fec_budget.h:16
src
video_fec_budget.h
Generated by
1.18.0