Debian Codegraph @

gstreamer/src/caps.hg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2016 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 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 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gstreamermm/miniobject.h>
21 #include <gstreamermm/structure.h>
22
23 _DEFS(gstreamermm,gst)
24
25
26 namespace Gst
27 {
28 _WRAP_ENUM(CapsIntersectMode, GstCapsIntersectMode, NO_GTYPE)
29
30 _WRAP_ENUM(CapsFlags, GstCapsFlags)
31
32 class CapsFeatures;
33
34 /** Structure describing sets of media formats.
35 * Caps (capabilities) are lightweight refcounted objects describing media types.
36 *
37 * They are composed of an array of Gst::Structure.
38 *
39 * Caps are exposed on Gst::PadTemplate to describe all possible types a
40 * given pad can handle. They are also stored in the Gst::Registry along with
41 * a description of the Gst::Element.
42 *
43 * Caps are exposed on the element pads using the Gst::Pad::query_caps() pad
44 * method. This function describes the possible types that the pad can
45 * handle or produce at runtime.
46 *
47 * @code
48 * Glib::RefPtr<Gst::Caps> caps = Gst::Caps::create_simple("video/x-raw",
49 * "format", Gst::Fourcc('I', '4', '2', '0'),
50 * "framerate", Gst::Fraction(25, 1),
51 * "pixel-aspect-ratio", Gst::Fraction(1, 1),
52 * "width", 320,
53 * "height", 240);
54 * @endcode
55 *
56 * A Gst::Caps is fixed when it has no properties with ranges or lists. Use
57 * Gst::Caps::is_fixed() to test for fixed caps. Fixed caps can be used in a
58 * caps event to notify downstream elements of the current media type.
59 *
60 * Various methods exist to work with the media types such as subtracting
61 * or intersecting.
62 *
63 * Be aware that the current Gst::Caps / Gst::Structure serialization into string
64 * has limited support for nested Gst::Caps / Gst::Structure fields. It can only
65 * support one level of nesting. Using more levels will lead to unexpected
66 * behavior when using serialization features, such as Gst::Caps::to_string() or
67 * gst_value_serialize() and their counterparts.
68 *
69 * Last reviewed on 2016-05-16 (1.8.0)
70 *
71 */
72 class Caps : public MiniObject
73 {
74 _CLASS_OPAQUE_REFCOUNTED(Caps, GstCaps, gst_caps_new_empty, gst_caps_ref, gst_caps_unref)
75 _IGNORE(gst_caps_ref, gst_caps_unref)
76
77 public:
78 #ifndef DOXYGEN_SHOULD_SKIP_THIS
79 static GType get_type() G_GNUC_CONST;
80 #endif
81
82 public:
83 /** Creates a new Gst::Caps that contains one Gst::Structure.
84 *
85 * @param media_type The media type of the structure.
86 * @param ...further_data further data to set in format: name, data (data
87 * value can be any supported C++ type).
88 *
89 * @return The new Gst::Caps.
90 */
91 template<class ...DataTypes>
92 static Glib::RefPtr<Gst::Caps> create_simple(const Glib::ustring& media_type, DataTypes... further_data);
93
94 /** Creates a new Gst::Caps and adds the given Gst::Structure.
95 * Use append_structure() to add additional structures.
96 *
97 * @param first_struct The first structure to add.
98 * @return Returns the new Gst::Caps.
99 */
100 static Glib::RefPtr<Gst::Caps> create(const Structure& first_struct);
101
102 _WRAP_METHOD(static Glib::RefPtr<Gst::Caps> create_from_string(const Glib::ustring& string), gst_caps_from_string)
103
104 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> copy_nth(guint nth) const, gst_caps_copy_nth)
105
106 _WRAP_METHOD(void append(Glib::RefPtr<Gst::Caps>&& caps), gst_caps_append)
107
108 Glib::RefPtr<Gst::Caps> merge(Glib::RefPtr<Gst::Caps>&& caps);
109 _IGNORE(gst_caps_merge)
110
111 /** Appends a structure to caps.
112 *
113 * @param structure The Gst::Structure to append.
114 */
115 void append_structure(const Structure& structure);
116
117 _WRAP_METHOD(void append_structure(Gst::Structure&& structure), gst_caps_append_structure)
118
119 /** Appends a structure to caps.
120 *
121 * @param structure The Gst::Structure to append.
122 * @param features The Gst::CapsFeatures to append.
123 */
124 void append_structure(const Structure& structure, const CapsFeatures& features);
125 _IGNORE(gst_caps_append_structure_full)
126
127 /** Appends a structure to caps if its not already expressed by caps.
128 *
129 * @param structure The Gst::Structure to merge.
130 */
131 Glib::RefPtr<Gst::Caps> merge_structure(const Structure& structure);
132 _IGNORE(gst_caps_merge_structure)
133
134 /** Appends a structure to caps if its not already expressed by caps.
135 *
136 * @param structure The Gst::Structure to merge.
137 * @param features The Gst::CapsFeatures to merge.
138 */
139 Glib::RefPtr<Gst::Caps> merge_structure(const Structure& structure, const CapsFeatures& features);
140 _IGNORE(gst_caps_merge_structure_full)
141
142 #m4 _CONVERSION(`GstStructure*', `const Structure', `Glib::wrap($3, true)')
143 /** Finds the structure in caps that has the index @a idx, and returns it.
144 *
145 * @param idx The index of the structure.
146 * @return The Gst::Structure corresponding to index.
147 */
148 _WRAP_METHOD(const Structure get_structure(guint idx) const, gst_caps_get_structure)
149
150 _WRAP_METHOD(void remove_structure(guint idx), gst_caps_remove_structure)
151 _WRAP_METHOD(guint size() const, gst_caps_get_size)
152
153 // There's no need to take an extra reference because we are stealing the
154 // structure.
155 #m4 _CONVERSION(`GstStructure*', `Structure', `Glib::wrap($3)')
156 _WRAP_METHOD(Structure steal_structure(guint index), gst_caps_steal_structure)
157
158 /** Sets fields in a simple Gst::Caps. A simple Gst::Caps is one that only
159 * has one structure. This method, like the Gst::Structure::set_field()
160 * methods, translates certain GTypes to GStreamer specific GTypes for
161 * functional compatibility.
162 *
163 * @param name Field to set.
164 * @param value The value which the field should be set to.
165 */
166 void set_simple(const Glib::ustring& name, const Glib::ValueBase& value);
167 _IGNORE(gst_caps_set_simple, gst_caps_set_simple_valist)
168
169 /** Sets fields in a simple Gst::Caps. A simple Gst::Caps is one that only
170 * has one structure. This method, like the Gst::Structure::set_field()
171 * methods, translates certain GTypes to GStreamer specific GTypes for
172 * functional compatibility.
173 *
174 * @param name Field to set.
175 * @param data A value which the field should be set to (this can be any
176 * supported C++ type).
177 * @param ...further_data further data to set in format: name, data.
178 */
179 template<class DataType, class ...DataTypes>
180 void set_simple(const Glib::ustring & name, const DataType& data, DataTypes ...further_data);
181
182 /** Sets fields in a simple Gst::Caps. A simple Gst::Caps is one that only
183 * has one structure.
184 *
185 * @param name Field to set.
186 * @param data A C string (const char*) which the field should be set to.
187 */
188 void set_simple(const Glib::ustring& name, const char* data);
189
190 _WRAP_METHOD(void set_value(const Glib::ustring& field, const Glib::ValueBase& value), gst_caps_set_value)
191
192 /** Sets the given @a field on all structures to the given value. This is a
193 * convenience function for calling Gst::Structure::set_value() on all
194 * structures.
195 *
196 * @param name Field to set.
197 * @param data A value which the field should be set to (this can be any
198 * supported C++ type).
199 */
200 template <class DataType>
201 void set_value(const Glib::ustring& name, const DataType& data);
202
203 _WRAP_METHOD(bool is_any() const, gst_caps_is_any)
204 _WRAP_METHOD(bool empty() const, gst_caps_is_empty)
205 _WRAP_METHOD(bool is_fixed() const, gst_caps_is_fixed)
206 _WRAP_METHOD(bool equals(const Glib::RefPtr<const Gst::Caps>& other_caps) const, gst_caps_is_equal)
207 _WRAP_METHOD(bool equals_fixed(const Glib::RefPtr<const Gst::Caps>& other_caps) const, gst_caps_is_equal_fixed)
208 _WRAP_METHOD(bool is_always_compatible(const Glib::RefPtr<const Gst::Caps>& other_caps) const, gst_caps_is_always_compatible)
209 _WRAP_METHOD(bool is_subset(const Glib::RefPtr<const Gst::Caps>& superset_caps) const, gst_caps_is_subset)
210 _WRAP_METHOD(bool can_intersect(const Glib::RefPtr<const Gst::Caps>& caps2) const, gst_caps_can_intersect)
211 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> fixate() const, gst_caps_fixate)
212 _WRAP_METHOD(bool is_strictly_equal(const Glib::RefPtr<const Gst::Caps>& caps2) const, gst_caps_is_strictly_equal)
213 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> copy() const, gst_caps_copy)
214 _WRAP_METHOD(bool is_subset_structure(const Gst::Structure& structure) const, gst_caps_is_subset_structure)
215 _WRAP_METHOD(bool is_subset_structure(const Gst::Structure& structure, const Gst::CapsFeatures& features) const, gst_caps_is_subset_structure_full)
216
217
218 _WRAP_METHOD(static Glib::RefPtr<Gst::Caps> create_any(), gst_caps_new_any)
219
220 //This is const (returns a non const) because it always creates a new instance:
221 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_intersect(const Glib::RefPtr<const Gst::Caps>& other_caps) const, gst_caps_intersect)
222
223 //This is const (returns a non const) because it always creates a new instance:
224 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_intersect(const Glib::RefPtr<const Gst::Caps>& other_caps, CapsIntersectMode) const, gst_caps_intersect_full)
225
226 //This is const (returns a non const) because it always creates a new instance:
227 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_normal() const, gst_caps_normalize)
228
229 //This is const (returns a non const) because it always creates a new instance:
230 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> simplify(), gst_caps_simplify)
231
232 _WRAP_METHOD(Glib::ustring to_string() const, gst_caps_to_string)
233
234 //This is const (returns a non const) because it always creates a new instance:
235 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_difference(const Glib::RefPtr<const Gst::Caps>& subtrahend_caps) const, gst_caps_subtract)
236
237 /**
238 * Returns a writable copy of @a caps.
239 *
240 * If there is only one reference count on Gst::Caps object , the caller must be
241 * the owner, and so this function will return the caps object unchanged. If on
242 * the other hand there is more than one reference on the object, a new caps object
243 * will be returned.
244 * @return A buffer (possibly the same pointer) that is writable.
245 */
246 Glib::RefPtr<Gst::Caps> create_writable();
247
248 /** Discard all but the first structure from @a caps. Useful when
249 * fixating.
250 *
251 * @return Truncated caps.
252 */
253 Glib::RefPtr<Gst::Caps> truncate();
254 _IGNORE(gst_caps_truncate)
255
256 /**
257 * Finds the features in caps that has the index index , and returns it.
258 *
259 * @param index the index of the structure.
260 * @return The new Gst::CapsFeatures corresponding to index.
261 */
262 CapsFeatures get_features(guint index) const;
263 _IGNORE(gst_caps_get_features)
264
265 /**
266 * Sets the Gst::CapsFeatures for the structure at index.
267 *
268 * @param index The index of the structure.
269 * @param features The Gst::CapsFeatures to set.
270 */
271 void set_features(guint index, const CapsFeatures& features);
272 _IGNORE(gst_caps_set_features)
273
274 private:
275 // This method is used for varadic template recursion
276 void set_simple() {}
277 };
278
279 /******************************* Gst::Caps *******************************/
280
281 #ifndef DOXYGEN_SHOULD_SKIP_THIS
282
283 template<class DataType, class ...DataTypes>
284 void Caps::set_simple(const Glib::ustring & name, const DataType& data, DataTypes ...further_data)
285 {
286 this->set_value(name, data);
287 this->set_simple(further_data...);
288 }
289
290 template<class ...DataTypes>
291 Glib::RefPtr<Gst::Caps> Caps::create_simple(const Glib::ustring& media_type, DataTypes... data)
292 {
293 /*
294 This method is implemented because gst_caps_new_simple is a variable argument
295 function and cannot be wrapped. In addition, because gst_caps_new_simple
296 creates a GstStructure for the GstCaps and will not be called, we must create
297 our own GstStructure here and append it to the GstCaps.
298 */
299 Glib::RefPtr<Gst::Caps> result(reinterpret_cast<Gst::Caps*>(gst_caps_new_empty()));
300 Gst::Structure gst_struct(media_type, data...);
301 result->append_structure(gst_struct);
302 return result;
303 }
304
305 template <class DataType>
306 void Caps::set_value(const Glib::ustring& name, const DataType& data)
307 {
308 typedef Glib::Value<DataType> ValueType;
309
310 ValueType value;
311 value.init(ValueType::value_type());
312 value.set(data);
313 this->set_value(name, reinterpret_cast<Glib::ValueBase&>(value));
314 }
315
316 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
317
318 } //namespace Gst
319
320 #ifndef DOXYGEN_SHOULD_SKIP_THIS
321 namespace Glib
322 {
323
324 template <>
325 class Value< Glib::RefPtr<Gst::Caps> > : public ValueBase_Boxed
326 {
327 public:
328 static GType value_type() { return Gst::Caps::get_type(); }
329 void set(const Glib::RefPtr<Gst::Caps>& caps) { set_boxed(Glib::unwrap(caps)); }
330 Glib::RefPtr<Gst::Caps> get();
331 };
332
333 }
334 #endif /* DOXYGEN_SHOULD_SKIP_THIS */