Skip to content

Commit

Permalink
snarthing
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Jan 11, 2025
1 parent 79c496e commit 2ff11fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
26 changes: 12 additions & 14 deletions src/display_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,14 @@ namespace display_device {
parse_remapping_entry(const config::video_t::dd_t::mode_remapping_entry_t &entry, const remapping_type_e type) {
parsed_remapping_entry_t result {};

if (is_resolution_mapped(type)) {
if (!parse_resolution_string(entry.requested_resolution, result.requested_resolution) ||
!parse_resolution_string(entry.final_resolution, result.final_resolution)) {
return std::nullopt;
}
if (is_resolution_mapped(type) && (!parse_resolution_string(entry.requested_resolution, result.requested_resolution) ||
!parse_resolution_string(entry.final_resolution, result.final_resolution))) {
return std::nullopt;
}

if (is_fps_mapped(type)) {
if (!parse_refresh_rate_string(entry.requested_fps, result.requested_fps, false) ||
!parse_refresh_rate_string(entry.final_refresh_rate, result.final_refresh_rate)) {
return std::nullopt;
}
if (is_fps_mapped(type) && (!parse_refresh_rate_string(entry.requested_fps, result.requested_fps, false) ||
!parse_refresh_rate_string(entry.final_refresh_rate, result.final_refresh_rate))) {
return std::nullopt;
}

return result;
Expand All @@ -536,7 +532,7 @@ namespace display_device {
* @returns True if the remapping was performed or skipped, false if remapping has failed due to invalid config.
*
* @examples
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session; // Assuming ptr is properly initialized
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
* const config::video_t &video_config { config::video };
*
* SingleDisplayConfiguration config;
Expand All @@ -551,12 +547,14 @@ namespace display_device {
}

const auto &remapping_list { [&]() {
using enum remapping_type_e;

switch (*remapping_type) {
case remapping_type_e::resolution_only:
case resolution_only:
return video_config.dd.mode_remapping.resolution_only;
case remapping_type_e::refresh_rate_only:
case refresh_rate_only:
return video_config.dd.mode_remapping.refresh_rate_only;
case remapping_type_e::mixed:
case mixed:
default:
return video_config.dd.mode_remapping.mixed;
}
Expand Down
20 changes: 12 additions & 8 deletions tests/unit/test_display_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,32 +445,36 @@ namespace {
rtsp_stream::launch_session_t session {};

{ // resolution
using enum resolution_option_e;

if (const auto *no_res { std::get_if<no_value_t>(&input_res) }; no_res) {
video_config.dd.resolution_option = resolution_option_e::disabled;
video_config.dd.resolution_option = disabled;
}
else if (const auto *auto_res { std::get_if<auto_value_t<res_t>>(&input_res) }; auto_res) {
video_config.dd.resolution_option = resolution_option_e::automatic;
video_config.dd.resolution_option = automatic;
session.width = static_cast<int>(auto_res->value.m_width);
session.height = static_cast<int>(auto_res->value.m_height);
}
else {
const auto [manual_res] = std::get<manual_value_t<res_t>>(input_res);
video_config.dd.resolution_option = resolution_option_e::manual;
video_config.dd.resolution_option = manual;
video_config.dd.manual_resolution = std::to_string(manual_res.m_width) + "x"s + std::to_string(manual_res.m_height);
}
}

{ // fps
using enum refresh_rate_option_e;

if (const auto *no_fps { std::get_if<no_value_t>(&input_fps) }; no_fps) {
video_config.dd.refresh_rate_option = refresh_rate_option_e::disabled;
video_config.dd.refresh_rate_option = disabled;
}
else if (const auto *auto_fps { std::get_if<auto_value_t<fps_t>>(&input_fps) }; auto_fps) {
video_config.dd.refresh_rate_option = refresh_rate_option_e::automatic;
video_config.dd.refresh_rate_option = automatic;
session.fps = auto_fps->value;
}
else {
const auto [manual_fps] = std::get<manual_value_t<fps_t>>(input_fps);
video_config.dd.refresh_rate_option = refresh_rate_option_e::manual;
video_config.dd.refresh_rate_option = manual;
video_config.dd.manual_refresh_rate = std::to_string(manual_fps);
}
}
Expand All @@ -484,8 +488,8 @@ namespace {
EXPECT_NO_THROW(std::get<display_device::failed_to_parse_tag_t>(result));
}
else {
const auto [expected_resolution, expected_refresh_rate] = std::get<final_values_t>(expected_value);
const auto parsed_config = std::get<display_device::SingleDisplayConfiguration>(result);
const auto& [expected_resolution, expected_refresh_rate] = std::get<final_values_t>(expected_value);
const auto& parsed_config = std::get<display_device::SingleDisplayConfiguration>(result);

EXPECT_EQ(parsed_config.m_resolution, expected_resolution);
EXPECT_EQ(parsed_config.m_refresh_rate, expected_refresh_rate ? std::make_optional(display_device::FloatingPoint { *expected_refresh_rate }) : std::nullopt);
Expand Down

0 comments on commit 2ff11fa

Please sign in to comment.