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