summaryrefslogtreecommitdiff
path: root/gst-libs/gst/codecparsers/parserutils.h
blob: 009b250cf8554276c721a66c3ca49baef26f25f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Gstreamer
 * Copyright (C) <2011> Intel
 * Copyright (C) <2011> Collabora Ltd.
 * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __PARSER_UTILS__
#define __PARSER_UTILS__

#include <gst/gst.h>
#include <gst/base/gstbitreader.h>

/* Parsing utils */
#define GET_BITS(b, num, bits) G_STMT_START {        \
  if (!gst_bit_reader_get_bits_uint32(b, bits, num)) \
    goto failed;                                     \
  GST_TRACE ("parsed %d bits: %d", num, *(bits));    \
} G_STMT_END

#define CHECK_ALLOWED(val, min, max) G_STMT_START { \
  if (val < min || val > max) { \
    GST_WARNING ("value not in allowed range. value: %d, range %d-%d", \
                     val, min, max); \
    goto failed; \
  } \
} G_STMT_END

#define READ_UINT8(reader, val, nbits) G_STMT_START { \
  if (!gst_bit_reader_get_bits_uint8 (reader, &val, nbits)) { \
    GST_WARNING ("failed to read uint8, nbits: %d", nbits); \
    goto failed; \
  } \
} G_STMT_END

#define READ_UINT16(reader, val, nbits) G_STMT_START { \
  if (!gst_bit_reader_get_bits_uint16 (reader, &val, nbits)) { \
    GST_WARNING ("failed to read uint16, nbits: %d", nbits); \
    goto failed; \
  } \
} G_STMT_END

#define READ_UINT32(reader, val, nbits) G_STMT_START { \
  if (!gst_bit_reader_get_bits_uint32 (reader, &val, nbits)) { \
    GST_WARNING ("failed to read uint32, nbits: %d", nbits); \
    goto failed; \
  } \
} G_STMT_END

#define READ_UINT64(reader, val, nbits) G_STMT_START { \
  if (!gst_bit_reader_get_bits_uint64 (reader, &val, nbits)) { \
    GST_WARNING ("failed to read uint64, nbits: %d", nbits); \
    goto failed; \
  } \
} G_STMT_END


#define U_READ_UINT8(reader, val, nbits) G_STMT_START { \
  val = gst_bit_reader_get_bits_uint8_unchecked (reader, nbits); \
} G_STMT_END

#define U_READ_UINT16(reader, val, nbits) G_STMT_START { \
  val = gst_bit_reader_get_bits_uint16_unchecked (reader, nbits); \
} G_STMT_END

#define U_READ_UINT32(reader, val, nbits) G_STMT_START { \
  val = gst_bit_reader_get_bits_uint32_unchecked (reader, nbits); \
} G_STMT_END

#define U_READ_UINT64(reader, val, nbits) G_STMT_START { \
  val = gst_bit_reader_get_bits_uint64_unchecked (reader, nbits); \
} G_STMT_END

#define SKIP(reader, nbits) G_STMT_START { \
  if (!gst_bit_reader_skip (reader, nbits)) { \
    GST_WARNING ("failed to skip nbits: %d", nbits); \
    goto failed; \
  } \
} G_STMT_END

typedef struct _VLCTable VLCTable;

struct _VLCTable
{
  guint value;
  guint cword;
  guint cbits;
};

gboolean
decode_vlc (GstBitReader * br, guint * res, const VLCTable * table,
    guint length);

#endif /* __PARSER_UTILS__ */