MythTV master
mythhdrtracker.cpp
Go to the documentation of this file.
1// MythTV
5
6#include "mythavutil.h"
7#include "mythframe.h"
8#include "mythhdrtracker.h"
9
10#define LOC QString("HDRTracker: ")
11
19{
20 if (!MDisplay)
21 return nullptr;
22
23 // Check for HDR support
24 auto hdr = MDisplay->GetHDRState();
25 if (!hdr.get())
26 return nullptr;
27
28 // We only support HDR10 and HLG
29 if (!hdr->m_supportedTypes)
30 {
31 LOG(VB_PLAYBACK, LOG_INFO, LOC + "No HDR support detected for this display");
32 return nullptr;
33 }
34
35 // We need to be able to set metadata
36 if (!hdr->IsControllable())
37 {
38 LOG(VB_PLAYBACK, LOG_INFO, LOC + "HDR signalling support not available");
39 return nullptr;
40 }
41
42 return std::shared_ptr<MythHDRTracker>(new MythHDRTracker(hdr));
43}
44
46 : m_hdr(std::move(HDR))
47{
48 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Tracking HDR signalling for: %1")
49 .arg(m_hdr->TypesToString().join(",")));
50}
51
53{
54 Reset();
55}
56
58{
59 // TODO Revert to the pre-existing state - don't assume SDR
60 if (m_hdr && m_hdr->m_currentType != MythHDR::SDR)
61 m_hdr->SetHDRMetadata(MythHDR::SDR, nullptr);
62 m_metadata = nullptr;
63}
64
73{
74 if (!Frame || !m_hdr)
75 return;
76
77 // Do we have an HDR EOTF that is supported by the display?
78 if (auto eotf = MythAVUtil::FFmpegTransferToHDRType(Frame->m_colortransfer);
79 eotf & m_hdr->m_supportedTypes)
80 {
81 if (eotf == MythHDR::HLG)
82 {
83 if (m_hdr->m_currentType != MythHDR::HLG)
84 {
85 m_hdr->SetHDRMetadata(MythHDR::HLG, nullptr);
86 m_metadata = nullptr;
87 }
88 }
89 else
90 {
91 // TODO Better change tracking when there is no metadata (i.e. Frame->m_hdrMetadata is null)
92 if (m_hdr->m_currentType != MythHDR::HDR10 || !m_metadata ||
93 (Frame->m_hdrMetadata.get() && !m_metadata->Equals(Frame->m_hdrMetadata.get())))
94 {
95 m_metadata = Frame->m_hdrMetadata ?
96 std::make_shared<MythHDRVideoMetadata>(*(Frame->m_hdrMetadata.get())) :
97 std::make_shared<MythHDRVideoMetadata>();
98 m_hdr->SetHDRMetadata(MythHDR::HDR10, m_metadata);
99 }
100 }
101 }
102 else
103 {
104 Reset();
105 }
106}
107
static MythHDR::HDRType FFmpegTransferToHDRType(int Transfer)
Definition: mythavutil.cpp:118
MythHDRPtr GetHDRState()
MythHDRPtr m_hdr
MythHDRVideoPtr m_metadata
MythHDRTracker(MythHDRPtr HDR)
void Update(class MythVideoFrame *Frame)
Track changes to the HDR type (EOTF) and request a change when needed.
static HDRTracker Create(class MythDisplay *MDisplay)
Create a tracker instance that looks for changes in the required EOTF.
@ SDR
Definition: mythhdr.h:38
@ HDR10
Definition: mythhdr.h:39
@ HLG
Definition: mythhdr.h:40
std::shared_ptr< class MythHDR > MythHDRPtr
Definition: mythhdr.h:30
#define LOC
std::shared_ptr< class MythHDRTracker > HDRTracker
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
STL namespace.