Use hasFrameFormatChanged() in DRMRenderer

This commit is contained in:
Cameron Gutman 2025-11-06 00:04:08 -06:00
commit a2670dd568
2 changed files with 61 additions and 70 deletions

View file

@ -166,8 +166,6 @@ DrmRenderer::DrmRenderer(AVHWDeviceType hwDeviceType, IFFmpegRenderer *backendRe
m_CrtcId(0), m_CrtcId(0),
m_PlaneId(0), m_PlaneId(0),
m_CurrentFbId(0), m_CurrentFbId(0),
m_LastFullRange(false),
m_LastColorSpace(-1),
m_Plane(nullptr), m_Plane(nullptr),
m_ColorEncodingProp(nullptr), m_ColorEncodingProp(nullptr),
m_ColorRangeProp(nullptr), m_ColorRangeProp(nullptr),
@ -1251,93 +1249,88 @@ void DrmRenderer::renderFrame(AVFrame* frame)
return; return;
} }
int colorspace = getFrameColorspace(frame); if (hasFrameFormatChanged(frame)) {
bool fullRange = isFrameFullRange(frame); // Set COLOR_RANGE property for the plane
{
const char* desiredValue = getDrmColorRangeValue(frame);
// We also update the color range when the colorspace changes in order to handle initialization if (m_ColorRangeProp != nullptr && desiredValue != nullptr) {
// where the last color range value may not actual be applied to the plane. int i;
if (fullRange != m_LastFullRange || colorspace != m_LastColorSpace) {
const char* desiredValue = getDrmColorRangeValue(frame);
if (m_ColorRangeProp != nullptr && desiredValue != nullptr) { for (i = 0; i < m_ColorRangeProp->count_enums; i++) {
int i; if (!strcmp(desiredValue, m_ColorRangeProp->enums[i].name)) {
err = drmModeObjectSetProperty(m_DrmFd, m_PlaneId, DRM_MODE_OBJECT_PLANE,
m_ColorRangeProp->prop_id, m_ColorRangeProp->enums[i].value);
if (err == 0) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"%s: %s",
m_ColorRangeProp->name,
desiredValue);
}
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"drmModeObjectSetProperty(%s) failed: %d",
m_ColorRangeProp->name,
errno);
// Non-fatal
}
for (i = 0; i < m_ColorRangeProp->count_enums; i++) { break;
if (!strcmp(desiredValue, m_ColorRangeProp->enums[i].name)) {
err = drmModeObjectSetProperty(m_DrmFd, m_PlaneId, DRM_MODE_OBJECT_PLANE,
m_ColorRangeProp->prop_id, m_ColorRangeProp->enums[i].value);
if (err == 0) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"%s: %s",
m_ColorRangeProp->name,
desiredValue);
}
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"drmModeObjectSetProperty(%s) failed: %d",
m_ColorRangeProp->name,
errno);
// Non-fatal
} }
}
break; if (i == m_ColorRangeProp->count_enums) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to find matching COLOR_RANGE value for '%s'. Colors may be inaccurate!",
desiredValue);
} }
} }
else if (desiredValue != nullptr) {
if (i == m_ColorRangeProp->count_enums) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to find matching COLOR_RANGE value for '%s'. Colors may be inaccurate!", "COLOR_RANGE property does not exist on output plane. Colors may be inaccurate!");
desiredValue);
} }
} }
else if (desiredValue != nullptr) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"COLOR_RANGE property does not exist on output plane. Colors may be inaccurate!");
}
m_LastFullRange = fullRange; // Set COLOR_ENCODING property for the plane
} {
const char* desiredValue = getDrmColorEncodingValue(frame);
if (colorspace != m_LastColorSpace) { if (m_ColorEncodingProp != nullptr && desiredValue != nullptr) {
const char* desiredValue = getDrmColorEncodingValue(frame); int i;
if (m_ColorEncodingProp != nullptr && desiredValue != nullptr) { for (i = 0; i < m_ColorEncodingProp->count_enums; i++) {
int i; if (!strcmp(desiredValue, m_ColorEncodingProp->enums[i].name)) {
err = drmModeObjectSetProperty(m_DrmFd, m_PlaneId, DRM_MODE_OBJECT_PLANE,
m_ColorEncodingProp->prop_id, m_ColorEncodingProp->enums[i].value);
if (err == 0) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"%s: %s",
m_ColorEncodingProp->name,
desiredValue);
}
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"drmModeObjectSetProperty(%s) failed: %d",
m_ColorEncodingProp->name,
errno);
// Non-fatal
}
for (i = 0; i < m_ColorEncodingProp->count_enums; i++) { break;
if (!strcmp(desiredValue, m_ColorEncodingProp->enums[i].name)) {
err = drmModeObjectSetProperty(m_DrmFd, m_PlaneId, DRM_MODE_OBJECT_PLANE,
m_ColorEncodingProp->prop_id, m_ColorEncodingProp->enums[i].value);
if (err == 0) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"%s: %s",
m_ColorEncodingProp->name,
desiredValue);
}
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"drmModeObjectSetProperty(%s) failed: %d",
m_ColorEncodingProp->name,
errno);
// Non-fatal
} }
}
break; if (i == m_ColorEncodingProp->count_enums) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to find matching COLOR_ENCODING value for '%s'. Colors may be inaccurate!",
desiredValue);
} }
} }
else if (desiredValue != nullptr) {
if (i == m_ColorEncodingProp->count_enums) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to find matching COLOR_ENCODING value for '%s'. Colors may be inaccurate!", "COLOR_ENCODING property does not exist on output plane. Colors may be inaccurate!");
desiredValue);
} }
} }
else if (desiredValue != nullptr) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"COLOR_ENCODING property does not exist on output plane. Colors may be inaccurate!");
}
m_LastColorSpace = colorspace;
} }
// Update the overlay // Update the overlay

View file

@ -95,8 +95,6 @@ private:
uint32_t m_CrtcId; uint32_t m_CrtcId;
uint32_t m_PlaneId; uint32_t m_PlaneId;
uint32_t m_CurrentFbId; uint32_t m_CurrentFbId;
bool m_LastFullRange;
int m_LastColorSpace;
drmModePlanePtr m_Plane; drmModePlanePtr m_Plane;
drmModePropertyPtr m_ColorEncodingProp; drmModePropertyPtr m_ColorEncodingProp;
drmModePropertyPtr m_ColorRangeProp; drmModePropertyPtr m_ColorRangeProp;