1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gstreamer.MiniObject; 26 27 private import gobject.ObjectG; 28 private import gstreamerc.gstreamer; 29 public import gstreamerc.gstreamertypes; 30 private import gtkd.Loader; 31 32 33 /** 34 * #GstMiniObject is a simple structure that can be used to implement refcounted 35 * types. 36 * 37 * Subclasses will include #GstMiniObject as the first member in their structure 38 * and then call gst_mini_object_init() to initialize the #GstMiniObject fields. 39 * 40 * gst_mini_object_ref() and gst_mini_object_unref() increment and decrement the 41 * refcount respectively. When the refcount of a mini-object reaches 0, the 42 * dispose function is called first and when this returns %TRUE, the free 43 * function of the miniobject is called. 44 * 45 * A copy can be made with gst_mini_object_copy(). 46 * 47 * gst_mini_object_is_writable() will return %TRUE when the refcount of the 48 * object is exactly 1, meaning the current caller has the only reference to the 49 * object. gst_mini_object_make_writable() will return a writable version of the 50 * object, which might be a new copy when the refcount was not 1. 51 * 52 * Opaque data can be associated with a #GstMiniObject with 53 * gst_mini_object_set_qdata() and gst_mini_object_get_qdata(). The data is 54 * meant to be specific to the particular object and is not automatically copied 55 * with gst_mini_object_copy() or similar methods. 56 * 57 * A weak reference can be added and remove with gst_mini_object_weak_ref() 58 * and gst_mini_object_weak_unref() respectively. 59 */ 60 public class MiniObject 61 { 62 /** the main Gtk struct */ 63 protected GstMiniObject* gstMiniObject; 64 protected bool ownedRef; 65 66 /** Get the main Gtk struct */ 67 public GstMiniObject* getMiniObjectStruct(bool transferOwnership = false) 68 { 69 if (transferOwnership) 70 ownedRef = false; 71 return gstMiniObject; 72 } 73 74 /** the main Gtk struct as a void* */ 75 protected void* getStruct() 76 { 77 return cast(void*)gstMiniObject; 78 } 79 80 /** 81 * Sets our main struct and passes it to the parent class. 82 */ 83 public this (GstMiniObject* gstMiniObject, bool ownedRef = false) 84 { 85 this.gstMiniObject = gstMiniObject; 86 this.ownedRef = ownedRef; 87 } 88 89 ~this () 90 { 91 if ( Linker.isLoaded(LIBRARY_GSTREAMER) && ownedRef ) 92 gst_mini_object_unref(gstMiniObject); 93 } 94 95 96 /** 97 * Creates a copy of the mini-object. 98 * 99 * MT safe 100 * 101 * Returns: the new mini-object. 102 */ 103 public MiniObject copy() 104 { 105 auto p = gst_mini_object_copy(gstMiniObject); 106 107 if(p is null) 108 { 109 return null; 110 } 111 112 return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p, true); 113 } 114 115 /** 116 * This function gets back user data pointers stored via 117 * gst_mini_object_set_qdata(). 118 * 119 * Params: 120 * quark = A #GQuark, naming the user data pointer 121 * 122 * Returns: The user data pointer set, or 123 * %NULL 124 */ 125 public void* getQdata(GQuark quark) 126 { 127 return gst_mini_object_get_qdata(gstMiniObject, quark); 128 } 129 130 /** 131 * Initializes a mini-object with the desired type and copy/dispose/free 132 * functions. 133 * 134 * Params: 135 * flags = initial #GstMiniObjectFlags 136 * type = the #GType of the mini-object to create 137 * copyFunc = the copy function, or %NULL 138 * disposeFunc = the dispose function, or %NULL 139 * freeFunc = the free function or %NULL 140 */ 141 public void init(uint flags, GType type, GstMiniObjectCopyFunction copyFunc, GstMiniObjectDisposeFunction disposeFunc, GstMiniObjectFreeFunction freeFunc) 142 { 143 gst_mini_object_init(gstMiniObject, flags, type, copyFunc, disposeFunc, freeFunc); 144 } 145 146 /** 147 * If @mini_object has the LOCKABLE flag set, check if the current EXCLUSIVE 148 * lock on @object is the only one, this means that changes to the object will 149 * not be visible to any other object. 150 * 151 * If the LOCKABLE flag is not set, check if the refcount of @mini_object is 152 * exactly 1, meaning that no other reference exists to the object and that the 153 * object is therefore writable. 154 * 155 * Modification of a mini-object should only be done after verifying that it 156 * is writable. 157 * 158 * Returns: %TRUE if the object is writable. 159 */ 160 public bool isWritable() 161 { 162 return gst_mini_object_is_writable(gstMiniObject) != 0; 163 } 164 165 /** 166 * Lock the mini-object with the specified access mode in @flags. 167 * 168 * Params: 169 * flags = #GstLockFlags 170 * 171 * Returns: %TRUE if @object could be locked. 172 */ 173 public bool lock(GstLockFlags flags) 174 { 175 return gst_mini_object_lock(gstMiniObject, flags) != 0; 176 } 177 178 /** 179 * Checks if a mini-object is writable. If not, a writable copy is made and 180 * returned. This gives away the reference to the original mini object, 181 * and returns a reference to the new object. 182 * 183 * MT safe 184 * 185 * Returns: a mini-object (possibly the same pointer) that 186 * is writable. 187 */ 188 public MiniObject makeWritable() 189 { 190 auto p = gst_mini_object_make_writable(gstMiniObject); 191 192 if(p is null) 193 { 194 return null; 195 } 196 197 return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p, true); 198 } 199 200 /** 201 * Increase the reference count of the mini-object. 202 * 203 * Note that the refcount affects the writability 204 * of @mini-object, see gst_mini_object_is_writable(). It is 205 * important to note that keeping additional references to 206 * GstMiniObject instances can potentially increase the number 207 * of memcpy operations in a pipeline, especially if the miniobject 208 * is a #GstBuffer. 209 * 210 * Returns: the mini-object. 211 */ 212 public MiniObject doref() 213 { 214 auto p = gst_mini_object_ref(gstMiniObject); 215 216 if(p is null) 217 { 218 return null; 219 } 220 221 return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p, true); 222 } 223 224 /** 225 * This sets an opaque, named pointer on a miniobject. 226 * The name is specified through a #GQuark (retrieved e.g. via 227 * g_quark_from_static_string()), and the pointer 228 * can be gotten back from the @object with gst_mini_object_get_qdata() 229 * until the @object is disposed. 230 * Setting a previously set user data pointer, overrides (frees) 231 * the old pointer set, using %NULL as pointer essentially 232 * removes the data stored. 233 * 234 * @destroy may be specified which is called with @data as argument 235 * when the @object is disposed, or the data is being overwritten by 236 * a call to gst_mini_object_set_qdata() with the same @quark. 237 * 238 * Params: 239 * quark = A #GQuark, naming the user data pointer 240 * data = An opaque user data pointer 241 * destroy = Function to invoke with @data as argument, when @data 242 * needs to be freed 243 */ 244 public void setQdata(GQuark quark, void* data, GDestroyNotify destroy) 245 { 246 gst_mini_object_set_qdata(gstMiniObject, quark, data, destroy); 247 } 248 249 /** 250 * This function gets back user data pointers stored via gst_mini_object_set_qdata() 251 * and removes the data from @object without invoking its destroy() function (if 252 * any was set). 253 * 254 * Params: 255 * quark = A #GQuark, naming the user data pointer 256 * 257 * Returns: The user data pointer set, or 258 * %NULL 259 */ 260 public void* stealQdata(GQuark quark) 261 { 262 return gst_mini_object_steal_qdata(gstMiniObject, quark); 263 } 264 265 /** 266 * Unlock the mini-object with the specified access mode in @flags. 267 * 268 * Params: 269 * flags = #GstLockFlags 270 */ 271 public void unlock(GstLockFlags flags) 272 { 273 gst_mini_object_unlock(gstMiniObject, flags); 274 } 275 276 /** 277 * Decreases the reference count of the mini-object, possibly freeing 278 * the mini-object. 279 */ 280 public void unref() 281 { 282 gst_mini_object_unref(gstMiniObject); 283 } 284 285 /** 286 * Adds a weak reference callback to a mini object. Weak references are 287 * used for notification when a mini object is finalized. They are called 288 * "weak references" because they allow you to safely hold a pointer 289 * to the mini object without calling gst_mini_object_ref() 290 * (gst_mini_object_ref() adds a strong reference, that is, forces the object 291 * to stay alive). 292 * 293 * Params: 294 * notify = callback to invoke before the mini object is freed 295 * data = extra data to pass to notify 296 */ 297 public void weakRef(GstMiniObjectNotify notify, void* data) 298 { 299 gst_mini_object_weak_ref(gstMiniObject, notify, data); 300 } 301 302 /** 303 * Removes a weak reference callback from a mini object. 304 * 305 * Params: 306 * notify = callback to search for 307 * data = data to search for 308 */ 309 public void weakUnref(GstMiniObjectNotify notify, void* data) 310 { 311 gst_mini_object_weak_unref(gstMiniObject, notify, data); 312 } 313 314 /** 315 * Atomically modifies a pointer to point to a new mini-object. 316 * The reference count of @olddata is decreased and the reference count of 317 * @newdata is increased. 318 * 319 * Either @newdata and the value pointed to by @olddata may be %NULL. 320 * 321 * Params: 322 * olddata = pointer to a pointer to a 323 * mini-object to be replaced 324 * newdata = pointer to new mini-object 325 * 326 * Returns: %TRUE if @newdata was different from @olddata 327 */ 328 public static bool replace(ref MiniObject olddata, MiniObject newdata) 329 { 330 GstMiniObject* outolddata = olddata.getMiniObjectStruct(); 331 332 auto p = gst_mini_object_replace(&outolddata, (newdata is null) ? null : newdata.getMiniObjectStruct()) != 0; 333 334 olddata = ObjectG.getDObject!(MiniObject)(outolddata); 335 336 return p; 337 } 338 339 /** 340 * Replace the current #GstMiniObject pointer to by @olddata with %NULL and 341 * return the old value. 342 * 343 * Params: 344 * olddata = pointer to a pointer to a mini-object to 345 * be stolen 346 * 347 * Returns: the #GstMiniObject at @oldata 348 */ 349 public static MiniObject steal(ref MiniObject olddata) 350 { 351 GstMiniObject* outolddata = olddata.getMiniObjectStruct(); 352 353 auto p = gst_mini_object_steal(&outolddata); 354 355 olddata = ObjectG.getDObject!(MiniObject)(outolddata); 356 357 if(p is null) 358 { 359 return null; 360 } 361 362 return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p); 363 } 364 365 /** 366 * Modifies a pointer to point to a new mini-object. The modification 367 * is done atomically. This version is similar to gst_mini_object_replace() 368 * except that it does not increase the refcount of @newdata and thus 369 * takes ownership of @newdata. 370 * 371 * Either @newdata and the value pointed to by @olddata may be %NULL. 372 * 373 * Params: 374 * olddata = pointer to a pointer to a mini-object to 375 * be replaced 376 * newdata = pointer to new mini-object 377 * 378 * Returns: %TRUE if @newdata was different from @olddata 379 */ 380 public static bool take(ref MiniObject olddata, MiniObject newdata) 381 { 382 GstMiniObject* outolddata = olddata.getMiniObjectStruct(); 383 384 auto p = gst_mini_object_take(&outolddata, (newdata is null) ? null : newdata.getMiniObjectStruct()) != 0; 385 386 olddata = ObjectG.getDObject!(MiniObject)(outolddata); 387 388 return p; 389 } 390 }