MythTV  master
mythdrmproperty.cpp
Go to the documentation of this file.
1 // MythTV
3 
4 // Qt
5 #include <QStringList>
6 
16 MythDRMProperty::MythDRMProperty(Type mType, uint32_t Id, uint32_t Flags, const char * Name)
17  : m_type(mType),
18  m_id(Id),
19  m_readOnly(Flags & DRM_MODE_PROP_IMMUTABLE),
20  m_atomic(Flags & DRM_MODE_PROP_ATOMIC),
21  m_name(Name)
22 {
23 }
24 
25 DRMProps MythDRMProperty::GetProperties(int FD, const uint32_t ObjectId, uint32_t ObjectType)
26 {
27  DRMProps result;
28  if (auto * props = drmModeObjectGetProperties(FD, ObjectId, ObjectType); props)
29  {
30  for (uint32_t index = 0; index < props->count_props; ++index)
31  {
32  if (auto * prop = drmModeGetProperty(FD, props->props[index]); prop)
33  {
34  auto value = props->prop_values[index];
35  if (prop->flags & DRM_MODE_PROP_RANGE)
36  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMRangeProperty(value, prop)));
37  else if (prop->flags & DRM_MODE_PROP_ENUM)
38  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMEnumProperty(value, prop)));
39  else if (prop->flags & DRM_MODE_PROP_BITMASK)
40  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMBitmaskProperty(value, prop)));
41  else if (prop->flags & DRM_MODE_PROP_BLOB)
42  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMBlobProperty(FD, value, prop)));
43  else if (prop->flags & DRM_MODE_PROP_OBJECT)
44  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMObjectProperty(prop)));
45  else if (prop->flags & DRM_MODE_PROP_SIGNED_RANGE)
46  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMSignedRangeProperty(value, prop)));
47  drmModeFreeProperty(prop);
48  }
49  }
50  drmModeFreeObjectProperties(props);
51  }
52  return result;
53 }
54 
56 {
57  for (const auto & prop : Properties)
58  if (Name.compare(prop->m_name, Qt::CaseInsensitive) == 0)
59  return prop;
60 
61  return nullptr;
62 }
63 
64 MythDRMRangeProperty::MythDRMRangeProperty(uint64_t Value, drmModePropertyPtr Property)
65  : MythDRMProperty(Range, Property->prop_id, Property->flags, Property->name),
66  m_value(Value)
67 {
68  for (int i = 0; i < Property->count_values; ++i)
69  {
70  auto value = Property->values[i];
71  if (value < m_min)
72  m_min = value;
73  if (value > m_max)
74  m_max = value;
75  }
76 }
77 
79 {
80  return QString("%1 Value: %2 Range: %3<->%4").arg(m_name).arg(m_value).arg(m_min).arg(m_max);
81 }
82 
84  : MythDRMProperty(SignedRange, Property->prop_id, Property->flags, Property->name),
85  m_value(static_cast<int64_t>(Value))
86 {
87  for (int i = 0; i < Property->count_values; ++i)
88  {
89  auto value = static_cast<int64_t>(Property->values[i]);
90  if (value < m_min)
91  m_min = value;
92  if (value > m_max)
93  m_max = value;
94  }
95 }
96 
98 {
99  return QString("%1 Value: %2 Range: %3<->%4").arg(m_name).arg(m_value).arg(m_min).arg(m_max);
100 }
101 
102 MythDRMEnumProperty::MythDRMEnumProperty(uint64_t Value, drmModePropertyPtr Property)
103  : MythDRMProperty(Enum, Property->prop_id, Property->flags, Property->name),
104  m_value(Value)
105 {
106  for (int i = 0; i < Property->count_enums; ++i)
107  m_enums.emplace(Property->enums[i].value, Property->enums[i].name);
108 }
109 
111 {
112  QStringList values;
113  for (const auto & value : m_enums)
114  values.append(QString("%1(%2)").arg(value.first).arg(value.second));
115  return QString("%1 Value: %2 Values: %3").arg(m_name).arg(m_value).arg(values.join(", "));
116 }
117 
118 MythDRMBitmaskProperty::MythDRMBitmaskProperty(uint64_t Value, drmModePropertyPtr Property)
119  : MythDRMEnumProperty(Value, Property)
120 {
121  m_type = Bitmask;
122 }
123 
124 MythDRMBlobProperty::MythDRMBlobProperty(int FD, uint64_t Value, drmModePropertyPtr Property)
125  : MythDRMProperty(Blob, Property->prop_id, Property->flags, Property->name)
126 {
127  if (auto * blob = drmModeGetPropertyBlob(FD, static_cast<uint32_t>(Value)); blob)
128  {
129  m_blob = QByteArray(reinterpret_cast<const char *>(blob->data), static_cast<int>(blob->length));
130  drmModeFreePropertyBlob(blob);
131  }
132 }
133 
135  : MythDRMProperty(Object, Property->prop_id, Property->flags, Property->name)
136 {
137 }
mythdrmproperty.h
MythDRMRangeProperty::MythDRMRangeProperty
MythDRMRangeProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:64
DRMProps
std::vector< DRMProp > DRMProps
Definition: mythdrmproperty.h:8
MythDRMObjectProperty::MythDRMObjectProperty
MythDRMObjectProperty(drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:134
MythDRMObjectProperty
Definition: mythdrmproperty.h:84
MythDRMProperty::m_name
QString m_name
Definition: mythdrmproperty.h:33
MythDRMRangeProperty::m_max
uint64_t m_max
Definition: mythdrmproperty.h:49
MythDRMProperty::MythDRMProperty
MythDRMProperty(Type mType, uint32_t Id, uint32_t Flags, const char *Name)
Definition: mythdrmproperty.cpp:16
MythDRMEnumProperty::m_value
uint64_t m_value
Definition: mythdrmproperty.h:67
MythDRMBlobProperty::MythDRMBlobProperty
MythDRMBlobProperty(int FD, uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:124
MythDRMEnumProperty::m_enums
std::map< uint64_t, QString > m_enums
Definition: mythdrmproperty.h:68
MythDRMEnumProperty::MythDRMEnumProperty
MythDRMEnumProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:102
MythDRMBitmaskProperty
Definition: mythdrmproperty.h:71
Property
Definition: upnpcdsobjects.h:45
MythDRMEnumProperty
Definition: mythdrmproperty.h:62
MythDRMProperty::GetProperty
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
Definition: mythdrmproperty.cpp:55
MythDRMProperty::Type
Type
Definition: mythdrmproperty.h:13
MythDRMRangeProperty
Definition: mythdrmproperty.h:42
MythDRMSignedRangeProperty::MythDRMSignedRangeProperty
MythDRMSignedRangeProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:83
Properties
QMultiMap< QString, Property * > Properties
Definition: upnpcdsobjects.h:96
DRMProp
std::shared_ptr< class MythDRMProperty > DRMProp
Definition: mythdrmproperty.h:7
MythDRMEnumProperty::ToString
QString ToString() override
Definition: mythdrmproperty.cpp:110
MythDRMSignedRangeProperty::m_max
int64_t m_max
Definition: mythdrmproperty.h:59
MythDRMBlobProperty::m_blob
QByteArray m_blob
Definition: mythdrmproperty.h:81
MythDRMSignedRangeProperty
Definition: mythdrmproperty.h:52
MythDRMProperty::m_type
Type m_type
Definition: mythdrmproperty.h:29
MythDRMRangeProperty::m_min
uint64_t m_min
Definition: mythdrmproperty.h:48
Name
Definition: channelsettings.cpp:71
MythDRMBlobProperty
Definition: mythdrmproperty.h:77
MythDRMSignedRangeProperty::ToString
QString ToString() override
Definition: mythdrmproperty.cpp:97
MythDRMSignedRangeProperty::m_min
int64_t m_min
Definition: mythdrmproperty.h:58
MythDRMRangeProperty::ToString
QString ToString() override
Definition: mythdrmproperty.cpp:78
MythDRMSignedRangeProperty::m_value
int64_t m_value
Definition: mythdrmproperty.h:57
MythDRMProperty
A wrapper around a DRM object property.
Definition: mythdrmproperty.h:10
MythDRMRangeProperty::m_value
uint64_t m_value
Definition: mythdrmproperty.h:47
MythDRMProperty::Bitmask
@ Bitmask
Definition: mythdrmproperty.h:18
MythDRMProperty::GetProperties
static DRMProps GetProperties(int FD, uint32_t ObjectId, uint32_t ObjectType)
Definition: mythdrmproperty.cpp:25
MythDRMBitmaskProperty::MythDRMBitmaskProperty
MythDRMBitmaskProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:118