Initial release including wifi display based on gst-rtsp-server-1.4.1
[platform/upstream/gstreamer.git] / tests / check / gst / stream.c
1 /* GStreamer
2  * Copyright (C) 2013 Axis Communications AB <dev-gstreamer at axis dot com>
3  *
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.
8  *
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.
13  *
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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21
22 #include <rtsp-stream.h>
23 #include <rtsp-address-pool.h>
24
25 GST_START_TEST (test_get_sockets)
26 {
27   GstPad *srcpad;
28   GstElement *pay;
29   GstRTSPStream *stream;
30   GstBin *bin;
31   GstElement *rtpbin;
32   GSocket *socket;
33   gboolean have_ipv4;
34   gboolean have_ipv6;
35
36   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
37   fail_unless (srcpad != NULL);
38   gst_pad_set_active (srcpad, TRUE);
39   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
40   fail_unless (pay != NULL);
41   stream = gst_rtsp_stream_new (0, pay, srcpad);
42   fail_unless (stream != NULL);
43   gst_object_unref (pay);
44   gst_object_unref (srcpad);
45   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
46   fail_unless (rtpbin != NULL);
47   bin = GST_BIN (gst_bin_new ("testbin"));
48   fail_unless (bin != NULL);
49   fail_unless (gst_bin_add (bin, rtpbin));
50
51   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
52
53   socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV4);
54   have_ipv4 = (socket != NULL);
55   if (have_ipv4) {
56     fail_unless (g_socket_get_fd (socket) >= 0);
57     g_object_unref (socket);
58   }
59
60   socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV4);
61   if (have_ipv4) {
62     fail_unless (socket != NULL);
63     fail_unless (g_socket_get_fd (socket) >= 0);
64     g_object_unref (socket);
65   } else {
66     fail_unless (socket == NULL);
67   }
68
69   socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV6);
70   have_ipv6 = (socket != NULL);
71   if (have_ipv6) {
72     fail_unless (g_socket_get_fd (socket) >= 0);
73     g_object_unref (socket);
74   }
75
76   socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV6);
77   if (have_ipv6) {
78     fail_unless (socket != NULL);
79     fail_unless (g_socket_get_fd (socket) >= 0);
80     g_object_unref (socket);
81   } else {
82     fail_unless (socket == NULL);
83   }
84
85   /* check that at least one family is available */
86   fail_unless (have_ipv4 || have_ipv6);
87
88   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
89
90   gst_object_unref (bin);
91   gst_object_unref (stream);
92 }
93
94 GST_END_TEST;
95
96 GST_START_TEST (test_get_multicast_address)
97 {
98   GstPad *srcpad;
99   GstElement *pay;
100   GstRTSPStream *stream;
101   GstRTSPAddressPool *pool;
102   GstRTSPAddress *addr1;
103   GstRTSPAddress *addr2;
104
105   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
106   fail_unless (srcpad != NULL);
107   gst_pad_set_active (srcpad, TRUE);
108   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
109   fail_unless (pay != NULL);
110   stream = gst_rtsp_stream_new (0, pay, srcpad);
111   fail_unless (stream != NULL);
112   gst_object_unref (pay);
113   gst_object_unref (srcpad);
114
115   pool = gst_rtsp_address_pool_new ();
116   fail_unless (gst_rtsp_address_pool_add_range (pool,
117           "233.252.0.0", "233.252.0.0", 5000, 5001, 1));
118   fail_unless (gst_rtsp_address_pool_add_range (pool,
119           "FF11:DB8::1", "FF11:DB8::1", 5002, 5003, 1));
120   gst_rtsp_stream_set_address_pool (stream, pool);
121
122   addr1 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
123   fail_unless (addr1 != NULL);
124   fail_unless_equals_string (addr1->address, "233.252.0.0");
125   fail_unless_equals_int (addr1->port, 5000);
126   fail_unless_equals_int (addr1->n_ports, 2);
127
128   addr2 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
129   fail_unless (addr2 != NULL);
130   fail_unless_equals_string (addr2->address, "233.252.0.0");
131   fail_unless_equals_int (addr2->port, 5000);
132   fail_unless_equals_int (addr2->n_ports, 2);
133
134   gst_rtsp_address_free (addr1);
135   gst_rtsp_address_free (addr2);
136
137   addr1 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV6);
138   fail_unless (addr1 != NULL);
139   fail_unless (!g_ascii_strcasecmp (addr1->address, "FF11:DB8::1"));
140   fail_unless_equals_int (addr1->port, 5002);
141   fail_unless_equals_int (addr1->n_ports, 2);
142
143   addr2 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV6);
144   fail_unless (addr2 != NULL);
145   fail_unless (!g_ascii_strcasecmp (addr2->address, "FF11:DB8::1"));
146   fail_unless_equals_int (addr2->port, 5002);
147   fail_unless_equals_int (addr2->n_ports, 2);
148
149   gst_rtsp_address_free (addr1);
150   gst_rtsp_address_free (addr2);
151
152   g_object_unref (pool);
153
154   gst_object_unref (stream);
155 }
156
157 GST_END_TEST;
158
159 static Suite *
160 rtspstream_suite (void)
161 {
162   Suite *s = suite_create ("rtspstream");
163   TCase *tc = tcase_create ("general");
164
165   suite_add_tcase (s, tc);
166   tcase_add_test (tc, test_get_sockets);
167   tcase_add_test (tc, test_get_multicast_address);
168
169   return s;
170 }
171
172 GST_CHECK_MAIN (rtspstream);