MythTV  master
mythdrmconnector.cpp
Go to the documentation of this file.
1 // MythTV
3 
10 DRMConn MythDRMConnector::Create(int FD, uint32_t Id)
11 {
12  if (FD && Id)
13  if (auto c = std::shared_ptr<MythDRMConnector>(new MythDRMConnector(FD, Id)); c.get() && c->m_id)
14  return c;
15 
16  return nullptr;
17 }
18 
19 DRMConn MythDRMConnector::GetConnector(const DRMConns &Connectors, uint32_t Id)
20 {
21  auto match = [&Id](const auto & Conn) { return Conn->m_id == Id; };
22  if (auto found = std::find_if(Connectors.cbegin(), Connectors.cend(), match); found != Connectors.cend())
23  return *found;
24  return nullptr;
25 }
26 
28 {
29  DRMConns result;
30  if (auto resources = MythDRMResources(FD); *resources)
31  {
32  for (auto i = 0; i < resources->count_connectors; ++i)
33  if (auto connector = Create(FD, resources->connectors[i]); connector.get())
34  result.emplace_back(connector);
35  }
36  return result;
37 }
38 
40 {
41  if (auto * connector = drmModeGetConnector(FD, Id); connector)
42  {
43  m_id = connector->connector_id;
44  m_encoderId = connector->encoder_id;
45  m_type = connector->connector_type;
46  m_typeId = connector->connector_type_id;
48  m_state = connector->connection;
49  m_mmWidth = connector->mmWidth;
50  m_mmHeight = connector->mmHeight;
51  m_properties = MythDRMProperty::GetProperties(FD, m_id, DRM_MODE_OBJECT_CONNECTOR);
52  for (auto i = 0; i < connector->count_modes; ++i)
53  m_modes.emplace_back(MythDRMMode::Create(&connector->modes[i], i));
54  drmModeFreeConnector(connector);
55  }
56 }
57 
59 {
60  return m_state == DRM_MODE_CONNECTED;
61 }
62 
63 QString MythDRMConnector::GetConnectorName(uint32_t Type, uint32_t Id)
64 {
65  constexpr size_t count = DRM_MODE_CONNECTOR_DPI + 1;
66  static const std::array<const QString,count> s_connectorNames
67  {
68  "None", "VGA", "DVI", "DVI", "DVI", "Composite", "TV", "LVDS",
69  "CTV", "DIN", "DP", "HDMI", "HDMI", "TV", "eDP", "Virtual", "DSI", "DPI"
70  };
71  uint32_t type = qMin(Type, static_cast<uint32_t>(DRM_MODE_CONNECTOR_DPI));
72  return QString("%1%2").arg(s_connectorNames[type]).arg(Id);
73 }
74 
75 DRMConn MythDRMConnector::GetConnectorByName(const DRMConns& Connectors, const QString &Name)
76 {
77  for (const auto & connector : Connectors)
78  if (Name.compare(connector->m_name, Qt::CaseInsensitive) == 0)
79  return connector;
80 
81  return nullptr;
82 }
MythDRMConnector::GetConnectors
static DRMConns GetConnectors(int FD)
Definition: mythdrmconnector.cpp:27
MythDRMConnector::MythDRMConnector
MythDRMConnector(int FD, uint32_t Id)
Definition: mythdrmconnector.cpp:39
MythDRMConnector::m_modes
DRMModes m_modes
Definition: mythdrmconnector.h:31
MythDRMConnector::m_mmHeight
uint32_t m_mmHeight
Definition: mythdrmconnector.h:30
MythDRMConnector::m_state
drmModeConnection m_state
Definition: mythdrmconnector.h:28
MythDRMConnector::m_id
uint32_t m_id
Definition: mythdrmconnector.h:23
MythDRMConnector::GetConnectorName
static QString GetConnectorName(uint32_t Type, uint32_t Id)
Definition: mythdrmconnector.cpp:63
MythDRMConnector::m_mmWidth
uint32_t m_mmWidth
Definition: mythdrmconnector.h:29
MythDRMResources
A simple wrapper around a drmModeResPtr that ensures proper cleanup.
Definition: mythdrmresources.h:24
mythdrmconnector.h
DRMConn
std::shared_ptr< class MythDRMConnector > DRMConn
Definition: mythdrmconnector.h:10
MythDRMMode::Create
static DRMMode Create(drmModeModeInfoPtr Mode, int Index)
Definition: mythdrmmode.cpp:7
MythDRMConnector::GetConnectorByName
static DRMConn GetConnectorByName(const DRMConns &Connectors, const QString &Name)
Definition: mythdrmconnector.cpp:75
MythDRMConnector::m_properties
DRMProps m_properties
Definition: mythdrmconnector.h:32
MythDRMConnector::Connected
bool Connected() const
Definition: mythdrmconnector.cpp:58
MythDRMConnector::m_type
uint32_t m_type
Definition: mythdrmconnector.h:25
Name
Definition: channelsettings.cpp:46
MythDRMConnector::m_typeId
uint32_t m_typeId
Definition: mythdrmconnector.h:26
MythDRMConnector::m_encoderId
uint32_t m_encoderId
Definition: mythdrmconnector.h:24
DRMConns
std::vector< DRMConn > DRMConns
Definition: mythdrmconnector.h:11
MythDRMConnector::GetConnector
static DRMConn GetConnector(const DRMConns &Connectors, uint32_t Id)
Definition: mythdrmconnector.cpp:19
MythDRMConnector::Create
static DRMConn Create(int FD, uint32_t Id)
Definition: mythdrmconnector.cpp:10
MythDRMProperty::GetProperties
static DRMProps GetProperties(int FD, uint32_t ObjectId, uint32_t ObjectType)
Definition: mythdrmproperty.cpp:25
MythDRMConnector::m_name
QString m_name
Definition: mythdrmconnector.h:27