Configure bitrate globally
This commit is contained in:
+8
-10
@@ -20,6 +20,11 @@ The x and y resolution of the streamed video are half the size on the headsed, r
|
|||||||
```
|
```
|
||||||
Scales x by a 0.75 factor, and y by a 0.5 factor.
|
Scales x by a 0.75 factor, and y by a 0.5 factor.
|
||||||
|
|
||||||
|
## `bitrate`
|
||||||
|
Default value: `50000000` (50Mb/s)
|
||||||
|
|
||||||
|
Bitrate of the video, in bit/s. Split among decoders based on size and codecs.
|
||||||
|
|
||||||
## `encoders`
|
## `encoders`
|
||||||
A list of encoders to use.
|
A list of encoders to use.
|
||||||
|
|
||||||
@@ -36,11 +41,6 @@ Default value: `h265`
|
|||||||
|
|
||||||
One of `h264` or `h265`. If using `x264` encoder, value is ignored and `h264` is used.
|
One of `h264` or `h265`. If using `x264` encoder, value is ignored and `h264` is used.
|
||||||
|
|
||||||
### `bitrate`
|
|
||||||
Default value: `50000000` (50Mb/s)
|
|
||||||
|
|
||||||
Bitrate of the video, in bit/s.
|
|
||||||
|
|
||||||
### `width`, `height`, `offset_x`, `offset_y` (advanced)
|
### `width`, `height`, `offset_x`, `offset_y` (advanced)
|
||||||
Default values: full image (`width` = 1, `height` = 1, `offset_x` = 0, `offset_y` = 0)
|
Default values: full image (`width` = 1, `height` = 1, `offset_x` = 0, `offset_y` = 0)
|
||||||
|
|
||||||
@@ -55,10 +55,10 @@ Identifier (number) of the encoder group. Encoders with the same identifier are
|
|||||||
1. Simple encoder
|
1. Simple encoder
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"bitrate": 50000000,
|
||||||
"encoders": [
|
"encoders": [
|
||||||
{
|
{
|
||||||
"encoder": "vaapi",
|
"encoder": "vaapi",
|
||||||
"bitrate": 50000000,
|
|
||||||
"codec": "h265"
|
"codec": "h265"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -69,10 +69,10 @@ Creates a single encoder, using vaapi hardware encoding, h265 video codec (HEVC)
|
|||||||
2. Hardware + software encoder
|
2. Hardware + software encoder
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"bitrate": 50000000,
|
||||||
"encoders": [
|
"encoders": [
|
||||||
{
|
{
|
||||||
"encoder": "vaapi",
|
"encoder": "vaapi",
|
||||||
"bitrate": 25000000,
|
|
||||||
"codec": "h265",
|
"codec": "h265",
|
||||||
"width": 0.5,
|
"width": 0.5,
|
||||||
"height": 1,
|
"height": 1,
|
||||||
@@ -81,7 +81,6 @@ Creates a single encoder, using vaapi hardware encoding, h265 video codec (HEVC)
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"encoder": "x264",
|
"encoder": "x264",
|
||||||
"bitrate": 25000000,
|
|
||||||
"codec": "h264",
|
"codec": "h264",
|
||||||
"width": 0.5,
|
"width": 0.5,
|
||||||
"height": 1,
|
"height": 1,
|
||||||
@@ -96,10 +95,10 @@ Creates a hardware encoder for left eye, and a software encoder for right eye.
|
|||||||
3. 2 Hardware encoders
|
3. 2 Hardware encoders
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"bitrate": 50000000,
|
||||||
"encoders": [
|
"encoders": [
|
||||||
{
|
{
|
||||||
"encoder": "vaapi",
|
"encoder": "vaapi",
|
||||||
"bitrate": 25000000,
|
|
||||||
"codec": "h265",
|
"codec": "h265",
|
||||||
"width": 0.5,
|
"width": 0.5,
|
||||||
"height": 1,
|
"height": 1,
|
||||||
@@ -109,7 +108,6 @@ Creates a hardware encoder for left eye, and a software encoder for right eye.
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"encoder": "vaapi",
|
"encoder": "vaapi",
|
||||||
"bitrate": 25000000,
|
|
||||||
"codec": "h264",
|
"codec": "h264",
|
||||||
"width": 0.5,
|
"width": 0.5,
|
||||||
"height": 1,
|
"height": 1,
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ configuration configuration::read_user_configuration()
|
|||||||
result.scale = json["scale"];
|
result.scale = json["scale"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (json.contains("bitrate"))
|
||||||
|
{
|
||||||
|
result.bitrate = json["bitrate"];
|
||||||
|
}
|
||||||
|
|
||||||
if (json.contains("encoders"))
|
if (json.contains("encoders"))
|
||||||
{
|
{
|
||||||
for (const auto & encoder: json["encoders"])
|
for (const auto & encoder: json["encoders"])
|
||||||
@@ -89,7 +94,6 @@ configuration configuration::read_user_configuration()
|
|||||||
SET_IF(height);
|
SET_IF(height);
|
||||||
SET_IF(offset_x);
|
SET_IF(offset_x);
|
||||||
SET_IF(offset_y);
|
SET_IF(offset_y);
|
||||||
SET_IF(bitrate);
|
|
||||||
SET_IF(group);
|
SET_IF(group);
|
||||||
SET_IF(codec);
|
SET_IF(codec);
|
||||||
if (e.codec == xrt::drivers::wivrn::video_codec(-1))
|
if (e.codec == xrt::drivers::wivrn::video_codec(-1))
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ struct configuration
|
|||||||
std::optional<double> height;
|
std::optional<double> height;
|
||||||
std::optional<double> offset_x;
|
std::optional<double> offset_x;
|
||||||
std::optional<double> offset_y;
|
std::optional<double> offset_y;
|
||||||
std::optional<int> bitrate;
|
|
||||||
std::optional<int> group;
|
std::optional<int> group;
|
||||||
std::optional<xrt::drivers::wivrn::video_codec> codec;
|
std::optional<xrt::drivers::wivrn::video_codec> codec;
|
||||||
std::map<std::string, std::string> options;
|
std::map<std::string, std::string> options;
|
||||||
@@ -43,6 +42,7 @@ struct configuration
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<encoder> encoders;
|
std::vector<encoder> encoders;
|
||||||
|
std::optional<int> bitrate;
|
||||||
std::optional<std::array<double, 2>> scale;
|
std::optional<std::array<double, 2>> scale;
|
||||||
std::vector<std::string> application;
|
std::vector<std::string> application;
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,30 @@ static bool is_nvidia(vk::PhysicalDevice physical_device)
|
|||||||
return props.vendorID == 0x10DE;
|
return props.vendorID == 0x10DE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void split_bitrate(std::vector<xrt::drivers::wivrn::encoder_settings> &encoders, uint64_t bitrate)
|
||||||
|
{
|
||||||
|
double total_weight = 0;
|
||||||
|
for (auto& encoder: encoders)
|
||||||
|
{
|
||||||
|
double w = encoder.width * encoder.height;
|
||||||
|
switch (encoder.codec)
|
||||||
|
{
|
||||||
|
case xrt::drivers::wivrn::h264:
|
||||||
|
w *= 2;
|
||||||
|
break;
|
||||||
|
case xrt::drivers::wivrn::h265:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
encoder.bitrate = w;
|
||||||
|
total_weight += w;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& encoder: encoders)
|
||||||
|
{
|
||||||
|
encoder.bitrate = encoder.bitrate * bitrate / total_weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static std::vector<xrt::drivers::wivrn::encoder_settings> get_encoder_default_settings(vk::PhysicalDevice physical_device, uint16_t width, uint16_t height)
|
static std::vector<xrt::drivers::wivrn::encoder_settings> get_encoder_default_settings(vk::PhysicalDevice physical_device, uint16_t width, uint16_t height)
|
||||||
{
|
{
|
||||||
xrt::drivers::wivrn::encoder_settings settings{};
|
xrt::drivers::wivrn::encoder_settings settings{};
|
||||||
@@ -89,6 +113,7 @@ std::vector<encoder_settings> xrt::drivers::wivrn::get_encoder_settings(vk::Phys
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto & config = configuration::read_user_configuration();
|
const auto & config = configuration::read_user_configuration();
|
||||||
|
uint64_t bitrate = config.bitrate.value_or(default_bitrate);
|
||||||
if (config.encoders.empty())
|
if (config.encoders.empty())
|
||||||
return get_encoder_default_settings(physical_device, width, height);
|
return get_encoder_default_settings(physical_device, width, height);
|
||||||
std::vector<xrt::drivers::wivrn::encoder_settings> res;
|
std::vector<xrt::drivers::wivrn::encoder_settings> res;
|
||||||
@@ -103,7 +128,6 @@ std::vector<encoder_settings> xrt::drivers::wivrn::get_encoder_settings(vk::Phys
|
|||||||
settings.video_height = settings.height;
|
settings.video_height = settings.height;
|
||||||
settings.offset_x = std::ceil(encoder.offset_x.value_or(0) * width);
|
settings.offset_x = std::ceil(encoder.offset_x.value_or(0) * width);
|
||||||
settings.offset_y = std::ceil(encoder.offset_y.value_or(0) * height);
|
settings.offset_y = std::ceil(encoder.offset_y.value_or(0) * height);
|
||||||
settings.bitrate = encoder.bitrate.value_or(default_bitrate);
|
|
||||||
settings.codec = encoder.codec.value_or(xrt::drivers::wivrn::h264);
|
settings.codec = encoder.codec.value_or(xrt::drivers::wivrn::h264);
|
||||||
settings.group = encoder.group.value_or(next_group);
|
settings.group = encoder.group.value_or(next_group);
|
||||||
settings.options = encoder.options;
|
settings.options = encoder.options;
|
||||||
@@ -112,6 +136,7 @@ std::vector<encoder_settings> xrt::drivers::wivrn::get_encoder_settings(vk::Phys
|
|||||||
next_group = std::max(next_group, settings.group + 1);
|
next_group = std::max(next_group, settings.group + 1);
|
||||||
res.push_back(settings);
|
res.push_back(settings);
|
||||||
}
|
}
|
||||||
|
split_bitrate(res, bitrate);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
catch (const std::exception & e)
|
catch (const std::exception & e)
|
||||||
|
|||||||
Reference in New Issue
Block a user