vdr-plugin-softhddevice-drm-gles 1.6.2
misc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
13#ifndef __MISC_H
14#define __MISC_H
15
16#include <cstdio>
17#include <cstdint>
18
19extern "C" {
20#include <libavutil/frame.h>
21}
22
23#ifdef USE_GLES
24#include <EGL/egl.h>
25#include <GLES2/gl2.h>
26
27#include "logger.h"
28
34/****************************************************************************************
35 * GL Helpers
36 ***************************************************************************************/
40static inline void glCheckError(const char *stmt, const char *fname, int line) {
42 if (err != GL_NO_ERROR)
43 LOGERROR("GL Error (0x%08x): %s failed at %s:%i", err, stmt, fname, line);
44}
45
49static inline void eglCheckError(const char *stmt, const char *fname, int line) {
51 if (err != EGL_SUCCESS)
52 LOGERROR("EGL ERROR (0x%08x): %s failed at %s:%i", err, stmt, fname, line);
53}
54
56#define GL_CHECK(stmt) do { \
57 stmt; \
58 glCheckError(#stmt, __FILE__, __LINE__); \
59 } while (0)
60
62#define EGL_CHECK(stmt) do { \
63 stmt; \
64 eglCheckError(#stmt, __FILE__, __LINE__); \
65 } while (0)
66
67#endif // USE_GLES
68
69
70/****************************************************************************************
71 * FFmpeg Helpers
72 ***************************************************************************************/
73#ifndef AV_NOPTS_VALUE
74#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
75#endif
76
77#define VIDEO_SURFACES_MAX 3
78
86static inline bool isInterlacedFrame(AVFrame *frame)
87{
88#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58,7,100)
89 return frame->interlaced_frame;
90#else
91 return frame->flags & AV_FRAME_FLAG_INTERLACED;
92#endif
93}
94
95#ifdef av_err2str
96#undef av_err2str
100static inline const char* av_err2string(int errnum)
101{
102 static char str[3][AV_ERROR_MAX_STRING_SIZE];
104 static int idx = 0;
105
106 idx = (idx + 1) % 3;
108 snprintf(str[idx], sizeof(str[idx]), "%s", buf);
109
110 return str[idx];
111}
112#define av_err2str(err) av_err2string(err)
113#endif
114
115/****************************************************************************************
116 * Misc Helpers
117 ***************************************************************************************/
118
127static inline const char *Timestamp2String(int64_t ts, uint8_t divisor)
128{
129 static char buf[3][20];
130 static int idx = 0;
131
132 if (ts == (int64_t) AV_NOPTS_VALUE) {
133 return "--:--:--.---";
134 }
135
136 ts /= divisor;
137
138 idx = (idx + 1) % 3;
139 snprintf(buf[idx], sizeof(buf[idx]), "%2d:%02d:%02d.%03d",
140 (int)(ts / (3600000)), (int)((ts / (60000)) % 60),
141 (int)((ts / (1000)) % 60), (int)(ts % 1000));
142
143 return buf[idx];
144}
145
149static inline uint32_t ReadBytes(const uint8_t *data, int count)
150{
151 uint32_t value = 0;
152
153 for (int i = 0; i < count; i++) {
154 value <<= 8;
155 value |= data[i];
156 }
157
158 return value;
159}
160
163#endif
static void glCheckError(const char *stmt, const char *fname, int line)
Check for OpenGL errors and log them.
Definition misc.h:40
static const char * av_err2string(int errnum)
Workaround for av_err2str() not working with C++.
Definition misc.h:100
#define LOGERROR
log to LOG_ERR
Definition logger.h:34
#define AV_NOPTS_VALUE
Definition misc.h:74
static uint32_t ReadBytes(const uint8_t *data, int count)
Return count amount of bytes from data
Definition misc.h:149
static void eglCheckError(const char *stmt, const char *fname, int line)
Check for EGL errors and log them.
Definition misc.h:49
static bool isInterlacedFrame(AVFrame *frame)
Check, if this is an interlaced frame.
Definition misc.h:86
static const char * Timestamp2String(int64_t ts, uint8_t divisor)
Nice time-stamp string.
Definition misc.h:127
Logger Header File.