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
GST_START_TEST(test_mpeg_parse)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
GST_START_TEST(test_mpeg_parse_sequence_header)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_packet_parse_sequence_header (&packet, &seqhdr));
101 assert_equals_int (seqhdr.width, 1920);
102 assert_equals_int (seqhdr.height, 1080);
103 assert_equals_int (seqhdr.aspect_ratio_info, 3);
104 assert_equals_int (seqhdr.par_w, 64);
105 assert_equals_int (seqhdr.par_h, 45);
106 assert_equals_int (seqhdr.frame_rate_code, 7);
107 assert_equals_int (seqhdr.fps_n, 60000);
108 assert_equals_int (seqhdr.fps_d, 1001);
109 assert_equals_int (seqhdr.bitrate_value, 262143);
110 assert_equals_int (seqhdr.bitrate, 0);
111 assert_equals_int (seqhdr.vbv_buffer_size_value, 512);
112 fail_unless (seqhdr.constrained_parameters_flag == FALSE);
113 }
114
115 GST_END_TEST;
116
GST_START_TEST(test_mpeg_parse_sequence_extension)117 GST_START_TEST (test_mpeg_parse_sequence_extension)
118 {
119 GstMpegVideoSequenceExt seqext;
120 GstMpegVideoPacket packet;
121
122 gst_mpeg_video_parse (&packet, mpeg2_seq, sizeof (mpeg2_seq), 24);
123
124 fail_unless (packet.type == GST_MPEG_VIDEO_PACKET_EXTENSION);
125 fail_unless (gst_mpeg_video_packet_parse_sequence_extension (&packet,
126 &seqext));
127 assert_equals_int (seqext.profile, 4);
128 assert_equals_int (seqext.level, 8);
129 assert_equals_int (seqext.progressive, 1);
130 assert_equals_int (seqext.chroma_format, 1);
131 assert_equals_int (seqext.horiz_size_ext, 0);
132 assert_equals_int (seqext.vert_size_ext, 0);
133 assert_equals_int (seqext.vert_size_ext, 0);
134 assert_equals_int (seqext.bitrate_ext, 8);
135 assert_equals_int (seqext.vbv_buffer_size_extension, 3);
136 assert_equals_int (seqext.low_delay, 0);
137 assert_equals_int (seqext.fps_n_ext, 3);
138 assert_equals_int (seqext.fps_d_ext, 2);
139 }
140
141 GST_END_TEST;
142
GST_START_TEST(test_mis_identified_datas)143 GST_START_TEST (test_mis_identified_datas)
144 {
145 GstMpegVideoPacket packet = { 0, };
146 const guint8 *data = mis_identified_datas;
147 gint i, off;
148
149 off = 0;
150 for (i = 0; i < 2; i++) {
151 gst_mpeg_video_parse (&packet, mis_identified_datas,
152 sizeof (mis_identified_datas), off);
153 assert_equals_int (data[packet.offset - 4], 0);
154 assert_equals_int (data[packet.offset - 3], 0);
155 assert_equals_int (data[packet.offset - 2], 1);
156 off = packet.offset + packet.size;
157 if (i == 1)
158 fail_unless (packet.size < 0);
159 else
160 fail_unless (packet.size > 0);
161 }
162 }
163
164 GST_END_TEST;
165
166 static Suite *
mpegvideoparsers_suite(void)167 mpegvideoparsers_suite (void)
168 {
169 Suite *s = suite_create ("Video Parsers library");
170
171 TCase *tc_chain = tcase_create ("general");
172
173 suite_add_tcase (s, tc_chain);
174 tcase_add_test (tc_chain, test_mpeg_parse);
175 tcase_add_test (tc_chain, test_mpeg_parse_sequence_header);
176 tcase_add_test (tc_chain, test_mpeg_parse_sequence_extension);
177 tcase_add_test (tc_chain, test_mis_identified_datas);
178
179 return s;
180 }
181
182 GST_CHECK_MAIN (mpegvideoparsers);
183