Skip to content

Commit

Permalink
MythDRMHDR: Simplify metadata handling
Browse files Browse the repository at this point in the history
- no need to keep a local copy of the DRM metadata.
- squashes a coverity warning and allows us to move the metadata
definitions out of the header.
  • Loading branch information
mark-kendall committed Feb 20, 2021
1 parent 5a919f2 commit 912728a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 61 deletions.
72 changes: 56 additions & 16 deletions mythtv/libs/libmythui/platforms/drm/mythdrmhdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,48 @@
#include "platforms/mythdisplaydrm.h"
#include "mythlogging.h"

// libdrm
extern "C" {
enum hdmi_eotf
{
HDMI_EOTF_TRADITIONAL_GAMMA_SDR = 0,
HDMI_EOTF_TRADITIONAL_GAMMA_HDR,
HDMI_EOTF_SMPTE_ST2084,
HDMI_EOTF_BT_2100_HLG,
};

enum hdmi_metadata_type
{
HDMI_STATIC_METADATA_TYPE1 = 0,
};

#if HAVE_STRUCT_HDR_METADATA_INFOFRAME
#include <drm_mode.h>
#else
struct hdr_metadata_infoframe {
__u8 eotf;
__u8 metadata_type;
struct {
__u16 x, y;
} display_primaries[3];
struct {
__u16 x, y;
} white_point;
__u16 max_display_mastering_luminance;
__u16 min_display_mastering_luminance;
__u16 max_cll;
__u16 max_fall;
};

struct hdr_output_metadata {
__u32 metadata_type;
union {
struct hdr_metadata_infoframe hdmi_metadata_type1;
};
};
#endif
}

#define LOC QString("HDR: ")

MythHDRPtr MythDRMHDR::Create(MythDisplay* _Display, const MythHDRDesc& Desc)
Expand Down Expand Up @@ -63,34 +105,32 @@ static inline hdmi_eotf MythHDRToDRMHDR(MythHDR::HDRType Type)

void MythDRMHDR::SetHDRMetadata(HDRType Type, const MythHDRMetaPtr& Metadata)
{
static hdr_output_metadata s_defaultMetadata =
{
HDMI_STATIC_METADATA_TYPE1, { 0, HDMI_STATIC_METADATA_TYPE1, {{0,0}}, {0,0}, 0, 0, 0, 0}
};

Cleanup();
auto eotf = MythHDRToDRMHDR(Type);
m_drmMetadata = s_defaultMetadata;
m_drmMetadata.hdmi_metadata_type1.eotf = eotf;
hdr_output_metadata drmmetadata =
{
HDMI_STATIC_METADATA_TYPE1,
{ static_cast<__u8>(eotf), HDMI_STATIC_METADATA_TYPE1, {{0,0}}, {0,0}, 0, 0, 0, 0}
};

if (Metadata)
{
m_drmMetadata.hdmi_metadata_type1.max_display_mastering_luminance = Metadata->m_maxMasteringLuminance;
m_drmMetadata.hdmi_metadata_type1.min_display_mastering_luminance = Metadata->m_minMasteringLuminance;
m_drmMetadata.hdmi_metadata_type1.max_cll = Metadata->m_maxContentLightLevel;
m_drmMetadata.hdmi_metadata_type1.max_fall = Metadata->m_maxFrameAverageLightLevel;
m_drmMetadata.hdmi_metadata_type1.white_point.x = Metadata->m_whitePoint[0];
m_drmMetadata.hdmi_metadata_type1.white_point.y = Metadata->m_whitePoint[1];
drmmetadata.hdmi_metadata_type1.max_display_mastering_luminance = Metadata->m_maxMasteringLuminance;
drmmetadata.hdmi_metadata_type1.min_display_mastering_luminance = Metadata->m_minMasteringLuminance;
drmmetadata.hdmi_metadata_type1.max_cll = Metadata->m_maxContentLightLevel;
drmmetadata.hdmi_metadata_type1.max_fall = Metadata->m_maxFrameAverageLightLevel;
drmmetadata.hdmi_metadata_type1.white_point.x = Metadata->m_whitePoint[0];
drmmetadata.hdmi_metadata_type1.white_point.y = Metadata->m_whitePoint[1];
for (size_t i = 0; i < 3; ++i)
{
m_drmMetadata.hdmi_metadata_type1.display_primaries[i].x = Metadata->m_displayPrimaries[i][0];
m_drmMetadata.hdmi_metadata_type1.display_primaries[i].y = Metadata->m_displayPrimaries[i][1];
drmmetadata.hdmi_metadata_type1.display_primaries[i].x = Metadata->m_displayPrimaries[i][0];
drmmetadata.hdmi_metadata_type1.display_primaries[i].y = Metadata->m_displayPrimaries[i][1];
}
}

LOG(VB_GENERAL, LOG_INFO, LOC + QString("Creating HDR info frame for %1")
.arg(eotf == HDMI_EOTF_BT_2100_HLG ? "HLG" : eotf == HDMI_EOTF_SMPTE_ST2084 ? "HDR10" : "SDR"));
if (drmModeCreatePropertyBlob(m_device->GetFD(), &m_drmMetadata, sizeof(m_drmMetadata), &m_hdrBlob) == 0)
if (drmModeCreatePropertyBlob(m_device->GetFD(), &drmmetadata, sizeof(drmmetadata), &m_hdrBlob) == 0)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("HDR blob id %1").arg(m_hdrBlob));
m_device->QueueAtomics({{ m_connector->m_id, m_hdrProp->m_id, m_hdrBlob }});
Expand Down
45 changes: 0 additions & 45 deletions mythtv/libs/libmythui/platforms/drm/mythdrmhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,6 @@
#include "mythhdr.h"
#include "platforms/mythdrmdevice.h"

// libdrm
extern "C" {
enum hdmi_eotf
{
HDMI_EOTF_TRADITIONAL_GAMMA_SDR = 0,
HDMI_EOTF_TRADITIONAL_GAMMA_HDR,
HDMI_EOTF_SMPTE_ST2084,
HDMI_EOTF_BT_2100_HLG,
};

enum hdmi_metadata_type
{
HDMI_STATIC_METADATA_TYPE1 = 0,
};

#if HAVE_STRUCT_HDR_METADATA_INFOFRAME
#include <drm_mode.h>
#else
struct hdr_metadata_infoframe {
__u8 eotf;
__u8 metadata_type;
struct {
__u16 x, y;
} display_primaries[3];
struct {
__u16 x, y;
} white_point;
__u16 max_display_mastering_luminance;
__u16 min_display_mastering_luminance;
__u16 max_cll;
__u16 max_fall;
};

struct hdr_output_metadata {
__u32 metadata_type;
union {
struct hdr_metadata_infoframe hdmi_metadata_type1;
};
};
#endif
}

using DRMMeta = hdr_output_metadata;

class MythDRMHDR : public MythHDR
{
public:
Expand All @@ -68,7 +24,6 @@ class MythDRMHDR : public MythHDR
DRMCrtc m_crtc { nullptr };
DRMProp m_activeProp { nullptr };
uint32_t m_hdrBlob { 0 };
DRMMeta m_drmMetadata;
};

#endif

0 comments on commit 912728a

Please sign in to comment.