1 /*
2 * GStreamer
3 *
4 * unit test for mpeg4videoparse
5 *
6 * Copyright (C) 2011 Nokia Corporation. All rights reserved.
7 *
8 * Contact: Stefan Kost <stefan.kost@nokia.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26 #include <gst/check/gstcheck.h>
27 #include "parser.h"
28
29 #define SRC_CAPS_TMPL "video/mpeg, mpegversion=(int)4, systemstream=(boolean)false, parsed=(boolean)false"
30 #define SINK_CAPS_TMPL "video/mpeg, mpegversion=(int)4, systemstream=(boolean)false, parsed=(boolean)true"
31
32 GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
33 GST_PAD_SINK,
34 GST_PAD_ALWAYS,
35 GST_STATIC_CAPS (SINK_CAPS_TMPL)
36 );
37
38 GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
39 GST_PAD_SRC,
40 GST_PAD_ALWAYS,
41 GST_STATIC_CAPS (SRC_CAPS_TMPL)
42 );
43
44 /* some data */
45
46 /* codec data; VOS up to and including GOP */
47 static guint8 mpeg4_config[] = {
48 0x00, 0x00, 0x01, 0xb0, 0x01, 0x00, 0x00, 0x01,
49 0xb5, 0x89, 0x13, 0x00, 0x00, 0x01, 0x00, 0x00,
50 0x00, 0x01, 0x20, 0x00, 0xc4, 0x8d, 0x88, 0x00,
51 0xf5, 0x01, 0x04, 0x03, 0x14, 0x63, 0x00, 0x00,
52 0x01, 0xb3, 0x00, 0x10, 0x07
53 };
54
55 /* keyframes all around */
56 static guint8 mpeg4_iframe[] = {
57 0x00, 0x00, 0x01, 0xb6, 0x10, 0x60, 0x91, 0x82,
58 0x3d, 0xb7, 0xf1, 0xb6, 0xdf, 0xc6, 0xdb, 0x7f,
59 0x1b, 0x6d, 0xfb
60 };
61
62 static gboolean
verify_buffer(buffer_verify_data_s * vdata,GstBuffer * buffer)63 verify_buffer (buffer_verify_data_s * vdata, GstBuffer * buffer)
64 {
65 GstMapInfo map;
66
67 gst_buffer_map (buffer, &map, GST_MAP_READ);
68
69 /* header is merged in initial frame */
70 if (vdata->buffer_counter == 0) {
71 /* the whole sequence header is included */
72 fail_unless (map.size == ctx_headers[0].size + vdata->data_to_verify_size);
73 fail_unless (memcmp (map.data, ctx_headers[0].data,
74 ctx_headers[0].size) == 0);
75 fail_unless (memcmp (map.data + ctx_headers[0].size,
76 vdata->data_to_verify, vdata->data_to_verify_size) == 0);
77 gst_buffer_unmap (buffer, &map);
78 return TRUE;
79 }
80 gst_buffer_unmap (buffer, &map);
81
82 return FALSE;
83 }
84
GST_START_TEST(test_parse_normal)85 GST_START_TEST (test_parse_normal)
86 {
87 gst_parser_test_normal (mpeg4_iframe, sizeof (mpeg4_iframe));
88 }
89
90 GST_END_TEST;
91
92
GST_START_TEST(test_parse_drain_single)93 GST_START_TEST (test_parse_drain_single)
94 {
95 gst_parser_test_drain_single (mpeg4_iframe, sizeof (mpeg4_iframe));
96 }
97
98 GST_END_TEST;
99
100
GST_START_TEST(test_parse_split)101 GST_START_TEST (test_parse_split)
102 {
103 gst_parser_test_split (mpeg4_iframe, sizeof (mpeg4_iframe));
104 }
105
106 GST_END_TEST;
107
108
109 #define structure_get_int(s,f) \
110 (g_value_get_int(gst_structure_get_value(s,f)))
111 #define fail_unless_structure_field_int_equals(s,field,num) \
112 fail_unless_equals_int (structure_get_int(s,field), num)
113
GST_START_TEST(test_parse_detect_stream)114 GST_START_TEST (test_parse_detect_stream)
115 {
116 GstCaps *caps;
117 GstStructure *s;
118 GstBuffer *buf;
119 const GValue *val;
120 GstMapInfo map;
121
122 caps = gst_parser_test_get_output_caps (mpeg4_iframe, sizeof (mpeg4_iframe),
123 NULL);
124 fail_unless (caps != NULL);
125
126 /* Check that the negotiated caps are as expected */
127 /* When codec_data is present, parser assumes that data is version 4 */
128 GST_LOG ("mpeg4video output caps: %" GST_PTR_FORMAT, caps);
129 s = gst_caps_get_structure (caps, 0);
130 fail_unless (gst_structure_has_name (s, "video/mpeg"));
131 fail_unless_structure_field_int_equals (s, "mpegversion", 4);
132 fail_unless_structure_field_int_equals (s, "width", 32);
133 fail_unless_structure_field_int_equals (s, "height", 24);
134 fail_unless (gst_structure_has_field (s, "codec_data"));
135
136 /* check codec-data in more detail */
137 val = gst_structure_get_value (s, "codec_data");
138 fail_unless (val != NULL);
139 buf = gst_value_get_buffer (val);
140 fail_unless (buf != NULL);
141 /* codec-data == config header - GOP */
142 gst_buffer_map (buf, &map, GST_MAP_READ);
143 fail_unless (map.size == sizeof (mpeg4_config) - 7);
144 fail_unless (memcmp (map.data, mpeg4_config, map.size) == 0);
145 gst_buffer_unmap (buf, &map);
146
147 gst_caps_unref (caps);
148 }
149
150 GST_END_TEST;
151
152
153 static Suite *
mpeg4videoparse_suite(void)154 mpeg4videoparse_suite (void)
155 {
156 Suite *s = suite_create ("mpeg4videoparse");
157 TCase *tc_chain = tcase_create ("general");
158
159 /* init test context */
160 ctx_factory = "mpeg4videoparse";
161 ctx_sink_template = &sinktemplate;
162 ctx_src_template = &srctemplate;
163 ctx_headers[0].data = mpeg4_config;
164 ctx_headers[0].size = sizeof (mpeg4_config);
165 ctx_verify_buffer = verify_buffer;
166 /* no timing info to parse */
167 ctx_no_metadata = TRUE;
168
169 suite_add_tcase (s, tc_chain);
170 tcase_add_test (tc_chain, test_parse_normal);
171 tcase_add_test (tc_chain, test_parse_drain_single);
172 tcase_add_test (tc_chain, test_parse_split);
173 tcase_add_test (tc_chain, test_parse_detect_stream);
174
175 return s;
176 }
177
178
179 /*
180 * TODO:
181 * - Both push- and pull-modes need to be tested
182 * * Pull-mode & EOS
183 */
184 GST_CHECK_MAIN (mpeg4videoparse);
185