Allow simple string for encoder configuration
This commit is contained in:
+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
|
bool Settings::simpleConfig() const
|
||||||
{
|
{
|
||||||
// Simple configuration: either unset, single encoder or all encoders + codecs are the same
|
// Simple configuration: either unset, single encoder or all encoders + codecs are the same
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto it = m_jsonSettings.find("encoder");
|
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;
|
return true;
|
||||||
std::optional<encoder_name> encoder;
|
std::optional<encoder_name> encoder;
|
||||||
std::optional<video_codec> codec;
|
std::optional<video_codec> codec;
|
||||||
for (const auto & item: *it)
|
for (const auto & item: *it)
|
||||||
{
|
{
|
||||||
if (auto it = item.find("encoder"); it != item.end())
|
auto e = encoder_for_item(item);
|
||||||
{
|
if (encoder and e != encoder)
|
||||||
auto e = encoder_id_from_string(std::string(*it));
|
return false;
|
||||||
if (encoder and e != encoder)
|
encoder = e;
|
||||||
return false;
|
|
||||||
encoder = e;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
encoder = encoder_name::EncoderAuto;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto it = item.find("codec"); it != item.end())
|
auto c = codec_for_item(item);
|
||||||
{
|
if (codec and c != codec)
|
||||||
auto e = codec_id_from_string(std::string(*it));
|
return false;
|
||||||
if (codec and e != codec)
|
codec = c;
|
||||||
return false;
|
|
||||||
codec = e;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
codec = video_codec::CodecAuto;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -196,12 +204,7 @@ Settings::encoder_name Settings::encoder() const
|
|||||||
return encoder_name::EncoderAuto;
|
return encoder_name::EncoderAuto;
|
||||||
if (it->is_array() and it->size())
|
if (it->is_array() and it->size())
|
||||||
it = it->begin();
|
it = it->begin();
|
||||||
if (it->is_object())
|
return encoder_for_item(*it);
|
||||||
{
|
|
||||||
if (auto e = it->find("encoder"); e != it->end())
|
|
||||||
return encoder_id_from_string(std::string(*e));
|
|
||||||
return encoder_name::EncoderAuto;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
@@ -211,7 +214,8 @@ Settings::encoder_name Settings::encoder() const
|
|||||||
|
|
||||||
void Settings::set_encoder(const encoder_name & value)
|
void Settings::set_encoder(const encoder_name & value)
|
||||||
{
|
{
|
||||||
auto old = encoder();
|
if (value == encoder())
|
||||||
|
return;
|
||||||
auto old_codec = codec();
|
auto old_codec = codec();
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
@@ -222,16 +226,11 @@ void Settings::set_encoder(const encoder_name & value)
|
|||||||
case Vaapi:
|
case Vaapi:
|
||||||
case X264:
|
case X264:
|
||||||
case Vulkan:
|
case Vulkan:
|
||||||
m_jsonSettings["encoder"] = nlohmann::json::object({
|
m_jsonSettings["encoder"] = encoder_from_id(value);
|
||||||
{"encoder", encoder_from_id(value)},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (value != old)
|
|
||||||
{
|
|
||||||
encoderChanged();
|
|
||||||
if (not can10bit())
|
|
||||||
set_tenbit(false);
|
|
||||||
}
|
}
|
||||||
|
encoderChanged();
|
||||||
|
if (not can10bit())
|
||||||
|
set_tenbit(false);
|
||||||
if (old_codec != codec())
|
if (old_codec != codec())
|
||||||
codecChanged();
|
codecChanged();
|
||||||
simpleConfigChanged();
|
simpleConfigChanged();
|
||||||
@@ -246,12 +245,7 @@ Settings::video_codec Settings::codec() const
|
|||||||
return video_codec::CodecAuto;
|
return video_codec::CodecAuto;
|
||||||
if (it->is_array() and it->size())
|
if (it->is_array() and it->size())
|
||||||
it = it->begin();
|
it = it->begin();
|
||||||
if (it->is_object())
|
return codec_for_item(*it);
|
||||||
{
|
|
||||||
if (auto c = it->find("codec"); c != it->end())
|
|
||||||
return codec_id_from_string(std::string(*c));
|
|
||||||
return video_codec::CodecAuto;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
@@ -266,10 +260,23 @@ void Settings::set_codec(const video_codec & value)
|
|||||||
if (it == m_jsonSettings.end())
|
if (it == m_jsonSettings.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (it->is_string())
|
||||||
|
{
|
||||||
|
m_jsonSettings["encoder"] = nlohmann::json::object({
|
||||||
|
{"encoder", *it},
|
||||||
|
{"codec", codec_from_id(value)},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (it->is_object())
|
if (it->is_object())
|
||||||
{
|
{
|
||||||
if (value == CodecAuto)
|
if (value == CodecAuto)
|
||||||
it->erase("codec");
|
{
|
||||||
|
if (auto encoder = it->find("encoder"); encoder != it->end())
|
||||||
|
*it = *encoder;
|
||||||
|
else
|
||||||
|
m_jsonSettings.erase("encoder");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
(*it)["codec"] = codec_from_id(value);
|
(*it)["codec"] = codec_from_id(value);
|
||||||
}
|
}
|
||||||
@@ -277,6 +284,14 @@ void Settings::set_codec(const video_codec & value)
|
|||||||
{
|
{
|
||||||
for (auto & item: *it)
|
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())
|
if (not item.is_object())
|
||||||
continue;
|
continue;
|
||||||
if (value == CodecAuto)
|
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`.
|
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`
|
## `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.
|
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.
|
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
|
* `vulkan`: experimental, for any GPU that supports vulkan video encode
|
||||||
|
|
||||||
### `codec`
|
### `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`.
|
One of `h264`, `h265`, `av1`, `raw`.
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,10 @@ configuration::configuration()
|
|||||||
encoders[i] = parse_encoder(it->at(i));
|
encoders[i] = parse_encoder(it->at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (it->is_string())
|
||||||
|
{
|
||||||
|
std::ranges::fill(encoders, encoder{.name = *it});
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::ranges::fill(encoders, parse_encoder(*it));
|
std::ranges::fill(encoders, parse_encoder(*it));
|
||||||
|
|||||||
Reference in New Issue
Block a user