Sayonara Player
EngineUtils.h
1/* EngineUtils.h */
2
3/* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef ENGINE_UTILS_H
22#define ENGINE_UTILS_H
23
24#include "Utils/typedefs.h"
25
26#include <type_traits>
27#include <utility>
28#include <memory>
29#include <iostream>
30#include <gst/gst.h>
31
32template<typename T>
33class QList;
34
35namespace Engine
36{
41 namespace Utils
42 {
44
45 template<typename T>
47 {
48 T* obj=nullptr;
49
50 GObjectAutoFree(T* obj) : obj(obj) {}
52 {
53 if(obj) {
54 g_free(obj);
55 }
56
57 obj = nullptr;
58 }
59 T* data() const { return obj; }
60 };
61
63
69 void configureQueue(GstElement* queue, guint64 max_time_ms=100);
70
75 void configureSink(GstElement* sink);
76
81 void configureLame(GstElement* lame);
82
90 bool connectTee(GstElement* tee, GstElement* queue, const QString& queue_name);
91
98 bool hasElement(GstBin* bin, GstElement* element);
99
106 bool testAndError(void* element, const QString& errorstr);
107
114 bool testAndErrorBool(bool b, const QString& errorstr);
115
122 bool createElement(GstElement** elem, const QString& elem_name);
123
131 bool createElement(GstElement** elem, const QString& elem_name, const QString& name);
132
138 void setPassthrough(GstElement* e, bool b);
139
145 GValue getInt64(gint64 value);
146
152 GValue getUint64(guint64 value);
153
159 GValue getUint(guint value);
160
166 GValue getInt(gint value);
167
172 MilliSeconds getUpdateInterval();
173
174 template<typename T>
175
180 {
182 {
183 std::string("There's a wrong value somewhere") + value;
184 }
185 };
186
187
188 template<typename GlibObject, typename T>
195 void setValue(GlibObject* object, const gchar* key, T value, std::true_type)
196 {
197 (void) object;
198 (void) key;
199 (void) value;
201 }
202
203
204 template<typename GlibObject, typename T>
211 void setValue(GlibObject* object, const gchar* key, T value, std::false_type)
212 {
213 g_object_set(G_OBJECT(object), key, value, nullptr);
214 }
215
216
217 template<typename GlibObject, typename T>
224 void setValue(GlibObject* object, const gchar* key, T value)
225 {
226 constexpr bool b = (std::is_integral<T>::value) && (sizeof(T) > sizeof(bool));
227 setValue(object, key, value, std::integral_constant<bool, b>());
228 }
229
230
231 template<typename GlibObject, typename First>
238 void setValues(GlibObject* object, const gchar* key, First value)
239 {
240 setValue(object, key, value);
241 }
242
243
244 template<typename GlibObject, typename First, typename... Args>
252 void setValues(GlibObject* object, const gchar* key, First value, Args... args)
253 {
254 setValue(object, key, value);
255 setValues(object, std::forward<Args>(args)...);
256 }
257
258
259 template<typename GlibObject>
266 void setInt64Value(GlibObject* object, const gchar* key, gint64 value)
267 {
268 GValue val = getInt64(value);
269 g_object_set_property(G_OBJECT(object), key, &val);
270 }
271
272
273 template<typename GlibObject>
280 void setIntValue(GlibObject* object,const gchar* key, gint value)
281 {
282 GValue val = getInt(value);
283 g_object_set_property(G_OBJECT(object), key, &val);
284 }
285
286
287
288 template<typename GlibObject>
295 void setUint64Value(GlibObject* object, const gchar* key, guint64 value)
296 {
297 GValue val = getUint64(value);
298 g_object_set_property(G_OBJECT(object), key, &val);
299 }
300
301
302 template<typename GlibObject>
309 void setUintValue(GlibObject* object, const gchar* key, guint value)
310 {
311 GValue val = getUint(value);
312 g_object_set_property(G_OBJECT(object), key, &val);
313 }
314
320 MilliSeconds getDurationMs(GstElement* element);
321
327 MilliSeconds getPositionMs(GstElement* element);
328
334 MilliSeconds getTimeToGo(GstElement* element);
335
341 GstState getState(GstElement* element);
342
349 bool setState(GstElement* element, GstState state);
350
356 bool isPluginAvailable(const gchar* str);
357
363
369
377 bool createBin(GstElement** bin, const Elements& elements, const QString& prefix);
378
385 bool createGhostPad(GstBin* bin, GstElement* e);
386
392 bool linkElements(const Elements& elements);
393
394 void unlinkElements(const Elements& elements);
395
401 bool addElements(GstBin* bin, const Elements& elements);
402
403 void removeElements(GstBin* bin, const Elements& elements);
404
409 void unrefElements(const Elements& elements);
410 }
411}
412
413#endif // ENGINE_UTILS_H
Definition: EngineUtils.h:33
MilliSeconds getUpdateInterval()
get_update_interval
void setUint64Value(GlibObject *object, const gchar *key, guint64 value)
set_uint64_value
Definition: EngineUtils.h:295
GstState getState(GstElement *element)
get_state
bool setState(GstElement *element, GstState state)
set_state
MilliSeconds getDurationMs(GstElement *element)
get_durationMs
bool hasElement(GstBin *bin, GstElement *element)
has_element
void setInt64Value(GlibObject *object, const gchar *key, gint64 value)
set_int64_value
Definition: EngineUtils.h:266
bool createBin(GstElement **bin, const Elements &elements, const QString &prefix)
create_bin
GValue getInt(gint value)
get_int
bool isPitchAvailable()
check_pitch_available
void setPassthrough(GstElement *e, bool b)
set_passthrough
bool addElements(GstBin *bin, const Elements &elements)
add_elements
MilliSeconds getTimeToGo(GstElement *element)
get_time_to_go
MilliSeconds getPositionMs(GstElement *element)
get_position_ms
void setValue(GlibObject *object, const gchar *key, T value, std::true_type)
set_value
Definition: EngineUtils.h:195
void setUintValue(GlibObject *object, const gchar *key, guint value)
set_uint_value
Definition: EngineUtils.h:309
void configureSink(GstElement *sink)
config_sink
bool isLameAvailable()
check_lame_available
void unrefElements(const Elements &elements)
unref_elements
GValue getUint64(guint64 value)
get_uint64
bool createGhostPad(GstBin *bin, GstElement *e)
create_ghost_pad
void setValues(GlibObject *object, const gchar *key, First value)
set_values
Definition: EngineUtils.h:238
void configureLame(GstElement *lame)
config_lame
bool isPluginAvailable(const gchar *str)
check_plugin_available
bool createElement(GstElement **elem, const QString &elem_name)
create_element
bool linkElements(const Elements &elements)
link_elements
void configureQueue(GstElement *queue, guint64 max_time_ms=100)
config_queue
GValue getInt64(gint64 value)
get_int64
bool testAndErrorBool(bool b, const QString &errorstr)
test_and_error_bool
void setIntValue(GlibObject *object, const gchar *key, gint value)
set_int_value
Definition: EngineUtils.h:280
GValue getUint(guint value)
get_uint
bool testAndError(void *element, const QString &errorstr)
test_and_error
bool connectTee(GstElement *tee, GstElement *queue, const QString &queue_name)
tee_connect
Class for compiler warnings.
Definition: EngineUtils.h:180
Definition: EngineUtils.h:47