Sayonara Player
EngineUtils.h
1 /* EngineUtils.h */
2 
3 /* Copyright (C) 2011-2019 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 ENGINEUTILS_H
22 #define ENGINEUTILS_H
23 
24 #include <gst/gst.h>
25 #include "Utils/typedefs.h"
26 #include <type_traits>
27 #include <utility>
28 #include <memory>
29 #include <iostream>
30 
31 namespace Engine
32 {
33  namespace Utils
34  {
35  void config_queue(GstElement* queue, gulong max_time_ms=100);
36  void config_sink(GstElement* sink);
37  void config_lame(GstElement* lame);
38 
39  bool tee_connect(GstElement* tee, GstElement* queue, const QString& queue_name);
40  bool has_element(GstBin* bin, GstElement* element);
41  bool test_and_error(void* element, const QString& errorstr);
42  bool test_and_error_bool(bool b, const QString& errorstr);
43  bool create_element(GstElement** elem, const QString& elem_name);
44  bool create_element(GstElement** elem, const QString& elem_name, const QString& name);
45 
46  void set_passthrough(GstElement* e, bool b);
47 
48  GValue get_int64(gint64 value);
49  GValue get_uint64(guint64 value);
50  GValue get_uint(guint value);
51  GValue get_int(gint value);
52 
53  template<typename T>
55  {
57  {
58  std::string("There's a wrong value somewhere") + value;
59  }
60  };
61 
62  template<typename GlibObject, typename T>
63  void set_value(GlibObject* object, const gchar* key, T value, std::true_type)
64  {
65  (void) object;
66  (void) key;
67  (void) value;
69  }
70 
71  template<typename GlibObject, typename T>
72  void set_value(GlibObject* object, const gchar* key, T value, std::false_type)
73  {
74  g_object_set(G_OBJECT(object), key, value, nullptr);
75  }
76 
77  template<typename GlibObject, typename T>
78  void set_value(GlibObject* object, const gchar* key, T value)
79  {
80  constexpr bool b = (std::is_integral<T>::value) && (sizeof(T) > sizeof(bool));
81  set_value(object, key, value, std::integral_constant<bool, b>());
82  }
83 
84  template<typename GlibObject, typename First>
85  void set_values(GlibObject* object, const gchar* key, First value)
86  {
87  set_value(object, key, value);
88  }
89 
90  template<typename GlibObject, typename First, typename... Args>
91  void set_values(GlibObject* object, const gchar* key, First value, Args... args)
92  {
93  set_value(object, key, value);
94  set_values(object, std::forward<Args>(args)...);
95  }
96 
97  template<typename GlibObject>
98  void set_int64_value(GlibObject* object, const gchar* key, gint64 value)
99  {
100  GValue val = get_int64(value);
101  g_object_set_property(G_OBJECT(object), key, &val);
102  }
103 
104  template<typename GlibObject>
105  void set_int_value(GlibObject* object,const gchar* key, gint value)
106  {
107  GValue val = get_int(value);
108  g_object_set_property(G_OBJECT(object), key, &val);
109  }
110 
111  template<typename GlibObject>
112  void set_uint64_value(GlibObject* object, const gchar* key, guint64 value)
113  {
114  GValue val = get_uint64(value);
115  g_object_set_property(G_OBJECT(object), key, &val);
116  }
117  template<typename GlibObject>
118  void set_uint_value(GlibObject* object, const gchar* key, guint value)
119  {
120  GValue val = get_uint(value);
121  g_object_set_property(G_OBJECT(object), key, &val);
122  }
123 
124  MilliSeconds get_duration_ms(GstElement* element);
125  MilliSeconds get_position_ms(GstElement* element);
126  MilliSeconds get_time_to_go(GstElement* element);
127 
128  GstState get_state(GstElement* element);
129  bool set_state(GstElement* element, GstState state);
130 
131  bool check_plugin_available(const gchar* str);
132  bool check_lame_available();
133  bool check_pitch_available();
134 
135  bool create_bin(GstElement** bin, const QList<GstElement*>& elements, const QString& prefix);
136 
137  bool create_ghost_pad(GstBin* bin, GstElement* e);
138  bool link_elements(const QList<GstElement*>& elements);
139  void add_elements(GstBin* bin, const QList<GstElement*>& elements);
140  void unref_elements(const QList<GstElement*>& elements);
141  }
142 }
143 
144 #endif // ENGINEUTILS_H
Definition: AbstractEngine.h:32
Definition: org_mpris_media_player2_adaptor.h:20