QtGStreamer 0.10.1

caps.cpp

00001 /*
00002     Copyright (C) 2009-2010  George Kiagiadakis <kiagiadakis.george@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as published
00006     by the Free Software Foundation; either version 2.1 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public License
00015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 #include "caps.h"
00018 #include "structure.h"
00019 #include "../QGlib/string_p.h"
00020 #include "objectstore_p.h"
00021 #include <QtCore/QDebug>
00022 #include <gst/gstcaps.h>
00023 #include <gst/gstvalue.h>
00024 
00025 namespace QGst {
00026 
00027 //static
00028 CapsPtr Caps::createSimple(const char *mediaType)
00029 {
00030     return CapsPtr::wrap(gst_caps_new_simple(mediaType, NULL), false);
00031 }
00032 
00033 //static
00034 CapsPtr Caps::createAny()
00035 {
00036     return CapsPtr::wrap(gst_caps_new_any(), false);
00037 }
00038 
00039 //static
00040 CapsPtr Caps::createEmpty()
00041 {
00042     return CapsPtr::wrap(gst_caps_new_empty(), false);
00043 }
00044 
00045 //static
00046 CapsPtr Caps::fromString(const char *string)
00047 {
00048     return CapsPtr::wrap(gst_caps_from_string(string), false);
00049 }
00050 
00051 QString Caps::toString() const
00052 {
00053     return QGlib::Private::stringFromGCharPtr(gst_caps_to_string(object<GstCaps>()));
00054 }
00055 
00056 void Caps::append(const CapsPtr & caps2)
00057 {
00058     gst_caps_append(object<GstCaps>(), gst_caps_copy(caps2));
00059 }
00060 
00061 void Caps::merge(const CapsPtr & caps2)
00062 {
00063     gst_caps_merge(object<GstCaps>(), gst_caps_copy(caps2));
00064 }
00065 
00066 void Caps::setValue(const char *field, const QGlib::Value & value)
00067 {
00068     gst_caps_set_value(object<GstCaps>(), field, value);
00069 }
00070 
00071 bool Caps::simplify()
00072 {
00073     return gst_caps_do_simplify(object<GstCaps>());
00074 }
00075 
00076 void Caps::truncate()
00077 {
00078     gst_caps_truncate(object<GstCaps>());
00079 }
00080 
00081 StructurePtr Caps::internalStructure(uint index)
00082 {
00083     GstStructure *structure = gst_caps_get_structure(object<GstCaps>(), index);
00084     return SharedStructure::fromCaps(structure, CapsPtr(this));
00085 }
00086 
00087 void Caps::appendStructure(const Structure & structure)
00088 {
00089     gst_caps_append_structure(object<GstCaps>(), gst_structure_copy(structure));
00090 }
00091 
00092 void Caps::mergeStructure(const Structure & structure)
00093 {
00094     gst_caps_merge_structure(object<GstCaps>(), gst_structure_copy(structure));
00095 }
00096 
00097 void Caps::removeStructure(uint index)
00098 {
00099     gst_caps_remove_structure(object<GstCaps>(), index);
00100 }
00101 
00102 uint Caps::size() const
00103 {
00104    return gst_caps_get_size(object<GstCaps>());
00105 }
00106 
00107 bool Caps::isSimple() const
00108 {
00109     return GST_CAPS_IS_SIMPLE(object<GstCaps>());
00110 }
00111 
00112 bool Caps::isAny() const
00113 {
00114     return gst_caps_is_any(object<GstCaps>());
00115 }
00116 
00117 bool Caps::isEmpty() const
00118 {
00119     return gst_caps_is_empty(object<GstCaps>());
00120 }
00121 
00122 bool Caps::isFixed() const
00123 {
00124     return gst_caps_is_fixed(object<GstCaps>());
00125 }
00126 
00127 bool Caps::isWritable() const
00128 {
00129     return (GST_CAPS_REFCOUNT_VALUE(object<GstCaps>()) == 1);
00130 }
00131 
00132 bool Caps::equals(const CapsPtr & caps2) const
00133 {
00134     return gst_caps_is_equal(object<GstCaps>(), caps2);
00135 }
00136 
00137 bool Caps::isAlwaysCompatibleWith(const CapsPtr & caps2) const
00138 {
00139     return gst_caps_is_always_compatible(object<GstCaps>(), caps2);
00140 }
00141 
00142 bool Caps::isSubsetOf(const CapsPtr & superset) const
00143 {
00144     return gst_caps_is_subset(object<GstCaps>(), superset);
00145 }
00146 
00147 bool Caps::canIntersect(const CapsPtr & caps2) const
00148 {
00149     return gst_caps_can_intersect(object<GstCaps>(), caps2);
00150 }
00151 
00152 CapsPtr Caps::getIntersection(const CapsPtr & caps2) const
00153 {
00154     return CapsPtr::wrap(gst_caps_intersect(object<GstCaps>(), caps2), false);
00155 }
00156 
00157 CapsPtr Caps::getUnion(const CapsPtr & caps2) const
00158 {
00159     return CapsPtr::wrap(gst_caps_union(object<GstCaps>(), caps2), false);
00160 }
00161 
00162 CapsPtr Caps::getNormal() const
00163 {
00164     return CapsPtr::wrap(gst_caps_normalize(object<GstCaps>()), false);
00165 }
00166 
00167 CapsPtr Caps::subtract(const CapsPtr & subtrahend) const
00168 {
00169     return CapsPtr::wrap(gst_caps_subtract(object<GstCaps>(), subtrahend), false);
00170 }
00171 
00172 CapsPtr Caps::copy() const
00173 {
00174     return CapsPtr::wrap(gst_caps_copy(object<GstCaps>()), false);
00175 }
00176 
00177 CapsPtr Caps::copyNth(uint index) const
00178 {
00179     return CapsPtr::wrap(gst_caps_copy_nth(object<GstCaps>(), index), false);
00180 }
00181 
00182 void Caps::ref(bool increaseRef)
00183 {
00184     if (Private::ObjectStore::put(this)) {
00185         if (increaseRef) {
00186             gst_caps_ref(GST_CAPS(m_object));
00187         }
00188     }
00189 }
00190 
00191 void Caps::unref()
00192 {
00193     if (Private::ObjectStore::take(this)) {
00194         gst_caps_unref(GST_CAPS(m_object));
00195         delete this;
00196     }
00197 }
00198 
00199 CapsPtr Caps::makeWritable() const
00200 {
00201     /*
00202      * Calling gst_*_make_writable() below is tempting but wrong.
00203      * Since MiniObjects and Caps do not share the same C++ instance in various wrappings, calling
00204      * gst_*_make_writable() on an already writable object and wrapping the result is wrong,
00205      * since it would just return the same pointer and we would wrap it in a new C++ instance.
00206      */
00207     if (!isWritable()) {
00208         return copy();
00209     } else {
00210         return CapsPtr(const_cast<Caps*>(this));
00211     }
00212 }
00213 
00214 QDebug operator<<(QDebug debug, const CapsPtr & caps)
00215 {
00216     debug.nospace() << "QGst::Caps(" << caps->toString() << ")";
00217     return debug.space();
00218 }
00219 
00220 
00221 namespace Private {
00222 
00223 QGlib::RefCountedObject *wrapCaps(void *caps)
00224 {
00225     return QGlib::constructWrapper(GST_CAPS(caps)->type, caps);
00226 }
00227 
00228 } //namespace Private
00229 } //namespace QGst
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator