Commit c64b9933 authored by Thibault Saunier's avatar Thibault Saunier Committed by Edward Hervey

codecparsers: mpeg: Add an mpeg video bitstream parsing library

Create a new codecparsers library
parent 4ca79463
......@@ -1946,6 +1946,7 @@ gst-libs/gst/Makefile
gst-libs/gst/basecamerabinsrc/Makefile
gst-libs/gst/interfaces/Makefile
gst-libs/gst/signalprocessor/Makefile
gst-libs/gst/codecparsers/Makefile
gst-libs/gst/video/Makefile
sys/Makefile
sys/dshowdecwrapper/Makefile
......
......@@ -20,6 +20,16 @@
package.
</para>
<xi:include href="compiling.sgml" />
<chapter id="codecparsers">
<title>Bitstream parsing Library</title>
<para>
This library should be linked to by getting cflags and libs from
<filename>gstreamer-plugins-bad-&GST_MAJORMINOR;.pc</filename> and adding
<filename>-lgscodeparsers-&GST_MAJORMINOR;</filename> to the library flags.
</para>
<xi:include href="xml/gstmpegvideoparser.xml" />
</chapter>
</part>
<part id="gstreamer-libs-hierarchy">
......
# codecparsers
<SECTION>
<FILE>gstmpegvideoparser</FILE>
<TITLE>mpegvideoparser</TITLE>
<INCLUDE>gst/codecparsers/gstmpegvideoparser.h</INCLUDE>
GstMpegVideoPacketTypeCode
GstMpegVideoPacketExtensionCode
GstMpegVideoLevel
GstMpegVideoProfile
GstMpegVideoPictureType
GstMpegVideoPictureStructure
GstMpegVideoSequenceHdr
GstMpegVideoSequenceExt
GstMpegVideoPictureHdr
GstMpegVideoGop
GstMpegVideoPictureExt
GstMpegVideoQuantMatrixExt
GstMpegVideoTypeOffsetSize
gst_mpeg_video_parse
gst_mpeg_video_parse_sequence_header
gst_mpeg_video_parse_picture_header
gst_mpeg_video_parse_picture_extension
gst_mpeg_video_parse_gop
gst_mpeg_video_parse_sequence_extension
gst_mpeg_video_parse_quant_matrix_extension
<SUBSECTION Standard>
<SUBSECTION Private>
</SECTION>
#include <gst/gst.h>
#include <gst/codecparsers/gstmpegvideoparser.h>
SUBDIRS = interfaces signalprocessor video basecamerabinsrc
SUBDIRS = interfaces signalprocessor video basecamerabinsrc codecparsers
noinst_HEADERS = gst-i18n-plugin.h gettext.h
DIST_SUBDIRS = interfaces signalprocessor video basecamerabinsrc
DIST_SUBDIRS = interfaces signalprocessor video basecamerabinsrc codecparsers
lib_LTLIBRARIES = libgstcodecparsers-@GST_MAJORMINOR@.la
libgstcodecparsers_@GST_MAJORMINOR@_la_SOURCES = gstmpegvideoparser.c
libgstcodecparsers_@GST_MAJORMINOR@includedir = \
$(includedir)/gstreamer-@GST_MAJORMINOR@/gst/codecparsers
libgstcodecparsers_@GST_MAJORMINOR@include_HEADERS = \
gstmpegvideoparser.h
libgstcodecparsers_@GST_MAJORMINOR@_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS)
libgstcodecparsers_@GST_MAJORMINOR@_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS)
libgstcodecparsers_@GST_MAJORMINOR@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)
Android.mk: $(BUILT_SOURCES) Makefile.am
androgenizer -:PROJECT libgstcodecparsers -:STATIC libgstcodecparsers-@GST_MAJORMINOR@ \
-:TAGS eng debug \
-:REL_TOP $(top_srcdir) -:ABS_TOP $(abs_top_srcdir) \
-:SOURCES $(libgstcodecparsers_@GST_MAJORMINOR@_la_SOURCES) \
$(built_sources) \
-:CFLAGS $(DEFS) $(libgstcodecparsers_@GST_MAJORMINOR@_la_CFLAGS) \
-:LDFLAGS $(libgstcodecparsers_@GST_MAJORMINOR@_la_LDFLAGS) \
$(libgstcodecparsers@GST_MAJORMINOR@_la_LIBADD) \
-ldl \
-:HEADER_TARGET gstreamer-@GST_MAJORMINOR@/gst/codecparsers \
-:HEADERS $(libgstcodecparsersinclude_HEADERS) \
$(built_headers) \
-:PASSTHROUGH LOCAL_ARM_MODE:=arm \
> $@
This diff is collapsed.
This diff is collapsed.
......@@ -204,6 +204,7 @@ make ERROR_CFLAGS='' ERROR_CXXFLAGS=''
%{_libdir}/libgstbasevideo-%{majorminor}.so.*
%{_libdir}/libgstphotography-%{majorminor}.so.*
%{_libdir}/libgstsignalprocessor-%{majorminor}.so.*
%{_libdir}/libgstcodecparsers-%{majorminor}.so.*
# Plugins without external dependencies
%{_libdir}/gstreamer-%{majorminor}/libgstadpcmdec.so
%{_libdir}/gstreamer-%{majorminor}/libgstadpcmenc.so
......@@ -329,8 +330,10 @@ make ERROR_CFLAGS='' ERROR_CXXFLAGS=''
%{_libdir}/libgstbasevideo-%{majorminor}.so
%{_libdir}/libgstphotography-%{majorminor}.so
%{_libdir}/libgstsignalprocessor-%{majorminor}.so
%{_libdir}/libgstcodecparsers-%{majorminor}.so
%{_libdir}/libgstbasecamerabinsrc-%{majorminor}.so
%{_includedir}/gstreamer-%{majorminor}/gst/interfaces/photography*
%{_includedir}/gstreamer-%{majorminor}/gst/codecparsers
%{_includedir}/gstreamer-%{majorminor}/gst/signalprocessor
%{_includedir}/gstreamer-%{majorminor}/gst/video
%{_includedir}/gstreamer-%{majorminor}/gst/basecamerabinsrc/gstbasecamerasrc.h
......
......@@ -7,6 +7,7 @@ Name: GStreamer Bad Plugin libraries
Description: Currently includes the photography interface library
Requires: gstreamer-@GST_MAJORMINOR@ gstreamer-base-@GST_MAJORMINOR@
Version: @VERSION@
Libs: -L${libdir} -lgstphotography-@GST_MAJORMINOR@
Libs: -L${libdir} -lgstphotography-@GST_MAJORMINOR@\
-L${libdir} -lgstcodecparsers-@GST_MAJORMINOR@\
Cflags: -I${includedir}
......@@ -183,6 +183,7 @@ check_PROGRAMS = \
pipelines/colorspace \
$(check_mimic) \
elements/rtpmux \
libs/mpegvideoparser \
$(check_schro) \
$(check_vp8) \
elements/viewfinderbin \
......@@ -214,6 +215,15 @@ elements_h263parse_LDADD = libparser.la $(LDADD)
elements_h264parse_LDADD = libparser.la $(LDADD)
libs_mpegvideoparser_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(AM_CFLAGS)
libs_mpegvideoparser_LDADD = \
$(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-@GST_MAJORMINOR@.la \
$(GST_PLUGINS_BAD_LIBS) -lgstcodecparsers-@GST_MAJORMINOR@ \
$(GST_BASE_LIBS) $(GST_LIBS) $(LDADD)
elements_voaacenc_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(AM_CFLAGS)
......
/* 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 <gst/check/gstcheck.h>
#include <gst/codecparsers/gstmpegvideoparser.h>
/* actually seq + gop */
static guint8 mpeg2_seq[] = {
0x00, 0x00, 0x01, 0xb3, 0x02, 0x00, 0x18, 0x15, 0xff, 0xff, 0xe0, 0x28,
0x00, 0x00, 0x01, 0xb3, 0x78, 0x04, 0x38, 0x37, 0xff, 0xff, 0xf0, 0x00,
0x00, 0x00, 0x01, 0xb5, 0x14, 0x8a, 0x00, 0x11, 0x03, 0x71,
0x00, 0x00, 0x01, 0xb8, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x01, 0x03, 0x00, 0x08, 0x00, 0x00
};
static guint8 mis_identified_datas[] = {
0x00, 0x00, 0x01, 0x1f, 0x4a, 0xf4, 0xd4, 0xd8, 0x08, 0x23, 0xdd,
0x7c, 0xd3, 0x75, 0x21, 0x43, 0x85, 0x31, 0x43, 0x04, 0x24, 0x30,
0x18, 0x43, 0xba, 0x1a, 0x50, 0x60, 0xbb, 0x53, 0x56, 0x80, 0x41,
0xb9, 0xd4, 0x25, 0x42, 0xea, 0x71, 0xb7, 0x49, 0x84, 0x0b, 0x14,
0x24, 0xc2, 0xaa, 0xba, 0xf9, 0xf7, 0x5b, 0x78, 0xa2, 0xba, 0xd3,
0xc7, 0x12, 0xee, 0xbe, 0xba, 0xfa, 0xeb, 0xeb, 0xaf, 0xbe, 0x6f,
0xce, 0x92, 0x05, 0x15, 0x22, 0x44, 0xf4, 0xc9, 0x1b, 0xcd, 0x84,
0x80, 0x87, 0x35, 0x6c, 0x07, 0x82, 0xaf, 0x3c, 0x3a, 0x89, 0x48,
0x3a, 0x26, 0x00, 0x64, 0x03, 0x12, 0x60, 0x03, 0xf4, 0x8c, 0x21,
0x16, 0xbe, 0x3c, 0x7c, 0x18, 0x03, 0x10, 0x0c, 0x80, 0xa0, 0x05,
0xe1, 0x85, 0x94, 0x90, 0xc4, 0x74, 0x05, 0x72, 0x80, 0x7a, 0x8e,
0x3e, 0x00, 0x30,
/* The accelerated version of scan_for_start_codes()
* mis-identifies the following as a start code */
0x01, 0x00, 0x01, 0x80, 0x68, 0x14,
0x26, 0xe4, 0x80, 0x98, 0x0a, 0xba, 0x77, 0x01, 0xc2, 0x42, 0x12,
0xc4, 0x59, 0x2a, 0xbb, 0x49, 0xf2, 0xc5, 0xa8, 0xd9, 0x30, 0x33,
0x16, 0x50, 0x60, 0x61, 0x41, 0xaa, 0x0d, 0x41, 0x5b, 0x17, 0x77,
0x76, 0x1a, 0x14, 0x3a, 0x08, 0x19, 0x3d, 0x6c, 0x94, 0x55, 0xd0,
0x94, 0x5a, 0xeb, 0x61, 0x22, 0xa7, 0xa6, 0x83, 0x47, 0x6d, 0x4d,
0x84, 0xc4, 0x6f, 0x78, 0xd8, 0x3a, 0xb4, 0x02, 0x0c, 0x36, 0xa6,
0x0b, 0x18, 0x49, 0xf7, 0xad, 0x00, 0x82, 0x09, 0xba, 0x12, 0xba,
0x1d, 0x44, 0x94, 0x0a, 0x1b, 0x03, 0xbb, 0xa2, 0x53, 0x02, 0xc0,
0x41, 0xac, 0x22,
/* the real start code is here */
0x00, 0x00, 0x01, 0x20, 0x4a, 0xfd, 0xf5, 0x50
};
static GstMpegVideoPacketTypeCode ordercode[] = {
GST_MPEG_VIDEO_PACKET_SEQUENCE,
GST_MPEG_VIDEO_PACKET_EXTENSION,
GST_MPEG_VIDEO_PACKET_GOP,
};
GST_START_TEST (test_mpeg_parse)
{
gint i;
GList *list, *tmp;
GstMpegVideoTypeOffsetSize *typeoffsz;
list = gst_mpeg_video_parse (mpeg2_seq, sizeof (mpeg2_seq), 12);
assert_equals_int (g_list_length (list), 4);
for (tmp = list, i = 0; tmp; tmp = g_list_next (tmp), i++) {
typeoffsz = tmp->data;
if (i == 3) {
fail_unless (GST_MPEG_VIDEO_PACKET_SLICE_MIN <= typeoffsz->type &&
typeoffsz->type <= GST_MPEG_VIDEO_PACKET_SLICE_MAX);
fail_unless (typeoffsz->size < 0);
} else
assert_equals_int (ordercode[i], typeoffsz->type);
}
g_list_free_full (list, (GDestroyNotify) g_free);
}
GST_END_TEST;
GST_START_TEST (test_mpeg_parse_sequence_header)
{
GList *list;
GstMpegVideoTypeOffsetSize *typeoffsz;
GstMpegVideoSequenceHdr seqhdr;
list = gst_mpeg_video_parse (mpeg2_seq, sizeof (mpeg2_seq), 12);
typeoffsz = list->data;
fail_unless (typeoffsz->type == GST_MPEG_VIDEO_PACKET_SEQUENCE);
fail_unless (gst_mpeg_video_parse_sequence_header (&seqhdr, mpeg2_seq,
sizeof (mpeg2_seq), typeoffsz->offset));
assert_equals_int (seqhdr.width, 1920);
assert_equals_int (seqhdr.height, 1080);
assert_equals_int (seqhdr.aspect_ratio_info, 3);
assert_equals_int (seqhdr.par_w, 17280);
assert_equals_int (seqhdr.par_h, 17280);
assert_equals_int (seqhdr.frame_rate_code, 7);
assert_equals_int (seqhdr.fps_n, 60000);
assert_equals_int (seqhdr.fps_d, 1001);
assert_equals_int (seqhdr.bitrate_value, 262143);
assert_equals_int (seqhdr.bitrate, 0);
assert_equals_int (seqhdr.vbv_buffer_size_value, 512);
fail_unless (seqhdr.constrained_parameters_flag == FALSE);
g_list_free_full (list, (GDestroyNotify) g_free);
}
GST_END_TEST;
GST_START_TEST (test_mpeg_parse_sequence_extension)
{
GList *list;
GstMpegVideoTypeOffsetSize *typeoffsz;
GstMpegVideoSequenceExt seqext;
list = gst_mpeg_video_parse (mpeg2_seq, sizeof (mpeg2_seq), 12);
typeoffsz = list->next->data;
fail_unless (typeoffsz->type == GST_MPEG_VIDEO_PACKET_EXTENSION);
fail_unless (gst_mpeg_video_parse_sequence_extension (&seqext,
mpeg2_seq, sizeof (mpeg2_seq), typeoffsz->offset));
assert_equals_int (seqext.profile, 4);
assert_equals_int (seqext.level, 8);
assert_equals_int (seqext.progressive, 1);
assert_equals_int (seqext.chroma_format, 1);
assert_equals_int (seqext.horiz_size_ext, 0);
assert_equals_int (seqext.vert_size_ext, 0);
assert_equals_int (seqext.vert_size_ext, 0);
assert_equals_int (seqext.bitrate_ext, 8);
assert_equals_int (seqext.vbv_buffer_size_extension, 3);
assert_equals_int (seqext.low_delay, 0);
assert_equals_int (seqext.fps_n_ext, 3);
assert_equals_int (seqext.fps_d_ext, 2);
g_list_free_full (list, (GDestroyNotify) g_free);
}
GST_END_TEST;
GST_START_TEST (test_mis_identified_datas)
{
GList *list, *tmp;
GstMpegVideoTypeOffsetSize *typeoffsz;
guint8 *data = mis_identified_datas;
list = gst_mpeg_video_parse (mis_identified_datas,
sizeof (mis_identified_datas), 0);
assert_equals_int (g_list_length (list), 2);
for (tmp = list; tmp; tmp = g_list_next (tmp)) {
typeoffsz = tmp->data;
assert_equals_int (data[typeoffsz->offset - 4], 0);
assert_equals_int (data[typeoffsz->offset - 3], 0);
assert_equals_int (data[typeoffsz->offset - 2], 1);
}
g_list_free_full (list, (GDestroyNotify) g_free);
}
GST_END_TEST;
static Suite *
videoparsers_suite (void)
{
Suite *s = suite_create ("Video Parsers library");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_mpeg_parse);
tcase_add_test (tc_chain, test_mpeg_parse_sequence_header);
tcase_add_test (tc_chain, test_mpeg_parse_sequence_extension);
tcase_add_test (tc_chain, test_mis_identified_datas);
return s;
}
int
main (int argc, char **argv)
{
int nf;
Suite *s = videoparsers_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);
srunner_run_all (sr, CK_NORMAL);
nf = srunner_ntests_failed (sr);
srunner_free (sr);
return nf;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment