QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
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 Lesser 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     GstCaps *caps = object<GstCaps>(); //workaround for bug #653266
00130     return (GST_CAPS_REFCOUNT_VALUE(caps) == 1);
00131 }
00132 
00133 bool Caps::equals(const CapsPtr & caps2) const
00134 {
00135     return gst_caps_is_equal(object<GstCaps>(), caps2);
00136 }
00137 
00138 bool Caps::isAlwaysCompatibleWith(const CapsPtr & caps2) const
00139 {
00140     return gst_caps_is_always_compatible(object<GstCaps>(), caps2);
00141 }
00142 
00143 bool Caps::isSubsetOf(const CapsPtr & superset) const
00144 {
00145     return gst_caps_is_subset(object<GstCaps>(), superset);
00146 }
00147 
00148 bool Caps::canIntersect(const CapsPtr & caps2) const
00149 {
00150     return gst_caps_can_intersect(object<GstCaps>(), caps2);
00151 }
00152 
00153 CapsPtr Caps::getIntersection(const CapsPtr & caps2) const
00154 {
00155     return CapsPtr::wrap(gst_caps_intersect(object<GstCaps>(), caps2), false);
00156 }
00157 
00158 CapsPtr Caps::getUnion(const CapsPtr & caps2) const
00159 {
00160     return CapsPtr::wrap(gst_caps_union(object<GstCaps>(), caps2), false);
00161 }
00162 
00163 CapsPtr Caps::getNormal() const
00164 {
00165     return CapsPtr::wrap(gst_caps_normalize(object<GstCaps>()), false);
00166 }
00167 
00168 CapsPtr Caps::subtract(const CapsPtr & subtrahend) const
00169 {
00170     return CapsPtr::wrap(gst_caps_subtract(object<GstCaps>(), subtrahend), false);
00171 }
00172 
00173 CapsPtr Caps::copy() const
00174 {
00175     return CapsPtr::wrap(gst_caps_copy(object<GstCaps>()), false);
00176 }
00177 
00178 CapsPtr Caps::copyNth(uint index) const
00179 {
00180     return CapsPtr::wrap(gst_caps_copy_nth(object<GstCaps>(), index), false);
00181 }
00182 
00183 void Caps::ref(bool increaseRef)
00184 {
00185     if (Private::ObjectStore::put(this)) {
00186         if (increaseRef) {
00187             gst_caps_ref(GST_CAPS(m_object));
00188         }
00189     }
00190 }
00191 
00192 void Caps::unref()
00193 {
00194     if (Private::ObjectStore::take(this)) {
00195         gst_caps_unref(GST_CAPS(m_object));
00196         delete this;
00197     }
00198 }
00199 
00200 CapsPtr Caps::makeWritable() const
00201 {
00202     /*
00203      * Calling gst_*_make_writable() below is tempting but wrong.
00204      * Since MiniObjects and Caps do not share the same C++ instance in various wrappings, calling
00205      * gst_*_make_writable() on an already writable object and wrapping the result is wrong,
00206      * since it would just return the same pointer and we would wrap it in a new C++ instance.
00207      */
00208     if (!isWritable()) {
00209         return copy();
00210     } else {
00211         return CapsPtr(const_cast<Caps*>(this));
00212     }
00213 }
00214 
00215 QDebug operator<<(QDebug debug, const CapsPtr & caps)
00216 {
00217     debug.nospace() << "QGst::Caps(" << caps->toString() << ")";
00218     return debug.space();
00219 }
00220 
00221 
00222 namespace Private {
00223 
00224 QGlib::RefCountedObject *wrapCaps(void *caps)
00225 {
00226     return QGlib::constructWrapper(GST_CAPS(caps)->type, caps);
00227 }
00228 
00229 } //namespace Private
00230 } //namespace QGst