2 * Copyright (C) 2013 Axis Communications AB <dev-gstreamer at axis dot com>
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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <gst/check/gstcheck.h>
22 #include <rtsp-stream.h>
23 #include <rtsp-address-pool.h>
25 GST_START_TEST (test_get_sockets)
29 GstRTSPStream *stream;
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));
51 fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
53 socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV4);
54 have_ipv4 = (socket != NULL);
56 fail_unless (g_socket_get_fd (socket) >= 0);
57 g_object_unref (socket);
60 socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV4);
62 fail_unless (socket != NULL);
63 fail_unless (g_socket_get_fd (socket) >= 0);
64 g_object_unref (socket);
66 fail_unless (socket == NULL);
69 socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV6);
70 have_ipv6 = (socket != NULL);
72 fail_unless (g_socket_get_fd (socket) >= 0);
73 g_object_unref (socket);
76 socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV6);
78 fail_unless (socket != NULL);
79 fail_unless (g_socket_get_fd (socket) >= 0);
80 g_object_unref (socket);
82 fail_unless (socket == NULL);
85 /* check that at least one family is available */
86 fail_unless (have_ipv4 || have_ipv6);
88 fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
90 gst_object_unref (bin);
91 gst_object_unref (stream);
96 GST_START_TEST (test_get_multicast_address)
100 GstRTSPStream *stream;
101 GstRTSPAddressPool *pool;
102 GstRTSPAddress *addr1;
103 GstRTSPAddress *addr2;
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);
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);
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);
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);
134 gst_rtsp_address_free (addr1);
135 gst_rtsp_address_free (addr2);
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);
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);
149 gst_rtsp_address_free (addr1);
150 gst_rtsp_address_free (addr2);
152 g_object_unref (pool);
154 gst_object_unref (stream);
160 rtspstream_suite (void)
162 Suite *s = suite_create ("rtspstream");
163 TCase *tc = tcase_create ("general");
165 suite_add_tcase (s, tc);
166 tcase_add_test (tc, test_get_sockets);
167 tcase_add_test (tc, test_get_multicast_address);
172 GST_CHECK_MAIN (rtspstream);