summaryrefslogtreecommitdiff
path: root/src/apps/common/stream_options.cpp
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2023-02-13 16:43:06 +0000
committerUmang Jain <umang.jain@ideasonboard.com>2023-02-15 01:32:05 +0530
commit58e0b6e18c425072a47594f42fc0b61801403aca (patch)
tree2309b5980b1073117ad4f7ea5d996a47237342e8 /src/apps/common/stream_options.cpp
parent02f0492c55f293b6a00ee702cee51b5f1b1c2e50 (diff)
apps: Return std::optional<> from StreamKeyValueParser::parseRole()
Instead of having bool return type and an out parameter, use std::optional<libcamera::StreamRole> to return from StreamKeyValueParser::parseRole(). Meanwhile at it, re-word an existing comment to make it lucid. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'src/apps/common/stream_options.cpp')
-rw-r--r--src/apps/common/stream_options.cpp41
1 files changed, 14 insertions, 27 deletions
diff --git a/src/apps/common/stream_options.cpp b/src/apps/common/stream_options.cpp
index 3a5625f5..19dfe051 100644
--- a/src/apps/common/stream_options.cpp
+++ b/src/apps/common/stream_options.cpp
@@ -30,10 +30,8 @@ StreamKeyValueParser::StreamKeyValueParser()
KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments)
{
KeyValueParser::Options options = KeyValueParser::parse(arguments);
- StreamRole role;
- if (options.valid() && options.isSet("role") &&
- !parseRole(&role, options)) {
+ if (options.valid() && options.isSet("role") && !parseRole(options)) {
std::cerr << "Unknown stream role "
<< options["role"].toString() << std::endl;
options.invalidate();
@@ -52,13 +50,8 @@ StreamRoles StreamKeyValueParser::roles(const OptionValue &values)
StreamRoles roles;
for (auto const &value : streamParameters) {
- StreamRole role;
-
- /* If role is invalid or not set default to viewfinder. */
- if (!parseRole(&role, value.toKeyValues()))
- role = StreamRole::Viewfinder;
-
- roles.push_back(role);
+ /* If a role is invalid default it to viewfinder. */
+ roles.push_back(parseRole(value.toKeyValues()).value_or(StreamRole::Viewfinder));
}
return roles;
@@ -108,27 +101,21 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
return 0;
}
-bool StreamKeyValueParser::parseRole(StreamRole *role,
- const KeyValueParser::Options &options)
+std::optional<libcamera::StreamRole> StreamKeyValueParser::parseRole(const KeyValueParser::Options &options)
{
if (!options.isSet("role"))
- return false;
+ return {};
std::string name = options["role"].toString();
- if (name == "viewfinder") {
- *role = StreamRole::Viewfinder;
- return true;
- } else if (name == "video") {
- *role = StreamRole::VideoRecording;
- return true;
- } else if (name == "still") {
- *role = StreamRole::StillCapture;
- return true;
- } else if (name == "raw") {
- *role = StreamRole::Raw;
- return true;
- }
+ if (name == "viewfinder")
+ return StreamRole::Viewfinder;
+ else if (name == "video")
+ return StreamRole::VideoRecording;
+ else if (name == "still")
+ return StreamRole::StillCapture;
+ else if (name == "raw")
+ return StreamRole::Raw;
- return false;
+ return {};
}