Skip to content

Commit

Permalink
Do handle frac rate policy by DRM property
Browse files Browse the repository at this point in the history
Changing the frac rate policy will automatic force a mode switch.
  • Loading branch information
Portisch committed Feb 4, 2025
1 parent 878350f commit 6d3f638
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 63 deletions.
8 changes: 2 additions & 6 deletions xbmc/guilib/guiinfo/PlayerGUIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "guilib/guiinfo/GUIInfo.h"
#include "guilib/guiinfo/GUIInfoHelper.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
#include "utils/AMLUtils.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
Expand Down Expand Up @@ -80,14 +81,9 @@ std::string CPlayerGUIInfo::GetAMLConfigInfo(std::string item) const

if (sub_items.size() > 1)
{
int cur_fractional_rate = 0;
item_value = StringUtils::Left(sub_items.at(1), sub_items.at(1).length() - 4) + " ";

CSysfsPath frac_rate_policy{"/sys/class/amhdmitx/amhdmitx0/frac_rate_policy"};
if (frac_rate_policy.Exists())
cur_fractional_rate = frac_rate_policy.Get<int>().value();

if (cur_fractional_rate)
if (aml_get_drmProperty("FRAC_RATE_POLICY", DRM_MODE_OBJECT_CONNECTOR))
{
float refreshrate = static_cast<float>(atof(StringUtils::Mid(sub_items.at(1), sub_items.at(1).length() - 4, 2).c_str()));
item_value += fmt::format("{:.2f}", refreshrate / 1.001f) + "Hz";
Expand Down
64 changes: 17 additions & 47 deletions xbmc/utils/AMLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,6 @@ bool aml_dolby_vision_enabled()
return ((dv_enabled && !!dv_user_enabled) == 1);
}

bool aml_has_frac_rate_policy()
{
static int has_frac_rate_policy = -1;

if (has_frac_rate_policy == -1)
{
CSysfsPath amhdmitx0_frac_rate_policy{"/sys/class/amhdmitx/amhdmitx0/frac_rate_policy"};
has_frac_rate_policy = static_cast<int>(amhdmitx0_frac_rate_policy.Exists());
}

return (has_frac_rate_policy == 1);
}

bool aml_video_started()
{
CSysfsPath videostarted{"/sys/class/tsync/videostarted"};
Expand Down Expand Up @@ -1356,15 +1343,8 @@ bool aml_get_native_resolution(RESOLUTION_INFO *res)
std::string mode = aml_get_drmDevice_mode();
bool result = aml_mode_to_resolution(mode.c_str(), res);

if (aml_has_frac_rate_policy())
{
int fractional_rate = 0;
CSysfsPath frac_rate_policy{"/sys/class/amhdmitx/amhdmitx0/frac_rate_policy"};
if (frac_rate_policy.Exists())
fractional_rate = frac_rate_policy.Get<int>().value();
if (fractional_rate == 1)
res->fRefreshRate /= 1.001f;
}
if (aml_get_drmProperty("FRAC_RATE_POLICY", DRM_MODE_OBJECT_CONNECTOR) == 1)
res->fRefreshRate /= 1.001f;

return result;
}
Expand Down Expand Up @@ -1432,20 +1412,17 @@ bool aml_probe_resolutions(std::vector<RESOLUTION_INFO> &resolutions)
else
resolutions.push_back(res);

if (aml_has_frac_rate_policy())
// Add fractional frame rates: 23.976, 29.97 and 59.94 Hz
switch ((int)res.fRefreshRate)
{
// Add fractional frame rates: 23.976, 29.97 and 59.94 Hz
switch ((int)res.fRefreshRate)
{
case 24:
case 30:
case 60:
res.fRefreshRate /= 1.001f;
res.strMode = StringUtils::Format("{:d}x{:d} @ {:.2f}{} - Full Screen", res.iScreenWidth, res.iScreenHeight, res.fRefreshRate,
res.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
resolutions.push_back(res);
break;
}
case 24:
case 30:
case 60:
res.fRefreshRate /= 1.001f;
res.strMode = StringUtils::Format("{:d}x{:d} @ {:.2f}{} - Full Screen", res.iScreenWidth, res.iScreenHeight, res.fRefreshRate,
res.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
resolutions.push_back(res);
break;
}
}
}
Expand Down Expand Up @@ -1489,19 +1466,12 @@ bool aml_set_display_resolution(const RESOLUTION_INFO &res, std::string framebuf
mode = "custombuilt";
}

if (aml_has_frac_rate_policy())
{
int cur_fractional_rate;
int fractional_rate = (res.fRefreshRate == floor(res.fRefreshRate)) ? 0 : 1;
CSysfsPath amhdmitx0_frac_rate_policy{"/sys/class/amhdmitx/amhdmitx0/frac_rate_policy"};
if (amhdmitx0_frac_rate_policy.Exists())
cur_fractional_rate = amhdmitx0_frac_rate_policy.Get<int>().value();
int fractional_rate = (res.fRefreshRate == floor(res.fRefreshRate)) ? 0 : 1;

if ((cur_fractional_rate != fractional_rate) || force_mode_switch)
{
if (amhdmitx0_frac_rate_policy.Exists())
amhdmitx0_frac_rate_policy.Set(fractional_rate);
}
if (aml_get_drmProperty("FRAC_RATE_POLICY", DRM_MODE_OBJECT_CONNECTOR) != fractional_rate)
{
aml_set_drmProperty("FRAC_RATE_POLICY", DRM_MODE_OBJECT_CONNECTOR, fractional_rate);
force_mode_switch = false;
}

aml_set_framebuffer_resolution(res.iScreenWidth, res.iScreenHeight, framebuffer_name);
Expand Down
1 change: 0 additions & 1 deletion xbmc/utils/AMLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ bool aml_support_avs2();
bool aml_support_avs3();
bool aml_support_dolby_vision();
bool aml_dolby_vision_enabled();
bool aml_has_frac_rate_policy();
bool aml_video_started();
void aml_video_mute(bool mute);
void aml_set_3d_video_mode(unsigned int mode, bool framepacking_support, int view_mode);
Expand Down
11 changes: 2 additions & 9 deletions xbmc/windowing/amlogic/WinSystemAmlogicGLESContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ bool CWinSystemAmlogicGLESContext::CreateNewWindow(const std::string& name,

// check for frac_rate_policy change
int fractional_rate = (res.fRefreshRate == floor(res.fRefreshRate)) ? 0 : 1;
int cur_fractional_rate = fractional_rate;
if (aml_has_frac_rate_policy())
{
CSysfsPath amhdmitx0_frac_rate_policy{"/sys/class/amhdmitx/amhdmitx0/frac_rate_policy"};
cur_fractional_rate = amhdmitx0_frac_rate_policy.Get<int>().value();
}
int cur_fractional_rate = aml_get_drmProperty("FRAC_RATE_POLICY", DRM_MODE_OBJECT_CONNECTOR);

StreamHdrType hdrType = CServiceBroker::GetWinSystem()->GetGfxContext().GetHDRType();
bool force_mode_switch_by_dv = false;
Expand Down Expand Up @@ -138,9 +133,7 @@ bool CWinSystemAmlogicGLESContext::CreateNewWindow(const std::string& name,
// check if a forced mode switch is required
if (((current_resolution.iWidth == res.iWidth && current_resolution.iHeight == res.iHeight &&
current_resolution.iScreenWidth == res.iScreenWidth && current_resolution.iScreenHeight == res.iScreenHeight &&
current_resolution.fRefreshRate == res.fRefreshRate) &&
(force_mode_switch_by_dv ||
(fractional_rate != cur_fractional_rate))) ||
current_resolution.fRefreshRate == res.fRefreshRate) && force_mode_switch_by_dv) ||
(m_stereo_mode != stereo_mode))
{
m_force_mode_switch = true;
Expand Down

0 comments on commit 6d3f638

Please sign in to comment.