vdr-plugin-softhddevice-drm-gles 1.7.3-98a2ef7
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#include <vdr/remux.h>
24
25#ifdef USE_GLES
26#include <EGL/egl.h>
27#include <GLES2/gl2.h>
28
29#include "logger.h"
30
36/****************************************************************************************
37 * GL Helpers
38 ***************************************************************************************/
42static inline void glCheckError(const char *stmt, const char *fname, int line) {
44 if (err != GL_NO_ERROR)
45 LOGERROR("GL Error (0x%08x): %s failed at %s:%i", err, stmt, fname, line);
46}
47
51static inline void eglCheckError(const char *stmt, const char *fname, int line) {
53 if (err != EGL_SUCCESS)
54 LOGERROR("EGL ERROR (0x%08x): %s failed at %s:%i", err, stmt, fname, line);
55}
56
58#define GL_CHECK(stmt) do { \
59 stmt; \
60 glCheckError(#stmt, __FILE__, __LINE__); \
61 } while (0)
62
64#define EGL_CHECK(stmt) do { \
65 stmt; \
66 eglCheckError(#stmt, __FILE__, __LINE__); \
67 } while (0)
68
69#endif // USE_GLES
70
71
72/****************************************************************************************
73 * FFmpeg Helpers
74 ***************************************************************************************/
75#ifndef AV_NOPTS_VALUE
76#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
77#endif
78
79#define VIDEO_SURFACES_MAX 3
80
88static inline bool isInterlacedFrame(AVFrame *frame)
89{
90#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58,7,100)
91 return frame->interlaced_frame;
92#else
93 return frame->flags & AV_FRAME_FLAG_INTERLACED;
94#endif
95}
96
97#ifdef av_err2str
98#undef av_err2str
102static inline const char* av_err2string(int errnum)
103{
104 static char str[3][AV_ERROR_MAX_STRING_SIZE];
106 static int idx = 0;
107
108 idx = (idx + 1) % 3;
110 snprintf(str[idx], sizeof(str[idx]), "%s", buf);
111
112 return str[idx];
113}
114#define av_err2str(err) av_err2string(err)
115#endif
116
117/****************************************************************************************
118 * Misc Helpers
119 ***************************************************************************************/
120
129static inline const char *Timestamp2String(int64_t ts, uint8_t divisor)
130{
131 static char buf[3][20];
132 static int idx = 0;
133
134 if (ts == (int64_t) AV_NOPTS_VALUE) {
135 return "--:--:--.---";
136 }
137
138 ts /= divisor;
139
140 idx = (idx + 1) % 3;
141 snprintf(buf[idx], sizeof(buf[idx]), "%2d:%02d:%02d.%03d",
142 (int)(ts / (3600000)), (int)((ts / (60000)) % 60),
143 (int)((ts / (1000)) % 60), (int)(ts % 1000));
144
145 return buf[idx];
146}
147
149static inline const char *Timestamp2StringPts(int64_t ts) { return Timestamp2String(ts, PTSTICKS / 1000); }
151static inline const char *Timestamp2StringMs(int64_t ts) { return Timestamp2String(ts, 1); }
152
156static inline uint32_t ReadBytes(const uint8_t *data, int count)
157{
158 uint32_t value = 0;
159
160 for (int i = 0; i < count; i++) {
161 value <<= 8;
162 value |= data[i];
163 }
164
165 return value;
166}
167
170#endif
static void glCheckError(const char *stmt, const char *fname, int line)
Check for OpenGL errors and log them.
Definition misc.h:42
static const char * av_err2string(int errnum)
Workaround for av_err2str() not working with C++.
Definition misc.h:102
#define LOGERROR
log to LOG_ERR
Definition logger.h:40
#define AV_NOPTS_VALUE
Definition misc.h:76
static const char * Timestamp2StringMs(int64_t ts)
Input PTS is in ms.
Definition misc.h:151
static const char * Timestamp2StringPts(int64_t ts)
Input PTS is in PTSTICKS.
Definition misc.h:149
static uint32_t ReadBytes(const uint8_t *data, int count)
Return count amount of bytes from data
Definition misc.h:156
static void eglCheckError(const char *stmt, const char *fname, int line)
Check for EGL errors and log them.
Definition misc.h:51
static bool isInterlacedFrame(AVFrame *frame)
Check, if this is an interlaced frame.
Definition misc.h:88
static const char * Timestamp2String(int64_t ts, uint8_t divisor)
Nice time-stamp string.
Definition misc.h:129
Logger Header File.