1 /* Gstreamer 2 * Copyright (C) <2011> Intel 3 * Copyright (C) <2011> Collabora Ltd. 4 * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com> 5 * 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. 10 * 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. 15 * 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. 20 */ 21 22 #ifndef __PARSER_UTILS__ 23 #define __PARSER_UTILS__ 24 25 #include <gst/gst.h> 26 #include <gst/base/gstbitreader.h> 27 28 /* Parsing utils */ 29 #define GET_BITS(b, num, bits) G_STMT_START { \ 30 if (!gst_bit_reader_get_bits_uint32(b, bits, num)) \ 31 goto failed; \ 32 GST_TRACE ("parsed %d bits: %d", num, *(bits)); \ 33 } G_STMT_END 34 35 #define CHECK_ALLOWED(val, min, max) G_STMT_START { \ 36 if (val < min || val > max) { \ 37 GST_WARNING ("value not in allowed range. value: %d, range %d-%d", \ 38 val, min, max); \ 39 goto failed; \ 40 } \ 41 } G_STMT_END 42 43 #define READ_UINT8(reader, val, nbits) G_STMT_START { \ 44 if (!gst_bit_reader_get_bits_uint8 (reader, &val, nbits)) { \ 45 GST_WARNING ("failed to read uint8, nbits: %d", nbits); \ 46 goto failed; \ 47 } \ 48 } G_STMT_END 49 50 #define READ_UINT16(reader, val, nbits) G_STMT_START { \ 51 if (!gst_bit_reader_get_bits_uint16 (reader, &val, nbits)) { \ 52 GST_WARNING ("failed to read uint16, nbits: %d", nbits); \ 53 goto failed; \ 54 } \ 55 } G_STMT_END 56 57 #define READ_UINT32(reader, val, nbits) G_STMT_START { \ 58 if (!gst_bit_reader_get_bits_uint32 (reader, &val, nbits)) { \ 59 GST_WARNING ("failed to read uint32, nbits: %d", nbits); \ 60 goto failed; \ 61 } \ 62 } G_STMT_END 63 64 #define READ_UINT64(reader, val, nbits) G_STMT_START { \ 65 if (!gst_bit_reader_get_bits_uint64 (reader, &val, nbits)) { \ 66 GST_WARNING ("failed to read uint64, nbits: %d", nbits); \ 67 goto failed; \ 68 } \ 69 } G_STMT_END 70 71 72 #define U_READ_UINT8(reader, val, nbits) G_STMT_START { \ 73 val = gst_bit_reader_get_bits_uint8_unchecked (reader, nbits); \ 74 } G_STMT_END 75 76 #define U_READ_UINT16(reader, val, nbits) G_STMT_START { \ 77 val = gst_bit_reader_get_bits_uint16_unchecked (reader, nbits); \ 78 } G_STMT_END 79 80 #define U_READ_UINT32(reader, val, nbits) G_STMT_START { \ 81 val = gst_bit_reader_get_bits_uint32_unchecked (reader, nbits); \ 82 } G_STMT_END 83 84 #define U_READ_UINT64(reader, val, nbits) G_STMT_START { \ 85 val = gst_bit_reader_get_bits_uint64_unchecked (reader, nbits); \ 86 } G_STMT_END 87 88 #define SKIP(reader, nbits) G_STMT_START { \ 89 if (!gst_bit_reader_skip (reader, nbits)) { \ 90 GST_WARNING ("failed to skip nbits: %d", nbits); \ 91 goto failed; \ 92 } \ 93 } G_STMT_END 94 95 typedef struct _VLCTable VLCTable; 96 97 struct _VLCTable 98 { 99 guint value; 100 guint cword; 101 guint cbits; 102 }; 103 104 G_GNUC_INTERNAL gboolean 105 decode_vlc (GstBitReader * br, guint * res, const VLCTable * table, 106 guint length); 107 108 #endif /* __PARSER_UTILS__ */ 109