mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-21 17:41:54 -08:00
Allow simple string for encoder configuration
This commit is contained in:
1 parent
6f32f049d7
commit
5a669e71f5
3 files changed
+68
-48
No files matched your search
+61
-46
@@ -143,41 +143,49 @@ void Settings::load(const wivrn_server * server)
|
||||
}
|
||||
}
|
||||
|
||||
static Settings::encoder_name encoder_for_item(const nlohmann::json & item)
|
||||
{
|
||||
if (item.is_string())
|
||||
return Settings::encoder_id_from_string(std::string(item));
|
||||
if (item.is_object())
|
||||
{
|
||||
if (auto i = item.find("encoder"); i != item.end())
|
||||
return Settings::encoder_id_from_string(std::string(*i));
|
||||
}
|
||||
return Settings::encoder_name::EncoderAuto;
|
||||
}
|
||||
|
||||
static Settings::video_codec codec_for_item(const nlohmann::json & item)
|
||||
{
|
||||
if (item.is_object())
|
||||
{
|
||||
if (auto i = item.find("codec"); i != item.end())
|
||||
return Settings::codec_id_from_string(std::string(*i));
|
||||
}
|
||||
return Settings::video_codec::CodecAuto;
|
||||
}
|
||||
|
||||
bool Settings::simpleConfig() const
|
||||
{
|
||||
// Simple configuration: either unset, single encoder or all encoders + codecs are the same
|
||||
try
|
||||
{
|
||||
auto it = m_jsonSettings.find("encoder");
|
||||
if (it == m_jsonSettings.end() or it->is_object())
|
||||
if (it == m_jsonSettings.end() or it->is_object() or it->is_string())
|
||||
return true;
|
||||
std::optional<encoder_name> encoder;
|
||||
std::optional<video_codec> codec;
|
||||
for (const auto & item: *it)
|
||||
{
|
||||
if (auto it = item.find("encoder"); it != item.end())
|
||||
{
|
||||
auto e = encoder_id_from_string(std::string(*it));
|
||||
if (encoder and e != encoder)
|
||||
return false;
|
||||
encoder = e;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder = encoder_name::EncoderAuto;
|
||||
}
|
||||
auto e = encoder_for_item(item);
|
||||
if (encoder and e != encoder)
|
||||
return false;
|
||||
encoder = e;
|
||||
|
||||
if (auto it = item.find("codec"); it != item.end())
|
||||
{
|
||||
auto e = codec_id_from_string(std::string(*it));
|
||||
if (codec and e != codec)
|
||||
return false;
|
||||
codec = e;
|
||||
}
|
||||
else
|
||||
{
|
||||
codec = video_codec::CodecAuto;
|
||||
}
|
||||
auto c = codec_for_item(item);
|
||||
if (codec and c != codec)
|
||||
return false;
|
||||
codec = c;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -196,12 +204,7 @@ Settings::encoder_name Settings::encoder() const
|
||||
return encoder_name::EncoderAuto;
|
||||
if (it->is_array() and it->size())
|
||||
it = it->begin();
|
||||
if (it->is_object())
|
||||
{
|
||||
if (auto e = it->find("encoder"); e != it->end())
|
||||
return encoder_id_from_string(std::string(*e));
|
||||
return encoder_name::EncoderAuto;
|
||||
}
|
||||
return encoder_for_item(*it);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -211,7 +214,8 @@ Settings::encoder_name Settings::encoder() const
|
||||
|
||||
void Settings::set_encoder(const encoder_name & value)
|
||||
{
|
||||
auto old = encoder();
|
||||
if (value == encoder())
|
||||
return;
|
||||
auto old_codec = codec();
|
||||
switch (value)
|
||||
{
|
||||
@@ -222,16 +226,11 @@ void Settings::set_encoder(const encoder_name & value)
|
||||
case Vaapi:
|
||||
case X264:
|
||||
case Vulkan:
|
||||
m_jsonSettings["encoder"] = nlohmann::json::object({
|
||||
{"encoder", encoder_from_id(value)},
|
||||
});
|
||||
}
|
||||
if (value != old)
|
||||
{
|
||||
encoderChanged();
|
||||
if (not can10bit())
|
||||
set_tenbit(false);
|
||||
m_jsonSettings["encoder"] = encoder_from_id(value);
|
||||
}
|
||||
encoderChanged();
|
||||
if (not can10bit())
|
||||
set_tenbit(false);
|
||||
if (old_codec != codec())
|
||||
codecChanged();
|
||||
simpleConfigChanged();
|
||||
@@ -246,12 +245,7 @@ Settings::video_codec Settings::codec() const
|
||||
return video_codec::CodecAuto;
|
||||
if (it->is_array() and it->size())
|
||||
it = it->begin();
|
||||
if (it->is_object())
|
||||
{
|
||||
if (auto c = it->find("codec"); c != it->end())
|
||||
return codec_id_from_string(std::string(*c));
|
||||
return video_codec::CodecAuto;
|
||||
}
|
||||
return codec_for_item(*it);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -266,10 +260,23 @@ void Settings::set_codec(const video_codec & value)
|
||||
if (it == m_jsonSettings.end())
|
||||
return;
|
||||
|
||||
if (it->is_string())
|
||||
{
|
||||
m_jsonSettings["encoder"] = nlohmann::json::object({
|
||||
{"encoder", *it},
|
||||
{"codec", codec_from_id(value)},
|
||||
});
|
||||
}
|
||||
|
||||
if (it->is_object())
|
||||
{
|
||||
if (value == CodecAuto)
|
||||
it->erase("codec");
|
||||
{
|
||||
if (auto encoder = it->find("encoder"); encoder != it->end())
|
||||
*it = *encoder;
|
||||
else
|
||||
m_jsonSettings.erase("encoder");
|
||||
}
|
||||
else
|
||||
(*it)["codec"] = codec_from_id(value);
|
||||
}
|
||||
@@ -277,6 +284,14 @@ void Settings::set_codec(const video_codec & value)
|
||||
{
|
||||
for (auto & item: *it)
|
||||
{
|
||||
if (it->is_string())
|
||||
{
|
||||
item = nlohmann::json::object({
|
||||
{"encoder", item},
|
||||
{"codec", codec_from_id(value)},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (not item.is_object())
|
||||
continue;
|
||||
if (value == CodecAuto)
|
||||
|
||||
@@ -18,7 +18,8 @@ Default value: `8` (bits)
|
||||
Bit depth of the video. 8-bit is supported by all encoders. 10-bit is supported by `vaapi` and `nvenc` encoders using `h265` or `av1`.
|
||||
|
||||
## `encoder`
|
||||
The encoder to use, either a single object applied to all streams, or a list of objects with values for left, right and alpha.
|
||||
The encoder to use, either a single string or object applied to all streams, or a list of string or objects with values for left, right and alpha.
|
||||
When a string it is used, it is equivalent to the `encoder` item of the object.
|
||||
|
||||
WiVRn encodes each eye separately, and the alpha channel as one for both eyes. Each stream is processed independently, this may use resources more effectively and reduce latency.
|
||||
All the provided encoders are put into groups, groups are executed concurrently and items within a group are processed sequentially.
|
||||
@@ -33,7 +34,7 @@ Identifier of the encoder, one of
|
||||
* `vulkan`: experimental, for any GPU that supports vulkan video encode
|
||||
|
||||
### `codec`
|
||||
Default value: first supported by both headset and encoder of `av1`, `h264`, `h265`.
|
||||
Default value: best supported by both headset and encoder of `av1`, `h264`, `h265`.
|
||||
|
||||
One of `h264`, `h265`, `av1`, `raw`.
|
||||
|
||||
|
||||
@@ -168,6 +168,10 @@ configuration::configuration()
|
||||
encoders[i] = parse_encoder(it->at(i));
|
||||
}
|
||||
}
|
||||
else if (it->is_string())
|
||||
{
|
||||
std::ranges::fill(encoders, encoder{.name = *it});
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ranges::fill(encoders, parse_encoder(*it));
|
||||
|
||||
Reference in new issue
Block a user