MythTV  master
mythvideodrm.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QGuiApplication>
3 #include <qpa/qplatformnativeinterface.h>
4 
5 // MythTV
6 #include "mythlogging.h"
7 #include "mythmainwindow.h"
8 #include "mythframe.h"
9 #include "mythvideocolourspace.h"
12 #include "drm/mythvideodrmutils.h"
13 #include "drm/mythvideodrm.h"
14 
15 // Std
16 #include <unistd.h>
17 
18 #define LOC QString("DRMVideo: ")
19 
21  : m_colourSpace(ColourSpace)
22 {
23  if (m_colourSpace)
25 
26  if (auto drmdisplay = HasMythMainWindow() ? dynamic_cast<MythDisplayDRM*>(GetMythMainWindow()->GetDisplay()) : nullptr; drmdisplay)
27  {
28  if (m_device = drmdisplay->GetDevice(); m_device && m_device->Atomic() && m_device->Authenticated())
29  {
30  if (m_videoPlane = m_device->GetVideoPlane(); m_videoPlane.get() && m_videoPlane->m_id)
31  {
32  m_valid = m_videoPlane->m_fbIdProp && m_videoPlane->m_crtcIdProp &&
33  m_videoPlane->m_srcWProp && m_videoPlane->m_srcHProp &&
34  m_videoPlane->m_srcXProp && m_videoPlane->m_srcYProp &&
35  m_videoPlane->m_crtcXProp && m_videoPlane->m_crtcYProp &&
36  m_videoPlane->m_crtcWProp && m_videoPlane->m_crtcHProp;
37  }
38  }
39  }
40 
41  if (m_valid)
42  {
43  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Using Plane #%1 for video").arg(m_videoPlane->m_id));
44 
45  // Set the CRTC for the plane. No need to do this for every frame.
46  m_device->QueueAtomics({{ m_videoPlane->m_id, m_videoPlane->m_crtcIdProp->m_id, m_device->GetCrtc()->m_id }});
47 
48  // Set colourspace and listen for changes
49  if (m_colourSpace)
50  {
51  // Disable colour adjustments.
52  // Note: If DRM subsequently fails, these should be re-enabled by
53  // the OpenGL code.
56  ColourSpaceUpdated(true/*??*/);
57  }
58  }
59  else
60  {
61  LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to setup DRM video");
62  }
63 }
64 
66 {
67  LOG(VB_GENERAL, LOG_INFO, LOC + "Closing");
68 
69  // Release colourspace
70  if (m_colourSpace)
72 
73  // Disable our video plane
74  //m_device->DisableVideoPlane();
75 }
76 
78 {
79  return m_valid;
80 }
81 
82 void MythVideoDRM::ColourSpaceUpdated(bool /*PrimariesChanged*/)
83 {
84  if (!(m_colourSpace && m_device && m_videoPlane.get()))
85  return;
86 
87  MythAtomics queue;
88  if (auto range = MythDRMProperty::GetProperty("COLOR_RANGE", m_videoPlane->m_properties); range.get())
89  {
91  queue.emplace_back(m_videoPlane->m_id, range->m_id, rangev);
92  }
93 
94  if (auto encoding = MythDRMProperty::GetProperty("COLOR_ENCODING", m_videoPlane->m_properties); encoding.get())
95  {
97  queue.emplace_back(m_videoPlane->m_id, encoding->m_id, encv);
98  }
99 
100  if (!queue.empty())
101  m_device->QueueAtomics(queue);
102 }
103 
104 bool MythVideoDRM::RenderFrame(AVDRMFrameDescriptor* DRMDesc, MythVideoFrame* Frame)
105 {
106  if (!m_valid)
107  return false;
108 
109  if (!(DRMDesc && Frame))
110  {
111  m_valid = false;
112  return false;
113  }
114 
115  if (!m_handles.contains(DRMDesc))
116  {
117  auto buffer = MythVideoDRMBuffer::Create(m_device, DRMDesc, { Frame->m_width, Frame->m_height });
118  if (!buffer.get())
119  {
120  m_valid = false;
121  return false;
122  }
123  m_handles.insert(DRMDesc, buffer);
124  }
125 
126  Frame->m_displayed = true;
127  auto handle = m_handles[DRMDesc];
128  auto id = m_videoPlane->m_id;
129 
130  if (m_lastSrc != Frame->m_srcRect)
131  {
132  m_lastSrc = Frame->m_srcRect;
133  m_device->QueueAtomics({
134  { id, m_videoPlane->m_srcXProp->m_id, m_lastSrc.left() << 16 },
135  { id, m_videoPlane->m_srcYProp->m_id, m_lastSrc.top() << 16 },
136  { id, m_videoPlane->m_srcWProp->m_id, m_lastSrc.width() << 16 },
137  { id, m_videoPlane->m_srcHProp->m_id, m_lastSrc.height() << 16 }});
138  }
139 
140  if (m_lastDst != Frame->m_dstRect)
141  {
142  m_lastDst = Frame->m_dstRect;
143  m_device->QueueAtomics({
144  { id, m_videoPlane->m_crtcXProp->m_id, (m_lastDst.left() + 1) & ~1 },
145  { id, m_videoPlane->m_crtcYProp->m_id, (m_lastDst.top() + 1) & ~1 },
146  { id, m_videoPlane->m_crtcWProp->m_id, (m_lastDst.width() + 1) & ~1 },
147  { id, m_videoPlane->m_crtcHProp->m_id, (m_lastDst.height() + 1) & ~1 }});
148  }
149 
150  return m_device->QueueAtomics({{ id, m_videoPlane->m_fbIdProp->m_id, handle->GetFB() }});
151 }
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
MythVideoDRM::m_valid
bool m_valid
Definition: mythvideodrm.h:29
MythDisplayDRM
Definition: mythdisplaydrm.h:11
MythVideoDRM::IsValid
bool IsValid()
Definition: mythvideodrm.cpp:77
MythVideoColourSpace::GetColourSpace
int GetColourSpace() const
Definition: mythvideocolourspace.cpp:485
Frame
Definition: zmdefines.h:93
mythvideodrmutils.h
MythVideoColourSpace::SetSupportedAttributes
void SetSupportedAttributes(PictureAttributeSupported Supported)
Enable the given set of picture attributes.
Definition: mythvideocolourspace.cpp:111
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythframe.h
mythvideodrm.h
MythVideoDRM::MythVideoDRM
MythVideoDRM(MythVideoColourSpace *ColourSpace)
Definition: mythvideodrm.cpp:20
MythVideoDRM::~MythVideoDRM
~MythVideoDRM() override
Definition: mythvideodrm.cpp:65
HasMythMainWindow
bool HasMythMainWindow(void)
Definition: mythmainwindow.cpp:106
kPictureAttributeSupported_None
@ kPictureAttributeSupported_None
Definition: videoouttypes.h:118
MythDRMProperty::GetProperty
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
Definition: mythdrmproperty.cpp:55
MythVideoColourSpace::GetRange
int GetRange() const
Definition: mythvideocolourspace.cpp:480
MythVideoDRMUtils::FFmpegColorEncodingToDRM
static uint64_t FFmpegColorEncodingToDRM(DRMProp Property, int Encoding)
Definition: mythvideodrmutils.cpp:37
mythvideocolourspace.h
MythVideoDRM::ColourSpaceUpdated
void ColourSpaceUpdated(bool)
Definition: mythvideodrm.cpp:82
mythlogging.h
MythVideoDRM::m_videoPlane
DRMPlane m_videoPlane
Definition: mythvideodrm.h:31
mythdisplaydrm.h
MythVideoDRM::RenderFrame
bool RenderFrame(AVDRMFrameDescriptor *DRMDesc, MythVideoFrame *Frame)
Definition: mythvideodrm.cpp:104
LOC
#define LOC
Definition: mythvideodrm.cpp:18
MythVideoDRMUtils::FFmpegColorRangeToDRM
static uint64_t FFmpegColorRangeToDRM(DRMProp Property, int Range)
Definition: mythvideodrmutils.cpp:14
MythVideoDRM::m_handles
QMap< AVDRMFrameDescriptor *, DRMHandle > m_handles
Definition: mythvideodrm.h:34
mythdrmframebuffer.h
MythVideoDRM::m_colourSpace
MythVideoColourSpace * m_colourSpace
Definition: mythvideodrm.h:35
MythVideoDRM::m_lastSrc
QRect m_lastSrc
Definition: mythvideodrm.h:32
MythVideoColourSpace::Updated
void Updated(bool PrimariesChanged)
MythVideoDRM::m_lastDst
QRect m_lastDst
Definition: mythvideodrm.h:33
MythVideoDRM::m_device
MythDRMPtr m_device
Definition: mythvideodrm.h:30
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:101
MythVideoDRMBuffer::Create
static DRMHandle Create(MythDRMPtr Device, AVDRMFrameDescriptor *DRMDesc, QSize Size)
Definition: mythvideodrmbuffer.cpp:34
MythAtomics
std::vector< MythAtomic > MythAtomics
Definition: mythdrmdevice.h:20
MythVideoFrame
Definition: mythframe.h:88
ReferenceCounter::IncrRef
virtual int IncrRef(void)
Increments reference count.
Definition: referencecounter.cpp:101
mythmainwindow.h
MythVideoColourSpace
MythVideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
Definition: mythvideocolourspace.h:18