21 #include "structure.h"
22 #include "miniobject.h"
24 #include "../QGlib/string_p.h"
25 #include <gst/gststructure.h>
26 #include <QtCore/QDebug>
32 struct QTGSTREAMER_NO_EXPORT Structure::Data :
public QSharedData
34 Data() : QSharedData(), structure(NULL) {}
35 Data(
const Data & other);
38 GstStructure *structure;
41 Structure::Data::Data(
const Structure::Data & other)
42 : QSharedData(other), structure(NULL)
44 if (other.structure) {
45 structure = gst_structure_copy(other.structure);
49 Structure::Data::~Data()
52 gst_structure_free(structure);
58 Structure::Structure()
63 Structure::Structure(Data* data)
68 Structure::Structure(
const char *name)
71 d->structure = gst_structure_empty_new(name);
74 Structure::Structure(
const GstStructure* structure)
77 d->structure = gst_structure_copy(structure);
80 Structure::Structure(
const Structure & other)
85 Structure::~Structure()
89 Structure & Structure::operator=(
const Structure & other)
95 bool Structure::isValid()
const
97 return d->structure != NULL;
100 QString Structure::name()
const
103 return QString::fromUtf8(gst_structure_get_name(d->structure));
109 void Structure::setName(
const char *name)
113 d->structure = gst_structure_empty_new(name);
115 gst_structure_set_name(d->structure, name);
119 QGlib::Value Structure::value(
const char *fieldName)
const
122 return QGlib::Value(gst_structure_get_value(d->structure, fieldName));
128 void Structure::setValue(
const char *fieldName,
const QGlib::Value & value)
131 gst_structure_set_value(d->structure, fieldName, value);
134 unsigned int Structure::numberOfFields()
const
136 return d->structure ? gst_structure_n_fields(d->structure) : 0;
139 QString Structure::fieldName(
unsigned int fieldNumber)
const
141 if (fieldNumber < numberOfFields()) {
142 return QString::fromUtf8(gst_structure_nth_field_name(d->structure, fieldNumber));
148 QGlib::Type Structure::fieldType(
const char *fieldName)
const
151 return gst_structure_get_field_type(d->structure, fieldName);
153 return QGlib::Type::Invalid;
157 bool Structure::hasField(
const char *fieldName)
const
159 return d->structure ? gst_structure_has_field(d->structure, fieldName) : false;
162 bool Structure::hasFieldTyped(
const char *fieldName,
QGlib::Type type)
const
164 return d->structure ? gst_structure_has_field_typed(d->structure, fieldName, type) : false;
167 void Structure::removeField(
const char *fieldName)
170 gst_structure_remove_field(d->structure, fieldName);
174 void Structure::removeAllFields()
177 gst_structure_remove_all_fields(d->structure);
181 QString Structure::toString()
const
184 return QGlib::Private::stringFromGCharPtr(gst_structure_to_string(d->structure));
190 Structure Structure::fromString(
const char *str)
194 s.d->structure = gst_structure_from_string(str, NULL);
198 Structure::operator GstStructure*()
203 Structure::operator
const GstStructure*()
const
214 struct QTGSTREAMER_NO_EXPORT SharedStructure::Data :
public Structure::Data
216 Data() : Structure::Data() {}
217 Data(
const Data & other) : Structure::Data(other) {}
219 MiniObjectPtr miniobject;
230 SharedStructure::SharedStructure(SharedStructure::Data* data)
235 StructurePtr SharedStructure::fromMiniObject(GstStructure *structure,
const MiniObjectPtr & parent)
237 SharedStructure::Data *d =
new SharedStructure::Data;
238 d->structure = structure;
239 d->miniobject = parent;
240 return StructurePtr(
new SharedStructure(d));
243 StructurePtr SharedStructure::fromCaps(GstStructure* structure,
const CapsPtr & parent)
245 SharedStructure::Data *d =
new SharedStructure::Data;
246 d->structure = structure;
248 return StructurePtr(
new SharedStructure(d));
251 SharedStructure::~SharedStructure()
258 QDebug operator<<(QDebug debug,
const Structure & structure)
260 debug.nospace() <<
"QGst::Structure";
261 if (structure.isValid()) {
262 debug.nospace() <<
"(" << structure.toString() <<
")";
264 debug.nospace() <<
"(<invalid>)";
266 return debug.space();