Skip to content

Commit

Permalink
CVideoLayerBridgeDRMPRIME: set HDR metadata only if edid supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
lrusak committed Jan 29, 2021
1 parent 242075e commit 56c19de
Showing 1 changed file with 25 additions and 11 deletions.
Expand Up @@ -9,6 +9,7 @@
#include "VideoLayerBridgeDRMPRIME.h"

#include "cores/VideoPlayer/Buffers/VideoBufferDRMPRIME.h"
#include "utils/EDIDUtils.h"
#include "utils/log.h"
#include "windowing/gbm/drm/DRMAtomic.h"

Expand Down Expand Up @@ -200,20 +201,30 @@ void CVideoLayerBridgeDRMPRIME::Configure(CVideoBufferDRMPRIME* buffer)
m_DRM->AddProperty(plane, "COLOR_RANGE", value);

auto connector = m_DRM->GetConnector();

std::vector<uint8_t> raw;
std::tie(result, raw) = connector->GetEDID();

KODI::UTILS::CEDIDUtils edid;
if (result)
edid.SetEDID(raw);

if (connector->SupportsProperty("HDR_OUTPUT_METADATA"))
{
m_hdr_metadata.metadata_type = HDMI_STATIC_METADATA_TYPE1;
m_hdr_metadata.hdmi_metadata_type1 = {
.eotf = GetEOTF(picture),
.metadata_type = HDMI_STATIC_METADATA_TYPE1,
};

if (m_hdr_blob_id)
drmModeDestroyPropertyBlob(m_DRM->GetFileDescriptor(), m_hdr_blob_id);
m_hdr_blob_id = 0;
m_hdr_metadata.hdmi_metadata_type1.metadata_type = HDMI_STATIC_METADATA_TYPE1;

uint8_t eotf = GetEOTF(picture);

if (m_hdr_metadata.hdmi_metadata_type1.eotf)
if (edid.SupportsEOTF(eotf))
{
m_hdr_metadata.hdmi_metadata_type1.eotf = eotf;

if (m_hdr_blob_id)
drmModeDestroyPropertyBlob(m_DRM->GetFileDescriptor(), m_hdr_blob_id);
m_hdr_blob_id = 0;

const AVMasteringDisplayMetadata* mdmd = GetMasteringDisplayMetadata(picture);
if (mdmd && mdmd->has_primaries)
{
Expand All @@ -231,6 +242,7 @@ void CVideoLayerBridgeDRMPRIME::Configure(CVideoBufferDRMPRIME* buffer)
m_hdr_metadata.hdmi_metadata_type1.white_point.y =
std::round(av_q2d(mdmd->white_point[1]) * 50000.0);
}

if (mdmd && mdmd->has_luminance)
{
// Convert to unsigned 16-bit value in units of 1 cd/m2,
Expand All @@ -253,11 +265,13 @@ void CVideoLayerBridgeDRMPRIME::Configure(CVideoBufferDRMPRIME* buffer)

drmModeCreatePropertyBlob(m_DRM->GetFileDescriptor(), &m_hdr_metadata, sizeof(m_hdr_metadata),
&m_hdr_blob_id);
}

m_DRM->AddProperty(connector, "HDR_OUTPUT_METADATA", m_hdr_blob_id);
m_DRM->SetActive(true);

m_DRM->AddProperty(connector, "HDR_OUTPUT_METADATA", m_hdr_blob_id);
}
}

m_DRM->SetActive(true);
}

void CVideoLayerBridgeDRMPRIME::SetVideoPlane(CVideoBufferDRMPRIME* buffer, const CRect& destRect)
Expand Down

0 comments on commit 56c19de

Please sign in to comment.