import ext/codecparsers instead of git submodule
[profile/ivi/gstreamer-vaapi.git] / ext / codecparsers / tests / check / libs / mpegvideoparser.c
1 /* Gstreamer
2  * Copyright (C) <2011> Intel Corporation
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 #include <gst/check/gstcheck.h>
23 #include <gst/codecparsers/gstmpegvideoparser.h>
24
25 /* actually seq + gop */
26 static const guint8 mpeg2_seq[] = {
27   0x00, 0x00, 0x01, 0xb3, 0x02, 0x00, 0x18, 0x15, 0xff, 0xff, 0xe0, 0x28,
28   0x00, 0x00, 0x01, 0xb3, 0x78, 0x04, 0x38, 0x37, 0xff, 0xff, 0xf0, 0x00,
29   0x00, 0x00, 0x01, 0xb5, 0x14, 0x8a, 0x00, 0x11, 0x03, 0x71,
30   0x00, 0x00, 0x01, 0xb8, 0x00, 0x08, 0x00, 0x00,
31   0x00, 0x00, 0x01, 0x03, 0x00, 0x08, 0x00, 0x00
32 };
33
34 static const guint8 mis_identified_datas[] = {
35   0x00, 0x00, 0x01, 0x1f, 0x4a, 0xf4, 0xd4, 0xd8, 0x08, 0x23, 0xdd,
36   0x7c, 0xd3, 0x75, 0x21, 0x43, 0x85, 0x31, 0x43, 0x04, 0x24, 0x30,
37   0x18, 0x43, 0xba, 0x1a, 0x50, 0x60, 0xbb, 0x53, 0x56, 0x80, 0x41,
38   0xb9, 0xd4, 0x25, 0x42, 0xea, 0x71, 0xb7, 0x49, 0x84, 0x0b, 0x14,
39   0x24, 0xc2, 0xaa, 0xba, 0xf9, 0xf7, 0x5b, 0x78, 0xa2, 0xba, 0xd3,
40   0xc7, 0x12, 0xee, 0xbe, 0xba, 0xfa, 0xeb, 0xeb, 0xaf, 0xbe, 0x6f,
41   0xce, 0x92, 0x05, 0x15, 0x22, 0x44, 0xf4, 0xc9, 0x1b, 0xcd, 0x84,
42   0x80, 0x87, 0x35, 0x6c, 0x07, 0x82, 0xaf, 0x3c, 0x3a, 0x89, 0x48,
43   0x3a, 0x26, 0x00, 0x64, 0x03, 0x12, 0x60, 0x03, 0xf4, 0x8c, 0x21,
44   0x16, 0xbe, 0x3c, 0x7c, 0x18, 0x03, 0x10, 0x0c, 0x80, 0xa0, 0x05,
45   0xe1, 0x85, 0x94, 0x90, 0xc4, 0x74, 0x05, 0x72, 0x80, 0x7a, 0x8e,
46   0x3e, 0x00, 0x30,
47   /* The accelerated version of scan_for_start_codes()
48    * mis-identifies the following as a start code */
49   0x01, 0x00, 0x01, 0x80, 0x68, 0x14,
50   0x26, 0xe4, 0x80, 0x98, 0x0a, 0xba, 0x77, 0x01, 0xc2, 0x42, 0x12,
51   0xc4, 0x59, 0x2a, 0xbb, 0x49, 0xf2, 0xc5, 0xa8, 0xd9, 0x30, 0x33,
52   0x16, 0x50, 0x60, 0x61, 0x41, 0xaa, 0x0d, 0x41, 0x5b, 0x17, 0x77,
53   0x76, 0x1a, 0x14, 0x3a, 0x08, 0x19, 0x3d, 0x6c, 0x94, 0x55, 0xd0,
54   0x94, 0x5a, 0xeb, 0x61, 0x22, 0xa7, 0xa6, 0x83, 0x47, 0x6d, 0x4d,
55   0x84, 0xc4, 0x6f, 0x78, 0xd8, 0x3a, 0xb4, 0x02, 0x0c, 0x36, 0xa6,
56   0x0b, 0x18, 0x49, 0xf7, 0xad, 0x00, 0x82, 0x09, 0xba, 0x12, 0xba,
57   0x1d, 0x44, 0x94, 0x0a, 0x1b, 0x03, 0xbb, 0xa2, 0x53, 0x02, 0xc0,
58   0x41, 0xac, 0x22,
59   /* the real start code is here */
60   0x00, 0x00, 0x01, 0x20, 0x4a, 0xfd, 0xf5, 0x50
61 };
62
63 static GstMpegVideoPacketTypeCode ordercode[] = {
64   GST_MPEG_VIDEO_PACKET_SEQUENCE,
65   GST_MPEG_VIDEO_PACKET_EXTENSION,
66   GST_MPEG_VIDEO_PACKET_GOP,
67 };
68
69 GST_START_TEST (test_mpeg_parse)
70 {
71   gint i, off;
72   GstMpegVideoPacket packet;
73
74   off = 12;
75   for (i = 0; i < 4; ++i) {
76     fail_unless (gst_mpeg_video_parse (&packet, mpeg2_seq, sizeof (mpeg2_seq),
77             off));
78     fail_unless (packet.offset == off + 4);
79     if (i == 3) {
80       fail_unless (GST_MPEG_VIDEO_PACKET_SLICE_MIN <= packet.type &&
81           packet.type <= GST_MPEG_VIDEO_PACKET_SLICE_MAX);
82       fail_unless (packet.size < 0);
83     } else {
84       assert_equals_int (ordercode[i], packet.type);
85     }
86     off = packet.offset + packet.size;
87   }
88 }
89
90 GST_END_TEST;
91
92 GST_START_TEST (test_mpeg_parse_sequence_header)
93 {
94   GstMpegVideoSequenceHdr seqhdr;
95   GstMpegVideoPacket packet;
96
97   gst_mpeg_video_parse (&packet, mpeg2_seq, sizeof (mpeg2_seq), 12);
98
99   fail_unless (packet.type == GST_MPEG_VIDEO_PACKET_SEQUENCE);
100   fail_unless (gst_mpeg_video_parse_sequence_header (&seqhdr, mpeg2_seq,
101           sizeof (mpeg2_seq), packet.offset));
102   assert_equals_int (seqhdr.width, 1920);
103   assert_equals_int (seqhdr.height, 1080);
104   assert_equals_int (seqhdr.aspect_ratio_info, 3);
105   assert_equals_int (seqhdr.par_w, 64);
106   assert_equals_int (seqhdr.par_h, 45);
107   assert_equals_int (seqhdr.frame_rate_code, 7);
108   assert_equals_int (seqhdr.fps_n, 60000);
109   assert_equals_int (seqhdr.fps_d, 1001);
110   assert_equals_int (seqhdr.bitrate_value, 262143);
111   assert_equals_int (seqhdr.bitrate, 0);
112   assert_equals_int (seqhdr.vbv_buffer_size_value, 512);
113   fail_unless (seqhdr.constrained_parameters_flag == FALSE);
114 }
115
116 GST_END_TEST;
117
118 GST_START_TEST (test_mpeg_parse_sequence_extension)
119 {
120   GstMpegVideoSequenceExt seqext;
121   GstMpegVideoPacket packet;
122
123   gst_mpeg_video_parse (&packet, mpeg2_seq, sizeof (mpeg2_seq), 24);
124
125   fail_unless (packet.type == GST_MPEG_VIDEO_PACKET_EXTENSION);
126   fail_unless (gst_mpeg_video_parse_sequence_extension (&seqext,
127           mpeg2_seq, sizeof (mpeg2_seq), packet.offset));
128   assert_equals_int (seqext.profile, 4);
129   assert_equals_int (seqext.level, 8);
130   assert_equals_int (seqext.progressive, 1);
131   assert_equals_int (seqext.chroma_format, 1);
132   assert_equals_int (seqext.horiz_size_ext, 0);
133   assert_equals_int (seqext.vert_size_ext, 0);
134   assert_equals_int (seqext.vert_size_ext, 0);
135   assert_equals_int (seqext.bitrate_ext, 8);
136   assert_equals_int (seqext.vbv_buffer_size_extension, 3);
137   assert_equals_int (seqext.low_delay, 0);
138   assert_equals_int (seqext.fps_n_ext, 3);
139   assert_equals_int (seqext.fps_d_ext, 2);
140 }
141
142 GST_END_TEST;
143
144 GST_START_TEST (test_mis_identified_datas)
145 {
146   GstMpegVideoPacket packet = { 0, };
147   const guint8 *data = mis_identified_datas;
148   gint i, off;
149
150   off = 0;
151   for (i = 0; i < 2; i++) {
152     gst_mpeg_video_parse (&packet, mis_identified_datas,
153         sizeof (mis_identified_datas), off);
154     assert_equals_int (data[packet.offset - 4], 0);
155     assert_equals_int (data[packet.offset - 3], 0);
156     assert_equals_int (data[packet.offset - 2], 1);
157     off = packet.offset + packet.size;
158     if (i == 1)
159       fail_unless (packet.size < 0);
160     else
161       fail_unless (packet.size > 0);
162   }
163 }
164
165 GST_END_TEST;
166
167 static Suite *
168 videoparsers_suite (void)
169 {
170   Suite *s = suite_create ("Video Parsers library");
171
172   TCase *tc_chain = tcase_create ("general");
173
174   suite_add_tcase (s, tc_chain);
175   tcase_add_test (tc_chain, test_mpeg_parse);
176   tcase_add_test (tc_chain, test_mpeg_parse_sequence_header);
177   tcase_add_test (tc_chain, test_mpeg_parse_sequence_extension);
178   tcase_add_test (tc_chain, test_mis_identified_datas);
179
180   return s;
181 }
182
183 int
184 main (int argc, char **argv)
185 {
186   int nf;
187
188   Suite *s = videoparsers_suite ();
189
190   SRunner *sr = srunner_create (s);
191
192   gst_check_init (&argc, &argv);
193
194   srunner_run_all (sr, CK_NORMAL);
195   nf = srunner_ntests_failed (sr);
196   srunner_free (sr);
197
198   return nf;
199 }