1 /* GStreamer
2 * unit test for jpegdec
3 * Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
4 * Copyright (C) <2012> Mathias Hasselmann <mathias@openismus.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 <unistd.h>
23
24 #include <gio/gio.h>
25 #include <gst/check/gstcheck.h>
26 #include <gst/app/gstappsink.h>
27 #include <gst/pbutils/gstdiscoverer.h>
28
29 /* Verify jpegdec is working when explicitly requested by a pipeline. */
GST_START_TEST(test_jpegdec_explicit)30 GST_START_TEST (test_jpegdec_explicit)
31 {
32 GstElement *pipeline, *source, *dec, *sink;
33 GstSample *sample;
34
35 /* construct a pipeline that explicitly uses jpegdec */
36 pipeline = gst_pipeline_new (NULL);
37 source = gst_element_factory_make ("filesrc", NULL);
38 dec = gst_element_factory_make ("jpegdec", NULL);
39 sink = gst_element_factory_make ("appsink", NULL);
40
41 gst_bin_add_many (GST_BIN (pipeline), source, dec, sink, NULL);
42 gst_element_link_many (source, dec, sink, NULL);
43
44 /* point that pipeline to our test image */
45 {
46 char *filename = g_build_filename (GST_TEST_FILES_PATH, "image.jpg", NULL);
47 g_object_set (G_OBJECT (source), "location", filename, NULL);
48 g_free (filename);
49 }
50
51 gst_element_set_state (pipeline, GST_STATE_PLAYING);
52
53 sample = gst_app_sink_pull_sample (GST_APP_SINK (sink));
54 fail_unless (GST_IS_SAMPLE (sample));
55
56 /* do some basic checks to verify image decoding */
57 {
58 GstCaps *decoded;
59 GstCaps *expected;
60
61 decoded = gst_sample_get_caps (sample);
62 expected = gst_caps_from_string ("video/x-raw, width=120, height=160");
63
64 fail_unless (gst_caps_is_always_compatible (decoded, expected));
65
66 gst_caps_unref (expected);
67 }
68 gst_sample_unref (sample);
69
70 /* wait for EOS */
71 sample = gst_app_sink_pull_sample (GST_APP_SINK (sink));
72 fail_unless (sample == NULL);
73 fail_unless (gst_app_sink_is_eos (GST_APP_SINK (sink)));
74
75 gst_element_set_state (pipeline, GST_STATE_NULL);
76 gst_object_unref (pipeline);
77 }
78
79 GST_END_TEST;
80
81 /* Verify JPEG discovery is working. Right now jpegdec would be used,
82 * but I have no idea how to actually verify this. */
GST_START_TEST(test_jpegdec_discover)83 GST_START_TEST (test_jpegdec_discover)
84 {
85 GstDiscoverer *disco;
86 GError *error = NULL;
87 char *uri;
88 GstDiscovererInfo *info;
89 GstDiscovererVideoInfo *video;
90
91 disco = gst_discoverer_new (60 * GST_SECOND, &error);
92
93 fail_unless (GST_IS_DISCOVERER (disco));
94 fail_unless (error == NULL, "%s", (error ? error->message : ""));
95
96 {
97 GFile *testdir = g_file_new_for_path (GST_TEST_FILES_PATH);
98 GFile *testfile = g_file_resolve_relative_path (testdir, "image.jpg");
99 uri = g_file_get_uri (testfile);
100 g_object_unref (testfile);
101 g_object_unref (testdir);
102 }
103
104 info = gst_discoverer_discover_uri (disco, uri, &error);
105 fail_unless (GST_IS_DISCOVERER_INFO (info));
106 fail_unless (error == NULL, "%s: %s", uri, (error ? error->message : ""));
107
108 fail_unless_equals_string (gst_discoverer_info_get_uri (info), uri);
109 fail_unless_equals_int (gst_discoverer_info_get_result (info),
110 GST_DISCOVERER_OK);
111
112 video =
113 GST_DISCOVERER_VIDEO_INFO (gst_discoverer_info_get_stream_info (info));
114 fail_unless (video != NULL);
115
116 fail_unless (gst_discoverer_video_info_is_image (video));
117 fail_unless_equals_int (gst_discoverer_video_info_get_width (video), 120);
118 fail_unless_equals_int (gst_discoverer_video_info_get_height (video), 160);
119
120 gst_discoverer_info_unref (video);
121 gst_discoverer_info_unref (info);
122 g_free (uri);
123 g_object_unref (disco);
124 }
125
126 GST_END_TEST;
127
128 static Suite *
jpegdec_suite(void)129 jpegdec_suite (void)
130 {
131 Suite *s = suite_create ("jpegdec");
132 TCase *tc_chain = tcase_create ("general");
133
134 suite_add_tcase (s, tc_chain);
135 tcase_add_test (tc_chain, test_jpegdec_explicit);
136 tcase_add_test (tc_chain, test_jpegdec_discover);
137
138 return s;
139 }
140
141 GST_CHECK_MAIN (jpegdec);
142