QtGStreamer 1.2.0
Loading...
Searching...
No Matches
structure.cpp
1/*
2 Copyright (C) 2009-2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 Copyright (C) 2010 Collabora Multimedia.
4 @author Mauricio Piacentini <mauricio.piacentini@collabora.co.uk>
5 Copyright (C) 2011 Collabora Ltd.
6 @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
7
8 This library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21#include "structure.h"
22#include "miniobject.h"
23#include "caps.h"
24#include "../QGlib/string_p.h"
25#include <gst/gst.h>
26#include <QtCore/QDebug>
27
28namespace QGst {
29
30#ifndef DOXYGEN_RUN
31
32struct QTGSTREAMER_NO_EXPORT Structure::Data : public QSharedData
33{
34 Data() : QSharedData(), structure(NULL) {}
35 Data(const Data & other);
36 virtual ~Data();
37
38 GstStructure *structure;
39};
40
41Structure::Data::Data(const Structure::Data & other)
42 : QSharedData(other), structure(NULL)
43{
44 if (other.structure) {
45 structure = gst_structure_copy(other.structure);
46 }
47}
48
49Structure::Data::~Data()
50{
51 if (structure) {
52 gst_structure_free(structure);
53 }
54}
55
56#endif //DOXYGEN_RUN
57
58Structure::Structure()
59 : d(new Data)
60{
61}
62
63Structure::Structure(Data* data)
64 : d(data)
65{
66}
67
68Structure::Structure(const char *name)
69 : d(new Data)
70{
71 d->structure = gst_structure_new_empty(name);
72}
73
74Structure::Structure(const GstStructure* structure)
75 : d(new Data)
76{
77 d->structure = gst_structure_copy(structure);
78}
79
80Structure::Structure(const Structure & other)
81 : d(other.d)
82{
83}
84
85Structure::~Structure()
86{
87}
88
89Structure & Structure::operator=(const Structure & other)
90{
91 d = other.d;
92 return *this;
93}
94
95bool Structure::isValid() const
96{
97 return d->structure != NULL;
98}
99
100QString Structure::name() const
101{
102 if (d->structure) {
103 return QString::fromUtf8(gst_structure_get_name(d->structure));
104 } else {
105 return QString();
106 }
107}
108
109void Structure::setName(const char *name)
110{
111 if (!d->structure) {
112 //lazy construction
113 d->structure = gst_structure_new_empty(name);
114 } else {
115 gst_structure_set_name(d->structure, name);
116 }
117}
118
119QGlib::Value Structure::value(const char *fieldName) const
120{
121 if (d->structure) {
122 return QGlib::Value(gst_structure_get_value(d->structure, fieldName));
123 } else {
124 return QGlib::Value();
125 }
126}
127
128void Structure::setValue(const char *fieldName, const QGlib::Value & value)
129{
130 Q_ASSERT(isValid());
131 gst_structure_set_value(d->structure, fieldName, value);
132}
133
134unsigned int Structure::numberOfFields() const
135{
136 return d->structure ? gst_structure_n_fields(d->structure) : 0;
137}
138
139QString Structure::fieldName(unsigned int fieldNumber) const
140{
141 if (fieldNumber < numberOfFields()) {
142 return QString::fromUtf8(gst_structure_nth_field_name(d->structure, fieldNumber));
143 } else {
144 return QString();
145 }
146}
147
148QGlib::Type Structure::fieldType(const char *fieldName) const
149{
150 if (d->structure) {
151 return gst_structure_get_field_type(d->structure, fieldName);
152 } else {
153 return QGlib::Type::Invalid;
154 }
155}
156
157bool Structure::hasField(const char *fieldName) const
158{
159 return d->structure ? gst_structure_has_field(d->structure, fieldName) : false;
160}
161
162bool Structure::hasFieldTyped(const char *fieldName, QGlib::Type type) const
163{
164 return d->structure ? gst_structure_has_field_typed(d->structure, fieldName, type) : false;
165}
166
167void Structure::removeField(const char *fieldName)
168{
169 if (d->structure) {
170 gst_structure_remove_field(d->structure, fieldName);
171 }
172}
173
174void Structure::removeAllFields()
175{
176 if (d->structure) {
177 gst_structure_remove_all_fields(d->structure);
178 }
179}
180
181QString Structure::toString() const
182{
183 if (d->structure) {
184 return QGlib::Private::stringFromGCharPtr(gst_structure_to_string(d->structure));
185 } else {
186 return QString();
187 }
188}
189
190Structure Structure::fromString(const char *str)
191{
192 //we don't use the Structure(const GstStructure*) constructor to avoid copying
193 Structure s;
194 s.d->structure = gst_structure_from_string(str, NULL);
195 return s;
196}
197
198Structure::operator GstStructure*()
199{
200 return d->structure;
201}
202
203Structure::operator const GstStructure*() const
204{
205 return d->structure;
206}
207
208//END Structure
209
210//BEGIN SharedStructure
211
212#ifndef DOXYGEN_RUN
213
214struct QTGSTREAMER_NO_EXPORT SharedStructure::Data : public Structure::Data
215{
216 Data() : Structure::Data() {}
217 Data(const Data & other) : Structure::Data(other) {}
218
219 MiniObjectPtr miniobject;
220 CapsPtr caps;
221};
222
223#endif
224
225Structure SharedStructure::copy() const
226{
227 return Structure(d->structure);
228}
229
230SharedStructure::SharedStructure(SharedStructure::Data* data)
231 : Structure(data)
232{
233}
234
235StructurePtr SharedStructure::fromMiniObject(GstStructure *structure, const MiniObjectPtr & parent)
236{
237 SharedStructure::Data *d = new SharedStructure::Data;
238 d->structure = structure;
239 d->miniobject = parent;
240 return StructurePtr(new SharedStructure(d));
241}
242
243StructurePtr SharedStructure::fromCaps(GstStructure* structure, const CapsPtr & parent)
244{
245 SharedStructure::Data *d = new SharedStructure::Data;
246 d->structure = structure;
247 d->caps = parent;
248 return StructurePtr(new SharedStructure(d));
249}
250
251SharedStructure::~SharedStructure()
252{
253 d->structure = NULL;
254}
255
256//END SharedStructure
257
258QDebug operator<<(QDebug debug, const Structure & structure)
259{
260 debug.nospace() << "QGst::Structure";
261 if (structure.isValid()) {
262 debug.nospace() << "(" << structure.toString() << ")";
263 } else {
264 debug.nospace() << "(<invalid>)";
265 }
266 return debug.space();
267}
268
269} //namespace QGst
Wrapper class for GType.
Definition type.h:64
Wrapper class for GValue.
Definition value.h:77
Wrapper for GstStructure.
Definition structure.h:50
Wrappers for GStreamer classes.