QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
miniobject.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 "miniobject.h"
18 #include "objectstore_p.h"
19 #include <gst/gst.h>
20 
21 namespace QGst {
22 
23 MiniObjectPtr MiniObject::copy() const
24 {
25  return MiniObjectPtr::wrap(gst_mini_object_copy(object<GstMiniObject>()), false);
26 }
27 
28 bool MiniObject::isWritable() const
29 {
30  return gst_mini_object_is_writable(object<GstMiniObject>());
31 }
32 
33 void MiniObject::ref(bool increaseRef)
34 {
35  if (Private::ObjectStore::put(this)) {
36  if (increaseRef) {
37  gst_mini_object_ref(GST_MINI_OBJECT(m_object));
38  }
39  }
40 }
41 
42 void MiniObject::unref()
43 {
44  if (Private::ObjectStore::take(this)) {
45  gst_mini_object_unref(GST_MINI_OBJECT(m_object));
46  delete this;
47  }
48 }
49 
50 MiniObjectPtr MiniObject::makeWritable() const
51 {
52  /*
53  * Calling gst_*_make_writable() below is tempting but wrong.
54  * Since MiniObjects and Caps do not share the same C++ instance in various wrappings, calling
55  * gst_*_make_writable() on an already writable object and wrapping the result is wrong,
56  * since it would just return the same pointer and we would wrap it in a new C++ instance.
57  */
58  if (!isWritable()) {
59  return copy();
60  } else {
61  return MiniObjectPtr(const_cast<MiniObject*>(this));
62  }
63 }
64 
65 
66 namespace Private {
67 
68 QGlib::RefCountedObject *wrapMiniObject(void *miniObject)
69 {
70  return QGlib::constructWrapper(GST_MINI_OBJECT_TYPE(miniObject), miniObject);
71 }
72 
73 } //namespace Private
74 } //namespace QGst
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition: refpointer.h:326
RefCountedObject * constructWrapper(Type instanceType, void *instance)
Definition: wrap.cpp:24
Base class for all the reference-counted object wrappers.
Definition: refpointer.h:179