1 /* GStreamer unit tests for the neonhttpsrc element
2 * Copyright (C) 2006-2007 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <gst/check/gstcheck.h>
27 handoff_cb (GstElement * fakesink, GstBuffer * buf, GstPad * pad,
28 GstBuffer ** p_outbuf)
30 GST_LOG ("handoff, buf = %p", buf);
31 if (*p_outbuf == NULL)
32 *p_outbuf = gst_buffer_ref (buf);
35 GST_START_TEST (test_first_buffer_has_offset)
37 GstStateChangeReturn ret;
38 GstElement *pipe, *src, *sink;
39 GstBuffer *buf = NULL;
42 pipe = gst_pipeline_new (NULL);
44 src = gst_element_factory_make ("neonhttpsrc", NULL);
45 fail_unless (src != NULL);
47 sink = gst_element_factory_make ("fakesink", NULL);
48 fail_unless (sink != NULL);
50 gst_bin_add (GST_BIN (pipe), src);
51 gst_bin_add (GST_BIN (pipe), sink);
52 fail_unless (gst_element_link (src, sink));
54 g_object_set (src, "location", "http://gstreamer.freedesktop.org/", NULL);
55 g_object_set (src, "automatic-redirect", TRUE, NULL);
57 /* set some cookies (shouldn't hurt) */
58 cookies = g_strsplit ("foo=1234,bar=9871615348162523726337x99FB", ",", -1);
59 g_object_set (src, "cookies", cookies, NULL);
62 g_object_set (sink, "signal-handoffs", TRUE, NULL);
63 g_signal_connect (sink, "preroll-handoff", G_CALLBACK (handoff_cb), &buf);
65 ret = gst_element_set_state (pipe, GST_STATE_PAUSED);
66 if (ret != GST_STATE_CHANGE_ASYNC) {
67 GST_DEBUG ("failed to start up neon http src, ret = %d", ret);
71 /* don't wait for more than 10 seconds */
72 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND);
73 GST_LOG ("ret = %u", ret);
76 /* we want to test the buffer offset, nothing else; if there's a failure
77 * it might be for lots of reasons (no network connection, whatever), we're
78 * not interested in those */
79 GST_DEBUG ("didn't manage to get data within 10 seconds, skipping test");
83 GST_DEBUG ("buffer offset = %" G_GUINT64_FORMAT, GST_BUFFER_OFFSET (buf));
85 /* first buffer should have a 0 offset */
86 fail_unless (GST_BUFFER_OFFSET (buf) == 0);
87 gst_buffer_unref (buf);
91 gst_element_set_state (pipe, GST_STATE_NULL);
92 gst_object_unref (pipe);
97 GST_START_TEST (test_icy_stream)
99 GstElement *pipe, *src, *sink;
102 pipe = gst_pipeline_new (NULL);
104 src = gst_element_factory_make ("neonhttpsrc", NULL);
105 fail_unless (src != NULL);
107 sink = gst_element_factory_make ("fakesink", NULL);
108 fail_unless (sink != NULL);
110 gst_bin_add (GST_BIN (pipe), src);
111 gst_bin_add (GST_BIN (pipe), sink);
112 fail_unless (gst_element_link (src, sink));
114 /* First try Virgin Radio Ogg stream, to see if there's connectivity and all
115 * (which is an attempt to work around the completely horrid error reporting
116 * and that we can't distinguish different types of failures here).
117 * Note that neonhttpsrc does the whole connect + session initiation all in
118 * the state change function. */
120 g_object_set (src, "location", "http://ogg2.smgradio.com/vr32.ogg", NULL);
121 g_object_set (src, "automatic-redirect", FALSE, NULL);
122 g_object_set (src, "num-buffers", 1, NULL);
123 gst_element_set_state (pipe, GST_STATE_PLAYING);
125 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
126 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
127 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
128 GST_INFO ("looks like there's no net connectivity or sgmradio.com is "
129 "down. In any case, let's just skip this test");
130 gst_message_unref (msg);
133 gst_message_unref (msg);
135 gst_element_set_state (pipe, GST_STATE_NULL);
137 /* Now, if the ogg stream works, the mp3 shoutcast stream should work as
138 * well (time will tell if that's true) */
140 /* Virgin Radio 32kbps mp3 shoutcast stream */
141 g_object_set (src, "location", "http://mp3-vr-32.smgradio.com:80/", NULL);
142 g_object_set (src, "automatic-redirect", FALSE, NULL);
144 /* g_object_set (src, "neon-http-debug", TRUE, NULL); */
146 /* EOS after the first buffer */
147 g_object_set (src, "num-buffers", 1, NULL);
149 gst_element_set_state (pipe, GST_STATE_PLAYING);
150 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
151 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
153 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
154 GST_DEBUG ("success, we're done here");
155 gst_message_unref (msg);
162 gst_message_parse_error (msg, &err, NULL);
163 gst_message_unref (msg);
164 g_error ("Error with ICY mp3 shoutcast stream: %s", err->message);
170 gst_element_set_state (pipe, GST_STATE_NULL);
171 gst_object_unref (pipe);
177 neonhttpsrc_suite (void)
179 Suite *s = suite_create ("neonhttpsrc");
180 TCase *tc_chain = tcase_create ("general");
182 suite_add_tcase (s, tc_chain);
183 tcase_set_timeout (tc_chain, 5);
184 tcase_add_test (tc_chain, test_first_buffer_has_offset);
185 tcase_add_test (tc_chain, test_icy_stream);
190 GST_CHECK_MAIN (neonhttpsrc);