ginga 1.0
The Ginga iTV middleware
Loading...
Searching...
No Matches
aux-ginga.h
1/* Copyright (C) 2006-2018 PUC-Rio/Laboratorio TeleMidia
2
3This file is part of Ginga (Ginga-NCL).
4
5Ginga is free software: you can redistribute it and/or modify it
6under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10Ginga is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13License for more details.
14
15You should have received a copy of the GNU General Public License
16along with Ginga. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef AUX_GINGA_H
19#define AUX_GINGA_H
20
21#include "aux-glib.h"
22#include "ginga.h"
23
24GINGA_BEGIN_DECLS
25
26#include "config.h"
27#include <stdlib.h>
28
29#define GINGA_PRAGMA_DIAG PRAGMA_DIAG
30#define GINGA_PRAGMA_DIAG_PUSH PRAGMA_DIAG_PUSH
31#define GINGA_PRAGMA_DIAG_POP PRAGMA_DIAG_POP
32#define GINGA_PRAGMA_DIAG_IGNORE PRAGMA_DIAG_IGNORE
33#define GINGA_PRAGMA_DIAG_WARNING PRAGMA_DIAG_WARNING
34
35// C library.
36#include <string.h>
37#include <math.h>
38#include <stdlib.h>
39
40// External C libraries.
41#include <gdk/gdk.h>
42
43GINGA_PRAGMA_DIAG_PUSH ()
44GINGA_PRAGMA_DIAG_IGNORE (-Wcast-qual)
45GINGA_PRAGMA_DIAG_IGNORE (-Wconversion)
46#include <gst/app/gstappsink.h>
47#include <gst/gst.h>
48#include <gst/video/video.h>
49GINGA_PRAGMA_DIAG_POP ()
50
51GINGA_END_DECLS
52
53// C++ library.
54#include <iostream>
55#include <algorithm>
56#include <list>
57#include <map>
58#include <set>
59#include <string>
60#include <vector>
61using namespace std;
62
63namespace ginga {
64
65// Utility macros.
66#undef unused
67#define unused(...) G_GNUC_UNUSED __VA_ARGS__
68
69template <typename... T>
70void
71ignore_unused (const T &...)
72{
73}
74
75#undef cast
76#define cast(a, b) (dynamic_cast<a> ((b)))
77#define instanceof(a, b) (cast (a, (b)) != nullptr)
78
79#define tryinsert(a, b, fn) \
80 (std::count ((b).begin (), (b).end (), (a)) == 0) ? ((b).fn (a), true) \
81 : false
82
83#define MAP_GET_IMPL(m, a, b) \
84 G_STMT_START \
85 { \
86 auto it = (m).find ((a)); \
87 if (it == (m).end ()) \
88 return false; \
89 tryset ((b), it->second); \
90 return true; \
91 } \
92 G_STMT_END
93
94#define MAP_SET_IMPL(m, a, b) \
95 G_STMT_START \
96 { \
97 auto it = (m).find ((a)); \
98 (m)[(a)] = (b); \
99 return it == (m).end (); \
100 } \
101 G_STMT_END
102
103// Logging, warnings and errors.
104#define GINGA_STRFUNC (__ginga_strfunc (G_STRFUNC)).c_str ()
105string __ginga_strfunc (const string &);
106#define __ginga_log(fn, fmt, ...) \
107 fn ("%s: " fmt, GINGA_STRFUNC, ##__VA_ARGS__)
108
109#define TRACE(fmt, ...) __ginga_log (g_debug, fmt, ##__VA_ARGS__)
110#define WARNING(fmt, ...) __ginga_log (g_warning, fmt, ##__VA_ARGS__)
111#define ERROR(fmt, ...) __ginga_log (g_error, fmt, ##__VA_ARGS__)
112#define CRITICAL(fmt, ...) __ginga_log (g_critical, fmt, ##__VA_ARGS__)
113
114#define ERROR_NOT_IMPLEMENTED(fmt, ...) \
115 ERROR ("not implemented: " fmt, ##__VA_ARGS__)
116
117// Internal types.
118typedef GdkRGBA Color;
119typedef GdkRectangle Rect;
120typedef GstClockTime Time;
121
122// Time macros and functions.
123#define GINGA_TIME_NONE GST_CLOCK_TIME_NONE
124#define GINGA_TIME_IS_VALID(t) GST_CLOCK_TIME_IS_VALID ((t))
125#define GINGA_STIME_NONE GST_CLOCK_STIME_NONE
126#define GINGA_STIME_IS_VALID(t) GST_CLOCK_STIME_IS_VALID ((t))
127#define GINGA_SECOND GST_SECOND
128#define GINGA_MSECOND GST_MSECOND
129#define GINGA_USECOND GST_USECOND
130#define GINGA_NSECOND GST_NSECOND
131#define GINGA_TIME_AS_SECONDS(t) GST_TIME_AS_SECONDS ((t))
132#define GINGA_TIME_AS_MSECONDS(t) GST_TIME_AS_MSECONDS ((t))
133#define GINGA_TIME_AS_USECONDS(t) GST_TIME_AS_USECONDS ((t))
134#define GINGA_TIME_AS_NSECONDS(t) GST_TIME_AS_NSECONDS ((t))
135#define GINGA_TIME_DIFF(s, e) GST_CLOCK_DIFF ((s), (e))
136#define GINGA_TIME_FORMAT GST_TIME_FORMAT
137#define GINGA_TIME_ARGS(t) GST_TIME_ARGS ((t))
138#define GINGA_STIME_FORMAT GST_STIME_FORMAT
139#define GINGA_STIME_ARGS(t) GST_STIME_ARGS ((t))
140
141// Numeric functions.
142bool floateq (double, double, double epsilon = .0000001);
143#define doubleeq floateq
144
145// Parsing and evaluation functions.
146bool try_parse_bool (const string &, bool *);
147bool parse_bool (const string &);
148
149bool try_parse_color (const string &, Color *);
150Color parse_color (const string &);
151
152bool try_parse_list (const string &, char, size_t, size_t, list<string> *);
153list<string> parse_list (const string &, char, size_t, size_t);
154
155bool try_parse_table (const string &, map<string, string> *);
156map<string, string> parse_table (const string &);
157
158bool try_parse_time (const string &, Time *);
159Time parse_time (const string &);
160
161int parse_percent (const string &, int, int, int);
162guint8 parse_pixel (const string &);
163
164// String functions.
165bool _xstrtod (const string &, double *);
166bool _xstrtoll (const string &, gint64 *, guint);
167bool _xstrtoull (const string &, guint64 *, guint);
168double xstrtod (const string &);
169gint xstrtoint (const string &, guint8);
170gint8 xstrtoint8 (const string &, guint8);
171gint64 xstrtoint64 (const string &, guint8);
172guint xstrtouint (const string &, guint8);
173guint8 xstrtouint8 (const string &, guint8);
174guint64 xstrtouint64 (const string &, guint8);
175bool xstrispercent (const string &);
176double xstrtodorpercent (const string &, bool *);
177int xstrcasecmp (const string &, const string &);
178#define xstrcaseeq(s1, s2) (xstrcasecmp ((s1), (s2)) == 0)
179bool xstrhasprefix (const string &, const string &);
180bool xstrhassuffix (const string &, const string &);
181int G_GNUC_PRINTF (2, 3) xstrassign (string &, const char *, ...);
182string G_GNUC_PRINTF (1, 2) xstrbuild (const char *, ...);
183string xstrstrip (string);
184list<string> xstrsplit (const string &, char);
185void xstrdelete (void *);
186
187// Path functions.
188string xpathbasename (string);
189string xpathdirname (string);
190bool xpathisabs (const string &);
191bool xpathisuri (const string &);
192string xpathmakeabs (string);
193string xpathbuild (const string &, const string &);
194string xpathbuildabs (const string &, const string &);
195
196// Uri functions.
197string xpathfromuri (const string &);
198string xurifromsrc (const string &, const string &);
199bool xurigetcontents (const string &, string &);
200
201// User data.
202typedef void (*UserDataCleanFunc) (void *);
204{
205public:
206 UserData ();
207 ~UserData ();
208 bool getData (const string &, void **);
209 bool setData (const string &, void *, UserDataCleanFunc fn = nullptr);
210
211private:
212 map<string, pair<void *, void (*) (void *)> > _udata;
213};
214
215}
216using namespace ginga;
217
218#endif // AUX_GINGA_H
Definition aux-ginga.h:204
The libginga API.