summaryrefslogtreecommitdiff
path: root/gst-libs
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@collabora.com>2011-09-21 19:40:47 -0300
committerThibault Saunier <thibault.saunier@collabora.com>2011-11-28 21:25:34 -0300
commit4439048e4a14e65732ac44db6dbc321da3945837 (patch)
treede884e9efa85cdca468090ce66c873f63bc5f53b /gst-libs
parentfbe30dd2eac83679a6efd36ea0531766876c81b7 (diff)
codecparsers: Move shared code to a parser utils file
Diffstat (limited to 'gst-libs')
-rw-r--r--gst-libs/gst/codecparsers/Makefile.am4
-rw-r--r--gst-libs/gst/codecparsers/gstmpegvideoparser.c28
-rw-r--r--gst-libs/gst/codecparsers/gstvc1parser.c81
-rw-r--r--gst-libs/gst/codecparsers/parserutils.c57
-rw-r--r--gst-libs/gst/codecparsers/parserutils.h108
5 files changed, 171 insertions, 107 deletions
diff --git a/gst-libs/gst/codecparsers/Makefile.am b/gst-libs/gst/codecparsers/Makefile.am
index c3dfe9307..f65311dad 100644
--- a/gst-libs/gst/codecparsers/Makefile.am
+++ b/gst-libs/gst/codecparsers/Makefile.am
@@ -1,11 +1,13 @@
lib_LTLIBRARIES = libgstcodecparsers-@GST_MAJORMINOR@.la
libgstcodecparsers_@GST_MAJORMINOR@_la_SOURCES = \
- gstmpegvideoparser.c gsth264parser.c gstvc1parser.c
+ gstmpegvideoparser.c gsth264parser.c gstvc1parser.c parserutils.c
libgstcodecparsers_@GST_MAJORMINOR@includedir = \
$(includedir)/gstreamer-@GST_MAJORMINOR@/gst/codecparsers
+noinst_HEADERS = parserutils.h
+
libgstcodecparsers_@GST_MAJORMINOR@include_HEADERS = \
gstmpegvideoparser.h gsth264parser.h gstvc1parser.h
diff --git a/gst-libs/gst/codecparsers/gstmpegvideoparser.c b/gst-libs/gst/codecparsers/gstmpegvideoparser.c
index 85d8b1d63..bcec01aaa 100644
--- a/gst-libs/gst/codecparsers/gstmpegvideoparser.c
+++ b/gst-libs/gst/codecparsers/gstmpegvideoparser.c
@@ -40,6 +40,7 @@
#endif
#include "gstmpegvideoparser.h"
+#include "parserutils.h"
#include <string.h>
#include <gst/base/gstbitreader.h>
@@ -47,33 +48,6 @@
#define MARKER_BIT 0x1
-#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 READ_UINT8(br, val, nbits) G_STMT_START { \
- if (!gst_bit_reader_get_bits_uint8 (br, &val, nbits)) { \
- GST_WARNING ("failed to read uint8, nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
-#define READ_UINT16(br, val, nbits) G_STMT_START { \
- if (!gst_bit_reader_get_bits_uint16 (br, &val, nbits)) { \
- GST_WARNING ("failed to read uint16, nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
-#define READ_UINT32(br, val, nbits) G_STMT_START { \
- if (!gst_bit_reader_get_bits_uint32 (br, &val, nbits)) { \
- GST_WARNING ("failed to read uint32, nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
/* default intra quant matrix, in zig-zag order */
const guint8 default_intra_quantizer_matrix[64] = {
8,
diff --git a/gst-libs/gst/codecparsers/gstvc1parser.c b/gst-libs/gst/codecparsers/gstvc1parser.c
index 7407b5585..b88b0d09a 100644
--- a/gst-libs/gst/codecparsers/gstvc1parser.c
+++ b/gst-libs/gst/codecparsers/gstvc1parser.c
@@ -33,6 +33,7 @@
#endif
#include "gstvc1parser.h"
+#include "parserutils.h"
#include <gst/base/gstbytereader.h>
#include <gst/base/gstbitreader.h>
#include <string.h>
@@ -64,49 +65,6 @@ ensure_debug_category (void)
#endif /* GST_DISABLE_GST_DEBUG */
-/* ------------------------------------------------------------------------- */
-
-#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 READ_UINT8(br, val, nbits) G_STMT_START { \
- if (!gst_bit_reader_get_bits_uint8 (br, &val, nbits)) { \
- GST_WARNING ("failed to read uint8, nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
-#define READ_UINT16(br, val, nbits) G_STMT_START { \
- if (!gst_bit_reader_get_bits_uint16 (br, &val, nbits)) { \
- GST_WARNING ("failed to read uint16, nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
-#define READ_UINT32(br, val, nbits) G_STMT_START { \
- if (!gst_bit_reader_get_bits_uint32 (br, &val, nbits)) { \
- GST_WARNING ("failed to read uint32, nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
-#define SKIP(br, nbits) G_STMT_START { \
- if (!gst_bit_reader_skip (br, nbits)) { \
- GST_WARNING ("Failed to skip nbits: %d", nbits); \
- goto failed; \
- } \
-} G_STMT_END
-
-typedef struct _VLCTable
-{
- guint value;
- guint cword;
- guint cbits;
-} VLCTable;
-
const guint8 vc1_pquant_table[3][32] = {
{ /* Implicit quantizer */
0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
@@ -468,41 +426,6 @@ failed:
}
}
-static gboolean
-decode_vlc (GstBitReader * br, guint * res, const VLCTable * table,
- guint length)
-{
- guint8 i;
- guint cbits = 0;
- guint32 value = 0;
-
- for (i = 0; i < length; i++) {
- if (cbits != table[i].cbits) {
- cbits = table[i].cbits;
- if (!gst_bit_reader_peek_bits_uint32 (br, &value, cbits)) {
- goto failed;
- }
- }
-
- if (value == table[i].cword) {
- SKIP (br, cbits);
- if (res)
- *res = table[i].value;
-
- return TRUE;
- }
- }
-
- GST_DEBUG ("Did not find code");
-
-failed:
- {
- GST_WARNING ("Could not decode VLC returning");
-
- return FALSE;
- }
-}
-
/*** bitplanes decoding ***/
static gboolean
bitplane_decoding (GstBitReader * br, guint8 * data,
@@ -1807,7 +1730,7 @@ gst_vc1_parse_sequence_layer (const guint8 * data, gsize size,
READ_UINT32 (&br, tmp, 32);
if (tmp != 0x04)
goto failed;
-
+
if (parse_sequence_header_struct_c (&br, &seqlayer->struct_c) ==
GST_VC1_PARSER_ERROR)
goto failed;
diff --git a/gst-libs/gst/codecparsers/parserutils.c b/gst-libs/gst/codecparsers/parserutils.c
new file mode 100644
index 000000000..a31fe48f5
--- /dev/null
+++ b/gst-libs/gst/codecparsers/parserutils.c
@@ -0,0 +1,57 @@
+/* Gstreamer
+ * Copyright (C) <2011> Intel Corporation
+ * 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.
+ */
+
+#include "parserutils.h"
+
+gboolean
+decode_vlc (GstBitReader * br, guint * res, const VLCTable * table,
+ guint length)
+{
+ guint8 i;
+ guint cbits = 0;
+ guint32 value = 0;
+
+ for (i = 0; i < length; i++) {
+ if (cbits != table[i].cbits) {
+ cbits = table[i].cbits;
+ if (!gst_bit_reader_peek_bits_uint32 (br, &value, cbits)) {
+ goto failed;
+ }
+ }
+
+ if (value == table[i].cword) {
+ SKIP (br, cbits);
+ if (res)
+ *res = table[i].value;
+
+ return TRUE;
+ }
+ }
+
+ GST_DEBUG ("Did not find code");
+
+failed:
+ {
+ GST_WARNING ("Could not decode VLC returning");
+
+ return FALSE;
+ }
+}
diff --git a/gst-libs/gst/codecparsers/parserutils.h b/gst-libs/gst/codecparsers/parserutils.h
new file mode 100644
index 000000000..009b250cf
--- /dev/null
+++ b/gst-libs/gst/codecparsers/parserutils.h
@@ -0,0 +1,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__ */