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