Debian Codegraph @

gstreamer/src/caps.ccg

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/capsfeatures.h>
21
22 namespace Gst
23 {
24
25 GType Caps::get_type()
26 {
27 return gst_caps_get_type();
28 }
29
30 Glib::RefPtr<Caps> Caps::create_writable()
31 {
32 return Glib::RefPtr<Caps>::cast_static(MiniObject::create_writable());
33 }
34
35 Glib::RefPtr<Gst::Caps> Caps::create(const Structure& structure)
36 {
37 //We take a copy because gst_caps_append_structure() wants to take ownership:
38 GstStructure* copy = gst_structure_copy(structure.gobj());
39 return Glib::wrap(gst_caps_new_full(copy, nullptr));
40 }
41
42 void Caps::append_structure(const Structure& structure)
43 {
44 //We take a copy because gst_caps_append_structure() wants to take ownership:
45 GstStructure* copy = gst_structure_copy(structure.gobj());
46 gst_caps_append_structure(gobj(), copy);
47 }
48
49 void Caps::append_structure(const Structure& structure, const CapsFeatures& features)
50 {
51 //We take a copy because gst_caps_append_structure_full() wants to take ownership:
52 GstStructure* copy_structure = gst_structure_copy(structure.gobj());
53 GstCapsFeatures* copy_features = gst_caps_features_copy(features.gobj());
54 gst_caps_append_structure_full(gobj(), copy_structure, copy_features);
55 }
56
57
58 Glib::RefPtr<Caps> Caps::merge_structure(const Structure& structure)
59 {
60 //We take a copy because gst_caps_merge_structure() wants to take ownership:
61 GstStructure* copy = gst_structure_copy(structure.gobj());
62 return Glib::wrap(gst_caps_merge_structure(gobj(), copy), true);
63 }
64
65 Glib::RefPtr<Caps> Caps::merge_structure(const Structure& structure, const CapsFeatures& features)
66 {
67 //We take a copy because gst_caps_merge_structure_full() wants to take ownership:
68 GstStructure* copy_structure = gst_structure_copy(structure.gobj());
69 GstCapsFeatures* copy_features = gst_caps_features_copy(features.gobj());
70 return Glib::wrap(gst_caps_merge_structure_full(gobj(), copy_structure, copy_features), true);
71 }
72
73 //TODO: Want to return RefPtr to Caps but using RefPtr in expressions such
74 // as 'caps->set_simple(name1, value1)->set_simple(name2, value2)' a
75 // causes gstreamer Structure immutability warnings because the Caps is
76 // referenced more than once in the expression (see bug #510301).
77 /*
78 This method is implemented in place of gst_caps_set_simple which is a
79 variable argument function and cannot be wrapped. We don't call
80 gst_caps_set_simple() directly because we are using a Glib::ValueBase as the
81 value to be set instead of listing out each field in the value as would be
82 done with gst_caps_set_simple()
83 */
84 //Glib::RefPtr<Gst::Caps>
85 void
86 Caps::set_simple(const Glib::ustring& name, const Glib::ValueBase& value)
87 {
88 g_return_if_fail (g_atomic_int_get(&(this->gobj())->mini_object.refcount) == 1); // IS_WRITABLE(caps) fails
89
90 //The result of gst_caps_get_structure() should not be modified, according to
91 //its documentation, but we are reimplementing gst_caps_set_simple() which
92 //does that:
93 GstStructure* structure = gst_caps_get_structure(gobj(), 0);
94 if(structure)
95 gst_structure_set_value(structure, name.c_str(), value.gobj());
96
97 //return Glib::wrap(gobj(), true);
98 }
99
100 void
101 Caps::set_simple(const Glib::ustring& name, const char* data)
102 {
103 set_simple(name, std::string(data));
104 }
105
106 CapsFeatures Caps::get_features(guint index) const
107 {
108 GstCapsFeatures* features = gst_caps_get_features(gobj(), index);
109 return CapsFeatures(features, true);
110 }
111
112 void Caps::set_features(guint index, const CapsFeatures& features)
113 {
114 GstCapsFeatures* copy = gst_caps_features_copy(features.gobj());
115 gst_caps_set_features(gobj(), index, copy);
116 }
117
118 Glib::RefPtr<Gst::Caps> Caps::truncate()
119 {
120 reference();
121 return Glib::wrap(gst_caps_truncate(gobj()));
122 }
123
124 Glib::RefPtr<Gst::Caps> Caps::merge(Glib::RefPtr<Gst::Caps>&& caps)
125 {
126 if (is_writable())
127 {
128 return Glib::wrap(gst_caps_merge(gobj(), caps.release()->gobj()), true);
129 }
130 else
131 {
132 reference();
133 return Glib::wrap(gst_caps_merge(gobj(), caps.release()->gobj()), false);
134 }
135 }
136
137 } //namespace Gst
138
139 namespace Glib
140 {
141 Glib::RefPtr<Gst::Caps> Value< Glib::RefPtr<Gst::Caps> >::get()
142 {
143 return Glib::wrap(reinterpret_cast<GstCaps*>(get_boxed()), true);
144 }
145 }