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