MythTV  master
mythhdrtracker.cpp
Go to the documentation of this file.
1 // MythTV
4 #include "libmythui/mythedid.h"
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 
MythHDRPtr
std::shared_ptr< class MythHDR > MythHDRPtr
Definition: mythhdr.h:30
MythHDRTracker::Update
void Update(class MythVideoFrame *Frame)
Track changes to the HDR type (EOTF) and request a change when needed.
Definition: mythhdrtracker.cpp:72
MythHDRTracker::Reset
void Reset()
Definition: mythhdrtracker.cpp:57
Frame
Definition: zmdefines.h:93
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
mythframe.h
MythHDR::HLG
@ HLG
Definition: mythhdr.h:40
MythDisplay::GetHDRState
MythHDRPtr GetHDRState()
Definition: mythdisplay.cpp:939
mythdisplay.h
mythlogging.h
MythHDRTracker::m_metadata
MythHDRVideoPtr m_metadata
Definition: mythhdrtracker.h:23
MythHDR::HDR10
@ HDR10
Definition: mythhdr.h:39
mythhdrtracker.h
MythDisplay
Definition: mythdisplay.h:22
HDRTracker
std::shared_ptr< class MythHDRTracker > HDRTracker
Definition: mythhdrtracker.h:10
mythedid.h
std
Definition: mythchrono.h:23
mythavutil.h
MythHDRTracker::~MythHDRTracker
~MythHDRTracker()
Definition: mythhdrtracker.cpp:52
MythAVUtil::FFmpegTransferToHDRType
static MythHDR::HDRType FFmpegTransferToHDRType(int Transfer)
Definition: mythavutil.cpp:117
LOC
#define LOC
Definition: mythhdrtracker.cpp:10
MythHDR::SDR
@ SDR
Definition: mythhdr.h:38
MythVideoFrame
Definition: mythframe.h:88
MythHDRTracker::MythHDRTracker
MythHDRTracker(MythHDRPtr HDR)
Definition: mythhdrtracker.cpp:45
MythHDRTracker::Create
static HDRTracker Create(class MythDisplay *MDisplay)
Create a tracker instance that looks for changes in the required EOTF.
Definition: mythhdrtracker.cpp:18
MythHDRTracker::m_hdr
MythHDRPtr m_hdr
Definition: mythhdrtracker.h:24