MythTV master
mythdrmhdr.cpp
Go to the documentation of this file.
1// MythTV
2#include "libmythbase/mythconfig.h"
4
7
8// libdrm
9extern "C" {
10enum hdmi_eotf : std::uint8_t
11{
16};
17
18enum hdmi_metadata_type : std::uint8_t
19{
21};
22
23#if HAVE_STRUCT_HDR_METADATA_INFOFRAME
24#include <drm_mode.h>
25#else
27 __u8 eotf;
29 struct {
30 __u16 x, y;
32 struct {
33 __u16 x, y;
37 __u16 max_cll;
38 __u16 max_fall;
39};
40
43 union {
45 };
46};
47#endif
48}
49
50#define LOC QString("HDR: ")
51
53{
54 auto * display = dynamic_cast<MythDisplayDRM*>(MDisplay);
55 if (!display)
56 return nullptr;
57
58 // Display support for HDR formats has already been checked. We need to check
59 // here that we have a valid, authenticated DRM device and that the connector
60 // supports the HDR_OUTPUT_METADATA property
61 auto device = display->GetDevice();
62 if (!(device && device->Authenticated() && device->Atomic()))
63 return nullptr;
64
65 if (auto connector = device->GetConnector(); connector.get())
66 if (auto hdrprop = MythDRMProperty::GetProperty("HDR_OUTPUT_METADATA", connector->m_properties); hdrprop)
67 return std::shared_ptr<MythHDR>(new MythDRMHDR(device, hdrprop, Desc));
68
69 return nullptr;
70}
71
73 : MythHDR(Desc),
74 m_device(Device),
75 m_connector(Device->GetConnector()),
76 m_hdrProp(std::move(HDRProp)),
77 m_crtc(Device->GetCrtc())
78{
79 m_controllable = true;
80 m_activeProp = MythDRMProperty::GetProperty("ACTIVE", m_crtc->m_properties);
81}
82
84{
85 Cleanup();
86}
87
89{
90 if (m_hdrBlob && m_device)
91 {
92 drmModeDestroyPropertyBlob(m_device->GetFD(), m_hdrBlob);
93 m_hdrBlob = 0;
94 }
95}
96
98{
99 switch (Type)
100 {
103 default: break;
104 }
106}
107
109{
110 Cleanup();
111 auto eotf = MythHDRToDRMHDR(Type);
112 hdr_output_metadata drmmetadata =
113 {
115 { static_cast<__u8>(eotf), HDMI_STATIC_METADATA_TYPE1, {{0,0}}, {0,0}, 0, 0, 0, 0}
116 };
117
118 if (Metadata)
119 {
120 drmmetadata.hdmi_metadata_type1.max_display_mastering_luminance = Metadata->m_maxMasteringLuminance;
121 drmmetadata.hdmi_metadata_type1.min_display_mastering_luminance = Metadata->m_minMasteringLuminance;
122 drmmetadata.hdmi_metadata_type1.max_cll = Metadata->m_maxContentLightLevel;
123 drmmetadata.hdmi_metadata_type1.max_fall = Metadata->m_maxFrameAverageLightLevel;
124 drmmetadata.hdmi_metadata_type1.white_point.x = Metadata->m_whitePoint[0];
125 drmmetadata.hdmi_metadata_type1.white_point.y = Metadata->m_whitePoint[1];
126 for (size_t i = 0; i < 3; ++i)
127 {
128 drmmetadata.hdmi_metadata_type1.display_primaries[i].x = Metadata->m_displayPrimaries[i][0];
129 drmmetadata.hdmi_metadata_type1.display_primaries[i].y = Metadata->m_displayPrimaries[i][1];
130 }
131 }
132
133 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Creating HDR info frame for %1")
134 .arg(eotf == HDMI_EOTF_BT_2100_HLG ? "HLG" : eotf == HDMI_EOTF_SMPTE_ST2084 ? "HDR10" : "SDR"));
135 if (drmModeCreatePropertyBlob(m_device->GetFD(), &drmmetadata, sizeof(drmmetadata), &m_hdrBlob) == 0)
136 {
137 LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("HDR blob id %1").arg(m_hdrBlob));
138 m_device->QueueAtomics({{ m_connector->m_id, m_hdrProp->m_id, m_hdrBlob }});
139 if (m_crtc && m_activeProp)
140 m_device->QueueAtomics({{ m_crtc->m_id, m_activeProp->m_id, 1 }});
141 m_currentType = Type;
142 }
143 else
144 {
145 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create HDR blob id");
146 }
147}
A device containing images (ie. USB stick, CD, storage group etc)
void SetHDRMetadata(HDRType Type, const MythHDRMetaPtr &Metadata) override
Definition: mythdrmhdr.cpp:108
void Cleanup()
Definition: mythdrmhdr.cpp:88
DRMCrtc m_crtc
Definition: mythdrmhdr.h:23
DRMProp m_hdrProp
Definition: mythdrmhdr.h:22
DRMConn m_connector
Definition: mythdrmhdr.h:21
static MythHDRPtr Create(class MythDisplay *MDisplay, const MythHDRDesc &Desc)
Definition: mythdrmhdr.cpp:52
~MythDRMHDR() override
Definition: mythdrmhdr.cpp:83
DRMProp m_activeProp
Definition: mythdrmhdr.h:24
MythDRMHDR(const MythDRMPtr &Device, DRMProp HDRProp, const MythHDRDesc &Desc)
Definition: mythdrmhdr.cpp:72
MythDRMPtr m_device
Definition: mythdrmhdr.h:20
uint32_t m_hdrBlob
Definition: mythdrmhdr.h:25
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
MythDRMPtr GetDevice()
HDRType m_currentType
Definition: mythhdr.h:56
HDRType
Definition: mythhdr.h:37
@ HDR10
Definition: mythhdr.h:39
@ HLG
Definition: mythhdr.h:40
bool m_controllable
Definition: mythhdr.h:62
std::tuple< HDRTypes, double, double, double > MythHDRDesc
Definition: mythhdr.h:45
std::shared_ptr< class MythDRMDevice > MythDRMPtr
Definition: mythdrmdevice.h:19
#define LOC
Definition: mythdrmhdr.cpp:50
hdmi_metadata_type
Definition: mythdrmhdr.cpp:19
@ HDMI_STATIC_METADATA_TYPE1
Definition: mythdrmhdr.cpp:20
static hdmi_eotf MythHDRToDRMHDR(MythHDR::HDRType Type)
Definition: mythdrmhdr.cpp:97
hdmi_eotf
Definition: mythdrmhdr.cpp:11
@ HDMI_EOTF_BT_2100_HLG
Definition: mythdrmhdr.cpp:15
@ HDMI_EOTF_SMPTE_ST2084
Definition: mythdrmhdr.cpp:14
@ HDMI_EOTF_TRADITIONAL_GAMMA_SDR
Definition: mythdrmhdr.cpp:12
@ HDMI_EOTF_TRADITIONAL_GAMMA_HDR
Definition: mythdrmhdr.cpp:13
std::shared_ptr< class MythDRMProperty > DRMProp
std::shared_ptr< class MythHDR > MythHDRPtr
Definition: mythhdr.h:30
std::shared_ptr< class MythHDRMetadata > MythHDRMetaPtr
Definition: mythhdr.h:14
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
STL namespace.
__u16 max_display_mastering_luminance
Definition: mythdrmhdr.cpp:35
__u16 min_display_mastering_luminance
Definition: mythdrmhdr.cpp:36
struct hdr_metadata_infoframe::@73 white_point
struct hdr_metadata_infoframe::@72 display_primaries[3]
struct hdr_metadata_infoframe hdmi_metadata_type1
Definition: mythdrmhdr.cpp:44