Hermes 0.7.0
Linux game streaming host
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
10namespace 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
constexpr std::size_t max_fec_blocks
The video packet header has 2 bits for the FEC block count.
constexpr int large_frame_fec_percentage(std::size_t data_packets, int configured, int min_parity)
constexpr std::size_t max_fec_block_shards
Reed-Solomon over GF(2^8): data and parity shards of one FEC block together.