vdr-plugin-softhddevice-drm-gles 1.5.9-20e15de
misc.h
Go to the documentation of this file.
1
21#ifndef __MISC_H
22#define __MISC_H
23
24#include <cstdio>
25#include <cstdint>
26
27extern "C" {
28#include <libavutil/frame.h>
29}
30
31#ifdef USE_GLES
32#include <EGL/egl.h>
33#include <GLES2/gl2.h>
34
35#include "logger.h"
36
37/****************************************************************************************
38 * GL Helpers
39 ***************************************************************************************/
40static inline void glCheckError(const char *stmt, const char *fname, int line) {
41 GLint err = glGetError();
42 if (err != GL_NO_ERROR)
43 LOGERROR("GL Error (0x%08x): %s failed at %s:%i", err, stmt, fname, line);
44}
45
46static inline void eglCheckError(const char *stmt, const char *fname, int line) {
47 EGLint err = eglGetError();
48 if (err != EGL_SUCCESS)
49 LOGERROR("EGL ERROR (0x%08x): %s failed at %s:%i", err, stmt, fname, line);
50}
51
52#define GL_CHECK(stmt) do { \
53 stmt; \
54 glCheckError(#stmt, __FILE__, __LINE__); \
55 } while (0)
56
57#define EGL_CHECK(stmt) do { \
58 stmt; \
59 eglCheckError(#stmt, __FILE__, __LINE__); \
60 } while (0)
61
62#endif // USE_GLES
63
64
65/****************************************************************************************
66 * FFmpeg Helpers
67 ***************************************************************************************/
68#ifndef AV_NOPTS_VALUE
69#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
70#endif
71
72#define VIDEO_SURFACES_MAX 3
73
81static inline bool isInterlacedFrame(AVFrame *frame)
82{
83#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58,7,100)
84 return frame->interlaced_frame;
85#else
86 return frame->flags & AV_FRAME_FLAG_INTERLACED;
87#endif
88}
89
93#ifdef av_err2str
94#undef av_err2str
95static inline const char* av_err2string(int errnum)
96{
97 static char str[3][AV_ERROR_MAX_STRING_SIZE];
98 char buf[AV_ERROR_MAX_STRING_SIZE];
99 static int idx = 0;
100
101 idx = (idx + 1) % 3;
102 av_make_error_string(buf, AV_ERROR_MAX_STRING_SIZE, errnum);
103 snprintf(str[idx], sizeof(str[idx]), "%s", buf);
104
105 return str[idx];
106}
107#define av_err2str(err) av_err2string(err)
108#endif
109
110/****************************************************************************************
111 * Misc Helpers
112 ***************************************************************************************/
113
119static inline const char *Timestamp2String(int64_t ts, uint8_t divisor)
120{
121 static char buf[3][20];
122 static int idx = 0;
123
124 if (ts == (int64_t) AV_NOPTS_VALUE) {
125 return "--:--:--.---";
126 }
127
128 ts /= divisor;
129
130 idx = (idx + 1) % 3;
131 snprintf(buf[idx], sizeof(buf[idx]), "%2d:%02d:%02d.%03d",
132 (int)(ts / (3600000)), (int)((ts / (60000)) % 60),
133 (int)((ts / (1000)) % 60), (int)(ts % 1000));
134
135 return buf[idx];
136}
137
141static inline uint32_t ReadBytes(const uint8_t *data, int count)
142{
143 uint32_t value = 0;
144
145 for (int i = 0; i < count; i++) {
146 value <<= 8;
147 value |= data[i];
148 }
149
150 return value;
151}
152
153#endif
Logger class header file.
#define LOGERROR
Definition logger.h:41
#define AV_NOPTS_VALUE
Definition misc.h:69
static uint32_t ReadBytes(const uint8_t *data, int count)
Return count amount of bytes from data.
Definition misc.h:141
static bool isInterlacedFrame(AVFrame *frame)
Check, if this is an interlaced frame.
Definition misc.h:81
static const char * Timestamp2String(int64_t ts, uint8_t divisor)
Workaround for av_err2str() not working with C++.
Definition misc.h:119