vdr-plugin-softhddevice-drm-gles 1.7.3-98a2ef7
hardwaredevice.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
13#ifndef __HARDWAREDEVICE_H
14#define __HARDWAREDEVICE_H
15
16#include <cstdio>
17#include <cstdint>
18#include <string>
19
20#include "logger.h"
21
30
42static inline size_t ReadLineFromFile(char *buf, size_t size, const char * file) {
43 FILE *fd = NULL;
44 size_t character;
45
46 fd = fopen(file, "r");
47 if (fd == NULL) {
48 LOGERROR("%s: Can't open %s", __FUNCTION__, file);
49 return 0;
50 }
51
52 character = getline(&buf, &size, fd);
53
54 fclose(fd);
55
56 return character;
57}
58
65{
66public:
69 char *txt_buf;
70 char *read_ptr;
71 size_t bufsize = 128;
72 size_t read_size;
73
74 txt_buf = (char *) calloc(bufsize, sizeof(char));
75
76 read_size = ReadLineFromFile(txt_buf, bufsize, "/sys/firmware/devicetree/base/compatible");
77 if (!read_size) {
78 free((void *)txt_buf);
79 LOGERROR("could not from read /sys/firmware/devicetree/base/compatible, no quirks set");
80 return;
81 }
82
84 // be aware: device tree string can contain \x0 bytes, so every C-string function
85 // thinks, we already reached the string's terminating null bytes
86 // so copy the string into a temporary string without the "\0"
87 char *_txt_buf = (char *) calloc(bufsize, sizeof(char));
88 char *_read_ptr = _txt_buf;
89 for (size_t i = 0; i < bufsize; i++) {
90 if (memcmp(read_ptr, "\0", sizeof(char))) {
91 memcpy(_read_ptr, read_ptr, sizeof(char));
92 _read_ptr++;
93 }
94 read_ptr++;
95 }
96
98 while(read_size) {
99 if (strstr(read_ptr, "bcm2836")) {
100 m_deviceName = "bcm2836 (Raspberry Pi 2 Model B)";
102 break;
103 }
104 if (strstr(read_ptr, "bcm2837")) {
105 m_deviceName = "bcm2837 (Raspberry Pi 2 Model B v1.2/ 3 Model B, Raspberry Pi 3 Compute Module 3)";
107 break;
108 }
109 if (strstr(read_ptr, "bcm2711")) {
110 m_deviceName = "bcm2711 (Raspberry Pi 4 Model B, Compute Module 4, Pi 400)";
112 break;
113 }
114 if (strstr(read_ptr, "bcm2712")) {
115 m_deviceName = "bcm2712 (Raspberry Pi 5, Compute Module 5, Pi 500)";
117 break;
118 }
119
120 read_size -= strlen(read_ptr) + 1;
121 read_ptr = (char *)&read_ptr[(strlen(read_ptr) + 1)];
122 }
123
124 if (m_deviceName)
125 LOGDEBUG("%s found%s", m_deviceName,
126 m_quirks & QUIRK_CODEC_FLUSH_WORKAROUND ? ", flush workaround" : "");
127 else
128 LOGDEBUG("%s found, no quirks set", txt_buf);
129
130 free((void *)_txt_buf);
131 free((void *)txt_buf);
132 }
133
135 int GetQuirks(void) { return m_quirks; };
137 const char *GetName(void) { return m_deviceName; };
138
139private:
140 const char *m_deviceName = nullptr;
141 int m_quirks = 0;
142};
143
144#endif
Hardware device.
const char * GetName(void)
Get Hardware Name (currently unused)
cHardwareDevice(void)
Create a new hardware device.
int GetQuirks(void)
Get Hardware Quirks.
const char * m_deviceName
device name
int m_quirks
hardware dependent quirks for codec and and display
#define LOGDEBUG
log to LOG_DEBUG
Definition logger.h:46
#define LOGERROR
log to LOG_ERR
Definition logger.h:40
HardwareQuirks
Hardware dependent quirks.
static size_t ReadLineFromFile(char *buf, size_t size, const char *file)
Helper function to read a line from a given file.
@ QUIRK_CODEC_FLUSH_WORKAROUND
set, if we have to close and reopen the codec instead of avcodec_flush_buffers (rpi)
Logger Header File.