MythTV  master
mythvideodrm.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QGuiApplication>
3 #include <qpa/qplatformnativeinterface.h>
4 
5 // MythTV
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 
77 void MythVideoDRM::ColourSpaceUpdated(bool /*PrimariesChanged*/)
78 {
79  if (!(m_colourSpace && m_device && m_videoPlane.get()))
80  return;
81 
82  MythAtomics queue;
83  if (auto range = MythDRMProperty::GetProperty("COLOR_RANGE", m_videoPlane->m_properties); range.get())
84  {
86  queue.emplace_back(m_videoPlane->m_id, range->m_id, rangev);
87  }
88 
89  if (auto encoding = MythDRMProperty::GetProperty("COLOR_ENCODING", m_videoPlane->m_properties); encoding.get())
90  {
92  queue.emplace_back(m_videoPlane->m_id, encoding->m_id, encv);
93  }
94 
95  if (!queue.empty())
96  m_device->QueueAtomics(queue);
97 }
98 
99 bool MythVideoDRM::RenderFrame(AVDRMFrameDescriptor* DRMDesc, MythVideoFrame* Frame)
100 {
101  if (!m_valid)
102  return false;
103 
104  if (!(DRMDesc && Frame))
105  {
106  m_valid = false;
107  return false;
108  }
109 
110  if (!m_handles.contains(DRMDesc))
111  {
112  auto buffer = MythVideoDRMBuffer::Create(m_device, DRMDesc, { Frame->m_width, Frame->m_height });
113  if (!buffer.get())
114  {
115  m_valid = false;
116  return false;
117  }
118  m_handles.insert(DRMDesc, buffer);
119  }
120 
121  Frame->m_displayed = true;
122  auto handle = m_handles[DRMDesc];
123  auto id = m_videoPlane->m_id;
124 
125  if (m_lastSrc != Frame->m_srcRect)
126  {
127  m_lastSrc = Frame->m_srcRect;
128  m_device->QueueAtomics({
129  { id, m_videoPlane->m_srcXProp->m_id, m_lastSrc.left() << 16 },
130  { id, m_videoPlane->m_srcYProp->m_id, m_lastSrc.top() << 16 },
131  { id, m_videoPlane->m_srcWProp->m_id, m_lastSrc.width() << 16 },
132  { id, m_videoPlane->m_srcHProp->m_id, m_lastSrc.height() << 16 }});
133  }
134 
135  if (m_lastDst != Frame->m_dstRect)
136  {
137  m_lastDst = Frame->m_dstRect;
138  m_device->QueueAtomics({
139  { id, m_videoPlane->m_crtcXProp->m_id, (m_lastDst.left() + 1) & ~1 },
140  { id, m_videoPlane->m_crtcYProp->m_id, (m_lastDst.top() + 1) & ~1 },
141  { id, m_videoPlane->m_crtcWProp->m_id, (m_lastDst.width() + 1) & ~1 },
142  { id, m_videoPlane->m_crtcHProp->m_id, (m_lastDst.height() + 1) & ~1 }});
143  }
144 
145  return m_device->QueueAtomics({{ id, m_videoPlane->m_fbIdProp->m_id, handle->GetFB() }});
146 }
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
MythVideoDRMUtils::FFmpegColorEncodingToDRM
static uint64_t FFmpegColorEncodingToDRM(const DRMProp &Property, int Encoding)
Definition: mythvideodrmutils.cpp:38
MythVideoColourSpace::GetColourSpace
int GetColourSpace() const
Definition: mythvideocolourspace.cpp:485
MythVideoDRMUtils::FFmpegColorRangeToDRM
static uint64_t FFmpegColorRangeToDRM(const DRMProp &Property, int Range)
Definition: mythvideodrmutils.cpp:14
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:39
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:107
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
mythvideocolourspace.h
MythVideoDRM::ColourSpaceUpdated
void ColourSpaceUpdated(bool)
Definition: mythvideodrm.cpp:77
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:99
LOC
#define LOC
Definition: mythvideodrm.cpp:18
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:102
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