QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
caps.cpp
1 /*
2  Copyright (C) 2009-2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published
6  by the Free Software Foundation; either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "caps.h"
18 #include "structure.h"
19 #include "../QGlib/string_p.h"
20 #include "objectstore_p.h"
21 #include <QtCore/QDebug>
22 #include <gst/gstcaps.h>
23 #include <gst/gstvalue.h>
24 
25 namespace QGst {
26 
27 //static
28 CapsPtr Caps::createSimple(const char *mediaType)
29 {
30  return CapsPtr::wrap(gst_caps_new_simple(mediaType, NULL), false);
31 }
32 
33 //static
34 CapsPtr Caps::createAny()
35 {
36  return CapsPtr::wrap(gst_caps_new_any(), false);
37 }
38 
39 //static
40 CapsPtr Caps::createEmpty()
41 {
42  return CapsPtr::wrap(gst_caps_new_empty(), false);
43 }
44 
45 //static
46 CapsPtr Caps::fromString(const char *string)
47 {
48  return CapsPtr::wrap(gst_caps_from_string(string), false);
49 }
50 
51 QString Caps::toString() const
52 {
53  return QGlib::Private::stringFromGCharPtr(gst_caps_to_string(object<GstCaps>()));
54 }
55 
56 void Caps::append(const CapsPtr & caps2)
57 {
58  gst_caps_append(object<GstCaps>(), gst_caps_copy(caps2));
59 }
60 
61 void Caps::merge(const CapsPtr & caps2)
62 {
63  gst_caps_merge(object<GstCaps>(), gst_caps_copy(caps2));
64 }
65 
66 void Caps::setValue(const char *field, const QGlib::Value & value)
67 {
68  gst_caps_set_value(object<GstCaps>(), field, value);
69 }
70 
71 bool Caps::simplify()
72 {
73  return gst_caps_do_simplify(object<GstCaps>());
74 }
75 
76 void Caps::truncate()
77 {
78  gst_caps_truncate(object<GstCaps>());
79 }
80 
81 StructurePtr Caps::internalStructure(uint index)
82 {
83  GstStructure *structure = gst_caps_get_structure(object<GstCaps>(), index);
84  return SharedStructure::fromCaps(structure, CapsPtr(this));
85 }
86 
87 void Caps::appendStructure(const Structure & structure)
88 {
89  gst_caps_append_structure(object<GstCaps>(), gst_structure_copy(structure));
90 }
91 
92 void Caps::mergeStructure(const Structure & structure)
93 {
94  gst_caps_merge_structure(object<GstCaps>(), gst_structure_copy(structure));
95 }
96 
97 void Caps::removeStructure(uint index)
98 {
99  gst_caps_remove_structure(object<GstCaps>(), index);
100 }
101 
102 uint Caps::size() const
103 {
104  return gst_caps_get_size(object<GstCaps>());
105 }
106 
107 bool Caps::isSimple() const
108 {
109  return GST_CAPS_IS_SIMPLE(object<GstCaps>());
110 }
111 
112 bool Caps::isAny() const
113 {
114  return gst_caps_is_any(object<GstCaps>());
115 }
116 
117 bool Caps::isEmpty() const
118 {
119  return gst_caps_is_empty(object<GstCaps>());
120 }
121 
122 bool Caps::isFixed() const
123 {
124  return gst_caps_is_fixed(object<GstCaps>());
125 }
126 
127 bool Caps::isWritable() const
128 {
129  GstCaps *caps = object<GstCaps>(); //workaround for bug #653266
130  return (GST_CAPS_REFCOUNT_VALUE(caps) == 1);
131 }
132 
133 bool Caps::equals(const CapsPtr & caps2) const
134 {
135  return gst_caps_is_equal(object<GstCaps>(), caps2);
136 }
137 
138 bool Caps::isAlwaysCompatibleWith(const CapsPtr & caps2) const
139 {
140  return gst_caps_is_always_compatible(object<GstCaps>(), caps2);
141 }
142 
143 bool Caps::isSubsetOf(const CapsPtr & superset) const
144 {
145  return gst_caps_is_subset(object<GstCaps>(), superset);
146 }
147 
148 bool Caps::canIntersect(const CapsPtr & caps2) const
149 {
150  return gst_caps_can_intersect(object<GstCaps>(), caps2);
151 }
152 
153 CapsPtr Caps::getIntersection(const CapsPtr & caps2) const
154 {
155  return CapsPtr::wrap(gst_caps_intersect(object<GstCaps>(), caps2), false);
156 }
157 
158 CapsPtr Caps::getUnion(const CapsPtr & caps2) const
159 {
160  return CapsPtr::wrap(gst_caps_union(object<GstCaps>(), caps2), false);
161 }
162 
163 CapsPtr Caps::getNormal() const
164 {
165  return CapsPtr::wrap(gst_caps_normalize(object<GstCaps>()), false);
166 }
167 
168 CapsPtr Caps::subtract(const CapsPtr & subtrahend) const
169 {
170  return CapsPtr::wrap(gst_caps_subtract(object<GstCaps>(), subtrahend), false);
171 }
172 
173 CapsPtr Caps::copy() const
174 {
175  return CapsPtr::wrap(gst_caps_copy(object<GstCaps>()), false);
176 }
177 
178 CapsPtr Caps::copyNth(uint index) const
179 {
180  return CapsPtr::wrap(gst_caps_copy_nth(object<GstCaps>(), index), false);
181 }
182 
183 void Caps::ref(bool increaseRef)
184 {
185  if (Private::ObjectStore::put(this)) {
186  if (increaseRef) {
187  gst_caps_ref(GST_CAPS(m_object));
188  }
189  }
190 }
191 
192 void Caps::unref()
193 {
194  if (Private::ObjectStore::take(this)) {
195  gst_caps_unref(GST_CAPS(m_object));
196  delete this;
197  }
198 }
199 
200 CapsPtr Caps::makeWritable() const
201 {
202  /*
203  * Calling gst_*_make_writable() below is tempting but wrong.
204  * Since MiniObjects and Caps do not share the same C++ instance in various wrappings, calling
205  * gst_*_make_writable() on an already writable object and wrapping the result is wrong,
206  * since it would just return the same pointer and we would wrap it in a new C++ instance.
207  */
208  if (!isWritable()) {
209  return copy();
210  } else {
211  return CapsPtr(const_cast<Caps*>(this));
212  }
213 }
214 
215 QDebug operator<<(QDebug debug, const CapsPtr & caps)
216 {
217  debug.nospace() << "QGst::Caps(" << caps->toString() << ")";
218  return debug.space();
219 }
220 
221 
222 namespace Private {
223 
224 QGlib::RefCountedObject *wrapCaps(void *caps)
225 {
226  return QGlib::constructWrapper(GST_CAPS(caps)->type, caps);
227 }
228 
229 } //namespace Private
230 } //namespace QGst