vdr-plugin-softhddevice-drm-gles 1.6.4-d0291bb
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
34
46static inline size_t ReadLineFromFile(char *buf, size_t size, const char * file) {
47 FILE *fd = NULL;
48 size_t character;
49
50 fd = fopen(file, "r");
51 if (fd == NULL) {
52 LOGERROR("%s: Can't open %s", __FUNCTION__, file);
53 return 0;
54 }
55
56 character = getline(&buf, &size, fd);
57
58 fclose(fd);
59
60 return character;
61}
62
69{
70public:
73 char *txt_buf;
74 char *read_ptr;
75 size_t bufsize = 128;
76 size_t read_size;
77
78 txt_buf = (char *) calloc(bufsize, sizeof(char));
79
80 read_size = ReadLineFromFile(txt_buf, bufsize, "/sys/firmware/devicetree/base/compatible");
81 if (!read_size) {
82 free((void *)txt_buf);
83 LOGERROR("could not from read /sys/firmware/devicetree/base/compatible, no quirks set");
84 return;
85 }
86
88 // be aware: device tree string can contain \x0 bytes, so every C-string function
89 // thinks, we already reached the string's terminating null bytes
90 // so copy the string into a temporary string without the "\0"
91 char *_txt_buf = (char *) calloc(bufsize, sizeof(char));
92 char *_read_ptr = _txt_buf;
93 for (size_t i = 0; i < bufsize; i++) {
94 if (memcmp(read_ptr, "\0", sizeof(char))) {
95 memcpy(_read_ptr, read_ptr, sizeof(char));
96 _read_ptr++;
97 }
98 read_ptr++;
99 }
100
102 while(read_size) {
103 if (strstr(read_ptr, "bcm2836")) {
104 m_deviceName = "bcm2836 (Raspberry Pi 2 Model B)";
106 break;
107 }
108 if (strstr(read_ptr, "bcm2837")) {
109 m_deviceName = "bcm2837 (Raspberry Pi 2 Model B v1.2/ 3 Model B, Raspberry Pi 3 Compute Module 3)";
111 break;
112 }
113 if (strstr(read_ptr, "bcm2711")) {
114 m_deviceName = "bcm2711 (Raspberry Pi 4 Model B, Compute Module 4, Pi 400)";
116 break;
117 }
118 if (strstr(read_ptr, "bcm2712")) {
119 m_deviceName = "bcm2712 (Raspberry Pi 5, Compute Module 5, Pi 500)";
121 break;
122 }
123 if (strstr(read_ptr, "amlogic")) {
124 m_deviceName = "amlogic";
128 break;
129 }
130
131 read_size -= strlen(read_ptr) + 1;
132 read_ptr = (char *)&read_ptr[(strlen(read_ptr) + 1)];
133 }
134
135 if (m_deviceName)
136 LOGDEBUG("%s found%s%s%s%s", m_deviceName,
137 m_quirks & QUIRK_NO_HW_DEINT ? ", hw deinterlacer disabled" : "",
138 m_quirks & QUIRK_CODEC_FLUSH_WORKAROUND ? ", flush workaround" : "",
139 m_quirks & QUIRK_CODEC_NEEDS_DIMENSION_PARSE ? ", parse H.264 dimensions" : "",
140 m_quirks & QUIRK_CODEC_SKIP_FIRST_FRAMES ? ", skip first I-Frames" : "");
141 else
142 LOGDEBUG("%s found, no quirks set", txt_buf);
143
144 free((void *)_txt_buf);
145 free((void *)txt_buf);
146 }
147
149 int GetQuirks(void) { return m_quirks; };
151 const char *GetName(void) { return m_deviceName; };
152
153private:
154 const char *m_deviceName = nullptr;
155 int m_quirks = 0;
156};
157
158#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:45
#define LOGERROR
log to LOG_ERR
Definition logger.h:39
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)
@ QUIRK_CODEC_SKIP_FIRST_FRAMES
set, if codec should skip first I-Frames
@ QUIRK_CODEC_SKIP_NUM_FRAMES
skip QUIRK_CODEC_SKIP_NUM_FRAMES, in case QUIRK_CODEC_SKIP_FIRST_FRAMES is set
@ QUIRK_CODEC_NEEDS_DIMENSION_PARSE
set, if codec needs some infos for init (coded_width and coded_height)
@ QUIRK_NO_HW_DEINT
set, if no hw deinterlacer available
Logger Header File.