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