gstreamer_core/libs/gst/base/gstbytereader.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
     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 #include "gstbytereader.h"
       
    26 
       
    27 #include <string.h>
       
    28 
       
    29 /**
       
    30  * SECTION:gstbytereader
       
    31  * @short_description: Reads different integer, string and floating point
       
    32  *     types from a memory buffer
       
    33  *
       
    34  * #GstByteReader provides a byte reader that can read different integer and
       
    35  * floating point types from a memory buffer. It provides functions for reading
       
    36  * signed/unsigned, little/big endian integers of 8, 16, 24, 32 and 64 bits
       
    37  * and functions for reading little/big endian floating points numbers of
       
    38  * 32 and 64 bits. It also provides functions to read NUL-terminated strings
       
    39  * in various character encodings.
       
    40  */
       
    41 
       
    42 /**
       
    43  * gst_byte_reader_new:
       
    44  * @data: Data from which the #GstByteReader should read
       
    45  * @size: Size of @data in bytes
       
    46  *
       
    47  * Create a new #GstByteReader instance, which will read from @data.
       
    48  *
       
    49  * Returns: a new #GstByteReader instance
       
    50  *
       
    51  * Since: 0.10.22
       
    52  */
       
    53 #ifdef __SYMBIAN32__
       
    54 EXPORT_C
       
    55 #endif
       
    56 
       
    57 GstByteReader *
       
    58 gst_byte_reader_new (const guint8 * data, guint size)
       
    59 {
       
    60   GstByteReader *ret = g_slice_new0 (GstByteReader);
       
    61 
       
    62   ret->data = data;
       
    63   ret->size = size;
       
    64 
       
    65   return ret;
       
    66 }
       
    67 
       
    68 /**
       
    69  * gst_byte_reader_new_from_buffer:
       
    70  * @buffer: Buffer from which the #GstByteReader should read
       
    71  *
       
    72  * Create a new #GstByteReader instance, which will read from the
       
    73  * #GstBuffer @buffer.
       
    74  *
       
    75  * Returns: a new #GstByteReader instance
       
    76  *
       
    77  * Since: 0.10.22
       
    78  */
       
    79 #ifdef __SYMBIAN32__
       
    80 EXPORT_C
       
    81 #endif
       
    82 
       
    83 GstByteReader *
       
    84 gst_byte_reader_new_from_buffer (const GstBuffer * buffer)
       
    85 {
       
    86   g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
       
    87 
       
    88   return gst_byte_reader_new (GST_BUFFER_DATA (buffer),
       
    89       GST_BUFFER_SIZE (buffer));
       
    90 }
       
    91 
       
    92 /**
       
    93  * gst_byte_reader_free:
       
    94  * @reader: a #GstByteReader instance
       
    95  *
       
    96  * Frees a #GstByteReader instance, which was previously allocated by
       
    97  * gst_byte_reader_new() or gst_byte_reader_new_from_buffer().
       
    98  * 
       
    99  * Since: 0.10.22
       
   100  */
       
   101 #ifdef __SYMBIAN32__
       
   102 EXPORT_C
       
   103 #endif
       
   104 
       
   105 void
       
   106 gst_byte_reader_free (GstByteReader * reader)
       
   107 {
       
   108   g_return_if_fail (reader != NULL);
       
   109 
       
   110   g_slice_free (GstByteReader, reader);
       
   111 }
       
   112 
       
   113 /**
       
   114  * gst_byte_reader_init:
       
   115  * @reader: a #GstByteReader instance
       
   116  * @data: Data from which the #GstByteReader should read
       
   117  * @size: Size of @data in bytes
       
   118  *
       
   119  * Initializes a #GstByteReader instance to read from @data. This function
       
   120  * can be called on already initialized instances.
       
   121  * 
       
   122  * Since: 0.10.22
       
   123  */
       
   124 #ifdef __SYMBIAN32__
       
   125 EXPORT_C
       
   126 #endif
       
   127 
       
   128 void
       
   129 gst_byte_reader_init (GstByteReader * reader, const guint8 * data, guint size)
       
   130 {
       
   131   g_return_if_fail (reader != NULL);
       
   132 
       
   133   reader->data = data;
       
   134   reader->size = size;
       
   135   reader->byte = 0;
       
   136 }
       
   137 
       
   138 /**
       
   139  * gst_byte_reader_init_from_buffer:
       
   140  * @reader: a #GstByteReader instance
       
   141  * @buffer: Buffer from which the #GstByteReader should read
       
   142  *
       
   143  * Initializes a #GstByteReader instance to read from @buffer. This function
       
   144  * can be called on already initialized instances.
       
   145  * 
       
   146  * Since: 0.10.22
       
   147  */
       
   148 #ifdef __SYMBIAN32__
       
   149 EXPORT_C
       
   150 #endif
       
   151 
       
   152 void
       
   153 gst_byte_reader_init_from_buffer (GstByteReader * reader,
       
   154     const GstBuffer * buffer)
       
   155 {
       
   156   g_return_if_fail (GST_IS_BUFFER (buffer));
       
   157 
       
   158   gst_byte_reader_init (reader, GST_BUFFER_DATA (buffer),
       
   159       GST_BUFFER_SIZE (buffer));
       
   160 }
       
   161 
       
   162 /**
       
   163  * gst_byte_reader_set_pos:
       
   164  * @reader: a #GstByteReader instance
       
   165  * @pos: The new position in bytes
       
   166  *
       
   167  * Sets the new position of a #GstByteReader instance to @pos in bytes.
       
   168  *
       
   169  * Returns: %TRUE if the position could be set successfully, %FALSE
       
   170  * otherwise.
       
   171  * 
       
   172  * Since: 0.10.22
       
   173  */
       
   174 #ifdef __SYMBIAN32__
       
   175 EXPORT_C
       
   176 #endif
       
   177 
       
   178 gboolean
       
   179 gst_byte_reader_set_pos (GstByteReader * reader, guint pos)
       
   180 {
       
   181   g_return_val_if_fail (reader != NULL, FALSE);
       
   182 
       
   183   if (pos > reader->size)
       
   184     return FALSE;
       
   185 
       
   186   reader->byte = pos;
       
   187 
       
   188   return TRUE;
       
   189 }
       
   190 
       
   191 /**
       
   192  * gst_byte_reader_get_pos:
       
   193  * @reader: a #GstByteReader instance
       
   194  *
       
   195  * Returns the current position of a #GstByteReader instance in bytes.
       
   196  *
       
   197  * Returns: The current position of @reader in bytes.
       
   198  * 
       
   199  * Since: 0.10.22
       
   200  */
       
   201 #ifdef __SYMBIAN32__
       
   202 EXPORT_C
       
   203 #endif
       
   204 
       
   205 guint
       
   206 gst_byte_reader_get_pos (const GstByteReader * reader)
       
   207 {
       
   208   g_return_val_if_fail (reader != NULL, 0);
       
   209 
       
   210   return reader->byte;
       
   211 }
       
   212 
       
   213 /**
       
   214  * gst_byte_reader_get_remaining:
       
   215  * @reader: a #GstByteReader instance
       
   216  *
       
   217  * Returns the remaining number of bytes of a #GstByteReader instance.
       
   218  *
       
   219  * Returns: The remaining number of bytes of @reader instance.
       
   220  * 
       
   221  * Since: 0.10.22
       
   222  */
       
   223 #ifdef __SYMBIAN32__
       
   224 EXPORT_C
       
   225 #endif
       
   226 
       
   227 guint
       
   228 gst_byte_reader_get_remaining (const GstByteReader * reader)
       
   229 {
       
   230   g_return_val_if_fail (reader != NULL, 0);
       
   231 
       
   232   return reader->size - reader->byte;
       
   233 }
       
   234 
       
   235 /**
       
   236  * gst_byte_reader_skip:
       
   237  * @reader: a #GstByteReader instance
       
   238  * @nbytes: the number of bytes to skip
       
   239  *
       
   240  * Skips @nbytes bytes of the #GstByteReader instance.
       
   241  *
       
   242  * Returns: %TRUE if @nbytes bytes could be skipped, %FALSE otherwise.
       
   243  * 
       
   244  * Since: 0.10.22
       
   245  */
       
   246 #ifdef __SYMBIAN32__
       
   247 EXPORT_C
       
   248 #endif
       
   249 
       
   250 gboolean
       
   251 gst_byte_reader_skip (GstByteReader * reader, guint nbytes)
       
   252 {
       
   253   g_return_val_if_fail (reader != NULL, FALSE);
       
   254 
       
   255   if (gst_byte_reader_get_remaining (reader) < nbytes)
       
   256     return FALSE;
       
   257 
       
   258   reader->byte += nbytes;
       
   259 
       
   260   return TRUE;
       
   261 }
       
   262 
       
   263 /**
       
   264  * gst_byte_reader_get_uint8:
       
   265  * @reader: a #GstByteReader instance
       
   266  * @val: Pointer to a #guint8 to store the result
       
   267  *
       
   268  * Read an unsigned 8 bit integer into @val and update the current position.
       
   269  *
       
   270  * Returns: %TRUE if successful, %FALSE otherwise.
       
   271  * 
       
   272  * Since: 0.10.22
       
   273  */
       
   274 
       
   275 /**
       
   276  * gst_byte_reader_get_int8:
       
   277  * @reader: a #GstByteReader instance
       
   278  * @val: Pointer to a #gint8 to store the result
       
   279  *
       
   280  * Read a signed 8 bit integer into @val and update the current position.
       
   281  *
       
   282  * Returns: %TRUE if successful, %FALSE otherwise.
       
   283  * 
       
   284  * Since: 0.10.22
       
   285  */
       
   286 
       
   287 /**
       
   288  * gst_byte_reader_peek_uint8:
       
   289  * @reader: a #GstByteReader instance
       
   290  * @val: Pointer to a #guint8 to store the result
       
   291  *
       
   292  * Read a signed 8 bit integer into @val but keep the current position.
       
   293  *
       
   294  * Returns: %TRUE if successful, %FALSE otherwise.
       
   295  * 
       
   296  * Since: 0.10.22
       
   297  */
       
   298 
       
   299 /**
       
   300  * gst_byte_reader_peek_int8:
       
   301  * @reader: a #GstByteReader instance
       
   302  * @val: Pointer to a #gint8 to store the result
       
   303  *
       
   304  * Read a signed 8 bit integer into @val but keep the current position.
       
   305  *
       
   306  * Returns: %TRUE if successful, %FALSE otherwise.
       
   307  * 
       
   308  * Since: 0.10.22
       
   309  */
       
   310 
       
   311 /**
       
   312  * gst_byte_reader_get_uint16_le:
       
   313  * @reader: a #GstByteReader instance
       
   314  * @val: Pointer to a #guint16 to store the result
       
   315  *
       
   316  * Read an unsigned 16 bit little endian integer into @val
       
   317  * and update the current position.
       
   318  *
       
   319  * Returns: %TRUE if successful, %FALSE otherwise.
       
   320  * 
       
   321  * Since: 0.10.22
       
   322  */
       
   323 
       
   324 /**
       
   325  * gst_byte_reader_get_int16_le:
       
   326  * @reader: a #GstByteReader instance
       
   327  * @val: Pointer to a #gint16 to store the result
       
   328  *
       
   329  * Read a signed 16 bit little endian integer into @val
       
   330  * and update the current position.
       
   331  *
       
   332  * Returns: %TRUE if successful, %FALSE otherwise.
       
   333  * 
       
   334  * Since: 0.10.22
       
   335  */
       
   336 
       
   337 /**
       
   338  * gst_byte_reader_peek_uint16_le:
       
   339  * @reader: a #GstByteReader instance
       
   340  * @val: Pointer to a #guint16 to store the result
       
   341  *
       
   342  * Read a signed 16 bit little endian integer into @val
       
   343  * but keep the current position.
       
   344  *
       
   345  * Returns: %TRUE if successful, %FALSE otherwise.
       
   346  * 
       
   347  * Since: 0.10.22
       
   348  */
       
   349 
       
   350 /**
       
   351  * gst_byte_reader_peek_int16_le:
       
   352  * @reader: a #GstByteReader instance
       
   353  * @val: Pointer to a #gint16 to store the result
       
   354  *
       
   355  * Read a signed 16 bit little endian integer into @val
       
   356  * but keep the current position.
       
   357  *
       
   358  * Returns: %TRUE if successful, %FALSE otherwise.
       
   359  * 
       
   360  * Since: 0.10.22
       
   361  */
       
   362 
       
   363 /**
       
   364  * gst_byte_reader_get_uint16_be:
       
   365  * @reader: a #GstByteReader instance
       
   366  * @val: Pointer to a #guint16 to store the result
       
   367  *
       
   368  * Read an unsigned 16 bit big endian integer into @val
       
   369  * and update the current position.
       
   370  *
       
   371  * Returns: %TRUE if successful, %FALSE otherwise.
       
   372  * 
       
   373  * Since: 0.10.22
       
   374  */
       
   375 
       
   376 /**
       
   377  * gst_byte_reader_get_int16_be:
       
   378  * @reader: a #GstByteReader instance
       
   379  * @val: Pointer to a #gint16 to store the result
       
   380  *
       
   381  * Read a signed 16 bit big endian integer into @val
       
   382  * and update the current position.
       
   383  *
       
   384  * Returns: %TRUE if successful, %FALSE otherwise.
       
   385  * 
       
   386  * Since: 0.10.22
       
   387  */
       
   388 
       
   389 /**
       
   390  * gst_byte_reader_peek_uint16_be:
       
   391  * @reader: a #GstByteReader instance
       
   392  * @val: Pointer to a #guint16 to store the result
       
   393  *
       
   394  * Read a signed 16 bit big endian integer into @val
       
   395  * but keep the current position.
       
   396  *
       
   397  * Returns: %TRUE if successful, %FALSE otherwise.
       
   398  * 
       
   399  * Since: 0.10.22
       
   400  */
       
   401 
       
   402 /**
       
   403  * gst_byte_reader_peek_int16_be:
       
   404  * @reader: a #GstByteReader instance
       
   405  * @val: Pointer to a #gint16 to store the result
       
   406  *
       
   407  * Read a signed 16 bit big endian integer into @val
       
   408  * but keep the current position.
       
   409  *
       
   410  * Returns: %TRUE if successful, %FALSE otherwise.
       
   411  * 
       
   412  * Since: 0.10.22
       
   413  */
       
   414 
       
   415 /**
       
   416  * gst_byte_reader_get_uint24_le:
       
   417  * @reader: a #GstByteReader instance
       
   418  * @val: Pointer to a #guint32 to store the result
       
   419  *
       
   420  * Read an unsigned 24 bit little endian integer into @val
       
   421  * and update the current position.
       
   422  *
       
   423  * Returns: %TRUE if successful, %FALSE otherwise.
       
   424  * 
       
   425  * Since: 0.10.22
       
   426  */
       
   427 
       
   428 /**
       
   429  * gst_byte_reader_get_int24_le:
       
   430  * @reader: a #GstByteReader instance
       
   431  * @val: Pointer to a #gint32 to store the result
       
   432  *
       
   433  * Read a signed 24 bit little endian integer into @val
       
   434  * and update the current position.
       
   435  *
       
   436  * Returns: %TRUE if successful, %FALSE otherwise.
       
   437  * 
       
   438  * Since: 0.10.22
       
   439  */
       
   440 
       
   441 /**
       
   442  * gst_byte_reader_peek_uint24_le:
       
   443  * @reader: a #GstByteReader instance
       
   444  * @val: Pointer to a #guint32 to store the result
       
   445  *
       
   446  * Read a signed 24 bit little endian integer into @val
       
   447  * but keep the current position.
       
   448  *
       
   449  * Returns: %TRUE if successful, %FALSE otherwise.
       
   450  * 
       
   451  * Since: 0.10.22
       
   452  */
       
   453 
       
   454 /**
       
   455  * gst_byte_reader_peek_int24_le:
       
   456  * @reader: a #GstByteReader instance
       
   457  * @val: Pointer to a #gint32 to store the result
       
   458  *
       
   459  * Read a signed 24 bit little endian integer into @val
       
   460  * but keep the current position.
       
   461  *
       
   462  * Returns: %TRUE if successful, %FALSE otherwise.
       
   463  * 
       
   464  * Since: 0.10.22
       
   465  */
       
   466 
       
   467 /**
       
   468  * gst_byte_reader_get_uint24_be:
       
   469  * @reader: a #GstByteReader instance
       
   470  * @val: Pointer to a #guint32 to store the result
       
   471  *
       
   472  * Read an unsigned 24 bit big endian integer into @val
       
   473  * and update the current position.
       
   474  *
       
   475  * Returns: %TRUE if successful, %FALSE otherwise.
       
   476  * 
       
   477  * Since: 0.10.22
       
   478  */
       
   479 
       
   480 /**
       
   481  * gst_byte_reader_get_int24_be:
       
   482  * @reader: a #GstByteReader instance
       
   483  * @val: Pointer to a #gint32 to store the result
       
   484  *
       
   485  * Read a signed 24 bit big endian integer into @val
       
   486  * and update the current position.
       
   487  *
       
   488  * Returns: %TRUE if successful, %FALSE otherwise.
       
   489  * 
       
   490  * Since: 0.10.22
       
   491  */
       
   492 
       
   493 /**
       
   494  * gst_byte_reader_peek_uint24_be:
       
   495  * @reader: a #GstByteReader instance
       
   496  * @val: Pointer to a #guint32 to store the result
       
   497  *
       
   498  * Read a signed 24 bit big endian integer into @val
       
   499  * but keep the current position.
       
   500  *
       
   501  * Returns: %TRUE if successful, %FALSE otherwise.
       
   502  * 
       
   503  * Since: 0.10.22
       
   504  */
       
   505 
       
   506 /**
       
   507  * gst_byte_reader_peek_int24_be:
       
   508  * @reader: a #GstByteReader instance
       
   509  * @val: Pointer to a #gint32 to store the result
       
   510  *
       
   511  * Read a signed 24 bit big endian integer into @val
       
   512  * but keep the current position.
       
   513  *
       
   514  * Returns: %TRUE if successful, %FALSE otherwise.
       
   515  * 
       
   516  * Since: 0.10.22
       
   517  */
       
   518 
       
   519 
       
   520 /**
       
   521  * gst_byte_reader_get_uint32_le:
       
   522  * @reader: a #GstByteReader instance
       
   523  * @val: Pointer to a #guint32 to store the result
       
   524  *
       
   525  * Read an unsigned 32 bit little endian integer into @val
       
   526  * and update the current position.
       
   527  *
       
   528  * Returns: %TRUE if successful, %FALSE otherwise.
       
   529  * 
       
   530  * Since: 0.10.22
       
   531  */
       
   532 
       
   533 /**
       
   534  * gst_byte_reader_get_int32_le:
       
   535  * @reader: a #GstByteReader instance
       
   536  * @val: Pointer to a #gint32 to store the result
       
   537  *
       
   538  * Read a signed 32 bit little endian integer into @val
       
   539  * and update the current position.
       
   540  *
       
   541  * Returns: %TRUE if successful, %FALSE otherwise.
       
   542  * 
       
   543  * Since: 0.10.22
       
   544  */
       
   545 
       
   546 /**
       
   547  * gst_byte_reader_peek_uint32_le:
       
   548  * @reader: a #GstByteReader instance
       
   549  * @val: Pointer to a #guint32 to store the result
       
   550  *
       
   551  * Read a signed 32 bit little endian integer into @val
       
   552  * but keep the current position.
       
   553  *
       
   554  * Returns: %TRUE if successful, %FALSE otherwise.
       
   555  * 
       
   556  * Since: 0.10.22
       
   557  */
       
   558 
       
   559 /**
       
   560  * gst_byte_reader_peek_int32_le:
       
   561  * @reader: a #GstByteReader instance
       
   562  * @val: Pointer to a #gint32 to store the result
       
   563  *
       
   564  * Read a signed 32 bit little endian integer into @val
       
   565  * but keep the current position.
       
   566  *
       
   567  * Returns: %TRUE if successful, %FALSE otherwise.
       
   568  * 
       
   569  * Since: 0.10.22
       
   570  */
       
   571 
       
   572 /**
       
   573  * gst_byte_reader_get_uint32_be:
       
   574  * @reader: a #GstByteReader instance
       
   575  * @val: Pointer to a #guint32 to store the result
       
   576  *
       
   577  * Read an unsigned 32 bit big endian integer into @val
       
   578  * and update the current position.
       
   579  *
       
   580  * Returns: %TRUE if successful, %FALSE otherwise.
       
   581  * 
       
   582  * Since: 0.10.22
       
   583  */
       
   584 
       
   585 /**
       
   586  * gst_byte_reader_get_int32_be:
       
   587  * @reader: a #GstByteReader instance
       
   588  * @val: Pointer to a #gint32 to store the result
       
   589  *
       
   590  * Read a signed 32 bit big endian integer into @val
       
   591  * and update the current position.
       
   592  *
       
   593  * Returns: %TRUE if successful, %FALSE otherwise.
       
   594  * 
       
   595  * Since: 0.10.22
       
   596  */
       
   597 
       
   598 /**
       
   599  * gst_byte_reader_peek_uint32_be:
       
   600  * @reader: a #GstByteReader instance
       
   601  * @val: Pointer to a #guint32 to store the result
       
   602  *
       
   603  * Read a signed 32 bit big endian integer into @val
       
   604  * but keep the current position.
       
   605  *
       
   606  * Returns: %TRUE if successful, %FALSE otherwise.
       
   607  * 
       
   608  * Since: 0.10.22
       
   609  */
       
   610 
       
   611 /**
       
   612  * gst_byte_reader_peek_int32_be:
       
   613  * @reader: a #GstByteReader instance
       
   614  * @val: Pointer to a #gint32 to store the result
       
   615  *
       
   616  * Read a signed 32 bit big endian integer into @val
       
   617  * but keep the current position.
       
   618  *
       
   619  * Returns: %TRUE if successful, %FALSE otherwise.
       
   620  * 
       
   621  * Since: 0.10.22
       
   622  */
       
   623 
       
   624 /**
       
   625  * gst_byte_reader_get_uint64_le:
       
   626  * @reader: a #GstByteReader instance
       
   627  * @val: Pointer to a #guint64 to store the result
       
   628  *
       
   629  * Read an unsigned 64 bit little endian integer into @val
       
   630  * and update the current position.
       
   631  *
       
   632  * Returns: %TRUE if successful, %FALSE otherwise.
       
   633  * 
       
   634  * Since: 0.10.22
       
   635  */
       
   636 
       
   637 /**
       
   638  * gst_byte_reader_get_int64_le:
       
   639  * @reader: a #GstByteReader instance
       
   640  * @val: Pointer to a #gint64 to store the result
       
   641  *
       
   642  * Read a signed 64 bit little endian integer into @val
       
   643  * and update the current position.
       
   644  *
       
   645  * Returns: %TRUE if successful, %FALSE otherwise.
       
   646  * 
       
   647  * Since: 0.10.22
       
   648  */
       
   649 
       
   650 /**
       
   651  * gst_byte_reader_peek_uint64_le:
       
   652  * @reader: a #GstByteReader instance
       
   653  * @val: Pointer to a #guint64 to store the result
       
   654  *
       
   655  * Read a signed 64 bit little endian integer into @val
       
   656  * but keep the current position.
       
   657  *
       
   658  * Returns: %TRUE if successful, %FALSE otherwise.
       
   659  * 
       
   660  * Since: 0.10.22
       
   661  */
       
   662 
       
   663 /**
       
   664  * gst_byte_reader_peek_int64_le:
       
   665  * @reader: a #GstByteReader instance
       
   666  * @val: Pointer to a #gint64 to store the result
       
   667  *
       
   668  * Read a signed 64 bit little endian integer into @val
       
   669  * but keep the current position.
       
   670  *
       
   671  * Returns: %TRUE if successful, %FALSE otherwise.
       
   672  * 
       
   673  * Since: 0.10.22
       
   674  */
       
   675 
       
   676 /**
       
   677  * gst_byte_reader_get_uint64_be:
       
   678  * @reader: a #GstByteReader instance
       
   679  * @val: Pointer to a #guint64 to store the result
       
   680  *
       
   681  * Read an unsigned 64 bit big endian integer into @val
       
   682  * and update the current position.
       
   683  *
       
   684  * Returns: %TRUE if successful, %FALSE otherwise.
       
   685  * 
       
   686  * Since: 0.10.22
       
   687  */
       
   688 
       
   689 /**
       
   690  * gst_byte_reader_get_int64_be:
       
   691  * @reader: a #GstByteReader instance
       
   692  * @val: Pointer to a #gint64 to store the result
       
   693  *
       
   694  * Read a signed 64 bit big endian integer into @val
       
   695  * and update the current position.
       
   696  *
       
   697  * Returns: %TRUE if successful, %FALSE otherwise.
       
   698  * 
       
   699  * Since: 0.10.22
       
   700  */
       
   701 
       
   702 /**
       
   703  * gst_byte_reader_peek_uint64_be:
       
   704  * @reader: a #GstByteReader instance
       
   705  * @val: Pointer to a #guint64 to store the result
       
   706  *
       
   707  * Read a signed 64 bit big endian integer into @val
       
   708  * but keep the current position.
       
   709  *
       
   710  * Returns: %TRUE if successful, %FALSE otherwise.
       
   711  * 
       
   712  * Since: 0.10.22
       
   713  */
       
   714 
       
   715 /**
       
   716  * gst_byte_reader_peek_int64_be:
       
   717  * @reader: a #GstByteReader instance
       
   718  * @val: Pointer to a #gint64 to store the result
       
   719  *
       
   720  * Read a signed 64 bit big endian integer into @val
       
   721  * but keep the current position.
       
   722  *
       
   723  * Returns: %TRUE if successful, %FALSE otherwise.
       
   724  * 
       
   725  * Since: 0.10.22
       
   726  */
       
   727 
       
   728 #define GST_BYTE_READER_READ_INTS(bits) \
       
   729 __declspec(dllexport) gboolean \
       
   730 gst_byte_reader_get_uint##bits##_le (GstByteReader *reader, guint##bits *val) \
       
   731 { \
       
   732   g_return_val_if_fail (reader != NULL, FALSE); \
       
   733   g_return_val_if_fail (val != NULL, FALSE); \
       
   734   \
       
   735   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   736     return FALSE; \
       
   737   \
       
   738   *val = GST_READ_UINT##bits##_LE (&reader->data[reader->byte]); \
       
   739   reader->byte += bits / 8; \
       
   740   return TRUE; \
       
   741 } \
       
   742 \
       
   743 __declspec(dllexport) gboolean \
       
   744 gst_byte_reader_get_uint##bits##_be (GstByteReader *reader, guint##bits *val) \
       
   745 { \
       
   746   g_return_val_if_fail (reader != NULL, FALSE); \
       
   747   g_return_val_if_fail (val != NULL, FALSE); \
       
   748   \
       
   749   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   750     return FALSE; \
       
   751   \
       
   752   *val = GST_READ_UINT##bits##_BE (&reader->data[reader->byte]); \
       
   753   reader->byte += bits / 8; \
       
   754   return TRUE; \
       
   755 } \
       
   756 \
       
   757 __declspec(dllexport) gboolean \
       
   758 gst_byte_reader_get_int##bits##_le (GstByteReader *reader, gint##bits *val) \
       
   759 { \
       
   760   g_return_val_if_fail (reader != NULL, FALSE); \
       
   761   g_return_val_if_fail (val != NULL, FALSE); \
       
   762   \
       
   763   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   764     return FALSE; \
       
   765   \
       
   766   *val = GST_READ_UINT##bits##_LE (&reader->data[reader->byte]); \
       
   767   reader->byte += bits / 8; \
       
   768   return TRUE; \
       
   769 } \
       
   770 \
       
   771 __declspec(dllexport) gboolean \
       
   772 gst_byte_reader_get_int##bits##_be (GstByteReader *reader, gint##bits *val) \
       
   773 { \
       
   774   g_return_val_if_fail (reader != NULL, FALSE); \
       
   775   g_return_val_if_fail (val != NULL, FALSE); \
       
   776   \
       
   777   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   778     return FALSE; \
       
   779   \
       
   780   *val = GST_READ_UINT##bits##_BE (&reader->data[reader->byte]); \
       
   781   reader->byte += bits / 8; \
       
   782   return TRUE; \
       
   783 } \
       
   784 __declspec(dllexport) gboolean \
       
   785 gst_byte_reader_peek_uint##bits##_le (GstByteReader *reader, guint##bits *val) \
       
   786 { \
       
   787   g_return_val_if_fail (reader != NULL, FALSE); \
       
   788   g_return_val_if_fail (val != NULL, FALSE); \
       
   789   \
       
   790   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   791     return FALSE; \
       
   792   \
       
   793   *val = GST_READ_UINT##bits##_LE (&reader->data[reader->byte]); \
       
   794   return TRUE; \
       
   795 } \
       
   796 \
       
   797 __declspec(dllexport) gboolean \
       
   798 gst_byte_reader_peek_uint##bits##_be (GstByteReader *reader, guint##bits *val) \
       
   799 { \
       
   800   g_return_val_if_fail (reader != NULL, FALSE); \
       
   801   g_return_val_if_fail (val != NULL, FALSE); \
       
   802   \
       
   803   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   804     return FALSE; \
       
   805   \
       
   806   *val = GST_READ_UINT##bits##_BE (&reader->data[reader->byte]); \
       
   807   return TRUE; \
       
   808 } \
       
   809 \
       
   810 __declspec(dllexport) gboolean \
       
   811 gst_byte_reader_peek_int##bits##_le (GstByteReader *reader, gint##bits *val) \
       
   812 { \
       
   813   g_return_val_if_fail (reader != NULL, FALSE); \
       
   814   g_return_val_if_fail (val != NULL, FALSE); \
       
   815   \
       
   816   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   817     return FALSE; \
       
   818   \
       
   819   *val = GST_READ_UINT##bits##_LE (&reader->data[reader->byte]); \
       
   820   return TRUE; \
       
   821 } \
       
   822 \
       
   823 __declspec(dllexport) gboolean \
       
   824 gst_byte_reader_peek_int##bits##_be (GstByteReader *reader, gint##bits *val) \
       
   825 { \
       
   826   g_return_val_if_fail (reader != NULL, FALSE); \
       
   827   g_return_val_if_fail (val != NULL, FALSE); \
       
   828   \
       
   829   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
   830     return FALSE; \
       
   831   \
       
   832   *val = GST_READ_UINT##bits##_BE (&reader->data[reader->byte]); \
       
   833   return TRUE; \
       
   834 }
       
   835 
       
   836 
       
   837 GST_BYTE_READER_READ_INTS (16);
       
   838 GST_BYTE_READER_READ_INTS (32);
       
   839 GST_BYTE_READER_READ_INTS (64);
       
   840 #ifdef __SYMBIAN32__
       
   841 EXPORT_C
       
   842 #endif
       
   843 
       
   844 
       
   845 gboolean
       
   846 gst_byte_reader_get_uint8 (GstByteReader * reader, guint8 * val)
       
   847 {
       
   848   g_return_val_if_fail (reader != NULL, FALSE);
       
   849   g_return_val_if_fail (val != NULL, FALSE);
       
   850 
       
   851   if (reader->byte >= reader->size)
       
   852     return FALSE;
       
   853 
       
   854   *val = GST_READ_UINT8 (&reader->data[reader->byte]);
       
   855   reader->byte++;
       
   856   return TRUE;
       
   857 }
       
   858 #ifdef __SYMBIAN32__
       
   859 EXPORT_C
       
   860 #endif
       
   861 
       
   862 
       
   863 gboolean
       
   864 gst_byte_reader_get_int8 (GstByteReader * reader, gint8 * val)
       
   865 {
       
   866   g_return_val_if_fail (reader != NULL, FALSE);
       
   867   g_return_val_if_fail (val != NULL, FALSE);
       
   868 
       
   869   if (reader->byte >= reader->size)
       
   870     return FALSE;
       
   871 
       
   872   *val = GST_READ_UINT8 (&reader->data[reader->byte]);
       
   873   reader->byte++;
       
   874   return TRUE;
       
   875 }
       
   876 #ifdef __SYMBIAN32__
       
   877 EXPORT_C
       
   878 #endif
       
   879 
       
   880 
       
   881 gboolean
       
   882 gst_byte_reader_peek_uint8 (GstByteReader * reader, guint8 * val)
       
   883 {
       
   884   g_return_val_if_fail (reader != NULL, FALSE);
       
   885   g_return_val_if_fail (val != NULL, FALSE);
       
   886 
       
   887   if (reader->byte >= reader->size)
       
   888     return FALSE;
       
   889 
       
   890   *val = GST_READ_UINT8 (&reader->data[reader->byte]);
       
   891   return TRUE;
       
   892 }
       
   893 #ifdef __SYMBIAN32__
       
   894 EXPORT_C
       
   895 #endif
       
   896 
       
   897 
       
   898 gboolean
       
   899 gst_byte_reader_peek_int8 (GstByteReader * reader, gint8 * val)
       
   900 {
       
   901   g_return_val_if_fail (reader != NULL, FALSE);
       
   902   g_return_val_if_fail (val != NULL, FALSE);
       
   903 
       
   904   if (reader->byte >= reader->size)
       
   905     return FALSE;
       
   906 
       
   907   *val = GST_READ_UINT8 (&reader->data[reader->byte]);
       
   908   return TRUE;
       
   909 }
       
   910 #ifdef __SYMBIAN32__
       
   911 EXPORT_C
       
   912 #endif
       
   913 
       
   914 
       
   915 gboolean
       
   916 gst_byte_reader_get_uint24_le (GstByteReader * reader, guint32 * val)
       
   917 {
       
   918   g_return_val_if_fail (reader != NULL, FALSE);
       
   919   g_return_val_if_fail (val != NULL, FALSE);
       
   920 
       
   921   if (gst_byte_reader_get_remaining (reader) < 3)
       
   922     return FALSE;
       
   923 
       
   924   *val = GST_READ_UINT24_LE (&reader->data[reader->byte]);
       
   925   reader->byte += 3;
       
   926   return TRUE;
       
   927 }
       
   928 #ifdef __SYMBIAN32__
       
   929 EXPORT_C
       
   930 #endif
       
   931 
       
   932 
       
   933 gboolean
       
   934 gst_byte_reader_get_uint24_be (GstByteReader * reader, guint32 * val)
       
   935 {
       
   936   g_return_val_if_fail (reader != NULL, FALSE);
       
   937   g_return_val_if_fail (val != NULL, FALSE);
       
   938 
       
   939   if (gst_byte_reader_get_remaining (reader) < 3)
       
   940     return FALSE;
       
   941 
       
   942   *val = GST_READ_UINT24_BE (&reader->data[reader->byte]);
       
   943   reader->byte += 3;
       
   944   return TRUE;
       
   945 }
       
   946 #ifdef __SYMBIAN32__
       
   947 EXPORT_C
       
   948 #endif
       
   949 
       
   950 
       
   951 gboolean
       
   952 gst_byte_reader_get_int24_le (GstByteReader * reader, gint32 * val)
       
   953 {
       
   954   guint32 ret;
       
   955 
       
   956   g_return_val_if_fail (reader != NULL, FALSE);
       
   957   g_return_val_if_fail (val != NULL, FALSE);
       
   958 
       
   959   if (gst_byte_reader_get_remaining (reader) < 3)
       
   960     return FALSE;
       
   961 
       
   962   ret = GST_READ_UINT24_LE (&reader->data[reader->byte]);
       
   963   if (ret & 0x00800000)
       
   964     ret |= 0xff000000;
       
   965 
       
   966   reader->byte += 3;
       
   967 
       
   968   *val = ret;
       
   969   return TRUE;
       
   970 }
       
   971 #ifdef __SYMBIAN32__
       
   972 EXPORT_C
       
   973 #endif
       
   974 
       
   975 
       
   976 gboolean
       
   977 gst_byte_reader_get_int24_be (GstByteReader * reader, gint32 * val)
       
   978 {
       
   979   guint32 ret;
       
   980 
       
   981   g_return_val_if_fail (reader != NULL, FALSE);
       
   982   g_return_val_if_fail (val != NULL, FALSE);
       
   983 
       
   984   if (gst_byte_reader_get_remaining (reader) < 3)
       
   985     return FALSE;
       
   986 
       
   987   ret = GST_READ_UINT24_BE (&reader->data[reader->byte]);
       
   988   if (ret & 0x00800000)
       
   989     ret |= 0xff000000;
       
   990 
       
   991   reader->byte += 3;
       
   992 
       
   993   *val = ret;
       
   994   return TRUE;
       
   995 }
       
   996 #ifdef __SYMBIAN32__
       
   997 EXPORT_C
       
   998 #endif
       
   999 
       
  1000 
       
  1001 gboolean
       
  1002 gst_byte_reader_peek_uint24_le (GstByteReader * reader, guint32 * val)
       
  1003 {
       
  1004   g_return_val_if_fail (reader != NULL, FALSE);
       
  1005   g_return_val_if_fail (val != NULL, FALSE);
       
  1006 
       
  1007   if (gst_byte_reader_get_remaining (reader) < 3)
       
  1008     return FALSE;
       
  1009 
       
  1010   *val = GST_READ_UINT24_LE (&reader->data[reader->byte]);
       
  1011   return TRUE;
       
  1012 }
       
  1013 #ifdef __SYMBIAN32__
       
  1014 EXPORT_C
       
  1015 #endif
       
  1016 
       
  1017 
       
  1018 gboolean
       
  1019 gst_byte_reader_peek_uint24_be (GstByteReader * reader, guint32 * val)
       
  1020 {
       
  1021   g_return_val_if_fail (reader != NULL, FALSE);
       
  1022   g_return_val_if_fail (val != NULL, FALSE);
       
  1023 
       
  1024   if (gst_byte_reader_get_remaining (reader) < 3)
       
  1025     return FALSE;
       
  1026 
       
  1027   *val = GST_READ_UINT24_BE (&reader->data[reader->byte]);
       
  1028   return TRUE;
       
  1029 }
       
  1030 #ifdef __SYMBIAN32__
       
  1031 EXPORT_C
       
  1032 #endif
       
  1033 
       
  1034 
       
  1035 gboolean
       
  1036 gst_byte_reader_peek_int24_le (GstByteReader * reader, gint32 * val)
       
  1037 {
       
  1038   guint32 ret;
       
  1039 
       
  1040   g_return_val_if_fail (reader != NULL, FALSE);
       
  1041   g_return_val_if_fail (val != NULL, FALSE);
       
  1042 
       
  1043   if (gst_byte_reader_get_remaining (reader) < 3)
       
  1044     return FALSE;
       
  1045 
       
  1046   ret = GST_READ_UINT24_LE (&reader->data[reader->byte]);
       
  1047   if (ret & 0x00800000)
       
  1048     ret |= 0xff000000;
       
  1049 
       
  1050   *val = ret;
       
  1051   return TRUE;
       
  1052 }
       
  1053 #ifdef __SYMBIAN32__
       
  1054 EXPORT_C
       
  1055 #endif
       
  1056 
       
  1057 
       
  1058 gboolean
       
  1059 gst_byte_reader_peek_int24_be (GstByteReader * reader, gint32 * val)
       
  1060 {
       
  1061   guint32 ret;
       
  1062 
       
  1063   g_return_val_if_fail (reader != NULL, FALSE);
       
  1064   g_return_val_if_fail (val != NULL, FALSE);
       
  1065 
       
  1066   if (gst_byte_reader_get_remaining (reader) < 3)
       
  1067     return FALSE;
       
  1068 
       
  1069   ret = GST_READ_UINT24_BE (&reader->data[reader->byte]);
       
  1070   if (ret & 0x00800000)
       
  1071     ret |= 0xff000000;
       
  1072 
       
  1073   *val = ret;
       
  1074   return TRUE;
       
  1075 }
       
  1076 
       
  1077 /**
       
  1078  * gst_byte_reader_get_float32_le:
       
  1079  * @reader: a #GstByteReader instance
       
  1080  * @val: Pointer to a #gfloat to store the result
       
  1081  *
       
  1082  * Read a 32 bit little endian integer into @val
       
  1083  * and update the current position.
       
  1084  *
       
  1085  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1086  * 
       
  1087  * Since: 0.10.22
       
  1088  */
       
  1089 
       
  1090 /**
       
  1091  * gst_byte_reader_peek_float32_le:
       
  1092  * @reader: a #GstByteReader instance
       
  1093  * @val: Pointer to a #gfloat to store the result
       
  1094  *
       
  1095  * Read a 32 bit little endian integer into @val
       
  1096  * but keep the current position.
       
  1097  *
       
  1098  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1099  * 
       
  1100  * Since: 0.10.22
       
  1101  */
       
  1102 
       
  1103 /**
       
  1104  * gst_byte_reader_get_float32_be:
       
  1105  * @reader: a #GstByteReader instance
       
  1106  * @val: Pointer to a #gfloat to store the result
       
  1107  *
       
  1108  * Read a 32 bit big endian integer into @val
       
  1109  * and update the current position.
       
  1110  *
       
  1111  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1112  * 
       
  1113  * Since: 0.10.22
       
  1114  */
       
  1115 
       
  1116 /**
       
  1117  * gst_byte_reader_peek_float32_be:
       
  1118  * @reader: a #GstByteReader instance
       
  1119  * @val: Pointer to a #gfloat to store the result
       
  1120  *
       
  1121  * Read a 32 bit big endian integer into @val
       
  1122  * but keep the current position.
       
  1123  *
       
  1124  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1125  * 
       
  1126  * Since: 0.10.22
       
  1127  */
       
  1128 
       
  1129 /**
       
  1130  * gst_byte_reader_get_float64_le:
       
  1131  * @reader: a #GstByteReader instance
       
  1132  * @val: Pointer to a #gdouble to store the result
       
  1133  *
       
  1134  * Read a 64 bit little endian integer into @val
       
  1135  * and update the current position.
       
  1136  *
       
  1137  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1138  * 
       
  1139  * Since: 0.10.22
       
  1140  */
       
  1141 
       
  1142 /**
       
  1143  * gst_byte_reader_peek_float64_le:
       
  1144  * @reader: a #GstByteReader instance
       
  1145  * @val: Pointer to a #gdouble to store the result
       
  1146  *
       
  1147  * Read a 64 bit little endian integer into @val
       
  1148  * but keep the current position.
       
  1149  *
       
  1150  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1151  * 
       
  1152  * Since: 0.10.22
       
  1153  */
       
  1154 
       
  1155 /**
       
  1156  * gst_byte_reader_get_float64_be:
       
  1157  * @reader: a #GstByteReader instance
       
  1158  * @val: Pointer to a #gdouble to store the result
       
  1159  *
       
  1160  * Read a 64 bit big endian integer into @val
       
  1161  * and update the current position.
       
  1162  *
       
  1163  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1164  * 
       
  1165  * Since: 0.10.22
       
  1166  */
       
  1167 
       
  1168 /**
       
  1169  * gst_byte_reader_peek_float64_be:
       
  1170  * @reader: a #GstByteReader instance
       
  1171  * @val: Pointer to a #gdouble to store the result
       
  1172  *
       
  1173  * Read a 64 bit big endian integer into @val
       
  1174  * but keep the current position.
       
  1175  *
       
  1176  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1177  * 
       
  1178  * Since: 0.10.22
       
  1179  */
       
  1180 
       
  1181 #define GST_BYTE_READER_READ_FLOATS(bits, type, TYPE) \
       
  1182     __declspec(dllexport) gboolean \
       
  1183 gst_byte_reader_get_float##bits##_le (GstByteReader *reader, g##type *val) \
       
  1184 { \
       
  1185   g_return_val_if_fail (reader != NULL, FALSE); \
       
  1186   g_return_val_if_fail (val != NULL, FALSE); \
       
  1187   \
       
  1188   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
  1189     return FALSE; \
       
  1190   \
       
  1191   *val = GST_READ_##TYPE##_LE (&reader->data[reader->byte]); \
       
  1192   reader->byte += bits / 8; \
       
  1193   return TRUE; \
       
  1194 } \
       
  1195 __declspec(dllexport) gboolean \
       
  1196 gst_byte_reader_get_float##bits##_be (GstByteReader *reader, g##type *val) \
       
  1197 { \
       
  1198   g_return_val_if_fail (reader != NULL, FALSE); \
       
  1199   g_return_val_if_fail (val != NULL, FALSE); \
       
  1200   \
       
  1201   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
  1202     return FALSE; \
       
  1203   \
       
  1204   *val = GST_READ_##TYPE##_BE (&reader->data[reader->byte]); \
       
  1205   reader->byte += bits / 8; \
       
  1206   return TRUE; \
       
  1207 } \
       
  1208 __declspec(dllexport) gboolean \
       
  1209 gst_byte_reader_peek_float##bits##_le (GstByteReader *reader, g##type *val) \
       
  1210 { \
       
  1211   g_return_val_if_fail (reader != NULL, FALSE); \
       
  1212   g_return_val_if_fail (val != NULL, FALSE); \
       
  1213   \
       
  1214   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
  1215     return FALSE; \
       
  1216   \
       
  1217   *val = GST_READ_##TYPE##_LE (&reader->data[reader->byte]); \
       
  1218   return TRUE; \
       
  1219 } \
       
  1220 __declspec(dllexport) gboolean \
       
  1221 gst_byte_reader_peek_float##bits##_be (GstByteReader *reader, g##type *val) \
       
  1222 { \
       
  1223   g_return_val_if_fail (reader != NULL, FALSE); \
       
  1224   g_return_val_if_fail (val != NULL, FALSE); \
       
  1225   \
       
  1226   if (gst_byte_reader_get_remaining (reader) < bits / 8) \
       
  1227     return FALSE; \
       
  1228   \
       
  1229   *val = GST_READ_##TYPE##_BE (&reader->data[reader->byte]); \
       
  1230   return TRUE; \
       
  1231 }
       
  1232 
       
  1233 GST_BYTE_READER_READ_FLOATS (32, float, FLOAT);
       
  1234 GST_BYTE_READER_READ_FLOATS (64, double, DOUBLE);
       
  1235 
       
  1236 /**
       
  1237  * gst_byte_reader_get_data:
       
  1238  * @reader: a #GstByteReader instance
       
  1239  * @size: Size in bytes
       
  1240  * @val: Pointer to a #guint8 to store the result
       
  1241  *
       
  1242  * Returns a constant pointer to the current data
       
  1243  * position if at least @size bytes are left and
       
  1244  * updates the current position.
       
  1245  *
       
  1246  *
       
  1247  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1248  * 
       
  1249  * Since: 0.10.22
       
  1250  */
       
  1251 #ifdef __SYMBIAN32__
       
  1252 EXPORT_C
       
  1253 #endif
       
  1254 
       
  1255 gboolean
       
  1256 gst_byte_reader_get_data (GstByteReader * reader, guint size,
       
  1257     const guint8 ** val)
       
  1258 {
       
  1259   g_return_val_if_fail (reader != NULL, FALSE);
       
  1260   g_return_val_if_fail (val != NULL, FALSE);
       
  1261 
       
  1262   if (gst_byte_reader_get_remaining (reader) < size)
       
  1263     return FALSE;
       
  1264 
       
  1265   *val = reader->data + reader->byte;
       
  1266   reader->byte += size;
       
  1267   return TRUE;
       
  1268 }
       
  1269 
       
  1270 /**
       
  1271  * gst_byte_reader_peek_data:
       
  1272  * @reader: a #GstByteReader instance
       
  1273  * @size: Size in bytes
       
  1274  * @val: Pointer to a #guint8 to store the result
       
  1275  *
       
  1276  * Returns a constant pointer to the current data
       
  1277  * position if at least @size bytes are left and
       
  1278  * keeps the current position.
       
  1279  *
       
  1280  *
       
  1281  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1282  * 
       
  1283  * Since: 0.10.22
       
  1284  */
       
  1285 #ifdef __SYMBIAN32__
       
  1286 EXPORT_C
       
  1287 #endif
       
  1288 
       
  1289 gboolean
       
  1290 gst_byte_reader_peek_data (GstByteReader * reader, guint size,
       
  1291     const guint8 ** val)
       
  1292 {
       
  1293   g_return_val_if_fail (reader != NULL, FALSE);
       
  1294   g_return_val_if_fail (val != NULL, FALSE);
       
  1295 
       
  1296   if (gst_byte_reader_get_remaining (reader) < size)
       
  1297     return FALSE;
       
  1298 
       
  1299   *val = reader->data + reader->byte;
       
  1300   return TRUE;
       
  1301 }
       
  1302 
       
  1303 /**
       
  1304  * gst_byte_reader_dup_data:
       
  1305  * @reader: a #GstByteReader instance
       
  1306  * @size: Size in bytes
       
  1307  * @val: Pointer to a #guint8 to store the result
       
  1308  *
       
  1309  * Returns a newly-allocated copy of the current data
       
  1310  * position if at least @size bytes are left and
       
  1311  * updates the current position.
       
  1312  *
       
  1313  * Returns: %TRUE if successful, %FALSE otherwise.
       
  1314  *
       
  1315  * Since: 0.10.24
       
  1316  */
       
  1317 #ifdef __SYMBIAN32__
       
  1318 EXPORT_C
       
  1319 #endif
       
  1320 
       
  1321 gboolean
       
  1322 gst_byte_reader_dup_data (GstByteReader * reader, guint size, guint8 ** val)
       
  1323 {
       
  1324   const guint8 *cval = NULL;
       
  1325 
       
  1326   if (!gst_byte_reader_get_data (reader, size, &cval))
       
  1327     return FALSE;
       
  1328 
       
  1329   *val = g_memdup (cval, size);
       
  1330   return TRUE;
       
  1331 }
       
  1332 
       
  1333 /**
       
  1334  * gst_byte_reader_masked_scan_uint32:
       
  1335  * @reader: a #GstByteReader
       
  1336  * @mask: mask to apply to data before matching against @pattern
       
  1337  * @pattern: pattern to match (after mask is applied)
       
  1338  * @offset: offset from which to start scanning, relative to the current
       
  1339  *     position
       
  1340  * @size: number of bytes to scan from offset
       
  1341  *
       
  1342  * Scan for pattern @pattern with applied mask @mask in the byte reader data,
       
  1343  * starting from offset @offset relative to the current position.
       
  1344  *
       
  1345  * The bytes in @pattern and @mask are interpreted left-to-right, regardless
       
  1346  * of endianness.  All four bytes of the pattern must be present in the
       
  1347  * byte reader data for it to match, even if the first or last bytes are masked
       
  1348  * out.
       
  1349  *
       
  1350  * It is an error to call this function without making sure that there is
       
  1351  * enough data (offset+size bytes) in the byte reader.
       
  1352  *
       
  1353  * Returns: offset of the first match, or -1 if no match was found.
       
  1354  *
       
  1355  * Example:
       
  1356  * <programlisting>
       
  1357  * // Assume the reader contains 0x00 0x01 0x02 ... 0xfe 0xff
       
  1358  *
       
  1359  * gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 0, 256);
       
  1360  * // -> returns 0
       
  1361  * gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 1, 255);
       
  1362  * // -> returns -1
       
  1363  * gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x01020304, 1, 255);
       
  1364  * // -> returns 1
       
  1365  * gst_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0001, 0, 256);
       
  1366  * // -> returns -1
       
  1367  * gst_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0203, 0, 256);
       
  1368  * // -> returns 0
       
  1369  * gst_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 256);
       
  1370  * // -> returns 2
       
  1371  * gst_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 4);
       
  1372  * // -> returns -1
       
  1373  * </programlisting>
       
  1374  *
       
  1375  * Since: 0.10.24
       
  1376  */
       
  1377 #ifdef __SYMBIAN32__
       
  1378 EXPORT_C
       
  1379 #endif
       
  1380 
       
  1381 guint
       
  1382 gst_byte_reader_masked_scan_uint32 (GstByteReader * reader, guint32 mask,
       
  1383     guint32 pattern, guint offset, guint size)
       
  1384 {
       
  1385   const guint8 *data;
       
  1386   guint32 state;
       
  1387   guint i;
       
  1388 
       
  1389   g_return_val_if_fail (size > 0, -1);
       
  1390   g_return_val_if_fail ((guint64) offset + size <= reader->size - reader->byte,
       
  1391       -1);
       
  1392 
       
  1393   /* we can't find the pattern with less than 4 bytes */
       
  1394   if (G_UNLIKELY (size < 4))
       
  1395     return -1;
       
  1396 
       
  1397   data = reader->data + reader->byte + offset;
       
  1398 
       
  1399   /* set the state to something that does not match */
       
  1400   state = ~pattern;
       
  1401 
       
  1402   /* now find data */
       
  1403   for (i = 0; i < size; i++) {
       
  1404     /* throw away one byte and move in the next byte */
       
  1405     state = ((state << 8) | data[i]);
       
  1406     if (G_UNLIKELY ((state & mask) == pattern)) {
       
  1407       /* we have a match but we need to have skipped at
       
  1408        * least 4 bytes to fill the state. */
       
  1409       if (G_LIKELY (i >= 3))
       
  1410         return offset + i - 3;
       
  1411     }
       
  1412   }
       
  1413 
       
  1414   /* nothing found */
       
  1415   return -1;
       
  1416 }
       
  1417 
       
  1418 #define GST_BYTE_READER_SCAN_STRING(bits) \
       
  1419 static guint \
       
  1420 gst_byte_reader_scan_string_utf##bits (GstByteReader * reader) \
       
  1421 { \
       
  1422   guint len, off, max_len; \
       
  1423   \
       
  1424   max_len = (reader->size - reader->byte) / sizeof (guint##bits); \
       
  1425   \
       
  1426   /* need at least a single NUL terminator */ \
       
  1427   if (max_len < 1) \
       
  1428     return 0; \
       
  1429   \
       
  1430   len = 0; \
       
  1431   off = reader->byte; \
       
  1432   /* endianness does not matter if we are looking for a NUL terminator */ \
       
  1433   while (GST_READ_UINT##bits##_LE (&reader->data[off]) != 0) { \
       
  1434     ++len; \
       
  1435     off += sizeof (guint##bits); \
       
  1436     /* have we reached the end without finding a NUL terminator? */ \
       
  1437     if (len == max_len) \
       
  1438       return 0; \
       
  1439   } \
       
  1440   /* return size in bytes including the NUL terminator (hence the +1) */ \
       
  1441   return (len + 1) * sizeof (guint##bits); \
       
  1442 }
       
  1443 
       
  1444 #define GST_READ_UINT8_LE GST_READ_UINT8
       
  1445 GST_BYTE_READER_SCAN_STRING (8);
       
  1446 #undef GST_READ_UINT8_LE
       
  1447 GST_BYTE_READER_SCAN_STRING (16);
       
  1448 GST_BYTE_READER_SCAN_STRING (32);
       
  1449 
       
  1450 #define GST_BYTE_READER_SKIP_STRING(bits) \
       
  1451 __declspec(dllexport) gboolean \
       
  1452 gst_byte_reader_skip_string_utf##bits (GstByteReader * reader) \
       
  1453 { \
       
  1454   guint size; /* size in bytes including the terminator */ \
       
  1455   \
       
  1456   g_return_val_if_fail (reader != NULL, FALSE); \
       
  1457   \
       
  1458   size = gst_byte_reader_scan_string_utf##bits (reader); \
       
  1459   reader->byte += size; \
       
  1460   return (size > 0); \
       
  1461 }
       
  1462 
       
  1463 /**
       
  1464  * gst_byte_reader_skip_string:
       
  1465  * @reader: a #GstByteReader instance
       
  1466  *
       
  1467  * Skips a NUL-terminated string in the #GstByteReader instance, advancing
       
  1468  * the current position to the byte after the string. This will work for
       
  1469  * any NUL-terminated string with a character width of 8 bits, so ASCII,
       
  1470  * UTF-8, ISO-8859-N etc.
       
  1471  *
       
  1472  * This function will fail if no NUL-terminator was found in in the data.
       
  1473  *
       
  1474  * Returns: %TRUE if a string could be skipped, %FALSE otherwise.
       
  1475  *
       
  1476  * Since: 0.10.24
       
  1477  */
       
  1478 /**
       
  1479  * gst_byte_reader_skip_string_utf8:
       
  1480  * @reader: a #GstByteReader instance
       
  1481  *
       
  1482  * Skips a NUL-terminated string in the #GstByteReader instance, advancing
       
  1483  * the current position to the byte after the string. This will work for
       
  1484  * any NUL-terminated string with a character width of 8 bits, so ASCII,
       
  1485  * UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done.
       
  1486  *
       
  1487  * This function will fail if no NUL-terminator was found in in the data.
       
  1488  *
       
  1489  * Returns: %TRUE if a string could be skipped, %FALSE otherwise.
       
  1490  *
       
  1491  * Since: 0.10.24
       
  1492  */
       
  1493 GST_BYTE_READER_SKIP_STRING (8);
       
  1494 
       
  1495 /**
       
  1496  * gst_byte_reader_skip_string_utf16:
       
  1497  * @reader: a #GstByteReader instance
       
  1498  *
       
  1499  * Skips a NUL-terminated UTF-16 string in the #GstByteReader instance,
       
  1500  * advancing the current position to the byte after the string.
       
  1501  *
       
  1502  * No input checking for valid UTF-16 is done.
       
  1503  *
       
  1504  * This function will fail if no NUL-terminator was found in in the data.
       
  1505  *
       
  1506  * Returns: %TRUE if a string could be skipped, %FALSE otherwise.
       
  1507  *
       
  1508  * Since: 0.10.24
       
  1509  */
       
  1510 GST_BYTE_READER_SKIP_STRING (16);
       
  1511 
       
  1512 /**
       
  1513  * gst_byte_reader_skip_string_utf32:
       
  1514  * @reader: a #GstByteReader instance
       
  1515  *
       
  1516  * Skips a NUL-terminated UTF-32 string in the #GstByteReader instance,
       
  1517  * advancing the current position to the byte after the string.
       
  1518  *
       
  1519  * No input checking for valid UTF-32 is done.
       
  1520  *
       
  1521  * This function will fail if no NUL-terminator was found in in the data.
       
  1522  *
       
  1523  * Returns: %TRUE if a string could be skipped, %FALSE otherwise.
       
  1524  *
       
  1525  * Since: 0.10.24
       
  1526  */
       
  1527 GST_BYTE_READER_SKIP_STRING (32);
       
  1528 
       
  1529 /**
       
  1530  * gst_byte_reader_peek_string:
       
  1531  * @reader: a #GstByteReader instance
       
  1532  * @str: Pointer to a #gchar to store the result
       
  1533  *
       
  1534  * Returns a constant pointer to the current data position if there is
       
  1535  * a NUL-terminated string in the data (this could be just a NUL terminator).
       
  1536  * The current position will be maintained. This will work for any
       
  1537  * NUL-terminated string with a character width of 8 bits, so ASCII,
       
  1538  * UTF-8, ISO-8859-N etc.
       
  1539  *
       
  1540  * This function will fail if no NUL-terminator was found in in the data.
       
  1541  *
       
  1542  * Returns: %TRUE if a string could be skipped, %FALSE otherwise.
       
  1543  *
       
  1544  * Since: 0.10.24
       
  1545  */
       
  1546 /**
       
  1547  * gst_byte_reader_peek_string_utf8:
       
  1548  * @reader: a #GstByteReader instance
       
  1549  * @str: Pointer to a #gchar to store the result
       
  1550  *
       
  1551  * Returns a constant pointer to the current data position if there is
       
  1552  * a NUL-terminated string in the data (this could be just a NUL terminator).
       
  1553  * The current position will be maintained. This will work for any
       
  1554  * NUL-terminated string with a character width of 8 bits, so ASCII,
       
  1555  * UTF-8, ISO-8859-N etc.
       
  1556  *
       
  1557  * No input checking for valid UTF-8 is done.
       
  1558  *
       
  1559  * This function will fail if no NUL-terminator was found in in the data.
       
  1560  *
       
  1561  * Returns: %TRUE if a string could be skipped, %FALSE otherwise.
       
  1562  *
       
  1563  * Since: 0.10.24
       
  1564  */
       
  1565 #ifdef __SYMBIAN32__
       
  1566 EXPORT_C
       
  1567 #endif
       
  1568 
       
  1569 gboolean
       
  1570 gst_byte_reader_peek_string_utf8 (GstByteReader * reader, const gchar ** str)
       
  1571 {
       
  1572   g_return_val_if_fail (reader != NULL, FALSE);
       
  1573   g_return_val_if_fail (str != NULL, FALSE);
       
  1574 
       
  1575   if (gst_byte_reader_scan_string_utf8 (reader) > 0) {
       
  1576     *str = (const gchar *) (reader->data + reader->byte);
       
  1577   } else {
       
  1578     *str = NULL;
       
  1579   }
       
  1580   return (*str != NULL);
       
  1581 }
       
  1582 
       
  1583 /**
       
  1584  * gst_byte_reader_get_string_utf8:
       
  1585  * @reader: a #GstByteReader instance
       
  1586  * @str: Pointer to a #gchar to store the result
       
  1587  *
       
  1588  * Returns a constant pointer to the current data position if there is
       
  1589  * a NUL-terminated string in the data (this could be just a NUL terminator),
       
  1590  * advancing the current position to the byte after the string. This will work
       
  1591  * for any NUL-terminated string with a character width of 8 bits, so ASCII,
       
  1592  * UTF-8, ISO-8859-N etc.
       
  1593  *
       
  1594  * No input checking for valid UTF-8 is done.
       
  1595  *
       
  1596  * This function will fail if no NUL-terminator was found in in the data.
       
  1597  *
       
  1598  * Returns: %TRUE if a string could be found, %FALSE otherwise.
       
  1599  *
       
  1600  * Since: 0.10.24
       
  1601  */
       
  1602 #ifdef __SYMBIAN32__
       
  1603 EXPORT_C
       
  1604 #endif
       
  1605 
       
  1606 gboolean
       
  1607 gst_byte_reader_get_string_utf8 (GstByteReader * reader, const gchar ** str)
       
  1608 {
       
  1609   guint size;                   /* size in bytes including the terminator */
       
  1610 
       
  1611   g_return_val_if_fail (reader != NULL, FALSE);
       
  1612   g_return_val_if_fail (str != NULL, FALSE);
       
  1613 
       
  1614   size = gst_byte_reader_scan_string_utf8 (reader);
       
  1615   if (size == 0) {
       
  1616     *str = NULL;
       
  1617     return FALSE;
       
  1618   }
       
  1619 
       
  1620   *str = (const gchar *) (reader->data + reader->byte);
       
  1621   reader->byte += size;
       
  1622   return TRUE;
       
  1623 }
       
  1624 
       
  1625 #define GST_BYTE_READER_DUP_STRING(bits,type) \
       
  1626 __declspec(dllexport) gboolean \
       
  1627 gst_byte_reader_dup_string_utf##bits (GstByteReader * reader, type ** str) \
       
  1628 { \
       
  1629   guint size; /* size in bytes including the terminator */ \
       
  1630   \
       
  1631   g_return_val_if_fail (reader != NULL, FALSE); \
       
  1632   g_return_val_if_fail (str != NULL, FALSE); \
       
  1633   \
       
  1634   size = gst_byte_reader_scan_string_utf##bits (reader); \
       
  1635   if (size == 0) { \
       
  1636     *str = NULL; \
       
  1637     return FALSE; \
       
  1638   } \
       
  1639   *str = g_memdup (reader->data + reader->byte, size); \
       
  1640   reader->byte += size; \
       
  1641   return TRUE; \
       
  1642 }
       
  1643 
       
  1644 /**
       
  1645  * gst_byte_reader_dup_string_utf8:
       
  1646  * @reader: a #GstByteReader instance
       
  1647  * @str: address of a string pointer to store the result
       
  1648  *
       
  1649  * FIXME:Reads (copies) a NUL-terminated string in the #GstByteReader instance,
       
  1650  * advancing the current position to the byte after the string. This will work
       
  1651  * for any NUL-terminated string with a character width of 8 bits, so ASCII,
       
  1652  * UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done.
       
  1653  *
       
  1654  * This function will fail if no NUL-terminator was found in in the data.
       
  1655  *
       
  1656  * Returns: %TRUE if a string could be read into @str, %FALSE otherwise. The
       
  1657  *     string put into @str must be freed with g_free() when no longer needed.
       
  1658  *
       
  1659  * Since: 0.10.24
       
  1660  */
       
  1661 GST_BYTE_READER_DUP_STRING (8, gchar);
       
  1662 
       
  1663 /**
       
  1664  * gst_byte_reader_dup_string_utf16:
       
  1665  * @reader: a #GstByteReader instance
       
  1666  * @str: address of a #guint16 pointer to store the result
       
  1667  *
       
  1668  * Returns a newly-allocated copy of the current data position if there is
       
  1669  * a NUL-terminated UTF-16 string in the data (this could be an empty string
       
  1670  * as well), and advances the current position.
       
  1671  *
       
  1672  * No input checking for valid UTF-16 is done. This function is endianness
       
  1673  * agnostic - you should not assume the UTF-16 characters are in host
       
  1674  * endianness.
       
  1675  *
       
  1676  * This function will fail if no NUL-terminator was found in in the data.
       
  1677  *
       
  1678  * Note: there is no peek or get variant of this function to ensure correct
       
  1679  * byte alignment of the UTF-16 string.
       
  1680  *
       
  1681  * Returns: %TRUE if a string could be read, %FALSE otherwise. The
       
  1682  *     string put into @str must be freed with g_free() when no longer needed.
       
  1683  *
       
  1684  * Since: 0.10.24
       
  1685  */
       
  1686 GST_BYTE_READER_DUP_STRING (16, guint16);
       
  1687 
       
  1688 /**
       
  1689  * gst_byte_reader_dup_string_utf32:
       
  1690  * @reader: a #GstByteReader instance
       
  1691  * @str: address of a #guint32 pointer to store the result
       
  1692  *
       
  1693  * Returns a newly-allocated copy of the current data position if there is
       
  1694  * a NUL-terminated UTF-32 string in the data (this could be an empty string
       
  1695  * as well), and advances the current position.
       
  1696  *
       
  1697  * No input checking for valid UTF-32 is done. This function is endianness
       
  1698  * agnostic - you should not assume the UTF-32 characters are in host
       
  1699  * endianness.
       
  1700  *
       
  1701  * This function will fail if no NUL-terminator was found in in the data.
       
  1702  *
       
  1703  * Note: there is no peek or get variant of this function to ensure correct
       
  1704  * byte alignment of the UTF-32 string.
       
  1705  *
       
  1706  * Returns: %TRUE if a string could be read, %FALSE otherwise. The
       
  1707  *     string put into @str must be freed with g_free() when no longer needed.
       
  1708  *
       
  1709  * Since: 0.10.24
       
  1710  */
       
  1711 GST_BYTE_READER_DUP_STRING (32, guint32);