File: BitWriter.d

package info (click to toggle)
gtk-d 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,152 kB
  • sloc: javascript: 565; sh: 71; makefile: 25
file content (389 lines) | stat: -rw-r--r-- 9,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
 * This file is part of gtkD.
 *
 * gtkD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version, with
 * some exceptions, please read the COPYING file.
 *
 * gtkD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with gtkD; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */

// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage


module gst.base.BitWriter;

private import glib.ConstructionException;
private import gobject.ObjectG;
private import gst.base.c.functions;
public  import gst.base.c.types;
private import gstreamer.Buffer;
private import gtkd.Loader;


/**
 * #GstBitWriter provides a bit writer that can write any number of
 * bits into a memory buffer. It provides functions for writing any
 * number of bits into 8, 16, 32 and 64 bit variables.
 */
public class BitWriter
{
	/** the main Gtk struct */
	protected GstBitWriter* gstBitWriter;
	protected bool ownedRef;

	/** Get the main Gtk struct */
	public GstBitWriter* getBitWriterStruct(bool transferOwnership = false)
	{
		if (transferOwnership)
			ownedRef = false;
		return gstBitWriter;
	}

	/** the main Gtk struct as a void* */
	protected void* getStruct()
	{
		return cast(void*)gstBitWriter;
	}

	/**
	 * Sets our main struct and passes it to the parent class.
	 */
	public this (GstBitWriter* gstBitWriter, bool ownedRef = false)
	{
		this.gstBitWriter = gstBitWriter;
		this.ownedRef = ownedRef;
	}

	~this ()
	{
		if ( Linker.isLoaded(LIBRARY_GSTBASE) && ownedRef )
			gst_bit_writer_free(gstBitWriter);
	}


	/**
	 * Write trailing bit to align last byte of @data. @trailing_bit can
	 * only be 1 or 0.
	 *
	 * Params:
	 *     trailingBit = trailing bits of last byte, 0 or 1
	 *
	 * Returns: %TRUE if successful, %FALSE otherwise.
	 */
	public bool alignBytes(ubyte trailingBit)
	{
		return gst_bit_writer_align_bytes(gstBitWriter, trailingBit) != 0;
	}

	/**
	 * Frees @bitwriter and the allocated data inside.
	 */
	public void free()
	{
		gst_bit_writer_free(gstBitWriter);
		ownedRef = false;
	}

	/**
	 * Frees @bitwriter without destroying the internal data, which is
	 * returned as #GstBuffer.
	 *
	 * Free-function: gst_buffer_unref
	 *
	 * Returns: a new allocated #GstBuffer wrapping the
	 *     data inside. gst_buffer_unref() after usage.
	 */
	public Buffer freeAndGetBuffer()
	{
		auto p = gst_bit_writer_free_and_get_buffer(gstBitWriter);

		if(p is null)
		{
			return null;
		}

		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
	}

	/**
	 * Frees @bitwriter without destroying the internal data, which is
	 * returned.
	 *
	 * Free-function: g_free
	 *
	 * Returns: the current data. g_free() after
	 *     usage.
	 */
	public ubyte[] freeAndGetData()
	{
		auto p = gst_bit_writer_free_and_get_data(gstBitWriter);

		return p[0 .. getArrayLength(p)];
	}

	/**
	 * Get written data pointer
	 *
	 * Returns: data pointer
	 */
	public ubyte* getData()
	{
		return gst_bit_writer_get_data(gstBitWriter);
	}

	/** */
	public uint getRemaining()
	{
		return gst_bit_writer_get_remaining(gstBitWriter);
	}

	/**
	 * Get size of written @data
	 *
	 * Returns: size of bits written in @data
	 */
	public uint getSize()
	{
		return gst_bit_writer_get_size(gstBitWriter);
	}

	/**
	 * Initializes @bitwriter to an empty instance.
	 */
	public void init()
	{
		gst_bit_writer_init(gstBitWriter);
	}

	/**
	 * Initializes @bitwriter with the given memory area @data. IF
	 * @initialized is %TRUE it is possible to read @size bits from the
	 * #GstBitWriter from the beginning.
	 *
	 * Params:
	 *     data = Memory area for writing
	 *     initialized = If %TRUE the complete data can be read from the beginning
	 */
	public void initWithData(ubyte[] data, bool initialized)
	{
		gst_bit_writer_init_with_data(gstBitWriter, data.ptr, cast(uint)data.length, initialized);
	}

	/**
	 * Initializes a #GstBitWriter instance and allocates the given data
	 * @size.
	 *
	 * Params:
	 *     size = the size on bytes to allocate for data
	 *     fixed = If %TRUE the data can't be reallocated
	 */
	public void initWithSize(uint size, bool fixed)
	{
		gst_bit_writer_init_with_size(gstBitWriter, size, fixed);
	}

	/**
	 * Write @nbits bits of @value to #GstBitWriter.
	 *
	 * Params:
	 *     value = value of #guint16 to write
	 *     nbits = number of bits to write
	 *
	 * Returns: %TRUE if successful, %FALSE otherwise.
	 */
	public bool putBitsUint16(ushort value, uint nbits)
	{
		return gst_bit_writer_put_bits_uint16(gstBitWriter, value, nbits) != 0;
	}

	/**
	 * Write @nbits bits of @value to #GstBitWriter.
	 *
	 * Params:
	 *     value = value of #guint32 to write
	 *     nbits = number of bits to write
	 *
	 * Returns: %TRUE if successful, %FALSE otherwise.
	 */
	public bool putBitsUint32(uint value, uint nbits)
	{
		return gst_bit_writer_put_bits_uint32(gstBitWriter, value, nbits) != 0;
	}

	/**
	 * Write @nbits bits of @value to #GstBitWriter.
	 *
	 * Params:
	 *     value = value of #guint64 to write
	 *     nbits = number of bits to write
	 *
	 * Returns: %TRUE if successful, %FALSE otherwise.
	 */
	public bool putBitsUint64(ulong value, uint nbits)
	{
		return gst_bit_writer_put_bits_uint64(gstBitWriter, value, nbits) != 0;
	}

	/**
	 * Write @nbits bits of @value to #GstBitWriter.
	 *
	 * Params:
	 *     value = value of #guint8 to write
	 *     nbits = number of bits to write
	 *
	 * Returns: %TRUE if successful, %FALSE otherwise.
	 */
	public bool putBitsUint8(ubyte value, uint nbits)
	{
		return gst_bit_writer_put_bits_uint8(gstBitWriter, value, nbits) != 0;
	}

	/**
	 * Write @nbytes bytes of @data to #GstBitWriter.
	 *
	 * Params:
	 *     data = pointer of data to write
	 *     nbytes = number of bytes to write
	 *
	 * Returns: %TRUE if successful, %FALSE otherwise.
	 */
	public bool putBytes(ubyte* data, uint nbytes)
	{
		return gst_bit_writer_put_bytes(gstBitWriter, data, nbytes) != 0;
	}

	/**
	 * Resets @bitwriter and frees the data if it's owned by @bitwriter.
	 */
	public void reset()
	{
		gst_bit_writer_reset(gstBitWriter);
	}

	/**
	 * Resets @bitwriter and returns the current data as #GstBuffer.
	 *
	 * Free-function: gst_buffer_unref
	 *
	 * Returns: a new allocated #GstBuffer wrapping the
	 *     current data. gst_buffer_unref() after usage.
	 */
	public Buffer resetAndGetBuffer()
	{
		auto p = gst_bit_writer_reset_and_get_buffer(gstBitWriter);

		if(p is null)
		{
			return null;
		}

		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
	}

	/**
	 * Resets @bitwriter and returns the current data.
	 *
	 * Free-function: g_free
	 *
	 * Returns: the current data. g_free() after
	 *     usage.
	 */
	public ubyte[] resetAndGetData()
	{
		auto p = gst_bit_writer_reset_and_get_data(gstBitWriter);

		return p[0 .. getArrayLength(p)];
	}

	/** */
	public bool setPos(uint pos)
	{
		return gst_bit_writer_set_pos(gstBitWriter, pos) != 0;
	}

	/**
	 * Creates a new, empty #GstBitWriter instance.
	 *
	 * Free-function: gst_bit_writer_free
	 *
	 * Returns: a new, empty #GstByteWriter instance
	 *
	 * Throws: ConstructionException GTK+ fails to create the object.
	 */
	public this()
	{
		auto p = gst_bit_writer_new();

		if(p is null)
		{
			throw new ConstructionException("null returned by new");
		}

		this(cast(GstBitWriter*) p);
	}

	/**
	 * Creates a new #GstBitWriter instance with the given memory area. If
	 * @initialized is %TRUE it is possible to read @size bits from the
	 * #GstBitWriter from the beginnig.
	 *
	 * Free-function: gst_bit_writer_free
	 *
	 * Params:
	 *     data = Memory area for writing
	 *     size = Size of @data in bytes
	 *     initialized = if %TRUE the complete data can be read from the beginning
	 *
	 * Returns: a new #GstBitWriter instance
	 *
	 * Throws: ConstructionException GTK+ fails to create the object.
	 */
	public this(ubyte* data, uint size, bool initialized)
	{
		auto p = gst_bit_writer_new_with_data(data, size, initialized);

		if(p is null)
		{
			throw new ConstructionException("null returned by new_with_data");
		}

		this(cast(GstBitWriter*) p);
	}

	/**
	 * Creates a #GstBitWriter instance with the given initial data size.
	 *
	 * Free-function: gst_bit_writer_free
	 *
	 * Params:
	 *     size = Initial size of data in bytes
	 *     fixed = If %TRUE the data can't be reallocated
	 *
	 * Returns: a new #GstBitWriter instance
	 *
	 * Throws: ConstructionException GTK+ fails to create the object.
	 */
	public this(uint size, bool fixed)
	{
		auto p = gst_bit_writer_new_with_size(size, fixed);

		if(p is null)
		{
			throw new ConstructionException("null returned by new_with_size");
		}

		this(cast(GstBitWriter*) p);
	}
}