mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
codecparsers: Move shared code to a parser utils file
This commit is contained in:
parent
fbe30dd2ea
commit
4439048e4a
5 changed files with 171 additions and 107 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
57
gst-libs/gst/codecparsers/parserutils.c
Normal file
57
gst-libs/gst/codecparsers/parserutils.c
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
108
gst-libs/gst/codecparsers/parserutils.h
Normal file
108
gst-libs/gst/codecparsers/parserutils.h
Normal file
|
@ -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__ */
|
Loading…
Reference in a new issue