2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006, 2007 Collabora Ltd.
5 * Contact: Dafydd Harries
6 * (C) 2006, 2007 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
25 * Dafydd Harries, Collabora Ltd.
27 * Alternatively, the contents of this file may be used under the terms of the
28 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
29 * case the provisions of LGPL are applicable instead of those above. If you
30 * wish to allow use of your version of this file only under the terms of the
31 * LGPL and not to allow others to use your version of this file under the
32 * MPL, indicate your decision by deleting the provisions above and replace
33 * them with the notice and other provisions required by the LGPL. If you do
34 * not delete the provisions above, a recipient may use your version of this
35 * file under either the MPL or the LGPL.
45 #include <nice/nice.h>
51 static GMainLoop
*loop
= NULL
;
53 /* XXX: code duplicated from agent/test-send.c */
55 send_connectivity_check (
57 NiceAddress
*remote_addr
)
61 NiceCandidate
*remote
;
67 candidates
= nice_agent_get_local_candidates (agent
, 1, 1);
68 g_assert (candidates
);
69 local
= candidates
->data
;
70 g_assert (local
->id
== 1);
71 g_slist_free (candidates
);
77 candidates
= nice_agent_get_remote_candidates (agent
, 1, 1);
78 g_assert (candidates
);
79 remote
= candidates
->data
;
80 g_slist_free (candidates
);
85 username
= g_strconcat (local
->username
, remote
->username
, NULL
);
92 msg
= stun_message_new (STUN_MESSAGE_BINDING_REQUEST
, NULL
, 1);
93 msg
->attributes
[0] = stun_attribute_username_new (username
);
94 len
= stun_message_pack (msg
, &packed
);
95 nice_udp_fake_socket_push_recv (sock
, remote_addr
, len
, packed
);
97 stun_message_free (msg
);
100 nice_agent_poll_read (agent
, NULL
, NULL
, NULL
);
104 NiceAddress addr
= {0,};
109 len
= nice_udp_fake_socket_pop_send (sock
, &addr
, 1024, packed
);
110 g_assert (nice_address_equal (&addr
, remote_addr
));
111 msg
= stun_message_unpack (len
, packed
);
112 dump
= stun_message_dump (msg
);
113 g_assert (0 == strcmp (dump
,
114 "BINDING-RESPONSE 00000000:00000000:00000000:00000000\n"
115 " MAPPED-ADDRESS 192.168.0.2:2345\n"
116 " USERNAME \"S9PObXR5username\"\n"));
118 stun_message_free (msg
);
123 NiceAddress addr
= {0,};
128 len
= nice_udp_fake_socket_pop_send (sock
, &addr
, 1024, packed
);
129 g_assert (nice_address_equal (&addr
, remote_addr
));
130 msg
= stun_message_unpack (len
, packed
);
131 dump
= stun_message_dump (msg
);
132 g_assert (0 == strcmp (dump
,
133 "BINDING-REQUEST 588c3ac1:e62757ae:5851a519:4d480994\n"
134 " USERNAME \"usernameS9PObXR5\"\n"));
136 stun_message_free (msg
);
145 GIOCondition condition
,
148 /* return value is whether to keep the source */
150 NiceAgent
*agent
= data
;
151 NiceCandidate
*candidate
;
160 candidates
= nice_agent_get_local_candidates (agent
, 1, 1);
161 g_assert (candidates
);
162 candidate
= candidates
->data
;
163 g_slist_free (candidates
);
166 sock
= &candidate
->sock
;
167 len
= nice_udp_fake_socket_pop_send (
168 sock
, &from
, 1024, buf
);
171 g_assert (0 == strncmp (buf
, "\x80hello", len
));
173 g_main_loop_quit (loop
);
178 main (gint argc
, gchar
*argv
[])
182 GstElement
*pipeline
;
184 NiceAddress addr
= {0,};
185 NiceUDPSocketFactory factory
;
187 gst_init (&argc
, &argv
);
189 nice_rng_set_new_func (nice_rng_glib_new_predictable
);
193 nice_address_set_ipv4 (&addr
, 0x7f000001);
194 nice_udp_fake_socket_factory_init (&factory
);
195 agent
= nice_agent_new (&factory
);
196 nice_agent_add_local_address (agent
, &addr
);
197 nice_address_set_ipv4 (&addr
, 0xc0a80002);
199 nice_agent_add_stream (agent
, 1);
200 nice_agent_add_remote_candidate (agent
, 1, 1, NICE_CANDIDATE_TYPE_HOST
,
201 &addr
, "username", "password");
203 // send connectivity check so that sending works
205 send_connectivity_check (agent
, &addr
);
210 NiceCandidate
*candidate
;
214 candidates
= nice_agent_get_local_candidates (agent
, 1, 1);
215 g_assert (candidates
);
216 candidate
= candidates
->data
;
217 sock
= &candidate
->sock
;
218 g_slist_free (candidates
);
222 nice_udp_fake_socket_push_recv (sock
, &addr
, 6, "\x80hello");
224 // watch socket for reveived data
226 io
= g_io_channel_unix_new (nice_udp_fake_socket_get_peer_fd (sock
));
227 source
= g_io_create_watch (io
, G_IO_IN
);
228 g_source_set_callback (source
, (GSourceFunc
) recv_cb
,
230 g_source_attach (source
, NULL
);
235 src
= g_object_new (GST_TYPE_NICE_SRC
,
241 sink
= g_object_new (GST_TYPE_NICE_SINK
,
247 pipeline
= gst_pipeline_new (NULL
);
248 gst_bin_add (GST_BIN (pipeline
), src
);
249 gst_bin_add (GST_BIN (pipeline
), sink
);
250 g_assert (gst_element_link (src
, sink
));
251 gst_element_set_state (pipeline
, GST_STATE_PLAYING
);
255 loop
= g_main_loop_new (NULL
, FALSE
);
256 g_main_loop_run (loop
);
257 g_main_loop_unref (loop
);
261 gst_object_unref (pipeline
);
262 g_object_unref (agent
);
263 nice_udp_socket_factory_close (&factory
);