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 gst.base.BitWriter; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gst.base.c.functions; 30 public import gst.base.c.types; 31 private import gstreamer.Buffer; 32 private import gtkd.Loader; 33 34 35 /** 36 * #GstBitWriter provides a bit writer that can write any number of 37 * bits into a memory buffer. It provides functions for writing any 38 * number of bits into 8, 16, 32 and 64 bit variables. 39 */ 40 public class BitWriter 41 { 42 /** the main Gtk struct */ 43 protected GstBitWriter* gstBitWriter; 44 protected bool ownedRef; 45 46 /** Get the main Gtk struct */ 47 public GstBitWriter* getBitWriterStruct(bool transferOwnership = false) 48 { 49 if (transferOwnership) 50 ownedRef = false; 51 return gstBitWriter; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected void* getStruct() 56 { 57 return cast(void*)gstBitWriter; 58 } 59 60 /** 61 * Sets our main struct and passes it to the parent class. 62 */ 63 public this (GstBitWriter* gstBitWriter, bool ownedRef = false) 64 { 65 this.gstBitWriter = gstBitWriter; 66 this.ownedRef = ownedRef; 67 } 68 69 ~this () 70 { 71 if ( Linker.isLoaded(LIBRARY_GSTBASE) && ownedRef ) 72 gst_bit_writer_free(gstBitWriter); 73 } 74 75 76 /** 77 * Write trailing bit to align last byte of @data. @trailing_bit can 78 * only be 1 or 0. 79 * 80 * Params: 81 * trailingBit = trailing bits of last byte, 0 or 1 82 * 83 * Returns: %TRUE if successful, %FALSE otherwise. 84 */ 85 public bool alignBytes(ubyte trailingBit) 86 { 87 return gst_bit_writer_align_bytes(gstBitWriter, trailingBit) != 0; 88 } 89 90 /** 91 * Frees @bitwriter and the allocated data inside. 92 */ 93 public void free() 94 { 95 gst_bit_writer_free(gstBitWriter); 96 ownedRef = false; 97 } 98 99 /** 100 * Frees @bitwriter without destroying the internal data, which is 101 * returned as #GstBuffer. 102 * 103 * Free-function: gst_buffer_unref 104 * 105 * Returns: a new allocated #GstBuffer wrapping the 106 * data inside. gst_buffer_unref() after usage. 107 */ 108 public Buffer freeAndGetBuffer() 109 { 110 auto p = gst_bit_writer_free_and_get_buffer(gstBitWriter); 111 112 if(p is null) 113 { 114 return null; 115 } 116 117 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true); 118 } 119 120 /** 121 * Frees @bitwriter without destroying the internal data, which is 122 * returned. 123 * 124 * Free-function: g_free 125 * 126 * Returns: the current data. g_free() after 127 * usage. 128 */ 129 public ubyte[] freeAndGetData() 130 { 131 auto p = gst_bit_writer_free_and_get_data(gstBitWriter); 132 133 return p[0 .. getArrayLength(p)]; 134 } 135 136 /** 137 * Get written data pointer 138 * 139 * Returns: data pointer 140 */ 141 public ubyte* getData() 142 { 143 return gst_bit_writer_get_data(gstBitWriter); 144 } 145 146 /** */ 147 public uint getRemaining() 148 { 149 return gst_bit_writer_get_remaining(gstBitWriter); 150 } 151 152 /** 153 * Get size of written @data 154 * 155 * Returns: size of bits written in @data 156 */ 157 public uint getSize() 158 { 159 return gst_bit_writer_get_size(gstBitWriter); 160 } 161 162 /** 163 * Initializes @bitwriter to an empty instance. 164 */ 165 public void init() 166 { 167 gst_bit_writer_init(gstBitWriter); 168 } 169 170 /** 171 * Initializes @bitwriter with the given memory area @data. IF 172 * @initialized is %TRUE it is possible to read @size bits from the 173 * #GstBitWriter from the beginning. 174 * 175 * Params: 176 * data = Memory area for writing 177 * initialized = If %TRUE the complete data can be read from the beginning 178 */ 179 public void initWithData(ubyte[] data, bool initialized) 180 { 181 gst_bit_writer_init_with_data(gstBitWriter, data.ptr, cast(uint)data.length, initialized); 182 } 183 184 /** 185 * Initializes a #GstBitWriter instance and allocates the given data 186 * @size. 187 * 188 * Params: 189 * size = the size on bytes to allocate for data 190 * fixed = If %TRUE the data can't be reallocated 191 */ 192 public void initWithSize(uint size, bool fixed) 193 { 194 gst_bit_writer_init_with_size(gstBitWriter, size, fixed); 195 } 196 197 /** 198 * Write @nbits bits of @value to #GstBitWriter. 199 * 200 * Params: 201 * value = value of #guint16 to write 202 * nbits = number of bits to write 203 * 204 * Returns: %TRUE if successful, %FALSE otherwise. 205 */ 206 public bool putBitsUint16(ushort value, uint nbits) 207 { 208 return gst_bit_writer_put_bits_uint16(gstBitWriter, value, nbits) != 0; 209 } 210 211 /** 212 * Write @nbits bits of @value to #GstBitWriter. 213 * 214 * Params: 215 * value = value of #guint32 to write 216 * nbits = number of bits to write 217 * 218 * Returns: %TRUE if successful, %FALSE otherwise. 219 */ 220 public bool putBitsUint32(uint value, uint nbits) 221 { 222 return gst_bit_writer_put_bits_uint32(gstBitWriter, value, nbits) != 0; 223 } 224 225 /** 226 * Write @nbits bits of @value to #GstBitWriter. 227 * 228 * Params: 229 * value = value of #guint64 to write 230 * nbits = number of bits to write 231 * 232 * Returns: %TRUE if successful, %FALSE otherwise. 233 */ 234 public bool putBitsUint64(ulong value, uint nbits) 235 { 236 return gst_bit_writer_put_bits_uint64(gstBitWriter, value, nbits) != 0; 237 } 238 239 /** 240 * Write @nbits bits of @value to #GstBitWriter. 241 * 242 * Params: 243 * value = value of #guint8 to write 244 * nbits = number of bits to write 245 * 246 * Returns: %TRUE if successful, %FALSE otherwise. 247 */ 248 public bool putBitsUint8(ubyte value, uint nbits) 249 { 250 return gst_bit_writer_put_bits_uint8(gstBitWriter, value, nbits) != 0; 251 } 252 253 /** 254 * Write @nbytes bytes of @data to #GstBitWriter. 255 * 256 * Params: 257 * data = pointer of data to write 258 * nbytes = number of bytes to write 259 * 260 * Returns: %TRUE if successful, %FALSE otherwise. 261 */ 262 public bool putBytes(ubyte* data, uint nbytes) 263 { 264 return gst_bit_writer_put_bytes(gstBitWriter, data, nbytes) != 0; 265 } 266 267 /** 268 * Resets @bitwriter and frees the data if it's owned by @bitwriter. 269 */ 270 public void reset() 271 { 272 gst_bit_writer_reset(gstBitWriter); 273 } 274 275 /** 276 * Resets @bitwriter and returns the current data as #GstBuffer. 277 * 278 * Free-function: gst_buffer_unref 279 * 280 * Returns: a new allocated #GstBuffer wrapping the 281 * current data. gst_buffer_unref() after usage. 282 */ 283 public Buffer resetAndGetBuffer() 284 { 285 auto p = gst_bit_writer_reset_and_get_buffer(gstBitWriter); 286 287 if(p is null) 288 { 289 return null; 290 } 291 292 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true); 293 } 294 295 /** 296 * Resets @bitwriter and returns the current data. 297 * 298 * Free-function: g_free 299 * 300 * Returns: the current data. g_free() after 301 * usage. 302 */ 303 public ubyte[] resetAndGetData() 304 { 305 auto p = gst_bit_writer_reset_and_get_data(gstBitWriter); 306 307 return p[0 .. getArrayLength(p)]; 308 } 309 310 /** */ 311 public bool setPos(uint pos) 312 { 313 return gst_bit_writer_set_pos(gstBitWriter, pos) != 0; 314 } 315 316 /** 317 * Creates a new, empty #GstBitWriter instance. 318 * 319 * Free-function: gst_bit_writer_free 320 * 321 * Returns: a new, empty #GstByteWriter instance 322 * 323 * Throws: ConstructionException GTK+ fails to create the object. 324 */ 325 public this() 326 { 327 auto p = gst_bit_writer_new(); 328 329 if(p is null) 330 { 331 throw new ConstructionException("null returned by new"); 332 } 333 334 this(cast(GstBitWriter*) p); 335 } 336 337 /** 338 * Creates a new #GstBitWriter instance with the given memory area. If 339 * @initialized is %TRUE it is possible to read @size bits from the 340 * #GstBitWriter from the beginnig. 341 * 342 * Free-function: gst_bit_writer_free 343 * 344 * Params: 345 * data = Memory area for writing 346 * size = Size of @data in bytes 347 * initialized = if %TRUE the complete data can be read from the beginning 348 * 349 * Returns: a new #GstBitWriter instance 350 * 351 * Throws: ConstructionException GTK+ fails to create the object. 352 */ 353 public this(ubyte* data, uint size, bool initialized) 354 { 355 auto p = gst_bit_writer_new_with_data(data, size, initialized); 356 357 if(p is null) 358 { 359 throw new ConstructionException("null returned by new_with_data"); 360 } 361 362 this(cast(GstBitWriter*) p); 363 } 364 365 /** 366 * Creates a #GstBitWriter instance with the given initial data size. 367 * 368 * Free-function: gst_bit_writer_free 369 * 370 * Params: 371 * size = Initial size of data in bytes 372 * fixed = If %TRUE the data can't be reallocated 373 * 374 * Returns: a new #GstBitWriter instance 375 * 376 * Throws: ConstructionException GTK+ fails to create the object. 377 */ 378 public this(uint size, bool fixed) 379 { 380 auto p = gst_bit_writer_new_with_size(size, fixed); 381 382 if(p is null) 383 { 384 throw new ConstructionException("null returned by new_with_size"); 385 } 386 387 this(cast(GstBitWriter*) p); 388 } 389 }