1 /*
2 * GStreamer
3 *
4 * unit test for h263parse
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/x-h263, variant=(string)itu, parsed=(boolean)false"
30 #define SINK_CAPS_TMPL "video/x-h263, 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 #if 0
47 static guint8 h263_iframe[] = {
48 /* keyframes all around */
49 0x00, 0x00, 0x80, 0x02, 0x1c, 0x88, 0x01, 0x00,
50 0x11, 0xe0, 0x44, 0xc4, 0x04, 0x04, 0x04, 0x3f,
51 0xff, 0xe6, 0x20, 0x20, 0x20, 0x21, 0xff, 0xff,
52 0x31, 0x01, 0x01, 0x01, 0x0f, 0xff, 0xf9, 0x88,
53 0x08, 0x08, 0x08, 0x7f, 0xff, 0x80
54 };
55 #endif
56
57 static guint8 h263_iframe[] = {
58 /* keyframes all around */
59 /* actually, this is a truncated keyframe,
60 * but don't tell anyone or try this at home */
61 0x00, 0x00, 0x80, 0x02, 0x0c, 0x04, 0x26, 0x20,
62 0x20, 0x20, 0x21, 0xff, 0xff, 0x31, 0x01, 0x01,
63 0x01, 0x0f, 0xff, 0xf9, 0x88, 0x08, 0x08, 0x08,
64 0x7f, 0xff, 0xcc, 0x40, 0x40, 0x40, 0x43, 0xff,
65 0xfe, 0x62, 0x02, 0x02, 0x02, 0x1f, 0xff, 0xf3,
66 0x10, 0x10, 0x10, 0x10, 0xff, 0xff, 0x98, 0x80,
67 0x80, 0x80, 0x87, 0xff, 0xfc, 0xc4, 0x04, 0x04,
68 0x04, 0x3f, 0xff, 0xe6, 0x20, 0x20, 0x20, 0x21,
69 0xff, 0xff, 0x31, 0x01, 0x01, 0x01, 0x0f, 0xff,
70 0xf9, 0x88, 0x08, 0x08, 0x08, 0x7f, 0xff, 0xcc,
71 0x40, 0x40, 0x40, 0x43, 0xff, 0xfe, 0x62, 0x02,
72 0x02, 0x02, 0x1f, 0xff, 0xf3, 0x10, 0x10, 0x10,
73 0x10, 0xff, 0xff, 0x98, 0x80, 0x80, 0x80, 0x87,
74 0xff, 0xfc, 0xc4, 0x04, 0x04, 0x04, 0x3f, 0xff,
75 0xe6, 0x20, 0x20, 0x20, 0x21, 0xff, 0xff, 0x31,
76 0x01, 0x01, 0x01, 0x0f, 0xff, 0xf9, 0x88, 0x08
77 };
78
GST_START_TEST(test_parse_normal)79 GST_START_TEST (test_parse_normal)
80 {
81 gst_parser_test_normal (h263_iframe, sizeof (h263_iframe));
82 }
83
84 GST_END_TEST;
85
86
GST_START_TEST(test_parse_drain_single)87 GST_START_TEST (test_parse_drain_single)
88 {
89 gst_parser_test_drain_single (h263_iframe, sizeof (h263_iframe));
90 }
91
92 GST_END_TEST;
93
94
GST_START_TEST(test_parse_split)95 GST_START_TEST (test_parse_split)
96 {
97 gst_parser_test_split (h263_iframe, sizeof (h263_iframe));
98 }
99
100 GST_END_TEST;
101
102
103 #define structure_get_int(s,f) \
104 (g_value_get_int(gst_structure_get_value(s,f)))
105 #define fail_unless_structure_field_int_equals(s,field,num) \
106 fail_unless_equals_int (structure_get_int(s,field), num)
107
GST_START_TEST(test_parse_detect_stream)108 GST_START_TEST (test_parse_detect_stream)
109 {
110 GstCaps *caps;
111 GstStructure *s;
112
113 caps = gst_parser_test_get_output_caps (h263_iframe, sizeof (h263_iframe),
114 NULL);
115 fail_unless (caps != NULL);
116
117 /* Check that the negotiated caps are as expected */
118 /* When codec_data is present, parser assumes that data is version 4 */
119 GST_LOG ("mpegvideo output caps: %" GST_PTR_FORMAT, caps);
120 s = gst_caps_get_structure (caps, 0);
121 fail_unless (gst_structure_has_name (s, "video/x-h263"));
122 fail_unless_structure_field_int_equals (s, "width", 352);
123 fail_unless_structure_field_int_equals (s, "height", 288);
124
125 gst_caps_unref (caps);
126 }
127
128 GST_END_TEST;
129
130
131 static Suite *
h263parse_suite(void)132 h263parse_suite (void)
133 {
134 Suite *s = suite_create ("h263parse");
135 TCase *tc_chain = tcase_create ("general");
136
137 /* init test context */
138 ctx_factory = "h263parse";
139 ctx_sink_template = &sinktemplate;
140 ctx_src_template = &srctemplate;
141 /* no timing info to parse */
142 ctx_no_metadata = TRUE;
143
144 suite_add_tcase (s, tc_chain);
145 tcase_add_test (tc_chain, test_parse_normal);
146 tcase_add_test (tc_chain, test_parse_drain_single);
147 tcase_add_test (tc_chain, test_parse_split);
148 tcase_add_test (tc_chain, test_parse_detect_stream);
149
150 return s;
151 }
152
153
154 /*
155 * TODO:
156 * - Both push- and pull-modes need to be tested
157 * * Pull-mode & EOS
158 */
159 GST_CHECK_MAIN (h263parse);
160