1 /*
2  * GStreamer
3  * Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __GST_GL_QUERY_H__
22 #define __GST_GL_QUERY_H__
23 
24 #include <gst/gl/gstgl_fwd.h>
25 #include <gst/gl/gstgldebug.h>
26 
27 G_BEGIN_DECLS
28 
29 /**
30  * GstGLQueryType:
31  * @GST_GL_QUERY_NONE: no query
32  * @GST_GL_QUERY_TIME_ELAPSED: query the time elapsed
33  * @GST_GL_QUERY_TIMESTAMP: query the current time
34  */
35 typedef enum
36 {
37   GST_GL_QUERY_NONE,
38   GST_GL_QUERY_TIME_ELAPSED,
39   GST_GL_QUERY_TIMESTAMP,
40 } GstGLQueryType;
41 
42 /**
43  * GstGLQuery:
44  *
45  * Opaque #GstGLQuery struct
46  */
47 struct _GstGLQuery
48 {
49   /* <private> */
50   GstGLContext *    context;
51   guint             query_type;
52   guint             query_id;
53   gboolean          supported;
54 
55   gboolean          start_called;
56   GstGLAsyncDebug   debug;
57 
58   /* <private> */
59   gpointer          _padding[GST_PADDING];
60 };
61 
62 GST_GL_API
63 void                gst_gl_query_init               (GstGLQuery * query,
64                                                      GstGLContext * context,
65                                                      GstGLQueryType query_type);
66 GST_GL_API
67 void                gst_gl_query_unset              (GstGLQuery * query);
68 GST_GL_API
69 GstGLQuery *        gst_gl_query_new                (GstGLContext * context,
70                                                      GstGLQueryType query_type);
71 GST_GL_API
72 void                gst_gl_query_free               (GstGLQuery * query);
73 
74 GST_GL_API
75 void                gst_gl_query_start              (GstGLQuery * query);
76 GST_GL_API
77 void                gst_gl_query_end                (GstGLQuery * query);
78 GST_GL_API
79 void                gst_gl_query_counter            (GstGLQuery * query);
80 GST_GL_API
81 guint64             gst_gl_query_result             (GstGLQuery * query);
82 
83 #define gst_gl_query_start_log_valist(query,cat,level,object,format,varargs) \
84   G_STMT_START {    \
85     GST_GL_ASYNC_CAT_LEVEL_LOG_valist (&(query)->debug, cat, level, object, format, varargs); \
86     gst_gl_async_debug_freeze (&(query)->debug); \
87     gst_gl_query_start (query); \
88     gst_gl_async_debug_thaw (&(query)->debug); \
89   } G_STMT_END
90 
91 #define gst_gl_query_counter_log_valist(query,cat,level,object,format,varargs) \
92   G_STMT_START {    \
93     GST_GL_ASYNC_CAT_LEVEL_LOG_valist (&(query)->debug, cat, level, object, format, varargs); \
94     gst_gl_async_debug_freeze (&(query)->debug); \
95     gst_gl_query_counter (query); \
96     gst_gl_async_debug_thaw (&(query)->debug); \
97   } G_STMT_END
98 
99 #ifdef G_HAVE_ISO_VARARGS
100 
101 #define gst_gl_query_start_log(query,cat,level,object,format,...) \
102   G_STMT_START {    \
103     GST_GL_ASYNC_CAT_LEVEL_LOG (&(query)->debug, cat, level, object, format, __VA_ARGS__); \
104     gst_gl_async_debug_freeze (&(query)->debug); \
105     gst_gl_query_start (query); \
106     gst_gl_async_debug_thaw (&(query)->debug); \
107   } G_STMT_END
108 #define gst_gl_query_counter_log(query,cat,level,object,format,...) \
109   G_STMT_START {    \
110     GST_GL_ASYNC_CAT_LEVEL_LOG (&(query)->debug, cat, level, object, format, __VA_ARGS__); \
111     gst_gl_async_debug_freeze (&(query)->debug); \
112     gst_gl_query_counter (query); \
113     gst_gl_async_debug_thaw (&(query)->debug); \
114   } G_STMT_END
115 
116 #else /* G_HAVE_ISO_VARARGS */
117 #if G_HAVE_GNUC_VARARGS
118 
119 #define gst_gl_query_start_log(query,cat,level,object,format,args...) \
120   G_STMT_START {    \
121     GST_GL_ASYNC_CAT_LEVEL_LOG (&(query)->debug, cat, level, object, format, ##args); \
122     gst_gl_async_debug_freeze (&(query)->debug); \
123     gst_gl_query_start (query); \
124     gst_gl_async_debug_thaw (&(query)->debug); \
125   } G_STMT_END
126 #define gst_gl_query_counter_log(query,cat,level,object,format,args...) \
127   G_STMT_START {    \
128     GST_GL_ASYNC_CAT_LEVEL_LOG (&(query)->debug, cat, level, object, format, ##args); \
129     gst_gl_async_debug_freeze (&(query)->debug); \
130     gst_gl_query_counter (query); \
131     gst_gl_async_debug_thaw (&(query)->debug); \
132   } G_STMT_END
133 
134 #else /* G_HAVE_GNUC_VARARGS */
135 
136 static inline void
gst_gl_query_start_log(GstGLQuery * query,GstDebugCategory * cat,GstDebugLevel level,GObject * object,const gchar * format,...)137 gst_gl_query_start_log(GstGLQuery * query, GstDebugCategory * cat,
138     GstDebugLevel level, GObject * object, const gchar * format, ...)
139 {
140   va_list varargs;
141 
142   va_start (varargs, format);
143   gst_gl_query_start_log_valist (query, cat, level, object, format, varargs);
144   va_end (varargs);
145 }
146 
147 static inline void
gst_gl_query_counter_log(GstGLQuery * query,GstDebugCategory * cat,GstDebugLevel level,GObject * object,const gchar * format,...)148 gst_gl_query_counter_log(GstGLQuery * query, GstDebugCategory * cat,
149     GstDebugLevel level, GObject * object, const gchar * format, ...)
150 {
151   va_list varargs;
152 
153   va_start (varargs, format);
154   gst_gl_query_counter_log_valist (query, cat, level, object, format, varargs);
155   va_end (varargs);
156 }
157 
158 #endif /* G_HAVE_GNUC_VARARGS */
159 #endif /* G_HAVE_ISO_VARARGS */
160 
161 G_END_DECLS
162 
163 #endif /* __GST_GL_QUERY_H__ */
164