base: add some missing introspection annotations
[platform/upstream/gstreamer.git] / libs / gst / base / gstbitreader.c
1 /* GStreamer
2  *
3  * Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #define GST_BIT_READER_DISABLE_INLINES
26 #include "gstbitreader.h"
27
28 #include <string.h>
29
30 /**
31  * SECTION:gstbitreader
32  * @short_description: Reads any number of bits from a memory buffer
33  *
34  * #GstBitReader provides a bit reader that can read any number of bits
35  * from a memory buffer. It provides functions for reading any number of bits
36  * into 8, 16, 32 and 64 bit variables.
37  */
38
39 /**
40  * gst_bit_reader_new:
41  * @data: (array length=size): Data from which the #GstBitReader
42  *   should read
43  * @size: Size of @data in bytes
44  *
45  * Create a new #GstBitReader instance, which will read from @data.
46  *
47  * Free-function: gst_bit_reader_free
48  *
49  * Returns: (transfer full): a new #GstBitReader instance
50  *
51  * Since: 0.10.22
52  */
53 GstBitReader *
54 gst_bit_reader_new (const guint8 * data, guint size)
55 {
56   GstBitReader *ret = g_slice_new0 (GstBitReader);
57
58   ret->data = data;
59   ret->size = size;
60
61   return ret;
62 }
63
64 /**
65  * gst_bit_reader_free:
66  * @reader: (in) (transfer full): a #GstBitReader instance
67  *
68  * Frees a #GstBitReader instance, which was previously allocated by
69  * gst_bit_reader_new().
70  * 
71  * Since: 0.10.22
72  */
73 void
74 gst_bit_reader_free (GstBitReader * reader)
75 {
76   g_return_if_fail (reader != NULL);
77
78   g_slice_free (GstBitReader, reader);
79 }
80
81 /**
82  * gst_bit_reader_init:
83  * @reader: a #GstBitReader instance
84  * @data: (in) (array length=size): data from which the bit reader should read
85  * @size: Size of @data in bytes
86  *
87  * Initializes a #GstBitReader instance to read from @data. This function
88  * can be called on already initialized instances.
89  * 
90  * Since: 0.10.22
91  */
92 void
93 gst_bit_reader_init (GstBitReader * reader, const guint8 * data, guint size)
94 {
95   g_return_if_fail (reader != NULL);
96
97   reader->data = data;
98   reader->size = size;
99   reader->byte = reader->bit = 0;
100 }
101
102 /**
103  * gst_bit_reader_set_pos:
104  * @reader: a #GstBitReader instance
105  * @pos: The new position in bits
106  *
107  * Sets the new position of a #GstBitReader instance to @pos in bits.
108  *
109  * Returns: %TRUE if the position could be set successfully, %FALSE
110  * otherwise.
111  * 
112  * Since: 0.10.22
113  */
114 gboolean
115 gst_bit_reader_set_pos (GstBitReader * reader, guint pos)
116 {
117   g_return_val_if_fail (reader != NULL, FALSE);
118
119   if (pos > reader->size * 8)
120     return FALSE;
121
122   reader->byte = pos / 8;
123   reader->bit = pos % 8;
124
125   return TRUE;
126 }
127
128 /**
129  * gst_bit_reader_get_pos:
130  * @reader: a #GstBitReader instance
131  *
132  * Returns the current position of a #GstBitReader instance in bits.
133  *
134  * Returns: The current position of @reader in bits.
135  * 
136  * Since: 0.10.22
137  */
138 guint
139 gst_bit_reader_get_pos (const GstBitReader * reader)
140 {
141   return _gst_bit_reader_get_pos_inline (reader);
142 }
143
144 /**
145  * gst_bit_reader_get_remaining:
146  * @reader: a #GstBitReader instance
147  *
148  * Returns the remaining number of bits of a #GstBitReader instance.
149  *
150  * Returns: The remaining number of bits of @reader instance.
151  * 
152  * Since: 0.10.22
153  */
154 guint
155 gst_bit_reader_get_remaining (const GstBitReader * reader)
156 {
157   return _gst_bit_reader_get_remaining_inline (reader);
158 }
159
160 /**
161  * gst_bit_reader_get_size:
162  * @reader: a #GstBitReader instance
163  *
164  * Returns the total number of bits of a #GstBitReader instance.
165  *
166  * Returns: The total number of bits of @reader instance.
167  * 
168  * Since: 0.10.26
169  */
170 guint
171 gst_bit_reader_get_size (const GstBitReader * reader)
172 {
173   return _gst_bit_reader_get_size_inline (reader);
174 }
175
176 /**
177  * gst_bit_reader_skip:
178  * @reader: a #GstBitReader instance
179  * @nbits: the number of bits to skip
180  *
181  * Skips @nbits bits of the #GstBitReader instance.
182  *
183  * Returns: %TRUE if @nbits bits could be skipped, %FALSE otherwise.
184  * 
185  * Since: 0.10.22
186  */
187 gboolean
188 gst_bit_reader_skip (GstBitReader * reader, guint nbits)
189 {
190   return _gst_bit_reader_skip_inline (reader, nbits);
191 }
192
193 /**
194  * gst_bit_reader_skip_to_byte:
195  * @reader: a #GstBitReader instance
196  *
197  * Skips until the next byte.
198  *
199  * Returns: %TRUE if successful, %FALSE otherwise.
200  * 
201  * Since: 0.10.22
202  */
203 gboolean
204 gst_bit_reader_skip_to_byte (GstBitReader * reader)
205 {
206   return _gst_bit_reader_skip_to_byte_inline (reader);
207 }
208
209 /**
210  * gst_bit_reader_get_bits_uint8:
211  * @reader: a #GstBitReader instance
212  * @val: (out): Pointer to a #guint8 to store the result
213  * @nbits: number of bits to read
214  *
215  * Read @nbits bits into @val and update the current position.
216  *
217  * Returns: %TRUE if successful, %FALSE otherwise.
218  * 
219  * Since: 0.10.22
220  */
221
222 /**
223  * gst_bit_reader_get_bits_uint16:
224  * @reader: a #GstBitReader instance
225  * @val: (out): Pointer to a #guint16 to store the result
226  * @nbits: number of bits to read
227  *
228  * Read @nbits bits into @val and update the current position.
229  *
230  * Returns: %TRUE if successful, %FALSE otherwise.
231  * 
232  * Since: 0.10.22
233  */
234
235 /**
236  * gst_bit_reader_get_bits_uint32:
237  * @reader: a #GstBitReader instance
238  * @val: (out): Pointer to a #guint32 to store the result
239  * @nbits: number of bits to read
240  *
241  * Read @nbits bits into @val and update the current position.
242  *
243  * Returns: %TRUE if successful, %FALSE otherwise.
244  * 
245  * Since: 0.10.22
246  */
247
248 /**
249  * gst_bit_reader_get_bits_uint64:
250  * @reader: a #GstBitReader instance
251  * @val: (out): Pointer to a #guint64 to store the result
252  * @nbits: number of bits to read
253  *
254  * Read @nbits bits into @val and update the current position.
255  *
256  * Returns: %TRUE if successful, %FALSE otherwise.
257  * 
258  * Since: 0.10.22
259  */
260
261 /**
262  * gst_bit_reader_peek_bits_uint8:
263  * @reader: a #GstBitReader instance
264  * @val: (out): Pointer to a #guint8 to store the result
265  * @nbits: number of bits to read
266  *
267  * Read @nbits bits into @val but keep the current position.
268  *
269  * Returns: %TRUE if successful, %FALSE otherwise.
270  * 
271  * Since: 0.10.22
272  */
273
274 /**
275  * gst_bit_reader_peek_bits_uint16:
276  * @reader: a #GstBitReader instance
277  * @val: (out): Pointer to a #guint16 to store the result
278  * @nbits: number of bits to read
279  *
280  * Read @nbits bits into @val but keep the current position.
281  *
282  * Returns: %TRUE if successful, %FALSE otherwise.
283  * 
284  * Since: 0.10.22
285  */
286
287 /**
288  * gst_bit_reader_peek_bits_uint32:
289  * @reader: a #GstBitReader instance
290  * @val: (out): Pointer to a #guint32 to store the result
291  * @nbits: number of bits to read
292  *
293  * Read @nbits bits into @val but keep the current position.
294  *
295  * Returns: %TRUE if successful, %FALSE otherwise.
296  * 
297  * Since: 0.10.22
298  */
299
300 /**
301  * gst_bit_reader_peek_bits_uint64:
302  * @reader: a #GstBitReader instance
303  * @val: (out): Pointer to a #guint64 to store the result
304  * @nbits: number of bits to read
305  *
306  * Read @nbits bits into @val but keep the current position.
307  *
308  * Returns: %TRUE if successful, %FALSE otherwise.
309  * 
310  * Since: 0.10.22
311  */
312
313 #define GST_BIT_READER_READ_BITS(bits) \
314 gboolean \
315 gst_bit_reader_peek_bits_uint##bits (const GstBitReader *reader, guint##bits *val, guint nbits) \
316 { \
317   return _gst_bit_reader_peek_bits_uint##bits##_inline (reader, val, nbits); \
318 } \
319 \
320 gboolean \
321 gst_bit_reader_get_bits_uint##bits (GstBitReader *reader, guint##bits *val, guint nbits) \
322 { \
323   return _gst_bit_reader_get_bits_uint##bits##_inline (reader, val, nbits); \
324 }
325
326 GST_BIT_READER_READ_BITS (8);
327 GST_BIT_READER_READ_BITS (16);
328 GST_BIT_READER_READ_BITS (32);
329 GST_BIT_READER_READ_BITS (64);