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