1 /* GStreamer byte reader
3 * Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>.
4 * Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef __GST_BYTE_READER_H__
23 #define __GST_BYTE_READER_H__
29 #define GST_BYTE_READER(reader) ((GstByteReader *) (reader))
33 * @data: (array length=size): Data from which the bit reader will
35 * @size: Size of @data in bytes
36 * @byte: Current byte position
38 * A byte reader instance.
44 guint byte; /* Byte position */
47 gpointer _gst_reserved[GST_PADDING];
50 GstByteReader * gst_byte_reader_new (const guint8 *data, guint size) G_GNUC_MALLOC;
51 void gst_byte_reader_free (GstByteReader *reader);
53 void gst_byte_reader_init (GstByteReader *reader, const guint8 *data, guint size);
55 gboolean gst_byte_reader_set_pos (GstByteReader *reader, guint pos);
56 guint gst_byte_reader_get_pos (const GstByteReader *reader);
58 guint gst_byte_reader_get_remaining (const GstByteReader *reader);
60 guint gst_byte_reader_get_size (const GstByteReader *reader);
62 gboolean gst_byte_reader_skip (GstByteReader *reader, guint nbytes);
64 gboolean gst_byte_reader_get_uint8 (GstByteReader *reader, guint8 *val);
65 gboolean gst_byte_reader_get_int8 (GstByteReader *reader, gint8 *val);
66 gboolean gst_byte_reader_get_uint16_le (GstByteReader *reader, guint16 *val);
67 gboolean gst_byte_reader_get_int16_le (GstByteReader *reader, gint16 *val);
68 gboolean gst_byte_reader_get_uint16_be (GstByteReader *reader, guint16 *val);
69 gboolean gst_byte_reader_get_int16_be (GstByteReader *reader, gint16 *val);
70 gboolean gst_byte_reader_get_uint24_le (GstByteReader *reader, guint32 *val);
71 gboolean gst_byte_reader_get_int24_le (GstByteReader *reader, gint32 *val);
72 gboolean gst_byte_reader_get_uint24_be (GstByteReader *reader, guint32 *val);
73 gboolean gst_byte_reader_get_int24_be (GstByteReader *reader, gint32 *val);
74 gboolean gst_byte_reader_get_uint32_le (GstByteReader *reader, guint32 *val);
75 gboolean gst_byte_reader_get_int32_le (GstByteReader *reader, gint32 *val);
76 gboolean gst_byte_reader_get_uint32_be (GstByteReader *reader, guint32 *val);
77 gboolean gst_byte_reader_get_int32_be (GstByteReader *reader, gint32 *val);
78 gboolean gst_byte_reader_get_uint64_le (GstByteReader *reader, guint64 *val);
79 gboolean gst_byte_reader_get_int64_le (GstByteReader *reader, gint64 *val);
80 gboolean gst_byte_reader_get_uint64_be (GstByteReader *reader, guint64 *val);
81 gboolean gst_byte_reader_get_int64_be (GstByteReader *reader, gint64 *val);
83 gboolean gst_byte_reader_peek_uint8 (const GstByteReader *reader, guint8 *val);
84 gboolean gst_byte_reader_peek_int8 (const GstByteReader *reader, gint8 *val);
85 gboolean gst_byte_reader_peek_uint16_le (const GstByteReader *reader, guint16 *val);
86 gboolean gst_byte_reader_peek_int16_le (const GstByteReader *reader, gint16 *val);
87 gboolean gst_byte_reader_peek_uint16_be (const GstByteReader *reader, guint16 *val);
88 gboolean gst_byte_reader_peek_int16_be (const GstByteReader *reader, gint16 *val);
89 gboolean gst_byte_reader_peek_uint24_le (const GstByteReader *reader, guint32 *val);
90 gboolean gst_byte_reader_peek_int24_le (const GstByteReader *reader, gint32 *val);
91 gboolean gst_byte_reader_peek_uint24_be (const GstByteReader *reader, guint32 *val);
92 gboolean gst_byte_reader_peek_int24_be (const GstByteReader *reader, gint32 *val);
93 gboolean gst_byte_reader_peek_uint32_le (const GstByteReader *reader, guint32 *val);
94 gboolean gst_byte_reader_peek_int32_le (const GstByteReader *reader, gint32 *val);
95 gboolean gst_byte_reader_peek_uint32_be (const GstByteReader *reader, guint32 *val);
96 gboolean gst_byte_reader_peek_int32_be (const GstByteReader *reader, gint32 *val);
97 gboolean gst_byte_reader_peek_uint64_le (const GstByteReader *reader, guint64 *val);
98 gboolean gst_byte_reader_peek_int64_le (const GstByteReader *reader, gint64 *val);
99 gboolean gst_byte_reader_peek_uint64_be (const GstByteReader *reader, guint64 *val);
100 gboolean gst_byte_reader_peek_int64_be (const GstByteReader *reader, gint64 *val);
102 gboolean gst_byte_reader_get_float32_le (GstByteReader *reader, gfloat *val);
103 gboolean gst_byte_reader_get_float32_be (GstByteReader *reader, gfloat *val);
104 gboolean gst_byte_reader_get_float64_le (GstByteReader *reader, gdouble *val);
105 gboolean gst_byte_reader_get_float64_be (GstByteReader *reader, gdouble *val);
107 gboolean gst_byte_reader_peek_float32_le (const GstByteReader *reader, gfloat *val);
108 gboolean gst_byte_reader_peek_float32_be (const GstByteReader *reader, gfloat *val);
109 gboolean gst_byte_reader_peek_float64_le (const GstByteReader *reader, gdouble *val);
110 gboolean gst_byte_reader_peek_float64_be (const GstByteReader *reader, gdouble *val);
112 gboolean gst_byte_reader_dup_data (GstByteReader * reader, guint size, guint8 ** val);
113 gboolean gst_byte_reader_get_data (GstByteReader * reader, guint size, const guint8 ** val);
114 gboolean gst_byte_reader_peek_data (const GstByteReader * reader, guint size, const guint8 ** val);
116 #define gst_byte_reader_dup_string(reader,str) \
117 gst_byte_reader_dup_string_utf8(reader,str)
119 gboolean gst_byte_reader_dup_string_utf8 (GstByteReader * reader, gchar ** str);
120 gboolean gst_byte_reader_dup_string_utf16 (GstByteReader * reader, guint16 ** str);
121 gboolean gst_byte_reader_dup_string_utf32 (GstByteReader * reader, guint32 ** str);
123 #define gst_byte_reader_skip_string(reader) \
124 gst_byte_reader_skip_string_utf8(reader)
126 gboolean gst_byte_reader_skip_string_utf8 (GstByteReader * reader);
127 gboolean gst_byte_reader_skip_string_utf16 (GstByteReader * reader);
128 gboolean gst_byte_reader_skip_string_utf32 (GstByteReader * reader);
130 #define gst_byte_reader_get_string(reader,str) \
131 gst_byte_reader_get_string_utf8(reader,str)
133 #define gst_byte_reader_peek_string(reader,str) \
134 gst_byte_reader_peek_string_utf8(reader,str)
136 gboolean gst_byte_reader_get_string_utf8 (GstByteReader * reader, const gchar ** str);
137 gboolean gst_byte_reader_peek_string_utf8 (const GstByteReader * reader, const gchar ** str);
139 guint gst_byte_reader_masked_scan_uint32 (const GstByteReader * reader,
146 * GST_BYTE_READER_INIT:
147 * @data: Data from which the #GstByteReader should read
148 * @size: Size of @data in bytes
150 * A #GstByteReader must be initialized with this macro, before it can be
151 * used. This macro can used be to initialize a variable, but it cannot
152 * be assigned to a variable. In that case you have to use
153 * gst_byte_reader_init().
155 #define GST_BYTE_READER_INIT(data, size) {data, size, 0}
157 /* unchecked variants */
159 gst_byte_reader_skip_unchecked (GstByteReader * reader, guint nbytes)
161 reader->byte += nbytes;
164 #define __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(bits,type,lower,upper,adj) \
167 gst_byte_reader_peek_##lower##_unchecked (const GstByteReader * reader) \
169 type val = (type) GST_READ_##upper (reader->data + reader->byte); \
175 gst_byte_reader_get_##lower##_unchecked (GstByteReader * reader) \
177 type val = gst_byte_reader_peek_##lower##_unchecked (reader); \
178 reader->byte += bits / 8; \
182 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(8,guint8,uint8,UINT8,/* */)
183 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(8,gint8,int8,UINT8,/* */)
185 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,guint16,uint16_le,UINT16_LE,/* */)
186 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,guint16,uint16_be,UINT16_BE,/* */)
187 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,gint16,int16_le,UINT16_LE,/* */)
188 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,gint16,int16_be,UINT16_BE,/* */)
190 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,guint32,uint32_le,UINT32_LE,/* */)
191 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,guint32,uint32_be,UINT32_BE,/* */)
192 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gint32,int32_le,UINT32_LE,/* */)
193 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gint32,int32_be,UINT32_BE,/* */)
195 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,guint32,uint24_le,UINT24_LE,/* */)
196 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,guint32,uint24_be,UINT24_BE,/* */)
198 /* fix up the sign for 24-bit signed ints stored in 32-bit signed ints */
199 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,gint32,int24_le,UINT24_LE,
200 if (val & 0x00800000) val |= 0xff000000;)
201 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,gint32,int24_be,UINT24_BE,
202 if (val & 0x00800000) val |= 0xff000000;)
204 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,guint64,uint64_le,UINT64_LE,/* */)
205 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,guint64,uint64_be,UINT64_BE,/* */)
206 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gint64,int64_le,UINT64_LE,/* */)
207 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gint64,int64_be,UINT64_BE,/* */)
209 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gfloat,float32_le,FLOAT_LE,/* */)
210 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gfloat,float32_be,FLOAT_BE,/* */)
211 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gdouble,float64_le,DOUBLE_LE,/* */)
212 __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gdouble,float64_be,DOUBLE_BE,/* */)
214 #undef __GET_PEEK_BITS_UNCHECKED
216 static inline const guint8 *
217 gst_byte_reader_peek_data_unchecked (const GstByteReader * reader)
219 return (const guint8 *) (reader->data + reader->byte);
222 static inline const guint8 *
223 gst_byte_reader_get_data_unchecked (GstByteReader * reader, guint size)
227 data = gst_byte_reader_peek_data_unchecked (reader);
228 gst_byte_reader_skip_unchecked (reader, size);
232 static inline guint8 *
233 gst_byte_reader_dup_data_unchecked (GstByteReader * reader, guint size)
235 gconstpointer data = gst_byte_reader_get_data_unchecked (reader, size);
236 return (guint8 *) g_memdup (data, size);
239 /* Unchecked variants that should not be used */
241 _gst_byte_reader_get_pos_unchecked (const GstByteReader * reader)
247 _gst_byte_reader_get_remaining_unchecked (const GstByteReader * reader)
249 return reader->size - reader->byte;
253 _gst_byte_reader_get_size_unchecked (const GstByteReader * reader)
258 /* inlined variants (do not use directly) */
261 _gst_byte_reader_get_remaining_inline (const GstByteReader * reader)
263 g_return_val_if_fail (reader != NULL, 0);
265 return _gst_byte_reader_get_remaining_unchecked (reader);
269 _gst_byte_reader_get_size_inline (const GstByteReader * reader)
271 g_return_val_if_fail (reader != NULL, 0);
273 return _gst_byte_reader_get_size_unchecked (reader);
276 #define __GST_BYTE_READER_GET_PEEK_BITS_INLINE(bits,type,name) \
278 static inline gboolean \
279 _gst_byte_reader_peek_##name##_inline (const GstByteReader * reader, type * val) \
281 g_return_val_if_fail (reader != NULL, FALSE); \
282 g_return_val_if_fail (val != NULL, FALSE); \
284 if (_gst_byte_reader_get_remaining_unchecked (reader) < (bits / 8)) \
287 *val = gst_byte_reader_peek_##name##_unchecked (reader); \
291 static inline gboolean \
292 _gst_byte_reader_get_##name##_inline (GstByteReader * reader, type * val) \
294 g_return_val_if_fail (reader != NULL, FALSE); \
295 g_return_val_if_fail (val != NULL, FALSE); \
297 if (_gst_byte_reader_get_remaining_unchecked (reader) < (bits / 8)) \
300 *val = gst_byte_reader_get_##name##_unchecked (reader); \
304 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(8,guint8,uint8)
305 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(8,gint8,int8)
307 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,guint16,uint16_le)
308 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,guint16,uint16_be)
309 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,gint16,int16_le)
310 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,gint16,int16_be)
312 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,guint32,uint32_le)
313 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,guint32,uint32_be)
314 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gint32,int32_le)
315 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gint32,int32_be)
317 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,guint32,uint24_le)
318 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,guint32,uint24_be)
319 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,gint32,int24_le)
320 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,gint32,int24_be)
322 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,guint64,uint64_le)
323 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,guint64,uint64_be)
324 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gint64,int64_le)
325 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gint64,int64_be)
327 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gfloat,float32_le)
328 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gfloat,float32_be)
329 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gdouble,float64_le)
330 __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gdouble,float64_be)
332 #undef __GST_BYTE_READER_GET_PEEK_BITS_INLINE
334 #ifndef GST_BYTE_READER_DISABLE_INLINES
336 #define gst_byte_reader_get_remaining(reader) \
337 _gst_byte_reader_get_remaining_inline(reader)
339 #define gst_byte_reader_get_size(reader) \
340 _gst_byte_reader_get_size_inline(reader)
342 #define gst_byte_reader_get_pos(reader) \
343 _gst_byte_reader_get_pos_inline(reader)
345 /* we use defines here so we can add the G_LIKELY() */
346 #define gst_byte_reader_get_uint8(reader,val) \
347 G_LIKELY(_gst_byte_reader_get_uint8_inline(reader,val))
348 #define gst_byte_reader_get_int8(reader,val) \
349 G_LIKELY(_gst_byte_reader_get_int8_inline(reader,val))
350 #define gst_byte_reader_get_uint16_le(reader,val) \
351 G_LIKELY(_gst_byte_reader_get_uint16_le_inline(reader,val))
352 #define gst_byte_reader_get_int16_le(reader,val) \
353 G_LIKELY(_gst_byte_reader_get_int16_le_inline(reader,val))
354 #define gst_byte_reader_get_uint16_be(reader,val) \
355 G_LIKELY(_gst_byte_reader_get_uint16_be_inline(reader,val))
356 #define gst_byte_reader_get_int16_be(reader,val) \
357 G_LIKELY(_gst_byte_reader_get_int16_be_inline(reader,val))
358 #define gst_byte_reader_get_uint24_le(reader,val) \
359 G_LIKELY(_gst_byte_reader_get_uint24_le_inline(reader,val))
360 #define gst_byte_reader_get_int24_le(reader,val) \
361 G_LIKELY(_gst_byte_reader_get_int24_le_inline(reader,val))
362 #define gst_byte_reader_get_uint24_be(reader,val) \
363 G_LIKELY(_gst_byte_reader_get_uint24_be_inline(reader,val))
364 #define gst_byte_reader_get_int24_be(reader,val) \
365 G_LIKELY(_gst_byte_reader_get_int24_be_inline(reader,val))
366 #define gst_byte_reader_get_uint32_le(reader,val) \
367 G_LIKELY(_gst_byte_reader_get_uint32_le_inline(reader,val))
368 #define gst_byte_reader_get_int32_le(reader,val) \
369 G_LIKELY(_gst_byte_reader_get_int32_le_inline(reader,val))
370 #define gst_byte_reader_get_uint32_be(reader,val) \
371 G_LIKELY(_gst_byte_reader_get_uint32_be_inline(reader,val))
372 #define gst_byte_reader_get_int32_be(reader,val) \
373 G_LIKELY(_gst_byte_reader_get_int32_be_inline(reader,val))
374 #define gst_byte_reader_get_uint64_le(reader,val) \
375 G_LIKELY(_gst_byte_reader_get_uint64_le_inline(reader,val))
376 #define gst_byte_reader_get_int64_le(reader,val) \
377 G_LIKELY(_gst_byte_reader_get_int64_le_inline(reader,val))
378 #define gst_byte_reader_get_uint64_be(reader,val) \
379 G_LIKELY(_gst_byte_reader_get_uint64_be_inline(reader,val))
380 #define gst_byte_reader_get_int64_be(reader,val) \
381 G_LIKELY(_gst_byte_reader_get_int64_be_inline(reader,val))
383 #define gst_byte_reader_peek_uint8(reader,val) \
384 G_LIKELY(_gst_byte_reader_peek_uint8_inline(reader,val))
385 #define gst_byte_reader_peek_int8(reader,val) \
386 G_LIKELY(_gst_byte_reader_peek_int8_inline(reader,val))
387 #define gst_byte_reader_peek_uint16_le(reader,val) \
388 G_LIKELY(_gst_byte_reader_peek_uint16_le_inline(reader,val))
389 #define gst_byte_reader_peek_int16_le(reader,val) \
390 G_LIKELY(_gst_byte_reader_peek_int16_le_inline(reader,val))
391 #define gst_byte_reader_peek_uint16_be(reader,val) \
392 G_LIKELY(_gst_byte_reader_peek_uint16_be_inline(reader,val))
393 #define gst_byte_reader_peek_int16_be(reader,val) \
394 G_LIKELY(_gst_byte_reader_peek_int16_be_inline(reader,val))
395 #define gst_byte_reader_peek_uint24_le(reader,val) \
396 G_LIKELY(_gst_byte_reader_peek_uint24_le_inline(reader,val))
397 #define gst_byte_reader_peek_int24_le(reader,val) \
398 G_LIKELY(_gst_byte_reader_peek_int24_le_inline(reader,val))
399 #define gst_byte_reader_peek_uint24_be(reader,val) \
400 G_LIKELY(_gst_byte_reader_peek_uint24_be_inline(reader,val))
401 #define gst_byte_reader_peek_int24_be(reader,val) \
402 G_LIKELY(_gst_byte_reader_peek_int24_be_inline(reader,val))
403 #define gst_byte_reader_peek_uint32_le(reader,val) \
404 G_LIKELY(_gst_byte_reader_peek_uint32_le_inline(reader,val))
405 #define gst_byte_reader_peek_int32_le(reader,val) \
406 G_LIKELY(_gst_byte_reader_peek_int32_le_inline(reader,val))
407 #define gst_byte_reader_peek_uint32_be(reader,val) \
408 G_LIKELY(_gst_byte_reader_peek_uint32_be_inline(reader,val))
409 #define gst_byte_reader_peek_int32_be(reader,val) \
410 G_LIKELY(_gst_byte_reader_peek_int32_be_inline(reader,val))
411 #define gst_byte_reader_peek_uint64_le(reader,val) \
412 G_LIKELY(_gst_byte_reader_peek_uint64_le_inline(reader,val))
413 #define gst_byte_reader_peek_int64_le(reader,val) \
414 G_LIKELY(_gst_byte_reader_peek_int64_le_inline(reader,val))
415 #define gst_byte_reader_peek_uint64_be(reader,val) \
416 G_LIKELY(_gst_byte_reader_peek_uint64_be_inline(reader,val))
417 #define gst_byte_reader_peek_int64_be(reader,val) \
418 G_LIKELY(_gst_byte_reader_peek_int64_be_inline(reader,val))
420 #define gst_byte_reader_get_float32_le(reader,val) \
421 G_LIKELY(_gst_byte_reader_get_float32_le_inline(reader,val))
422 #define gst_byte_reader_get_float32_be(reader,val) \
423 G_LIKELY(_gst_byte_reader_get_float32_be_inline(reader,val))
424 #define gst_byte_reader_get_float64_le(reader,val) \
425 G_LIKELY(_gst_byte_reader_get_float64_le_inline(reader,val))
426 #define gst_byte_reader_get_float64_be(reader,val) \
427 G_LIKELY(_gst_byte_reader_get_float64_be_inline(reader,val))
428 #define gst_byte_reader_peek_float32_le(reader,val) \
429 G_LIKELY(_gst_byte_reader_peek_float32_le_inline(reader,val))
430 #define gst_byte_reader_peek_float32_be(reader,val) \
431 G_LIKELY(_gst_byte_reader_peek_float32_be_inline(reader,val))
432 #define gst_byte_reader_peek_float64_le(reader,val) \
433 G_LIKELY(_gst_byte_reader_peek_float64_le_inline(reader,val))
434 #define gst_byte_reader_peek_float64_be(reader,val) \
435 G_LIKELY(_gst_byte_reader_peek_float64_be_inline(reader,val))
437 #endif /* GST_BYTE_READER_DISABLE_INLINES */
439 static inline gboolean
440 _gst_byte_reader_dup_data_inline (GstByteReader * reader, guint size, guint8 ** val)
442 g_return_val_if_fail (reader != NULL, FALSE);
443 g_return_val_if_fail (val != NULL, FALSE);
445 if (G_UNLIKELY (size > reader->size || _gst_byte_reader_get_remaining_inline (reader) < size))
448 *val = gst_byte_reader_dup_data_unchecked (reader, size);
452 static inline gboolean
453 _gst_byte_reader_get_data_inline (GstByteReader * reader, guint size, const guint8 ** val)
455 g_return_val_if_fail (reader != NULL, FALSE);
456 g_return_val_if_fail (val != NULL, FALSE);
458 if (G_UNLIKELY (size > reader->size || _gst_byte_reader_get_remaining_inline (reader) < size))
461 *val = gst_byte_reader_get_data_unchecked (reader, size);
465 static inline gboolean
466 _gst_byte_reader_peek_data_inline (const GstByteReader * reader, guint size, const guint8 ** val)
468 g_return_val_if_fail (reader != NULL, FALSE);
469 g_return_val_if_fail (val != NULL, FALSE);
471 if (G_UNLIKELY (size > reader->size || _gst_byte_reader_get_remaining_inline (reader) < size))
474 *val = gst_byte_reader_peek_data_unchecked (reader);
479 _gst_byte_reader_get_pos_inline (const GstByteReader * reader)
481 g_return_val_if_fail (reader != NULL, 0);
483 return _gst_byte_reader_get_pos_unchecked (reader);
486 static inline gboolean
487 _gst_byte_reader_skip_inline (GstByteReader * reader, guint nbytes)
489 g_return_val_if_fail (reader != NULL, FALSE);
491 if (G_UNLIKELY (_gst_byte_reader_get_remaining_unchecked (reader) < nbytes))
494 reader->byte += nbytes;
498 #ifndef GST_BYTE_READER_DISABLE_INLINES
500 #define gst_byte_reader_dup_data(reader,size,val) \
501 G_LIKELY(_gst_byte_reader_dup_data_inline(reader,size,val))
502 #define gst_byte_reader_get_data(reader,size,val) \
503 G_LIKELY(_gst_byte_reader_get_data_inline(reader,size,val))
504 #define gst_byte_reader_peek_data(reader,size,val) \
505 G_LIKELY(_gst_byte_reader_peek_data_inline(reader,size,val))
506 #define gst_byte_reader_skip(reader,nbytes) \
507 G_LIKELY(_gst_byte_reader_skip_inline(reader,nbytes))
509 #endif /* GST_BYTE_READER_DISABLE_INLINES */
513 #endif /* __GST_BYTE_READER_H__ */